Annotation of src/usr.bin/nm/elf.c, Revision 1.36
1.36 ! deraadt 1: /* $OpenBSD: elf.c,v 1.35 2017/10/27 16:47:08 mpi Exp $ */
1.1 mickey 2:
3: /*
4: * Copyright (c) 2003 Michael Shalayeff
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: *
16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19: * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22: * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25: * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26: * THE POSSIBILITY OF SUCH DAMAGE.
27: */
28:
1.10 mickey 29: #include <sys/mman.h>
30: #include <unistd.h>
31: #include <a.out.h>
1.35 mpi 32: #include <elf.h>
1.10 mickey 33: #include <errno.h>
34: #include <err.h>
1.26 millert 35: #include <stdint.h>
1.10 mickey 36: #include <stdio.h>
37: #include <stdlib.h>
38: #include <string.h>
39: #include <ctype.h>
1.33 miod 40: #include "util.h"
1.10 mickey 41: #include "elfuncs.h"
42:
43: #if ELFSIZE == 32
1.1 mickey 44: #define swap_addr swap32
45: #define swap_off swap32
46: #define swap_sword swap32
47: #define swap_word swap32
48: #define swap_sxword swap32
49: #define swap_xword swap32
50: #define swap_half swap16
51: #define swap_quarter swap16
1.10 mickey 52: #define elf_fix_header elf32_fix_header
53: #define elf_load_shdrs elf32_load_shdrs
1.13 grange 54: #define elf_load_phdrs elf32_load_phdrs
1.10 mickey 55: #define elf_fix_shdrs elf32_fix_shdrs
56: #define elf_fix_phdrs elf32_fix_phdrs
57: #define elf_fix_sym elf32_fix_sym
58: #define elf_size elf32_size
1.14 kettenis 59: #define elf_symloadx elf32_symloadx
1.10 mickey 60: #define elf_symload elf32_symload
61: #define elf2nlist elf32_2nlist
62: #define elf_shn2type elf32_shn2type
63: #elif ELFSIZE == 64
1.1 mickey 64: #define swap_addr swap64
65: #define swap_off swap64
66: #ifdef __alpha__
67: #define swap_sword swap64
68: #define swap_word swap64
69: #else
70: #define swap_sword swap32
71: #define swap_word swap32
72: #endif
73: #define swap_sxword swap64
74: #define swap_xword swap64
75: #define swap_half swap64
76: #define swap_quarter swap16
1.10 mickey 77: #define elf_fix_header elf64_fix_header
78: #define elf_load_shdrs elf64_load_shdrs
1.13 grange 79: #define elf_load_phdrs elf64_load_phdrs
1.10 mickey 80: #define elf_fix_shdrs elf64_fix_shdrs
81: #define elf_fix_phdrs elf64_fix_phdrs
82: #define elf_fix_sym elf64_fix_sym
83: #define elf_size elf64_size
1.14 kettenis 84: #define elf_symloadx elf64_symloadx
1.10 mickey 85: #define elf_symload elf64_symload
86: #define elf2nlist elf64_2nlist
87: #define elf_shn2type elf64_shn2type
1.1 mickey 88: #else
89: #error "Unsupported ELF class"
90: #endif
91:
1.9 mickey 92: #define ELF_SDATA ".sdata"
1.20 uwe 93: #define ELF_TDATA ".tdata"
1.3 mickey 94: #define ELF_SBSS ".sbss"
1.20 uwe 95: #define ELF_TBSS ".tbss"
1.6 mickey 96: #define ELF_PLT ".plt"
1.3 mickey 97:
1.11 mickey 98: #ifndef SHN_MIPS_ACOMMON
99: #define SHN_MIPS_ACOMMON SHN_LOPROC + 0
100: #endif
101: #ifndef SHN_MIPS_TEXT
102: #define SHN_MIPS_TEXT SHN_LOPROC + 1
103: #endif
104: #ifndef SHN_MIPS_DATA
105: #define SHN_MIPS_DATA SHN_LOPROC + 2
106: #endif
107: #ifndef SHN_MIPS_SUNDEFINED
108: #define SHN_MIPS_SUNDEFINED SHN_LOPROC + 4
109: #endif
110: #ifndef SHN_MIPS_SCOMMON
111: #define SHN_MIPS_SCOMMON SHN_LOPROC + 3
112: #endif
113:
114: #ifndef STT_PARISC_MILLI
115: #define STT_PARISC_MILLI STT_LOPROC + 0
116: #endif
117:
1.22 deraadt 118: int elf_shn2type(Elf_Ehdr *, u_int, const char *);
1.33 miod 119: int elf2nlist(Elf_Sym *, Elf_Ehdr *, Elf_Shdr *, char *, struct xnlist *);
1.22 deraadt 120:
1.1 mickey 121: int
122: elf_fix_header(Elf_Ehdr *eh)
123: {
124: /* nothing to do */
125: if (eh->e_ident[EI_DATA] == ELF_TARG_DATA)
126: return (0);
127:
128: eh->e_type = swap16(eh->e_type);
129: eh->e_machine = swap16(eh->e_machine);
130: eh->e_version = swap32(eh->e_version);
131: eh->e_entry = swap_addr(eh->e_entry);
132: eh->e_phoff = swap_off(eh->e_phoff);
133: eh->e_shoff = swap_off(eh->e_shoff);
134: eh->e_flags = swap32(eh->e_flags);
135: eh->e_ehsize = swap16(eh->e_ehsize);
136: eh->e_phentsize = swap16(eh->e_phentsize);
137: eh->e_phnum = swap16(eh->e_phnum);
138: eh->e_shentsize = swap16(eh->e_shentsize);
139: eh->e_shnum = swap16(eh->e_shnum);
140: eh->e_shstrndx = swap16(eh->e_shstrndx);
141:
142: return (1);
143: }
144:
1.10 mickey 145: Elf_Shdr *
146: elf_load_shdrs(const char *name, FILE *fp, off_t foff, Elf_Ehdr *head)
147: {
148: Elf_Shdr *shdr;
149:
150: elf_fix_header(head);
1.29 semarie 151:
152: if (head->e_shnum == 0) {
153: warnx("%s: no section header table", name);
154: return (NULL);
155: }
156:
157: if (head->e_shstrndx >= head->e_shnum) {
158: warnx("%s: inconsistent section header table", name);
159: return (NULL);
160: }
1.10 mickey 161:
1.31 semarie 162: if (head->e_shentsize < sizeof(Elf_Shdr)) {
163: warnx("%s: inconsistent section header size", name);
164: return (NULL);
165: }
166:
167: if ((shdr = calloc(head->e_shnum, head->e_shentsize)) == NULL) {
1.10 mickey 168: warn("%s: malloc shdr", name);
169: return (NULL);
170: }
171:
172: if (fseeko(fp, foff + head->e_shoff, SEEK_SET)) {
173: warn("%s: fseeko", name);
174: free(shdr);
175: return (NULL);
176: }
177:
178: if (fread(shdr, head->e_shentsize, head->e_shnum, fp) != head->e_shnum) {
179: warnx("%s: premature EOF", name);
180: free(shdr);
181: return (NULL);
182: }
183:
184: elf_fix_shdrs(head, shdr);
185: return (shdr);
1.13 grange 186: }
187:
188: Elf_Phdr *
189: elf_load_phdrs(const char *name, FILE *fp, off_t foff, Elf_Ehdr *head)
190: {
191: Elf_Phdr *phdr;
192:
1.18 deraadt 193: if ((phdr = calloc(head->e_phentsize, head->e_phnum)) == NULL) {
1.13 grange 194: warn("%s: malloc phdr", name);
195: return (NULL);
196: }
197:
198: if (fseeko(fp, foff + head->e_phoff, SEEK_SET)) {
199: warn("%s: fseeko", name);
200: free(phdr);
201: return (NULL);
202: }
203:
204: if (fread(phdr, head->e_phentsize, head->e_phnum, fp) != head->e_phnum) {
205: warnx("%s: premature EOF", name);
206: free(phdr);
207: return (NULL);
208: }
209:
210: elf_fix_phdrs(head, phdr);
211: return (phdr);
1.10 mickey 212: }
213:
1.1 mickey 214: int
215: elf_fix_shdrs(Elf_Ehdr *eh, Elf_Shdr *shdr)
216: {
217: int i;
218:
219: /* nothing to do */
220: if (eh->e_ident[EI_DATA] == ELF_TARG_DATA)
221: return (0);
222:
223: for (i = eh->e_shnum; i--; shdr++) {
224: shdr->sh_name = swap32(shdr->sh_name);
225: shdr->sh_type = swap32(shdr->sh_type);
226: shdr->sh_flags = swap_xword(shdr->sh_flags);
227: shdr->sh_addr = swap_addr(shdr->sh_addr);
228: shdr->sh_offset = swap_off(shdr->sh_offset);
229: shdr->sh_size = swap_xword(shdr->sh_size);
230: shdr->sh_link = swap32(shdr->sh_link);
231: shdr->sh_info = swap32(shdr->sh_info);
232: shdr->sh_addralign = swap_xword(shdr->sh_addralign);
233: shdr->sh_entsize = swap_xword(shdr->sh_entsize);
234: }
235:
236: return (1);
237: }
238:
239: int
240: elf_fix_phdrs(Elf_Ehdr *eh, Elf_Phdr *phdr)
241: {
242: int i;
243:
244: /* nothing to do */
245: if (eh->e_ident[EI_DATA] == ELF_TARG_DATA)
246: return (0);
247:
248: for (i = eh->e_phnum; i--; phdr++) {
249: phdr->p_type = swap32(phdr->p_type);
250: phdr->p_flags = swap32(phdr->p_flags);
251: phdr->p_offset = swap_off(phdr->p_offset);
252: phdr->p_vaddr = swap_addr(phdr->p_vaddr);
253: phdr->p_paddr = swap_addr(phdr->p_paddr);
254: phdr->p_filesz = swap_xword(phdr->p_filesz);
255: phdr->p_memsz = swap_xword(phdr->p_memsz);
256: phdr->p_align = swap_xword(phdr->p_align);
257: }
258:
259: return (1);
260: }
261:
262: int
263: elf_fix_sym(Elf_Ehdr *eh, Elf_Sym *sym)
264: {
265: /* nothing to do */
266: if (eh->e_ident[EI_DATA] == ELF_TARG_DATA)
267: return (0);
268:
269: sym->st_name = swap32(sym->st_name);
270: sym->st_shndx = swap16(sym->st_shndx);
271: sym->st_value = swap_addr(sym->st_value);
272: sym->st_size = swap_xword(sym->st_size);
273:
274: return (1);
275: }
276:
1.9 mickey 277: int
1.11 mickey 278: elf_shn2type(Elf_Ehdr *eh, u_int shn, const char *sn)
1.9 mickey 279: {
280: switch (shn) {
281: case SHN_MIPS_SUNDEFINED:
1.11 mickey 282: if (eh->e_machine == EM_MIPS)
283: return (N_UNDF | N_EXT);
284: break;
285:
1.9 mickey 286: case SHN_UNDEF:
287: return (N_UNDF | N_EXT);
1.11 mickey 288:
1.9 mickey 289: case SHN_ABS:
290: return (N_ABS);
1.11 mickey 291:
1.9 mickey 292: case SHN_MIPS_ACOMMON:
1.11 mickey 293: if (eh->e_machine == EM_MIPS)
294: return (N_COMM);
295: break;
296:
1.9 mickey 297: case SHN_MIPS_SCOMMON:
1.11 mickey 298: if (eh->e_machine == EM_MIPS)
299: return (N_COMM);
300: break;
301:
1.9 mickey 302: case SHN_COMMON:
303: return (N_COMM);
1.11 mickey 304:
1.9 mickey 305: case SHN_MIPS_TEXT:
1.11 mickey 306: if (eh->e_machine == EM_MIPS)
307: return (N_TEXT);
308: break;
309:
1.9 mickey 310: case SHN_MIPS_DATA:
1.11 mickey 311: if (eh->e_machine == EM_MIPS)
312: return (N_DATA);
313: break;
314:
1.9 mickey 315: default:
1.20 uwe 316: /* TODO: beyond 8 a table-driven binsearch should be used */
1.9 mickey 317: if (sn == NULL)
318: return (-1);
319: else if (!strcmp(sn, ELF_TEXT))
320: return (N_TEXT);
321: else if (!strcmp(sn, ELF_RODATA))
1.36 ! deraadt 322: return (N_SIZE);
! 323: else if (!strcmp(sn, ELF_OPENBSDRANDOMDATA))
1.9 mickey 324: return (N_SIZE);
325: else if (!strcmp(sn, ELF_DATA))
326: return (N_DATA);
327: else if (!strcmp(sn, ELF_SDATA))
328: return (N_DATA);
1.20 uwe 329: else if (!strcmp(sn, ELF_TDATA))
330: return (N_DATA);
1.9 mickey 331: else if (!strcmp(sn, ELF_BSS))
332: return (N_BSS);
333: else if (!strcmp(sn, ELF_SBSS))
334: return (N_BSS);
1.20 uwe 335: else if (!strcmp(sn, ELF_TBSS))
336: return (N_BSS);
1.9 mickey 337: else if (!strncmp(sn, ELF_GOT, sizeof(ELF_GOT) - 1))
338: return (N_DATA);
339: else if (!strncmp(sn, ELF_PLT, sizeof(ELF_PLT) - 1))
340: return (N_DATA);
341: }
1.11 mickey 342:
343: return (-1);
1.9 mickey 344: }
345:
1.1 mickey 346: /*
1.33 miod 347: * Devise xnlist's type from Elf_Sym.
1.1 mickey 348: * XXX this task is done as well in libc and kvm_mkdb.
349: */
350: int
1.33 miod 351: elf2nlist(Elf_Sym *sym, Elf_Ehdr *eh, Elf_Shdr *shdr, char *shstr,
352: struct xnlist *np)
1.1 mickey 353: {
1.9 mickey 354: u_char stt;
1.1 mickey 355: const char *sn;
1.9 mickey 356: int type;
1.1 mickey 357:
358: if (sym->st_shndx < eh->e_shnum)
359: sn = shstr + shdr[sym->st_shndx].sh_name;
360: else
1.9 mickey 361: sn = NULL;
1.6 mickey 362: #if 0
363: {
364: extern char *stab;
1.21 miod 365: printf("%d:%s %d %d %s\n", sym->st_shndx, sn? sn : "",
366: ELF_ST_TYPE(sym->st_info), ELF_ST_BIND(sym->st_info),
367: stab + sym->st_name);
1.6 mickey 368: }
369: #endif
1.9 mickey 370:
371: switch (stt = ELF_ST_TYPE(sym->st_info)) {
1.1 mickey 372: case STT_NOTYPE:
1.9 mickey 373: case STT_OBJECT:
1.20 uwe 374: case STT_TLS:
1.11 mickey 375: type = elf_shn2type(eh, sym->st_shndx, sn);
1.9 mickey 376: if (type < 0) {
377: if (sn == NULL)
1.33 miod 378: np->nl.n_other = '?';
1.9 mickey 379: else
1.33 miod 380: np->nl.n_type = stt == STT_NOTYPE ?
381: N_COMM : N_DATA;
1.9 mickey 382: } else {
383: /* a hack for .rodata check (; */
384: if (type == N_SIZE) {
1.33 miod 385: np->nl.n_type = N_DATA;
386: np->nl.n_other = 'r';
1.9 mickey 387: } else
1.33 miod 388: np->nl.n_type = type;
1.8 mickey 389: }
1.21 miod 390: if (ELF_ST_BIND(sym->st_info) == STB_WEAK)
1.33 miod 391: np->nl.n_other = 'W';
1.8 mickey 392: break;
393:
1.1 mickey 394: case STT_FUNC:
1.11 mickey 395: type = elf_shn2type(eh, sym->st_shndx, NULL);
1.33 miod 396: np->nl.n_type = type < 0? N_TEXT : type;
1.1 mickey 397: if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
1.33 miod 398: np->nl.n_other = 'W';
1.14 kettenis 399: } else if (sn != NULL && *sn != 0 &&
1.9 mickey 400: strcmp(sn, ELF_INIT) &&
1.6 mickey 401: strcmp(sn, ELF_TEXT) &&
402: strcmp(sn, ELF_FINI)) /* XXX GNU compat */
1.33 miod 403: np->nl.n_other = '?';
1.1 mickey 404: break;
405:
1.8 mickey 406: case STT_SECTION:
1.11 mickey 407: type = elf_shn2type(eh, sym->st_shndx, NULL);
1.9 mickey 408: if (type < 0)
1.33 miod 409: np->nl.n_other = '?';
1.9 mickey 410: else
1.33 miod 411: np->nl.n_type = type;
1.1 mickey 412: break;
413:
414: case STT_FILE:
1.33 miod 415: np->nl.n_type = N_FN | N_EXT;
1.1 mickey 416: break;
417:
418: case STT_PARISC_MILLI:
1.11 mickey 419: if (eh->e_machine == EM_PARISC)
1.33 miod 420: np->nl.n_type = N_TEXT;
1.11 mickey 421: else
1.33 miod 422: np->nl.n_other = '?';
1.1 mickey 423: break;
1.11 mickey 424:
1.1 mickey 425: default:
1.33 miod 426: np->nl.n_other = '?';
1.1 mickey 427: break;
428: }
1.33 miod 429: if (np->nl.n_type != N_UNDF && ELF_ST_BIND(sym->st_info) != STB_LOCAL) {
430: np->nl.n_type |= N_EXT;
431: if (np->nl.n_other)
432: np->nl.n_other = toupper((unsigned char)np->nl.n_other);
1.10 mickey 433: }
434:
435: return (0);
436: }
437:
438: int
439: elf_size(Elf_Ehdr *head, Elf_Shdr *shdr,
440: u_long *ptext, u_long *pdata, u_long *pbss)
441: {
442: int i;
443:
444: *ptext = *pdata = *pbss = 0;
445:
446: for (i = 0; i < head->e_shnum; i++) {
447: if (!(shdr[i].sh_flags & SHF_ALLOC))
448: ;
449: else if (shdr[i].sh_flags & SHF_EXECINSTR ||
450: !(shdr[i].sh_flags & SHF_WRITE))
451: *ptext += shdr[i].sh_size;
452: else if (shdr[i].sh_type == SHT_NOBITS)
453: *pbss += shdr[i].sh_size;
454: else
455: *pdata += shdr[i].sh_size;
456: }
457:
458: return (0);
459: }
460:
461: int
1.14 kettenis 462: elf_symloadx(const char *name, FILE *fp, off_t foff, Elf_Ehdr *eh,
1.33 miod 463: Elf_Shdr *shdr, char *shstr, long shstrsize, struct xnlist **pnames,
464: struct xnlist ***psnames, size_t *pstabsize, int *pnrawnames,
1.14 kettenis 465: const char *strtab, const char *symtab)
1.10 mickey 466: {
1.14 kettenis 467: long symsize;
1.33 miod 468: struct xnlist *np;
1.10 mickey 469: Elf_Sym sbuf;
470: int i;
471:
472: for (i = 0; i < eh->e_shnum; i++) {
1.30 semarie 473: if (shdr[i].sh_name >= shstrsize) {
474: warnx("%s: corrupt file", name);
475: return (1);
476: }
1.14 kettenis 477: if (!strcmp(shstr + shdr[i].sh_name, strtab)) {
1.10 mickey 478: *pstabsize = shdr[i].sh_size;
1.26 millert 479: if (*pstabsize > SIZE_MAX) {
1.10 mickey 480: warnx("%s: corrupt file", name);
481: return (1);
482: }
483:
484: MMAP(stab, *pstabsize, PROT_READ, MAP_PRIVATE|MAP_FILE,
485: fileno(fp), foff + shdr[i].sh_offset);
1.16 ray 486: if (stab == MAP_FAILED)
1.10 mickey 487: return (1);
488: }
489: }
490: for (i = 0; i < eh->e_shnum; i++) {
1.14 kettenis 491: if (!strcmp(shstr + shdr[i].sh_name, symtab)) {
1.10 mickey 492: symsize = shdr[i].sh_size;
493: if (fseeko(fp, foff + shdr[i].sh_offset, SEEK_SET)) {
494: warn("%s: fseeko", name);
495: if (stab)
496: MUNMAP(stab, *pstabsize);
497: return (1);
498: }
499:
500: *pnrawnames = symsize / sizeof(sbuf);
501: if ((*pnames = calloc(*pnrawnames, sizeof(*np))) == NULL) {
502: warn("%s: malloc names", name);
503: if (stab)
504: MUNMAP(stab, *pstabsize);
1.32 semarie 505: *pnrawnames = 0;
1.10 mickey 506: return (1);
507: }
1.18 deraadt 508: if ((*psnames = calloc(*pnrawnames, sizeof(np))) == NULL) {
1.10 mickey 509: warn("%s: malloc snames", name);
510: if (stab)
511: MUNMAP(stab, *pstabsize);
512: free(*pnames);
1.32 semarie 513: *pnames = NULL;
514: *pnrawnames = 0;
1.10 mickey 515: return (1);
516: }
517:
518: for (np = *pnames; symsize > 0; symsize -= sizeof(sbuf)) {
519: if (fread(&sbuf, 1, sizeof(sbuf),
520: fp) != sizeof(sbuf)) {
521: warn("%s: read symbol", name);
522: if (stab)
523: MUNMAP(stab, *pstabsize);
524: free(*pnames);
525: free(*psnames);
1.32 semarie 526: *pnames = NULL;
527: *psnames = NULL;
528: *pnrawnames = 0;
1.10 mickey 529: return (1);
530: }
531:
532: elf_fix_sym(eh, &sbuf);
533:
1.15 mickey 534: if (!sbuf.st_name ||
535: sbuf.st_name > *pstabsize)
1.10 mickey 536: continue;
537:
538: elf2nlist(&sbuf, eh, shdr, shstr, np);
1.33 miod 539: np->nl.n_value = sbuf.st_value;
540: np->nl.n_un.n_strx = sbuf.st_name;
541: np->n_size = sbuf.st_size;
1.10 mickey 542: np++;
543: }
544: *pnrawnames = np - *pnames;
545: }
1.14 kettenis 546: }
1.22 deraadt 547: return (0);
1.14 kettenis 548: }
549:
550: int
551: elf_symload(const char *name, FILE *fp, off_t foff, Elf_Ehdr *eh,
1.33 miod 552: Elf_Shdr *shdr, struct xnlist **pnames, struct xnlist ***psnames,
1.14 kettenis 553: size_t *pstabsize, int *pnrawnames)
554: {
555: long shstrsize;
556: char *shstr;
557:
558: shstrsize = shdr[eh->e_shstrndx].sh_size;
1.17 miod 559: if (shstrsize == 0) {
560: warnx("%s: no name list", name);
561: return (1);
562: }
563:
1.14 kettenis 564: if ((shstr = malloc(shstrsize)) == NULL) {
565: warn("%s: malloc shsrt", name);
566: return (1);
567: }
568:
569: if (fseeko(fp, foff + shdr[eh->e_shstrndx].sh_offset, SEEK_SET)) {
570: warn("%s: fseeko", name);
571: free(shstr);
572: return (1);
573: }
574:
575: if (fread(shstr, 1, shstrsize, fp) != shstrsize) {
576: warnx("%s: premature EOF", name);
577: free(shstr);
578: return(1);
579: }
580:
581: stab = NULL;
1.25 miod 582: *pnames = NULL; *psnames = NULL; *pnrawnames = 0;
1.28 guenther 583: if (!dynamic_only) {
1.30 semarie 584: elf_symloadx(name, fp, foff, eh, shdr, shstr, shstrsize, pnames,
1.28 guenther 585: psnames, pstabsize, pnrawnames, ELF_STRTAB, ELF_SYMTAB);
586: }
1.14 kettenis 587: if (stab == NULL) {
1.30 semarie 588: elf_symloadx(name, fp, foff, eh, shdr, shstr, shstrsize, pnames,
1.14 kettenis 589: psnames, pstabsize, pnrawnames, ELF_DYNSTR, ELF_DYNSYM);
1.10 mickey 590: }
591:
592: free(shstr);
593: if (stab == NULL) {
594: warnx("%s: no name list", name);
1.34 mmcc 595: free(*pnames);
596: free(*psnames);
1.10 mickey 597: return (1);
1.1 mickey 598: }
599:
600: return (0);
601: }