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