blob: 70bc19b17601e5612c845f635d0117b1a66bc82f [file] [log] [blame]
Juan Cespedesd914a202004-11-10 00:15:33 +01001#include <gelf.h>
Juan Cespedesa7af00d2009-07-26 13:23:18 +02002#include <sys/ptrace.h>
Petr Machata366c2f42012-02-09 19:34:36 +01003#include "proc.h"
Juan Cespedesf7281232009-06-25 16:11:21 +02004#include "common.h"
Juan Cespedesd914a202004-11-10 00:15:33 +01005
Juan Cespedesf1350522008-12-16 18:19:58 +01006GElf_Addr
7arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +01008 return rela->r_offset;
Juan Cespedesd914a202004-11-10 00:15:33 +01009}
Ian Wienand9a2ad352006-02-20 22:44:45 +010010
Juan Cespedesf1350522008-12-16 18:19:58 +010011void *
Juan Cespedesa8909f72009-04-28 20:02:41 +020012sym2addr(Process *proc, struct library_symbol *sym) {
Olaf Heringa841f652006-09-15 01:57:49 +020013 void *addr = sym->enter_addr;
Paul Gilliam76c61f12006-06-14 06:55:21 +020014 long pt_ret;
Ian Wienand9a2ad352006-02-20 22:44:45 +010015
Ian Wienand2d45b1a2006-02-20 22:48:07 +010016 debug(3, 0);
Ian Wienand9a2ad352006-02-20 22:44:45 +010017
Paul Gilliam76c61f12006-06-14 06:55:21 +020018 if (sym->plt_type != LS_TOPLT_POINT) {
19 return addr;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010020 }
Ian Wienand9a2ad352006-02-20 22:44:45 +010021
Paul Gilliam76c61f12006-06-14 06:55:21 +020022 if (proc->pid == 0) {
23 return 0;
24 }
25
Juan Cespedesda9b9532009-04-07 15:33:50 +020026 if (options.debug >= 3) {
Paul Gilliam76c61f12006-06-14 06:55:21 +020027 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. Edwards9bc4a9b2011-03-06 17:20:11 +000048#if SIZEOF_LONG == 8
Paul Gilliam76c61f12006-06-14 06:55:21 +020049 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. Edwards9bc4a9b2011-03-06 17:20:11 +000055#else
56 addr = (void *)pt_ret;
57#endif
Paul Gilliam76c61f12006-06-14 06:55:21 +020058
59 return addr;
Ian Wienand9a2ad352006-02-20 22:44:45 +010060}