summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* Add support for BPFRichard Henderson2016-06-282-1/+5
| | | | Signed-off-by: Richard Henderson <[email protected]>
* 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 <[email protected]>
* nm: Check for malloc size argument overflow in show_symbols.Mark Wielaard2016-03-212-0/+9
| | | | | Reported-by: Florian Weimer <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* elflint: Recognize ELFOSABI_FREEBSD which Debian kFreeBSD uses.Mark Wielaard2016-01-182-2/+8
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* nm: Don't leak duplicate Dwarf local names.Mark Wielaard2016-01-022-5/+14
| | | | | | | Badly formed DWARF can have duplicate local names. In which case we do want to detect those so we don't leak the memory. Signed-off-by: Mark Wielaard <[email protected]>
* unstrip: Don't leak new section data.Mark Wielaard2016-01-022-2/+47
| | | | | | | When we copy elided sections some section data is newly allocated. Track those allocations so we can free them when done. Signed-off-by: Mark Wielaard <[email protected]>
* elfcmp: Fix leaking Ebl handles.Mark Wielaard2016-01-022-0/+6
| | | | | | | open_file () explicitly gets Ebl handles for both Elf files to compare. Make sure to close those when done. Signed-off-by: Mark Wielaard <[email protected]>
* Make zlib mandatory.Mark Wielaard2015-10-262-2/+7
| | | | | | Explicitly link libelf and libdw with -lz. Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Don't check shdr or TLS symbol offsets against debuginfo phdrs.Mark Wielaard2015-10-162-2/+10
| | | | | | | | | | | | In debuginfo files the phdrs file offsets match those of the original ELF file. So the section header file offsets and the TLS symbol value offset in debuginfo files cannot be sanity checked against the phdrs file offset. The issue can be triggered with run-strip-strmerge.sh test when configured with --enable-gcov. Which will insert a .tbss section and TLS symbols that trigger the above checks. Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Reject mergable string sections as relocation target.Mark Wielaard2015-10-162-2/+8
| | | | | | | | Mergable sections can be the target of a relocation, but only if they contain items of the same size. So only reject mergable string sections as target of a relocation section. Signed-off-by: Mark Wielaard <[email protected]>
* Do not rely on ebl_check_special_section when checking debuginfo files.Jose E. Marchesi2015-10-132-5/+19
| | | | | | | | | | | | | | | | | | | | | | | The test run-strip-strmerge.sh is failing in sparc targets. This is because it does an `elflint -d' in a debuginfo file, and this fails with: section [21] '.plt' is both executable and writable elflint uses the ebl_check_special_section hook (implemented only by the alpha and sparc backends) in order to determine whether an executable+writable section must be flagged or not. In both cases the hook will fail analyzing eu-strip debuginfo files (as they should, because debuginfo files are broken ;). This patch just modifies elflint to not use the hook when -d is specified in the command-line. This fixes the test in sparc-* and sparc64-* targets (and presumably in alpha* targets too). Additionaly, the patch checks that the type of WE sections in debuginfo files is NOBITS. Signed-off-by: Jose E. Marchesi <[email protected]>
* elflint: Check relro flags are a subset of the load segment.Mark Wielaard2015-10-132-3/+24
| | | | | | | | | If the RELRO segment doesn't fully overlap with the load segment then the load segment might have more flags sets. This happens for example on sparc when the .plt, which is executable, is also part of the load segment that RELRO covers. Signed-off-by: Mark Wielaard <[email protected]>
* ldlex: Fix sign-compare warning, suppress -Wstack-usage.Mark Wielaard2015-10-123-1/+7
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* Trust AC_SYS_LARGEFILE to provide large file supportJosh Stone2015-10-098-52/+69
| | | | | | | | | | | | | | | AC_SYS_LARGEFILE defines _FILE_OFFSET_BITS in config.h if needed for LFS, and this automatically maps things like open to open64. But quite a few places used explicit 64-bit names, which won't work on platforms like FreeBSD where off_t is always 64-bit and there are no foo64 names. It's better to just trust that AC_SYS_LARGEFILE is doing it correctly. But we can verify this too, as some file could easily forget to include config.h. The new tests/run-lfs-symbols.sh checks all build targets against lfs-symbols (taken from lintian) to make sure everything was implicitly mapped to 64-bit variants when _FILE_OFFSET_BITS is set. Signed-off-by: Josh Stone <[email protected]>
* Move recursive nested function to file scope.Chih-Hung Hsieh2015-10-092-46/+53
| | | | | | Prepare src/ld.c to compile with clang. Signed-off-by: Chih-Hung Hsieh <[email protected]>
* strip: Only sanity check symbols to not discarded sections for debug file.Mark Wielaard2015-10-092-3/+10
| | | | | | | | | | | | | | We can only sanity check the symbols to discarded sections when creating a debug file. Otherwise we won't keep track of debug_data. This can trigger erroneously when there are relocation symbols in the symtab for a .debug section but we are not putting those symbols in a separate .debug file. Adjust run-strip-test.sh to always run in-place strip size check even for ET_REL files. Before this fix the sanity check would trigger for some ET_REL files because they contained such relocation symbols to .debug sections (but debug_data would be NULL because -f wasn't used). Signed-off-by: Mark Wielaard <[email protected]>
* Allocate exact amount of bytes for phdrs and shdrs.Mark Wielaard2015-10-082-11/+13
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* Do without union of variable length arrays.Chih-Hung Hsieh2015-10-073-18/+43
| | | | | | | | | | | | | | Prepare to compile with clang. A union like { T32 a32[n]; T64 a64[n]; } u; is expanded to size_t nbytes = n * MAX(sizeof(T32), sizeof(T64)); void *data = malloc(nbytes); T32 (*a32)[n] = data; T64 (*a64)[n] = data; Signed-off-by: Chih-Hung Hsieh <[email protected]>