| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 1 | #include <gelf.h> |
| 2 | #include "ltrace.h" |
| 3 | #include "elf.h" |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 4 | #include "debug.h" |
| 5 | #include "ptrace.h" |
| 6 | #include "options.h" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 7 | |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 8 | GElf_Addr |
| 9 | arch_plt_sym_val (struct ltelf *lte, size_t ndx, GElf_Rela *rela) |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 10 | { |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 11 | return rela->r_offset; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 12 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 13 | |
| 14 | void * plt2addr(struct process *proc, void ** plt) |
| 15 | { |
| 16 | long addr; |
| 17 | |
| 18 | debug(3, 0); |
| 19 | |
| 20 | if (proc->e_machine == EM_PPC || plt == 0) |
| 21 | return (void *)plt; |
| 22 | |
| 23 | if (proc->pid == 0) |
| 24 | return (void *)0; |
| 25 | |
| 26 | // On a PowerPC-64 system, a plt is three 64-bit words: the first is the |
| 27 | // 64-bit address of the routine. Before the PLT has been initialized, this |
| 28 | // will be 0x0. In fact, the symbol table won't have the plt's address even. |
| 29 | // Ater the PLT has been initialized, but before it has been resolved, the |
| 30 | // first word will be the address of the function in the dynamic linker that |
| 31 | // will reslove the PLT. After the PLT is resolved, this will will be the |
| 32 | // address of the routine whose symbol is in the symbol table. |
| 33 | |
| 34 | addr = ptrace(PTRACE_PEEKTEXT, proc->pid, plt); |
| 35 | |
| 36 | if (opt_d >= 3) { |
| 37 | xinfdump(proc->pid, plt, sizeof(void*)*3); |
| 38 | } |
| 39 | |
| 40 | return (void *)addr; |
| 41 | } |
| 42 | |