plt.c revision f13505251e6402460f6cc7ec84e0d8ca91607b4f
1#include <gelf.h> 2#include "ltrace.h" 3#include "elf.h" 4#include "debug.h" 5#include "ptrace.h" 6#include "options.h" 7 8GElf_Addr 9arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) { 10 return rela->r_offset; 11} 12 13void * 14sym2addr(struct process *proc, struct library_symbol *sym) { 15 void *addr = sym->enter_addr; 16 long pt_ret; 17 18 debug(3, 0); 19 20 if (sym->plt_type != LS_TOPLT_POINT) { 21 return addr; 22 } 23 24 if (proc->pid == 0) { 25 return 0; 26 } 27 28 if (opt_d >= 3) { 29 xinfdump(proc->pid, (void *)(((long)addr-32)&0xfffffff0), 30 sizeof(void*)*8); 31 } 32 33 // On a PowerPC-64 system, a plt is three 64-bit words: the first is the 34 // 64-bit address of the routine. Before the PLT has been initialized, 35 // this will be 0x0. In fact, the symbol table won't have the plt's 36 // address even. Ater the PLT has been initialized, but before it has 37 // been resolved, the first word will be the address of the function in 38 // the dynamic linker that will reslove the PLT. After the PLT is 39 // resolved, this will will be the address of the routine whose symbol 40 // is in the symbol table. 41 42 // On a PowerPC-32 system, there are two types of PLTs: secure (new) and 43 // non-secure (old). For the secure case, the PLT is simply a pointer 44 // and we can treat it much as we do for the PowerPC-64 case. For the 45 // non-secure case, the PLT is executable code and we can put the 46 // break-point right in the PLT. 47 48 pt_ret = ptrace(PTRACE_PEEKTEXT, proc->pid, addr, 0); 49 50 if (proc->mask_32bit) { 51 // Assume big-endian. 52 addr = (void *)((pt_ret >> 32) & 0xffffffff); 53 } else { 54 addr = (void *)pt_ret; 55 } 56 57 return addr; 58} 59