GDB Administrator [Thu, 10 Oct 2019 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Tue, 1 Oct 2019 23:42:17 +0000 (17:42 -0600)]
Don't call erase_data_content from tui_data_window::show_registers
tui_data_window::show_registers currently calls erase_data_content.
However, I think it's better to have fewer calls to this (ideally just
one would suffice). This refactors that function to remove this call.
gdb/ChangeLog
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-regs.c (tui_data_window::show_registers): Don't call
erase_data_content.
Tom Tromey [Tue, 1 Oct 2019 23:29:49 +0000 (17:29 -0600)]
Make TUI window handle a unique_ptr
This changes tui_gen_win_info::handle to be a specialization of
unique_ptr. This is perhaps mildly uglier in some spots, due to the
proliferation of "get"; but on the other hand it cleans up some manual
management and it allows for the removal of tui_delete_win.
gdb/ChangeLog
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-wingeneral.h (tui_delete_win): Don't declare.
* tui/tui-stack.c (tui_locator_window::rerender): Update.
* tui/tui-command.c (tui_cmd_window::resize)
(tui_refresh_cmd_win): Update.
* tui/tui-win.c (tui_resize_all, tui_set_focus_command): Update.
* tui/tui.c (tui_rl_other_window, tui_enable): Update.
* tui/tui-data.c (~tui_gen_win_info): Remove.
* tui/tui-layout.c (tui_gen_win_info::resize): Update.
* tui/tui-io.c (update_cmdwin_start_line, tui_putc, tui_puts)
(tui_redisplay_readline, tui_mld_flush)
(tui_mld_erase_entire_line, tui_mld_getc, tui_getc): Update.
* tui/tui-regs.c (tui_data_window::delete_data_content_windows)
(tui_data_window::erase_data_content)
(tui_data_item_window::rerender)
(tui_data_item_window::refresh_window): Update.
* tui/tui-wingeneral.c (tui_gen_win_info::refresh_window)
(box_win, tui_gen_win_info::make_window)
(tui_gen_win_info::make_visible): Update.
(tui_delete_win): Remove.
* tui/tui-winsource.c
(tui_source_window_base::do_erase_source_content): Update.
(tui_show_source_line, tui_source_window_base::update_tab_width)
(tui_source_window_base::update_exec_info): Update.
* tui/tui-data.h (struct curses_deleter): New.
(struct tui_gen_win_info) <handle>: Now a unique_ptr.
(struct tui_gen_win_info) <~tui_gen_win_info>: Define.
Tom Tromey [Tue, 1 Oct 2019 23:16:41 +0000 (17:16 -0600)]
Remove declaration from tui-wingeneral.h
tui-wingeneral.h has an unused forward declaration. This removes it.
gdb/ChangeLog
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-wingeneral.h (struct tui_gen_win_info): Don't declare.
Tom Tromey [Tue, 1 Oct 2019 23:14:14 +0000 (17:14 -0600)]
Remove tui_win_is_auxiliary
tui_win_is_auxiliary is not used, so remove it.
gdb/ChangeLog
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-data.c (tui_win_is_auxiliary): Remove.
* tui/tui-data.h (tui_win_is_auxiliary): Don't declare.
Tom Tromey [Tue, 1 Oct 2019 23:03:54 +0000 (17:03 -0600)]
Remove tui_default_win_viewport_height
tui_default_win_viewport_height was only called from a single spot,
for a single type of window. This patch removes the function and
moves the logic into the sole caller.
gdb/ChangeLog
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-disasm.c (tui_get_low_disassembly_address): Compute
window height directly.
* tui/tui-layout.h (tui_default_win_viewport_height): Don't
declare.
* tui/tui-layout.c (tui_default_win_height): Remove.
(tui_default_win_viewport_height): Remove.
Tom Tromey [Tue, 1 Oct 2019 22:58:26 +0000 (16:58 -0600)]
Remove two TUI comments
This removes two comments from tui.h. These were not useful.
gdb/ChangeLog
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui.h: Remove comments.
Tom de Vries [Wed, 9 Oct 2019 21:57:11 +0000 (23:57 +0200)]
[gdb/testsuite] Add XFAILs in gdb.rust/simple.exp for incorrect DWARF
On openSUSE Leap 15.1 using rustc version 1.36.0 (using llvm 7), I get:
...
(gdb) PASS: gdb.rust/simple.exp: print e2.0
print k^M
$54 = simple::SpaceSaver::Thebox(40, 0x0)^M
(gdb) FAIL: gdb.rust/simple.exp: print k
...
while we're expecting:
...
gdb_test "print k" " = simple::SpaceSaver::Nothing"
...
When using a relatively recent version of Rust with a somewhat older version
of LLVM, the Rust compiler will emit a legacy encoding of enums (see also
quirk_rust_enum in dwarf2read.c).
So, the variable k:
...
<17><3d58>: Abbrev Number: 15 (DW_TAG_variable)
<3d59> DW_AT_location : 3 byte block: 91 b8 4 (DW_OP_fbreg: 568)
<3d5d> DW_AT_name : (indirect string, offset: 0xf9a): k
<3d61> DW_AT_alignment : 1
<3d62> DW_AT_decl_file : 1
<3d63> DW_AT_decl_line : 129
<3d64> DW_AT_type : <0x4232>
...
has type:
...
<2><4232>: Abbrev Number: 11 (DW_TAG_union_type)
<4233> DW_AT_name : (indirect string, offset: 0x3037): SpaceSaver
<4237> DW_AT_byte_size : 16
<4238> DW_AT_alignment : 8
<3><4239>: Abbrev Number: 9 (DW_TAG_member)
<423a> DW_AT_name : (indirect string, offset: 0x29f5): RUST$ENCODED$ENUM$0$Nothing
<423e> DW_AT_type : <0x4245>
<4242> DW_AT_alignment : 8
<4243> DW_AT_data_member_location: 0
...
The "RUST$ENCODED$ENUM$0$Nothing" means that field 0 is both a pointer and a
discriminant, and if the value is 0, then the enum is just a data-less variant
named "Nothing".
However, the corresponding type has two fields, where not field 0 but field 1
is a pointer, and field 0 is a byte:
...
<2><4245>: Abbrev Number: 8 (DW_TAG_structure_type)
<4246> DW_AT_name : (indirect string, offset: 0x2a11): Thebox
<424a> DW_AT_byte_size : 16
<424b> DW_AT_alignment : 8
<3><424c>: Abbrev Number: 9 (DW_TAG_member)
<424d> DW_AT_name : (indirect string, offset: 0x670): __0
<4251> DW_AT_type : <0x436b>
<4255> DW_AT_alignment : 1
<4256> DW_AT_data_member_location: 8
<3><4257>: Abbrev Number: 9 (DW_TAG_member)
<4258> DW_AT_name : (indirect string, offset: 0x1662): __1
<425c> DW_AT_type : <0x45da>
<4260> DW_AT_alignment : 8
<4261> DW_AT_data_member_location: 0
...
Mark this as xfail.
gdb/testsuite/ChangeLog:
2019-10-09 Tom de Vries <tdevries@suse.de>
PR testsuite/25048
* gdb.rust/simple.exp: Add xfails for incorrect DWARF.
Tom de Vries [Wed, 9 Oct 2019 21:52:46 +0000 (23:52 +0200)]
[gdb/target] Fix pretty-printer for MPX bnd registers
I'm seeing this failure:
...
(gdb) print /x $bnd0 = {0x10, 0x20}^M
$23 = {lbound = 0x10, ubound = 0x20}^M
(gdb) FAIL: gdb.arch/i386-mpx.exp: verify size for bnd0
...
The test expects a pretty printer to be actived printing 'size 17':
...
set test_string ".*\\\: size 17.*"
gdb_test "print /x \$bnd0 = {0x10, 0x20}" "$test_string" "verify size for bnd0"
...
but that doesn't happen.
The pretty printer is for the type of the $bnd0 register, which is created
here in i386_bnd_type:
...
t = arch_composite_type (gdbarch,
"__gdb_builtin_type_bound128", TYPE_CODE_STRUCT);
append_composite_type_field (t, "lbound", bt->builtin_data_ptr);
append_composite_type_field (t, "ubound", bt->builtin_data_ptr);
TYPE_NAME (t) = "builtin_type_bound128";
...
And the pretty-printer is registered here in
gdb/python/lib/gdb/printer/bound_registers.py:
...
gdb.printing.add_builtin_pretty_printer ('mpx_bound128',
'^__gdb_builtin_type_bound128',
MpxBound128Printer)
...
Fix the pretty printer by changing the regexp argument of
add_builtin_pretty_printer to match "builtin_type_bound128", the TYPE_NAME.
Tested on x86_64-linux.
gdb/ChangeLog:
2019-10-09 Tom de Vries <tdevries@suse.de>
* python/lib/gdb/printer/bound_registers.py: Use
'^builtin_type_bound128' as regexp argument for
add_builtin_pretty_printer.
Christian Biesinger [Mon, 7 Oct 2019 22:38:51 +0000 (17:38 -0500)]
Mark guile_{extension_,}script_ops as static
This makes it clearer that the structs are only used in this file. It
required moving the definition of extension_language_guile further
down in the file, because static structs can't be forward-declared.
gdb/ChangeLog:
2019-10-09 Christian Biesinger <cbiesinger@google.com>
* guile/guile.c (guile_extension_script_ops): Remove forward
declaration and mark as static.
(guile_script_ops): Likewise.
(extension_language_guile): Move further down in the file so
it can reference the definitions for guile_{extension_,}script_ops.
Nick Clifton [Wed, 9 Oct 2019 12:48:06 +0000 (13:48 +0100)]
Fix the disassembly of the LDS and STS instructions of the AVR architecture.
PR 25041
opcodes * avr-dis.c (avr_operand): Fix construction of address for lds/sts
instructions.
gas * testsuite/gas/avr/pr25041.s: New test.
* testsuite/gas/avr/pr25041.d: New test driver.
Alan Modra [Wed, 9 Oct 2019 10:55:25 +0000 (21:25 +1030)]
PR25081, Discrepancy between VMA and LMA after ALIGN
The testcase in the PR has two empty output sections, .sec1 with an
ALIGN and symbol assignment, and .sec2 just with an empty input
section. The symbol assignment results in .sec1 being kept, but
because it is empty this section doesn't take space from the memory
region as you might expect from the ALIGN. Instead the next section
.sec2, has vma/lma as if .sec1 wasn't present. However, .sec2 is
discarded and os->ignored set, which unfortunately meant that dot
wasn't set from .sec2 vma. That in turn results in .sec2 lma being
set incorrectly. That vma/lma difference is then propagated to
.sec3 where it is seen as an overlap.
PR 25081
* ldlang.c (lang_size_sections_1): Set lma from section vma
rather than dot.
Andreas Arnez [Wed, 9 Oct 2019 09:09:22 +0000 (11:09 +0200)]
s390: Add record/replay support for arch13 instructions
Enable recording most of the new "arch13" instructions on z/Architecture
targets, except for the specialized-function-assist instructions:
SORTL - sort lists
DFLTCC - deflate conversion call
KDSA - compute digital signature authentication
gdb/ChangeLog:
* s390-tdep.c (390_process_record): Handle new arch13 instructions
except SORTL, DFLTCC, and KDSA.
Alan Modra [Wed, 9 Oct 2019 00:17:13 +0000 (10:47 +1030)]
PR25070, SEGV in function _bfd_dwarf2_find_nearest_line
Evil testcase with two debug info sections, with sizes of
2aaaabac4ec1
and
ffffd5555453b140 result in a total size of 1. Reading the first
section of course overflows the buffer and tramples on other memory.
PR 25070
* dwarf2.c (_bfd_dwarf2_slurp_debug_info): Catch overflow of
total_size calculation.
GDB Administrator [Wed, 9 Oct 2019 00:00:17 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom Tromey [Tue, 8 Oct 2019 17:21:46 +0000 (11:21 -0600)]
Remove two unused items from windows-nat.c
windows_thread_info_struct::sf is unused, as is
struct safe_symbol_file_add_args in windows-nat.c.
This patch removes them both. Tested by grep and
rebuilding.
gdb/ChangeLog
2019-10-08 Tom Tromey <tromey@adacore.com>
* windows-nat.c (struct windows_thread_info_struct) <sf>: Remove.
(struct safe_symbol_file_add_args): Remove.
Tom Tromey [Wed, 2 Oct 2019 19:24:15 +0000 (13:24 -0600)]
Don't include buildsym-legacy.h in windows-nat.c
I noticed that windows-nat.c includes buildsym-legacy.h -- but there's
no reason to do so, as windows-nat.c doesn't create any symbols.
gdb/ChangeLog
2019-10-08 Tom Tromey <tromey@adacore.com>
* windows-nat.c: Don't include buildsym-legacy.h.
Tom Tromey [Wed, 2 Oct 2019 16:13:33 +0000 (10:13 -0600)]
Let ARI allow gdb %p printf extensions
As pointed out by Simon, this changes ARI to allow the gdb-specific %p
printf extensions.
gdb/ChangeLog
2019-10-08 Tom Tromey <tromey@adacore.com>
* contrib/ari/gdb_ari.sh (%p): Allow gdb-specific %p extensions.
Christian Biesinger [Mon, 7 Oct 2019 19:40:32 +0000 (14:40 -0500)]
Move declaration of overload_debug to header
gdb/ChangeLog:
2019-10-08 Christian Biesinger <cbiesinger@google.com>
* gdbtypes.c (overload_debug): Move comment to header.
* gdbtypes.h (overload_debug): Declare.
* valops.c: Remove declaration of overload_debug, instead
include gdbtypes.h.
Christian Biesinger [Mon, 7 Oct 2019 17:55:44 +0000 (12:55 -0500)]
Move declaration of lang_frame_mismatch_warn to header.
Also makes it localizable.
gdb/ChangeLog:
2019-10-08 Christian Biesinger <cbiesinger@google.com>
* language.c (show_language_command): Pass lang_frame_mismatch_warn
through _().
(lang_frame_mismatch_warn): Make const, mark with N_(), and
move comment...
* language.h (lang_frame_mismatch_warn): ... here. Also add
declaration.
* top.c (lang_frame_mismatch_warn): Remove declaration.
(check_frame_language_change): Pass lang_frame_mismatch_warn
through _().
Alan Modra [Tue, 8 Oct 2019 13:41:28 +0000 (00:11 +1030)]
PR25079, "ar s" stopped working
's' is both a command and a modifier. If given as a command then we
aren't lacking an operation. I think the same goes when mri mode is
selected: any following command line used to be ignored.
PR 25079
* ar.c (decode_options): Don't try for command options if
write_armap or mri_mode is selected.
Alan Modra [Tue, 8 Oct 2019 13:37:29 +0000 (00:07 +1030)]
PR25078, stack overflow in function find_abstract_instance
PR 25078
* dwarf2.c (find_abstract_instance): Delete orig_info_ptr, add
recur_count. Error on recur_count reaching 100 rather than
info_ptr matching orig_info_ptr. Adjust calls.
Alan Modra [Tue, 8 Oct 2019 00:30:11 +0000 (11:00 +1030)]
PowerPC local got test
This is the one that causes ld segfaults between 2019-10-04 and
2019-10-07. Bug introduced with
f749f26eea, fixed by
93370e8e7b.
* testsuite/ld-powerpc/localgot.s,
* testsuite/ld-powerpc/localgot.d: New test.
* testsuite/ld-powerpc/powerpc.exp: Run it.
Andreas Krebbel [Tue, 8 Oct 2019 09:23:57 +0000 (11:23 +0200)]
S/390: Add support for z15 as CPU name.
So far z15 was identified as arch13. After the machine has been
announced we can now add the real name.
gas/ChangeLog:
2019-10-08 Andreas Krebbel <krebbel@linux.ibm.com>
* config/tc-s390.c (s390_parse_cpu): Add z15 as alternate CPU
name.
* doc/as.texi: Add z15 to CPU string list.
* doc/c-s390.texi: Likewise.
opcodes/ChangeLog:
2019-10-08 Andreas Krebbel <krebbel@linux.ibm.com>
* s390-mkopc.c (main): Enable z15 as CPU string in the opcode
table.
GDB Administrator [Tue, 8 Oct 2019 00:00:41 +0000 (00:00 +0000)]
Automatic date update in version.in
Christian Biesinger [Mon, 7 Oct 2019 18:23:34 +0000 (13:23 -0500)]
Move declaration of vtbl_ptr_name to the header.
There are conflicting comments about whether this was
introduced in GCC 2.4.5 or GCC 2.6 and I don't know
which one is correct...
gdb/ChangeLog:
2019-10-07 Christian Biesinger <cbiesinger@google.com>
* c-lang.h (vtbl_ptr_name): Declare.
* cp-valprint.c (vtbl_ptr_name): Remove "extern" now that we get
it from the header.
* stabsread.c (define_symbol): Remove declaration of vtbl_ptr_name.
Christian Biesinger [Mon, 7 Oct 2019 17:33:06 +0000 (12:33 -0500)]
Use gdb_static_assert in charset.c
It currently has a "manual" static assert.
gdb/ChangeLog:
2019-10-07 Christian Biesinger <cbiesinger@google.com>
* charset.c (your_gdb_wchar_t_is_bogus): Replace with a
gdb_static_assert.
Weimin Pan [Mon, 7 Oct 2019 16:22:14 +0000 (16:22 +0000)]
Move top-level Makefile.def/Makefile.in to the top-level ChangeLog
Jozef Lawrynowicz [Mon, 7 Oct 2019 15:34:31 +0000 (16:34 +0100)]
Add support for new functionality in the msp430 backend of GCC.
This functionality will generate a new GNU object attribute for the "data region"
has been added. This object attribute is used
mark whether the compiler has generated code assuming that data could be in the
upper or lower memory regions.
Code which assumes data is always in the lower memory region is incompatible
with code which uses the full memory range for data.
The patch also adds a new assembler directive ".mspabi_attribute" to handle the
existing MSPABI object attributes. GCC will now emit both .gnu_attribute and
.mspabi_attribute directives to indicate what options the source file was
compiled with.
The assembler will now check the values set in these directives against the
options that the it has been invoked with. If there is a discrepancy, the
assembler will exit with an error.
bfd * elf32-msp430.c (elf32_msp430_merge_mspabi_attributes): Rename to..
(elf32_msp430_merge_msp430_attributes): Add support for merging the GNU
object attribute for data region.
binutils* readelf.c (display_msp430_gnu_attribute): New.
(process_arch_specific): Use msp430 specific handler for GNU
attributes.
gas * config/tc-msp430.c (md_parse_option): Set lower_data_region_only to
FALSE if the data region is set to "upper", "either" or "none".
(msp430_object_attribute): New.
(md_pseudo_table): Handle .mspabi_attribute and .gnu_attribute.
(msp430_md_end): Replace hard-coded attribute values with enums.
Handle data region object attribute.
* doc/as.texi: Document MSP430 Data Region object attribute.
* doc/c-msp430.texi: Document the .mspabi_attribute directive.
* testsuite/gas/msp430/attr-430-small-bad.d: New test.
* testsuite/gas/msp430/attr-430-small-bad.l: New test.
* testsuite/gas/msp430/attr-430-small-good.d: New test.
* testsuite/gas/msp430/attr-430-small.s: New test.
* testsuite/gas/msp430/attr-430x-large-any-bad.d: New test.
* testsuite/gas/msp430/attr-430x-large-any-bad.l: New test.
* testsuite/gas/msp430/attr-430x-large-any-good.d: New test.
* testsuite/gas/msp430/attr-430x-large-any.s: New test.
* testsuite/gas/msp430/attr-430x-large-lower-bad.d: New test.
* testsuite/gas/msp430/attr-430x-large-lower-bad.l: New test.
* testsuite/gas/msp430/attr-430x-large-lower-good.d: New test.
* testsuite/gas/msp430/attr-430x-large-lower.s: New test.
* testsuite/gas/msp430/msp430.exp: Run new tests.
include * elf/msp430.h: Add enums for MSPABI and GNU object attribute tag names
and values.
ld * testsuite/ld-msp430-elf/attr-gnu-main.s: New test.
* testsuite/ld-msp430-elf/attr-gnu-obj.s: New test.
* testsuite/ld-msp430-elf/attr-gnu-region-lower-upper.d: New test.
* testsuite/ld-msp430-elf/attr-gnu-region-lower.d: New test.
* testsuite/ld-msp430-elf/attr-gnu-region-upper.d: New test.
* testsuite/ld-msp430-elf/msp430-elf.exp: Run new tests.
Alan Modra [Mon, 7 Oct 2019 12:44:31 +0000 (23:14 +1030)]
Re: PowerPC PIC vs. DLL TLS issues
A bug crept into commit
f749f26eea, which could cause linker
segfaults when creating PIEs. This patch fixes it.
* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Do allocate
space for local got non-tls relocs when PIE.
Andrew Burgess [Mon, 7 Oct 2019 12:10:55 +0000 (13:10 +0100)]
gdb/testsuite/ada: Handle missing debug info case
Update a test script to handle the case where missing Ada debug
information means we can't catch exceptions. This was discussed on
the list here:
https://sourceware.org/ml/gdb-patches/2019-08/msg00607.html
And is similar to code that already exists in the test scripts
gdb.ada/catch_ex.exp and gdb.ada/mi_catch_ex.exp.
gdb/testsuite/ChangeLog:
* gdb.ada/catch_ex_std.exp: Handle being unabled to catch Ada
exceptions due to missing debug information.
Andrew Burgess [Mon, 7 Oct 2019 11:34:51 +0000 (12:34 +0100)]
gdb: Rename structures within ctfread.c
Commit:
commit
30d1f0184953478d14641c495261afd06ebfabac
Date: Mon Oct 7 00:46:52 2019 +0000
gdb: CTF support
Introduces some structures with names that are already in use within
GBB, this violates C++'s one-definition rule. Specifically the
structures 'nextfield' and 'field_info' are now defined in
dwarf2read.c and ctfread.c.
This commit renames the new structures (in ctfread.c), adding a 'ctf_'
prefix. Maybe we should consider renaming the DWARF versions too in
the future to avoid accidental conflicts.
gdb/ChangeLog:
* ctfread.c (struct nextfield): Renamed to ...
(struct ctf_nextfield): ... this.
(struct field_info): Renamed to ...
(strut ctf_field_info): ... this.
(attach_fields_to_type): Update for renamed structures.
(ctf_add_member_cb): Likewise.
(ctf_add_enum_member_cb): Likewise.
(process_struct_members): Likewise.
(process_enum_type): Likewise.
Tom de Vries [Mon, 7 Oct 2019 10:50:04 +0000 (12:50 +0200)]
[gdb/testsuite] Update expected _gdb_major/_gdb_minor in default.exp
Now that commit "
225f296a023 Change gdb/version.in to 9.0.50.DATE-git (new
version numbering scheme)" has changed the gdb version number, we see:
...
FAIL: gdb.base/default.exp: show convenience ($_gdb_major = 8 not found)
...
Fix this by updating the expected _gdb_major/_gdb_minor to 9.1.
Tested on x86_64-linux.
gdb/testsuite/ChangeLog:
2019-10-07 Tom de Vries <tdevries@suse.de>
* gdb.base/default.exp: Expect _gdb_major/_gdb_minor to be 9.1.
Andrew Burgess [Tue, 1 Oct 2019 14:29:20 +0000 (15:29 +0100)]
gdb/testsuite: Add gdb_test_name variable
This commit adds a new feature to gdb_test_multiple, an automatically
created variable gdb_test_name. The idea is to make it easier to
write tests using gdb_test_multiple, and avoid places where the string
passed to pass/fail within an action element is different to the
message passed to the top level gdb_test_multiple.
As an example, previously you might write this:
gdb_test_multiple "print foo" "test foo" {
-re "expected output 1" {
pass "test foo"
}
-re "expected output 2" {
fail "test foo"
}
}
This is OK, but it's easy for the pass/fail strings to come out of
sync, or contain a typo. A better version would look like this:
set testname "test foo"
gdb_test_multiple "print foo" $testname {
-re "expected output 1" {
pass $testname
}
-re "expected output 2" {
fail $testname
}
}
This is better, but its a bit of a drag having to create a new
variable each time.
After this patch you can now write this:
gdb_test_multiple "print foo" "test foo" {
-re "expected output 1" {
pass $gdb_test_name
}
-re "expected output 2" {
fail $gdb_test_name
}
}
The $gdb_test_name is setup by gdb_test_multiple, and cleaned up once
the test has completed. Nested calls to gdb_test_multiple are
supported, though $gdb_test_name will only ever contain the inner most
test message (which is probably what you want).
My only regret is that '$gdb_test_name' is so long, but I wanted
something that was unlikely to clash with any existing variable name,
or anything that a user is likely to want to use.
I've tested this on x86-64/GNU Linux and see no test regressions, and
I've converted one test script over to make use of this new technique
both as an example, and to ensure that the new facility doesn't get
broken. I have no plans to convert all tests over to this technique,
but I hope others will find this useful for writing tests in the
future.
gdb/testsuite/ChangeLog:
* lib/gdb.exp (gdb_test_multiple): Add gdb_test_name mechanism.
* gdb.base/annota1.exp: Update to use gdb_test_name.
Tom de Vries [Mon, 7 Oct 2019 07:51:18 +0000 (09:51 +0200)]
[gdb/doc] Fix some typos
Fix typos 'prevsiouly -> previously' and 'corresonding -> corresponding' in the
docs.
gdb/doc/ChangeLog:
2019-10-07 Tom de Vries <tdevries@suse.de>
* gdb.texinfo: Fix typo.
* guile.texi: Same.
* python.texi: Same.
Jan Beulich [Mon, 7 Oct 2019 06:40:03 +0000 (08:40 +0200)]
add missing ChangeLog entry for
d241b91073
Jan Beulich [Mon, 7 Oct 2019 06:38:01 +0000 (08:38 +0200)]
x86/Intel: correct MOVSD and CMPSD handling
First and foremost the EsSeg attribute was misplaced for CMPSD. Then
both it and MOVSD were lacking Dword on both of their operands.
Finally string insns with multiple operands and requiring use of ES:
had the wrong operand number reported in the diagnostic.
Alan Modra [Mon, 7 Oct 2019 03:07:23 +0000 (13:37 +1030)]
Bogus "final link failed" messages
This patch is a result of noticing messages like the following:
tmpdir/tls32.o: in function `_start':
(.text+0x1c): unresolvable R_PPC_REL24 relocation against symbol `__tls_get_addr_opt'
./ld-new: final link failed: symbol needs debug section which does not exist
The "needs debug section" comes from attempting to use debug info to
find source line information to print the first error message. That
error isn't of interest to the user, and any previous bfd_error value
which might be of interest is overwritten. So save and restore
bfd_error around the fancy error reporting code.
That still doesn't leave us with a clean bfd_error. Now we get
./ld-new: final link failed: nonrepresentable section on output
An unresolvable relocation surely doesn't mean there is some bfd
section that ld doesn't know how to output! Digging into that showed
a _bfd_elf_section_from_bfd_section failure attempting to find an elf
section correcsponding to ".interp". So don't go looking for elf
sections on linker created bfd sections.
And then fix the linker testsuite which expected the bogus message..
bfd/
* elflink.c (elf_fixup_link_order): Don't attempt to find
an elf_section for linker created bfd sections.
ld/
* ldmisc.c (vfinfo): Save and restore bfd_error around bfd
function calls that might set it.
* testsuite/ld-elf/indirect.exp: Don't expect "nonrepresentable
section" message.
Alan Modra [Mon, 7 Oct 2019 03:04:40 +0000 (13:34 +1030)]
PowerPC TLS tests
This patch adds some --no-tls-optimize tests and performs some of the
existing dynamic tests with tls markers in order to catch any
regression in PLT counting.
* testsuite/ld-powerpc/tlsexe.r: Adjust for added TLSMARK symbol.
* testsuite/ld-powerpc/tlsexe32.r: Likewise.
* testsuite/ld-powerpc/tlsso.r: Likewise.
* testsuite/ld-powerpc/tlsso32.r: Likewise.
* testsuite/ld-powerpc/tls32no.d,
* testsuite/ld-powerpc/tls32no.g: New test files.
* testsuite/ld-powerpc/tlsexe32no.d,
* testsuite/ld-powerpc/tlsexe32no.g,
* testsuite/ld-powerpc/tlsexe32no.r: New test files.
* testsuite/ld-powerpc/tlsexeno.d,
* testsuite/ld-powerpc/tlsexeno.g,
* testsuite/ld-powerpc/tlsexeno.r: New test files.
* testsuite/ld-powerpc/tlsexetocno.d,
* testsuite/ld-powerpc/tlsexetocno.g: New test files.
* testsuite/ld-powerpc/tlsno.d,
* testsuite/ld-powerpc/tlsno.g: New test files.
* testsuite/ld-powerpc/tlstocno.d,
* testsuite/ld-powerpc/tlstocno.g: New test files.
* testsuite/ld-powerpc/powerpc.exp: Run new tests.
Alan Modra [Mon, 7 Oct 2019 02:51:02 +0000 (13:21 +1030)]
PowerPC TLS miscounting PLT for __tls_get_addr
ppc*_elf_tls_optimize decrements the PLT refcount for __tls_get_addr
when a GD or LD sequence can be optimized. Without tls marker relocs
this must be done when processing the argument setup relocations.
With marker relocs it's better done when processing the marker reloc.
But don't count them both ways.
Seen as "unresolvable R_PPC_REL24 relocation against symbol
`__tls_get_addr_opt'" (and other branch relocs).
* elf32-ppc.c (ppc_elf_tls_optimize): Don't process R_PPC_TLSLD
with non-local symbol. Don't double count __tls_get_addr calls
with marker relocs.
* elf64-ppc.c (ppc64_elf_tls_optimize): Likewise.
Alan Modra [Mon, 7 Oct 2019 02:47:59 +0000 (13:17 +1030)]
PowerPC section flag tidy
has_tls_get_addr_call is no longer named correctly as the flag is
only set on finding a __tls_get_addr call without tlsld/tlsgd marker
relocations.
* elf32-ppc.c (nomark_tls_get_addr): Rename from has_tls_get_addr_call
throughout.
* elf64-ppc.c (nomark_tls_get_addr): Likewise.
Alan Modra [Mon, 7 Oct 2019 02:44:11 +0000 (13:14 +1030)]
ld-arm/tls-gdesc-neg test
Fixes a failure on armeb-linuxeabi.
* testsuite/ld-arm/tls-gdesc-neg.d: Relax target match.
Weimin Pan [Mon, 7 Oct 2019 00:46:52 +0000 (00:46 +0000)]
gdb: CTF support
This patch adds the CTF (Compact Ansi-C Type Format) support in gdb.
Two submissions on which this gdb work depends were posted earlier
in May:
* On the binutils mailing list - adding libctf which creates, updates,
reads, and manipulates the CTF data.
* On the gcc mailing list - expanding gcc to directly emit the CFT data
with a new command line option -gt.
CTF is a reduced form of debugging information whose main purpose is to
describe the type of C entities such as structures, unions, typedefs and
function arguments at the global scope only. It does not contain debug
information about source lines, location expressions, or local variables.
For more information on CTF, see the documentation in the libdtrace-ctf
source tree, available here:
<https://raw.githubusercontent.com/oracle/libdtrace-ctf/master/doc/ctf-format>.
This patch expands struct elfinfo by adding the .ctf section, which
contains CTF debugging info, and modifies elf_symfile_read() to read it.
If both DWARF and CTF exist in a program, only DWARF will be read. CTF data
will be read only when there is no DWARF. The two-stage symbolic reading
and setting strategy, partial and full, was used.
File ctfread.c contains functions to transform CTF data into gdb's internal
symbol table structures by iterately reading entries from CTF sections
of "data objects", "function info", "variable info", and "data types"
when setting up either partial or full symbol table. If the ELF symbol table
is available, e.g. not stripped, the CTF reader will associate the found
type information with these symbol entries. Due to the proximity between DWARF
and CTF (CTF being a much simplified subset of DWARF), some DWARF implementation
was reused to support CTF.
Test cases ctf-constvars.exp, ctf-cvexpr.exp, ctf-ptype.exp, and ctf-whatis.exp
have been added to verify the correctness of this support.
This patch has missing features and limitations which we will add and
address in the future patches.
gdb/ChangeLog
+2019-10-07 Weimin Pan <weimin.pan@oracle.com>
+
+ * gdb/ctfread.c: New file.
+ * gdb/ctfread.h: New file.
+ * gdb/elfread.c: Include ctfread.h.
+ (struct elfinfo text_p): New member ctfsect.
+ (elf_locate_sections): Mark CTF section.
+ (elf_symfile_read): Call elfctf_build_psymtabs.
+ * gdb/Makefile.in (LIBCTF): Add.
+ (CLIBS): Use it.
+ (CDEPS): Likewise.
+ (DIST): Add ctfread.c.
+ * Makefile.def (dependencies): Add all-libctf to all-gdb
+ * Makefile.in: Add "all-gdb: maybe-all-libctf"
+
gdb/testsuite/ChangeLog
+2019-10-07 Weimin Pan <weimin.pan@oracle.com>
+
+ * gdb.base/ctf-whatis.exp: New file.
+ * gdb.base/ctf-whatis.c: New file.
+ * gdb.base/ctf-ptype.exp: New file.
+ * gdb.base/ctf-ptype.c: New file.
+ * gdb.base/ctf-constvars.exp: New file.
+ * gdb.base/ctf-constvars.c: New file.
+ * gdb.base/ctf-cvexpr.exp: New file.
+
Weimin Pan [Mon, 7 Oct 2019 00:16:06 +0000 (00:16 +0000)]
Renaming of ctf (the trace format) files
GDB Administrator [Mon, 7 Oct 2019 00:00:29 +0000 (00:00 +0000)]
Automatic date update in version.in
Joel Brobecker [Sun, 6 Oct 2019 15:32:00 +0000 (08:32 -0700)]
Change gdb/version.in to 9.0.50.DATE-git (new version numbering scheme)
gdb/ChangeLog:
* version.in: Change version number to "9.0.50.DATE-git".
GDB Administrator [Sun, 6 Oct 2019 00:00:56 +0000 (00:00 +0000)]
Automatic date update in version.in
GDB Administrator [Sat, 5 Oct 2019 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in
Tom de Vries [Fri, 4 Oct 2019 14:23:24 +0000 (16:23 +0200)]
[gdb/testsuite] Fix local-static.exp with gcc-4.8
With gdb.cp/local-static.exp and gcc 4.8, I see:
...
gdb compile failed, src/gdb/testsuite/gdb.cp/local-static.c: In function 'main':
src/gdb/testsuite/gdb.cp/local-static.c:148:3: error: 'for' loop initial \
declarations are only allowed in C99 mode
for (int i = 0; i < 1000; i++)
^
src/gdb/testsuite/gdb.cp/local-static.c:148:3: note: use option -std=c99 or \
-std=gnu99 to compile your code
UNTESTED: gdb.cp/local-static.exp: c: failed to prepare
...
Fix this by moving the declaration of int i out of the for loop.
gdb/testsuite/ChangeLog:
2019-10-04 Tom de Vries <tdevries@suse.de>
* gdb.cp/local-static.c (main): Move declaration of int i out of the
for loop.
Alan Modra [Thu, 3 Oct 2019 23:18:41 +0000 (08:48 +0930)]
PowerPC PIC vs. DLL TLS issues
1) GOT entries generated for any of the GOT TLS relocations don't need
dynamic relocations for locally defined symbols in PIEs. In the case
of a tls_index doubleword, the dtpmod entry is known to be 1, and the
dtprel entry is also known at link time and relative. Similarly,
dtprel and tprel words are known at link time and relative. (GOT
entries for other than TLS symbols are not relative and thus need
dynamic relocations in PIEs.)
2) Local dynamic TLS code is really only meant for accesses local to
the current binary. There was a cheapskate test for this before using
the common tlsld_got slot, but the test wasn't exactly correct and
might confuse anyone looking at the code. The proper test,
SYMBOL_REFERENCES_LOCAL isn't so expensive that it should be avoided.
3) The same cheap test for local syms when optimising TLS sequences
should be SYMBOL_REFERENCES_LOCAL too.
bfd/
* elf64-ppc.c (ppc64_elf_check_relocs): Move initialisation of vars.
(ppc64_elf_tls_optimize): Correct is_local condition.
(allocate_got): Don't reserve dynamic relocations for any of the
tls got relocs in PIEs when the symbol is local.
(allocate_dynrelocs): Correct validity test for local sym using
tlsld_got slot.
(ppc64_elf_size_dynamic_sections): Don't reserve dynamic relocations
for any of the tls got relocs in PIEs.
(ppc64_elf_layout_multitoc): Likewise.
(ppc64_elf_relocate_section): Correct validity test for local sym
using tlsld_got slot. Don't emit dynamic relocations for any of
the tls got relocs in PIEs when the symbol is local.
* elf32-ppc.c (ppc_elf_tls_optimize): Correct is_local condition.
(got_relocs_needed): Delete.
(allocate_dynrelocs): Correct validity test for local sym using
tlsld_got slot. Don't reserve dynamic relocations for any of the
tls got relocs in PIEs when the symbol is local.
(ppc_elf_size_dynamic_sections): Don't reserve dynamic relocations
for any of the tls got relocs in PIEs.
(ppc_elf_relocate_section): Correct validity test for local sym
using tlsld_got slot. Don't emit dynamic relocations for any of
the tls got relocs in PIEs when the symbol is local.
ld/
* testsuite/ld-powerpc/tlsso.d: Adjust to suit tlsld_got usage change.
* testsuite/ld-powerpc/tlsso.g: Likewise.
* testsuite/ld-powerpc/tlsso.r: Likewise.
* testsuite/ld-powerpc/tlsso32.d: Likewise.
* testsuite/ld-powerpc/tlsso32.g: Likewise.
* testsuite/ld-powerpc/tlsso32.r: Likewise.
Szabolcs Nagy [Wed, 2 Oct 2019 18:46:46 +0000 (19:46 +0100)]
[PR ld/22263][PR ld/25056] arm: Avoid dynamic TLS relocs in PIE
Dynamic relocs are only needed in an executable for TLS symbols if
those are defined in an external module and even then TLS access
can be relaxed to use IE model instead of GD.
Several bfd_link_pic checks are turned into bfd_link_dll checks
to fix TLS handling in PIE, for the same fix some other targets
used !bfd_link_executable checks, but that includes relocatable
objects so dll seems safer (in most cases either should work, since
dynamic relocations are not applied in relocatable objects).
On arm* fixes
FAIL: Build pr22263-1
bfd/
PR ld/22263
PR ld/25056
* elf32-arm.c (elf32_arm_tls_transition): Use bfd_link_dll instead of
bfd_link_pic for TLS checks.
(elf32_arm_final_link_relocate): Likewise.
(allocate_dynrelocs_for_symbol): Likewise.
Szabolcs Nagy [Thu, 3 Oct 2019 18:11:50 +0000 (19:11 +0100)]
[PR ld/25062] arm: sign extend the addend of R_ARM_TLS_GOTDESC
On 64-bit host the 32-bit addend was loaded without sign extension into
an unsigned long.
bfd/ChangeLog:
PR ld/25062
* elf32-arm.c (elf32_arm_final_link_relocate): Sign extend data.
ld/ChangeLog:
PR ld/25062
* testsuite/ld-arm/arm-elf.exp: Update.
* testsuite/ld-arm/tls-gdesc-neg.d: New test.
* testsuite/ld-arm/tls-gdesc-neg.s: New test.
Tom Tromey [Thu, 3 Oct 2019 23:21:52 +0000 (17:21 -0600)]
Avoid crash on single-field union in Rust
PR rust/24976 points out a crash in gdb when a single-field union is
used in Rust.
The immediate problem was a NULL pointer dereference in
quirk_rust_enum. However, that code is also erroneously treating a
single-field union as if it were a univariant enum. Looking at the
output of an older Rust compiler, it turns out that univariant enums
are distinguished by having a single *anonymous* field. This patch
changes quirk_rust_enum to limit its fixup to this case.
Tested with a new-enough version of the Rust compiler to cause the
crash; plus by using an older executable that uses the old univariant
encoding.
gdb/ChangeLog
2019-10-03 Tom Tromey <tom@tromey.com>
PR rust/24976:
* dwarf2read.c (quirk_rust_enum): Handle single-element unions.
gdb/testsuite/ChangeLog
2019-10-03 Tom Tromey <tom@tromey.com>
PR rust/24976:
* gdb.rust/simple.rs (Union2): New type.
(main): Use Union2.
* gdb.rust/simple.exp: Add test.
GDB Administrator [Fri, 4 Oct 2019 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in
Andrew Burgess [Mon, 2 Sep 2019 22:31:10 +0000 (23:31 +0100)]
gdb/fortran: Allow for matching symbols with missing scope
This commit allows symbol matching within Fortran code without having
to specify all of the symbol's scope. For example, given this Fortran
code:
module aaa
contains
subroutine foo
print *, "hello."
end subroutine foo
end module aaa
subroutine foo
print *, "hello."
end subroutine foo
program test
call foo
contains
subroutine foo
print *, "hello."
end subroutine foo
subroutine bar
use aaa
call foo
end subroutine bar
end program test
The user can now do this:
(gdb) b foo
Breakpoint 1 at 0x4006c2: foo. (3 locations)
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y <MULTIPLE>
1.1 y 0x00000000004006c2 in aaa::foo at nest.f90:4
1.2 y 0x0000000000400730 in foo at nest.f90:9
1.3 y 0x00000000004007c3 in test::foo at nest.f90:16
The user asks for a breakpoint on 'foo' and is given a breakpoint on
all three possible 'foo' locations. The user is, of course, still
able to specify the scope in order to place a single breakpoint on
just one of the foo functions (or use 'break -qualified foo' to break
on just the global foo).
gdb/ChangeLog:
* f-lang.c (f_language_defn): Use cp_get_symbol_name_matcher and
cp_search_name_hash.
* NEWS: Add entry about nested function support.
gdb/testsuite/ChangeLog:
* gdb.fortran/nested-funcs-2.exp: Run tests with and without the
nested function prefix.
Andrew Burgess [Thu, 15 Aug 2019 13:57:13 +0000 (14:57 +0100)]
gdb/fortran: Nested subroutine support
This patch is a rebase and update of the following three patches:
https://sourceware.org/ml/gdb-patches/2018-11/msg00298.html
https://sourceware.org/ml/gdb-patches/2018-11/msg00302.html
https://sourceware.org/ml/gdb-patches/2018-11/msg00301.html
I have merged these together into a single commit as the second patch,
adding scope support to nested subroutines, means that some of the
changes in the first patch are now no longer useful and would have to
be backed out. The third patch is tightly coupled to the changes in
the second of these patches and I think deserves to live together with
it.
There is an extra change in cp-namespace.c that is new, this resolves
an issue with symbol lookup when placing breakpoints from within
nested subroutines.
There is also an extra test added to this commit 'nested-funcs-2.exp'
that was written by Richard Bunt from ARM, this offers some additional
testing of breakpoints on nested functions.
After this commit it is possible to place breakpoints on nested
Fortran subroutines and functions by using a fully scoped name, for
example, given this simple Fortran program:
program greeting
call message
contains
subroutine message
print *, "Hello World"
end subroutine message
end program greeting
It is possible to place a breakpoint in 'message' with:
(gdb) break greeting::message
Breakpoint 1 at 0x4006c9: file basic.f90, line 5.
What doesn't work with this commit is placing a breakpoint like this:
(gdb) break message
Function "message" not defined.
Making this work will come in a later commit.
gdb/ChangeLog:
* cp-namespace.c (cp_search_static_and_baseclasses): Only search
for nested static variables when searchin VAR_DOMAIN.
* dwarf2read.c (add_partial_symbol): Add nested subroutines to the
global scope, update comment.
(add_partial_subprogram): Call add_partial_subprogram recursively
for nested subroutines when processinng Fortran.
(load_partial_dies): Process the child entities of a subprogram
when processing Fortran.
(partial_die_parent_scope): Handle building scope
for Fortran nested functions.
(process_die): Record that nested functions have a scope.
(new_symbol): Always record Fortran subprograms on the global
symbol list.
(determine_prefix): How to build the prefix for Fortran
subprograms.
gdb/testsuite/ChangeLog:
* gdb.fortran/nested-funcs.exp: Tests for placing breakpoints on
nested functions.
* gdb.fortran/nested-funcs.f90: Update expected results.
* gdb.fortran/nested-funcs-2.exp: New file.
* gdb.fortran/nested-funcs-2.f90: New file.
gdb/doc/ChangeLog:
* doc/gdb.texinfo (Fortran Operators): Describe scope operator.
Andrew Burgess [Mon, 16 Sep 2019 01:53:11 +0000 (21:53 -0400)]
gdb/testsuite: Reduce test name duplication in gdb.python tests
This commit removes some, but not all, of the test name duplication
within the gdb.python tests. On my local machine this takes the
number of duplicate test names in this set of tests from 174 to 85.
It is possible that different setups might encounter more duplicate
tests.
gdb/testsuite/ChangeLog:
* gdb.python/py-parameter.exp: Make test names unique.
* gdb.python/py-template.exp: Likewise.
* gdb.python/py-value.exp: Likewise.
Andrew Burgess [Mon, 16 Sep 2019 01:50:17 +0000 (21:50 -0400)]
gdb/testsuite: Reduce test name duplication in gdb.base tests
This commit removes some, but not all, of the test name duplication
within the gdb.base tests. On my local machine this takes the number
of duplicate test names in this set of tests from 454 to 145. It is
possible that different setups might encounter more duplicate tests.
gdb/testsuite/ChangeLog:
* gdb.base/break-interp.exp: Reduce test name duplication.
* gdb.base/call-sc.exp: Likewise.
* gdb.base/callfuncs.exp: Likewise.
* gdb.base/charset.exp: Likewise.
* gdb.base/dump.exp: Likewise.
* gdb.base/ena-dis-br.exp: Likewise.
* gdb.base/relational.exp: Likewise.
* gdb.base/step-over-syscall.exp: Likewise.
* gdb.base/structs.exp: Likewise.
Andrew Burgess [Sun, 15 Sep 2019 17:42:54 +0000 (13:42 -0400)]
gdb/testsuite: Make test names unique in gdb.linespec tests
Make test names unique in the gdb.linespec tests. On my local machine
this removed 43 duplicate test names. It is possible that different
setups might still encounter some duplicates.
gdb/testsuite/ChangeLog:
* gdb.linespec/explicit.exp: Make test names unique.
* gdb.linespec/ls-errs.exp: Likewise.
Andrew Burgess [Sun, 15 Sep 2019 17:21:32 +0000 (13:21 -0400)]
gdb/testsuite: Make test names unique in gdb.reverse tests
Make test names unique in the gdb.reverse tests. On my local machine
this removed 825 duplicate test names. It is possible that different
setups might still encounter some duplicates.
gdb/testsuite/ChangeLog:
* gdb.reverse/break-precsave.exp: Make test names unique.
* gdb.reverse/break-reverse.exp: Likewise.
* gdb.reverse/finish-precsave.exp: Likewise.
* gdb.reverse/finish-reverse.exp: Likewise.
* gdb.reverse/machinestate-precsave.exp: Likewise.
* gdb.reverse/machinestate.exp: Likewise.
* gdb.reverse/readv-reverse.exp: Likewise.
* gdb.reverse/recvmsg-reverse.exp: Likewise.
* gdb.reverse/sigall-precsave.exp: Likewise.
* gdb.reverse/sigall-reverse.exp: Likewise.
* gdb.reverse/step-indirect-call-thunk.exp: Likewise.
* gdb.reverse/watch-precsave.exp: Likewise.
* gdb.reverse/watch-reverse.exp: Likewise.
Nick Alcock [Thu, 26 Sep 2019 14:26:48 +0000 (15:26 +0100)]
libctf: fix tabdamage
A little tabdamage predating the linker patch series has crept in.
New in v5.
libctf/
* ctf-open.c (ctf_bufopen_internal): Fix tabdamage.
* ctf-types.c (ctf_type_lname): Likewise.
Nick Alcock [Thu, 26 Sep 2019 14:24:13 +0000 (15:24 +0100)]
binutils: spaces -> tabs in CTF parts of objdump and readelf
For readelf particularly, this is more or less whistling in the dark:
there are hundreds of lines where spaces are used where tabs were used
on adjacent lines.
New in v5.
binutils/
* objdump.c (main): Fix tabdamage.
* readelf.c (CTF_DUMP): Likewise.
(options): Likewise.
(dump_section_as_ctf): Likewise.
Nick Alcock [Tue, 17 Sep 2019 05:59:31 +0000 (06:59 +0100)]
libctf: fix refcount leak in ctf_import
Calling ctf_import (fp, NULL) to cancel out a pre-existing import leaked
the refcnt increment on the parent, so it could never be freed.
New in v4.
libctf/
* ctf-open.c (ctf_import): Do not leak a ctf_file_t ref on every
ctf_import after the first for a given file.
Nick Alcock [Tue, 17 Sep 2019 05:57:00 +0000 (06:57 +0100)]
libctf: make ctf_dump not crash on OOM
ctf_dump calls ctf_str_append extensively but never checks to see if it
returns NULL (on OOM). If it ever does, we truncate the string we are
appending to and leak it!
Instead, create a variant of ctf_str_append that returns the *original
string* on OOM, and use it in ctf-dump. It is far better to omit a tiny
piece of a dump on OOM than to omit a bigger piece, and it is also
better to do this in what is after all purely debugging code than it is
to uglify ctf-dump.c with huge numbers of checks for the out-of-memory
case. Slightly truncated debugging output is better than no debugging
output at all and an out-of-memory message.
New in v4.
libctf/
* ctf-impl.h (ctf_str_append_noerr): Declare.
* ctf-util.c (ctf_str_append_noerr): Define in terms of
ctf_str_append.
* ctf-dump.c (str_append): New, call it.
(ctf_dump_format_type): Use str_append, not ctf_str_append.
(ctf_dump_label): Likewise.
(ctf_dump_objts): Likewise.
(ctf_dump_funcs): Likewise.
(ctf_dump_var): Likewise.
(ctf_dump_member): Likewise.
(ctf_dump_type): Likewise.
(ctf_dump): Likewise.
Nick Alcock [Tue, 17 Sep 2019 05:54:23 +0000 (06:54 +0100)]
libctf: remove ctf_malloc, ctf_free and ctf_strdup
These just get in the way of auditing for erroneous usage of strdup and
add a huge irregular surface of "ctf_malloc or malloc? ctf_free or free?
ctf_strdup or strdup?"
ctf_malloc and ctf_free usage has not reliably matched up for many
years, if ever, making the whole game pointless.
Go back to malloc, free, and strdup like everyone else: while we're at
it, fix a bunch of places where we weren't properly checking for OOM.
This changes the interface of ctf_cuname_set and ctf_parent_name_set,
which could strdup but could not return errors (like ENOMEM).
New in v4.
include/
* ctf-api.h (ctf_cuname_set): Can now fail, returning int.
(ctf_parent_name_set): Likewise.
libctf/
* ctf-impl.h (ctf_alloc): Remove.
(ctf_free): Likewise.
(ctf_strdup): Likewise.
* ctf-subr.c (ctf_alloc): Remove.
(ctf_free): Likewise.
* ctf-util.c (ctf_strdup): Remove.
* ctf-create.c (ctf_serialize): Use malloc, not ctf_alloc; free, not
ctf_free; strdup, not ctf_strdup.
(ctf_dtd_delete): Likewise.
(ctf_dvd_delete): Likewise.
(ctf_add_generic): Likewise.
(ctf_add_function): Likewise.
(ctf_add_enumerator): Likewise.
(ctf_add_member_offset): Likewise.
(ctf_add_variable): Likewise.
(membadd): Likewise.
(ctf_compress_write): Likewise.
(ctf_write_mem): Likewise.
* ctf-decl.c (ctf_decl_push): Likewise.
(ctf_decl_fini): Likewise.
(ctf_decl_sprintf): Likewise. Check for OOM.
* ctf-dump.c (ctf_dump_append): Use malloc, not ctf_alloc; free, not
ctf_free; strdup, not ctf_strdup.
(ctf_dump_free): Likewise.
(ctf_dump): Likewise.
* ctf-open.c (upgrade_types_v1): Likewise.
(init_types): Likewise.
(ctf_file_close): Likewise.
(ctf_bufopen_internal): Likewise. Check for OOM.
(ctf_parent_name_set): Likewise: report the OOM to the caller.
(ctf_cuname_set): Likewise.
(ctf_import): Likewise.
* ctf-string.c (ctf_str_purge_atom_refs): Use malloc, not ctf_alloc;
free, not ctf_free; strdup, not ctf_strdup.
(ctf_str_free_atom): Likewise.
(ctf_str_create_atoms): Likewise.
(ctf_str_add_ref_internal): Likewise.
(ctf_str_remove_ref): Likewise.
(ctf_str_write_strtab): Likewise.
Nick Alcock [Fri, 9 Aug 2019 21:53:50 +0000 (22:53 +0100)]
libctf: get the encoding of non-ints/fps in the dynamic space right
If you call ctf_type_encoding() on a slice, you are meant to get the
encoding of the slice with the format of the underlying type. If
you call it on a non-int, non-fp, non-slice, you're meant to get the
error ECTF_INTNOTFP.
None of this was implemented for types in the dynamic space (which, now,
is *all* types in writable containers). Instead, we were always
returning the encoding as if it were a float, which for all other types
consulted the wrong part of a discriminated union and returned garbage.
(Curiously, existing users were more disturbed by the lack of an error
in the non-int/fp/slice case than they were about getting garbage back.)
libctf/
* ctf-types.c (ctf_type_encoding): Fix the dynamic case to
work right for non-int/fps.
Nick Alcock [Thu, 8 Aug 2019 15:53:48 +0000 (16:53 +0100)]
libctf: allow ctf_type_lname of a null pointer.
The code was meant to handle this, but accidentally dereferenced the
null pointer before checking it for nullity.
v5: fix tabdamage.
libctf/
* ctf-types.c (ctf_type_name): Don't strlen a potentially-
null pointer.
Nick Alcock [Wed, 7 Aug 2019 17:01:08 +0000 (18:01 +0100)]
libctf: properly handle ctf_add_type of forwards and self-reffing structs
The code to handle structures (and unions) that refer to themselves in
ctf_add_type is extremely dodgy. It works by looking through the list
of not-yet-committed types for a structure with the same name as the
structure in question and assuming, if it finds it, that this must be a
reference to the same type. This is a linear search that gets ever
slower as the dictionary grows, requiring you to call ctf_update at
intervals to keep performance tolerable: but if you do that, you run
into the problem that if a forward declared before the ctf_update is
changed to a structure afterwards, ctf_update explodes.
The last commit fixed most of this: this commit can use it, adding a new
ctf_add_processing hash that tracks source type IDs that are currently
being processed and uses it to avoid infinite recursion rather than the
dynamic type list: we split ctf_add_type into a ctf_add_type_internal,
so that ctf_add_type itself can become a wrapper that empties out this
being-processed hash once the entire recursive type addition is over.
Structure additions themselves avoid adding their dependent types
quite so much by checking the type mapping and avoiding re-adding types
we already know we have added.
We also add support for adding forwards to dictionaries that already
contain the thing they are a forward to: we just silently return the
original type.
v4: return existing struct/union/enum types properly, rather than using
an uninitialized variable: shrinks sizes of CTF sections back down
to roughly where they were in v1/v2 of this patch series.
v5: fix tabdamage.
libctf/
* ctf-impl.h (ctf_file_t) <ctf_add_processing>: New.
* ctf-open.c (ctf_file_close): Free it.
* ctf-create.c (ctf_serialize): Adjust.
(membcmp): When reporting a conflict due to an error, report the
error.
(ctf_add_type): Turn into a ctf_add_processing wrapper. Rename to...
(ctf_add_type_internal): ... this. Hand back types we are already
in the middle of adding immediately. Hand back structs/unions with
the same number of members immediately. Do not walk the dynamic
list. Call ctf_add_type_internal, not ctf_add_type. Handle
forwards promoted to other types and the inverse case identically.
Add structs to the mapping as soon as we intern them, before they
gain any members.
Nick Alcock [Wed, 7 Aug 2019 16:55:09 +0000 (17:55 +0100)]
libctf: avoid the need to ever use ctf_update
The method of operation of libctf when the dictionary is writable has
before now been that types that are added land in the dynamic type
section, which is a linked list and hash of IDs -> dynamic type
definitions (and, recently a hash of names): the DTDs are a bit of CTF
representing the ctf_type_t and ad hoc C structures representing the
vlen. Historically, libctf was unable to do anything with these types,
not even look them up by ID, let alone by name: if you wanted to do that
say if you were adding a type that depended on one you just added) you
called ctf_update, which serializes all the DTDs into a CTF file and
reopens it, copying its guts over the fp it's called with. The
ctf_updated types are then frozen in amber and unchangeable: all lookups
will return the types in the static portion in preference to the dynamic
portion, and we will refuse to re-add things that already exist in the
static portion (and, of late, in the dynamic portion too). The libctf
machinery remembers the boundary between static and dynamic types and
looks in the right portion for each type. Lots of things still don't
quite work with dynamic types (e.g. getting their size), but enough
works to do a bunch of additions and then a ctf_update, most of the
time.
Except it doesn't, because ctf_add_type finds it necessary to walk the
full dynamic type definition list looking for types with matching names,
so it gets slower and slower with every type you add: fixing this
requires calling ctf_update periodically for no other reason than to
avoid massively slowing things down.
This is all clunky and very slow but kind of works, until you consider
that it is in fact possible and indeed necessary to modify one sort of
type after it has been added: forwards. These are necessarily promoted
to structs, unions or enums, and when they do so *their type ID does not
change*. So all of a sudden we are changing types that already exist in
the static portion. ctf_update gets massively confused by this and
allocates space enough for the forward (with no members), but then emits
the new dynamic type (with all the members) into it. You get an
assertion failure after that, if you're lucky, or a coredump.
So this commit rejigs things a bit and arranges to exclusively use the
dynamic type definitions in writable dictionaries, and the static type
definitions in readable dictionaries: we don't at any time have a mixture
of static and dynamic types, and you don't need to call ctf_update to
make things "appear". The ctf_dtbyname hash I introduced a few months
ago, which maps things like "struct foo" to DTDs, is removed, replaced
instead by a change of type of the four dictionaries which track names.
Rather than just being (unresizable) ctf_hash_t's populated only at
ctf_bufopen time, they are now a ctf_names_t structure, which is a pair
of ctf_hash_t and ctf_dynhash_t, with the ctf_hash_t portion being used
in readonly dictionaries, and the ctf_dynhash_t being used in writable
ones. The decision as to which to use is centralized in the new
functions ctf_lookup_by_rawname (which takes a type kind) and
ctf_lookup_by_rawhash, which it calls (which takes a ctf_names_t *.)
This change lets us switch from using static to dynamic name hashes on
the fly across the entirety of libctf without complexifying anything: in
fact, because we now centralize the knowledge about how to map from type
kind to name hash, it actually simplifies things and lets us throw out
quite a lot of now-unnecessary complexity, from ctf_dtnyname (replaced
by the dynamic half of the name tables), through to ctf_dtnextid (now
that a dictionary's static portion is never referenced if the dictionary
is writable, we can just use ctf_typemax to indicate the maximum type:
dynamic or non-dynamic does not matter, and we no longer need to track
the boundary between the types). You can now ctf_rollback() as far as
you like, even past a ctf_update or for that matter a full writeout; all
the iteration functions work just as well on writable as on read-only
dictionaries; ctf_add_type no longer needs expensive duplicated code to
run over the dynamic types hunting for ones it might be interested in;
and the linker no longer needs a hack to call ctf_update so that calling
ctf_add_type is not impossibly expensive.
There is still a bit more complexity: some new code paths in ctf-types.c
need to know how to extract information from dynamic types. This
complexity will go away again in a few months when libctf acquires a
proper intermediate representation.
You can still call ctf_update if you like (it's public API, after all),
but its only effect now is to set the point to which ctf_discard rolls
back.
Obviously *something* still needs to serialize the CTF file before
writeout, and this job is done by ctf_serialize, which does everything
ctf_update used to except set the counter used by ctf_discard. It is
automatically called by the various functions that do CTF writeout:
nobody else ever needs to call it.
With this in place, forwards that are promoted to non-forwards no longer
crash the link, even if it happens tens of thousands of types later.
v5: fix tabdamage.
libctf/
* ctf-impl.h (ctf_names_t): New.
(ctf_lookup_t) <ctf_hash>: Now a ctf_names_t, not a ctf_hash_t.
(ctf_file_t) <ctf_structs>: Likewise.
<ctf_unions>: Likewise.
<ctf_enums>: Likewise.
<ctf_names>: Likewise.
<ctf_lookups>: Improve comment.
<ctf_ptrtab_len>: New.
<ctf_prov_strtab>: New.
<ctf_str_prov_offset>: New.
<ctf_dtbyname>: Remove, redundant to the names hashes.
<ctf_dtnextid>: Remove, redundant to ctf_typemax.
(ctf_dtdef_t) <dtd_name>: Remove.
<dtd_data>: Note that the ctt_name is now populated.
(ctf_str_atom_t) <csa_offset>: This is now the strtab
offset for internal strings too.
<csa_external_offset>: New, the external strtab offset.
(CTF_INDEX_TO_TYPEPTR): Handle the LCTF_RDWR case.
(ctf_name_table): New declaration.
(ctf_lookup_by_rawname): Likewise.
(ctf_lookup_by_rawhash): Likewise.
(ctf_set_ctl_hashes): Likewise.
(ctf_serialize): Likewise.
(ctf_dtd_insert): Adjust.
(ctf_simple_open_internal): Likewise.
(ctf_bufopen_internal): Likewise.
(ctf_list_empty_p): Likewise.
(ctf_str_remove_ref): Likewise.
(ctf_str_add): Returns uint32_t now.
(ctf_str_add_ref): Likewise.
(ctf_str_add_external): Now returns a boolean (int).
* ctf-string.c (ctf_strraw_explicit): Check the ctf_prov_strtab
for strings in the appropriate range.
(ctf_str_create_atoms): Create the ctf_prov_strtab. Detect OOM
when adding the null string to the new strtab.
(ctf_str_free_atoms): Destroy the ctf_prov_strtab.
(ctf_str_add_ref_internal): Add make_provisional argument. If
make_provisional, populate the offset and fill in the
ctf_prov_strtab accordingly.
(ctf_str_add): Return the offset, not the string.
(ctf_str_add_ref): Likewise.
(ctf_str_add_external): Return a success integer.
(ctf_str_remove_ref): New, remove a single ref.
(ctf_str_count_strtab): Do not count the initial null string's
length or the existence or length of any unreferenced internal
atoms.
(ctf_str_populate_sorttab): Skip atoms with no refs.
(ctf_str_write_strtab): Populate the nullstr earlier. Add one
to the cts_len for the null string, since it is no longer done
in ctf_str_count_strtab. Adjust for csa_external_offset rename.
Populate the csa_offset for both internal and external cases.
Flush the ctf_prov_strtab afterwards, and reset the
ctf_str_prov_offset.
* ctf-create.c (ctf_grow_ptrtab): New.
(ctf_create): Call it. Initialize new fields rather than old
ones. Tell ctf_bufopen_internal that this is a writable dictionary.
Set the ctl hashes and data model.
(ctf_update): Rename to...
(ctf_serialize): ... this. Leave a compatibility function behind.
Tell ctf_simple_open_internal that this is a writable dictionary.
Pass the new fields along from the old dictionary. Drop
ctf_dtnextid and ctf_dtbyname. Use ctf_strraw, not dtd_name.
Do not zero out the DTD's ctt_name.
(ctf_prefixed_name): Rename to...
(ctf_name_table): ... this. No longer return a prefixed name: return
the applicable name table instead.
(ctf_dtd_insert): Use it, and use the right name table. Pass in the
kind we're adding. Migrate away from dtd_name.
(ctf_dtd_delete): Adjust similarly. Remove the ref to the
deleted ctt_name.
(ctf_dtd_lookup_type_by_name): Remove.
(ctf_dynamic_type): Always return NULL on read-only dictionaries.
No longer check ctf_dtnextid: check ctf_typemax instead.
(ctf_snapshot): No longer use ctf_dtnextid: use ctf_typemax instead.
(ctf_rollback): Likewise. No longer fail with ECTF_OVERROLLBACK. Use
ctf_name_table and the right name table, and migrate away from
dtd_name as in ctf_dtd_delete.
(ctf_add_generic): Pass in the kind explicitly and pass it to
ctf_dtd_insert. Use ctf_typemax, not ctf_dtnextid. Migrate away
from dtd_name to using ctf_str_add_ref to populate the ctt_name.
Grow the ptrtab if needed.
(ctf_add_encoded): Pass in the kind.
(ctf_add_slice): Likewise.
(ctf_add_array): Likewise.
(ctf_add_function): Likewise.
(ctf_add_typedef): Likewise.
(ctf_add_reftype): Likewise. Initialize the ctf_ptrtab, checking
ctt_name rather than dtd_name.
(ctf_add_struct_sized): Pass in the kind. Use
ctf_lookup_by_rawname, not ctf_hash_lookup_type /
ctf_dtd_lookup_type_by_name.
(ctf_add_union_sized): Likewise.
(ctf_add_enum): Likewise.
(ctf_add_enum_encoded): Likewise.
(ctf_add_forward): Likewise.
(ctf_add_type): Likewise.
(ctf_compress_write): Call ctf_serialize: adjust for ctf_size not
being initialized until after the call.
(ctf_write_mem): Likewise.
(ctf_write): Likewise.
* ctf-archive.c (arc_write_one_ctf): Likewise.
* ctf-lookup.c (ctf_lookup_by_name): Use ctf_lookuup_by_rawhash, not
ctf_hash_lookup_type.
(ctf_lookup_by_id): No longer check the readonly types if the
dictionary is writable.
* ctf-open.c (init_types): Assert that this dictionary is not
writable. Adjust to use the new name hashes, ctf_name_table,
and ctf_ptrtab_len. GNU style fix for the final ptrtab scan.
(ctf_bufopen_internal): New 'writable' parameter. Flip on LCTF_RDWR
if set. Drop out early when dictionary is writable. Split the
ctf_lookups initialization into...
(ctf_set_cth_hashes): ... this new function.
(ctf_simple_open_internal): Adjust. New 'writable' parameter.
(ctf_simple_open): Adjust accordingly.
(ctf_bufopen): Likewise.
(ctf_file_close): Destroy the appropriate name hashes. No longer
destroy ctf_dtbyname, which is gone.
(ctf_getdatasect): Remove spurious "extern".
* ctf-types.c (ctf_lookup_by_rawname): New, look up types in the
specified name table, given a kind.
(ctf_lookup_by_rawhash): Likewise, given a ctf_names_t *.
(ctf_member_iter): Add support for iterating over the
dynamic type list.
(ctf_enum_iter): Likewise.
(ctf_variable_iter): Likewise.
(ctf_type_rvisit): Likewise.
(ctf_member_info): Add support for types in the dynamic type list.
(ctf_enum_name): Likewise.
(ctf_enum_value): Likewise.
(ctf_func_type_info): Likewise.
(ctf_func_type_args): Likewise.
* ctf-link.c (ctf_accumulate_archive_names): No longer call
ctf_update.
(ctf_link_write): Likewise.
(ctf_link_intern_extern_string): Adjust for new
ctf_str_add_external return value.
(ctf_link_add_strtab): Likewise.
* ctf-util.c (ctf_list_empty_p): New.
Nick Alcock [Mon, 5 Aug 2019 10:40:33 +0000 (11:40 +0100)]
libctf: handle nonrepresentable types at link time
GCC can emit references to type 0 to indicate that this type is one that
is not representable in the version of CTF it emits (for instance,
version 3 cannot encode vector types). Type 0 is already used in the
function section to indicate padding inserted to skip functions we do
not want to encode the type of, so using zero in this way is a good
extension of the format: but libctf reports such types as ECTF_BADID,
which is indistinguishable from file corruption via links to truly
nonexistent types with IDs like 0xDEADBEEF etc, which we really do want
to stop for.
In particular, this stops all traversals of types dead at this point,
preventing us from even dumping CTF files containing unrepresentable
types to see what's going on!
So add a new error, ECTF_NONREPRESENTABLE, which is returned by
recursive type resolution when a reference to a zero type is found. (No
zero type is ever emitted into the CTF file by GCC, only references to
one). We can't do much with types that are ultimately nonrepresentable,
but we can do enough to keep functioning.
Adjust ctf_add_type to ensure that top-level types of type zero and
structure and union members of ultimate type zero are simply skipped
without reporting an error, so we can copy structures and unions that
contain nonrepresentable members (skipping them and leaving a hole where
they would be, so no consumers downstream of the linker need to worry
about this): adjust the dumper so that we dump members of
nonrepresentable types in a simple form that indicates
nonrepresentability rather than terminating the dump, and do not falsely
assume all errors to be -ENOMEM: adjust the linker so that types that
fail to get added are simply skipped, so that both nonrepresentable
types and outright errors do not terminate the type addition, which
could skip many valid types and cause further errors when variables of
those types are added.
In future, when we gain the ability to call back to the linker to report
link-time type resolution errors, we should report failures to add all
but nonrepresentable types. But we can't do that yet.
v5: Fix tabdamage.
include/
* ctf-api.h (ECTF_NONREPRESENTABLE): New.
libctf/
* ctf-types.c (ctf_type_resolve): Return ECTF_NONREPRESENTABLE on
type zero.
* ctf-create.c (ctf_add_type): Detect and skip nonrepresentable
members and types.
(ctf_add_variable): Likewise for variables pointing to them.
* ctf-link.c (ctf_link_one_type): Do not warn for nonrepresentable
type link failure, but do warn for others.
* ctf-dump.c (ctf_dump_format_type): Likewise. Do not assume all
errors to be ENOMEM.
(ctf_dump_member): Likewise.
(ctf_dump_type): Likewise.
(ctf_dump_header_strfield): Do not assume all errors to be ENOMEM.
(ctf_dump_header_sectfield): Do not assume all errors to be ENOMEM.
(ctf_dump_header): Likewise.
(ctf_dump_label): likewise.
(ctf_dump_objts): likewise.
(ctf_dump_funcs): likewise.
(ctf_dump_var): likewise.
(ctf_dump_str): Likewise.
Nick Alcock [Fri, 2 Aug 2019 23:41:05 +0000 (00:41 +0100)]
objdump: get CTF parent importing right
The linker emits CTF into a single section named .ctf, which is a CTF
archive where the default member (itself named ".ctf", or simply NULL)
is the parent of all other members. Teach objdump to look for this by
default, rather than only trying to do it if a specific CTF parent
section was specified. (If no parent name is specified, we get the .ctf
member from the same section as everything else, which matches what the
linker generates.)
binutils/
* objdump.c (dump_ctf): Use the default CTF archive member as the
parent even when no parent section is specified.
(dump_ctf_archive_member): Only import from the parent
if this is not the default ".ctf" member.
Nick Alcock [Sat, 20 Jul 2019 13:45:12 +0000 (14:45 +0100)]
libctf: installable libctf as a shared library
This lets other programs read and write CTF-format data.
Two versioned shared libraries are created: libctf.so and
libctf-nobfd.so. They contain identical content except that
libctf-nobfd.so contains no references to libbfd and does not implement
ctf_open, ctf_fdopen, ctf_bfdopen or ctf_bfdopen_ctfsect, so it can be
used by programs that cannot use BFD, like readelf.
The soname major version is presently .0 until the linker API
stabilizes, when it will flip to .1 and hopefully never change again.
New in v3.
v4: libtoolize and turn into a pair of shared libraries. Drop
--enable-install-ctf: now controlled by --enable-shared and
--enable-install-libbfd, like everything else.
v5: Add ../bfd to ACLOCAL_AMFLAGS and AC_CONFIG_MACRO_DIR. Fix tabdamage.
* Makefile.def (host_modules): libctf is no longer no_install.
* Makefile.in: Regenerated.
libctf/
* configure.ac (AC_DISABLE_SHARED): New, like opcodes/.
(LT_INIT): Likewise.
(AM_INSTALL_LIBBFD): Likewise.
(dlopen): Note why this is necessary in a comment.
(SHARED_LIBADD): Initialize for possibly-PIC libiberty: derived from
opcodes/.
(SHARED_LDFLAGS): Likewise.
(BFD_LIBADD): Likewise, for libbfd.
(BFD_DEPENDENCIES): Likewise.
(VERSION_FLAGS): Initialize, using a version script if ld supports
one, or libtool -export-symbols-regex otherwise.
(AC_CONFIG_MACRO_DIR): Add ../BFD.
* Makefile.am (ACLOCAL_AMFLAGS): Likewise.
(INCDIR): New.
(AM_CPPFLAGS): Use $(srcdir), not $(top_srcdir).
(noinst_LIBRARIES): Replace with...
[INSTALL_LIBBFD] (lib_LTLIBRARIES): This, or...
[!INSTALL_LIBBFD] (noinst_LTLIBRARIES): ... this, mentioning new
libctf-nobfd.la as well.
[INSTALL_LIBCTF] (include_HEADERS): Add the CTF headers.
[!INSTALL_LIBCTF] (include_HEADERS): New, empty.
(libctf_a_SOURCES): Rename to...
(libctf_nobfd_la_SOURCES): ... this, all of libctf other than
ctf-open-bfd.c.
(libctf_la_SOURCES): Now derived from libctf_nobfd_la_SOURCES,
with ctf-open-bfd.c added.
(libctf_nobfd_la_LIBADD): New, using @SHARED_LIBADD@.
(libctf_la_LIBADD): New, using @BFD_LIBADD@ as well.
(libctf_la_DEPENDENCIES): New, using @BFD_DEPENDENCIES@.
* Makefile.am [INSTALL_LIBCTF]: Use it.
* aclocal.m4: Add ../bfd/acinclude.m4, ../config/acx.m4, and the
libtool macros.
* libctf.ver: New, everything is version LIBCTF_1.0 currently (even
the unstable components).
* Makefile.in: Regenerated.
* config.h.in: Likewise.
* configure: Likewise.
binutils/
* Makefile.am (LIBCTF): Mention the .la file.
(LIBCTF_NOBFD): New.
(readelf_DEPENDENCIES): Use it.
(readelf_LDADD): Likewise.
* Makefile.in: Regenerated.
ld/
* configure.ac (TESTCTFLIB): Set to the .so or .a, like TESTBFDLIB.
* Makefile.am (TESTCTFLIB): Use it.
(LIBCTF): Use the .la file.
(check-DEJAGNU): Use it.
* Makefile.in: Regenerated.
* configure: Likewise.
include/
* ctf-api.h: Note the instability of the ctf_link interfaces.
Nick Alcock [Sat, 13 Jul 2019 21:38:00 +0000 (22:38 +0100)]
bfd, ld: add CTF section linking
This is quite complicated because the CTF section's contents depend on
the final contents of the symtab and strtab, because it has two sections
whose contents are shuffled to be in 1:1 correspondence with the symtab,
and an internal strtab that gets deduplicated against the ELF strtab
(with offsets adjusted to point into the ELF strtab instead). It is
also compressed if large enough, so its size depends on its contents!
So we cannot construct it as early as most sections: we cannot even
*begin* construction until after the symtab and strtab are finalized.
Thankfully there is already one section treated similarly: compressed
debugging sections: the only differences are that compressed debugging
sections have extra handling to deal with their changing name if
compressed (CTF sections are always called ".ctf" for now, though we
have reserved ".ctf.*" against future use), and that compressed
debugging sections have previously-uncompressed content which has to be
stashed away for later compression, while CTF sections have no content
at all until we generate it (very late).
BFD also cannot do the link itself: libctf knows how to do it, and BFD
cannot call libctf directly because libctf already depends on bfd for
file I/O. So we have to use a pair of callbacks, one, examine_strtab,
which allows a caller to examine the symtab and strtab after
finalization (called from elf_link_swap_symbols_out(), right before the
symtabs are written, and after the strtab has been finalized), and one
which actually does the emission (called emit_ctf simply because it is
grouped with a bunch of section-specific late-emission function calls at
the bottom of bfd_elf_final_link, and a section-specific name seems best
for that). emit_ctf is actually called *twice*: once from lang_process
if the emulation suggests that this bfd target does not examine the
symtab or strtab, and once via a bfd callback if it does. (This means
that non-ELF targets still get CTF emitted, even though the late CTF
emission stage is never called for them).
v2: merged with non-ELF support patch: slight commit message
adjustments.
v3: do not spend time merging CTF, or crash, if the CTF section is
explicitly discarded. Do not try to merge or compress CTF unless
linking.
v4: add CTF_COMPRESSION_THRESHOLD. Annul the freed input ctf_file_t's
after writeout: set SEC_IN_MEMORY on the output contents so a future
bfd enhancement knows it could free it. Add SEC_LINKER_CREATED |
SEC_KEEP to avoid having to add .ctf to the linker script. Drop
now-unnecessary ldlang.h-level elf-bfd.h include and hackery around
it. Adapt to elf32.em->elf.em and elf-generic.em->ldelf*.c
changes.
v5: fix tabdamage. Drop #inclusions in .h files: include in .c files,
.em files, and use struct forwards instead. Use bfd_section_is_ctf
inline function rather than SECTION_IS_CTF macro. Move a few
comments.
* Makefile.def (dependencies): all-ld depends on all-libctf.
* Makefile.in: Regenerated.
include/
* bfdlink.h (elf_strtab_hash): New forward.
(elf_sym_strtab): Likewise.
(struct bfd_link_callbacks <examine_strtab>): New.
(struct bfd_link_callbacks <emit_ctf>): Likewise.
bfd/
* elf-bfd.h (bfd_section_is_ctf): New inline function.
* elf.c (special_sections_c): Add ".ctf".
(assign_file_positions_for_non_load_sections): Note that
compressed debugging sections etc are not assigned here. Treat
CTF sections like SEC_ELF_COMPRESS sections when is_linker_output:
sh_offset -1.
(assign_file_positions_except_relocs): Likewise.
(find_section_in_list): Note that debugging and CTF sections, as
well as reloc sections, are assigned later.
(_bfd_elf_assign_file_positions_for_non_load): CTF sections get
their size and contents updated.
(_bfd_elf_set_section_contents): Skip CTF sections: unlike
compressed sections, they have no uncompressed content to copy at
this stage.
* elflink.c (elf_link_swap_symbols_out): Call the examine_strtab
callback right before the strtab is written out.
(bfd_elf_final_link): Don't cache the section contents of CTF
sections: they are not populated yet. Call the emit_ctf callback
right at the end, after all the symbols and strings are flushed
out.
ld/
* ldlang.h: (struct lang_input_statement_struct): Add the_ctf.
(struct elf_sym_strtab): Add forward.
(struct elf_strtab_hash): Likewise.
(ldlang_ctf_apply_strsym): Declare.
(ldlang_write_ctf_late): Likewise.
* ldemul.h (ldemul_emit_ctf_early): New.
(ldemul_examine_strtab_for_ctf): Likewise.
(ld_emulation_xfer_type) <emit_ctf_early>: Likewise.
(ld_emulation_xfer_type) <examine_strtab_for_ctf>: Likewise.
* ldemul.c (ldemul_emit_ctf_early): New.
(ldemul_examine_strtab_for_ctf): Likewise.
* ldlang.c: Include ctf-api.h.
(CTF_COMPRESSION_THRESHOLD): New.
(ctf_output): New. Initialized in...
(ldlang_open_ctf): ... this new function. Open all the CTF
sections in the input files: mark them non-loaded and empty
so as not to copy their contents to the output, but linker-created
so the section gets created in the target.
(ldlang_merge_ctf): New, merge types via ctf_link_add_ctf and
ctf_link.
(ldlang_ctf_apply_strsym): New, an examine_strtab callback: wrap
ldemul_examine_strtab_for_ctf.
(lang_write_ctf): New, write out the CTF section.
(ldlang_write_ctf_late): New, late call via bfd's emit_ctf hook.
(lang_process): Call ldlang_open_ctf, ldlang_merge_ctf, and
lang_write_ctf.
* ldmain.c (link_callbacks): Add ldlang_ctf_apply_strsym,
ldlang_write_ctf_late.
* emultempl/aix.em: Add ctf-api.h.
* emultempl/armcoff.em: Likewise.
* emultempl/beos.em: Likewise.
* emultempl/elf.em: Likewise.
* emultempl/generic.em: Likewise.
* emultempl/linux.em: Likewise.
* emultempl/msp430.em: Likewise.
* emultempl/pe.em: Likewise.
* emultempl/pep.em: Likewise.
* emultempl/ticoff.em: Likewise.
* emultempl/vanilla.em: Likewise.
* ldcref.c: Likewise.
* ldctor.c: Likewise.
* ldelf.c: Likewise.
* ldelfgen.c: Likewise.
* ldemul.c: Likewise.
* ldexp.c: Likewise.
* ldfile.c: Likewise.
* ldgram.c: Likewise.
* ldlex.l: Likewise.
* ldmain.c: Likewise.
* ldmisc.c: Likewise.
* ldver.c: Likewise.
* ldwrite.c: Likewise.
* lexsup.c: Likewise.
* mri.c: Likewise.
* pe-dll.c: Likewise.
* plugin.c: Likewise.
* ldelfgen.c (ldelf_emit_ctf_early): New.
(ldelf_examine_strtab_for_ctf): tell libctf about the symtab and
strtab.
(struct ctf_strsym_iter_cb_arg): New, state to do so.
(ldelf_ctf_strtab_iter_cb): New: tell libctf about
each string in the strtab in turn.
(ldelf_ctf_symbols_iter_cb): New, tell libctf
about each symbol in the symtab in turn.
* ldelfgen.h (struct elf_sym_strtab): Add forward.
(struct elf_strtab_hash): Likewise.
(struct ctf_file): Likewise.
(ldelf_emit_ctf_early): Declare.
(ldelf_examine_strtab_for_ctf): Likewise.
* emultempl/elf-generic.em (LDEMUL_EMIT_CTF_EARLY): Set it.
(LDEMUL_EXAMINE_STRTAB_FOR_CTF): Likewise.
* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Add
emit_ctf_early and examine_strtab_for_ctf, NULL by default.
* emultempl/armcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/beos.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/linux.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/msp430.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/pe.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/pep.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/ticoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/vanilla.em (ld_vanilla_emulation): Likewise.
* Makefile.am: Pull in libctf (and zlib, a transitive requirement
for compressed CTF section emission). Pass it on to DejaGNU.
* configure.ac: Add AM_ZLIB.
* aclocal.m4: Added zlib.m4.
* Makefile.in: Regenerated.
* testsuite/ld-bootstrap/bootstrap.exp: Use it when relinking ld.
Nick Alcock [Sat, 13 Jul 2019 20:47:30 +0000 (21:47 +0100)]
bfd: new functions for getting strings out of a strtab
The CTF linking process wants to deduplicate the CTF strtab against the
ELF strtab, for which it needs to know the number of strings in the
strtab and it needs to be able to extract them one by one.
The BFD strtab functions only support returning the
size-or-section-length of the strtab (with _bfd_elf_strtab_size)
and returning the offset (but not string!) and decrementing the refcount
at the same time.
So add new functions _bfd_elf_strtab_len (that just returns the length
in strings of the strtab, never the section size) and bfd_elf_strtab_str
(which returns the string at a given strtab index, and its offset,
without touching the refcount).
It is probably a mistake to use _bfd_elf_strtab_str in particular before
_bfd_elf_strtab_finalize is called, and will not produce useful output
if you do so.
v5: fix tabdamage.
bfd/
* elf-strtab.c (_bfd_elf_strtab_len): New.
(_bfd_elf_strtab_str): Likewise.
* bfd-elf.h: Declare them.
Nick Alcock [Mon, 29 Jul 2019 16:02:48 +0000 (17:02 +0100)]
libctf: actually close bfds we have opened
When we do a ctf_fdopen, we open things via bfd_fdopenr and set up a
hook to close the bfd again... but then we never actually call that hook
from anywhere, so we eventually leak every bfd we open.
Fix this by calling the hook (if set) in ctf_arc_close.
New in v3.
libctf/
* ctf-archive.c (ctf_arc_close): Call ctfi_bfd_close if set.
* ctf-open-bfd.c (ctf_bfdclose): Fix comment.
Nick Alcock [Fri, 26 Jul 2019 20:52:11 +0000 (21:52 +0100)]
libctf: bfd-open: mark the bfd as cacheable
Without this, the FD is only closed when the CTF file is, leading to
running out of fds on (e.g.) very large links.
New in v3.
libctf/
* ctf-open-bfd.c (ctf_fdopen): Call bfd_set_cacheable.
Nick Alcock [Sat, 13 Jul 2019 20:45:55 +0000 (21:45 +0100)]
libctf: get rid of a disruptive public include of <sys/param.h>
This hoary old header defines things like MAX that users of libctf might
perfectly reasonably define themselves.
The CTF headers do not need it: move it into libctf/ctf-impl.h instead.
include/
* ctf-api.h (includes): No longer include <sys/param.h>.
libctf/
* ctf-impl.h (includes): Include <sys/param.h> here.
Nick Alcock [Thu, 25 Jul 2019 18:59:32 +0000 (19:59 +0100)]
libctf: eschew C99 for loop initial declarations
We shouldn't use these, since binutils doesn't require a C99-capable
compiler yet.
New in v3.
v5: fix tabdamage.
libctf/
* ctf-open.c (flip_lbls): Eschew for-loop initial declarations.
(flip_objts): Likewise.
(flip_vars): Likewise.
(flip_types): Likewise.
Nick Alcock [Wed, 24 Jul 2019 14:21:56 +0000 (15:21 +0100)]
libctf: don't leak hash keys or values on value replacement
When a ctf_dynhash_insert() finds a slot already existing, it should
call the key and value free functions on the existing key and value and
move the passed-in key into place, so that the lifetime rules for hash
keys are always the same no matter whether the key existed or not but
neither are the keys or values leaked.
New in v3.
v5: fix tabdamage.
libctf/
* ctf-hash.c (ctf_hashtab_insert): Pass in the key and value
freeing functions: if set, free the key and value if the slot
already exists. Always reassign the key.
(ctf_dynhash_insert): Adjust call appropriately.
(ctf_hash_insert_type): Likewise.
Nick Alcock [Fri, 2 Aug 2019 23:46:01 +0000 (00:46 +0100)]
libctf: teach ctf_add_type how forwards work
This machinery has been broken for as long as Solaris has existed.
Forwards are meant to encode "struct foo;", "enum foo;" or "union
foo;". Obviously these all exist in distinct namespaces, so forwards
store the type kind they forward to in their ctt_type member
(which makes conceptual sense if you squint at it). The addition
machinery uses this to promote forwards to the appropriate type as
needed.
Unfortunately ctf_add_type does not: it checks the global namespace
(which is always wrong), and so fails with a spurious conflict if you
have, say, a typedef and then a forward comes along with the same name,
even if it's a forward to something like a struct. (This was observed
with <libio.h>, which has "struct _IO_FILE;" and also
"typedef struct _IO_FILE _IO_FILE"). We should look at the recorded
type kind and look in the appropriate namespace. We should also,
when creating the forward in the new container, use that type kind,
rather than just defaulting to CTF_K_STRUCT and hoping that what
eventually comes along is a struct.
This bug is as old as the first implementation of ctf_add_type in
Solaris. But we also want a new feature for the linker, closely-related
and touching the same code so we add it here: not only do we want a
forward followed by a struct/union/enum to promote the forward, but
we want want a struct/union/enum followed by a forward to act as a NOP
and return the existing type, because when we're adding many files
in succession to a target link, there will often be already-promoted
forwards (in the shape of a struct/union/enum) that want to unify
with duplicate forwards coming from other object files.
v5: fix tabdamage.
libctf/
* ctf-create.c (ctf_add_type): Look up and use the forwarded-to
type kind. Allow forwards to unify with pre-existing structs/
unions/enums.
Nick Alcock [Sat, 20 Jul 2019 13:44:44 +0000 (14:44 +0100)]
libctf: add CU-mapping machinery
Once the deduplicator is capable of actually detecting conflicting types
with the same name (i.e., not yet) we will place such conflicting types,
and types that depend on them, into CTF dictionaries that are the child
of the main dictionary we usually emit: currently, this will lead to the
.ctf section becoming a CTF archive rather than a single dictionary,
with the default-named archive member (_CTF_SECTION, or NULL) being the
main shared dictionary with most of the types in it.
By default, the sections are named after the compilation unit they come
from (complete path and all), with the cuname field in the CTF header
providing further evidence of the name without requiring the caller to
engage in tiresome parsing. But some callers may not wish the mapping
from input CU to output sub-dictionary to be purely CU-based.
The machinery here allows this to be freely changed, in two ways:
- callers can call ctf_link_add_cu_mapping to specify that a single
input compilation unit should have its types placed in some other CU
if they conflict: the CU will always be created, even if empty, so
the consuming program can depend on its existence. You can map
multiple input CUs to one output CU to force all their types to be
merged together: if some of *those* types conflict, the behaviour is
currently unspecified (the new deduplicator will specify it).
- callers can call ctf_link_set_memb_name_changer to provide a function
which is passed every CTF sub-dictionary name in turn (including
_CTF_SECTION) and can return a new name, or NULL if no change is
desired. The mapping from input to output names should not map two
input names to the same output name: if this happens, the two are not
merged but will result in an archive with two members with the same
name (technically valid, but it's hard to access the second
same-named member: you have to do an iteration over archive members).
This is used by the kernel's ctfarchive machinery (not yet upstream) to
encode CTF under member names like {module name}.ctf rather than
.ctf.CU, but it is anticipated that other large projects may wish to
have their own storage for CTF outside of .ctf sections and may wish to
have new naming schemes that suit their special-purpose consumers.
New in v3.
v4: check for strdup failure.
v5: fix tabdamage.
include/
* ctf-api.h (ctf_link_add_cu_mapping): New.
(ctf_link_memb_name_changer_f): New.
(ctf_link_set_memb_name_changer): New.
libctf/
* ctf-impl.h (ctf_file_t) <ctf_link_cu_mappping>: New.
<ctf_link_memb_name_changer>: Likewise.
<ctf_link_memb_name_changer_arg>: Likewise.
* ctf-create.c (ctf_update): Update accordingly.
* ctf-open.c (ctf_file_close): Likewise.
* ctf-link.c (ctf_create_per_cu): Apply the cu mapping.
(ctf_link_add_cu_mapping): New.
(ctf_link_set_memb_name_changer): Likewise.
(ctf_change_parent_name): New.
(ctf_name_list_accum_cb_arg_t) <dynames>: New, storage for names
allocated by the caller's ctf_link_memb_name_changer.
<ndynames>: Likewise.
(ctf_accumulate_archive_names): Call the ctf_link_memb_name_changer.
(ctf_link_write): Likewise (for _CTF_SECTION only): also call
ctf_change_parent_name. Free any resulting names.
Nick Alcock [Sat, 13 Jul 2019 20:41:25 +0000 (21:41 +0100)]
libctf: add linking of the variable section
The compiler describes the name and type of all file-scope variables in
this section. Merging it at link time requires using the type mapping
added in the previous commit to determine the appropriate type for the
variable in the output, given its type in the input: we check the shared
container first, and if the type doesn't exist there, it must be a
conflicted type in the per-CU child, and the variable should go there
too. We also put the variable in the per-CU child if a variable with
the same name but a different type already exists in the parent: we
ignore any such conflict in the child because CTF cannot represent such
things, nor can they happen unless a third-party linking program has
overridden the mapping of CU to CTF archive member name (using machinery
added in a later commit).
v3: rewritten using an algorithm that actually works in the case of
conflicting names. Some code motion from the next commit. Set
the per-CU parent name.
v4: check for strdup failure.
v5: fix tabdamage.
include/
* ctf-api.h (ECTF_INTERNAL): New.
libctf/
* ctf-link.c (ctf_create_per_cu): New, refactored out of...
(ctf_link_one_type): ... here, with parent-name setting added.
(check_variable): New.
(ctf_link_one_variable): Likewise.
(ctf_link_one_input_archive_member): Call it.
* ctf-error.c (_ctf_errlist): Updated with new errors.
Nick Alcock [Sat, 13 Jul 2019 20:31:26 +0000 (21:31 +0100)]
libctf: map from old to corresponding newly-added types in ctf_add_type
This lets you call ctf_type_mapping (dest_fp, src_fp, src_type_id)
and get told what type ID the corresponding type has in the target
ctf_file_t. This works even if it was added by a recursive call, and
because it is stored in the target ctf_file_t it works even if we
had to add one type to multiple ctf_file_t's as part of conflicting
type handling.
We empty out this mapping after every archive is linked: because it maps
input to output fps, and we only visit each input fp once, its contents
are rendered entirely useless every time the source fp changes.
v3: add several missing mapping additions. Add ctf_dynhash_empty, and
empty after every input archive.
v5: fix tabdamage.
libctf/
* ctf-impl.h (ctf_file_t): New field ctf_link_type_mapping.
(struct ctf_link_type_mapping_key): New.
(ctf_hash_type_mapping_key): Likewise.
(ctf_hash_eq_type_mapping_key): Likewise.
(ctf_add_type_mapping): Likewise.
(ctf_type_mapping): Likewise.
(ctf_dynhash_empty): Likewise.
* ctf-open.c (ctf_file_close): Update accordingly.
* ctf-create.c (ctf_update): Likewise.
(ctf_add_type): Populate the mapping.
* ctf-hash.c (ctf_hash_type_mapping_key): Hash a type mapping key.
(ctf_hash_eq_type_mapping_key): Check the key for equality.
(ctf_dynhash_insert): Fix comment typo.
(ctf_dynhash_empty): New.
* ctf-link.c (ctf_add_type_mapping): New.
(ctf_type_mapping): Likewise.
(empty_link_type_mapping): New.
(ctf_link_one_input_archive): Call it.
Nick Alcock [Sat, 13 Jul 2019 20:06:55 +0000 (21:06 +0100)]
libctf: add the ctf_link machinery
This is the start of work on the core of the linking mechanism for CTF
sections. This commit handles the type and string sections.
The linker calls these functions in sequence:
ctf_link_add_ctf: to add each CTF section in the input in turn to a
newly-created ctf_file_t (which will appear in the output, and which
itself will become the shared parent that contains types that all
TUs have in common (in all link modes) and all types that do not
have conflicting definitions between types (by default). Input files
that are themselves products of ld -r are supported, though this is
not heavily tested yet.
ctf_link: called once all input files are added to merge the types in
all the input containers into the output container, eliminating
duplicates.
ctf_link_add_strtab: called once the ELF string table is finalized and
all its offsets are known, this calls a callback provided by the
linker which returns the string content and offset of every string in
the ELF strtab in turn: all these strings which appear in the input
CTF strtab are eliminated from it in favour of the ELF strtab:
equally, any strings that only appear in the input strtab will
reappear in the internal CTF strtab of the output.
ctf_link_shuffle_syms (not yet implemented): called once the ELF symtab
is finalized, this calls a callback provided by the linker which
returns information on every symbol in turn as a ctf_link_sym_t. This
is then used to shuffle the function info and data object sections in
the CTF section into symbol table order, eliminating the index
sections which map those sections to symbol names before that point.
Currently just returns ECTF_NOTYET.
ctf_link_write: Returns a buffer containing either a serialized
ctf_file_t (if there are no types with conflicting definitions in the
object files in the link) or a ctf_archive_t containing a large
ctf_file_t (the common types) and a bunch of small ones named after
individual CUs in which conflicting types are found (containing the
conflicting types, and all types that reference them). A threshold
size above which compression takes place is passed as one parameter.
(Currently, only gzip compression is supported, but I hope to add lzma
as well.)
Lifetime rules for this are simple: don't close the input CTF files
until you've called ctf_link for the last time. We do not assume
that symbols or strings passed in by the callback outlast the
call to ctf_link_add_strtab or ctf_link_shuffle_syms.
Right now, the duplicate elimination mechanism is the one already
present as part of the ctf_add_type function, and is not particularly
good: it misses numerous actual duplicates, and the conflicting-types
detection hardly ever reports that types conflict, even when they do
(one of them just tends to get silently dropped): it is also very slow.
This will all be fixed in the next few weeks, but the fix hardly touches
any of this code, and the linker does work without it, just not as
well as it otherwise might. (And when no CTF section is present,
there is no effect on performance, of course. So only people using
a trunk GCC with not-yet-committed patches will even notice. By the
time it gets upstream, things should be better.)
v3: Fix error handling.
v4: check for strdup failure.
v5: fix tabdamage.
include/
* ctf-api.h (struct ctf_link_sym): New, a symbol in flight to the
libctf linking machinery.
(CTF_LINK_SHARE_UNCONFLICTED): New.
(CTF_LINK_SHARE_DUPLICATED): New.
(ECTF_LINKADDEDLATE): New, replacing ECTF_UNUSED.
(ECTF_NOTYET): New, a 'not yet implemented' message.
(ctf_link_add_ctf): New, add an input file's CTF to the link.
(ctf_link): New, merge the type and string sections.
(ctf_link_strtab_string_f): New, callback for feeding strtab info.
(ctf_link_iter_symbol_f): New, callback for feeding symtab info.
(ctf_link_add_strtab): New, tell the CTF linker about the ELF
strtab's strings.
(ctf_link_shuffle_syms): New, ask the CTF linker to shuffle its
symbols into symtab order.
(ctf_link_write): New, ask the CTF linker to write the CTF out.
libctf/
* ctf-link.c: New file, linking of the string and type sections.
* Makefile.am (libctf_a_SOURCES): Add it.
* Makefile.in: Regenerate.
* ctf-impl.h (ctf_file_t): New fields ctf_link_inputs,
ctf_link_outputs.
* ctf-create.c (ctf_update): Update accordingly.
* ctf-open.c (ctf_file_close): Likewise.
* ctf-error.c (_ctf_errlist): Updated with new errors.
Nick Alcock [Sat, 13 Jul 2019 19:50:49 +0000 (20:50 +0100)]
libctf: dump: check the right error values when dumping functions
We weren't correctly detecting when there were no functions to dump in
the function info table, because we were checking for ECTF_NOTYPEDAT,
which means there are no *data objects* to dump.
Adjust accordingly.
libctf/
* ctf-dump.c (ctf_dump_funcs): Check the right error value.
Nick Alcock [Sat, 13 Jul 2019 19:49:19 +0000 (20:49 +0100)]
libctf: dump: support non-root type dumping
Use the recently-added ctf_type_iter_all function to iterate over
non-root types, too, indicating them via {....} surrounding the type
description in the dump.
libctf/
* ctf-dump.c (ctf_dump): Use ctf_type_iter_all to dump types, not
ctf_type_iter.
(ctf_dump_type): Pass down the flag from ctf_type_iter_all.
(ctf_dump_format_type): Add non-root-type { } notation.
Add root flag to prototype.
(ctf_dump_label): Adjust accordingly.
(ctf_dump_objts): Likewise.
(ctf_dump_var): Likewise.
Nick Alcock [Sat, 13 Jul 2019 19:44:38 +0000 (20:44 +0100)]
libctf: fix double-free on ctf_compress_write error path
We were freeing the compressed data buffer twice if compression failed.
v4: Fix commit message.
v5: fix tabdamage.
libctf/
* ctf-create.c (ctf_compress_write): Fix double-free.
Nick Alcock [Sat, 13 Jul 2019 19:40:52 +0000 (20:40 +0100)]
libctf: write CTF files to memory, and CTF archives to fds
Before now, we've been able to write CTF files to gzFile descriptors or
fds, and CTF archives to named files only.
Make this a bit less irregular by allowing CTF archives to be written
to fds with the new function ctf_arc_write_fd: also allow CTF
files to be written to a new memory buffer via ctf_write_mem.
(It would be nice to complete things by adding a new function to write
CTF archives to memory, but this is too difficult to do given the short
time the linker is expected to be writing them out: we will transition
to a better format in format v4, though we will always support reading
CTF archives that are stored in .ctf sections.)
include/
* ctf-api.h (ctf_arc_write_fd): New.
(ctf_write_mem): Likewise.
(ctf_gzwrite): Spacing fix.
libctf/
* ctf-archive.c (ctf_arc_write): Split off, and reimplement in terms
of...
(ctf_arc_write_fd): ... this new function.
* ctf-create.c (ctf_write_mem): New.
Nick Alcock [Sat, 13 Jul 2019 19:33:01 +0000 (20:33 +0100)]
libctf: support getting strings from the ELF strtab
The CTF file format has always supported "external strtabs", which
internally are strtab offsets with their MSB on: such refs
get their strings from the strtab passed in at CTF file open time:
this is usually intended to be the ELF strtab, and that's what this
implementation is meant to support, though in theory the external
strtab could come from anywhere.
This commit adds support for these external strings in the ctf-string.c
strtab tracking layer. It's quite easy: we just add a field csa_offset
to the atoms table that tracks all strings: this field tracks the offset
of the string in the ELF strtab (with its MSB already on, courtesy of a
new macro CTF_SET_STID), and adds a new function that sets the
csa_offset to the specified offset (plus MSB). Then we just need to
avoid writing out strings to the internal strtab if they have csa_offset
set, and note that the internal strtab is shorter than it might
otherwise be.
(We could in theory save a little more time here by eschewing sorting
such strings, since we never actually write the strings out anywhere,
but that would mean storing them separately and it's just not worth the
complexity cost until profiling shows it's worth doing.)
We also have to go through a bit of extra effort at variable-sorting
time. This was previously using direct references to the internal
strtab: it couldn't use ctf_strptr or ctf_strraw because the new strtab
is not yet ready to put in its usual field (in a ctf_file_t that hasn't
even been allocated yet at this stage): but now we're using the external
strtab, this will no longer do because it'll be looking things up in the
wrong strtab, with disastrous results. Instead, pass the new internal
strtab in to a new ctf_strraw_explicit function which is just like
ctf_strraw except you can specify a ne winternal strtab to use.
But even now that it is using a new internal strtab, this is not quite
enough: it can't look up strings in the external strtab because ld
hasn't written it out yet, and when it does will write it straight to
disk. Instead, when we write the internal strtab, note all the offset
-> string mappings that we have noted belong in the *external* strtab to
a new "synthetic external strtab" dynhash, ctf_syn_ext_strtab, and look
in there at ctf_strraw time if it is set. This uses minimal extra
memory (because only strings in the external strtab that we actually use
are stored, and even those come straight out of the atoms table), but
let both variable sorting and name interning when ctf_bufopen is next
called work fine. (This also means that we don't need to filter out
spurious ECTF_STRTAB warnings from ctf_bufopen but can pass them back to
the caller, once we wrap ctf_bufopen so that we have a new internal
variant of ctf_bufopen etc that we can pass the synthetic external
strtab to. That error has been filtered out since the days of Solaris
libctf, which didn't try to handle the problem of getting external
strtabs right at construction time at all.)
v3: add the synthetic strtab and all associated machinery.
v5: fix tabdamage.
include/
* ctf.h (CTF_SET_STID): New.
libctf/
* ctf-impl.h (ctf_str_atom_t) <csa_offset>: New field.
(ctf_file_t) <ctf_syn_ext_strtab>: Likewise.
(ctf_str_add_ref): Name the last arg.
(ctf_str_add_external) New.
(ctf_str_add_strraw_explicit): Likewise.
(ctf_simple_open_internal): Likewise.
(ctf_bufopen_internal): Likewise.
* ctf-string.c (ctf_strraw_explicit): Split from...
(ctf_strraw): ... here, with new support for ctf_syn_ext_strtab.
(ctf_str_add_ref_internal): Return the atom, not the
string.
(ctf_str_add): Adjust accordingly.
(ctf_str_add_ref): Likewise. Move up in the file.
(ctf_str_add_external): New: update the csa_offset.
(ctf_str_count_strtab): Only account for strings with no csa_offset
in the internal strtab length.
(ctf_str_write_strtab): If the csa_offset is set, update the
string's refs without writing the string out, and update the
ctf_syn_ext_strtab. Make OOM handling less ugly.
* ctf-create.c (struct ctf_sort_var_arg_cb): New.
(ctf_update): Handle failure to populate the strtab. Pass in the
new ctf_sort_var arg. Adjust for ctf_syn_ext_strtab addition.
Call ctf_simple_open_internal, not ctf_simple_open.
(ctf_sort_var): Call ctf_strraw_explicit rather than looking up
strings by hand.
* ctf-hash.c (ctf_hash_insert_type): Likewise (but using
ctf_strraw). Adjust to diagnose ECTF_STRTAB nonetheless.
* ctf-open.c (init_types): No longer filter out ECTF_STRTAB.
(ctf_file_close): Destroy the ctf_syn_ext_strtab.
(ctf_simple_open): Rename to, and reimplement as a wrapper around...
(ctf_simple_open_internal): ... this new function, which calls
ctf_bufopen_internal.
(ctf_bufopen): Rename to, and reimplement as a wrapper around...
(ctf_bufopen_internal): ... this new function, which sets
ctf_syn_ext_strtab.
Nick Alcock [Sat, 13 Jul 2019 19:00:07 +0000 (20:00 +0100)]
libctf: Add iteration over non-root types
The existing function ctf_type_iter lets you iterate over root-visible
types (types you can look up by name). There is no way to iterate over
non-root-visible types, which is troublesome because both the linker
and dumper want to do that.
So add a new function that can do it: the callback it takes accepts
an extra parameter which indicates whether the type is root-visible
or not.
include/
* ctf-api.h (ctf_type_all_f): New.
(ctf_type_iter_all): New.
libctf/
* ctf_types.c (ctf_type_iter_all): New.
Nick Alcock [Sat, 13 Jul 2019 18:48:56 +0000 (19:48 +0100)]
binutils: objdump does not take --ctf-symbols or --ctf-strings options
libctf figures out what to load itself, with no overriding currently
possible, so remove the documentation of these nonexistent options.
Nick Alcock [Sat, 13 Jul 2019 18:47:11 +0000 (19:47 +0100)]
binutils: readelf: when dumping CTF, load strtab and symtab automatically
We were only loading them when explicitly requested, which leads to
strings that point off into empty space (into the non-loaded "external"
ELF string table). Avoid this unfortunate consequence by loading the
strtab and symtab by default, unless a blank name is given.
binutils/
* readelf.c (dump_ctf_symtab_name): Give default value.
(dump_ctf_strtab_name): Likewise.
(dump_section_as_ctf): Allow for the null string.
Nick Alcock [Thu, 11 Jul 2019 15:21:26 +0000 (16:21 +0100)]
libctf: add the object index and function index sections
No code handles these yet, but our latest GCC patches are generating
them, so we have to be ready for them or erroneously conclude that we
have file corruption.
(This simultaneously fixes a longstanding bug, concealed because nothing
was generating anything in the object or function info sections, where
the end of the section was being tested against the wrong thing: it
would have walked over the entire contents of the variable section and
treated them as part of the function info section. This had to change
now anyway because the new sections have landed in between.)
include/
* ctf.h: Add object index and function index sections. Describe
them. Improve the description of the variable section and clarify
the constraints on backward-pointing type nodes.
(ctf_header): Add cth_objtidxoff, cth_funcidxoff.
libctf/
* ctf-open.c (init_symtab): Check for overflow against the right
section.
(upgrade_header): Set cth_objtidxoff, cth_funcidxoff to zero-length.
(upgrade_types_v1): Note that these sections are not checked.
(flip_header): Endian-swap the header fields.
(flip_ctf): Endian-swap the sections.
(flip_objts): Update comment.
(ctf_bufopen): Check header offsets and alignment for validity.
Nick Alcock [Thu, 11 Jul 2019 15:26:54 +0000 (16:26 +0100)]
libctf, bfd: fix ctf_bfdopen_ctfsect opening symbol and string sections
The code in ctf_bfdopen_ctfsect (which is the ultimate place where you
end up if you use ctf_open to open a CTF file and pull in the ELF string
and symbol tables) was written before it was possible to actually test
it, since the linker was not written. Now it is, it turns out that the
previous code was completely nonfunctional: it assumed that you could
load the symbol table via bfd_section_from_elf_index (...,elf_onesymtab())
and the string table via bfd_section_from_elf_index on the sh_link.
Unfortunately BFD loads neither of these sections in the conventional
fashion it uses for most others: the symbol table is immediately
converted into internal form (which is useless for our purposes, since
we also have to work in the absence of BFD for readelf, etc) and the
string table is loaded specially via bfd_elf_get_str_section which is
private to bfd/elf.c.
So make this function public, export it in elf-bfd.h, and use it from
libctf, which does something similar to what bfd_elf_sym_name and
bfd_elf_string_from_elf_section do. Similarly, load the symbol table
manually using bfd_elf_get_elf_syms and throw away the internal form
it generates for us (we never use it).
BFD allocates the strtab for us via bfd_alloc, so we can leave BFD to
deallocate it: we allocate the symbol table ourselves before calling
bfd_elf_get_elf_syms, so we still have to free it.
Also change the rules around what you are allowed to provide: It is
useful to provide a string section but no symbol table, because CTF
sections can legitimately have no function info or data object sections
while relying on the ELF strtab for some of their strings. So allow
that combination.
v4: adjust to upstream changes. ctf_bfdopen_ctfsect's first parameter
is potentially unused again (if BFD is not in use for this link
due to not supporting an ELF target).
v5: fix tabdamage.
bfd/
* elf-bfd.h (bfd_elf_get_str_section): Add.
* elf.c (bfd_elf_get_str_section): No longer static.
libctf/
* ctf-open-bfd.c: Add <assert.h>.
(ctf_bfdopen_ctfsect): Open string and symbol tables using
techniques borrowed from bfd_elf_sym_name.
(ctf_new_archive_internal): Improve comment.
* ctf-archive.c (ctf_arc_close): Do not free the ctfi_strsect.
* ctf-open.c (ctf_bufopen): Allow opening with a string section but
no symbol section, but not vice versa.
Nick Alcock [Mon, 8 Jul 2019 12:59:15 +0000 (13:59 +0100)]
libctf, binutils: dump the CTF header
The CTF header has before now been thrown away too soon to be dumped
using the ctf_dump() machinery used by objdump and readelf: instead, a
kludge involving debugging-priority dumps of the header offsets on every
open was used.
Replace this with proper first-class dumping machinery just like
everything else in the CTF file, and have objdump and readelf use it.
(The dumper already had an enum value in ctf_sect_names_t for this
purpose, waiting to be used.)
v5: fix tabdamage.
libctf/
* ctf-impl.h (ctf_file_t): New field ctf_openflags.
* ctf-open.c (ctf_bufopen): Set it. No longer dump header offsets.
* ctf-dump.c (dump_header): New function, dump the CTF header.
(ctf_dump): Call it.
(ctf_dump_header_strfield): New function.
(ctf_dump_header_sectfield): Likewise.
binutils/
* objdump.c (dump_ctf_archive_member): Dump the CTF header.
* readelf.c (dump_section_as_ctf): Likewise.
Nick Alcock [Sat, 6 Jul 2019 16:36:21 +0000 (17:36 +0100)]
libctf: allow the header to change between versions
libctf supports dynamic upgrading of the type table as file format
versions change, but before now has not supported changes to the CTF
header. Doing this is complicated by the baroque storage method used:
the CTF header is kept prepended to the rest of the CTF data, just as
when read from the file, and written out from there, and is
endian-flipped in place.
This makes accessing it needlessly hard and makes it almost impossible
to make the header larger if we add fields. The general storage
machinery around the malloced ctf pointer (the 'ctf_base') is also
overcomplicated: the pointer is sometimes malloced locally and sometimes
assigned from a parameter, so freeing it requires checking to see if
that parameter was used, needlessly coupling ctf_bufopen and
ctf_file_close together.
So split the header out into a new ctf_file_t.ctf_header, which is
written out explicitly: squeeze it out of the CTF buffer whenever we
reallocate it, and use ctf_file_t.ctf_buf to skip past the header when
we do not need to reallocate (when no upgrading or endian-flipping is
required). We now track whether the CTF base can be freed explicitly
via a new ctf_dynbase pointer which is non-NULL only when freeing is
possible.
With all this done, we can upgrade the header on the fly and add new
fields as desired, via a new upgrade_header function in ctf-open.
As with other forms of upgrading, libctf upgrades older headers
automatically to the latest supported version at open time.
For a first use of this field, we add a new string field cth_cuname, and
a corresponding setter/getter pair ctf_cuname_set and ctf_cuname: this
is used by debuggers to determine whether a CTF section's types relate
to a single compilation unit, or to all compilation units in the
program. (Types with ambiguous definitions in different CUs have only
one of these types placed in the top-level shared .ctf container: the
rest are placed in much smaller per-CU containers, which have the shared
container as their parent. Since CTF must be useful in the absence of
DWARF, we store the names of the relevant CUs ourselves, so the debugger
can look them up.)
v5: fix tabdamage.
include/
* ctf-api.h (ctf_cuname): New function.
(ctf_cuname_set): Likewise.
* ctf.h: Improve comment around upgrading, no longer
implying that v2 is the target of upgrades (it is v3 now).
(ctf_header_v2_t): New, old-format header for backward
compatibility.
(ctf_header_t): Add cth_cuname: this is the first of several
header changes in format v3.
libctf/
* ctf-impl.h (ctf_file_t): New fields ctf_header, ctf_dynbase,
ctf_cuname, ctf_dyncuname: ctf_base and ctf_buf are no longer const.
* ctf-open.c (ctf_set_base): Preserve the gap between ctf_buf and
ctf_base: do not assume that it is always sizeof (ctf_header_t).
Print out ctf_cuname: only print out ctf_parname if set.
(ctf_free_base): Removed, ctf_base is no longer freed: free
ctf_dynbase instead.
(ctf_set_version): Fix spacing.
(upgrade_header): New, in-place header upgrading.
(upgrade_types): Rename to...
(upgrade_types_v1): ... this. Free ctf_dynbase, not ctf_base. No
longer track old and new headers separately. No longer allow for
header sizes explicitly: squeeze the headers out on upgrade (they
are preserved in fp->ctf_header). Set ctf_dynbase, ctf_base and
ctf_buf explicitly. Use ctf_free, not ctf_free_base.
(upgrade_types): New, also handle ctf_parmax updating.
(flip_header): Flip ctf_cuname.
(flip_types): Flip BUF explicitly rather than deriving BUF from
BASE.
(ctf_bufopen): Store the header in fp->ctf_header. Correct minimum
required alignment of objtoff and funcoff. No longer store it in
the ctf_buf unless that buf is derived unmodified from the input.
Set ctf_dynbase where ctf_base is dynamically allocated. Drop locals
that duplicate fields in ctf_file: move allocation of ctf_file
further up instead. Call upgrade_header as needed. Move
version-specific ctf_parmax initialization into upgrade_types. More
concise error handling.
(ctf_file_close): No longer test for null pointers before freeing.
Free ctf_dyncuname, ctf_dynbase, and ctf_header. Do not call
ctf_free_base.
(ctf_cuname): New.
(ctf_cuname_set): New.
* ctf-create.c (ctf_update): Populate ctf_cuname.
(ctf_gzwrite): Write out the header explicitly. Remove obsolescent
comment.
(ctf_write): Likewise.
(ctf_compress_write): Get the header from ctf_header, not ctf_base.
Fix the compression length: fp->ctf_size never counted the CTF
header. Simplify the compress call accordingly.
Nick Alcock [Tue, 16 Jul 2019 09:42:37 +0000 (10:42 +0100)]
libctf, include: ChangeLog format fixes
Double-spaces before email addresses were consistently missing.
Hans-Peter Nilsson [Thu, 11 Jul 2019 04:11:09 +0000 (00:11 -0400)]
libctf: make it compile for old glibc
With a glibc before 2.9 (such as 2.8), there's <endian.h> but no
htole64 or le64toh, so you get, compiling binutils for any target:
libtool: link: gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes \
-Wshadow -Werror -I/x/binutils/../zlib -g -O2 -o objdump \
objdump.o dwarf.o prdbg.o rddbg.o debug.o stabs.o rdcoff.o \
bucomm.o version.o filemode.o elfcomm.o ../opcodes/.libs/libopcodes.a \
../libctf/libctf.a ../bfd/.libs/libbfd.a -L/x/obj/b/zlib -lz ../libiberty/libiberty.a -ldl
../libctf/libctf.a(ctf-archive.o): In function `ctf_archive_raw_iter_internal':
/x/src/libctf/ctf-archive.c:543: undefined reference to `le64toh'
/x/src/libctf/ctf-archive.c:550: undefined reference to `le64toh'
/x/src/libctf/ctf-archive.c:551: undefined reference to `le64toh'
/x/src/libctf/ctf-archive.c:551: undefined reference to `le64toh'
/x/src/libctf/ctf-archive.c:554: undefined reference to `le64toh'
../libctf/libctf.a(ctf-archive.o):/x/src/libctf/ctf-archive.c:545: more undefined references to `le64toh' follow
(etc)
Also, I see no bswap_identity_64 *anywhere* except in libctf/swap.h
(including current glibc) and I don't think calling an "identity"-
function is better than just plain "#define foo(x) (x)" anyway.
(Where does the idea of a bytestap.h bswap_identity_64 come from?)
Speaking of that, I should mention that I instrumented the condition
to observe that the WORDS_BIGENDIAN case passes too for a presumed
big-endian target and glibc-2.8: there is a bswap_64 present for that
version. Curiously, no test-case regressed with that instrumentation.
For the record, constructing binary blobs using text source to run
tests on, can be done by linking to --oformat binary (with most ELF
targets), but I guess that's seen as unnecessary roundabout perhaps
checking in binary files in the test-suite would be ok these days.
[...]
[nca: trimmed commit log slightly, updated changelog]
v5: fix tabdamage.
libctf/
* ctf-endian.h: Don't assume htole64 and le64toh are always
present if HAVE_ENDIAN_H; also check if htole64 is defined.
[!WORDS_BIGENDIAN] (htole64, le64toh): Define as identity,
not bswap_identity_64.
Andrew Burgess [Tue, 10 Sep 2019 14:24:28 +0000 (15:24 +0100)]
gdb: Don't ignore all SIGSTOP when the signal handler is set to pass
It was observed that in a multi-threaded application on GNU/Linux,
that if the user has set the SIGSTOP to be pass (using GDB's handle
command) then the inferior would hang upon hitting a breakpoint.
What happens is that when a thread hits the breakpoint GDB tries to
stop all of the other threads by sending them a SIGSTOP and setting
the stop_requested flag in the target_ops structure - this can be seen
in infrun.c:stop_all_threads.
GDB then waits for all of the other threads to stop.
When the SIGSTOP event arrives we eventually end up in
linux-nat.c:linux_nat_filter_event, which has the job of deciding if
the event we're looking at (the SIGSTOP arriving in this case) is
something that should be reported back to the core of GDB.
One of the final actions of this function is to check if we stopped
due to a signal, and if we did, and the signal has been set to 'pass'
by the user then we ignore the event and resume the thread.
This code already has some conditions in place that mean the event is
reported to GDB even if the signal is in the set of signals to be
passed to the inferior.
In this commit I extend this condition such that:
If the signal is a SIGSTOP, and the thread's stop_requested flag is
set (indicating we're waiting for the thread to stop with a SIGSTOP)
then we should report this SIGSTOP to GDB and not pass it to the
inferior.
With this change in place the test now passes. Regression tested on
x86-64 GNU/Linux with no regressions.
gdb/ChangeLog:
* linux-nat.c (linux_nat_filter_event): Don't ignore SIGSTOP if we
have just sent the thread a SIGSTOP and are waiting for it to
arrive.
gdb/testsuite/ChangeLog:
* gdb.threads/stop-with-handle.c: New file.
* gdb.threads/stop-with-handle.exp: New file.
Tom de Vries [Thu, 3 Oct 2019 14:22:09 +0000 (16:22 +0200)]
[gdb/testsuite] Fix list-missing-source.exp with gcc 4.8
With gcc 4.8.1, we see this FAIL:
...
(gdb) PASS: gdb.base/list-missing-source.exp: list
info source^M
Current source file is outputs/gdb.base/list-missing-source/main.c^M
Source language is c.^M
Producer is GNU C 4.8.5 -mtune=generic -march=x86-64 -g -fno-stack-protector.^M
Compiled with DWARF 2 debugging format.^M
Does not include preprocessor macro info.^M
(gdb) FAIL: gdb.base/list-missing-source.exp: info source
...
The problem is that a "Compilation directory is <dir>" line is expected, but
this is missing due to the fact the the compilation unit for main.c doesn't
contain a DW_AT_comp_dir in the DW_TAG_compile_unit DIE.
Fix this by allowing the "Compilation directory" line to be missing.
Tested on x86_64-linux.
gdb/testsuite/ChangeLog:
2019-10-03 Tom de Vries <tdevries@suse.de>
PR testsuite/25059
* gdb.base/list-missing-source.exp: Allowing the "Compilation
directory" line to be missing.