Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 1 | #ifndef LTRACE_ELF_H |
| 2 | #define LTRACE_ELF_H |
| 3 | |
Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 4 | #include <gelf.h> |
| 5 | #include <stdlib.h> |
Petr Machata | fd43ef7 | 2012-02-10 12:25:11 +0100 | [diff] [blame] | 6 | #include "proc.h" |
Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 7 | |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 8 | struct ltelf { |
| 9 | int fd; |
| 10 | Elf *elf; |
| 11 | GElf_Ehdr ehdr; |
| 12 | Elf_Data *dynsym; |
| 13 | size_t dynsym_count; |
| 14 | const char *dynstr; |
| 15 | GElf_Addr plt_addr; |
| 16 | size_t plt_size; |
| 17 | Elf_Data *relplt; |
| 18 | size_t relplt_count; |
| 19 | Elf_Data *symtab; |
| 20 | const char *strtab; |
| 21 | size_t symtab_count; |
| 22 | Elf_Data *opd; |
| 23 | GElf_Addr *opd_addr; |
| 24 | size_t opd_size; |
| 25 | Elf32_Word *hash; |
Petr Machata | 35fe518 | 2006-07-18 12:58:12 +0200 | [diff] [blame] | 26 | int hash_type; |
Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 27 | int lte_flags; |
Joe Damato | 87f4f58 | 2010-11-08 15:47:36 -0800 | [diff] [blame] | 28 | GElf_Addr dyn_addr; |
| 29 | size_t dyn_sz; |
Joe Damato | 07581fb | 2010-11-08 15:47:37 -0800 | [diff] [blame] | 30 | GElf_Addr base_addr; |
Eric Vaitl | 1228a91 | 2006-12-28 16:16:56 +0100 | [diff] [blame] | 31 | #ifdef __mips__ |
Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 32 | size_t pltgot_addr; |
| 33 | size_t mips_local_gotno; |
| 34 | size_t mips_gotsym; |
Eric Vaitl | 1228a91 | 2006-12-28 16:16:56 +0100 | [diff] [blame] | 35 | #endif // __mips__ |
Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 36 | GElf_Addr plt_stub_vma; |
Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 37 | }; |
| 38 | |
Joe Damato | 47cae1e | 2010-11-08 15:47:39 -0800 | [diff] [blame] | 39 | #define ELF_MAX_SEGMENTS 50 |
Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 40 | #define LTE_HASH_MALLOCED 1 |
| 41 | #define LTE_PLT_EXECUTABLE 2 |
| 42 | |
| 43 | #define PLTS_ARE_EXECUTABLE(lte) ((lte->lte_flags & LTE_PLT_EXECUTABLE) != 0) |
| 44 | |
Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame] | 45 | extern size_t library_num; |
Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 46 | extern char *library[MAX_LIBRARIES]; |
Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 47 | |
Petr Machata | 02bd9ec | 2011-09-21 17:38:59 +0200 | [diff] [blame] | 48 | extern int open_elf(struct ltelf *lte, const char *filename); |
Petr Machata | e84fa00 | 2012-02-07 13:43:03 +0100 | [diff] [blame] | 49 | extern struct library_symbol *read_elf(Process *proc, GElf_Addr *entryp); |
Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 50 | |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 51 | extern GElf_Addr arch_plt_sym_val(struct ltelf *, size_t, GElf_Rela *); |
Juan Cespedes | 96935a9 | 1997-08-09 23:45:39 +0200 | [diff] [blame] | 52 | |
Olaf Hering | 03c087b | 2006-09-25 02:31:27 +0200 | [diff] [blame] | 53 | #ifndef SHT_GNU_HASH |
| 54 | #define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */ |
| 55 | #endif |
Zachary T Welch | 3ba522f | 2010-12-14 15:12:47 -0800 | [diff] [blame] | 56 | |
| 57 | #if __WORDSIZE == 32 |
| 58 | #define PRI_ELF_ADDR PRIx32 |
| 59 | #define GELF_ADDR_CAST(x) (void *)(uint32_t)(x) |
| 60 | #else |
| 61 | #define PRI_ELF_ADDR PRIx64 |
| 62 | #define GELF_ADDR_CAST(x) (void *)(x) |
| 63 | #endif |
| 64 | |
Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 65 | #endif |