summaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* libdwelf: add dwelf_elf_remove_debug_relocsupstream/users/amerey/try-remove-relocs2Di Chen2024-10-184-1/+96
| | | | | | | | | | | | | Provide a public function for removing debug section relocations. eu-strip previously contained the code to remove debug section relocations. This patch moves that code into dwelf_elf_remove_debug_relocs. https://sourceware.org/bugzilla/show_bug.cgi?id=31447 Signed-off-by: Di Chen <[email protected]> Signed-off-by: Aaron Merey <[email protected]>
* eu-stacktrace [4/5]: src: add unwind origin diagnostics to eu-stackSerhei Makarov2024-10-171-1/+14
| | | | | | | | | | | | | | | | | | | Since we obtain diagnostics about unwind method, another logical place to show them is in eu-stack. * src/stack.c (show_unwound_source): New global variable. (struct frame): Add unwound_source field. (frame_callback): Copy over unwound_source from Dwfl_Frame. (print_frame): Take unwound_source string and print it. (print_inline_frames): Take unwound_source argument and pass it on, except for subsequent frames where we pass the string "inline". (print_frames): Take unwound_source field from struct frame and pass it on. (parse_opt): Add --cfi-type,-c option to set show_unwound_source. (main): Ditto. * tests/run-stack-i-test.sh: Add testcase for --cfi-type. Signed-off-by: Serhei Makarov <[email protected]>
* Remove usage of "unlocked" variant of stdio print functionsMichael Pratt2024-10-171-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These "unlocked" Linux Standard Base variants of standard functions are not available on some systems that are still capable of building Linux and ELFs. The difference is negligible for simple printing to stdout. POSIX also states for the similar putc_unlocked(): These functions can safely be used in a multi-threaded program if and only if they are called while the invoking thread owns the (FILE *) object, as is the case after a successful call to the flockfile() or ftrylockfile() functions. ... These unlocked versions can be safely used only within explicitly locked program regions, using exported locking primitives. and these precautions were never done. Use the standard forms of these print functions. There is inconsistent use of fputc_unlocked() with putc_unlocked(), so consistently use the safer fputc() instead. Signed-off-by: Michael Pratt <[email protected]>
* PR32218: debuginfod-client: support very long source file namesFrank Ch. Eigler2024-10-167-9/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | | debuginfod clients & servers may sometimes encounter very long source file names. Previously, the client would synthesize a path name like $CACHEDIR/$BUILDID/source-$PATHNAME where $PATHNAME was a funky ##-encoded version of the entire source path name. See https://sourceware.org/PR32218 for a horror case. This can get too long to store as a single component of a file system pathname (e.g. linux/limits.h NAME_MAX), resulting on client-side errors even after a successful download. New code switches encoding of the $PATHNAME part to use less escaping, and a merciless truncation to the tail part of the filename. (We keep the tail rather than the head, so that the extension is preserved, which makes some consumers happier.) To limit collision damage from truncation, we add also insert a goofy hash (4-byte DJBX33A) of the name into the path name. The result is a relatively short name: $CACHEDIR/$BUILDID/source-$HASH-$NAMETAIL This is a transparent change to clients, who are not to make any assumptions about cache file naming structure. However, one existing test did make such assumptions, so is fixed with some globness. A new test is also added, using a pre-baked tarball with a very long srcfile name. Signed-off-by: Frank Ch. Eigler <[email protected]>
* tests/test-subr.sh: Put test_dir under /var/tmp.Frank Ch. Eigler2024-10-101-2/+3
| | | | | | | | | | | | | | | | | Every individual test in elfutils involves a temporary directory. Previous version of this script put that directory under the build tree. That's OK if it's a local disk, but if it's on NFS, then some tests - run-large-elf-file.sh, several run-debuginfod-*.sh - take long enough to run to fail tests intermittently. This patch moves the temp_dir under ${TMPDIR-/var/tmp/}, so it operates at local disk speed rather than whatever-build-filesystem speed. Individual test scripts are all unaffected. (One could consider /tmp instead, which is a RAM disk on modern systems, except that some of the elfutils tests produce GB-sized temporary files. That's probably too big for RAM.) Signed-off-by: Frank Ch. Eigler <[email protected]>
* tests: Fix specifying constant of double typeKhem Raj2024-10-031-1/+1
| | | | | | | | | | | | | | | 'd' suffix seems to be not acceptable by clang compiler Using 'e0' fixes this by keeping value to be same Fixes funcretval_test_struct.c:83:27: error: invalid suffix 'd' on floating constant 83 | dpoint_t dp = dmkpt (3.0d, 1.0d); | ^ funcretval_test_struct.c:83:33: error: invalid suffix 'd' on floating constant 83 | dpoint_t dp = dmkpt (3.0d, 1.0d); | Signed-off-by: Khem Raj <[email protected]>
* srcfiles: Fix compile with --disable-libdebuginfodMark Wielaard2024-09-102-2/+3
| | | | | | | | | | | | | | | | | The eu-srcfiles --no-backup option is only valid when build with libdebuginfod support. Adjust the ENABLE_LIBDEBUGINFOD conditional to not use no_backup anywhere. Also only run the run-srcfiles-self.sh test when debuginfod is enabled. * src/srcfiles.cxx (zip_files): Move endif ENABLE_LIBDEBUGINFOD after no_backup check. * tests/Makefile.am (TESTS): Only add run-srcfiles-self.sh if DEBUGINFOD and !DUMMY_LIBDEBUGINFOD. * tests/run-srcfiles.self.sh: Use local DEBUGINFOD_CACHE_PATH. https://sourceware.org/bugzilla/show_bug.cgi?id=32155 Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Fix printing of .gdb_index symbol table offset.Mark Wielaard2024-09-071-4/+4
| | | | | | | | | | | | | We were printing the addr_off instead of the sym_off. And the testcases all expected the address offset instead of the symbol table offset. * src/readelf.c (print_gdb_index_section): Print sym_off as Symbol table offset. * tests/run-readelf-gdb_index.sh: Fix up all symbol table offsets that were the same as the address offset. Signed-off-by: Mark Wielaard <[email protected]>
* aarch64: Create definitions for AARCH64_RA_SIGN_STATE registerGerman Gomez2024-08-302-0/+2
| | | | | | | | | | | This register will be used to indicate whether a return address is mangled with a PAC or not, in accordance with the DWARF AARCH64 ABI [1]. [1] https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#41dwarf-register-names Signed-off-by: German Gomez <[email protected]> [SteveC: move DW_AARCH64_RA_SIGN_STATE to cfi.h, fix comments] Signed-off-by: Steve Capper <[email protected]>
* tests: When BUILD_STATIC always link against libeuMark Wielaard2024-08-211-1/+1
| | | | | | | | | | libeu is a static library with internal helper functions normally included in all shared libraries. But when linking static (with --enable-gcov) we need to explicitly link it into the test binaries. * tests/Makefile.am (libelf): Add $(libeu) when BUILD_STATIC. Signed-off-by: Mark Wielaard <[email protected]>
* debuginfod: populate _r_seekable on requestOmar Sandoval2024-07-241-0/+48
| | | | | | | | | | | | | | Since the schema change adding _r_seekable was done in a backward compatible way, seekable archives that were previously scanned will not be in _r_seekable. Whenever an archive is going to be extracted to satisfy a request, check if it is seekable. If so, populate _r_seekable while extracting it so that future requests use the optimized path. The next time that BUILDIDS is bumped, all archives will be checked at scan time. At that point, checking again will be unnecessary and this commit (including the test case modification) can be reverted. Signed-off-by: Omar Sandoval <[email protected]>
* debuginfod: populate _r_seekable on scanOmar Sandoval2024-07-2411-2/+174
| | | | | | | | | Whenever a new archive is scanned, check if it is seekable with a little liblzma magic, and populate _r_seekable if so. With this, newly scanned seekable archives will used the optimized extraction path added in the previous commit. Also add a test case using some artificial packages. Signed-off-by: Omar Sandoval <[email protected]>
* tests/run-debuginfod-fd-prefetch-caches.sh: disable fdcache limit checkOmar Sandoval2024-07-241-0/+4
| | | | | | | | | | | | | | | Since commit acd9525e93d7 ("PR31265 - rework debuginfod archive-extract fdcache"), the fdcache limit is only applied when a new file is interned and it has been at least 10 seconds since the limit was last applied. This means that the fdcache can go over the limit temporarily. run-debuginfod-fd-prefetch-caches.sh happens to avoid tripping over this because of lucky sizes of the files used in the test. However, adding new files for an upcoming test exposed this failure. Disable this part of the test for now. Signed-off-by: Omar Sandoval <[email protected]>
* debuginfod: fix skipping <built-in> source fileOmar Sandoval2024-07-242-2/+2
| | | | | | | | | | | | | dwarf_extract_source_paths explicitly skips source files that equal "<built-in>", but dwarf_filesrc may return a path like "dir/<built-in>". Check for and skip that case, too. In particular, the test debuginfod RPMs have paths like this. However, the test cases didn't catch this because they have a bug, too: they follow symlinks, which results in double-counting every file. Fix that, too. Signed-off-by: Omar Sandoval <[email protected]>
* libdwfl: Make dwfl_report_offline_memory work with ELF_C_READ_MMAPAleksei Vetrov2024-07-123-7/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | elf_memory open mode recently changed from ELF_C_READ to ELF_C_READ_MMAP. This broken dwfl_report_offline_memory that changes mode to ELF_C_READ_MMAP_PRIVATE to be compatible with subsequent elf_begin on embedded ELF files. The proper implementation of dwfl_report_offline_memory doesn't change open mode and subsequent elf_begin invocations simply use cmd from the reference Elf*. Add tests to exercise Elf* to trigger the bug caused by incorrect cmd set to Elf*. * libdwfl/offline.c (process_archive): Use archive->cmd instead of hardcoded ELF_C_READ_MMAP_PRIVATE. * libdwfl/open.c (libdw_open_elf): Use elf->cmd instead of hardcoded ELF_C_READ_MMAP_PRIVATE. (__libdw_open_elf_memory): Don't override (*elfp)->cmd. * tests/Makefile.am (dwfl_report_offline_memory): Add libelf as dependency. * tests/dwfl-report-offline-memory.c: Add count_sections to exercise Elf* from dwfl_report_offline_memory. * tests/run-dwfl-report-offline-memory.sh: Add expected number of sections to test invocations. Signed-off-by: Aleksei Vetrov <[email protected]>
* tests/run-sysroot.sh: Call exit_cleanup directlyAaron Merey2024-07-111-0/+2
| | | | | | exit_cleanup needs to be called directly since this test traps EXIT. Signed-off-by: Aaron Merey <[email protected]>
* 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]>