blob: 761681406b9dfffdd886e6f79070e536cbed6c61 [file] [log] [blame]
Juan Cespedes1cd999a2001-07-03 00:46:04 +02001#ifndef LTRACE_ELF_H
2#define LTRACE_ELF_H
3
Juan Cespedesd914a202004-11-10 00:15:33 +01004#include <gelf.h>
5#include <stdlib.h>
6
Petr Machata2b46cfc2012-02-18 11:17:29 +01007struct Process;
8struct library;
9
10/* XXX Ok, the original idea was to separate the low-level ELF data
11 * from the abstract "struct library" object, but we use some of the
12 * following extensively in the back end. Not all though. So what we
13 * use should be move to struct library, and the rest of this
14 * structure maybe could be safely hidden in .c. How to integrate the
15 * arch-specific bits into struct library is unclear as of now. */
Ian Wienand2d45b1a2006-02-20 22:48:07 +010016struct ltelf {
17 int fd;
18 Elf *elf;
19 GElf_Ehdr ehdr;
20 Elf_Data *dynsym;
21 size_t dynsym_count;
22 const char *dynstr;
23 GElf_Addr plt_addr;
24 size_t plt_size;
25 Elf_Data *relplt;
26 size_t relplt_count;
27 Elf_Data *symtab;
28 const char *strtab;
Petr Machata2b46cfc2012-02-18 11:17:29 +010029 const char *soname;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010030 size_t symtab_count;
31 Elf_Data *opd;
32 GElf_Addr *opd_addr;
33 size_t opd_size;
Paul Gilliam76c61f12006-06-14 06:55:21 +020034 int lte_flags;
Joe Damato87f4f582010-11-08 15:47:36 -080035 GElf_Addr dyn_addr;
36 size_t dyn_sz;
Joe Damato07581fb2010-11-08 15:47:37 -080037 GElf_Addr base_addr;
Petr Machata2b46cfc2012-02-18 11:17:29 +010038 GElf_Addr entry_addr;
Eric Vaitl1228a912006-12-28 16:16:56 +010039#ifdef __mips__
Juan Cespedesa413e5b2007-09-04 17:34:53 +020040 size_t pltgot_addr;
41 size_t mips_local_gotno;
42 size_t mips_gotsym;
Eric Vaitl1228a912006-12-28 16:16:56 +010043#endif // __mips__
Petr Machatafe1c1712010-10-27 16:57:34 +020044 GElf_Addr plt_stub_vma;
Juan Cespedes1cd999a2001-07-03 00:46:04 +020045};
46
Joe Damato47cae1e2010-11-08 15:47:39 -080047#define ELF_MAX_SEGMENTS 50
Paul Gilliam76c61f12006-06-14 06:55:21 +020048#define LTE_PLT_EXECUTABLE 2
49
Petr Machata2b46cfc2012-02-18 11:17:29 +010050#define PLTS_ARE_EXECUTABLE(lte) (((lte)->lte_flags & LTE_PLT_EXECUTABLE) != 0)
Paul Gilliam76c61f12006-06-14 06:55:21 +020051
Petr Machata2b46cfc2012-02-18 11:17:29 +010052int open_elf(struct ltelf *lte, const char *filename);
Juan Cespedes1cd999a2001-07-03 00:46:04 +020053
Petr Machata2b46cfc2012-02-18 11:17:29 +010054/* XXX is it possible to put breakpoints in VDSO and VSYSCALL
55 * pseudo-libraries? For now we assume that all libraries can be
56 * opened via a filesystem. BASE is ignored for ET_EXEC files. */
57struct library *ltelf_read_library(const char *filename, GElf_Addr base);
Juan Cespedesd914a202004-11-10 00:15:33 +010058
Petr Machata2b46cfc2012-02-18 11:17:29 +010059/* Create a library object representing the main binary. The entry
60 * point address is stored to *ENTRYP. */
61struct library *ltelf_read_main_binary(struct Process *proc, const char *path);
Juan Cespedes96935a91997-08-09 23:45:39 +020062
Petr Machata2b46cfc2012-02-18 11:17:29 +010063GElf_Addr arch_plt_sym_val(struct ltelf *, size_t, GElf_Rela *);
Zachary T Welch3ba522f2010-12-14 15:12:47 -080064
65#if __WORDSIZE == 32
66#define PRI_ELF_ADDR PRIx32
67#define GELF_ADDR_CAST(x) (void *)(uint32_t)(x)
68#else
69#define PRI_ELF_ADDR PRIx64
70#define GELF_ADDR_CAST(x) (void *)(x)
71#endif
72
Juan Cespedes1cd999a2001-07-03 00:46:04 +020073#endif