blob: 6d3d371baf631078eb00a4eb977e8238ceaeda51 [file] [log] [blame]
Juan Cespedesd914a202004-11-10 00:15:33 +01001#include <gelf.h>
2#include "ltrace.h"
3#include "elf.h"
Ian Wienand9a2ad352006-02-20 22:44:45 +01004#include "debug.h"
5#include "ptrace.h"
6#include "options.h"
Juan Cespedesd914a202004-11-10 00:15:33 +01007
Ian Wienand2d45b1a2006-02-20 22:48:07 +01008GElf_Addr arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela)
Juan Cespedesd914a202004-11-10 00:15:33 +01009{
Ian Wienand2d45b1a2006-02-20 22:48:07 +010010 return rela->r_offset;
Juan Cespedesd914a202004-11-10 00:15:33 +010011}
Ian Wienand9a2ad352006-02-20 22:44:45 +010012
Paul Gilliam76c61f12006-06-14 06:55:21 +020013void *sym2addr(struct process *proc, struct library_symbol *sym)
Ian Wienand9a2ad352006-02-20 22:44:45 +010014{
Olaf Heringa841f652006-09-15 01:57:49 +020015 void *addr = sym->enter_addr;
Paul Gilliam76c61f12006-06-14 06:55:21 +020016 long pt_ret;
Ian Wienand9a2ad352006-02-20 22:44:45 +010017
Ian Wienand2d45b1a2006-02-20 22:48:07 +010018 debug(3, 0);
Ian Wienand9a2ad352006-02-20 22:44:45 +010019
Paul Gilliam76c61f12006-06-14 06:55:21 +020020 if (sym->plt_type != LS_TOPLT_POINT) {
21 return addr;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010022 }
Ian Wienand9a2ad352006-02-20 22:44:45 +010023
Paul Gilliam76c61f12006-06-14 06:55:21 +020024 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 Wienand9a2ad352006-02-20 22:44:45 +010058}