plt.c revision fea4a1285dc7bea02b0203845ad43117f091fc3e
1#include <gelf.h> 2#include "ltrace.h" 3#include "elf.h" 4#include "debug.h" 5 6/* A bundle is 128 bits */ 7#define BUNDLE_SIZE 16 8 9/* 10 11 The PLT has 12 13 ] 3 bundles as a header 14 15 ] The special reserved entry 16 17 ] Following that, each PLT entry has it's initial code that the GOT entry 18 points to. Each PLT entry has one bundle allocated. 19 20 ] Following that, each PLT entry has two bundles of actual PLT code, 21 i.e. load up the address from the GOT and jump to it. This is the 22 point we want to insert the breakpoint, as this will be captured 23 every time we jump to the PLT entry in the code. 24 25*/ 26 27GElf_Addr 28arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) { 29 /* Find number of entires by removing header and special 30 * entry, dividing total size by three, since each PLT entry 31 * will have 3 bundles (1 for inital entry and two for the PLT 32 * code). */ 33 int entries = (lte->plt_size - 4 * BUNDLE_SIZE) / (3 * BUNDLE_SIZE); 34 35 /* Now the point we want to break on is the PLT entry after 36 * all the header stuff */ 37 unsigned long addr = 38 lte->plt_addr + (4 * BUNDLE_SIZE) + (BUNDLE_SIZE * entries) + 39 (2 * ndx * BUNDLE_SIZE); 40 debug(3, "Found PLT %d entry at %lx\n", ndx, addr); 41 42 return addr; 43} 44 45void * 46sym2addr(Process *proc, struct library_symbol *sym) { 47 return sym->enter_addr; 48} 49