summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* ar: Check whether ar header values fit.Mark Wielaard2017-09-202-20/+55
| | | | | | | | | | | | | | | | | When compiling with -O3 gcc finds an interesting error: src/ar.c: In function ‘do_oper_insert’: src/ar.c:1077:56: error: ‘%-*ld’ directive output may be truncated writing between 6 and 10 bytes into a region of size 7 [-Werror=format-truncation=] snprintf (tmpbuf, sizeof (tmpbuf), ofmt ? "%-*lo" : "%-*ld", bufsize, val); ^~~~~ The problem is that the ar header values have to fit in a limited (not zero terminated) string. We should check the snprintf return value to see if the values are representable. Also make ar valgrind and ubsan clean and add a minimal sanity test. Reported-by: Matthias Klose <doko@ubuntu.com> Signed-off-by: Mark Wielaard <mark@klomp.org>
* Internationalized messages should not contain the '\v' escape sequence.Mark Wielaard2017-09-153-2/+9
| | | | | | | Replace horizontal tab '\v' with double line feed '\n\n' in doc strings. Regenerate .po files. Signed-off-by: Mark Wielaard <mark@klomp.org>
* Cast pid_t to long long when printingUlf Hermann2017-08-182-14/+22
| | | | | | | | | We don't know sizeof(pid_t) as it's not specified in any standard. In order to still print it, we cast to long long, the largest integer type we can easily print. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io> Signed-off-by: Mark Wielaard <mark@klomp.org>
* On non-linux systems, don't use native signal numbersUlf Hermann2017-08-182-5/+23
| | | | | | | | We assume core files from linux systems, so we should use the linux version of the signals when reading them. Other OS might have different signal numbers. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* libdw: Add DW_MACRO constants and DW_MACRO_GNU compatibility defines.Mark Wielaard2017-08-022-16/+86
| | | | | | | | | | Accept version 5 .debug_macro format, which is identical to the GNU version 4 format. No real support yet for the new supplementary object file (sup) and indirect string references (strx). GCC doesn't generate them yet. readelf does recognize them, but doesn't try to decode them. dwarf_getmacros currently rejects the new formats. Signed-off-by: Mark Wielaard <mark@klomp.org>
* Handle DWARF5 defaulted member function encodings.Mark Wielaard2017-08-022-0/+35
| | | | | | | | | Add DW_DEFAULTED_no, DW_DEFAULTED_in_class and DW_DEFAULTED_out_of_class to dwarf.h. Print value (no, in_class or out_of_class) of DW_AT_defaulted in readelf. Signed-off-by: Mark Wielaard <mark@klomp.org>
* strip: Deal with ARM data marker symbols pointing to debug sections.Mark Wielaard2017-07-242-6/+29
| | | | | | | | | | | | | | | | | | | ARM data marker symbols "$d" indicate the start of a sequence of data items in a section. For data only sections no data marker symbol is necessary, but may be put pointing to the start of the section. binutils however has a bug which places a data marker symbol somewhere inside the section (at least for .debug_frame). https://sourceware.org/bugzilla/show_bug.cgi?id=21809 When strip finds a symbol pointing to a debug section that would be put into the .debug file then it will copy over the whole symbol table. This isn't necessary because the symbol is redundant. Add an ebl hook to recognize data marker symbols with implementations for arm and aarch64. Use it in strip to strip such symbols from the symbol table if they point to a debug section. Signed-off-by: Mark Wielaard <mark@klomp.org>
* strip: Add --keep-section=SECTION and --remove-section=SECTION.Mark Wielaard2017-07-172-17/+123
| | | | | | | | | | | | | | | | | | | | | Adds two new output options: --keep-section=SECTION Keep the named section. SECTION is an extended wildcard pattern. May be given more than once. --remove-section=SECTION Remove the named section. SECTION is an extended wildcard pattern. May be given more than once. Only non-allocated sections can be removed. The --remove-section was already partially implemented, but only for the .comment section. The short option -R is to be compatible with binutils. The new testcase makes sure that various combinations of kept/removed sections pull the correct dependencies into the output and/or debug files. https://bugzilla.redhat.com/show_bug.cgi?id=1465997 Signed-off-by: Mark Wielaard <mark@klomp.org>
* strip: Don't generate empty output file when nothing to do.Mark Wielaard2017-06-142-12/+25
| | | | | | | | | | | | | | | | | If there was nothing to do strip would skip generating a separate debug file if one was requested, but it would also not finish the creation of a new output file (with the non-stripped sections). Also if there was an error any partially created output would be kept. Make sure that when the -o output file option is given we always generate a complete output file (except on error). Also make sure that when the -f debug file option is given it is only generated when it is not empty. Add testcase run-strip-nothing.sh that tests the various combinations. https://sourceware.org/bugzilla/show_bug.cgi?id=21522 Signed-off-by: Mark Wielaard <mark@klomp.org>
* strip: Make sure old .shstrab is removed when eu-strip recreates it.Mark Wielaard2017-06-142-6/+14
| | | | | | | | | | | | | | | | Although we always recreate the .shstrtab section for the new output file we never explicitly assumed it could be removed. It might not be possible to remove it when the section string table is shared with a symbol table. But if it is removable we should (and recreate it for the new section list). Regression introduced in commit elfutils-0.163-33-gdf7dfab. "Handle merged strtab/shstrtab string tables in strip and unstrip." Add extra testcase to explicitly check for this case. https://sourceware.org/bugzilla/show_bug.cgi?id=21525 Signed-off-by: Mark Wielaard <mark@klomp.org>
* Include strings.h to make ffs availableUlf Hermann2017-04-272-0/+5
| | | | | | We cannot rely on it to be available from any of the other headers. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* Protect against integer overflow on shnumUlf Hermann2017-04-272-11/+18
| | | | | | | If shnum is 0, the many "shnum - 1" would result in an overflow. Check it for 0, and only subtract once, rather than on every usage. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* Avoid YESSTR and NOSTRUlf Hermann2017-04-262-3/+8
| | | | | | | | | Those are deprecated and apparently some implementations of nl_langinfo return empty strings for them. The tests even tested for those empty strings even though the intention of the code was clearly to output "yes" or "no" there. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* elflint: Support checking ELF files with compressed sections.Mark Wielaard2017-04-052-1/+10
| | | | | | | | | Simply unconditionally uncompress any section to make sure indexes between sections check out. Add some testcases with various compressed sections. https://sourceware.org/bugzilla/show_bug.cgi?id=21332 Signed-off-by: Mark Wielaard <mark@klomp.org>
* elflint: Don't check section group without flags word.Mark Wielaard2017-04-042-1/+8
| | | | | | https://sourceware.org/bugzilla/show_bug.cgi?id=21320 Signed-off-by: Mark Wielaard <mark@klomp.org>
* elflint: Sanity check the number of phdrs and shdrs available.Mark Wielaard2017-04-042-0/+30
| | | | | | | | | Make sure we can at least read the shnum sections or phnum segments. Limit the number we do check to those we can actually read. https://sourceware.org/bugzilla/show_bug.cgi?id=21312 Signed-off-by: Mark Wielaard <mark@klomp.org>
* elflint: Don't trust sh_entsize when checking hash sections.Mark Wielaard2017-04-042-12/+27
| | | | | | | | | | Calculate and use the expected entsize instead of relying on the one given by the ELF file section header. Return early if there isn't enough data in the section to check the full hash table. https://sourceware.org/bugzilla/show_bug.cgi?id=21311 Signed-off-by: Mark Wielaard <mark@klomp.org>
* elflint: Check symbol table data is big enough before checking.Mark Wielaard2017-04-042-1/+6
| | | | | | | | | Before checking symbol index zero we should make sure the data size is big enough. https://sourceware.org/bugzilla/show_bug.cgi?id=21310 Signed-off-by: Mark Wielaard <mark@klomp.org>
* Use the empty string for note names with zero size (without any data).Mark Wielaard2017-04-033-3/+11
| | | | | | | | | | ELF notes can have a zero sized name. In which case there is no data at all (so also no zero terminator). Make sure to use the empty string for such notes if the code does not otherwise explicitly check n_namesz. https://sourceware.org/bugzilla/show_bug.cgi?id=21300 Signed-off-by: Mark Wielaard <mark@klomp.org>
* readelf: Fix off by one sanity check in handle_gnu_hash.Mark Wielaard2017-04-032-1/+6
| | | | | | | | | | We sanity check to make sure we don't index outside the chain array by testing inner > max_nsyms. But inner is a zero-based index, while max_nsyms is the maximum number. Change the check to inner >= max_nsyms. https://sourceware.org/bugzilla/show_bug.cgi?id=21299 Signed-off-by: Mark Wielaard <mark@klomp.org>
* Move print_version into printversion.{h|c}Ulf Hermann2017-02-1716-5/+33
| | | | | | | | Rename version.c so that the implementation is called after the header and the header doesn't clash with the toplevel version.h. print_version depends on argp and is only used in the tools. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* Move color handling into a separate headerUlf Hermann2017-02-153-0/+7
| | | | | | | | We only need it in nm.c and objdump.c, but it pulls in argp as dependency. By dropping it from libeu.h, the libraries can be compiled without argp. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* http://elfutils.org/ is now hosted at http://sourceware.org/elfutils/Mark Wielaard2016-12-2417-211/+24
| | | | | | | | | | | | | | | | | fedorahosted used to be our home, but we are now hosted at sourceware. Change the elfutils project home to http://elfutils.org/ Point hosted services (email, release, git, bug tracker and web pages) to https://sourceware.org/elfutils/ Move design notes from README to NOTES. Add URLs for home, releases, bugs, git and mailinglist to README. Make the --version output of all tools the same by using a common print_version function and update the publicly shown copyright holder to the elfutils developers. Signed-off-by: Mark Wielaard <mark@klomp.org>
* readelf: Add optional --symbols[=SECTION] argument to select section name.Mark Wielaard2016-11-172-1/+26
| | | | | | | | | Make it possible to display just the symbols from a named symbol section instead of always displaying all symbol sections. https://bugzilla.redhat.com/show_bug.cgi?id=1396092 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* ar: Fix GCC7 -Wformat-length issues.Mark Wielaard2016-11-113-10/+28
| | | | | | | | | | | | GCC7 adds warnings for snprintf formatting into too small buffers. Fix the two issues pointed out by the new warning. The ar header fields are fixed length containing left-justified strings without zero terminator. snprintf always adds a '\0' char at the end (which we then don't copy into the ar header field) and numbers are decimal strings of fixed 10 chars (-Wformat-length thinks formatting them as size_t might overflow the buffer on 64bit arches). Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Add GCC7 -Wimplicit-fallthrough support/fixes.Mark Wielaard2016-11-105-3/+17
| | | | | | | | | | | GCC7 will have a new -Wimplicit-fallthrough warning. It did catch one small buglet in elflint option procession. So it seems useful to enable to make sure all swatch case fallthroughs are deliberate. Add configure check to detect whether gcc support -Wimplicit-fallthrough and enable it. Add fixes and explicit fallthrough comments where necessary. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* unstrip: Don't try to use unstripped .symtab with stripped .strtabKevin Cernekee2016-10-242-7/+12
| | | | | | | | | | | | | | | | | | | | | | | Prematurely matching up the stripped and unstripped .strtab sections in the "Match each debuginfo" loop can lead to a case where sec->outscn gets populated for the stripped .strtab, which we normally want to ignore. This causes the .strtab override in the "Make sure each main file section" loop to be skipped, so the code winds up using indices from the unstripped .symtab to look up strings in the stripped .strtab. This returns incorrect strings for a little while, and then fails catastrophically when it tries to read past the end of the (smaller) stripped file's .strtab section: eu-unstrip: invalid string offset in symbol [1589] Fix this by adding logic to the "Match each debuginfo" loop to treat the unstripped .strtab, .shstrtab, and .symtab sections essentially the same way. The new logic will break if the .strtab section shows up earlier than the .symtab section. We will assume this never happens in practice. Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
* lib: Provide MAX and MIN in system.hAkihiko Odaki2016-10-1213-10/+24
| | | | | | | | | | This change also creates a new header file libeu.h to provide the prototypes for the function of libeu. That hides the definition of function crc32, which can conflict with zlib, from libelf. It also prevents mistakes to refer those functions from a component which doesn't link with libeu, such as libelf. Signed-off-by: Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
* strip: Don't remove real symbols from allocated symbol tables.Mark Wielaard2016-10-062-11/+29
| | | | | | | | | | | | | | | Having a symbol in an allocated symbol table (like .dynsym) that points to an unallocated section is wrong. Traditionally strip has removed such symbols if they are section or group symbols. But removing a real symbol from an allocate symbol table is hard and probably a mistake. Really removing it means rewriting the dynamic segment and hash sections. Since we don't do that, don't remove the symbol (and corrupt the ELF file). Do warn and set the symbol section to SHN_UNDEF. https://bugzilla.redhat.com/show_bug.cgi?id=1380961 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* strip: Use ELF_CHF_FORCE to recompress any sections that were uncompressed.Mark Wielaard2016-08-252-1/+5
| | | | | | | | Older gcc might create small .debug_pubtype. If such a section is compressed then strip should use ELF_CHF_FORCE to return it to compressed state after it is done with the section. Found by the run-strip-reloc.sh testcase on rhel6. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* strip: Handle compressed relocation target sections.Mark Wielaard2016-08-152-5/+22
| | | | | | | | | | | | | | | binutils 2.27 assembler will create compressed sections for x86 ELF targets. The linker will decompress them again and it doesn't do this for any other target. This broke one of the run-strip-reloc.sh self tests. Fix by checking if the target of a relocation section is compressed and first decompressing it before applying relocations and then compressing again if necessary. Add explicit testcases for compressed and uncompressed ET_REL files to run-strip-reloc.sh. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* dwelf: Add string table functions from ebl.Mark Wielaard2016-08-035-46/+69
| | | | | | | | | | | | | | | | Move the strtab functions from libebl to libdw. Programs often want to create ELF/DWARF string tables. We don't want (static) linking against ebl since those are internal functions that might change. This introduces dwelf_strtab_init, dwelf_strtab_add, dwelf_strtab_add_len, dwelf_strtab_finalize, dwelf_strent_off, dwelf_strent_str and dwelf_strtab_free. Documentation for each has been added to libdwelf.h. The add fucntion got a variant that takes the length explicitly and finalize was changed to return NULL on out of memory instead of aborting. All code and tests now uses the new functions. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Remove eu-ld and unused code.Mark Wielaard2016-08-0319-13157/+29
| | | | | | | | Nobody has hacked on eu-ld in a very long time. It didn't really work. And we didn't install it by default in the spec file. Remove sources, the build rules and any (now) unused code. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* unstrip: Fix off by one array access with unstripped_strent.Mark Wielaard2016-07-112-3/+8
| | | | | | | | | | When configuring with --enable-sanitize-undefined the latest GCC found an array out of bounds access when running the un-strip-strmerge.sh test. We keep an array of section names. But skipped section zero, since it didn't have a name. We should however not actually skip the first array index (zero) when storing and reading the names. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Add support for BPFRichard Henderson2016-06-282-1/+5
| | | | Signed-off-by: Richard Henderson <rth@redhat.com>
* elfcmp: fix self-comparison error with GCC 6David Abdurachmanov2016-04-112-1/+5
| | | | | | | | | | | | Noticed with Fedora 24 Alpha, gcc (GCC) 6.0.0 20160406 (Red Hat 6.0.0-0.20). elfcmp.c: In function ‘main’: elfcmp.c:364:199: error: self-comparison always evaluates to false [-Werror=tautological-compare] if (unlikely (name1 == NULL || name2 == NULL Signed-off-by: David Abdurachmanov <davidlt@cern.ch>
* nm: Check for malloc size argument overflow in show_symbols.Mark Wielaard2016-03-212-0/+9
| | | | | Reported-by: Florian Weimer <fweimer@redhat.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* readelf: Warn when uncompressing fails and error when gelf_getshdr fails.Mark Wielaard2016-02-222-5/+46
| | | | | | | | After decompressing we want to get the new shdr. This can theoretically fail so we have to check. Also warn the user if a section couldn't be uncompressed. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elfcompress: -q should not imply --force.Mark Wielaard2016-02-222-1/+6
| | | | | | We accidentally set force = true after handling -q and setting verbose--. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Fix GCC6 -Wnull-dereference warnings.Mark Wielaard2016-02-222-2/+8
| | | | | | | | | | | | | | | | | | | | | | | asm_begin.c: In function ‘asm_begin’: asm_begin.c:62:7: error: potential null pointer dereference [-Werror=null-dereference] __fsetlocking (result->out.file, FSETLOCKING_BYCALLER); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We set result to NULL just before this call in case of error. Fixed by only calling __fsetlocking when result is not NULL. strip.c: In function ‘handle_elf.constprop’: strip.c:1270:31: error: null pointer dereference [-Werror=null-dereference] elf_assert ((versiondata->d_size / sizeof (Elf32_Word)) ~~~~~~~~~~~^~~ src/strip.c:597:37: note: in definition of macro ‘elf_assert’ #define elf_assert(test) do { if (!(test)) goto illformed; } while (0) ^~~~ That is the wrong check, we want to check shndxdata, not versiondata here. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* readelf: Read and print (encoded) DW_CFA_set_loc op and update pc.Mark Wielaard2016-02-182-60/+68
| | | | | | | DW_CFA_set_loc takes an address as op, not an uleb128. Read and decode it. Print the actual address and (updated) pc (address plus vma_base). Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elflint: Fix sh_entsize check when comparing SHT_HASH and SHT_GNU_HASH.Mark Wielaard2016-02-152-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | GCC6 -Wduplicated-cond found the following issue: elflint.c: In function ‘compare_hash_gnu_hash’: elflint.c:2483:34: error: duplicated ‘if’ condition [-Werror=duplicated-cond] else if (hash_shdr->sh_entsize == sizeof (Elf64_Word)) ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ elflint.c:2448:29: note: previously used here if (hash_shdr->sh_entsize == sizeof (Elf32_Word)) ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ Which is correct, a Word in both Elf32 and Elf64 files is 4 bytes. We meant to check for sizeof (Elf64_Xword) which is 8 bytes. Also fix the section index and name in the error message. The reason we probably didn't see this issue before is that SHT_HASH sections really always should have sh_entsize of 4 even on 64bit arches. There are however a couple of arches with mistakes in their sysv ABI. See libelf/common.h. This also would only be triggered if on such an architectures when the ELF file would have both a SHT_HASH and SHT_GNU_HASH section and elflint would try to compare those sections. Add an example testfile-s390x-hash-both to run-elflint-test.sh. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elflint: Recognize ELFOSABI_FREEBSD which Debian kFreeBSD uses.Mark Wielaard2016-01-182-2/+8
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Fix build on 32bit systems.Mark Wielaard2016-01-083-2/+7
| | | | | | size_t has a different size on 32 and 64 bit systems. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elfcompress: New utility.Mark Wielaard2016-01-063-1/+1329
| | | | | | | | | | | | | | | | | | | | | | | | | | | Usage: elfcompress [OPTION...] FILE... Compress or decompress sections in an ELF file. -f, --force Force compression of section even if it would become larger -n, --name=SECTION SECTION name to (de)compress, SECTION is an extended wildcard pattern (defaults to '.?(z)debug*') -o, --output=FILE Place (de)compressed output into FILE -p, --permissive Relax a few rules to handle slightly broken ELF files -q, --quiet Be silent when a section cannot be compressed -t, --type=TYPE What type of compression to apply. TYPE can be 'none' (decompress), 'zlib' (ELF ZLIB compression, the default, 'zlib-gabi' is an alias) or 'zlib-gnu' (.zdebug GNU style compression, 'gnu' is an alias) -v, --verbose Print a message for each section being (de)compressed -?, --help Give this help list --usage Give a short usage message -V, --version Print program version Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elflint: Recognize and check SHF_COMPRESSED section flag.Mark Wielaard2016-01-062-10/+43
| | | | | | | | SHF_COMPRESSED is a valid section flag, it can optionally be on any special section, but it cannot be used on NOBITS sections or together with SHF_ALLOC. A section that has SHF_COMPRESSED set must have a valid Chdr. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* readelf: Handle compressed sections and extend -z to cover -x and -p.Mark Wielaard2016-01-062-21/+116
| | | | | | | | | | | | | | | When printing a (non-string, non-data) section use uncompressed data when possible. For dumping hex and string sections (-x and -p) -z will dump the uncompressed data (otherwise the compressed data is dumped). -z, --decompress Show compression information for compressed sections (when used with -S); decompress section before dumping data (when used with -p or -x) Includes test cases for ET_REL files using compressed relocation (target) debug sections to test libdwfl transparent uncompression of sections. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* readelf: Add -z,--decompress option.Mark Wielaard2016-01-062-3/+71
| | | | | | | -z, --decompress Show compression information for compressed sections (when used with -S). Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elflint: Add _edata and _end to the list of possibly dangling gnuld symbols.Mark Wielaard2016-01-052-1/+10
| | | | | | | | | | gnuld might keep dangling/unused symbols around (see sourceware PR13621). Add _edata (end of initialized data address) and _end (end of uninitialized data address) to that list. They might have been added by gnuld even if there is no such [un]initialized data. Also add the double underscore variants which are used on some architectures. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* nm: If the file is ET_REL and we need Dwarf use libdwfl to get it relocated.Mark Wielaard2016-01-022-8/+116
| | | | | | | | | | | If we need Dwarf and the file is ET_REL use the same trick as in readelf to get a relocated Dwarf. Otherwise lots of references in the debug_info will come out as zero. This also explains the "bogus" Dwarf seen that caused the memory leak in the local_root that was fixed previously. Signed-off-by: Mark Wielaard <mjw@redhat.com>