plt.c revision 9a2ad351a1c3215dc596ff3e2e3fd4bc24445a6b
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{
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 = lte->plt_addr + (4*BUNDLE_SIZE) + (BUNDLE_SIZE*entries) +  (2*ndx*BUNDLE_SIZE);
39	debug(3, "Found PLT %d entry at %lx\n", ndx, addr);
40
41	return addr;
42}
43
44void * plt2addr(struct process *proc, void ** plt)
45{
46  return (void *) plt;
47}
48