blob: 707d9d94b416c067fc93e04b6358c01f018b9567 [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
Petr Machata2b46cfc2012-02-18 11:17:29 +010011/* XXX Apparently PPC64 doesn't support PLT breakpoints. */
Juan Cespedesf1350522008-12-16 18:19:58 +010012void *
Juan Cespedesa8909f72009-04-28 20:02:41 +020013sym2addr(Process *proc, struct library_symbol *sym) {
Olaf Heringa841f652006-09-15 01:57:49 +020014 void *addr = sym->enter_addr;
Paul Gilliam76c61f12006-06-14 06:55:21 +020015 long pt_ret;
Ian Wienand9a2ad352006-02-20 22:44:45 +010016
Ian Wienand2d45b1a2006-02-20 22:48:07 +010017 debug(3, 0);
Ian Wienand9a2ad352006-02-20 22:44:45 +010018
Paul Gilliam76c61f12006-06-14 06:55:21 +020019 if (sym->plt_type != LS_TOPLT_POINT) {
20 return addr;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010021 }
Ian Wienand9a2ad352006-02-20 22:44:45 +010022
Paul Gilliam76c61f12006-06-14 06:55:21 +020023 if (proc->pid == 0) {
24 return 0;
25 }
26
Juan Cespedesda9b9532009-04-07 15:33:50 +020027 if (options.debug >= 3) {
Paul Gilliam76c61f12006-06-14 06:55:21 +020028 xinfdump(proc->pid, (void *)(((long)addr-32)&0xfffffff0),
29 sizeof(void*)*8);
30 }
31
32 // On a PowerPC-64 system, a plt is three 64-bit words: the first is the
33 // 64-bit address of the routine. Before the PLT has been initialized,
34 // this will be 0x0. In fact, the symbol table won't have the plt's
35 // address even. Ater the PLT has been initialized, but before it has
36 // been resolved, the first word will be the address of the function in
37 // the dynamic linker that will reslove the PLT. After the PLT is
38 // resolved, this will will be the address of the routine whose symbol
39 // is in the symbol table.
40
41 // On a PowerPC-32 system, there are two types of PLTs: secure (new) and
42 // non-secure (old). For the secure case, the PLT is simply a pointer
43 // and we can treat it much as we do for the PowerPC-64 case. For the
44 // non-secure case, the PLT is executable code and we can put the
45 // break-point right in the PLT.
46
47 pt_ret = ptrace(PTRACE_PEEKTEXT, proc->pid, addr, 0);
48
Michael K. Edwards9bc4a9b2011-03-06 17:20:11 +000049#if SIZEOF_LONG == 8
Paul Gilliam76c61f12006-06-14 06:55:21 +020050 if (proc->mask_32bit) {
51 // Assume big-endian.
52 addr = (void *)((pt_ret >> 32) & 0xffffffff);
53 } else {
54 addr = (void *)pt_ret;
55 }
Michael K. Edwards9bc4a9b2011-03-06 17:20:11 +000056#else
Petr Machata2b46cfc2012-02-18 11:17:29 +010057 /* XXX Um, so where exactly are we dealing with the non-secure
58 PLT thing? */
Michael K. Edwards9bc4a9b2011-03-06 17:20:11 +000059 addr = (void *)pt_ret;
60#endif
Paul Gilliam76c61f12006-06-14 06:55:21 +020061
62 return addr;
Ian Wienand9a2ad352006-02-20 22:44:45 +010063}