2 * This file is part of ltrace.
3 * Copyright (C) 2006,2010,2012 Petr Machata, Red Hat Inc.
4 * Copyright (C) 2010 Zachary T Welch
5 * Copyright (C) 2001,2004,2007,2009 Juan Cespedes
6 * Copyright (C) 2006 Ian Wienand
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
33 struct library_symbol;
35 /* XXX Ok, the original idea was to separate the low-level ELF data
36 * from the abstract "struct library" object, but we use some of the
37 * following extensively in the back end. Not all though. So what we
38 * use should be move to struct library, and the rest of this
39 * structure maybe could be safely hidden in .c. How to integrate the
40 * arch-specific bits into struct library is unclear as of now. */
67 struct arch_ltelf_data arch;
70 int open_elf(struct ltelf *lte, const char *filename);
71 void do_close_elf(struct ltelf *lte);
73 /* XXX is it possible to put breakpoints in VDSO and VSYSCALL
74 * pseudo-libraries? For now we assume that all libraries can be
75 * opened via a filesystem. BASE is ignored for ET_EXEC files. */
76 int ltelf_read_library(struct library *lib, struct Process *proc,
77 const char *filename, GElf_Addr bias);
79 /* Create a library object representing the main binary. The entry
80 * point address is stored to *ENTRYP. */
81 struct library *ltelf_read_main_binary(struct Process *proc, const char *path);
83 /* Create a default PLT entry. This can be used instead (or in
84 * addition to) returning plt_default from arch_elf_add_plt_entry.
85 * RET shall be initialized, the created symbol will be added to the
86 * beginning of the linked list at *RET. This function doesn't add
87 * the symbol to LTE. arch_elf_add_plt_entry has the chance to adjust
88 * symbol internals to its liking, and then return either plt_default
90 int default_elf_add_plt_entry(struct Process *proc, struct ltelf *lte,
91 const char *a_name, GElf_Rela *rela, size_t ndx,
92 struct library_symbol **ret);
94 /* The base implementation of backend.h (arch_get_sym_info).
95 * See backend.h for details. */
96 int elf_get_sym_info(struct ltelf *lte, const char *filename,
97 size_t sym_index, GElf_Rela *rela, GElf_Sym *sym);
99 Elf_Data *elf_loaddata(Elf_Scn *scn, GElf_Shdr *shdr);
100 int elf_get_section_covering(struct ltelf *lte, GElf_Addr addr,
101 Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr);
102 int elf_get_section_type(struct ltelf *lte, GElf_Word type,
103 Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr);
104 int elf_get_section_named(struct ltelf *lte, const char *name,
105 Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr);
107 /* Read, respectively, 2, 4, or 8 bytes from Elf data at given OFFSET,
108 * and store it in *RETP. Returns 0 on success or a negative value if
109 * there's not enough data. */
110 int elf_read_u16(Elf_Data *data, GElf_Xword offset, uint16_t *retp);
111 int elf_read_u32(Elf_Data *data, GElf_Xword offset, uint32_t *retp);
112 int elf_read_u64(Elf_Data *data, GElf_Xword offset, uint64_t *retp);
115 #define PRI_ELF_ADDR PRIx32
116 #define GELF_ADDR_CAST(x) (void *)(uint32_t)(x)
118 #define PRI_ELF_ADDR PRIx64
119 #define GELF_ADDR_CAST(x) (void *)(x)