blob: 980d0283dfa87b3a4fa02c95319b6155c0ff5770 [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>
Juan Cespedesf7281232009-06-25 16:11:21 +02003#include "common.h"
Juan Cespedesd914a202004-11-10 00:15:33 +01004
Juan Cespedesf1350522008-12-16 18:19:58 +01005GElf_Addr
6arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +01007 return rela->r_offset;
Juan Cespedesd914a202004-11-10 00:15:33 +01008}
Ian Wienand9a2ad352006-02-20 22:44:45 +01009
Juan Cespedesf1350522008-12-16 18:19:58 +010010void *
Juan Cespedesa8909f72009-04-28 20:02:41 +020011sym2addr(Process *proc, struct library_symbol *sym) {
Olaf Heringa841f652006-09-15 01:57:49 +020012 void *addr = sym->enter_addr;
Paul Gilliam76c61f12006-06-14 06:55:21 +020013 long pt_ret;
Ian Wienand9a2ad352006-02-20 22:44:45 +010014
Ian Wienand2d45b1a2006-02-20 22:48:07 +010015 debug(3, 0);
Ian Wienand9a2ad352006-02-20 22:44:45 +010016
Paul Gilliam76c61f12006-06-14 06:55:21 +020017 if (sym->plt_type != LS_TOPLT_POINT) {
18 return addr;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010019 }
Ian Wienand9a2ad352006-02-20 22:44:45 +010020
Paul Gilliam76c61f12006-06-14 06:55:21 +020021 if (proc->pid == 0) {
22 return 0;
23 }
24
Juan Cespedesda9b9532009-04-07 15:33:50 +020025 if (options.debug >= 3) {
Paul Gilliam76c61f12006-06-14 06:55:21 +020026 xinfdump(proc->pid, (void *)(((long)addr-32)&0xfffffff0),
27 sizeof(void*)*8);
28 }
29
30 // On a PowerPC-64 system, a plt is three 64-bit words: the first is the
31 // 64-bit address of the routine. Before the PLT has been initialized,
32 // this will be 0x0. In fact, the symbol table won't have the plt's
33 // address even. Ater the PLT has been initialized, but before it has
34 // been resolved, the first word will be the address of the function in
35 // the dynamic linker that will reslove the PLT. After the PLT is
36 // resolved, this will will be the address of the routine whose symbol
37 // is in the symbol table.
38
39 // On a PowerPC-32 system, there are two types of PLTs: secure (new) and
40 // non-secure (old). For the secure case, the PLT is simply a pointer
41 // and we can treat it much as we do for the PowerPC-64 case. For the
42 // non-secure case, the PLT is executable code and we can put the
43 // break-point right in the PLT.
44
45 pt_ret = ptrace(PTRACE_PEEKTEXT, proc->pid, addr, 0);
46
47 if (proc->mask_32bit) {
48 // Assume big-endian.
49 addr = (void *)((pt_ret >> 32) & 0xffffffff);
50 } else {
51 addr = (void *)pt_ret;
52 }
53
54 return addr;
Ian Wienand9a2ad352006-02-20 22:44:45 +010055}