plt.c revision c0ab28673d03bdf8f264556bde0d3806ea062322
1#include <gelf.h>
2
3#include "proc.h"
4#include "library.h"
5#include "ltrace-elf.h"
6
7static int
8arch_plt_entry_has_stub(struct ltelf *lte, size_t off) {
9	uint16_t op = *(uint16_t *)((char *)lte->relplt->d_buf + off);
10	return op == 0x4778;
11}
12
13GElf_Addr
14arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) {
15	size_t start = lte->relplt->d_size + 12;
16	size_t off = start + 20, i;
17	for (i = 0; i < ndx; i++)
18		off += arch_plt_entry_has_stub(lte, off) ? 16 : 12;
19	if (arch_plt_entry_has_stub(lte, off))
20		off += 4;
21	return lte->plt_addr + off - start;
22}
23
24void *
25sym2addr(Process *proc, struct library_symbol *sym) {
26	return sym->enter_addr;
27}
28