| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 1 | #include <gelf.h> |
| Juan Cespedes | a7af00d | 2009-07-26 13:23:18 +0200 | [diff] [blame] | 2 | #include <sys/ptrace.h> |
| Petr Machata | 366c2f4 | 2012-02-09 19:34:36 +0100 | [diff] [blame^] | 3 | #include "proc.h" |
| Juan Cespedes | f728123 | 2009-06-25 16:11:21 +0200 | [diff] [blame] | 4 | #include "common.h" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 5 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 6 | GElf_Addr |
| 7 | arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 8 | return rela->r_offset; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 9 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 10 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 11 | void * |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 12 | sym2addr(Process *proc, struct library_symbol *sym) { |
| Olaf Hering | a841f65 | 2006-09-15 01:57:49 +0200 | [diff] [blame] | 13 | void *addr = sym->enter_addr; |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 14 | long pt_ret; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 15 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 16 | debug(3, 0); |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 17 | |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 18 | if (sym->plt_type != LS_TOPLT_POINT) { |
| 19 | return addr; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 20 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 21 | |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 22 | if (proc->pid == 0) { |
| 23 | return 0; |
| 24 | } |
| 25 | |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 26 | if (options.debug >= 3) { |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 27 | xinfdump(proc->pid, (void *)(((long)addr-32)&0xfffffff0), |
| 28 | sizeof(void*)*8); |
| 29 | } |
| 30 | |
| 31 | // On a PowerPC-64 system, a plt is three 64-bit words: the first is the |
| 32 | // 64-bit address of the routine. Before the PLT has been initialized, |
| 33 | // this will be 0x0. In fact, the symbol table won't have the plt's |
| 34 | // address even. Ater the PLT has been initialized, but before it has |
| 35 | // been resolved, the first word will be the address of the function in |
| 36 | // the dynamic linker that will reslove the PLT. After the PLT is |
| 37 | // resolved, this will will be the address of the routine whose symbol |
| 38 | // is in the symbol table. |
| 39 | |
| 40 | // On a PowerPC-32 system, there are two types of PLTs: secure (new) and |
| 41 | // non-secure (old). For the secure case, the PLT is simply a pointer |
| 42 | // and we can treat it much as we do for the PowerPC-64 case. For the |
| 43 | // non-secure case, the PLT is executable code and we can put the |
| 44 | // break-point right in the PLT. |
| 45 | |
| 46 | pt_ret = ptrace(PTRACE_PEEKTEXT, proc->pid, addr, 0); |
| 47 | |
| Michael K. Edwards | 9bc4a9b | 2011-03-06 17:20:11 +0000 | [diff] [blame] | 48 | #if SIZEOF_LONG == 8 |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 49 | if (proc->mask_32bit) { |
| 50 | // Assume big-endian. |
| 51 | addr = (void *)((pt_ret >> 32) & 0xffffffff); |
| 52 | } else { |
| 53 | addr = (void *)pt_ret; |
| 54 | } |
| Michael K. Edwards | 9bc4a9b | 2011-03-06 17:20:11 +0000 | [diff] [blame] | 55 | #else |
| 56 | addr = (void *)pt_ret; |
| 57 | #endif |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 58 | |
| 59 | return addr; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 60 | } |