summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Improve AM_SILENT_RULES coverageJosh Stone2015-10-062-5/+11
| | | | | | | | | | | Note, elfutils does not explicitly enable AM_SILENT_RULES. It's only available starting from automake 1.11, but starting from automake 1.13 silent rules are always generated, defaulting to verbose. $(AM_V_foo) additions should be no-ops on systems that don't support silent rules. To be silent, use "./configure --enable-silent-rules" or "make V=0". Signed-off-by: Josh Stone <[email protected]>
* unstrip: Update sh_info when SH_INFO_LINK_P not just when SHF_INFO_LINK setMark Wielaard2015-10-052-1/+6
| | | | | | | | | | | SHF_INFO_LINK is not consistently set when sh_info is actually a section index reference. Use SH_INFO_LINK_P to check whether to update the sh_info value. SH_INFO_LINK_P also checks the section type to know whether or not sh_info is meant as section index. Found by run-strip-strmerge.sh test with older binutils. Signed-off-by: Mark Wielaard <[email protected]>
* Handle merged strtab/shstrtab string tables in strip and unstrip.Mark Wielaard2015-10-053-7/+60
| | | | | | | | | | | | | | | | | | | | | ELF files can share the section header string table (e_shstrndx) with the symtab .strtab section. That might in some cases save a bit of space since symbols and sections might share some (sub)strings. To handle that eu-strip just needs to not unconditionally remove the .shstrtab section (it will be properly marked as used/unused as needed). eu-unstrip needs to make sure the section names are added to the strtab if it decides to rewrite that section. Also makes sure that eu-strip won't move around a SHT_NOBITS section that has SHF_ALLOC set. Although it is allowed to move such sections around, there is no benefit. And some tools might expect no allocated section to move around, not even a nobits section. It also makes it harder to do "roundtripping" sanity checks that make sure splitting a file with eu-strip and then reconstructed with eu-unstrip produce the same ELF file (as is done in the new run-strip-strmerge.sh). Introduces a somewhat large test generator elfstrmerge.c that will hopefully turn into a more generic string table merger program. Signed-off-by: Mark Wielaard <[email protected]>
* Remove old-style function definitions.Mark Wielaard2015-09-232-2/+6
| | | | | | | We already require -std=gnu99 and old-style function definitions might hide some compiler warnings. Signed-off-by: Mark Wielaard <[email protected]>
* Initialize variable before use.Chih-Hung Hsieh2015-09-102-1/+8
| | | | | | Some compiler does not know that error function never returns. Signed-off-by: Chih-Hung Hsieh <[email protected]>
* Replace printf %Z length modifier with %z.Chih-Hung Hsieh2015-09-076-35/+60
| | | | | | | | %Z is a GNU extension predating the ISO C99 %z modifier supported by libc5 and no longer recommended. Signed-off-by: Chih-Hung Hsieh <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* readelf: handle_core_item large right shift triggers undefined behaviour.Mark Wielaard2015-09-032-2/+14
| | | | | | | | | | | | | | | | | | | | | | The problem is this: int n = ffs (w); w >>= n; The intent is to shift away up to (and including) the first least significant bit in w. But w is an unsigned int, so 32 bits. And the least significant bit could be bit 32 (ffs counts from 1). Unfortunately a right shift equal to (or larger than) the length in bits of the left hand operand is undefined behaviour. We expect w to be zero afterwards. Which would terminate the while loop in the function. But since it is undefined behaviour anything can happen. In this case, what will actually happen is that w is unchanged, causing an infinite loop... gcc -fsanitize=undefined will catch and warn about this when w = 0x80000000 https://bugzilla.redhat.com/show_bug.cgi?id=1259259 Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Add gnuld check when a NOBITS section falls inside a segment.Mark Wielaard2015-08-172-2/+37
| | | | | | | | | | | | gnuld has a really bad bug where it can place a NOBITS section inside a PT_LOAD segment. Normally that would not work. But it also makes sure that the contents of the file is all zeros. So in practice it is actually a PROGBITS section with all zero data. Except that other tools will think there is an unused gap in the ELF file after the NOBITS section. Recognize and check this pattern in elflint when --gnu is given. Signed-off-by: Mark Wielaard <[email protected]>
* unstrip: Handle debuginfo files with missing SHF_INFO_LINK section flags.Mark Wielaard2015-08-032-5/+38
| | | | | | | | | | | | | | | | With GCC 5 there might be a .rela.plt section with SHF_INFO_LINK set. Buggy binutils objdump might strip it from the section in the debug file. Ignore such differences for relocation sections and put the flag back if necessary. Also improve the error message a little by only discarding the already matched sections if there is an prelink undo section. Otherwise we will report all sections as not matching if the file wasn't prelinked instead of just the non-matching sections. New testfiles generated by gcc5 and binutils objdump added. Signed-off-by: Mark Wielaard <[email protected]>
* strings: Define MAP_POPULATE if not defined alreadyPino Toscano2015-06-272-0/+8
| | | | | | Currently it is available on Linux only, and it is more an hint. Signed-off-by: Pino Toscano <[email protected]>
* nm: First call elf_getdata, then allocate memory.Mark Wielaard2015-06-272-6/+10
| | | | | | | | This catches bogus data early before we might try to allocate giant amounts of memory. Reported-by: Hanno Böck <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* findtextrel: Don't leak memory in process_file.Mark Wielaard2015-06-192-0/+5
| | | | | | | | | | | | When a files do contain textrels we fail to release the segments searched and valgrind will show: 2,560 bytes in 16 blocks are definitely lost in loss record 1 of 1 at 0x40281B5: malloc (in vgpreload_memcheck-x86-linux.so) by 0x804AE63: process_file (findtextrel.c:322) by 0x804909B: main (findtextrel.c:149) Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Make sure phdr2_mem lifetime/scope equals phdr2 pointer.Mark Wielaard2015-06-192-1/+6
| | | | | | | We dont' want GCC to dispose or reuse phdr2_mem stack memory while phdr2 is pointing to it. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Don't leak memory on failure path in handle_gnu_hash.Mark Wielaard2015-06-192-1/+7
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Only check the PT_TLS phdr if it actually exists, warn otherwise.Mark Wielaard2015-06-192-0/+11
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* nm: Fix typo in size check to determine whether we stack allocated memory.Mark Wielaard2015-06-192-1/+6
| | | | | | | | | We allocate GElf_SymX entries, which are larger than plain GElf_Sym structs. The check to see whether we could use stack allocation used the correct sizeof (GElf_SymX), but the check to see if we needed to free was using the incorrect sizeof (GElf_Sym). Which could cause us to leak memory. Signed-off-by: Mark Wielaard <[email protected]>
* strings: Handle failure of getting section name on bogus section data.Mark Wielaard2015-06-192-2/+11
| | | | | | | | If there is something wrong with getting the section data it is likely we won't be able to get the actual section name because the file is somehow corrupted. Try to get the name, but handle failure gracefully. Signed-off-by: Mark Wielaard <[email protected]>
* addr2line: Fix memory leak in print_dwarf_function.Mark Wielaard2015-06-102-5/+15
| | | | | | Always free the scopes returned by dwarf_getscopes () when done. Signed-off-by: Mark Wielaard <[email protected]>
* strip: Just admit we don't support stripping ar archives for now.Mark Wielaard2015-06-102-2/+17
| | | | | | | | | | | | | We try to handle (in-place) stripping of ar archives, but since elf_clone doesn't really support cloning ar members and we don't handle reducing the size of the members, moving the offsets of other members. This causes crashes or writing garbage. Better to just admit that for now we don't support stripping archives. Call error when we see an ELF_K_AR file. https://bugzilla.redhat.com/show_bug.cgi?id=766156 https://lists.fedorahosted.org/pipermail/elfutils-devel/2009-August/000567.html Signed-off-by: Mark Wielaard <[email protected]>
* elfcmp: Don't call memcmp with possible NULL d_buf.Mark Wielaard2015-06-052-1/+6
| | | | | | When d_size is zero d_buf might be NULL. Signed-off-by: Mark Wielaard <[email protected]>
* config: Add -Wstack-usage=262144 (256K) warning check.Mark Wielaard2015-05-272-0/+19
| | | | | | | | All library code now builds with this warning and -Werror enabled. Add exceptions for most of the src tools (ldgeneric, readelf, nm, size, strip, elflint, findtextrel, elfcmp objdump, ranlib, ar and unstrip). Signed-off-by: Mark Wielaard <[email protected]>
* addr2line: Set scopes to NULL after free in handle_address.Mark Wielaard2015-05-272-0/+5
| | | | | | | If dwarf_getscopes_die () fails then scopes might not be reset and we could cause a double free. Signed-off-by: Mark Wielaard <[email protected]>
* addr2line: Add --pretty-print option to show all information on one line.Mark Wielaard2015-05-272-11/+46
| | | | | | | | | | | | | | | | | | This adds an option --pretty-print to eu-addr2line to show all information on one line and all inlines on a line of their own. This mimics the same option from binutils addr2line, but without the short option variant -p. Since we already use -p to select the process. Example output: eu-addr2line --pretty-print -s -i -f -C -p$(pidof firefox) 0x00007f368c6f8915 mozilla::ReentrantMonitor::Wait(unsigned int) at ReentrantMonitor.h:92 (inlined by) mozilla::ReentrantMonitorAutoEnter::Wait(unsigned int) at ReentrantMonitor.h:190 A couple of tests were added to check the output matches that of binutils addr2line. Signed-off-by: Mark Wielaard <[email protected]>
* addr2line: Add demangler support.Mark Wielaard2015-05-273-7/+58
| | | | | | | Makes the -C, --demangle option visible and implements it (ignoring the demangle style argument). Adds a new test with sample output. Signed-off-by: Mark Wielaard <[email protected]>
* addr2line: Add -a, --address. Print address before for each entry.Mark Wielaard2015-05-272-1/+45
| | | | | | Adds test cases with sample output. Signed-off-by: Mark Wielaard <[email protected]>
* addr2line: Always parse addresses as hex numbers.Mark Wielaard2015-05-272-2/+7
| | | | | | | | We would sometimes interpret input addresses as decimal or octal. That could be confusing and isn't what binutils addr2line does. Be consistent and always treat input addresses as hex. Signed-off-by: Mark Wielaard <[email protected]>
* addr2line: Split options in input and output format groups.Mark Wielaard2015-05-272-3/+10
| | | | | | | This makes it clear that -j, --section=NAME is about how input is treated, not how the output is formatted. Signed-off-by: Mark Wielaard <[email protected]>
* strip: Harden against bogus input files. Don't leak tmp debug file on error.Mark Wielaard2015-05-182-77/+204
| | | | | | | | | | There were various places where a bogus/unexpected input file would cause eu-strip to crash. Also on an unexpected error eu-strip would leak the temp debug file it was writing. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c34 Signed-off-by: Mark Wielaard <[email protected]>
* Always call gelf_fsize with EV_CURRENT as argument.Mark Wielaard2015-05-133-13/+13
| | | | | | | | | | Don't trust the elf version given by the file. It could be completely bogus. In which case gelf_fsize just returns zero. Which could cause divide by zero errors. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c34 Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Check gnu_hash has enough data and bitmask_words is not zero.Mark Wielaard2015-05-122-7/+22
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c31 Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Add sanity checks to check_attributes.Mark Wielaard2015-05-122-2/+6
| | | | | | | | | | This is similar to commit 9644aa for readelf print_attributes. Bail out when the vendor name isn't terminated and add overflow check for subsection_len. Note that readelf does handle non-gnu attributes, while elflint doesn't. Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Use Use Elf64_Word for shdr->sh_info cnt.Mark Wielaard2015-05-122-2/+8
| | | | | | | On 32bit using int might overflow. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c31 Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Stop checking section when 2nd hash function shift too big.Mark Wielaard2015-05-122-2/+10
| | | | | | Nothing good comes from trying to continue with a bogus hash function. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c31
* nm: Handle dwarf_linesrc returning NULL.Mark Wielaard2015-05-122-4/+7
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#32 Signed-off-by: Mark Wielaard <[email protected]>
* Replace futimes with futimens.Max Filippov2015-05-053-13/+21
| | | | | | | | futimes is not standard function, and it's not available in uClibc. Use futimens which is POSIX. Suggested-by: Mike Frysinger <[email protected]> Signed-off-by: Max Filippov <[email protected]>
* Drop mtrace calls.Max Filippov2015-05-0410-38/+12
| | | | | | | mtrace is a GNU extension not supported by uClibc and it's believed to not be really used. Drop mtrace() calls and #include <mcheck.h>. Signed-off-by: Max Filippov <[email protected]>
* Link against standalone argp libraryAnthony G. Basile2015-05-042-15/+22
| | | | | | | | | | | | | | argp is not part of POSIX standards and not provided by uClibc or some other standard C libraries. However, it is possible to link against a breakout argp library. One is provided at http://www.lysator.liu.se/~nisse/misc/ This patch tests if libc provides argp otherwise it adds the linker flag -largp where needed in the build system. Signed-off-by: Anthony G. Basile <[email protected]> Signed-off-by: Max Filippov <[email protected]>
* readelf: Fix cie_offset calculation comparison on 32bit.Mark Wielaard2015-04-282-2/+8
| | | | | | | | | gcc -fsanitize=undefined pointed out that on 32bit systems the calculation to match the cie_offset to the cie_id could be undefined because a cie_id could be an unsigned 64bit value while ptrdiff_t is only 32bits. Correct the calculation to use 64bit values. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Check all offsets used in print_gdb_index_section against d_size.Mark Wielaard2015-04-282-2/+18
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c29 Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Always try to print some debug section information.Mark Wielaard2015-04-282-2/+4
| | | | | | | | Even if we cannot create a proper Dwarf dbg we can still print the information of various debug sections. All all debug print section functions already check first they can access the appropriate data. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Add overflow checking to print_gdb_index_section dataend checks.Mark Wielaard2015-04-282-9/+20
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c29 Signed-off-by: Mark Wielaard <[email protected]>
* src: Remove __DATE__ from internal error messages.Mark Wielaard2015-04-145-12/+19
| | | | | | | The date didn't really add much information (it is the day on which the code happened to be compiled) and it prevents creating reproducible builds. Signed-off-by: Mark Wielaard <[email protected]>
* Publish known-dwarf.hPetr Machata2015-03-312-47/+54
| | | | | | | | | | | | | - Make the macro names properly scoped (DWARF_ALL_KNOWN_* and DWARF_ONE_KNOWN_*). - Simplify the calling convention: don't keep track of the comment associated with the enumerator, always use the non-_DESC DWARF_ONE_KNOWN_* callback. - Install known-dwarf.h alongside libdw.h and others. Signed-off-by: Petr Machata <[email protected]>
* elflint: Correct gnu_symbias usage in compare_hash_gnu_hash.Mark Wielaard2015-03-132-14/+20
| | | | | | | | | | | commit 0a545e "elflint: Add various low-level checks." introduced a bug in the handling of the gnu_symbias. The symbol in the bucket should first be compared to STN_UNDEF before applying the bias. And the used symbol index should have the bias added when compared against plain hash symbol. Found on Debian wheezy with run-elflint-self.sh. Signed-off-by: Mark Wielaard <[email protected]>
* elfcmp: Add some NULL and zero checks.Mark Wielaard2015-01-152-7/+19
| | | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c17 Reported-by: Alexander Cherepanov <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Add various low-level checks.Mark Wielaard2015-01-152-52/+236
| | | | | | | | | elflint could crash or hang because it didn't check some low level issues. https://bugzilla.redhat.com/show_bug.cgi?id=1170810 Reported-by: Alexander Cherepanov <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* strings: Produce error when section data falls outside file.Mark Wielaard2015-01-122-2/+20
| | | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810 Reported-by: Alexander Cherepanov <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* nm: Guard against divide by zero in error check.Mark Wielaard2015-01-122-5/+13
| | | | | | | | | Also add section index number in error message. https://bugzilla.redhat.com/show_bug.cgi?id=1170810 Reported-by: Alexander Cherepanov <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* nm: Handle/Skip /SYM64/ index entries.Mark Wielaard2015-01-122-1/+6
| | | | | | Add a testcase to show eu-nm now handles archives with 64-bit symbol table. Signed-off-by: Mark Wielaard <[email protected]>
* nm: Stop processing ar members on first invalid offset.Mark Wielaard2015-01-122-1/+5
| | | | | | | | | Otherwise we will keep looping on that same invalid entry. https://bugzilla.redhat.com/show_bug.cgi?id=1170810 Reported-by: Alexander Cherepanov <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>