Deleted Added
sdiff udiff text old ( 289071 ) new ( 295577 )
full compact
1/*-
2 * Copyright (c) 2007-2012 Kai Wang
3 * Copyright (c) 2003 David O'Brien. All rights reserved.
4 * Copyright (c) 2001 Jake Burkholder
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

--- 36 unchanged lines hidden (view full) ---

45
46#ifdef USE_LIBARCHIVE_AR
47#include <archive.h>
48#include <archive_entry.h>
49#endif
50
51#include "_elftc.h"
52
53ELFTC_VCSID("$Id: elfdump.c 3250 2015-10-06 13:56:15Z emaste $");
54
55#if defined(ELFTC_NEED_ELF_NOTE_DEFINITION)
56#include "native-elf-format.h"
57#if ELFTC_CLASS == ELFCLASS32
58typedef Elf32_Nhdr Elf_Note;
59#else
60typedef Elf64_Nhdr Elf_Note;
61#endif

--- 88 unchanged lines hidden (view full) ---

150 return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
151}
152#endif
153
154/* http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#tag_encodings */
155static const char *
156d_tags(uint64_t tag)
157{
158 switch (tag) {
159 case 0: return "DT_NULL";
160 case 1: return "DT_NEEDED";
161 case 2: return "DT_PLTRELSZ";
162 case 3: return "DT_PLTGOT";
163 case 4: return "DT_HASH";
164 case 5: return "DT_STRTAB";
165 case 6: return "DT_SYMTAB";
166 case 7: return "DT_RELA";
167 case 8: return "DT_RELASZ";
168 case 9: return "DT_RELAENT";
169 case 10: return "DT_STRSZ";
170 case 11: return "DT_SYMENT";
171 case 12: return "DT_INIT";
172 case 13: return "DT_FINI";
173 case 14: return "DT_SONAME";
174 case 15: return "DT_RPATH";
175 case 16: return "DT_SYMBOLIC";
176 case 17: return "DT_REL";
177 case 18: return "DT_RELSZ";
178 case 19: return "DT_RELENT";
179 case 20: return "DT_PLTREL";
180 case 21: return "DT_DEBUG";
181 case 22: return "DT_TEXTREL";
182 case 23: return "DT_JMPREL";
183 case 24: return "DT_BIND_NOW";
184 case 25: return "DT_INIT_ARRAY";
185 case 26: return "DT_FINI_ARRAY";
186 case 27: return "DT_INIT_ARRAYSZ";
187 case 28: return "DT_FINI_ARRAYSZ";
188 case 29: return "DT_RUNPATH";
189 case 30: return "DT_FLAGS";
190 case 32: return "DT_PREINIT_ARRAY"; /* XXX: DT_ENCODING */
191 case 33: return "DT_PREINIT_ARRAYSZ";
192 /* 0x6000000D - 0x6ffff000 operating system-specific semantics */
193 case 0x6ffffdf5: return "DT_GNU_PRELINKED";
194 case 0x6ffffdf6: return "DT_GNU_CONFLICTSZ";
195 case 0x6ffffdf7: return "DT_GNU_LIBLISTSZ";
196 case 0x6ffffdf8: return "DT_SUNW_CHECKSUM";
197 case 0x6ffffdf9: return "DT_PLTPADSZ";
198 case 0x6ffffdfa: return "DT_MOVEENT";
199 case 0x6ffffdfb: return "DT_MOVESZ";
200 case 0x6ffffdfc: return "DT_FEATURE";
201 case 0x6ffffdfd: return "DT_POSFLAG_1";
202 case 0x6ffffdfe: return "DT_SYMINSZ";
203 case 0x6ffffdff: return "DT_SYMINENT (DT_VALRNGHI)";
204 case 0x6ffffe00: return "DT_ADDRRNGLO";
205 case 0x6ffffef5: return "DT_GNU_HASH";
206 case 0x6ffffef8: return "DT_GNU_CONFLICT";
207 case 0x6ffffef9: return "DT_GNU_LIBLIST";
208 case 0x6ffffefa: return "DT_CONFIG";
209 case 0x6ffffefb: return "DT_DEPAUDIT";
210 case 0x6ffffefc: return "DT_AUDIT";
211 case 0x6ffffefd: return "DT_PLTPAD";
212 case 0x6ffffefe: return "DT_MOVETAB";
213 case 0x6ffffeff: return "DT_SYMINFO (DT_ADDRRNGHI)";
214 case 0x6ffffff9: return "DT_RELACOUNT";
215 case 0x6ffffffa: return "DT_RELCOUNT";
216 case 0x6ffffffb: return "DT_FLAGS_1";
217 case 0x6ffffffc: return "DT_VERDEF";
218 case 0x6ffffffd: return "DT_VERDEFNUM";
219 case 0x6ffffffe: return "DT_VERNEED";
220 case 0x6fffffff: return "DT_VERNEEDNUM";
221 case 0x6ffffff0: return "DT_GNU_VERSYM";
222 /* 0x70000000 - 0x7fffffff processor-specific semantics */
223 case 0x70000000: return "DT_IA_64_PLT_RESERVE";
224 case 0x7ffffffd: return "DT_SUNW_AUXILIARY";
225 case 0x7ffffffe: return "DT_SUNW_USED";
226 case 0x7fffffff: return "DT_SUNW_FILTER";
227 default: return "ERROR: TAG NOT DEFINED";
228 }
229}
230
231static const char *
232e_machines(unsigned int mach)
233{
234 static char machdesc[64];
235
236 switch (mach) {

--- 71 unchanged lines hidden (view full) ---

308 snprintf(num, sizeof(num), "%d", ndx);
309 return (num);
310 }
311 }
312}
313
314/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html#sh_type */
315static const char *
316sh_types(u_int64_t sht) {
317 switch (sht) {
318 case 0: return "SHT_NULL";
319 case 1: return "SHT_PROGBITS";
320 case 2: return "SHT_SYMTAB";
321 case 3: return "SHT_STRTAB";
322 case 4: return "SHT_RELA";
323 case 5: return "SHT_HASH";
324 case 6: return "SHT_DYNAMIC";
325 case 7: return "SHT_NOTE";
326 case 8: return "SHT_NOBITS";
327 case 9: return "SHT_REL";
328 case 10: return "SHT_SHLIB";
329 case 11: return "SHT_DYNSYM";
330 case 14: return "SHT_INIT_ARRAY";
331 case 15: return "SHT_FINI_ARRAY";
332 case 16: return "SHT_PREINIT_ARRAY";
333 case 17: return "SHT_GROUP";
334 case 18: return "SHT_SYMTAB_SHNDX";
335 /* 0x60000000 - 0x6fffffff operating system-specific semantics */
336 case 0x6ffffff0: return "XXX:VERSYM";
337 case 0x6ffffff4: return "SHT_SUNW_dof";
338 case 0x6ffffff6: return "SHT_GNU_HASH";
339 case 0x6ffffff7: return "SHT_GNU_LIBLIST";
340 case 0x6ffffffc: return "XXX:VERDEF";
341 case 0x6ffffffd: return "SHT_SUNW(GNU)_verdef";
342 case 0x6ffffffe: return "SHT_SUNW(GNU)_verneed";
343 case 0x6fffffff: return "SHT_SUNW(GNU)_versym";
344 /* 0x70000000 - 0x7fffffff processor-specific semantics */
345 case 0x70000000: return "SHT_IA_64_EXT";
346 case 0x70000001: return "SHT_IA_64_UNWIND";
347 case 0x7ffffffd: return "XXX:AUXILIARY";
348 case 0x7fffffff: return "XXX:FILTER";
349 /* 0x80000000 - 0xffffffff application programs */
350 default: return "ERROR: SHT NOT DEFINED";
351 }
352}
353
354/*
355 * Define known section flags. These flags are defined in the order
356 * they are to be printed out.
357 */
358#define DEFINE_SHFLAGS() \
359 DEFINE_SHF(WRITE) \

--- 25 unchanged lines hidden (view full) ---

385
386 DEFINE_SHFLAGS()
387
388 flg[strlen(flg) - 1] = '\0'; /* Remove the trailing "|". */
389
390 return (flg);
391}
392
393static const char *st_types[] = {
394 "STT_NOTYPE", "STT_OBJECT", "STT_FUNC", "STT_SECTION", "STT_FILE",
395 "STT_COMMON", "STT_TLS"
396};
397
398static const char *st_types_S[] = {
399 "NOTY", "OBJT", "FUNC", "SECT", "FILE"
400};
401
402static const char *st_bindings[] = {
403 "STB_LOCAL", "STB_GLOBAL", "STB_WEAK"
404};
405
406static const char *st_bindings_S[] = {
407 "LOCL", "GLOB", "WEAK"
408};
409
410static unsigned char st_others[] = {
411 'D', 'I', 'H', 'P'
412};
413
414static const char *
415r_type(unsigned int mach, unsigned int type)
416{
417 switch(mach) {
418 case EM_NONE: return "";
419 case EM_386:
420 case EM_IAMCU:
421 switch(type) {
422 case 0: return "R_386_NONE";
423 case 1: return "R_386_32";
424 case 2: return "R_386_PC32";
425 case 3: return "R_386_GOT32";
426 case 4: return "R_386_PLT32";
427 case 5: return "R_386_COPY";
428 case 6: return "R_386_GLOB_DAT";
429 case 7: return "R_386_JMP_SLOT";
430 case 8: return "R_386_RELATIVE";
431 case 9: return "R_386_GOTOFF";
432 case 10: return "R_386_GOTPC";
433 case 14: return "R_386_TLS_TPOFF";
434 case 15: return "R_386_TLS_IE";
435 case 16: return "R_386_TLS_GOTIE";
436 case 17: return "R_386_TLS_LE";
437 case 18: return "R_386_TLS_GD";

--- 326 unchanged lines hidden (view full) ---

764 switch(type) {
765 case 0: return "R_X86_64_NONE";
766 case 1: return "R_X86_64_64";
767 case 2: return "R_X86_64_PC32";
768 case 3: return "R_X86_64_GOT32";
769 case 4: return "R_X86_64_PLT32";
770 case 5: return "R_X86_64_COPY";
771 case 6: return "R_X86_64_GLOB_DAT";
772 case 7: return "R_X86_64_JMP_SLOT";
773 case 8: return "R_X86_64_RELATIVE";
774 case 9: return "R_X86_64_GOTPCREL";
775 case 10: return "R_X86_64_32";
776 case 11: return "R_X86_64_32S";
777 case 12: return "R_X86_64_16";
778 case 13: return "R_X86_64_PC16";
779 case 14: return "R_X86_64_8";
780 case 15: return "R_X86_64_PC8";

--- 822 unchanged lines hidden (view full) ---

1603 PRT("\nSection Header[%d]:", i);
1604 PRT(" sh_name: %s\n", s->name);
1605 PRT(" sh_addr: %#-14jx", (uintmax_t)s->addr);
1606 if (s->flags != 0)
1607 PRT(" sh_flags: [ %s ]\n", sh_flags(s->flags));
1608 else
1609 PRT(" sh_flags: 0\n");
1610 PRT(" sh_size: %#-14jx", (uintmax_t)s->sz);
1611 PRT(" sh_type: [ %s ]\n", sh_types(s->type));
1612 PRT(" sh_offset: %#-14jx", (uintmax_t)s->off);
1613 PRT(" sh_entsize: %#jx\n", (uintmax_t)s->entsize);
1614 PRT(" sh_link: %-14u", s->link);
1615 PRT(" sh_info: %u\n", s->info);
1616 PRT(" sh_addralign: %#jx\n", (uintmax_t)s->align);
1617 } else {
1618 PRT("\n");
1619 PRT("entry: %ju\n", (uintmax_t)i);
1620 PRT("\tsh_name: %s\n", s->name);
1621 PRT("\tsh_type: %s\n", sh_types(s->type));
1622 PRT("\tsh_flags: %s\n", sh_flags(s->flags));
1623 PRT("\tsh_addr: %#jx\n", (uintmax_t)s->addr);
1624 PRT("\tsh_offset: %ju\n", (uintmax_t)s->off);
1625 PRT("\tsh_size: %ju\n", (uintmax_t)s->sz);
1626 PRT("\tsh_link: %u\n", s->link);
1627 PRT("\tsh_info: %u\n", s->info);
1628 PRT("\tsh_addralign: %ju\n", (uintmax_t)s->align);
1629 PRT("\tsh_entsize: %ju\n", (uintmax_t)s->entsize);

--- 110 unchanged lines hidden (view full) ---

1740 PRT("%10s ", idx);
1741 else
1742 PRT("%10s ", idx);
1743 PRT("0x%8.8jx ", (uintmax_t)sym.st_value);
1744 if (ed->ec == ELFCLASS32)
1745 PRT("0x%8.8jx ", (uintmax_t)sym.st_size);
1746 else
1747 PRT("0x%12.12jx ", (uintmax_t)sym.st_size);
1748 PRT("%s ", st_types_S[GELF_ST_TYPE(sym.st_info)]);
1749 PRT("%s ", st_bindings_S[GELF_ST_BIND(sym.st_info)]);
1750 PRT("%c ", st_others[sym.st_other]);
1751 PRT("%3u ", (vs == NULL ? 0 : vs[j]));
1752 PRT("%-11.11s ", sh_name(ed, sym.st_shndx));
1753 PRT("%s\n", name);
1754 } else {
1755 PRT("\nentry: %d\n", j);
1756 PRT("\tst_name: %s\n", name);
1757 PRT("\tst_value: %#jx\n", (uintmax_t)sym.st_value);
1758 PRT("\tst_size: %ju\n", (uintmax_t)sym.st_size);
1759 PRT("\tst_info: %s %s\n",
1760 st_types[GELF_ST_TYPE(sym.st_info)],
1761 st_bindings[GELF_ST_BIND(sym.st_info)]);
1762 PRT("\tst_shndx: %ju\n", (uintmax_t)sym.st_shndx);
1763 }
1764 }
1765}
1766
1767/*
1768 * Dump the symbol tables. (.dynsym and .symtab)
1769 */

--- 398 unchanged lines hidden (view full) ---

2168 PRT("addend symbol\n");
2169 } else {
2170 PRT(" ndx addr value ");
2171 PRT("reloc addend symbol\n");
2172 }
2173 for(i = 0; i < len; i++) {
2174 PRT("[%5.5d] ", i);
2175 if (ed->ec == ELFCLASS32) {
2176 PRT("%-8.8jx ", s->addr + i * s->entsize);
2177 PRT("%-8.8x ", *((uint32_t *)dst.d_buf + i));
2178 } else {
2179 PRT("%-16.16jx ", s->addr + i * s->entsize);
2180 PRT("%-16.16jx ", *((uint64_t *)dst.d_buf + i));
2181 }
2182 PRT("%-18s ", r_type(ed->ehdr.e_machine,
2183 GELF_R_TYPE(got[i].u_r.rel.r_info)));
2184 if (ed->ec == ELFCLASS32)
2185 PRT("%-8.8jd ",
2186 (intmax_t)got[i].u_r.rela.r_addend);
2187 else
2188 PRT("%-12.12jd ",

--- 4 unchanged lines hidden (view full) ---

2193 }
2194 free(got);
2195 } else {
2196 for(i = 0; i < len; i++) {
2197 PRT("\nentry: %d\n", i);
2198 if (ed->ec == ELFCLASS32)
2199 PRT("\t%#x\n", *((uint32_t *)dst.d_buf + i));
2200 else
2201 PRT("\t%#jx\n", *((uint64_t *)dst.d_buf + i));
2202 }
2203 }
2204}
2205
2206/*
2207 * Dump the content of Global Offset Table section.
2208 */
2209static void

--- 649 unchanged lines hidden ---