mirror of
https://github.com/sstefani/mtrace.git
synced 2025-12-08 01:36:43 +08:00
fixes for prelink
This commit is contained in:
parent
65e33d33d0
commit
3f7f77d105
@ -25,6 +25,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include <link.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libiberty/demangle.h>
|
||||
|
||||
#include "binfile.h"
|
||||
#include "process.h"
|
||||
@ -150,7 +151,7 @@ struct rb_sym *bin_file_lookup(struct bin_file *binfile, bfd_vma addr, unsigned
|
||||
if (!name || !*name)
|
||||
name = "?";
|
||||
else {
|
||||
alloc = bfd_demangle(binfile->abfd, name, 27);
|
||||
alloc = bfd_demangle(binfile->abfd, name, DMGL_TYPES | DMGL_VERBOSE | DMGL_ANSI | DMGL_PARAMS);
|
||||
if (alloc)
|
||||
name = alloc;
|
||||
}
|
||||
|
||||
@ -79,6 +79,7 @@ struct map {
|
||||
unsigned long offset;
|
||||
unsigned long addr;
|
||||
unsigned long size;
|
||||
unsigned long bias;
|
||||
char *filename;
|
||||
struct bin_file *binfile;
|
||||
unsigned int ignore:1;
|
||||
@ -347,7 +348,7 @@ static struct rb_sym *resolv_address(struct process *process, bfd_vma addr)
|
||||
struct map *map = open_map(process, addr);
|
||||
|
||||
if (map) {
|
||||
sym = bin_file_lookup(map->binfile, addr, map->addr);
|
||||
sym = bin_file_lookup(map->binfile, addr, map->bias);
|
||||
if (sym)
|
||||
return sym;
|
||||
}
|
||||
@ -729,13 +730,14 @@ static int process_rb_insert_block(struct process *process, unsigned long addr,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct map *_process_add_map(struct process *process, unsigned long addr, unsigned long offset, unsigned long size, const char *filename, size_t len, struct bin_file *binfile)
|
||||
static struct map *_process_add_map(struct process *process, unsigned long addr, unsigned long offset, unsigned long size, unsigned long bias, const char *filename, size_t len, struct bin_file *binfile)
|
||||
{
|
||||
struct map *map = malloc(sizeof(*map));
|
||||
|
||||
map->addr = addr;
|
||||
map->offset = offset;
|
||||
map->size = size;
|
||||
map->bias = bias;
|
||||
map->filename = malloc(len + 1);
|
||||
map->binfile = binfile;
|
||||
map->ignore = 0;
|
||||
@ -764,8 +766,9 @@ void process_add_map(struct process *process, void *payload, uint32_t payload_le
|
||||
uint64_t addr = process->val64(mt_map->addr);
|
||||
uint64_t offset = process->val64(mt_map->offset);
|
||||
uint64_t size = process->val64(mt_map->size);
|
||||
uint64_t bias = process->val64(mt_map->bias);
|
||||
|
||||
_process_add_map(process, addr, offset, size, mt_map->filename, payload_len - sizeof(*mt_map), NULL);
|
||||
_process_add_map(process, addr, offset, size, bias, mt_map->filename, payload_len - sizeof(*mt_map), NULL);
|
||||
}
|
||||
|
||||
static void _process_del_map(struct map *map)
|
||||
@ -921,7 +924,7 @@ void process_duplicate(struct process *process, struct process *copy)
|
||||
list_for_each(it, ©->map_list) {
|
||||
struct map *map = container_of(it, struct map, list);
|
||||
|
||||
_process_add_map(process, map->addr, map->offset, map->size, map->filename, strlen(map->filename), map->binfile);
|
||||
_process_add_map(process, map->addr, map->offset, map->size, map->bias, map->filename, strlen(map->filename), map->binfile);
|
||||
}
|
||||
|
||||
process->total_allocations = copy->total_allocations;
|
||||
|
||||
1
dict.c
1
dict.c
@ -25,6 +25,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "dict.h"
|
||||
|
||||
1
dwarf.c
1
dwarf.c
@ -36,6 +36,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "backend.h"
|
||||
#include "common.h"
|
||||
|
||||
2
event.c
2
event.c
@ -155,7 +155,7 @@ fail:
|
||||
static void handle_signal(struct task *task)
|
||||
{
|
||||
if (unlikely(options.verbose > 1)) {
|
||||
if (task->event.e_un.signum && (task->event.e_un.signum != SIGSTOP || !task->was_stopped))
|
||||
if (task->event.e_un.signum && task->event.e_un.signum != SIGSTOP)
|
||||
fprintf(stderr, "+++ process pid=%d signal %d: %s +++\n", task->pid, task->event.e_un.signum, strsignal(task->event.e_un.signum));
|
||||
}
|
||||
|
||||
|
||||
@ -63,6 +63,7 @@ struct libref {
|
||||
unsigned long load_offset;
|
||||
unsigned long load_addr;
|
||||
unsigned long load_size;
|
||||
unsigned long bias;
|
||||
|
||||
/* mapped image */
|
||||
void *image_addr;
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
#define IS64BIT 0
|
||||
#endif
|
||||
|
||||
#define MEMTRACE_SI_VERSION 7
|
||||
#define MEMTRACE_SI_VERSION 8
|
||||
|
||||
#define MEMTRACE_SI_FORK 1
|
||||
#define MEMTRACE_SI_EXEC 2
|
||||
@ -135,6 +135,7 @@ struct __attribute__((packed)) mt_map_payload {
|
||||
uint64_t addr;
|
||||
uint64_t offset;
|
||||
uint64_t size;
|
||||
uint64_t bias;
|
||||
char filename[0];
|
||||
};
|
||||
|
||||
|
||||
10
mtelf.c
10
mtelf.c
@ -247,8 +247,10 @@ static int elf_lib_init(struct mt_elf *mte, struct task *task, struct libref *li
|
||||
libref->load_offset = mte->txt_hdr.p_offset;
|
||||
libref->load_addr = mte->txt_hdr.p_vaddr + mte->bias;
|
||||
libref->load_size = mte->txt_hdr.p_filesz;
|
||||
libref->bias = mte->bias;
|
||||
libref->seg_offset = mte->eh_hdr.p_offset;
|
||||
libref->gp = mte->pltgot;
|
||||
libref->key = mte->dyn;
|
||||
|
||||
#ifdef __arm__
|
||||
if (mte->exidx_hdr.p_filesz) {
|
||||
@ -288,7 +290,6 @@ static int elf_read(struct mt_elf *mte, struct task *task, const char *filename,
|
||||
|
||||
memset(&mte->txt_hdr, 0, sizeof(mte->txt_hdr));
|
||||
memset(&mte->eh_hdr, 0, sizeof(mte->eh_hdr));
|
||||
memset(&mte->dyn_hdr, 0, sizeof(mte->dyn_hdr));
|
||||
memset(&mte->exidx_hdr, 0, sizeof(mte->exidx_hdr));
|
||||
|
||||
for (i = 0; gelf_getphdr(mte->elf, i, &phdr) != NULL; ++i) {
|
||||
@ -312,6 +313,9 @@ static int elf_read(struct mt_elf *mte, struct task *task, const char *filename,
|
||||
case PT_INTERP:
|
||||
mte->interp = phdr.p_vaddr + bias;
|
||||
break;
|
||||
case PT_DYNAMIC:
|
||||
mte->dyn = phdr.p_vaddr + bias;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -511,8 +515,6 @@ struct libref *elf_read_main_binary(struct task *task)
|
||||
mte.bias = (GElf_Addr) (uintptr_t) entry - mte.ehdr.e_entry;
|
||||
mte.entry_addr = (GElf_Addr) (uintptr_t) entry;
|
||||
|
||||
libref->key = ARCH_ADDR_T(mte.bias);
|
||||
|
||||
if (elf_lib_init(&mte, task, libref))
|
||||
goto fail3;
|
||||
|
||||
@ -541,8 +543,6 @@ struct libref *elf_read_main_binary(struct task *task)
|
||||
mte_ld.bias = (GElf_Addr)base;
|
||||
mte_ld.entry_addr = mte_ld.ehdr.e_entry + (GElf_Addr)base;
|
||||
|
||||
libref->key = ARCH_ADDR_T(mte_ld.bias);
|
||||
|
||||
ret = elf_lib_init(&mte_ld, task, libref);
|
||||
if (!ret) {
|
||||
library_add(task, libref);
|
||||
|
||||
2
mtelf.h
2
mtelf.h
@ -48,7 +48,7 @@ struct mt_elf {
|
||||
GElf_Addr interp;
|
||||
GElf_Phdr txt_hdr;
|
||||
GElf_Phdr eh_hdr;
|
||||
GElf_Phdr dyn_hdr;
|
||||
GElf_Addr dyn;
|
||||
GElf_Phdr exidx_hdr;
|
||||
GElf_Addr pltgot;
|
||||
};
|
||||
|
||||
1
report.c
1
report.c
@ -388,6 +388,7 @@ int _report_map(struct task *task, struct library *lib, enum mt_operation op)
|
||||
payload->addr = libref->load_addr;
|
||||
payload->offset = libref->load_offset;
|
||||
payload->size = libref->load_size;
|
||||
payload->bias = libref->bias;
|
||||
|
||||
memcpy(payload->filename, libref->filename, len);
|
||||
|
||||
|
||||
@ -396,7 +396,7 @@ static void linkmap_add(struct task *task, struct lt_r_debug_64 *dbg)
|
||||
}
|
||||
|
||||
/* Do we have that library already? */
|
||||
lib = library_find_with_key(&task->libraries_list, ARCH_ADDR_T(rlm.l_addr));
|
||||
lib = library_find_with_key(&task->libraries_list, ARCH_ADDR_T(rlm.l_ld));
|
||||
if (lib)
|
||||
continue;
|
||||
|
||||
@ -426,8 +426,6 @@ static void linkmap_add(struct task *task, struct lt_r_debug_64 *dbg)
|
||||
continue;
|
||||
}
|
||||
|
||||
libref->key = ARCH_ADDR_T(rlm.l_addr);
|
||||
|
||||
library_add(task, libref);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user