summaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* readelf: Print abbrev code for DIE with --debug-dump=info.Mark Wielaard2017-11-293-41/+46
| | | | | | | If there is anything wrong with a DIE it is useful to know what the abbrev code was so you can lookup the abbrev description. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Adjust print_ops formatting.Mark Wielaard2017-11-295-49/+56
| | | | | | | Use only 2 spaces for index (there are never 10000, the most seen in the wild is 64). Adjust re-indenting after GNU_entry_value. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Fix cfi_debug => cfi_debug_bias typo in varlocs assert.Mark Wielaard2017-11-162-1/+5
| | | | | | | | | | We want to check whether the bias is zero, not whether we have dwarf debug_frame cfi. This triggered on a ppc64/ppc64le self-check since it has both debug_frame and eh_frame cfi (other arches often only have eh_frame). Signed-off-by: Mark Wielaard <[email protected]>
* tests: Add varlocs-self and exprlocs-self tests.Mark Wielaard2017-11-155-16/+110
| | | | | | | | | Make sure the testcases (library functions they use) don't crash, triggers self-check/asserts or leaks memory under valgrind. This also helps making sure newer DWARF constructs are handled (when building with -gdwarf-5). Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Handle DW_OP_GNU_variable_value.Mark Wielaard2017-11-105-7/+421
| | | | | | | | | | | | | Handle DW_OP_GNU_variable_value in dwarf_getlocation[_attr,_die]. DW_OP_GNU_variable_value takes one argument a DIE reference that describes a value given by a location of const_value attribute. To test handling of the new operand the varlocs test is adapted to print out all DIEs and attributes with expressions or location lists (the original varlocs test only prints out variables and arguments of function DIEs). Signed-off-by: Mark Wielaard <[email protected]>
* lib: Remove md5 and sha1 implementations.Mark Wielaard2017-10-203-97/+10
| | | | | | Only the testcase md5-sha1-test used them. So also remove that testcase. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Add ELF_E_INVALID_ELF error value.Mark Wielaard2017-10-132-0/+5
| | | | | | | | Add ELF_E_INVALID_ELF which is set when the ELF file data is bad. This is different from ELF_E_INVALID_FILE which is set when the file could not be read. Signed-off-by: Mark Wielaard <[email protected]>
* ar: Check whether ar header values fit.Mark Wielaard2017-09-203-2/+48
| | | | | | | | | | | | | | | | | 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 <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* Drop -rdynamic from deleted-lib.so link stepUlf Hermann2017-08-182-1/+5
| | | | | | | | | | | | -rdynamic is meant for ELF objects that need to export internal symbols to libraries they link to, but deleted-lib.so does not link to anything else and doesn't have any internal symbols. Note that the "deleted" test program does link to deleted-lib.so, but deleted-lib.so being a shared object, will automatically export the (non-hidden) "libfunc" symbol anyway. Signed-off-by: Ulf Hermann <[email protected]>
* Check for -z,defs, -z,relro, -fPIC, -fPIE before using themUlf Hermann2017-08-182-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | Those flags are not available on all platforms, and omitting them when not available will not cause any harm. In particular: -z,defs disallows undefined symbols in object files. This option is unsupported if the target binary format enforces the same condition already. Furthermore it is only a compile time sanity check. When it is omitted, the same binary is produced. -z,relro instructs the loader to mark sections read-only after loading the library, where possible. This is a hardening mechanism. If it is unavailable, the functionality of the code is not affected in any way. -fPIC instructs the compiler to produce position independent code. While this is preferable to relocatable code, relocatable code also works and may even be faster. Relocatable code might just be loaded into memory multiple times for different processes. -fPIE is the same thing as -fPIC for executables rather than shared libraries. Signed-off-by: Ulf Hermann <[email protected]>
* tests: robustify run-strip-nothing.sh against unstripped libc_nonshared.aDmitry V. Levin2017-08-092-1/+5
| | | | | | | | | When glibc's libc_nonshared.a contains objects with debug info, this debug info is leaked into every output file produced by gcc. Change run-strip-nothing.sh to use "gcc -s" instead of plain "gcc" for producing objects without debug info. Signed-off-by: Dmitry V. Levin <[email protected]>
* libdw: Add DW_MACRO constants and DW_MACRO_GNU compatibility defines.Mark Wielaard2017-08-022-5/+9
| | | | | | | | | | 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 <[email protected]>
* libdw: Add dwarf_default_lower_bound.Mark Wielaard2017-08-023-2/+93
| | | | | | | | | | Add dwarf_default_lower_bound to get the default lower bound for a language when not given as attribute for an subrange type. Implementation extracted from dwarf_aggregate_size. Add a test to check all known language codes are handled. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add dwarf_line_file.Mark Wielaard2017-07-262-0/+27
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* ppc64: Add HTM SPRs support to readelfGustavo Romero2017-07-253-15/+20
| | | | | | | | | | Since POWER8, PowerPC 64 supports Hardware Transactional Memory, which has three special purpose registers associated to it: tfhar, tfiar, and texasr. This commit add HTM SPRs set as known note type so it's possible to use 'readelf --notes' to inspect the HTM SPRs in a coredump file generated in such a machines. Signed-off-by: Gustavo Romero <[email protected]>
* strip: Deal with ARM data marker symbols pointing to debug sections.Mark Wielaard2017-07-243-2/+110
| | | | | | | | | | | | | | | | | | | 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 <[email protected]>
* backends: Don't depend on linux/bpf.h to compile bpf disassembler.Mark Wielaard2017-07-242-4/+5
| | | | | | | | | We only need a few constants and one structure definition from linux/bpf. Just define those in a local lib/bpf.h file. This makes sure the bpf disassembler is always build and included even when elfutils is build on older GNU/Linux systems (and even on other platforms). Signed-off-by: Mark Wielaard <[email protected]>
* Write to /dev/null rather than /dev/zeroUlf Hermann2017-07-242-1/+5
| | | | | | | /dev/zero is meant for reading zeroes. /dev/null is for writing into nirvana. Signed-off-by: Ulf Hermann <[email protected]>
* strip: Add --keep-section=SECTION and --remove-section=SECTION.Mark Wielaard2017-07-173-2/+696
| | | | | | | | | | | | | | | | | | | | | 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 <[email protected]>
* strip: Don't generate empty output file when nothing to do.Mark Wielaard2017-06-143-0/+70
| | | | | | | | | | | | | | | | | 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 <[email protected]>
* strip: Make sure old .shstrab is removed when eu-strip recreates it.Mark Wielaard2017-06-142-0/+12
| | | | | | | | | | | | | | | | 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 <[email protected]>
* ppc64: Add minimal fallback unwinder.Mark Wielaard2017-06-126-1/+43
| | | | | | | | | | | | | This adds a minimal fallback unwinder for ppc64[le] in case we cannot find CFI for a particular address. It simply always sets the program counter to the link register, picks the previous stack pointer from the backchain, and the previous link register from the LR save area. This is enough for some simple situations when we don't have CFI and seems to work nicely in the case of perf with libdw powerpc support: https://lkml.org/lkml/2017/5/18/998 Signed-off-by: Mark Wielaard <[email protected]>
* Add frame pointer unwinding for aarch64 and relax backtrace testcases.Ulf Hermann2017-05-027-1/+54
| | | | | | | | | | | | | | | If we don't find any debug information for a given frame, we usually cannot unwind any further. However, the binary in question might have been compiled with frame pointers, in which case we can look up the well known frame pointer locations in the stack snapshot and use them to bridge the frames without debug information. Relax the backtrace core testcases a little by allowing a duplicate sigusr2 frame or a backtrace ending with an invalid register. Both of which can happen if the frame pointer unwinder guesses slightly wrong. Signed-off-by: Ulf Hermann <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* Add i386 frame pointer unwinder.Mark Wielaard2017-05-025-1/+42
| | | | | | | Add a simple i386_unwind.c frame pointer unwinder as fallback if DWARF/CFI unwinding fails. Signed-off-by: Mark Wielaard <[email protected]>
* Add frame pointer unwinding as fallback on x86_64Ulf Hermann2017-05-025-0/+39
| | | | | | | | | | | | | | If we don't find any debug information for a given frame, we usually cannot unwind any further. However, the binary in question might have been compiled with frame pointers, in which case we can look up the well known frame pointer locations in the stack snapshot and use them to bridge the frames without debug information. The "unwind" hook is the right place for this as it is so far only used on s390 and called only after trying to unwind with debug information. Signed-off-by: Ulf Hermann <[email protected]>
* tests: Add core backtracegen check and regen ppc32 backtrace testfiles.Mark Wielaard2017-05-025-0/+30
| | | | | | | | | | | | | Add a check to check_core to make sure the backtracegen function is found in the backtrace. This function is in the middle of the backtrace in the main executable and if not found it means the backtrace was incomplete or the frame was skipped (which could happen on a bad frame pointer only unwind). This showed that the ppc32 backtrace test files were missing DWARF CFI for the main executable. Regenerated them to include full CFI. Signed-off-by: Mark Wielaard <[email protected]>
* Revert "Optionally allow unknown symbols in the backtrace tests"Mark Wielaard2017-05-023-31/+17
| | | | | | | | | | | | | | This reverts commit f9971cb422df39adea7e8c7e22689b879e39c626. Allowing no symbol resolving at all makes it too hard to see whether the test actually tests anything. But do keep "address out of range" as allowed error in check_err. This can be interpreted as DWARF not available (if end of callstack marker is missing, which it unfortunately often is missing even if CFI is available.). Signed-off-by: Mark Wielaard <[email protected]>
* Avoid YESSTR and NOSTRUlf Hermann2017-04-263-18/+24
| | | | | | | | | 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 <[email protected]>
* Clean up linux-specific system includesUlf Hermann2017-04-263-2/+7
| | | | | | We only include them where we actually need them and only on linux. Signed-off-by: Ulf Hermann <[email protected]>
* Add missing peel_type.c test for commit f339da.Mark Wielaard2017-04-071-0/+119
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Support checking ELF files with compressed sections.Mark Wielaard2017-04-054-2/+37
| | | | | | | | | 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 <[email protected]>
* libdw: Fix dwarf_peel_type infinite loop.Mark Wielaard2017-04-053-3/+77
| | | | | | | | | | We were calling dwarf_attr_integrate () in the die in the loop instead of on the result. Which would cause an infinite loop when die != result. Add a testcase that explicitly checks this case. https://sourceware.org/bugzilla/show_bug.cgi?id=21330 Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Always update last_offset in updatefile and updatemmap.Mark Wielaard2017-04-043-2/+459
| | | | | | | | | | | | | | | | When ELF section data was used, but not updated or marked as dirty and there also existed non-dirty sections and some padding was needed between the sections (possibly because of alignment) then elf_update might write "fill" over some of the existing data. This happened because in that case the last_position was not updated correctly. Includes a new testcase fillfile that fails before this patch by showing fill instead of the expected data in some section data. It succeeds with this patch. https://sourceware.org/bugzilla/show_bug.cgi?id=21199 Signed-off-by: Mark Wielaard <[email protected]>
* backends: Add support for EM_PPC64 GNU_ATTRIBUTES.Mark Wielaard2017-03-244-3/+22
| | | | | | | | ppc64 and ppc64le ELF files can also contain a power specific .gnu.attributes section. Add support for those and recognize the new GNU_Power_ABI_FP Single-precision hard float value. Signed-off-by: Mark Wielaard <[email protected]>
* Check for existence of mempcpyUlf Hermann2017-02-172-0/+5
| | | | | | If it doesn't exist, provide a definition based on memcpy. Signed-off-by: Ulf Hermann <[email protected]>
* Optionally allow unknown symbols in the backtrace testsUlf Hermann2017-02-143-12/+38
| | | | | | | | This is useful to test unwinding without debug information. The binaries being examined might still have frame pointers that allow us to bridge the unknown symbols. Signed-off-by: Ulf Hermann <[email protected]>
* Make the backtrace-data test helper more robustUlf Hermann2017-02-142-3/+19
| | | | | | | | | When unwinding by frame pointer the unwinder might ask for invalid addresses. We don't have to fail the test in this case. In fact any broken dwarf information can lead to requests for invalid addresses, also without frame pointer unwinding. Signed-off-by: Ulf Hermann <[email protected]>
* readelf: Add optional --symbols[=SECTION] argument to select section name.Mark Wielaard2016-11-172-0/+15
| | | | | | | | | 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]>
* Add GCC7 -Wimplicit-fallthrough support/fixes.Mark Wielaard2016-11-103-1/+7
| | | | | | | | | | | 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]>
* tests: unstrip: Add test for mismatched .strtab sectionsKevin Cernekee2016-10-246-3/+33
| | | | | | | | | | Current unstrip test cases either have no .symtab/.strtab in the stripped binary, or .strtab sections that are identical between the stripped and debuginfo binaries. Add a test case where .symtab/.strtab in the stripped binary contains a small subset of the full unstripped data. Signed-off-by: Kevin Cernekee <[email protected]>
* lib: Provide MAX and MIN in system.hAkihiko Odaki2016-10-122-1/+5
| | | | | | | | | | 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]>
* tests: Fix --enable-gcov tests build. Add libdw to LDADD for asm_tsts.Mark Wielaard2016-08-302-9/+13
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* tests: Simplify backtrace-native tests. Drop raise jmp patching for x86_64.Mark Wielaard2016-08-253-22/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The backtrace-native[-biarch] testcase was a little too clever in places making it unreliable. On x86_64 we tried to make an interesting backtrace by catching the first signal and then replacing the pc with the address of the first instruction of a function. Then we would raise a new signal, through ptrace, to create a backtrace that went from a signal frame into a frame at the start of a function. That way we could check that we were trying to fetch the correct CFI for the (jmp) function even at the first instruction (normally we would substract one from the return address to get at the call address). This works as long as the CFI for the jmp() function is identical to the CFI for the raise() function that we "patched away". Unfortunately on Fedora rawhide glibc has a rewritten raise() implementation that has different CFI, in particular the CFA is calculated differently. Making the testcase fail because we cannot properly unwind from jmp(). So this special x86_64 case has been disabled (the code is still there in case we find another way to test this in a more reliable way). On Ubuntu there have been spurious testcase failures because see_exec_module found two Dwfl_Modules with the same path. This would trigger an assert. Although this might indicate some issue (maybe we are not parsing the proc/pid/map correctly?) it isn't clear that it really is a bug. Since the assert is not very helpful finding any actual bug and for the testcase it is only necessary that the first Dwfl_Module that represents the executable is found we just pick that Dwfl_Module and don't iterate through any of the others. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Add testfilesparc64attrs.o.bz2 to EXTRA_DIST.Mark Wielaard2016-08-242-0/+5
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* sparc: fix the printing of hw capabilities object attributes.Jose E. Marchesi2016-08-243-1/+23
| | | | | | | | | | The GNU_Sparc_HWCAPS and GNU_Sparc_HWCAPS2 object attributes comprise a set of hardware capabilities that may (or not) be present in the target machine for which the object was compiled. This patch adds the support for printing a nicely formatted comma-separated list with the selected hw capabilities. Signed-off-by: Jose E. Marchesi <[email protected]>
* strip: Handle compressed relocation target sections.Mark Wielaard2016-08-152-0/+16
| | | | | | | | | | | | | | | 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]>
* Fix bpf disassembler for _FORTIFY_SOURCERichard Henderson2016-08-112-1/+6
| | | | | | | | It's illegal to skip positional operands for printf. Rearrange the printing of the instructions to use exactly the operands required. Also, fix printing of mod operations: s/%/%%/ in the print format. Also, fix printing of endian operations: remove extra spaces.
* dwelf: Add string table functions from ebl.Mark Wielaard2016-08-036-61/+74
| | | | | | | | | | | | | | | | 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]>
* Add m68k testsAndreas Schwab2016-07-1110-5/+122
| | | | Signed-off-by: Andreas Schwab <[email protected]>
* libelf: Allow updating phdrs for any e_type.Mark Wielaard2016-07-114-3/+209
| | | | | | | | | | | | | | | | | | | | | | | | elf[32|64]_updatenull would sanity check the e_type before allowing to update the phdrs. This prevents creating an ET_REL file with phdrs. It also prevents creating any vendor specific ELF file having phdrs. We only check this when updating/writing out the file. But we would just read such files. Don't prevent people from creating unexpected ELF files. elflint will warn for such files. While writing a new testcase for this another bug was found that prevented updating a just created phdr because elf_getphdrnum would sanity check the phdr offset in the file (which doesn't exist yet). Fix that by only doing such a sanity check if the phdrs haven't been read in or created yet. This second bug should have been found by the existing elfshphehdr test, but that test contained a typo checking elf_getphdrnum. It tested that the called failed when there were no phdrs, but then elf_getphdrnum should simply succeed and return zero. https://bugzilla.redhat.com/show_bug.cgi?id=1352232 Signed-off-by: Mark Wielaard <[email protected]>