fixes for prelink

This commit is contained in:
Stefani Seibold 2016-05-19 13:24:15 +02:00
parent 65e33d33d0
commit 3f7f77d105
13 changed files with 25 additions and 16 deletions

View File

@ -25,6 +25,7 @@
#include <assert.h>
#include <errno.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -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;
}

View File

@ -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, &copy->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
View File

@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <malloc.h>
#include "common.h"
#include "dict.h"

View File

@ -36,6 +36,7 @@
#include <inttypes.h>
#include <errno.h>
#include <unistd.h>
#include <malloc.h>
#include "backend.h"
#include "common.h"

View File

@ -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));
}

View File

@ -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;

View File

@ -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
View File

@ -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);

View File

@ -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;
};

View File

@ -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);

View File

@ -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);
}

1
task.c
View File

@ -26,6 +26,7 @@
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>