summaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
...
* tests/run-sysroot.sh: Delete file with tempfilesAaron Merey2024-07-111-0/+2
| | | | Signed-off-by: Aaron Merey <[email protected]>
* tests/run-sysroot.sh: Avoid testing output that depends on LZMA supportAaron Merey2024-07-111-5/+6
| | | | | | | | | | | | | | | run-sysroot.sh checks whether a backtrace generated by eu-stack contains symbol names found in binaries under a test sysroot. Two frames in the backtrace contain symbol names that must be read from .gnu_debugdata. However this section can only be read if elfutils was built with LZMA support. If not, then the symbol names will be absent from the backtrace. Test the eu-stack output with these 2 frames removed in order to prevent a test failure when LZMA support is missing. Signed-off-by: Aaron Merey <[email protected]>
* tests/Makefile.am: Add run-sysroot.sh to EXTRA_DISTAaron Merey2024-07-041-1/+1
| | | | Signed-off-by: Aaron Merey <[email protected]>
* tests: add test for eu-stack --sysrootMichal Sekletar2024-07-043-2/+48
|
* rework debuginfod configuryFrank Ch. Eigler2024-06-041-1/+1
| | | | | | | | | | | | Rework the top level configure.ac to systematize the debuginfod-related checks, inferences, rejections, and configuration outputs. Tested by hand on a F39 machine, installing/uninstalling the various dependencies one at a time, and rerunning the configury with / without --enable-*debuginfod* flags. Signed-off-by: Frank Ch. Eigler <[email protected]>
* PR29472: debuginfod: add metadata query webapi, C api, clientFrank Ch. Eigler2024-06-033-5/+121
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch extends the debuginfod API with a "metadata query" operation. It allows clients to request an enumeration of file names known to debuginfod servers, returning a JSON response including the matching buildids. This lets clients later download debuginfo for a range of versions of the same named binaries, in case they need to to prospective work (like systemtap-based live-patching). It also lets server operators implement prefetch triggering operations for popular but slow debuginfo slivers like kernel vdso.debug files on fedora. Implementation requires a modern enough json-c library, namely 0.11, which dates from 2014. Without that, debuginfod client/server bits will refuse to build. % debuginfod-find metadata file /bin/ls % debuginfod-find metadata glob "/usr/local/bin/c*" Refactored several functions in debuginfod-client.c, because the metadata search logic is different for multiple servers (merge all responses instead of first responder wins). Documentation and testing are included. Signed-off-by: Ryan Goldberg <[email protected]> Signed-off-by: Frank Ch. Eigler <[email protected]>
* readelf: Fix printing of DW_FORM_strx and DW_MACRO parsingMark Wielaard2024-05-143-2/+817
| | | | | | | | | | | | | | | | | | | | | | print_form_data didn't take the offset_len (4 or 8 bytes) into account causing the wrong entry to be read from .debug_str_offsets. print_debug_macro_section did sanity checking before calling print_form_data, which does sanity checking itself. The sanity check for DW_FORM_strx was wrong in print_debug_macro_section (but correct in print_form_data). Add a new testfile for run-readelf-macro.sh, this one compiled with clang -gdwarf-5 -fdebug-macro. * src/readelf.c (print_form_data): Multiply by offset_len for strx_val. (print_debug_macro_section): Remove sanity checks before calling print_form_data. * tests/testfileclangmacro.bz2: New testfile. * tests/Makefile.am (EXTRA_DIST): Add testfileclangmacro.bz2. * tests/run-readelf-macro.sh: Add testfileclangmacro output. Signed-off-by: Mark Wielaard <[email protected]>
* debuginfod: PR28204 - RPM IMA per-file signature verificationRyan Goldberg2024-05-107-0/+194
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Recent versions of Fedora/RHEL include per-file cryptographic signatures in RPMs, not just an overall RPM signature. This work extends debuginfod client & server to extract, transfer, and verify those signatures. These allow clients to assure users that the downloaded files have not been corrupted since their original packaging. Downloads that fail the test are rejected. Clients may select a desired level of enforcement for sets of URLs in the DEBUGINFOD_URLS by inserting special markers ahead of them: ima:ignore pay no attention to absence or presence of signatures ima:enforcing require every file to be correctly signed The default is ima:ignore mode. In ima:enforcing mode, section queries are forced to be entire-file downloads, as it is not possible to crypto-verify just sections. IMA signatures are verified against a set of signing certificates. These are normally published by distributions. The environment variable $DEBUGINFOD_IMA_CERT_PATH contains a colon-separated path for finding DER or PEM formatted certificates / public keys. These certificates are assumed trusted. The profile.d scripts transcribe /etc/debuginfod/*.certdir files into that variable. As for implementation: * configure.ac: Add --enable-debuginfod-ima-verification parameter. Add --enable-default-ima-cert-path=PATH parameter. Check for libimaevm (using headers only). * config/Makefile.am: Install defaults into /etc files. * config/profile.{csh,sh}.in: Process defaults into env variables. * config/elfutils.spec.in: Add more buildrequires. * debuginfod/debuginfod.cxx (handle_buildid_r_match): Added extraction of the per-file IMA signature for the queried file and store in http header. (find_globbed_koji_filepath): New function. (parse_opt): New flag --koji-sigcache. * debuginfod/debuginfod-client.c (debuginfod_query_server): Added policy for validating IMA signatures (debuginfod_validate_imasig): New function, with friends. * debuginfod/debuginfod.h.in: Added DEBUGINFOD_IMA_CERT_PATH_ENV_VAR. * debuginfod/Makefile.am: Add linker flags for rpm and crypto. * doc/debuginfod-client-config.7: Document DEBUGINFOD_IMA_CERT_PATH, update DEBUGINFOD_URLS. * doc/debuginfod.8: Document --koji-sigcache. * doc/debuginfod-find.1, doc/debuginfod_find_debuginfo.3: Update SECURITY. * tests/run-debuginfod-ima-verification.sh: New test. * tests/debuginfod-ima: Some new files for the tests. * tests/Makefile.am: run/distribute them. Signed-off-by: Ryan Goldberg <[email protected]> Signed-off-by: Frank Ch. Eigler <[email protected]>
* config/profile.fish.in: Prevent bracketed variables and unmatched wildcard ↵Aaron Merey2024-04-171-0/+3
| | | | | | | | | | | | | | | errors Fish does not support bracketed variables in scripts. Remove brackets from the variable ${prefix} in profile.fish before installation to prevent this error. Fish also raises an error for unmatched wildcards, except for special cases like the set command. Use a wildcard to match .urls files using the set command instead of cat to prevent an unmatched wildcard error when no .urls files are found. Signed-off-by: Aaron Merey <[email protected]>
* tests/.gitignore: Use correct spelling for get-files-define-fileAaron Merey2024-04-171-1/+1
| | | | | | Replace get-files-define_file with get-files-define-file. Signed-off-by: Aaron Merey <[email protected]>
* PR31637: debuginfod-find -v SIGSEGVFrank Ch. Eigler2024-04-121-0/+3
| | | | | | | Correct an off-by-one error in argv parsing. Reported-By: <[email protected]> Signed-Off-By: Frank Ch. Eigler <[email protected]>
* libdw: dwarf_getsrcfiles should not imply dwarf_getsrclinesAaron Merey2024-04-117-4/+266
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dwarf_getsrcfiles causes line data to be read in addition to file data. This is wasteful for programs which only need file or directory names. Debuginfod server is one such example. Fix this by moving the srcfile reading in read_srclines into a separate function read_srcfiles. This change improves debuginfod server's max resident set size by up to 75% during rpm indexing. * libdw/dwarf_getsrcfiles.c (dwarf_getsrcfiles): Replace dwarf_getsrclines and __libdw_getsrclines with __libdw_getsrcfiles. * libdw/dwarf_getsrclines.c (read_line_header): New function. (read_srcfiles): New function. (read_srclines): Move srcfile reading into read_srcfiles. Add parameter to use cached srcfiles if available. Also merge srcfiles with any files from DW_LNE_define_file. (__libdw_getsrclines): Changed to call get_lines_or_files. (__libdw_getsrcfiles): New function. Calls get_lines_or_files. (get_lines_or_files): New function based on the old __libdw_getsrclines. Call read_srcfiles if linesp is NULL, otherwise call read_srclines. Pass previously read srcfiles to read_srclines if available. * libdw/dwarf_macro_getsrcfiles.c (dwarf_macro_getsrcfiles): Replace __libdw_getsrclines with __libdw_getsrcfiles. * libdw/libdwP.h (__libdw_getsrcfiles): New declaration. * tests/.gitignore: Add new test binary. * tests/get-files.c: Verify that dwarf_getsrcfiles does not cause srclines to be read. * tests/get-lines.c: Verify that srclines can be read after srcfiles have been read. * tests/Makefile.am: Add new testfiles. * tests/get-files-define-file.c: Print file names before and after reading DW_LNE_define_file. * tests/run-get-files.sh: Add get-files-define-file test. * tests/testfile-define-file.bz2: New testfile. Copy of testfile36.debug but with a line program consisting of two DW_LNE_define_file opcodes. https://sourceware.org/bugzilla/show_bug.cgi?id=27405 Signed-off-by: Aaron Merey <[email protected]>
* Add support for HexagonMatheus Tavares Bernardino2024-04-043-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements initial support for the Hexagon architecture. The Hexagon ABI spec can be seen at https://lists.llvm.org/pipermail/llvm-dev/attachments/20190916/21516a52/attachment-0001.pdf A hello_hexagon.ko test is also added. $ head tests/test-suite.log [...] # TOTAL: 275 # PASS: 269 # SKIP: 6 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 $ cat tests/run-strip-reloc-ko.sh.log [...] runtest hello_hexagon.ko PASS run-strip-reloc-ko.sh (exit status: 0) * backends/Makefile.am (modules): Add hexagon. (hexagon_SRCS): New var for hexagon_init.c and hexagon_symbol.c. (libebl_backends_a_SOURCES): Add hexagon_SRCS. * backends/hexagon_init.c: New file. * backends/hexagon_reloc.def: Likewise. * backends/hexagon_symbol.c: Likewise. * libebl/eblopenbackend.c (hexagon_init): Declare. (machines): Add hexagon. * libelf/elf-knowledge.h: Add hexagon e_flags values, section indices and and relocs. * src/elflint.c (valid_e_machine): Add EM_QDSP6. * tests/Makefile.am (EXTRA_DIST): Add hello_hexagon.ko.bz2. * tests/hello_hexagon.ko.bz2: New test file. * tests/run-strip-reloc-ko.sh: Add hello_hexagon.ko. Signed-off-by: Matheus Tavares Bernardino <[email protected]>
* tests, config: Add more .gitignore filesMark Wielaard2024-04-012-1/+4
| | | | | | | | | | | | Some new tests and one configure file weren't in .gitignore. Also we made a copy of libelf.h in tests/ which should be an symlink. * config/.gitignore: Add profile.fish. * tests/.gitignore: Add funcretval_test_struct, libelf.h and system-elf-gelf-test. * tests/Makefile.am (libelf.h): Make symlink instead of copy. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Use bash for run-debuginfod-client-profile.shMark Wielaard2024-03-271-1/+1
| | | | | | | | | The test uses set -o pipefail which is a bashism and so the test fails on systems where /bin/sh isn't bash. * tests/run-debuginfod-client-profile.sh: Use bash. Signed-off-by: Mark Wielaard <[email protected]>
* config: Make sure profile.sh succeeds with set -e and set -o pipefailMark Wielaard2024-03-272-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | profile.sh might fail with set -o pipefail because: cat /dev/null "${prefix}/etc/debuginfod"/*.urls 2>/dev/null | tr '\n' ' ' might fail when there isn't an *.urls file the first command in the pipe fails (the 2>/dev/null is there to hide that failure). This can be fixed by adding || : at the end. This works because : always succeeds and produces no outpur which is what the script expects when the command would fail. Also add a new testcase that runs profile.sh with bout set -e and set -o pipefail. * config/profile.sh.in: Add || : at end of pipe. * tests/run-debuginfod-client-profile.sh: New test. * tests/Makefile.am (TESTS): Add run-debuginfod-client-profile.sh. (EXTRA_DIST): Likewise. https://sourceware.org/bugzilla/show_bug.cgi?id=31562 Signed-off-by: Mark Wielaard <[email protected]>
* riscv: Partial implementation of flatten_aggregateMark Wielaard2024-03-205-0/+150
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dwfl_module_return_value_location would fail on riscv for functions which return a (small) struct. This patch implements the simplest cases of flatten_aggregate in backends/riscv_retval.c. It just handles structs containing one or two members of the same base type which fit completely or in pieces in one or two general or floating point registers. It also adds a specific test case run-funcretval-struct.sh containing small structs of ints, longs, floats and doubles. All these testscases now work for riscv. There is already a slightly more extensive testcase for this in tests/run-funcretval.sh but that only has a testcase for aarch64. * backends/riscv_retval.c (flatten_aggregate_arg): Implement for the simple cases where we have a struct with one or two members of the same base type. (pass_by_flattened_arg): Likewise. Call either pass_in_gpr_lp64 or pass_in_fpr_lp64d. (riscv_return_value_location_lp64ifd): Call flatten_aggregate_arg including size. * tests/Makefile.am (TESTS): Add run-funcretval-struct.sh and run-funcretval-struct-native.sh. (check_PROGRAMS): Add funcretval_test_struct. (funcretval_test_struct_SOURCES): New. (EXTRA_DIST): Add run-funcretval-struct.sh, funcretval_test_struct_riscv.bz2 and run-funcretval-struct-native.sh. * tests/funcretval_test_struct_riscv.bz2: New test binary. * tests/run-funcretval-struct-native.sh: New test. * tests/run-funcretval-struct.sh: Likewise. https://sourceware.org/bugzilla/show_bug.cgi?id=31142 Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Handle overflowed DW_SECT_INFO offsets in DWARF package file indexesOmar Sandoval2024-03-017-1/+266
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Meta uses DWARF package files for our large, statically-linked C++ applications. Some of our largest applications have more than 4GB in .debug_info.dwo, but the section offsets in .debug_cu_index and .debug_tu_index are 32 bits; see the discussion here [1]. We implemented a workaround/extension for this in LLVM. Implement the equivalent in libdw. To test this, we need files with more than 4GB in .debug_info.dwo. I created these artificially by editing GCC's assembly output. They compress down to 6KB. I test them from run-large-elf-file.sh to take advantage of the existing checks for large file support. 1: https://discourse.llvm.org/t/dwarf-dwp-4gb-limit/63902. * libdw/dwarf_end.c (dwarf_package_index_free): New function. * tests/testfile-dwp-4-cu-index-overflow.bz2: New test file. * tests/testfile-dwp-4-cu-index-overflow.dwp.bz2: New test file. * tests/testfile-dwp-5-cu-index-overflow.bz2: New test file. * tests/testfile-dwp-5-cu-index-overflow.dwp.bz2: New test file. * tests/testfile-dwp-cu-index-overflow.source: New file. * tests/run-large-elf-file.sh: Check testfile-dwp-5-cu-index-overflow and testfile-dwp-4-cu-index-overflow. Signed-off-by: Omar Sandoval <[email protected]>
* tests/run-getsrc-die.sh: Skip tests if objcopy failsAaron Merey2024-02-291-16/+20
| | | | | | | | run-getsrc-die.sh uses objcopy to remove .debug_aranges from testfiles. Depending how objcopy is built, it may fail to recognize the format of the testfiles. Skip the remaining tests if objcopy fails. Signed-off-by: Aaron Merey <[email protected]>
* libdw: Apply DWARF package file section offsets where appropriateOmar Sandoval2024-03-019-0/+2447
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The final piece of DWARF package file support is that offsets have to be interpreted relative to the section offset from the package index. .debug_abbrev.dwo is already covered, so sprinkle around calls to dwarf_cu_dwp_section_info for the remaining sections: .debug_line.dwo, .debug_loclists.dwo/.debug_loc.dwo, .debug_str_offsets.dwo, .debug_macro.dwo/.debug_macinfo.dwo, and .debug_rnglists.dwo. With all of that in place, we can finally test various libdw functions on dwp files. * libdw/dwarf_getlocation.c (initial_offset): Call dwarf_cu_dwp_section_info and add offset to start_offset. * libdw/dwarf_getmacros.c (get_macinfo_table): Call dwarf_cu_dwp_section_info and add offset to line_offset. (get_offset_from): Call dwarf_cu_dwp_section_info and add offset to *retp. * libdw/dwarf_getsrcfiles.c (dwarf_getsrcfiles): Call dwarf_cu_dwp_section_info and pass offset to __libdw_getsrclines. * libdw/dwarf_next_lines.c (dwarf_next_lines): Call dwarf_cu_dwp_section_info and add offset to stmt_off. * libdw/libdwP.h (str_offsets_base_off): Call dwarf_cu_dwp_section_info and add offset. (__libdw_cu_ranges_base): Ditto. (__libdw_cu_locs_base): Ditto. * tests/run-all-dwarf-ranges.sh: Check testfile-dwp-5 and testfile-dwp-4. * tests/run-declfiles.sh: Ditto. * tests/run-get-lines.sh: Ditto. * tests/run-next-lines.sh: Ditto. * tests/run-varlocs.sh: Ditto. * tests/run-get-files.sh: Check testfile-dwp-5, testfile-dwp-5.dwp, testfile-dwp-4, and testfile-dwp-4.dwp * tests/run-next-files.sh: Ditto. * tests/run-dwarf-getmacros.sh: Check testfile-dwp-5 and testfile-dwp-4-strict. * tests/run-get-units-split.sh: Ditto. Signed-off-by: Omar Sandoval <[email protected]>
* Add __libdw_getdierangesAaron Merey2024-02-291-3/+19
| | | | | | | | | | | | | | | | | | | __libdw_getdieranges builds an aranges list by iterating over each CU and recording each address range. This function is an alternative to dwarf_getaranges. dwarf_getaranges attempts to read address ranges from .debug_aranges, which might be absent or incomplete. This patch replaces dwarf_getaranges with __libdw_getdieranges in dwarf_addrdie and dwfl_module_addrdie. The existing tests in run-getsrc-die.sh are also rerun with .debug_aranges removed from the testfiles. https://sourceware.org/bugzilla/show_bug.cgi?id=22288 https://sourceware.org/bugzilla/show_bug.cgi?id=30948 Signed-off-by: Aaron Merey <[email protected]>
* libdw: Handle split DWARF in dwarf_decl_fileOmar Sandoval2024-02-294-3/+329
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Calling dwarf_decl_file on a split DWARF DIE fails this assertion: dwarf_decl_file.c:72: dwarf_decl_file: Assertion `cu->files != NULL && cu->files != (void *) -1l' failed. This is because dwarf_decl_file calls dwarf_getsrclines to populate cu->files. For normal units, cu->files is cached by dwarf_getsrclines when it parses the line number information. However, for split units, the line number information is parsed for the skeleton unit, then copied to the split unit's cu->lines. Split units have their own file name table, so cu->files is not copied. The obvious solution is to use dwarf_getsrcfiles instead of relying on implicit caching. Also add a test case for dwarf_decl_file. * libdw/dwarf_decl_file.c (dwarf_decl_file): Use dwarf_getsrcfiles instead of dwarf_getsrclines. * tests/Makefile.am (check_PROGRAMS): Add declfiles. (TESTS): Add run-declfiles.sh. (EXTRA_DIST): Add run-declfiles.sh. (declfiles_LDADD): New variable. * tests/declfiles.c: New test. * tests/run-declfiles.sh: New test. Signed-off-by: Omar Sandoval <[email protected]>
* libdw: Parse DWARF package file index sectionsOmar Sandoval2024-02-1511-2/+352
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The .debug_cu_index and .debug_tu_index sections in DWARF package files are basically hash tables mapping a unit's 8 byte signature to an offset and size in each section used by that unit [1]. Add support for parsing and doing lookups in the index sections. We look up a unit in the index when we intern it and cache its hash table row in Dwarf_CU. Then, a new function, dwarf_cu_dwp_section_info, can be used to look up the section offsets and sizes for a unit. This will mostly be used internally in libdw, but it will also be needed in static inline functions shared with eu-readelf. Additionally, making it public it makes dwp support much easier for external tools that do their own low-level parsing of DWARF information, like drgn [2]. 1: https://gcc.gnu.org/wiki/DebugFissionDWP#Format_of_the_CU_and_TU_Index_Sections 2: https://github.com/osandov/drgn * libdw/dwarf.h: Add DW_SECT_TYPES. * libdw/libdwP.h (Dwarf): Add cu_index and tu_index. (Dwarf_CU): Add dwp_row. (Dwarf_Package_Index): New type. (__libdw_dwp_find_unit): New declaration. (dwarf_cu_dwp_section_info): New INTDECL. Add DWARF_E_UNKNOWN_SECTION. * libdw/Makefile.am (libdw_a_SOURCES): Add dwarf_cu_dwp_section_info.c. * libdw/dwarf_end.c (dwarf_end): Free dwarf->cu_index and dwarf->tu_index. * libdw/dwarf_error.c (errmsgs): Add DWARF_E_UNKNOWN_SECTION. * libdw/libdw.h (dwarf_cu_dwp_section_info): New declaration. * libdw/libdw.map (ELFUTILS_0.190): Add dwarf_cu_dwp_section_info. * libdw/libdw_findcu.c (__libdw_intern_next_unit): Call __libdw_dwp_find_unit, and use it to adjust abbrev_offset and assign newp->dwp_row. * libdw/dwarf_cu_dwp_section_info.c: New file. * tests/Makefile.am (check_PROGRAMS): Add cu-dwp-section-info. (TESTS): Add run-cu-dwp-section-info.sh (EXTRA_DIST): Add run-cu-dwp-section-info.sh and new test files. (cu_dwp_section_info_LDADD): New variable. * tests/cu-dwp-section-info.c: New test. * tests/run-cu-dwp-section-info.sh: New test. * tests/testfile-dwp-4-strict.bz2: New test file. * tests/testfile-dwp-4-strict.dwp.bz2: New test file. * tests/testfile-dwp-4.bz2: New test file. * tests/testfile-dwp-4.dwp.bz2: New test file. * tests/testfile-dwp-5.bz2: New test file. * tests/testfile-dwp-5.dwp.bz2: New test file. * tests/testfile-dwp.source: New file. Signed-off-by: Omar Sandoval <[email protected]>
* Handle DW_AT_decl_file 0Aaron Merey2024-02-123-1/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Modify dwarf_decl_file to support DW_AT_decl_file with value 0. Because of inconsistencies in the DWARF 5 spec, it is ambiguous whether DW_AT_decl_file value 0 is a valid .debug_line file table index for the main source file or if it means that there is no source file specified. dwarf_decl_file interprets DW_AT_decl_file 0 as meaning no source file is specified. This works with DWARF 5 produced by gcc, which duplicates the main source file name at index 0 and 1 of the file table and avoids using DW_AT_decl_file 0. However clang uses DW_AT_decl_file 0 for the main source index with no duplication at another index. In this case dwarf_decl_file will be unable to find the file name of the main file. This patch changes dwarf_decl_file to treat DW_AT_decl_file 0 as a normal index into the file table, allowing it to work with DWARF 5 debuginfo produced by clang. As for earlier DWARF versions which exclusively use DW_AT_decl_file 0 to indicate that no source file is specified, dwarf_decl_file will now return the name "???" if called on a DIE with DW_AT_decl_file 0. https://sourceware.org/bugzilla/show_bug.cgi?id=31111 Signed-off-by: Aaron Merey <[email protected]>
* unstrip: Call adjust_relocs no more than once per section.Aaron Merey2024-02-064-1/+153
| | | | | | | | | | | | | | | | | | | | | | | During symtab merging, adjust_relocs might be called multiple times on some SHT_REL/SHT_RELA sections. In these cases it is possible for a relocation's symbol index to be correctly mapped from X to Y during the first call to adjust_relocs but then wrongly remapped from Y to Z during the second call. Fix this by adjusting relocation symbol indices just once per section. Also add stable sorting for symbols during symtab merging so that the symbol order in the output file's symtab does not depend on undefined behaviour in qsort. Note that adjust_relocs still might be called a second time on a section during add_new_section_symbols. However since add_new_section_symbols generates its own distinct symbol index map, this should not trigger the bug described above. https://sourceware.org/bugzilla/show_bug.cgi?id=31097 Signed-off-by: Aaron Merey <[email protected]>
* PR 30991: srcfiles tarball featureHousam Alamour2024-02-052-6/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * srcfiles.cxx: Introduce new --zip option that places all the source files associated with a specified dwarf/elf file into a zip file and sends it to stdout. Files may be fetched from debuginfod (if applicable) or locally as a backup. Added -b option to disable the backup of checking for files locally in -z mode. * run-srcfiles-self.sh: Added test-case for the new zip feature that archives the source files of the srcfiles tool and checks archive integrity. An additional test ensures that if debuginfod is enabled, the files are fetched and archived properly while maintaing integrity. * debuginfod-subr.sh: On very slow/remote storage, it can take O(minute) to finish indexing the entire elfutils build tree, so a wait_ready4 shell function is one way to let a longer debuginfod wait operation work. * srcfiles.1, NEWS: Added documentation for the new zip feature. * configure.ac: Simplify check for libarchive for srcfiles.cxx by integrating it into the same check for debuginfod. * Makefile.am: build with local copy of debuginfod-client. Example: % ./src/srcfiles -z -e /bin/ls > output.zip https://sourceware.org/bugzilla/show_bug.cgi?id=30991 Signed-off-by: Housam Alamour <[email protected]>
* libelf: Treat elf_memory as if using ELF_C_READ_MMAPMark Wielaard2024-02-022-5/+157
| | | | | | | | | | | | | | | | | | | | | | | | An Elf handle created through elf_memory was treated as if opened with ELF_C_READ. Which means libelf believed it had read the memory itself and could simply write to it if it wanted (because it wasn't mmaped directly on top of a file). This causes issues when that memory was actually read-only. Work around this by pretending the memory was actually read with ELF_C_READ_MMAP (so directly readable, but not writable). Add extra tests to elfgetzdata to check using elf_memory with read-only memory works as expected. * libelf/elf_memory.c (elf_memory): Call __libelf_read_mmaped_file with ELF_C_READ_MMAP. * tests/elfgetzdata.c (main): Add new "mem" option. * tests/run-elfgetzdata.sh: Also run all tests with new "mem" option. https://sourceware.org/bugzilla/show_bug.cgi?id=31225 Reported-by: Derek Bruening <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* tests: fix build against upcoming `gcc-14` (`-Werror=calloc-transposed-args`)Sergei Trofimovich2023-12-211-1/+1
| | | | | | | | | | | | | | `gcc-14` added a new `-Wcalloc-transposed-args` warning recently. It detected minor infelicity in `calloc()` API usage in `elfutils`: elfstrmerge.c: In function 'main': elfstrmerge.c:450:32: error: 'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args] 450 | newscnbufs = calloc (sizeof (void *), newshnums); | ^~~~ elfstrmerge.c:450:32: note: earlier argument should specify number of elements, later size of each element Signed-off-by: Sergei Trofimovich <[email protected]>
* Add helper function for basenameKhem Raj2023-12-212-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | musl does not provide GNU version of basename and lately have removed the definiton from string.h [1] which exposes this problem. It can be made to work by providing a local implementation of basename which implements the GNU basename behavior, this makes it work across C libraries which have POSIX implementation only. [1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 * lib/system.h (xbasename): New static inline functions. Poison basename. * libdw/dwarf_getsrc_file.c (dwarf_getsrc_file): Use xbasename. * libdwfl/core-file.c (dwfl_core_file_report): Likewise. * libdwfl/dwfl_module_getsrc_file.c (dwfl_module_getsrc_file): Likewise. * libdwfl/dwfl_segment_report_module.c (dwfl_segment_report_module): Likewise. * libdwfl/find-debuginfo.c (find_debuginfo_in_path): Likewise. * libdwfl/link_map.c (report_r_debug): Likewise. * libdwfl/linux-kernel-modules.c (try_kernel_name): Likewise. * src/addr2line.c (print_dwarf_function): Likewise. (print_src): Likewise. * src/ar.c (do_oper_insert): Likewise. And cast away const in entry.key assignment. * src/nm.c (show_symbols): Use xbasename. * src/stack.c (module_callback): Likewise. * src/strip.c (handle_elf): Likewise. * tests/show-die-info.c: Include system.h. (dwarf_tag_string): Use xbasename. * tests/varlocs.c: Likewise. * debuginfod/debuginfod.cxx: Move include system.h to the end. (register_file_name): Rename basename to filename. Signed-off-by: Khem Raj <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* tests: Don't redirect output to /dev/null in run-native-test.shMark Wielaard2023-12-181-6/+9
| | | | | | | | | | By redirecting all output to /dev/null in run-native-test.sh the run-native-test.sh.log file will be empty on failures. This makes it hard to figure out what went wrong. * tests/run-native-test.sh: Remove /dev/null redirects. Signed-off-by: Mark Wielaard <[email protected]>
* libdwfl: Correctly handle corefile non-contiguous segmentsAaron Merey2023-11-215-3/+151
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is possible for segments of different shared libaries to be interleaved in memory such that the segments of one library are located in between non-contiguous segments of another library. For example, this can be seen with firefox on RHEL 7.9 where multiple shared libraries could be mapped in between ld-2.17.so segments: [...] 7f0972082000-7f09720a4000 00000000 139264 /usr/lib64/ld-2.17.so 7f09720a4000-7f09720a5000 00000000 4096 /memfd:mozilla-ipc (deleted) 7f09720a5000-7f09720a7000 00000000 8192 /memfd:mozilla-ipc (deleted) 7f09720a7000-7f09720a9000 00000000 8192 /memfd:mozilla-ipc (deleted) 7f0972134000-7f0972136000 00000000 8192 /usr/lib64/firefox/libmozwayland.so 7f0972136000-7f0972137000 00002000 4096 /usr/lib64/firefox/libmozwayland.so 7f0972137000-7f0972138000 00003000 4096 /usr/lib64/firefox/libmozwayland.so 7f0972138000-7f0972139000 00003000 4096 /usr/lib64/firefox/libmozwayland.so 7f097213a000-7f0972147000 00000000 53248 /usr/lib64/firefox/libmozsqlite3.so 7f0972147000-7f097221e000 0000d000 880640 /usr/lib64/firefox/libmozsqlite3.so 7f097221e000-7f0972248000 000e4000 172032 /usr/lib64/firefox/libmozsqlite3.so 7f0972248000-7f0972249000 0010e000 4096 /usr/lib64/firefox/libmozsqlite3.so 7f0972249000-7f097224c000 0010e000 12288 /usr/lib64/firefox/libmozsqlite3.so 7f097224c000-7f0972250000 00111000 16384 /usr/lib64/firefox/libmozsqlite3.so 7f0972250000-7f0972253000 00000000 12288 /usr/lib64/firefox/liblgpllibs.so [...] 7f09722a3000-7f09722a4000 00021000 4096 /usr/lib64/ld-2.17.so 7f09722a4000-7f09722a5000 00022000 4096 /usr/lib64/ld-2.17.so dwfl_segment_report_module did not account for the possibility of interleaving non-contiguous segments, resulting in premature closure of modules as well as failing to report modules. Fix this by removing segment skipping in dwfl_segment_report_module. When dwfl_segment_report_module reported a module, it would return the index of the segment immediately following the end address of the current module. Since there's a chance that other modules might fall within this address range, dwfl_segment_report_module instead returns the index of the next segment. This patch also fixes premature module closure that can occur in dwfl_segment_report_module when interleaving non-contiguous segments are found. Previously modules with start and end addresses that overlap with the current segment would have their build-ids compared with the current segment's build-id. If there was a mismatch, that module would be closed. Avoid closing modules in this case when mismatching build-ids correspond to distinct modules. https://sourceware.org/bugzilla/show_bug.cgi?id=30975 Signed-off-by: Aaron Merey <[email protected]>
* tests: Add test for duplicate entries in archiveAleksei Vetrov2023-11-213-1/+9
| | | | | | | | | | | | Test dwfl-report-offline-memory against an archive that contains non-relocatable ELFs with the same name and contents. * tests/test-ar-duplicates.a.bz2: New test file. * tests/run-dwfl-report-offline-memory.sh: Test new test-ar-duplicates.a.bz2. * tests/Makefile.am (EXTRA_DIST): Add test-ar-duplicates.a.bz2. Signed-off-by: Aleksei Vetrov <[email protected]>
* tests: Restructure run-debuginfod-response-headers.shMark Wielaard2023-11-191-9/+14
| | | | | | | | | | | run-debuginfod-response-headers.sh does occassionally fail because it might scan an rpm more than once. Try to fix this by making sure all files that debuginfod is supposed to scan are ready before the server starts. And to explicitly wait till the first scan is ready and done before testing 'scanned_files_total{source=".rpm archive"}' instead of sending an kill -USR1. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Optionally dump all units in dwarf-getmacrosOmar Sandoval2023-11-022-10/+44
| | | | | | | If instead of a CU offset an empty string is given as the second argument, dump all units. Signed-off-by: Omar Sandoval <[email protected]>
* tests: Handle DW_MACRO_{define,undef}_{strx,sup} in dwarf-getmacrosOmar Sandoval2023-11-022-0/+10
| | | | Signed-off-by: Omar Sandoval <[email protected]>
* readelf: Support .gdb_index version 9Aaron Merey2023-11-024-2/+96
| | | | | | | | | | | Version 9 adds a "shortcut table" to the index. The shortcut table contains the name and language of the main function, if it exists. A testcase added in this patch uses an executable written with Fortran. This is because gdb does not currently populate the shortcut table of C/C++ programs (see sourceware PR30996). Signed-off-by: Aaron Merey <[email protected]>
* PR 30000: debuginfod-find should have a source-list verbHousam Alamour2023-10-242-1/+51
| | | | | | | | | | | | | | | | | | * seclines.cxx: Introduce new tool that compiles a list of source files associated with a specified dwarf/elf file. This compilation relies on searching the dwarf debug information, which can be automatically retrieved via debuginfod using libdwfl functions when required. The target file can encompass various types, such as an executable, a coredump, a running process, or the currently executing kernel. The source file names are rendered as unique entries and then displayed on the standard output. * run-srcfiles-self.sh: New test-case for tool. https://sourceware.org/bugzilla/show_bug.cgi?id=30000 Signed-off-by: Housam Alamour <[email protected]>
* PR30962: debuginfod: full paths for X-DEBUGINFOD-FILE/ARCHIVE response headersFrank Ch. Eigler2023-10-111-4/+4
| | | | | | | | | | Previous code was inconsistent in offering basename versus full pathname for these headers. The documentation was not explicit on this issue. We now simplify by always passing full names back, and document this in the debuginfod.8 man page, along with pointers to how to use proxy front-end servers to strip them if needed. Signed-Off-By: Frank Ch. Eigler <[email protected]>
* libdw: Handle split DWARF in dwarf_entrypcOmar Sandoval2023-10-032-7/+11
| | | | | | | | | If a DIE has no DW_AT_entry_pc attribute, dwarf_entrypc looks for DW_AT_low_pc in that DIE. But for a split compilation unit DIE, DW_AT_low_pc is in the corresponding skeleton DIE, so this fails. dwarf_lowpc already handles this fallback, so use it instead. Signed-off-by: Omar Sandoval <[email protected]>
* tests: Fix system_elf_gelf_test build without system libelf.hMark Wielaard2023-09-041-1/+6
| | | | | | | | | | | | | | | | | | | | | | If there is no system libelf.h then the building of system-elf-gelf-test fails with: ../libelf/gelf.h:32:10: fatal error: libelf.h: No such file or directory This is because although the testcase includes the headers as ../libelf/libelf.h and ../libelf/gelf.h, gelf.h itself does an Fix this by putting a copy of libelf.h in the build test directory and using -I. for building system-elf-gelf-test. * tests/Makefile.am (BUILT_SOURCES): New for libelf.h. (CLEANFILES): Add libelf.h. (libelf.h): New target that copies srdir libelf.h. (system_elf_gelf_test_CPPFLAGS): Add -I. https://sourceware.org/bugzilla/show_bug.cgi?id=30812 Signed-off-by: Mark Wielaard <[email protected]>
* libelf, readelf, elflint: Add RELR supportMark Wielaard2023-08-292-3/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Handle RELR as defined here: https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/YT2RrjpMAwAJ Introduce new ELF_T_RELR Elf_Type and handle it for SHT_RELR. Check various properties in elflint. Print RELR relocations in readelf. Just the entries with -U. Just the addresses with -N. And addresses plus symbol/offsets by default. Also add a test to check that gelf.h works with the system elf.h. * libebl/eblsectiontypename.c (ebl_section_type_name): Add RELR to knownstype. * libelf/elf32_updatenull.c (updatenull_wrlock): Handle sh_entsize for SHT_RELR. * libelf/gelf.h (GElf_Relr): New typedef for Elf64_Relr. * libelf/gelf_fsize.c (__libelf_type_sizes): Add ELF_T_RELR. * libelf/gelf_xlate.c (__elf_xfctstom): Likewise. * libelf/gelf_xlate.h: Add RELR as FUNDAMENTAL. * libelf/libelf.h (Elf_Type): Add ELF_T_RELR. Add RELR defines/typedefs if undefined in system elf.h. * libelf/libelfP.h: Define ELF32_FSZ_RELR and ELF64_FSZ_RELR. * src/elflint.c (check_reloc_shdr): Check she_entsize for ELF_T_RELR. (check_relr): New function. (check_dynamic): Handle DT_RELR. (special_sections): Add SHT_RELR. (check_sections): Call check_relr. * src/readelf.c (print_relocs): Also accept a Dwfl_Module. (handle_relocs_relr): New function. (print_dwarf_addr): Make static and declare early. (process_elf_file): Pass dwflmod to print_relocs. (handle_dynamic): Handle DT_RELRSZ and DTRELRENT. * system-elf-gelf-test.c: New test. * Makefile.am (TESTS): Add system-elf-gelf-test. (check_PROGRAMS): Likewise. (system_elf_gelf_test_CPPFLAGS): New variable. (system_elf_gelf_test_LDADD): Likewise. https://sourceware.org/bugzilla/show_bug.cgi?id=28495 Signed-off-by: Mark Wielaard <[email protected]>
* tests: run-lfs-symbols.sh needs gawkSam James2023-07-201-2/+2
| | | | | | | | | | | | | | | | | With awk=mawk, I get: ``` FAIL: run-lfs-symbols.sh ======================== First sanity-check that LFS detection works. checking ./testfile-nolfs awk: line 3: syntax error at or near / FAIL run-lfs-symbols.sh (exit status: 2) ``` * tests/run-lfs-symbols.sh: Call 'gawk' instead of 'awk'. Signed-off-by: Sam James <[email protected]>
* tests: Use -N for run-readelf-self.sh.Mark Wielaard2023-06-171-1/+1
| | | | | | | | | The test doesn't really need to resolve all addresses and -N is really slow. * tests/run-readelf-self.sh: Add -N. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Split up run-strip-reloc.sh test in three subtestsMark Wielaard2023-06-176-158/+171
| | | | | | | | | | | | | | | | | | | | | | | | This test can take a very long time under valgrind (on s390x). Split it into three tests for kernel modules, self-test and ppc64. That way the tests can run in parallel and each individual test produces a result (so the buildbot won't time out). Also change the comparison to elfcmp instead of doing readelf -a on both and compare the textual output. * tests/run-strip-reloc.sh: Split out generic part into... * tests/strip-reloc-subr.sh: ...this file. * tests/run-strip-reloc-ko.sh: New file. * tests/run-strip-reloc-ppc64.sh: New file. * tests/run-strip-reloc-self.sh: New file. * tests/Makefile.am (TESTS): Remove run-strip-reloc.sh. Add run-strip-reloc-ko.sh, run-strip-reloc-self.sh and run-strip-reloc-ppc64.sh (EXTRA_DIST): Remove run-strip-reloc.sh. Add strip-reloc-subr.sh, run-strip-reloc-ko.sh, run-strip-reloc-self.sh and run-strip-reloc-ppc64.sh. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Really split run-copymany-sections.sh into separate testsMark Wielaard2023-06-175-45/+3
| | | | | | | | | | | | | | | | The previous commit 4fac1627c "tests: Split run-copymany-sections.sh into separate tests" duplicated the tests because they were still also done in the new test-copymany-subr.sh. Remove them really this time. Also don't source test-subr.sh twice, test-copymany-subr.sh already sources it, so the subtests don't have to also do it again. * tests/test-copymany-subr.sh: Remove actual tests. * tests/run-copymany-be32.sh: Remove . $srcdir/test-subr.sh. * tests/run-copymany-be64.sh: Likewise. * tests/run-copymany-le32.sh: Likewise. * tests/run-copymany-le64.sh: Likewise. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Split run-copymany-sections.sh into separate testsMark Wielaard2023-06-176-3/+71
| | | | | | | | | | | | | | | | | | | | | | | | This test can take a very long time under valgrind (on s390x). Split it into four tests for big/little endian, 32/64 bit. That way the tests can run in parallel and each individual test produces a result (so the buildbot won't time out). * tests/run-copymany-sections.sh: Delete and move generic part into... * tests/test-copymany-subr.sh: ... here. * tests/run-copymany-be32.sh: New big endian 32 bit tests. * tests/run-copymany-be64.sh: New big endian 64 bit tests. * tests/run-copymany-le32.sh: New little endian 32 bit tests. * tests/run-copymany-le64.sh: New little endian 64 bit tests. * tests/Makefile.am (TESTS): Remove run-copymany-sections.sh, add run-copymany-be32.sh, run-copymany-le32.sh, run-copymany-be64.sh and run-copymany-le64.sh. (EXTRA_DIST): Remove run-copymany-sections.sh. Add test-copymany-subr.sh, run-copymany-be32.sh, run-copymany-le32.sh, run-copymany-be64.sh and run-copymany-le64.sh. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Use readelf -N -w in run-strip-reloc.shMark Wielaard2023-06-171-5/+5
| | | | | | | | | With -N the test runs 4 times faster. And the address lookup is not essential for the test. * tests/run-strip-reloc.sh: Use readelf -N -w. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Add a bit less and slightly smaller sections for addsectionsMark Wielaard2023-06-172-5/+7
| | | | | | | | | | | | | | | | | The run-copymany-sections.sh testcase adds 64K sections (twice) to a couple of times. Each section is just 6 bytes long, but each data section is malloced and freed. That adds up. And is especially slow when running under valgrind. Reduce the number of sections added to 32K (twice) and make each section data just one single zero byte. * tests/addsections.c (add_sections): Don't strdup and free the string ".extra", but just add the empty string. * tests/run-copymany-sections.sh: Call addsections with 32768 instead of 65535. Signed-off-by: Mark Wielaard <[email protected]>
* debuginfod: PR29696: enlarge run-debuginfod-federation-metrics.sh workload againFrank Ch. Eigler2023-06-161-2/+1
| | | | | | Now that the bug is fixed, we can let debuginfod have all the traffic. Signed-off-by: Frank Ch. Eigler <[email protected]>
* PR30316: debuginfod wal checkpointingFrank Ch. Eigler2023-05-091-1/+1
| | | | | | | | | | | | Add a "--scan-checkpoint=NUM" option to debuginfod to control forced synchronization & sqlite -wal checkpointing for the multithreaded scanning process. In absence of this, a server that's busy with other read & write operations can accumulate potentially large SQLITE WAL temporary files. This option causes the server to take intermittent quiescent breaks during scanning, during which the -wal file can be processed and truncated. Signed-off-by: Frank Ch. Eigler <[email protected]>