diff options
author | emaste <emaste@FreeBSD.org> | 2015-05-27 14:28:19 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2015-05-27 14:28:19 +0000 |
commit | aa01a21e0c7d20fb276cc0628a159a595e0e617e (patch) | |
tree | 74d3c6f019cc59be7b175c8db630ad55260c4062 /contrib/elftoolchain/readelf/readelf.c | |
parent | abf78a3a279a4db8cb4d6cc74dae9ae4c35003e4 (diff) | |
download | FreeBSD-src-aa01a21e0c7d20fb276cc0628a159a595e0e617e.zip FreeBSD-src-aa01a21e0c7d20fb276cc0628a159a595e0e617e.tar.gz |
Update to ELF Tool Chain r3223
Highlights (upstream revisions):
- Fix SHT_GROUP handling in elfcopy/strip (3206 3220 3221)
- Misc elfcopy / strip bug fixes (3215 3216 3217)
- Many C++ demangler improvements (3199 3200 3201 3202 3203 3204 3205
3208 3210 3211 3212)
- Improve GNU binutils compatibility in elfcopy / strip (3213 3214)
- Add -g option to readelf(1): dump contents of section groups (3219)
- Add EM_IAMCU 32-bit Intel MCU (3198)
Also add a compat #define for building with older FreeBSD ELF headers.
The GRP_COMDAT flag was added to elf_common.h in r283110, but it's not
available during the bootstrap build. It is also convenient to be able
to build on older hosts.
Thanks to antoine@ for tracking down issues through multiple exp-runs
and to kaiw@ for fixing.
PR: 198611 (exp-run), 200350
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'contrib/elftoolchain/readelf/readelf.c')
-rw-r--r-- | contrib/elftoolchain/readelf/readelf.c | 71 |
1 files changed, 66 insertions, 5 deletions
diff --git a/contrib/elftoolchain/readelf/readelf.c b/contrib/elftoolchain/readelf/readelf.c index 29bc389..b1b81a3 100644 --- a/contrib/elftoolchain/readelf/readelf.c +++ b/contrib/elftoolchain/readelf/readelf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2014 Kai Wang + * Copyright (c) 2009-2015 Kai Wang * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,7 +46,7 @@ #include "_elftc.h" -ELFTC_VCSID("$Id: readelf.c 3189 2015-04-20 17:02:01Z emaste $"); +ELFTC_VCSID("$Id: readelf.c 3223 2015-05-25 20:37:57Z emaste $"); /* * readelf(1) options. @@ -302,6 +302,7 @@ static void dump_gnu_hash(struct readelf *re, struct section *s); static void dump_hash(struct readelf *re); static void dump_phdr(struct readelf *re); static void dump_ppc_attributes(uint8_t *p, uint8_t *pe); +static void dump_section_groups(struct readelf *re); static void dump_symtab(struct readelf *re, int i); static void dump_symtabs(struct readelf *re); static uint8_t *dump_unknown_tag(uint64_t tag, uint8_t *p); @@ -445,6 +446,7 @@ elf_machine(unsigned int mach) case EM_SPARC: return "Sun SPARC"; case EM_386: return "Intel i386"; case EM_68K: return "Motorola 68000"; + case EM_IAMCU: return "Intel MCU"; case EM_88K: return "Motorola 88000"; case EM_860: return "Intel i860"; case EM_MIPS: return "MIPS R3000 Big-Endian only"; @@ -1050,6 +1052,7 @@ r_type(unsigned int mach, unsigned int type) switch(mach) { case EM_NONE: return ""; case EM_386: + case EM_IAMCU: switch(type) { case 0: return "R_386_NONE"; case 1: return "R_386_32"; @@ -2381,6 +2384,7 @@ dwarf_reg(unsigned int mach, unsigned int reg) switch (mach) { case EM_386: + case EM_IAMCU: switch (reg) { case 0: return "eax"; case 1: return "ecx"; @@ -4047,6 +4051,61 @@ dump_liblist(struct readelf *re) #undef Elf_Lib +static void +dump_section_groups(struct readelf *re) +{ + struct section *s; + const char *symname; + Elf_Data *d; + uint32_t *w; + int i, j, elferr; + size_t n; + + for (i = 0; (size_t) i < re->shnum; i++) { + s = &re->sl[i]; + if (s->type != SHT_GROUP) + continue; + (void) elf_errno(); + if ((d = elf_getdata(s->scn, NULL)) == NULL) { + elferr = elf_errno(); + if (elferr != 0) + warnx("elf_getdata failed: %s", + elf_errmsg(elferr)); + continue; + } + if (d->d_size <= 0) + continue; + + w = d->d_buf; + + /* We only support COMDAT section. */ +#ifndef GRP_COMDAT +#define GRP_COMDAT 0x1 +#endif + if ((*w++ & GRP_COMDAT) == 0) + return; + + if (s->entsize == 0) + s->entsize = 4; + + symname = get_symbol_name(re, s->link, s->info); + n = s->sz / s->entsize; + if (n-- < 1) + return; + + printf("\nCOMDAT group section [%5d] `%s' [%s] contains %ju" + " sections:\n", i, s->name, symname, (uintmax_t)n); + printf(" %-10.10s %s\n", "[Index]", "Name"); + for (j = 0; (size_t) j < n; j++, w++) { + if (*w >= re->shnum) { + warnx("invalid section index: %u", *w); + continue; + } + printf(" [%5u] %s\n", *w, re->sl[*w].name); + } + } +} + static uint8_t * dump_unknown_tag(uint64_t tag, uint8_t *p) { @@ -6838,6 +6897,8 @@ dump_elf(struct readelf *re) dump_phdr(re); if (re->options & RE_SS) dump_shdr(re); + if (re->options & RE_G) + dump_section_groups(re); if (re->options & RE_D) dump_dynamic(re); if (re->options & RE_R) @@ -7311,7 +7372,7 @@ Usage: %s [options] file...\n\ -c | --archive-index Print the archive symbol table for archives.\n\ -d | --dynamic Print the contents of SHT_DYNAMIC sections.\n\ -e | --headers Print all headers in the object.\n\ - -g | --section-groups (accepted, but ignored)\n\ + -g | --section-groups Print the contents of the section groups.\n\ -h | --file-header Print the file header for the object.\n\ -l | --program-headers Print the PHDR table for the object.\n\ -n | --notes Print the contents of SHT_NOTE sections.\n\ @@ -7365,8 +7426,8 @@ main(int argc, char **argv) re->options |= RE_AA; break; case 'a': - re->options |= RE_AA | RE_D | RE_H | RE_II | RE_L | - RE_R | RE_SS | RE_S | RE_VV; + re->options |= RE_AA | RE_D | RE_G | RE_H | RE_II | + RE_L | RE_R | RE_SS | RE_S | RE_VV; break; case 'c': re->options |= RE_C; |