Commit Graph

123 Commits

Author SHA1 Message Date
Ian Lance Taylor
b9e40069c0 libbacktrace: use correct names in #undef of ELF macros
Patch from Joseph Koshy.

	* elf.c (ELFMAGn): In #undef rename from ELF_MAGn.
2025-11-06 11:30:33 -08:00
Ian Lance Taylor
2f67a3abfd libbacktrace: recognize PE bigobj objects at configure time
Patch from Christopher Wellons.

	* filetype.awk: Recognize PE bigobj objects at configure time.
2025-09-28 14:48:55 -07:00
John David Anglin
793921876c libbacktrace: Add hpux fileline support
Fixes libstdc++ stacktrace tests.

2025-04-10  John David Anglin  <danglin@gcc.gnu.org>

libbacktrace/ChangeLog:
	* fileline.c (hpux_get_executable_path): New.
	(fileline_initialize): Add pass to get hpux executable path.
2025-04-10 14:43:16 -07:00
Richard Biener
0bb163df97 bootstrap/119680 - fix cross-compiler build with --enable-host-shared
It seems that at least when cross-compiling at least collect2 pulls
in objects from libbacktrace.a which is linked via LIBDEPS.  But
libbacktrace for the host is only built -fPIC with --enable-host-shared
but not -fPIE with --enable-host-pie so this fails.  The following
teaches libbacktrace about --enable-host-pie and handles it similar
to libcpp.

	PR bootstrap/119680
libbacktrace/
	* configure.ac (--enable-host-pie): Handle by setting PIC_FLAG
	to -fPIE.
	* configure: Regenerate.
2025-04-10 14:40:29 -07:00
Jonathan Wakely
f1104f3270 libbacktrace: Use correct type in backtrace_atomic_store_int
libbacktrace/ChangeLog:

	* atomic.c (backtrace_atomic_store_int): Use int for old value.
2025-04-07 20:49:15 -07:00
Ian Lance Taylor
0034e33946 libbacktrace: add cast to avoid undefined shift
Patch from pgerell@github.

	* elf.c (elf_uncompress_lzma_block): Add casts to avoid
	potentially shifting a value farther than its type size.
2025-02-10 15:04:43 -08:00
Ian Lance Taylor
78af4ffa26 libbacktrace: add casts to avoid undefined shifts
Patch from pgerell@github.

	* elf.c (elf_fetch_bits): Add casts to avoid potentially shifting
	a value farther than its type size.
	(elf_fetch_bits_backward): Likewise.
	(elf_uncompress_lzma_block): Likewise.
	(elf_uncompress_lzma): Likewise.
2025-01-30 15:24:13 -08:00
Richard Earnshaw
5da31b9952 arm: libbacktrace: Check if the compiler supports __sync atomics
Older versions of the Arm architecture lack support for __sync
operations directly in hardware and require calls into appropriate
operating-system hooks.  But such hooks obviously don't exist in a
freestanding environment.

Consquently, it is incorrect to assume during configure that such
functions will exist and we need a configure-time check to determine
whether or not these routines will work.

libbacktrace:

	* configure.ac: Always check if the compiler supports __sync
	operations.
	* configure: Regenerated.
2025-01-30 15:24:07 -08:00
Ian Lance Taylor
1db85642e3 libbacktrace: use WIN32_LEAN_AND_MEAN, not WIN32_MEAN_AND_LEAN
Patch from awmorgan.

	* fileline.c: Use WIN32_LEAN_AND_MEAN, not WIN32_MEAN_AND_LEAN.
	* pecoff.c: Likewise.

Fixes #144
2024-11-29 13:21:28 -08:00
Ian Lance Taylor
d48f84034c libbacktrace: recognize new Mach-O DWARF sections
Patch from Pavel Safonov.

These sections are used on macOS Sequoia.

Fixes #136

	* macho.c (dwarf_section_names): Add __debug_addr and
	__debug_line_str.
2024-10-25 15:21:34 -07:00
Benjamin Peterson
531aec7c52 libbacktrace: remove extra characters in README.md 2024-10-20 16:56:59 -07:00
Ian Lance Taylor
3d0be55844 libbacktrace: don't get confused by overlapping address ranges
Fixes https://github.com/ianlancetaylor/libbacktrace/issues/137.

	* dwarf.c (resolve_unit_addrs_overlap_walk): New static function.
	(resolve_unit_addrs_overlap): New static function.
	(build_dwarf_data): Call resolve_unit_addrs_overlap.
2024-10-18 13:04:47 -07:00
Ian Lance Taylor
86885d1404 libbacktrace: update xcoff.c for base_address changes
* xcoff.c (struct xcoff_fileline_data): Change base_address field
	to struct libbacktrace_base_address.
	(xcoff_initialize_syminfo): Change base_address to struct
	libbacktrace_base_address.  Use libbacktrace_add_base.
	(xcoff_initialize_fileline): Likewise.
	(xcoff_lookup_pc): Use libbacktrace_add_base.
	(xcoff_add): Change base_address to struct
	libbacktrace_base_address.
	(xcoff_armem_add, xcoff_add_shared_libs): Likewise.
	(backtrace_initialize): Likewise.
	* Makefile.am (xcoff.lo): Remove unused target.
	(xcoff_32.lo, xcoff_64.lo): New targets.
	* Makefile.in: Regenerate.
2024-08-05 16:54:56 -07:00
Ian Lance Taylor
6ce91a2ef7 libbacktrace: avoid -Wpointer-arith errors
Based on patch from Kirill Müller.

	* configure.ac (ACX_PROG_CC_WARNING_OPTS): Add -Wpointer-arith.
	* pecoff.c (coff_add): Cast void pointers.
	* xcoff.c (xcoff_add): Likewise.
	* configure: Regenerate.
2024-08-05 16:49:57 -07:00
Ian Lance Taylor
0dd27b95f9 libbacktrace: fix syntax of Windows registration functions
Adjust the syntax to keep MSVC happy.

Fixes #131

	* pecoff.c (LDR_DLL_NOTIFICATION): Put function modifier
	inside parentheses.
	(LDR_REGISTER_FUNCTION): Likewise.
2024-07-30 09:28:33 -07:00
Ian Lance Taylor
7e2b7da3d6 libbacktrace: use __has_attribute for fallthrough
Also convert some FALLTHROUGH comments to ATTRIBUTE_FALLTHROUGH.

	* internal.h: Use __has_attribute to check for fallthrough
	attribute.
	* elf.c (elf_zstd_decompress): Use ATTRIBUTE_FALLTHROUGH rather
	than a FALLTHROUGH comment.
2024-07-18 11:37:33 -07:00
Ian Lance Taylor
f37b51de9b libbacktrace: add cast to avoid warning
* print.c (print_syminfo_callback): Add cast to avoid warning.
2024-07-17 18:00:03 -07:00
Ian Lance Taylor
9e10af0e8f libbacktrace: better backtrace_print when no debug info
Fixes #59

	* print.c (print_syminfo_callback): New static function.
	(print_callback): Call backtrace_syminfo if there is no function
	or file name.
2024-07-17 17:40:19 -07:00
Ian Lance Taylor
8e32931a4f libbacktrace: add notes about dl_iterate_phdr to README
* README: Add notes about dl_iterate_phdr.

For #20
2024-07-17 17:06:51 -07:00
Ian Lance Taylor
1dd5c408fe libbacktrace: support FDPIC
Based on patch by Max Filippov.

	* internal.h: If FDPIC, #include <link.h> and/or <sys/link.h>.
	(libbacktrace_using_fdpic): Define.
	(struct libbacktrace_base_address): Define.
	(libbacktrace_add_base): Define.
	(backtrace_dwarf_add): Change base_address to struct
	libbacktrace_base_address.
	* dwarf.c (struct dwarf_data): Change base_address to struct
	libbacktrace_base_address.
	(add_ranges, find_address_ranges, build_ddress_map): Likewise.
	(build_dwarf_data, build_dwarf_add): Likewise.
	(add_low_high_range): Change base_address to struct
	libbacktrace_base_address.  Use libbacktrace_add_base.
	(add_ranges_from_ranges, add_ranges_from_rnglists): Likewise.
	(add_line): Use libbacktrace_add_base.
	* elf.c (elf_initialize_syminfo): Change base_address to struct
	libbacktrace_base_address.  Use libbacktrace_add_base.
	(elf_add): Change base_address to struct
	libbacktrace_base_address.
	(phdr_callback): Likewise.  Initialize base_address.m.
	(backtrace_initialize): If using FDPIC, don't call elf_add with
	main executable; always use dl_iterate_phdr.
	* macho.c (macho_add_symtab): Change base_address to struct
	libbacktrace_base_address.  Use libbacktrace_add_base.
	(macho_syminfo): Change base_address to struct
	libbacktrace_base_address.
	(macho_add_fat, macho_add_dsym, macho_add): Likewise.
	(backtrace_initialize): Likewise.  Initialize base_address.m.
	* pecoff.c (coff_initialize_syminfo): Change base_address to
	struct libbacktrace_base_address.  Use libbacktrace_add_base.
	(coff_add): Change base_address to struct
	libbacktrace_base_address.  Initialize base_address.m.
2024-07-15 17:29:35 -07:00
Ian Lance Taylor
febbb9bff9 libbacktrace: avoid infinite recursion
We could get an infinite recursion in an odd case in which a
.gnu_debugdata section was added to a debug file, and mini_debuginfo
was put into the debug file, and the debug file was put into a
/usr/lib/debug directory to be found by build ID.  This combination
doesn't really make sense but we shouldn't get an infinite recursion.

	* elf.c (elf_add): Don't use .gnu_debugdata if we are already
	reading a debuginfo file.
	* Makefile.am (m2test_*): New test targets.
	(CHECK_PROGRAMS): Add m2test.
	(MAKETESTS): Add m2test_minidebug2.
	(%_minidebug2): New pattern.
	(CLEANFILES): Remove minidebug2 files.
	* Makefile.in: Regenerate.

Fixes #129
2024-07-11 19:36:00 -07:00
Ian Lance Taylor
1023a09511 libbacktrace: improve XCOFF support
libbacktrace/ChangeLog:
2021-06-28  Clément Chigot  <clement.chigot@atos.net>

	* xcoff.c (SSUBTYP_DWRNGES): New define.
	(xcoff_add): Use correct XCOFF DWARF section subtype
	for DEBUG_RANGES. Remove lineoff workaround.
	Adjust base_address.
	(xcoff_initialize_syminfo): Adapt to new base_address.
	(xcoff_lookup_pc): Likewise.
	(xcoff_initialize_fileline): Likewise.
2024-07-11 18:44:19 -07:00
Francois-Xavier Coudert
e652e16083 Libbacktrace: Fix the use of newline in sed replacement
On non-ELF targets, the Makefile needs a newline inside the sed REPLACE
string. The way it is currently done fails with GNU Make < 4, but GCC
only requires "GNU make version 3.80 (or later)".

The portable solution is given in the autoconf manual:
https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Newlines-in-Make-Rules.html

libbacktrace/ChangeLog:

	PR libbacktrace/103822

	* Makefile.am: Fix newline.
	* Makefile.in: Regenerate.
2024-07-11 18:43:01 -07:00
Sergei Trofimovich
96bc206df0 libbacktrace: fix b2test_buildid test on non-english locales
On LANG=ru_RU.UTF-8 'b2test_buildid' test fails due to localized readelf
output:

$ LANG=ru_RU.UTF-8 readelf -n b2test | fgrep 4e37e8f
    ID сборки: 4e37e8fead8d6e8b0a9dc95ea25cd784dff3a393
$ LANG=C readelf -n b2test | fgrep 4e37e8f
    Build ID: 4e37e8fead8d6e8b0a9dc95ea25cd784dff3a393

libbacktrace/

	* install-debuginfo-for-buildid.sh.in: Force non-localized readelf
	output with LANG=C.
2024-07-11 18:42:34 -07:00
Martin Liska
5aa92540f0 libbacktrace: fix UBSAN issues
Fix issues mentioned in the PR.

	PR libbacktrace/103167

libbacktrace/ChangeLog:

	* elf.c (elf_uncompress_lzma_block): Cast to unsigned int.
	(elf_uncompress_lzma): Likewise.
	* xztest.c (test_samples): memcpy only if v > 0.
2024-07-11 18:40:13 -07:00
Iain Sandoe
c5cc931918 Config,Darwin: Allow for configuring Darwin to use embedded runpath.
Recent Darwin versions place contraints on the use of run paths
specified in environment variables.  This breaks some assumptions
in the GCC build.

This change allows the user to configure a Darwin build to use
'@rpath/libraryname.dylib' in library names and then to add an
embedded runpath to executables (and libraries with dependents).

The embedded runpath is added by default unless the user adds
'-nodefaultrpaths' to the link line.

For an installed compiler, it means that any executable built with
that compiler will reference the runtimes installed with the
compiler (equivalent to hard-coding the library path into the name
of the library).

During build-time configurations  any "-B" entries will be added to
the runpath thus the newly-built libraries will be found by exes.

Since the install name is set in libtool, that decision needs to be
available here (but might also cause dependent ones in Makefiles,
so we need to export a conditional).

This facility is not available for Darwin 8 or earlier, however the
existing environment variable runpath does work there.

We default this on for systems where the external DYLD_LIBRARY_PATH
does not work and off for Darwin 8 or earlier.  For systems that can
use either method, if the value is unset, we use the default (which
is currently DYLD_LIBRARY_PATH).
2024-07-11 18:39:24 -07:00
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