Commit Graph

97 Commits

Author SHA1 Message Date
Ian Lance Taylor
dbb5fd82bc libbacktrace: correct duplicate configury
I accidentally duplicated the autoconf config files in the top level
directory and the config directory.  Fix that, and regenerate
Makefile.in and configure.
2024-07-11 18:36:00 -07:00
Ian Lance Taylor
e3def4fa6e libbacktrace: update libtool.m4 to current GCC HEAD 2024-07-11 18:31:47 -07:00
Martin Liska
ca24ca944e Handle jobserver file descriptors in btest.
PR testsuite/102742

libbacktrace/ChangeLog:

	* btest.c (MIN_DESCRIPTOR): New.
	(MAX_DESCRIPTOR): Likewise.
	(check_available_files): Likewise.
	(check_open_files): Check only file descriptors that
	were not available at the entry.
	(main): Call check_available_files.
2024-07-11 18:17:44 -07:00
Ian Lance Taylor
8c05bcb94f libbacktrace: update copyright years 2024-07-11 18:14:01 -07:00
Ian Lance Taylor
0cb5d00374 libbacktrace: don't fail if symbol size is unknown
* btest.c (test5): Don't fail if symbol size is 0.
	* mtest.c (test5): Likewise.
2024-07-11 18:00:38 -07:00
Ian Lance Taylor
3fda5a8759 libbacktrace: correctly gather Mach-O symbol table
For PR libbacktrace/97082.
	* macho.c (MACH_O_N_EXT): Don't define.
	(MACH_O_N_UNDF): Define.
	(macho_defined_symbol): Don't discard N_EXT symbols.  Do
	discard N_UNDF symbols.
2024-07-11 17:57:40 -07:00
Ian Lance Taylor
d4bdca038e libbacktrace: fix testsuite for clang
* btest.c (test1, test3): Add optnone attribute.
	* edtest.c (test1): Likewise.
	* mtest.c (test1, test3): Likewise.
	* configure.ac: Use -Wno-attributes and -Wno-unknown-attributes.
	* configure: Regenerate.
2024-07-11 16:13:11 -07:00
Ian Lance Taylor
e3e64ddd18 libbacktrace: suggest how to fix missing debug info
* elf.c (elf_nodebug): Suggest -g.
	* macho.c (macho_nodebug): Suggest -g and dsymutil.
	* pecoff.c (coff_nodebug): Suggest -g.

Fixes #122
2024-07-11 15:42:10 -07:00
Ian Lance Taylor
f69acdfbd6 libbacktrace: remove trailing whitespace
* dwarf.c: Remove trailing whitespace.
	* macho.c: Likewise.

Fixes #124
2024-07-11 15:30:09 -07:00
Ian Lance Taylor
4ead348bb4 libbacktrace: it's OK if zstd decompressor sees no backward bits
* elf.c (elf_fetch_bits_backward) Don't fail if no bits are
	available.
2024-06-26 09:12:25 -07:00
Ian Lance Taylor
11427f31a6 libbacktrace: add DLLS as they are loaded
Patch from Björn Schäpers.

	* pecoff.c (struct dll_notification_data): Define.
	(LDR_DLL_NOTIFICATION): New typedef.
	(LDR_REGISTER_FUNCTION): New typedef.
	(struct dll_notification_context): Define.
	(dll_notification): New static function.
	(backtrace_initialize): Register DLL notification.
2024-05-03 15:27:21 -07:00
Ian Lance Taylor
0e933e763f libbacktrace: load Windows modules
Patch from Björn Schäpers <bjoern@hazardy.de>.

	* configure.ac: Checked for tlhelp32.h
	* pecoff.c: Include <tlhelp32.h> if available.
	(backtrace_initialize): Use tlhelp32 api for a snapshot to
	detect loaded modules.
	(coff_add): New argument for the module handle of the file,
	to get the base address.
	* configure, config.h.in: Regenerate.
2024-05-01 10:40:39 -07:00
Ian Lance Taylor
ae1e707dba libbacktrace: test --compress-debug-sections=ARG for each ARG
This should fix a testsuite problem with Solaris ld that supports zlib
but not zlib-gabi.

	* configure.ac: Test --compress-debug-sections=zlib-gnu and
	--compress-debug-sections=zlib-gabi separately, setting new
	automake conditionals.
	* Makefile.am (ctestg, ctestg_alloc): Only build if
	HAVE_COMPRESSED_DEBUG_ZLIB_GNU.
	(ctesta, ctesta_alloc): Only build if
	HAVE_COMPRESSED_DEBUG_ZLIB_GABI.
	(ctestzstd_alloc): New test if HAVE_COMPRESSED_DEBUG_ZSTD.
	* configure, Makefile.in: Regenerate.
2024-04-23 10:17:03 -07:00
Ian Lance Taylor
7ead8c1ea2 libbacktrace: don't assume compressed section is aligned
Patch originally by GitHub user ubyte at
https://github.com/ianlancetaylor/libbacktrace/pull/120.

	* elf.c (elf_uncompress_chdr): Don't assume compressed section is
	aligned.
2024-03-08 13:57:13 -08:00
Ian Lance Taylor
f41cf1fecb libbacktrace: pass -no-install when linking test programs
* Makefile.am (libbacktrace_testing_ldflags): Define.
	(*_LDFLAGS): Add $(libbacktrace_testing_ldflags) for test
	programs.
	* Makefile.in: Regenerate
2024-03-02 13:12:16 -08:00
Ian Lance Taylor
28824f2cc9 libbacktrace: skip all LZMA block header padding bytes
* elf.c (elf_uncompress_lzma_block): Skip all header padding bytes
	and verify that they are zero.

Fixes #118
2024-03-02 12:18:17 -08:00
Ian Lance Taylor
592e9c8727 libbacktrace: use real .opd for debuginfo on ppc64 v1 ABI
PR libbacktrace/114201
	* elf.c (elf_add): Add caller_opd parameter.  Change all callers.
	Release opd data after all recursive calls.
2024-03-02 07:09:12 -08:00
Ian Lance Taylor
36cfdc18ed libbacktrace: read symbol table of debuginfo file
These become another symbol table to search.  This is needed if people
use --strip-all rather than --strip-debug when adding a debuglink
section.

Patch is from GitHub user pickard1.

Fixes #113

	* elf.c (elf_add): Add the symbol table from a debuginfo file.
	* Makefile.am (MAKETESTS): Add buildidfull and gnudebuglinkfull
	variants of buildid and gnudebuglink tests.
	(%_gnudebuglinkfull, %_buildidfull): New patterns.
	* Makefile.in: Regenerate.
2024-02-29 19:48:38 -08:00
Ian Lance Taylor
14818b7783 libbacktrace: support ASLR on Windows
Patch from Björn Schäpers.

	* pecoff.c: Include <windows.h> if available.
	(coff_add): On Windows call GetModuleHandle to get base address.
2023-11-30 11:46:57 -08:00
Ian Lance Taylor
25889d241c libbacktrace: call GetModuleFileNameA on Windows
Patch from Björn Schäpers.

	* fileline.c: Include <windows.h> if available.
	(windows_get_executable_path): New static function.
	(fileline_initialize): Call windows_get_executable_path.
	* configure.ac: Checked for windows.h
	* configure: Regenerate.
	* config.h.in: Regenerate.
2023-11-29 14:09:55 -08:00
Richard Biener
9ae4f4ae44 [libbacktrace] fix up broken test
zstdtest has some inline data where some testcases lack the
uncompressed length field.  Thus it computes that but still
ends up allocating memory for the uncompressed buffer based on
that (zero) length.  Oops.  Causes memory corruption if the
allocator returns non-NULL.

libbacktrace/
	* zstdtest.c (test_samples): Properly compute the allocation
	size for the uncompressed data.
2023-08-03 11:47:58 -07:00
Ian Lance Taylor
c1c86fa2f0 libbacktrace: look for _pgmptr on Windows
Patch from Andres Freund:
	* configure.ac: Check for _pgmptr declaration.
	* fileline.c (fileline_initialize): Check for _pgmfptr before
	/proc/self/exec.
	* configure, config.h.in: Regenerate.
2023-07-31 17:02:14 -07:00
Ian Lance Taylor
cdb64b688d libbacktrace: minor fixes for zstd decompression
* elf.c (elf_zstd_read_fse): Call elf_fetch_bits after reading
	bits, not before.  Add unlikely for error case.
	(elf_zstd_offset_table): Regenerate.
	(elf_zstd_read_huff): Clear 13 entries in weight_mark, not 12.
	(elf_zstd_read_literals): For a single stream adjust by
	total_streams_size, not compressed_size.
2023-03-28 13:10:54 -07:00
Ian Lance Taylor
afe2967c77 libbacktrace: change PC variables from uint64_t to uintptr_t
Change variables holding PC values from uint64_t to uintptr_t.
	Patch by Björn Schäpers.
	* dwarf.c (struct function_addrs): Change low and high fields to
	uintptr_t.
	(struct unit_addrs): Likewise.
	(resolve_addr_index): Change address parameter to uintptr_t*.
	(add_unit_addr): Change lowpc and highpc parameters to uintptr_t.
	(add_function_range): Likewise.
	(struct pcrange): Change lowpc and highpc fields to uintptr_t.
	(add_low_high_range): Change add_range lowpc and highpc parameters
	to uintptr_t.
	(add_ranges_from_ranges): Likewise.
	(add_ranges_from_rnglists): Likewise.
	(add_low_high_range): Chnage lowpc and highpc variables to
	uintpr_t.
	(add_ranges_from_rnglists): Change some local variables to
	uintptr_t.
	(add_ranges_from_ranges): Change base parameter to uintptr_t.
	(add_ranges_from_rnglists): Likewise.
	(read_function_entry): Likewise.
	(resolve_addr_index): Add explicit casts to uintptr_t.
	(update_pcrange): Likewise.
	(add_ranges_from_ranges): Likewise.
	(add_ranges_from_rnglists): Likewise.
	(read_function_entry): Likewise.
2023-01-20 14:25:38 -08:00
Ian Lance Taylor
ad106d5fdd libbacktrace: don't run --build-id tests if it is not supported
PR libbacktrace/108297
	* configure.ac: Test whether linker supports --build-id.
	* Makefile.am: Only run --build-id tests if supported.
	* configure, Makefile.in: Regenerate.
2023-01-06 09:46:08 -08:00
Ian Lance Taylor
da7eff2f37 libbacktrace: unpack literals into output buffer
* elf.c (elf_fetch_backward_init): New static function.
	(ZSTD_TABLE_SIZE): Use huffman scratch space size rather than
	literal size.
	(ZSTD_TABLE_WORK_LIT_SIZE): Don't define.
	(elf_zstd_read_huff): Use elf_fetch_backward_init.
	(elf_zstd_read_literals): New static function.
	(ZSTD_LIT_RAW, ZSTD_LIT_RLE, ZSTD_LIT_HUFF): Don't define.
	(struct elf_zstd_literals): Don't define.
	(elf_zstd_literal_output): Remove static function.
	(elf_zstd_decompress): Use elf_fetch_backward_init and
	elf_zstd_read_literals.  Rewrite literal copying.<
2022-12-16 18:53:11 -08:00
Ian Lance Taylor
fd9442f7b5 libbacktrace: rewrite and simplify main zstd loop
* elf.c (ZSTD_TABLE_*): Use elf_zstd_fse_baseline_entry.
	(ZSTD_ENCODE_BASELINE_BITS): Define.
	(ZSTD_DECODE_BASELINE, ZSTD_DECODE_BASEBITS): Define.
	(elf_zstd_literal_length_base): New static const array.
	(elf_zstd_match_length_base): Likewise.
	(struct elf_zstd_fse_baseline_entry): Define.
	(elf_zstd_make_literal_baseline_fse): New static function.
	(elf_zstd_make_offset_baseline_fse): Likewise.
	(elf_zstd_make_match_baseline_fse): Likewise.
	(print_table, main): Use elf_zstd_fse_baseline_entry.
	(elf_zstd_lit_table, elf_zstd_match_table): Likewise.
	(elf_zstd_offset_table): Likewise.
	(struct elf_zstd_seq_decode): Likewise.  Remove use_rle and rle
	fields.
	(elf_zstd_unpack_seq_decode): Use elf_zstd_fse_baseline_entry,
	taking a conversion function.  Convert RLE to FSE.
	(elf_zstd_literal_length_baseline): Remove.
	(elf_zstd_literal_length_bits): Remove.
	(elf_zstd_match_length_baseline): Remove.
	(elf_zstd_match_length_bits): Remove.
	(elf_zstd_decompress): Use elf_zstd_fse_baseline_entry.  Rewrite
	and simplify main loop.
2022-12-09 17:47:18 -08:00
Ian Lance Taylor
c992dd8a9b libbacktrace: support zstd decompression
Support decompressing --compress-debug-sections=zstd.
	* configure.ac: Check for zstd library and
	--compress-debug-sections=zstd linker option.
	* Makefile.am (zstdtest_*): New targets.
	(zstdtest_alloc_*, ctestzstd_*): New targets.
	(BUILDTESTS): Add zstdtest, zstdtest_alloc, ctestzstd as
	appropriate.
	* elf.c (ELFCOMPRESS_ZSTD): Define.
	(elf_fetch_bits): Rename from elf_zlib_fetch.  Update uses.
	(elf_fetch_bits_backward): New static function.
	(ZLIB_HUFFMAN_*): Rename from HUFFMAN_*.  Update uses.
	(ZLIB_TABLE_*): Rename from ZDEBUG_TABLE_*.  Update uses.
	(ZSTD_TABLE_*): Define.
	(struct elf_zstd_fse_entry): Define.
	(elf_zstd_read_fse): New static function.
	(elf_zstd_build_fse): Likewise.
	(lit): Define if BACKTRACE_GENERATE_ZSTD_FSE_TABLES.
	(match, offset, next, print_table, main): Likewise.
	(elf_zstd_lit_table): New static const array.
	(elf_zstd_match_table, elf_zstd_offset_table): Likewise.
	(elf_zstd_read_huff): New static function.
	(struct elf_zstd_seq_decode): Define.
	(elf_zstd_unpack_seq_decode): New static function.
	(ZSTD_LIT_*): Define.
	(struct elf_zstd_literals): Define.
	(elf_zstd_literal_output): New static function.
	(ZSTD_LITERAL_LENGTH_BASELINE_OFFSET): Define.
	(elf_zstd_literal_length_baseline): New static const array.
	(elf_zstd_literal_length_bits): Likewise.
	(ZSTD_MATCH_LENGTH_BASELINE_OFFSET): Define.
	(elf_zstd_match_length_baseline): New static const array.
	(elf_zstd_match_length_bits): Likewise.
	(elf_zstd_decompress): New static function.
	(ZDEBUG_TABLE_SIZE): New definition.
	(elf_uncompress_chdr): Support ELF_COMPRESS_ZSTD.
	(backtrace_uncompress_zstd): New function.
	(elf_add): Use ZLIB_TABLE_SIZE for zlib-gnu sections.
	* internal.h (backtrace_uncompress_zstd): Declare.
	* zstdtest.c: New file.
	* configure, config.h.in, Makefile.in: Regenerate.
2022-12-07 16:27:12 -08:00
Ian Lance Taylor
8602fda64e libbacktrace: check for sys/link.h
QNX uses sys/link.h rather than link.h for dl_iterate_phdr

Fixes #86

	* configure.ac: Check for sys/link.h.  Use either link.h or
	sys/link.h when checking for dl_iterate_phdr.
	* elf.c: Include sys/link.h if available.
	* configure, config.h.in: Regenerate.
2022-07-08 10:35:17 -07:00
Ian Lance Taylor
7409767403 libbacktrace: don't exit Mach-O dyld library loop on one failure
* macho.c (backtrace_initialize) [HAVE_MACH_O_DYLD_H]: Don't exit
	loop if we can't find debug info for one shared library.

For #85
2022-07-07 16:55:51 -07:00
Ian Lance Taylor
bc78542d20 libbacktrace: don't let "make clean" remove allocfail.sh
* Makefile.am (MAKETESTS): New variable split out of TESTS.
	(CLEANFILES): Replace TESTS with BUILDTESTS and MAKETESTS.
	* Makefile.in: Regenerate.

Fixes #81
2022-07-07 16:18:23 -07:00
Ian Lance Taylor
b6ddb3aa1b libbacktrace: replace fgrep with grep in configure script
Patch by Xi Ruoyao.

	* configure.ac: Use grep instead of fgrep.
	* configure: Regenerate.
2022-07-07 15:46:41 -07:00
Ian Lance Taylor
4d2dd0b172 libbacktrace: don't skip initial aligned byte in uncompressed block
Patch from Rui Ueyama, who says:

libbacktrace occasionally fails to decompress compressed debug info
even though the sections contain valid zlib streams. The cause of the
issue is an off-by-one error.

If a zlib data block is a plain data (uncompressed data), the next two
bytes contain the size of the block. These two bytes value is byte-
aligned, so if we read-ahead more than 8 bits, we need to unread it.

So, the correct condition to determine whether or not we need to
unread a byte is bits >= 8 and not bits > 8. Due to this error,
if the last read bits happened to end at a byte boundary, the next
byte would be skipped. That caused the decompression failure.

This bug was originally reported against the mold linker.
rui314/mold#402

	* elf.c (elf_zlib_inflate): Don't skip initial aligned byte in
	uncompressed block.
2022-04-05 16:10:04 -07:00
Ian Lance Taylor
2446c66076 libbacktrace: gather address ranges from skeleton units
* dwarf.c (find_address_ranges): Handle skeleton units.
	(read_function_entry): Likewise.
2022-02-17 08:27:13 -08:00
Ian Lance Taylor
509f74a2fb libbacktrace: initialize DWARF 5 fields of unit
When I added the fields in 2019-12-13 I forgot to initialize them.

	* dwarf.c (build_address_map): Initialize DWARF 5 fields of unit.
2022-02-16 11:42:40 -08:00
Ian Lance Taylor
c062afc28c configury: support --disable-werror 2022-02-16 11:41:40 -08:00
Ian Lance Taylor
332522e199 configury: update to recent versions
Copied from GCC tip.

Fixes #84
2022-01-18 20:10:43 -08:00
Ian Lance Taylor
d0f5e95a87 config/override.m4: don't require exactly autoconf 2.69
Fixes #71
Fixes #74
2021-05-29 14:17:08 -07:00
Ian Lance Taylor
4f57c99971 libbacktrace: don't special case file 0
It's no longer necessary as file 0 is now set up in all cases.

	* dwarf.c (read_line_program): Don't special case file 0.
	(read_function_entry): Likewise.

Fixes #69
2021-03-02 18:17:36 -08:00
Ian Lance Taylor
59473f7906 libbacktrace: pass -1 to error callback for unrecognized DWARF
PR libbacktrace/98818
	* dwarf.c (dwarf_buf_error): Add errnum parameter.  Change all
	callers.
	* backtrace.h: Update backtrace_error_callback comment.
2021-03-02 13:49:18 -08:00
Ian Lance Taylor
7854b0bc25 libbacktrace: check for objcopy --add-gnu-debuglink using --help
* configure.ac: Check for objcopy --add-gnu-debuglink by using
	objcopy --help.
	* configure: Regenerate
2021-02-11 18:11:18 -08:00
Ian Lance Taylor
dedbe13fda libbacktrace: don't fail tests if dwz fails
* Makefile.am (%_dwz): If dwz fails, use uncompressed debug info.
	* Makefile.in: Regenerate.
2021-01-18 14:58:41 -08:00
Ian Lance Taylor
096650403a libbacktrace: use correct directory/filename for DWARF 5
PR debug/98716
	* dwarf.c (read_v2_paths): Allocate zero entry for dirs and
	filenames.
	(read_line_program): Remove parameter u, change caller.  Don't
	subtract one from dirs and filenames index.
	(read_function_entry): Don't subtract one from filenames index.
2021-01-18 14:57:11 -08:00
Jakub Jelinek
5496ee0a1a Update copyright years. 2021-01-18 14:56:19 -08:00
Ian Lance Taylor
1da441c1b0 libbacktrace: correct buffer overflow tests
* dwarf.c (resolve_string): Use > rather than >= to check whether
	string index extends past buffer.
	(resolve_addr_index): Similarly for address index.
2020-12-04 11:19:55 -08:00
Ian Lance Taylor
f24e9f401f libbacktrace: update README 2020-10-26 13:45:23 -07:00
Ian Lance Taylor
73eb1803b1 libbacktrace: use __attribute__((__fallthrough__))
Use an attribute rather than a comment when falling through a switch case.

	* internal.h (ATTRIBUTE_FALLTHROUGH): Define.
	* elf.c (elf_zlib_inflate): Use ATTRIBUTE_FALLTHROUGH.
2020-10-20 11:50:23 -07:00
Ian Lance Taylor
5009c11398 libbacktrace: replace Tom Sawyer with Opticks
The main source uses Opticks now.
2020-09-30 20:08:56 -07:00
Ian Lance Taylor
3bd25ab355 libbacktrace/ChangeLog:
PR libbacktrace/97082
        * Makefile.am (check_DATA): Add mtest.dSYM if USE_DSYMUTIL.
        * Makefile.in: Regenerate.
2020-09-28 13:57:18 -07:00
Ian Lance Taylor
1286f69fde libbacktrace: only run dsymutil with Mach-O
libbacktrace/ChangeLog:
	PR libbacktrace/97227
	* configure.ac (USE_DSYMUTIL): Define instead of HAVE_DSYMUTIL.
	* Makefile.am: Change all uses of HAVE_DSYMUTIL to USE_DSYMUTIL.
	* configure: Regenerate.
	* Makefile.in: Regenerate.
2020-09-28 13:50:34 -07:00