blob: 29a8b9dcf884a2eabd68d63c18d347ea6ec2071b [file] [log] [blame]
Joe Damatof0bd98b2010-11-08 15:47:42 -08001#include "config.h"
Juan Cespedesd44c6b81998-09-25 14:48:42 +02002
Juan Cespedesd914a202004-11-10 00:15:33 +01003#include <endian.h>
Juan Cespedes96935a91997-08-09 23:45:39 +02004#include <errno.h>
Juan Cespedesd914a202004-11-10 00:15:33 +01005#include <error.h>
Juan Cespedes96935a91997-08-09 23:45:39 +02006#include <fcntl.h>
Juan Cespedesd914a202004-11-10 00:15:33 +01007#include <gelf.h>
Zachary T Welchbfb26c72010-12-06 23:21:00 -08008#include <inttypes.h>
Juan Cespedesd914a202004-11-10 00:15:33 +01009#include <stdint.h>
10#include <stdlib.h>
Juan Cespedes96935a91997-08-09 23:45:39 +020011#include <string.h>
Juan Cespedes5e01f651998-03-08 22:31:44 +010012#include <unistd.h>
Petr Machatafe1c1712010-10-27 16:57:34 +020013#include <assert.h>
Juan Cespedes96935a91997-08-09 23:45:39 +020014
Juan Cespedesf7281232009-06-25 16:11:21 +020015#include "common.h"
Juan Cespedes96935a91997-08-09 23:45:39 +020016
Joe Damato7a2bdf82010-11-08 15:47:41 -080017void do_init_elf(struct ltelf *lte, const char *filename);
18void do_close_elf(struct ltelf *lte);
19void add_library_symbol(GElf_Addr addr, const char *name,
20 struct library_symbol **library_symbolspp,
21 enum toplt type_of_plt, int is_weak);
22int in_load_libraries(const char *name, struct ltelf *lte, size_t count, GElf_Sym *sym);
Ian Wienand4bfcedd2006-08-07 04:03:15 +020023static GElf_Addr opd2addr(struct ltelf *ltc, GElf_Addr addr);
Juan Cespedes1cd999a2001-07-03 00:46:04 +020024
Joe Damato7a2bdf82010-11-08 15:47:41 -080025struct library_symbol *library_symbols = NULL;
Joe Damatof0bd98b2010-11-08 15:47:42 -080026struct ltelf main_lte;
27
Paul Gilliambe320772006-04-24 22:06:23 +020028#ifdef PLT_REINITALISATION_BP
Ian Wienand2d45b1a2006-02-20 22:48:07 +010029extern char *PLTs_initialized_by_here;
Paul Gilliambe320772006-04-24 22:06:23 +020030#endif
Ian Wienand9a2ad352006-02-20 22:44:45 +010031
Petr Machatafe1c1712010-10-27 16:57:34 +020032#ifndef DT_PPC_GOT
33# define DT_PPC_GOT (DT_LOPROC + 0)
34#endif
35
36#define PPC_PLT_STUB_SIZE 16
37
38static Elf_Data *loaddata(Elf_Scn *scn, GElf_Shdr *shdr)
39{
40 Elf_Data *data = elf_getdata(scn, NULL);
41 if (data == NULL || elf_getdata(scn, data) != NULL
42 || data->d_off || data->d_size != shdr->sh_size)
43 return NULL;
44 return data;
45}
46
47static int inside(GElf_Addr addr, GElf_Shdr *shdr)
48{
49 return addr >= shdr->sh_addr
50 && addr < shdr->sh_addr + shdr->sh_size;
51}
52
53static int maybe_pick_section(GElf_Addr addr,
54 Elf_Scn *in_sec, GElf_Shdr *in_shdr,
55 Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr)
56{
57 if (inside (addr, in_shdr)) {
58 *tgt_sec = in_sec;
59 *tgt_shdr = *in_shdr;
60 return 1;
61 }
62 return 0;
63}
64
65static int get_section_covering(struct ltelf *lte, GElf_Addr addr,
66 Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr)
67{
68 int i;
69 for (i = 1; i < lte->ehdr.e_shnum; ++i) {
70 Elf_Scn *scn;
71 GElf_Shdr shdr;
72
73 scn = elf_getscn(lte->elf, i);
74 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) {
75 debug(1, "Couldn't read section or header.");
76 return 0;
77 }
78
79 if (maybe_pick_section(addr, scn, &shdr, tgt_sec, tgt_shdr))
80 return 1;
81 }
82
83 return 0;
84}
85
86static GElf_Addr read32be(Elf_Data *data, size_t offset)
87{
88 if (data->d_size < offset + 4) {
89 debug(1, "Not enough data to read 32bit value at offset %zd.",
90 offset);
91 return 0;
92 }
93
94 unsigned char const *buf = data->d_buf + offset;
95 return ((Elf32_Word)buf[0] << 24)
96 | ((Elf32_Word)buf[1] << 16)
97 | ((Elf32_Word)buf[2] << 8)
98 | ((Elf32_Word)buf[3]);
99}
100
101static GElf_Addr get_glink_vma(struct ltelf *lte, GElf_Addr ppcgot,
102 Elf_Data *plt_data)
103{
104 Elf_Scn *ppcgot_sec = NULL;
105 GElf_Shdr ppcgot_shdr;
106 if (ppcgot != 0
107 && !get_section_covering(lte, ppcgot, &ppcgot_sec, &ppcgot_shdr))
108 // xxx should be the log out
109 fprintf(stderr,
Zachary T Welchbfb26c72010-12-06 23:21:00 -0800110 "DT_PPC_GOT=%#" PRIx64 ", but no such section found.\n",
Petr Machatafe1c1712010-10-27 16:57:34 +0200111 ppcgot);
112
113 if (ppcgot_sec != NULL) {
114 Elf_Data *data = loaddata(ppcgot_sec, &ppcgot_shdr);
115 if (data == NULL
116 || data->d_size < 8 )
117 debug(1, "Couldn't read GOT data.");
118 else {
119 // where PPCGOT begins in .got
120 size_t offset = ppcgot - ppcgot_shdr.sh_addr;
121 GElf_Addr glink_vma = read32be(data, offset + 4);
122 if (glink_vma != 0) {
Zachary T Welchbfb26c72010-12-06 23:21:00 -0800123 debug(1, "PPC GOT glink_vma address: %#" PRIx64,
Petr Machatafe1c1712010-10-27 16:57:34 +0200124 glink_vma);
125 return glink_vma;
126 }
127 }
128 }
129
130 if (plt_data != NULL) {
131 GElf_Addr glink_vma = read32be(plt_data, 0);
Zachary T Welchbfb26c72010-12-06 23:21:00 -0800132 debug(1, ".plt glink_vma address: %#" PRIx64, glink_vma);
Petr Machatafe1c1712010-10-27 16:57:34 +0200133 return glink_vma;
134 }
135
136 return 0;
137}
138
Joe Damato7a2bdf82010-11-08 15:47:41 -0800139void
Juan Cespedesf1350522008-12-16 18:19:58 +0100140do_init_elf(struct ltelf *lte, const char *filename) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100141 int i;
142 GElf_Addr relplt_addr = 0;
143 size_t relplt_size = 0;
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200144
Juan Cespedescd8976d2009-05-14 13:47:58 +0200145 debug(DEBUG_FUNCTION, "do_init_elf(filename=%s)", filename);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100146 debug(1, "Reading ELF from %s...", filename);
Juan Cespedes1afec691997-08-23 21:31:46 +0200147
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100148 lte->fd = open(filename, O_RDONLY);
149 if (lte->fd == -1)
150 error(EXIT_FAILURE, errno, "Can't open \"%s\"", filename);
Juan Cespedes96935a91997-08-09 23:45:39 +0200151
Juan Cespedesd914a202004-11-10 00:15:33 +0100152#ifdef HAVE_ELF_C_READ_MMAP
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100153 lte->elf = elf_begin(lte->fd, ELF_C_READ_MMAP, NULL);
Juan Cespedes5c3fe062004-06-14 18:08:37 +0200154#else
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100155 lte->elf = elf_begin(lte->fd, ELF_C_READ, NULL);
Juan Cespedes5c3fe062004-06-14 18:08:37 +0200156#endif
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200157
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100158 if (lte->elf == NULL || elf_kind(lte->elf) != ELF_K_ELF)
159 error(EXIT_FAILURE, 0, "Can't open ELF file \"%s\"", filename);
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200160
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100161 if (gelf_getehdr(lte->elf, &lte->ehdr) == NULL)
162 error(EXIT_FAILURE, 0, "Can't read ELF header of \"%s\"",
163 filename);
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200164
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100165 if (lte->ehdr.e_type != ET_EXEC && lte->ehdr.e_type != ET_DYN)
166 error(EXIT_FAILURE, 0,
167 "\"%s\" is not an ELF executable nor shared library",
168 filename);
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200169
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100170 if ((lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS
171 || lte->ehdr.e_machine != LT_ELF_MACHINE)
Juan Cespedesd914a202004-11-10 00:15:33 +0100172#ifdef LT_ELF_MACHINE2
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100173 && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS2
174 || lte->ehdr.e_machine != LT_ELF_MACHINE2)
Juan Cespedesd914a202004-11-10 00:15:33 +0100175#endif
176#ifdef LT_ELF_MACHINE3
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100177 && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS3
178 || lte->ehdr.e_machine != LT_ELF_MACHINE3)
Juan Cespedesd914a202004-11-10 00:15:33 +0100179#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100180 )
181 error(EXIT_FAILURE, 0,
182 "\"%s\" is ELF from incompatible architecture", filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100183
Petr Machatafe1c1712010-10-27 16:57:34 +0200184 Elf_Data *plt_data = NULL;
185 GElf_Addr ppcgot = 0;
186
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100187 for (i = 1; i < lte->ehdr.e_shnum; ++i) {
188 Elf_Scn *scn;
189 GElf_Shdr shdr;
190 const char *name;
Juan Cespedesd914a202004-11-10 00:15:33 +0100191
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100192 scn = elf_getscn(lte->elf, i);
193 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
194 error(EXIT_FAILURE, 0,
195 "Couldn't get section header from \"%s\"",
196 filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100197
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100198 name = elf_strptr(lte->elf, lte->ehdr.e_shstrndx, shdr.sh_name);
199 if (name == NULL)
200 error(EXIT_FAILURE, 0,
201 "Couldn't get section header from \"%s\"",
202 filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100203
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100204 if (shdr.sh_type == SHT_SYMTAB) {
205 Elf_Data *data;
Juan Cespedesd914a202004-11-10 00:15:33 +0100206
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100207 lte->symtab = elf_getdata(scn, NULL);
208 lte->symtab_count = shdr.sh_size / shdr.sh_entsize;
209 if ((lte->symtab == NULL
210 || elf_getdata(scn, lte->symtab) != NULL)
211 && opt_x != NULL)
212 error(EXIT_FAILURE, 0,
213 "Couldn't get .symtab data from \"%s\"",
214 filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100215
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100216 scn = elf_getscn(lte->elf, shdr.sh_link);
217 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
218 error(EXIT_FAILURE, 0,
219 "Couldn't get section header from \"%s\"",
220 filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100221
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100222 data = elf_getdata(scn, NULL);
223 if (data == NULL || elf_getdata(scn, data) != NULL
224 || shdr.sh_size != data->d_size || data->d_off)
225 error(EXIT_FAILURE, 0,
226 "Couldn't get .strtab data from \"%s\"",
227 filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100228
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100229 lte->strtab = data->d_buf;
230 } else if (shdr.sh_type == SHT_DYNSYM) {
231 Elf_Data *data;
Juan Cespedesd914a202004-11-10 00:15:33 +0100232
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100233 lte->dynsym = elf_getdata(scn, NULL);
234 lte->dynsym_count = shdr.sh_size / shdr.sh_entsize;
235 if (lte->dynsym == NULL
236 || elf_getdata(scn, lte->dynsym) != NULL)
237 error(EXIT_FAILURE, 0,
238 "Couldn't get .dynsym data from \"%s\"",
239 filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100240
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100241 scn = elf_getscn(lte->elf, shdr.sh_link);
242 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
243 error(EXIT_FAILURE, 0,
244 "Couldn't get section header from \"%s\"",
245 filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100246
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100247 data = elf_getdata(scn, NULL);
248 if (data == NULL || elf_getdata(scn, data) != NULL
249 || shdr.sh_size != data->d_size || data->d_off)
250 error(EXIT_FAILURE, 0,
251 "Couldn't get .dynstr data from \"%s\"",
252 filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100253
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100254 lte->dynstr = data->d_buf;
255 } else if (shdr.sh_type == SHT_DYNAMIC) {
256 Elf_Data *data;
257 size_t j;
Juan Cespedesd914a202004-11-10 00:15:33 +0100258
Joe Damato87f4f582010-11-08 15:47:36 -0800259 lte->dyn_addr = shdr.sh_addr;
260 lte->dyn_sz = shdr.sh_size;
261
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100262 data = elf_getdata(scn, NULL);
263 if (data == NULL || elf_getdata(scn, data) != NULL)
264 error(EXIT_FAILURE, 0,
265 "Couldn't get .dynamic data from \"%s\"",
266 filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100267
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100268 for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j) {
269 GElf_Dyn dyn;
Juan Cespedesd914a202004-11-10 00:15:33 +0100270
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100271 if (gelf_getdyn(data, j, &dyn) == NULL)
272 error(EXIT_FAILURE, 0,
273 "Couldn't get .dynamic data from \"%s\"",
274 filename);
Eric Vaitl1228a912006-12-28 16:16:56 +0100275#ifdef __mips__
276/**
277 MIPS ABI Supplement:
Ian Wienand9a2ad352006-02-20 22:44:45 +0100278
Juan Cespedesf1350522008-12-16 18:19:58 +0100279 DT_PLTGOT This member holds the address of the .got section.
Eric Vaitl1228a912006-12-28 16:16:56 +0100280
281 DT_MIPS_SYMTABNO This member holds the number of entries in the
282 .dynsym section.
283
284 DT_MIPS_LOCAL_GOTNO This member holds the number of local global
285 offset table entries.
286
287 DT_MIPS_GOTSYM This member holds the index of the first dyamic
288 symbol table entry that corresponds to an entry in the gobal offset
289 table.
290
291 */
Juan Cespedesa413e5b2007-09-04 17:34:53 +0200292 if(dyn.d_tag==DT_PLTGOT){
Juan Cespedesf1350522008-12-16 18:19:58 +0100293 lte->pltgot_addr=dyn.d_un.d_ptr;
Juan Cespedesa413e5b2007-09-04 17:34:53 +0200294 }
295 if(dyn.d_tag==DT_MIPS_LOCAL_GOTNO){
296 lte->mips_local_gotno=dyn.d_un.d_val;
297 }
298 if(dyn.d_tag==DT_MIPS_GOTSYM){
299 lte->mips_gotsym=dyn.d_un.d_val;
300 }
Eric Vaitl1228a912006-12-28 16:16:56 +0100301#endif // __mips__
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100302 if (dyn.d_tag == DT_JMPREL)
303 relplt_addr = dyn.d_un.d_ptr;
304 else if (dyn.d_tag == DT_PLTRELSZ)
305 relplt_size = dyn.d_un.d_val;
Petr Machatafe1c1712010-10-27 16:57:34 +0200306 else if (dyn.d_tag == DT_PPC_GOT) {
307 ppcgot = dyn.d_un.d_val;
Zachary T Welchbfb26c72010-12-06 23:21:00 -0800308 debug(1, "ppcgot %#" PRIx64, ppcgot);
Petr Machatafe1c1712010-10-27 16:57:34 +0200309 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100310 }
311 } else if (shdr.sh_type == SHT_HASH) {
312 Elf_Data *data;
313 size_t j;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100314
Petr Machata35fe5182006-07-18 12:58:12 +0200315 lte->hash_type = SHT_HASH;
316
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100317 data = elf_getdata(scn, NULL);
318 if (data == NULL || elf_getdata(scn, data) != NULL
319 || data->d_off || data->d_size != shdr.sh_size)
320 error(EXIT_FAILURE, 0,
321 "Couldn't get .hash data from \"%s\"",
322 filename);
Ian Wienand9a2ad352006-02-20 22:44:45 +0100323
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100324 if (shdr.sh_entsize == 4) {
325 /* Standard conforming ELF. */
326 if (data->d_type != ELF_T_WORD)
327 error(EXIT_FAILURE, 0,
328 "Couldn't get .hash data from \"%s\"",
329 filename);
330 lte->hash = (Elf32_Word *) data->d_buf;
331 } else if (shdr.sh_entsize == 8) {
332 /* Alpha or s390x. */
333 Elf32_Word *dst, *src;
334 size_t hash_count = data->d_size / 8;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100335
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100336 lte->hash = (Elf32_Word *)
337 malloc(hash_count * sizeof(Elf32_Word));
338 if (lte->hash == NULL)
339 error(EXIT_FAILURE, 0,
340 "Couldn't convert .hash section from \"%s\"",
341 filename);
Paul Gilliam76c61f12006-06-14 06:55:21 +0200342 lte->lte_flags |= LTE_HASH_MALLOCED;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100343 dst = lte->hash;
344 src = (Elf32_Word *) data->d_buf;
345 if ((data->d_type == ELF_T_WORD
346 && __BYTE_ORDER == __BIG_ENDIAN)
347 || (data->d_type == ELF_T_XWORD
348 && lte->ehdr.e_ident[EI_DATA] ==
349 ELFDATA2MSB))
350 ++src;
351 for (j = 0; j < hash_count; ++j, src += 2)
352 *dst++ = *src;
353 } else
354 error(EXIT_FAILURE, 0,
355 "Unknown .hash sh_entsize in \"%s\"",
356 filename);
Petr Machata35fe5182006-07-18 12:58:12 +0200357 } else if (shdr.sh_type == SHT_GNU_HASH
358 && lte->hash == NULL) {
359 Elf_Data *data;
Petr Machata35fe5182006-07-18 12:58:12 +0200360
361 lte->hash_type = SHT_GNU_HASH;
362
363 if (shdr.sh_entsize != 0
364 && shdr.sh_entsize != 4) {
365 error(EXIT_FAILURE, 0,
Olaf Hering03c087b2006-09-25 02:31:27 +0200366 ".gnu.hash sh_entsize in \"%s\" should be 4, but is %llu",
Petr Machata35fe5182006-07-18 12:58:12 +0200367 filename, shdr.sh_entsize);
368 }
369
Petr Machatafe1c1712010-10-27 16:57:34 +0200370 data = loaddata(scn, &shdr);
371 if (data == NULL)
Petr Machata35fe5182006-07-18 12:58:12 +0200372 error(EXIT_FAILURE, 0,
373 "Couldn't get .gnu.hash data from \"%s\"",
374 filename);
375
376 lte->hash = (Elf32_Word *) data->d_buf;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100377 } else if (shdr.sh_type == SHT_PROGBITS
378 || shdr.sh_type == SHT_NOBITS) {
379 if (strcmp(name, ".plt") == 0) {
380 lte->plt_addr = shdr.sh_addr;
381 lte->plt_size = shdr.sh_size;
Paul Gilliam76c61f12006-06-14 06:55:21 +0200382 if (shdr.sh_flags & SHF_EXECINSTR) {
383 lte->lte_flags |= LTE_PLT_EXECUTABLE;
384 }
Petr Machatafe1c1712010-10-27 16:57:34 +0200385 if (lte->ehdr.e_machine == EM_PPC) {
386 plt_data = loaddata(scn, &shdr);
387 if (plt_data == NULL)
388 fprintf(stderr,
389 "Can't load .plt data\n");
390 }
Petr Machatab3f8fef2006-11-30 14:45:07 +0100391 }
392#ifdef ARCH_SUPPORTS_OPD
393 else if (strcmp(name, ".opd") == 0) {
Paul Gilliam3f1219f2006-04-24 18:25:38 +0200394 lte->opd_addr = (GElf_Addr *) (long) shdr.sh_addr;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100395 lte->opd_size = shdr.sh_size;
396 lte->opd = elf_rawdata(scn, NULL);
397 }
Petr Machatab3f8fef2006-11-30 14:45:07 +0100398#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100399 }
Juan Cespedesd914a202004-11-10 00:15:33 +0100400 }
401
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100402 if (lte->dynsym == NULL || lte->dynstr == NULL)
403 error(EXIT_FAILURE, 0,
404 "Couldn't find .dynsym or .dynstr in \"%s\"", filename);
Juan Cespedesd914a202004-11-10 00:15:33 +0100405
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100406 if (!relplt_addr || !lte->plt_addr) {
407 debug(1, "%s has no PLT relocations", filename);
408 lte->relplt = NULL;
409 lte->relplt_count = 0;
Petr Machatafe1c1712010-10-27 16:57:34 +0200410 } else if (relplt_size == 0) {
411 debug(1, "%s has unknown PLT size", filename);
412 lte->relplt = NULL;
413 lte->relplt_count = 0;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100414 } else {
Petr Machatafe1c1712010-10-27 16:57:34 +0200415 if (lte->ehdr.e_machine == EM_PPC) {
416 GElf_Addr glink_vma
417 = get_glink_vma(lte, ppcgot, plt_data);
418
419 assert (relplt_size % 12 == 0);
420 size_t count = relplt_size / 12; // size of RELA entry
421 lte->plt_stub_vma = glink_vma
422 - (GElf_Addr)count * PPC_PLT_STUB_SIZE;
Zachary T Welchbfb26c72010-12-06 23:21:00 -0800423 debug(1, "stub_vma is %#" PRIx64, lte->plt_stub_vma);
Petr Machatafe1c1712010-10-27 16:57:34 +0200424 }
425
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100426 for (i = 1; i < lte->ehdr.e_shnum; ++i) {
427 Elf_Scn *scn;
428 GElf_Shdr shdr;
429
430 scn = elf_getscn(lte->elf, i);
431 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
432 error(EXIT_FAILURE, 0,
433 "Couldn't get section header from \"%s\"",
434 filename);
435 if (shdr.sh_addr == relplt_addr
436 && shdr.sh_size == relplt_size) {
437 lte->relplt = elf_getdata(scn, NULL);
438 lte->relplt_count =
439 shdr.sh_size / shdr.sh_entsize;
440 if (lte->relplt == NULL
441 || elf_getdata(scn, lte->relplt) != NULL)
442 error(EXIT_FAILURE, 0,
443 "Couldn't get .rel*.plt data from \"%s\"",
444 filename);
445 break;
446 }
447 }
448
449 if (i == lte->ehdr.e_shnum)
450 error(EXIT_FAILURE, 0,
451 "Couldn't find .rel*.plt section in \"%s\"",
452 filename);
453
454 debug(1, "%s %zd PLT relocations", filename, lte->relplt_count);
455 }
456}
457
Joe Damato7a2bdf82010-11-08 15:47:41 -0800458void
Juan Cespedesf1350522008-12-16 18:19:58 +0100459do_close_elf(struct ltelf *lte) {
Juan Cespedescd8976d2009-05-14 13:47:58 +0200460 debug(DEBUG_FUNCTION, "do_close_elf()");
Paul Gilliam76c61f12006-06-14 06:55:21 +0200461 if (lte->lte_flags & LTE_HASH_MALLOCED)
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100462 free((char *)lte->hash);
463 elf_end(lte->elf);
464 close(lte->fd);
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200465}
466
Joe Damato7a2bdf82010-11-08 15:47:41 -0800467void
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100468add_library_symbol(GElf_Addr addr, const char *name,
469 struct library_symbol **library_symbolspp,
Juan Cespedesf1350522008-12-16 18:19:58 +0100470 enum toplt type_of_plt, int is_weak) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100471 struct library_symbol *s;
Juan Cespedescd8976d2009-05-14 13:47:58 +0200472
473 debug(DEBUG_FUNCTION, "add_library_symbol()");
474
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100475 s = malloc(sizeof(struct library_symbol) + strlen(name) + 1);
476 if (s == NULL)
477 error(EXIT_FAILURE, errno, "add_library_symbol failed");
478
479 s->needs_init = 1;
480 s->is_weak = is_weak;
Paul Gilliam76c61f12006-06-14 06:55:21 +0200481 s->plt_type = type_of_plt;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100482 s->next = *library_symbolspp;
483 s->enter_addr = (void *)(uintptr_t) addr;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100484 s->name = (char *)(s + 1);
485 strcpy(s->name, name);
486 *library_symbolspp = s;
487
488 debug(2, "addr: %p, symbol: \"%s\"", (void *)(uintptr_t) addr, name);
Juan Cespedesd914a202004-11-10 00:15:33 +0100489}
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200490
Olaf Hering03c087b2006-09-25 02:31:27 +0200491/* stolen from elfutils-0.123 */
Juan Cespedesf1350522008-12-16 18:19:58 +0100492static unsigned long
493private_elf_gnu_hash(const char *name) {
Olaf Hering03c087b2006-09-25 02:31:27 +0200494 unsigned long h = 5381;
495 const unsigned char *string = (const unsigned char *)name;
496 unsigned char c;
497 for (c = *string; c; c = *++string)
498 h = h * 33 + c;
499 return h & 0xffffffff;
500}
501
Juan Cespedesf1350522008-12-16 18:19:58 +0100502static int
Joe Damato3268c5a2010-11-08 15:47:38 -0800503symbol_matches(struct ltelf *lte, size_t lte_i, GElf_Sym *sym,
504 size_t symidx, const char *name)
505{
506 GElf_Sym tmp_sym;
507 GElf_Sym *tmp;
508
509 tmp = (sym) ? (sym) : (&tmp_sym);
510
511 if (gelf_getsym(lte[lte_i].dynsym, symidx, tmp) == NULL)
512 error(EXIT_FAILURE, 0, "Couldn't get symbol from .dynsym");
513 else {
514 tmp->st_value += lte[lte_i].base_addr;
Zachary T Welchbfb26c72010-12-06 23:21:00 -0800515 debug(2, "symbol found: %s, %zd, %#" PRIx64,
Joe Damato3268c5a2010-11-08 15:47:38 -0800516 name, lte_i, tmp->st_value);
517 }
518 return tmp->st_value != 0
519 && tmp->st_shndx != SHN_UNDEF
520 && strcmp(name, lte[lte_i].dynstr + tmp->st_name) == 0;
521}
522
Joe Damato7a2bdf82010-11-08 15:47:41 -0800523int
Joe Damato3268c5a2010-11-08 15:47:38 -0800524in_load_libraries(const char *name, struct ltelf *lte, size_t count, GElf_Sym *sym) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100525 size_t i;
526 unsigned long hash;
Petr Machata35fe5182006-07-18 12:58:12 +0200527 unsigned long gnu_hash;
Juan Cespedesd914a202004-11-10 00:15:33 +0100528
Joe Damato3268c5a2010-11-08 15:47:38 -0800529 if (!count)
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100530 return 1;
Juan Cespedesd914a202004-11-10 00:15:33 +0100531
Paul Gilliam3f1219f2006-04-24 18:25:38 +0200532 hash = elf_hash((const unsigned char *)name);
Petr Machata07bc4d12006-11-30 14:47:40 +0100533 gnu_hash = private_elf_gnu_hash(name);
Joe Damato3268c5a2010-11-08 15:47:38 -0800534
535 for (i = 0; i < count; ++i) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100536 if (lte[i].hash == NULL)
537 continue;
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200538
Petr Machata35fe5182006-07-18 12:58:12 +0200539 if (lte[i].hash_type == SHT_GNU_HASH) {
540 Elf32_Word * hashbase = lte[i].hash;
541 Elf32_Word nbuckets = *hashbase++;
542 Elf32_Word symbias = *hashbase++;
543 Elf32_Word bitmask_nwords = *hashbase++;
Petr Machata35fe5182006-07-18 12:58:12 +0200544 Elf32_Word * buckets;
545 Elf32_Word * chain_zero;
546 Elf32_Word bucket;
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200547
Petr Machatab3f8fef2006-11-30 14:45:07 +0100548 // +1 for skipped `shift'
549 hashbase += lte[i].ehdr.e_ident[EI_CLASS] * bitmask_nwords + 1;
Petr Machata35fe5182006-07-18 12:58:12 +0200550 buckets = hashbase;
551 hashbase += nbuckets;
552 chain_zero = hashbase - symbias;
553 bucket = buckets[gnu_hash % nbuckets];
Juan Cespedesd914a202004-11-10 00:15:33 +0100554
Petr Machata35fe5182006-07-18 12:58:12 +0200555 if (bucket != 0) {
556 const Elf32_Word *hasharr = &chain_zero[bucket];
557 do
558 if ((*hasharr & ~1u) == (gnu_hash & ~1u)) {
559 int symidx = hasharr - chain_zero;
Joe Damato3268c5a2010-11-08 15:47:38 -0800560 if (symbol_matches(lte, i,
561 sym, symidx,
562 name))
Petr Machata35fe5182006-07-18 12:58:12 +0200563 return 1;
564 }
565 while ((*hasharr++ & 1u) == 0);
566 }
Olaf Hering03c087b2006-09-25 02:31:27 +0200567 } else {
Petr Machata35fe5182006-07-18 12:58:12 +0200568 Elf32_Word nbuckets, symndx;
569 Elf32_Word *buckets, *chain;
570 nbuckets = lte[i].hash[0];
571 buckets = &lte[i].hash[2];
572 chain = &lte[i].hash[2 + nbuckets];
573
574 for (symndx = buckets[hash % nbuckets];
Joe Damato3268c5a2010-11-08 15:47:38 -0800575 symndx != STN_UNDEF; symndx = chain[symndx])
576 if (symbol_matches(lte, i, sym, symndx, name))
Petr Machata35fe5182006-07-18 12:58:12 +0200577 return 1;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100578 }
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200579 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100580 return 0;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100581}
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200582
Juan Cespedesf1350522008-12-16 18:19:58 +0100583static GElf_Addr
584opd2addr(struct ltelf *lte, GElf_Addr addr) {
Petr Machatab3f8fef2006-11-30 14:45:07 +0100585#ifdef ARCH_SUPPORTS_OPD
Ian Wienand4bfcedd2006-08-07 04:03:15 +0200586 unsigned long base, offset;
Juan Cespedes1cd999a2001-07-03 00:46:04 +0200587
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100588 if (!lte->opd)
Ian Wienand4bfcedd2006-08-07 04:03:15 +0200589 return addr;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100590
Ian Wienand4bfcedd2006-08-07 04:03:15 +0200591 base = (unsigned long)lte->opd->d_buf;
592 offset = (unsigned long)addr - (unsigned long)lte->opd_addr;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100593 if (offset > lte->opd_size)
594 error(EXIT_FAILURE, 0, "static plt not in .opd");
595
Olaf Heringa841f652006-09-15 01:57:49 +0200596 return *(GElf_Addr*)(base + offset);
Petr Machatab3f8fef2006-11-30 14:45:07 +0100597#else //!ARCH_SUPPORTS_OPD
598 return addr;
599#endif
Ian Wienand9a2ad352006-02-20 22:44:45 +0100600}
601
Juan Cespedesf1350522008-12-16 18:19:58 +0100602struct library_symbol *
Juan Cespedesa8909f72009-04-28 20:02:41 +0200603read_elf(Process *proc) {
Juan Cespedes8d1b92b2009-07-03 10:39:34 +0200604 struct ltelf lte[MAX_LIBRARIES + 1];
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100605 size_t i;
Paul Gilliam24e643a2006-03-13 18:43:13 +0100606 struct opt_x_t *xptr;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100607 struct library_symbol **lib_tail = NULL;
Paul Gilliam24e643a2006-03-13 18:43:13 +0100608 int exit_out = 0;
Joe Damato3268c5a2010-11-08 15:47:38 -0800609 int count = 0;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100610
Juan Cespedescd8976d2009-05-14 13:47:58 +0200611 debug(DEBUG_FUNCTION, "read_elf(file=%s)", proc->filename);
612
Joe Damatof0bd98b2010-11-08 15:47:42 -0800613 memset(lte, 0, sizeof(*lte));
Joe Damato7a2bdf82010-11-08 15:47:41 -0800614 library_symbols = NULL;
615 library_num = 0;
Joe Damatof0bd98b2010-11-08 15:47:42 -0800616 proc->libdl_hooked = 0;
617
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100618 elf_version(EV_CURRENT);
Ian Wienand9a2ad352006-02-20 22:44:45 +0100619
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100620 do_init_elf(lte, proc->filename);
Joe Damatof0bd98b2010-11-08 15:47:42 -0800621
622 memcpy(&main_lte, lte, sizeof(struct ltelf));
623
624 if (opt_p && opt_p->pid > 0) {
625 linkmap_init(proc, lte);
626 proc->libdl_hooked = 1;
627 }
628
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100629 proc->e_machine = lte->ehdr.e_machine;
Joe Damatof0bd98b2010-11-08 15:47:42 -0800630
631 for (i = 0; i < library_num; ++i) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100632 do_init_elf(&lte[i + 1], library[i]);
Joe Damatof0bd98b2010-11-08 15:47:42 -0800633 }
Joe Damatofa2aefc2010-10-30 19:56:50 -0700634
635 if (!options.no_plt) {
Eric Vaitl1228a912006-12-28 16:16:56 +0100636#ifdef __mips__
Joe Damatofa2aefc2010-10-30 19:56:50 -0700637 // MIPS doesn't use the PLT and the GOT entries get changed
638 // on startup.
639 proc->need_to_reinitialize_breakpoints = 1;
640 for(i=lte->mips_gotsym; i<lte->dynsym_count;i++){
641 GElf_Sym sym;
642 const char *name;
643 GElf_Addr addr = arch_plt_sym_val(lte, i, 0);
644 if (gelf_getsym(lte->dynsym, i, &sym) == NULL){
645 error(EXIT_FAILURE, 0,
646 "Couldn't get relocation from \"%s\"",
647 proc->filename);
648 }
649 name=lte->dynstr+sym.st_name;
Arnaud Patard95623b22010-01-08 08:40:02 -0500650 if(ELF64_ST_TYPE(sym.st_info) != STT_FUNC){
651 debug(2,"sym %s not a function",name);
652 continue;
653 }
654 add_library_symbol(addr, name, &library_symbols, 0,
655 ELF64_ST_BIND(sym.st_info) != 0);
656 if (!lib_tail)
657 lib_tail = &(library_symbols->next);
Juan Cespedesa413e5b2007-09-04 17:34:53 +0200658 }
Eric Vaitl1228a912006-12-28 16:16:56 +0100659#else
Joe Damatofa2aefc2010-10-30 19:56:50 -0700660 for (i = 0; i < lte->relplt_count; ++i) {
661 GElf_Rel rel;
662 GElf_Rela rela;
663 GElf_Sym sym;
664 GElf_Addr addr;
665 void *ret;
666 const char *name;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100667
Joe Damatofa2aefc2010-10-30 19:56:50 -0700668 if (lte->relplt->d_type == ELF_T_REL) {
669 ret = gelf_getrel(lte->relplt, i, &rel);
670 rela.r_offset = rel.r_offset;
671 rela.r_info = rel.r_info;
672 rela.r_addend = 0;
673 } else
674 ret = gelf_getrela(lte->relplt, i, &rela);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100675
Joe Damatofa2aefc2010-10-30 19:56:50 -0700676 if (ret == NULL
677 || ELF64_R_SYM(rela.r_info) >= lte->dynsym_count
678 || gelf_getsym(lte->dynsym, ELF64_R_SYM(rela.r_info),
679 &sym) == NULL)
680 error(EXIT_FAILURE, 0,
681 "Couldn't get relocation from \"%s\"",
682 proc->filename);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100683
Paul Gilliambe320772006-04-24 22:06:23 +0200684#ifdef PLT_REINITALISATION_BP
Joe Damatofa2aefc2010-10-30 19:56:50 -0700685 if (!sym.st_value && PLTs_initialized_by_here)
686 proc->need_to_reinitialize_breakpoints = 1;
Paul Gilliambe320772006-04-24 22:06:23 +0200687#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100688
Joe Damato3268c5a2010-11-08 15:47:38 -0800689 name = lte->dynstr + sym.st_name;
690 count = library_num ? library_num+1 : 0;
Petr Machatafe1c1712010-10-27 16:57:34 +0200691
Joe Damato3268c5a2010-11-08 15:47:38 -0800692 if (in_load_libraries(name, lte, count, NULL)) {
693 enum toplt pltt;
694 if (sym.st_value == 0 && lte->plt_stub_vma != 0) {
695 pltt = LS_TOPLT_EXEC;
696 addr = lte->plt_stub_vma + PPC_PLT_STUB_SIZE * i;
697 }
698 else {
699 pltt = PLTS_ARE_EXECUTABLE(lte)
700 ? LS_TOPLT_EXEC : LS_TOPLT_POINT;
701 addr = arch_plt_sym_val(lte, i, &rela);
702 }
703
704 add_library_symbol(addr, name, &library_symbols, pltt,
705 ELF64_ST_BIND(sym.st_info) == STB_WEAK);
706 if (!lib_tail)
707 lib_tail = &(library_symbols->next);
Joe Damatofa2aefc2010-10-30 19:56:50 -0700708 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100709 }
Eric Vaitl1228a912006-12-28 16:16:56 +0100710#endif // !__mips__
Paul Gilliambe320772006-04-24 22:06:23 +0200711#ifdef PLT_REINITALISATION_BP
Joe Damatofa2aefc2010-10-30 19:56:50 -0700712 struct opt_x_t *main_cheat;
Ian Wienand4bfcedd2006-08-07 04:03:15 +0200713
Joe Damatofa2aefc2010-10-30 19:56:50 -0700714 if (proc->need_to_reinitialize_breakpoints) {
715 /* Add "PLTs_initialized_by_here" to opt_x list, if not
716 already there. */
717 main_cheat = (struct opt_x_t *)malloc(sizeof(struct opt_x_t));
718 if (main_cheat == NULL)
719 error(EXIT_FAILURE, 0, "Couldn't allocate memory");
720 main_cheat->next = opt_x;
721 main_cheat->found = 0;
722 main_cheat->name = PLTs_initialized_by_here;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100723
Joe Damatofa2aefc2010-10-30 19:56:50 -0700724 for (xptr = opt_x; xptr; xptr = xptr->next)
725 if (strcmp(xptr->name, PLTs_initialized_by_here) == 0
726 && main_cheat) {
727 free(main_cheat);
728 main_cheat = NULL;
729 break;
730 }
731 if (main_cheat)
732 opt_x = main_cheat;
733 }
Paul Gilliambe320772006-04-24 22:06:23 +0200734#endif
Joe Damatofa2aefc2010-10-30 19:56:50 -0700735 } else {
736 lib_tail = &library_symbols;
737 }
Ian Wienand9a2ad352006-02-20 22:44:45 +0100738
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100739 for (i = 0; i < lte->symtab_count; ++i) {
740 GElf_Sym sym;
741 GElf_Addr addr;
742 const char *name;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100743
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100744 if (gelf_getsym(lte->symtab, i, &sym) == NULL)
745 error(EXIT_FAILURE, 0,
746 "Couldn't get symbol from \"%s\"",
747 proc->filename);
Ian Wienand9a2ad352006-02-20 22:44:45 +0100748
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100749 name = lte->strtab + sym.st_name;
750 addr = sym.st_value;
751 if (!addr)
752 continue;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100753
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100754 for (xptr = opt_x; xptr; xptr = xptr->next)
755 if (xptr->name && strcmp(xptr->name, name) == 0) {
756 /* FIXME: Should be able to use &library_symbols as above. But
757 when you do, none of the real library symbols cause breaks. */
Ian Wienand4bfcedd2006-08-07 04:03:15 +0200758 add_library_symbol(opd2addr(lte, addr),
Paul Gilliam76c61f12006-06-14 06:55:21 +0200759 name, lib_tail, LS_TOPLT_NONE, 0);
Paul Gilliam24e643a2006-03-13 18:43:13 +0100760 xptr->found = 1;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100761 break;
762 }
763 }
Joe Damatoe2a8f572010-11-08 15:47:40 -0800764
Zachary T Welchba6aca22010-12-08 18:55:09 -0800765 unsigned found_count = 0;
Joe Damatoe2a8f572010-11-08 15:47:40 -0800766
767 for (xptr = opt_x; xptr; xptr = xptr->next) {
768 if (xptr->found)
769 continue;
770
771 GElf_Sym sym;
772 GElf_Addr addr;
773 if (in_load_libraries(xptr->name, lte, library_num+1, &sym)) {
Zachary T Welchbfb26c72010-12-06 23:21:00 -0800774 debug(2, "found symbol %s @ %#" PRIx64 ", adding it.",
775 xptr->name, sym.st_value);
Joe Damatoe2a8f572010-11-08 15:47:40 -0800776 addr = sym.st_value;
777 if (ELF32_ST_TYPE (sym.st_info) == STT_FUNC) {
778 add_library_symbol(addr, xptr->name, lib_tail, LS_TOPLT_NONE, 0);
779 xptr->found = 1;
780 found_count++;
781 }
782 }
783 if (found_count == opt_x_cnt){
784 debug(2, "done, found everything: %d\n", found_count);
785 break;
786 }
787 }
788
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100789 for (xptr = opt_x; xptr; xptr = xptr->next)
Paul Gilliam24e643a2006-03-13 18:43:13 +0100790 if ( ! xptr->found) {
791 char *badthing = "WARNING";
Paul Gilliambe320772006-04-24 22:06:23 +0200792#ifdef PLT_REINITALISATION_BP
793 if (strcmp(xptr->name, PLTs_initialized_by_here) == 0) {
794 if (lte->ehdr.e_entry) {
795 add_library_symbol (
Ian Wienand4bfcedd2006-08-07 04:03:15 +0200796 opd2addr (lte, lte->ehdr.e_entry),
Paul Gilliambe320772006-04-24 22:06:23 +0200797 PLTs_initialized_by_here,
798 lib_tail, 1, 0);
799 fprintf (stderr, "WARNING: Using e_ent"
800 "ry from elf header (%p) for "
801 "address of \"%s\"\n", (void*)
802 (long) lte->ehdr.e_entry,
803 PLTs_initialized_by_here);
804 continue;
805 }
Paul Gilliam24e643a2006-03-13 18:43:13 +0100806 badthing = "ERROR";
807 exit_out = 1;
808 }
Paul Gilliambe320772006-04-24 22:06:23 +0200809#endif
Paul Gilliam24e643a2006-03-13 18:43:13 +0100810 fprintf (stderr,
Joe Damatof0bd98b2010-11-08 15:47:42 -0800811 "%s: Couldn't find symbol \"%s\" in file \"%s\" assuming it will be loaded by libdl!"
812 "\n", badthing, xptr->name, proc->filename);
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100813 }
Paul Gilliam24e643a2006-03-13 18:43:13 +0100814 if (exit_out) {
815 exit (1);
816 }
Ian Wienand9a2ad352006-02-20 22:44:45 +0100817
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100818 for (i = 0; i < library_num + 1; ++i)
819 do_close_elf(&lte[i]);
Ian Wienand9a2ad352006-02-20 22:44:45 +0100820
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100821 return library_symbols;
Juan Cespedes96935a91997-08-09 23:45:39 +0200822}