blob: 36c713b07bd3fe99afab0e814dac10cc67c1ee81 [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
Ian Wienand2d45b1a2006-02-20 22:48:07 +010013void *plt2addr(struct process *proc, void **plt)
Ian Wienand9a2ad352006-02-20 22:44:45 +010014{
Ian Wienand2d45b1a2006-02-20 22:48:07 +010015 long addr;
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
Ian Wienand2d45b1a2006-02-20 22:48:07 +010019 if (proc->e_machine == EM_PPC || plt == 0)
20 return (void *)plt;
Ian Wienand9a2ad352006-02-20 22:44:45 +010021
Ian Wienand2d45b1a2006-02-20 22:48:07 +010022 if (proc->pid == 0)
23 return (void *)0;
Ian Wienand9a2ad352006-02-20 22:44:45 +010024
Ian Wienand2d45b1a2006-02-20 22:48:07 +010025 // On a PowerPC-64 system, a plt is three 64-bit words: the first is the
26 // 64-bit address of the routine. Before the PLT has been initialized, this
27 // will be 0x0. In fact, the symbol table won't have the plt's address even.
28 // Ater the PLT has been initialized, but before it has been resolved, the
29 // first word will be the address of the function in the dynamic linker that
30 // will reslove the PLT. After the PLT is resolved, this will will be the
31 // address of the routine whose symbol is in the symbol table.
Ian Wienand9a2ad352006-02-20 22:44:45 +010032
Ian Wienand2d45b1a2006-02-20 22:48:07 +010033 addr = ptrace(PTRACE_PEEKTEXT, proc->pid, plt);
Ian Wienand9a2ad352006-02-20 22:44:45 +010034
Ian Wienand2d45b1a2006-02-20 22:48:07 +010035 if (opt_d >= 3) {
36 xinfdump(proc->pid, plt, sizeof(void *) * 3);
37 }
Ian Wienand9a2ad352006-02-20 22:44:45 +010038
Ian Wienand2d45b1a2006-02-20 22:48:07 +010039 return (void *)addr;
Ian Wienand9a2ad352006-02-20 22:44:45 +010040}