| 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 | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 8 | GElf_Addr 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] | 9 | { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 10 | return rela->r_offset; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 11 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 12 | |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 13 | void *sym2addr(struct process *proc, struct library_symbol *sym) |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 14 | { |
| Olaf Hering | a841f65 | 2006-09-15 01:57:49 +0200 | [diff] [blame^] | 15 | void *addr = sym->enter_addr; |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 16 | long pt_ret; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 17 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 18 | debug(3, 0); |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 19 | |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 20 | if (sym->plt_type != LS_TOPLT_POINT) { |
| 21 | return addr; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 22 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 23 | |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 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; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 58 | } |