* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
* dwarf.c (struct pcrange): Define.
(update_pcrange, add_ranges): New static functions.
(add_unit_addr): Change signature to work with add_ranges. Don't
add base_address here.
(add_unit_ranges): Remove.
(find_address_ranges): Replace str/ranges parameters with
dwarf_sections. Use update_pcrange and add_ranges. Change all
callers.
(add_function_range): Change signature to work with add_ranges.
Don't add base_address here.
(add_function_ranges): Remove.
(read_function_entry): Use update_pcrange and add_ranges.
From-SVN: r279154
With gcc 4.8.5, btest_lto ends up with a privatized name for the variable with
name 'global':
...
$ nm btest_lto | grep ' d ' | grep global
0000000000617150 d global.2530
...
which makes test5 fail:
...
test5: unexpected syminfo name got global.2530 expected global
...
Fix this failure by accepting this type of name as a valid name in btest_lto.
2019-02-26 Tom de Vries <tdevries@suse.de>
* btest.c (test5): Allow global.* as minimal symbol name for global.
From-SVN: r269217
If dwz is not available, then the libbacktrace test b3test_dwz_buildid fails
like this:
...
gmake[4]: *** No rule to make target 'b3test_dwz_buildid'
...
Fix this by guarding the test with HAVE_DWZ.
Tested on x86_64 with and without dwz installed.
2019-02-26 Tom de Vries <tdevries@suse.de>
* Makefile.am (TESTS): Only add b3test_dwz_buildid if HAVE_DWZ.
* Makefile.in: Regenerate.
From-SVN: r269204
The call to bsearch in dwarf_lookup_pc can have NULL as base argument when
the nmemb argument is 0. The base argument is required to be pointing to the
initial member of an array of nmemb objects. It is not specified what
constitutes a valid pointer to an array of 0 objects, but glibc declares base
with attribute non-null, so the NULL will trigger a sanitizer runtime error.
Fix this by only calling bsearch if nmemb != 0.
2019-02-12 Tom de Vries <tdevries@suse.de>
PR libbacktrace/81983
* dwarf.c (dwarf_lookup_pc): Don't call bsearch if nmemb == 0.
From-SVN: r268796
The backtrace functions backtrace_full, backtrace_print and backtrace_simple
walk the call stack, but make sure to skip the first entry, in order to skip
over the functions themselves, and start the backtrace at the caller of the
functions.
When compiling with -flto, the functions may be inlined, causing them to skip
over the caller instead.
Fix this by declaring the functions with __attribute__((noinline)).
2019-02-08 Tom de Vries <tdevries@suse.de>
* backtrace.c (backtrace_full): Declare with __attribute__((noinline)).
* print.c (backtrace_print): Same.
* simple.c (backtrace_simple): Same.
From-SVN: r268668
Add handling of the DW_FORM_ref_addr encoding to libbacktrace.
2019-02-08 Tom de Vries <tdevries@suse.de>
PR libbacktrace/78063
* dwarf.c (build_address_map): Keep all parsed units.
(read_referenced_name_from_attr): Handle DW_FORM_ref_addr.
From-SVN: r268663
The 'debugaltlink_name_len =+ 1' bug reported in PR89136 exposes the fact that
the build-id is not verified for the .gnu_debugaltlink.
Fix both problems.
2019-01-31 Tom de Vries <tdevries@suse.de>
PR libbacktrace/89136
* elf.c (elf_add): Read build-id if with_buildid_data. Fix
'debugaltlink_name_len =+ 1'.
From-SVN: r268419
Add test-cases b2test_buildid and b3test_dwz_buildid.
The last one triggers the segfault fixed by "[backtrace] Avoid segfault"
( r268275 ).
2019-01-29 Tom de Vries <tdevries@suse.de>
* install-debuginfo-for-buildid.sh.in: New script.
* Makefile.am (check_PROGRAMS): Add b2test and b3test.
(TESTS): Add b2test_buildid and b3test_dwz_buildid.
* Makefile.in: Regenerate.
* configure.ac (HAVE_ELF): Set with AM_CONDITIONAL.
(READELF): Set with AC_CHECK_PROG.
(install-debuginfo-for-buildid.sh): Generate with AC_CONFIG_FILES.
* configure: Regenerate.
* elf.c (SYSTEM_BUILD_ID_DIR): Factor out of ...
(elf_open_debugfile_by_buildid): ... here.
From-SVN: r268369
In automake files, the check_PROGRAMS variable lists programs that need to be
build for testing, and TESTS lists the programs that need to be run.
The libbacktrace/Makefile.am uses a shortcut:
...
TESTS = $(check_PROGRAMS)
...
to make sure that each program added with:
...
check_PROGRAMS += foo
...
is both build and run.
However, for the allocfail.sh test, we need allocfail to be build and
allocfail.sh to be run:
...
check_PROGRAMS += allocfail
TESTS += allocfail.sh
...
but the shortcut causes allocfail also to be run, which is not required.
Fix this by removing the short-cut, allowing check_PROGRAMS to retain its
original semantics, and introducing a variable BUILDTESTS for programs that
need to be both build and run.
2019-01-29 Tom de Vries <tdevries@suse.de>
* Makefile.am: Replace check_PROGRAMS with BUILDTESTS, except for
allocfail.
(TESTS): Don't add check_PROGRAMS. Add BUILDTESTS.
(check_PROGRAMS): Add BUILDTESTS.
* Makefile.in: Regenerate.
From-SVN: r268360
When generating xcoff_%.c, the last command is a sed command. In case of a
sed failure, this will leave an incomplete file, which will appear as up to
date to make, so consequently it will not be regenerated. Fix this by
sedding into a temporary file instead.
Also, use $< to access the prerequisite xcoff.c, instead of spelling out the
file name once more.
2019-01-28 Tom de Vries <tdevries@suse.de>
* Makefile.am (xcoff_%.c): Generate sed result into temporary file.
Use $< to access prerequisite.
* Makefile.in: Regenerate.
From-SVN: r268344
Currently, when running a libbacktrace testcase t with .gnu_debuglink to
t.debug, and t.debug having a .gnu_debugaltlink to t.alt.debug, a segfault
is triggered when calling strrchr with a NULL string from
elf_find_debugfile_by_debuglink. The NULL string originates from the elf_add
called for the .gnu_debugaltlink, which uses NULL as filename argument.
Fix this by using "" as filename argument instead.
2019-01-25 Tom de Vries <tdevries@suse.de>
* elf.c (elf_add): When handling .gnu_debugaltlink, call elf_add with
filename == "".
* Makefile.am (TESTS): Add btest_dwz_gnudebuglink.
* Makefile.in: Regenerate.
From-SVN: r268269
Create a pattern rule for copying an existing test-case, separating out the
debug information into a .debug file, and referencing the .debug file from
the copied test-case using a .gnu_debuglink.
2019-01-25 Tom de Vries <tdevries@suse.de>
* Makefile.am: Rewrite dtest rule into "%_gnudebuglink" pattern rule.
(TESTS): Rename dtest to btest_gnudebuglink.
* Makefile.in: Regenerate.
From-SVN: r268268
2019-01-23 Tom de Vries <tdevries@suse.de>
* dwarf.c (struct unit): Use size_t for low_offset/high_offset fields.
(units_search, find_unit): Use size_t for offset.
(build_address_map): Use size_t for unit_offset.
From-SVN: r268180
Add test-case to verify that libbacktrace can read debug info that was
compressed with dwz.
2019-01-17 Tom de Vries <tdevries@suse.de>
PR libbacktrace/82857
* configure.ac (DWZ): Set with AC_CHECK_PROG.
(HAVE_DWZ): Set with AM_CONDITIONAL.
* configure: Regenerate.
* Makefile.am (TESTS): Add btest_dwz.
* Makefile.in: Regenerate.
From-SVN: r268032
Handle DW_FORM_GNU_ref_alt which references the .debug_info section in the
.gnu_debugaltlink file.
2019-01-17 Tom de Vries <tdevries@suse.de>
PR libbacktrace/82857
* dwarf.c (enum attr_val_encoding): Add ATTR_VAL_REF_ALT_INFO.
(read_attribute): Handle DW_FORM_GNU_ref_alt using
ATTR_VAL_REF_ALT_INFO.
(read_referenced_name_from_attr): Handle DW_FORM_GNU_ref_alt.
From-SVN: r268031
Add a function that finds the unit given an offset into .debug_info.
2019-01-17 Tom de Vries <tdevries@suse.de>
* dwarf.c (struct unit): Add low_offset and high_offset fields.
(struct unit_vector): New type.
(struct dwarf_data): Add units and units_counts fields.
(find_unit): New function.
(find_address_ranges): Add and handle unit_tag parameter.
(build_address_map): Add and handle units_vec parameter.
(build_dwarf_data): Pass units_vec to build_address_map. Store resulting
units vector.
From-SVN: r268030
Handle DW_FORM_GNU_strp_alt which references the .debug_str section in the
.gnu_debugaltlink file.
2019-01-17 Tom de Vries <tdevries@suse.de>
PR libbacktrace/82857
* dwarf.c (read_attribute): Handle DW_FORM_GNU_strp_alt
using altlink.
From-SVN: r267996
Add an altlink field to struct dwarf_data, and initialize it with the pointer
to the struct dwarf_data for the .gnu_debugaltlink.
2019-01-17 Tom de Vries <tdevries@suse.de>
* dwarf.c (struct dwarf_data): Add altlink field.
(backtrace_dwarf_add): Add and handle fileline_altlink parameter.
* elf.c (elf_add): Add argument to backtrace_dwarf_add call.
(phdr_callback, backtrace_initialize): Add argument to elf_add calls.
* internal.h (backtrace_dwarf_add): Add fileline_altlink parameter.
* pecoff.c (coff_add): Add argument to backtrace_dwarf_add call.
* xcoff.c (xcoff_add): Same.
From-SVN: r267994
Read the elf file pointed at by the .gnu_debugaltlink section, and verify that
the build id matches.
2019-01-17 Tom de Vries <tdevries@suse.de>
* elf.c (elf_add): Add and handle with_buildid_data and
with_buildid_size parameters. Handle .gnu_debugaltlink section.
(phdr_callback, backtrace_initialize): Add arguments to elf_add calls.
From-SVN: r267992
Factor out the common handling of DW_AT_abstract_origin and
DW_AT_specification from read_function_entry and read_referenced_name.
2019-01-16 Tom de Vries <tdevries@suse.de>
* dwarf.c (read_referenced_name_from_attr): New function. Factor out
of ...
(read_referenced_name): ... here, and ...
(read_function_entry): ... here.
From-SVN: r267986
Both read_function_entry and read_referenced_name implement a priority scheme
for names. The priorities are:
- 1st: DW_AT_linkage_name
- 2nd: Name from DW_AT_abstract_origin or DW_AT_specification
- 3rd: DW_AT_name.
Ensure both functions fully adhere to it.
2019-01-16 Tom de Vries <tdevries@suse.de>
* dwarf.c (read_referenced_name): Don't allow DW_AT_name to override any
name.
(read_function_entry): Same. Don't allow name found via
DW_AT_abstract_origin or case DW_AT_specification to override linkage
name.
From-SVN: r267963
In build_address_map we allocate a unit, and then look for addresses in the
unit, which we store in the addrs vector, with the elements pointing to the
unit. However, if we cannot find addresses in the unit, the allocated unit is
not used.
Fix this by detecting if the allocated unit has been used, and reusing it
otherwise.
Bootstrapped and reg-tested on x86_64.
2018-12-28 Tom de Vries <tdevries@suse.de>
* dwarf.c (build_address_map): Reuse unused units.
From-SVN: r267445
In the main loop in build_address_map, we first read the abbrevs into a local
variable abbrevs, and then allocate the corresponding unit, after which we assign
the abbrevs to the unit. This results in dedicated free-upon-failure
handling for the variable, and extra code to make sure that free-upon-failure
doesn't trigger once the unit has taken ownership of the abbrevs.
Simplify this by reversing the order of abbrev reading and unit allocation,
and eliminating the abbrevs local variable.
Bootstrapped and reg-tested on x86_64.
2018-12-28 Tom de Vries <tdevries@suse.de>
* dwarf.c (build_address_map): Simplify by removing local variable
abbrevs.
From-SVN: r267444
When failing in build_address_map, we free the unit that's currently being
handled in the loop, but the ones that already have been allocated are leaked.
Fix this by keeping track of allocated units in a vector, and releasing them
upon failure.
Also, now that we have a vector of allocated units, move the freeing upon
failure of the abbrevs associated with each unit to build_address_map, and
remove the now redundant call to free_unit_addrs_vector.
Bootstrapped and reg-tested on x86_64.
2018-12-28 Ian Lance Taylor <iant@golang.org>
Tom de Vries <tdevries@suse.de>
PR libbacktrace/88063
* dwarf.c (free_unit_addrs_vector): Remove.
(build_address_map): Keep track of allocated units in vector. Free
allocated units and corresponding abbrevs upon failure. Remove now
redundant call to free_unit_addrs_vector. Free addrs vector upon
failure. Free allocated unit vector.
Co-Authored-By: Tom de Vries <tdevries@suse.de>
From-SVN: r267443
While upon failure in build_address_map we call free_unit_addrs_vector, this
does not actually free the addrs vector, but merely the abbrevs of the units
pointed at by the elements of the addrs vector.
Fix this by adding code to build_address_map to make sure that the addrs vector
is freed upon failure.
Bootstrapped and reg-tested on x86_64.
2018-12-28 Tom de Vries <tdevries@suse.de>
* dwarf.c (build_address_map): Free addrs vector upon failure.
From-SVN: r267442
Test-case libbacktrace/allocfail.sh contains bashism "set -o pipefail", which
makes the script fail on ubuntu 18.04, which links /bin/sh to /bin/dash.
Fix this by removing the "set -o pipefail".
Tested by running the test-case with dash on x86_64-linux.
2018-12-14 Tom de Vries <tdevries@suse.de>
PR testsuite/88491
* allocfail.sh: Remove "set -o pipefail".
From-SVN: r267127
Add test-case that forces alloc.c functions to fail, and check whether fail
handling is robust.
This is the test-case for "[libbacktrace] Fix segfault upon allocation
failure". Without that patch, this test-case fails like this:
...
allocfail.sh: line 71: 26041 Segmentation fault (core dumped) \
./allocfail $i > /dev/null 2>&1
Unallowed fail found: 13
FAIL allocfail.sh (exit status: 1)
...
This is a seperate patch because the test-case is nontrivial.
Bootstrapped and reg-tested on x86_64.
2018-12-12 Tom de Vries <tdevries@suse.de>
* Makefile.am (TESTS): Add allocfail.sh.
(check_PROGRAMS): Add allocfail.
* Makefile.in: Regenerate.
* instrumented_alloc.c: New file. Redefine malloc and realloc.
Include alloc.c.
* allocfail.c: New file.
* allocfail.sh: New file.
From-SVN: r267054
When building libbacktrace, we typically use elf.c, and don't build pecoff.c,
xcoff.c or unknown.c.
Add testcases that use unused format to ensure that we also build and
test those on a typical development setup.
Bootstrapped and reg-tested on x86_64.
2018-11-30 Tom de Vries <tdevries@suse.de>
* Makefile.am (check_PROGRAMS): Add test_elf, test_xcoff_32,
test_xcoff_64, test_pecoff and test_unknown.
* Makefile.in: Regenerate.
* test_format.c: New file.
From-SVN: r266668
When building libbacktrace, we typically use mmapio.c and mmap.c, and don't
build read.c and alloc.c.
Add testcases that use read.c and alloc.c to ensure that we also build and
test those on a typical development setup.
Bootstrapped and reg-tested on x86_64.
2018-11-30 Tom de Vries <tdevries@suse.de>
* Makefile.am : Add _with_alloc version for each test in
check_PROGRAMS.
* Makefile.in: Regenerate.
From-SVN: r266667
Factor out new function backtrace_vector_free.
Bootstrapped and reg-tested on x86_64.
2018-11-30 Tom de Vries <tdevries@suse.de>
* internal.h (backtrace_vector_free): New static inline fuction,
factored out of ...
* dwarf.c (read_line_info): ... here.
From-SVN: r266658
If the allocation of abbrevs->abbrevs in read_abbrevs fails, then
abbrevs->num_abbrevs remains nonzero, and consequently free_abbrevs will
segfault when accessing abbrevs->abbrevs.
Fix this by setting abbrevs->num_abbrevs only after abbrevs->abbrevs
allocation has succeeded.
Bootstrapped and reg-tested on x86_64.
2018-11-28 Tom de Vries <tdevries@suse.de>
* dwarf.c (read_abbrevs): Fix handling of abbrevs->abbrevs allocation
failure.
From-SVN: r266562