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