Commit Graph

105670 Commits

Author SHA1 Message Date
Holger Berger
07b1c3dbd9 Fix call to system fallocate to handle errno correctly.
2021-03-19  Holger Berger  <holger.berger@googlemail.com>

gold/
	PR gold/26541
	* output.cc (gold_fallocate): Use errno when calling system fallocate.
2021-03-19 16:18:53 -07:00
Cary Coutant
cc1849716f Fix typo in previous patch: should use struct mallinfo2.
PR gold/26585
	* main.cc (main): Fix typo in previous patch.
2021-03-19 15:29:49 -07:00
Cary Coutant
9331846e44 Regenerate config.in, missing from previous commit.
PR gold/26585
	* config.in: Regenerate from previous commit.
2021-03-19 15:23:49 -07:00
Duncan Simpson
4ee6049505 Fix gold to use mallinfo2 if available instead of deprecated mallinfo.
gold/
	PR gold/26585
	* configure.ac: Add check for mallinfo2.
	* configure: Regenerate.
	* main.cc (main): Use mallinfo2 if available.
2021-03-19 14:22:08 -07:00
Cary Coutant
5cde809b7b Add DWARF 5 support in gold.
elfcpp/
	PR gold/27246
	* dwarf.h (enum DW_LNCT): Add line number table content type codes.
	(enum DW_LINE_OPS): Reformat.
	(enum DW_LINE_EXTENDED_OPS): Reformat.
	(enum DW_CHILDREN): Reformat.
	(enum DW_RLE): Add range list entry types.
	(enum DW_SECT): Update values for DWARF 5.

gold/
	PR gold/27246
	* dwarf_reader.cc (Dwarf_abbrev_table::do_get_abbrev): Handle
	DW_FORM_implicit_const.
	(Dwarf_ranges_table::read_ranges_table): Add version parameter;
	Adjust all callers.  Look for .debug_rnglists section if DWARF 5.
	(Dwarf_ranges_table::read_range_list_v5): New method.
	(Dwarf_die::read_attributes): Handle new DWARF 5 DW_FORM codes.
	(Dwarf_die::skip_attributes): Likewise.
	(Dwarf_info_reader::do_parse): Support DWARF 5 unit header format.
	(Dwarf_info_reader::read_3bytes_from_pointer): New method.
	(Sized_dwarf_line_info::Sized_dwarf_line_info): Initialize
	str_buffer_, str_buffer_start, reloc_map_, line_number_map_.
	Look for .debug_line_str section.
	(Sized_dwarf_line_info::read_header_prolog): Support DWARF 5 prolog.
	(Sized_dwarf_line_info::read_header_tables): Rename to...
	(Sized_dwarf_line_info::read_header_tables_v2): ... this.
	(Sized_dwarf_line_info::read_header_tables_v5): New method.
	(Sized_dwarf_line_info::process_one_opcode): Insert missing "this->".
	Change advance_line to signed int64_t.
	(Sized_dwarf_line_info::read_lines): Add endptr parameter; adjust
	callers.  Insert missing "this->".
	(Sized_dwarf_line_info::read_line_mappings): Support DWARF 5.
	(Sized_dwarf_line_info::do_addr2line): Add debug code.
	* dwarf_reader.h (Dwarf_abbrev_table::Attribute): Add implicit_const
	field. Adjust constructor.
	(Dwarf_abbrev_table::add_sttribute): Add implicit_const parameter.
	(Dwarf_ranges_table::read_ranges_table): Add version parameter.
	(Dwarf_ranges_table::read_range_list_v5): New method.
	(Dwarf_die): Remove unused attr_off field.
	(Dwarf_info_reader::Dwarf_info_reader): Initialize unit_type_ field.
	(Dwarf_info_reader::is_type_unit): New method.
	(Dwarf_info_reader::read_3bytes_from_pointer): New method.
	(Dwarf_info_reader::read_range_list): Call read_range_list_v5 for
	DWARF 5 range lists.
	(Dwarf_info_reader::is_type_unit_): Remove.
	(Dwarf_info_reader::unit_type_): New field.
	(Sized_dwarf_line_info::~Sized_dwarf_line_info): Delete
	str_buffer_start_.
	(Sized_dwarf_line_info::read_header_tables): Rename to...
	(Sized_dwarf_line_info::read_header_tables_v2): ... this.
	(Sized_dwarf_line_info::read_header_tables_v5): New method.
	(Sized_dwarf_line_info::read_lines): Add endptr parameter.
	(Sized_dwarf_line_info::Dwarf_line_infoHeader): Add address_size field.
	(Sized_dwarf_line_info::str_buffer_): New field.
	(Sized_dwarf_line_info::str_buffer_end_): New field.
	(Sized_dwarf_line_info::str_buffer_start_): New field.
	(Sized_dwarf_line_info::end_of_header_length_): New field.
	(Sized_dwarf_line_info::end_of_unit_): New field.
2021-03-19 13:55:35 -07:00
Kevin Buettner
e0d6d27406 Fix potential hang during gdbserver testing
We're currently seeing testing of native-extended-gdbserver hang while
testing the x86_64 architecture on both Fedora 34 and Fedora Rawhide.
The test responsible for the hang is gdb.threads/fork-plus-threads.exp.

While there is clearly a problem/bug with this test on F34 and
Rawhide, it's also the case that testing should not hang.  This commit
prevents the hang by waiting with the "-nowait" flag in
close_gdbserver.

The -nowait flag is also used in the kill_wait_spawned_process proc in
gdb/testsuite/lib/gdb.exp, so there is precedent for doing this.

There are also 15 other uses of "wait -i" scattered throughout the
test suite.  While it's tempting to change these to also use the
-nowait flag, I think it might be safer to defer doing so until we
actually see a problem.

I've tested this patch on Fedora 32, 33, 34, and Rawhide.  Results are
comparable on Fedora 32 and 33.  On Fedora 34 and Rawhide, with this
commit in place, testing completes when the target_board is
native-extended-gdbserver.  On those OSes, when not using this commit,
testing usually hangs due to a problem with
gdb.threads/fork-plus-threads.exp.  I've also tested on all of the
mentioned OSes with target_board=native-gdbserver; for that testing,
I achieved comparable results over a number of runs.  (Unfortunately
results are rarely identical due to racy tests.)

gdb/testsuite/ChangeLog:

	* lib/gdbserver-support.exp (gdbserver_exit): Use the
	"-nowait" flag when waiting for gdbserver to exit.
2021-03-19 13:36:33 -07:00
Pedro Alves
219f56b484 Fix any_thread_of_inferior
Running gdb-term.exp against gdbserver with "maint set target-non-stop
on", runs into this:

  [infrun] fetch_inferior_event: exit
  [infrun] fetch_inferior_event: enter
  /home/pedro/gdb/binutils-gdb/src/gdb/thread.c:72: internal-error: thread_info* inferior_thread(): Assertion `current_thread_ != nullptr' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.

  This is a bug, please report it.  For instructions, see:
  <https://www.gnu.org/software/gdb/bugs/>.

  FAIL: gdb.base/gdb-sigterm.exp: expect eof #2 (GDB internal error)
  Resyncing due to internal error.
  ERROR: : spawn id exp9 not open
      while executing
  "expect {
  -i exp9 -timeout 10
	      -re "Quit this debugging session\\? \\(y or n\\) $" {
		  send_gdb "n\n" answer
		  incr count
	      }
	      -re "Create ..."
      ("uplevel" body line 1)
      invoked from within
  "uplevel $body" NONE : spawn id exp9 not open
  ERROR: Could not resync from internal error (timeout)
  gdb.base/gdb-sigterm.exp: expect eof #2: stepped 0 times
  UNRESOLVED: gdb.base/gdb-sigterm.exp: 50 SIGTERM passes

The assertion fails here:

  ...
  #5  0x000055af4b4a7164 in internal_error (file=0x55af4b5e5de8 "/home/pedro/gdb/binutils-gdb/src/gdb/thread.c", line=72, fmt=0x55af4b5e5ce9 "%s: Assertion `%s' failed.") at /home/pedro/gdb/binutils-gdb/src/gdbsupport/errors.cc:55
  #6  0x000055af4b25fc43 in inferior_thread () at /home/pedro/gdb/binutils-gdb/src/gdb/thread.c:72
  #7  0x000055af4b26177e in any_thread_of_inferior (inf=0x55af4cf874f0) at /home/pedro/gdb/binutils-gdb/src/gdb/thread.c:638
  #8  0x000055af4b26eec8 in kill_or_detach (inf=0x55af4cf874f0, from_tty=0) at /home/pedro/gdb/binutils-gdb/src/gdb/top.c:1665
  #9  0x000055af4b26f37f in quit_force (exit_arg=0x0, from_tty=0) at /home/pedro/gdb/binutils-gdb/src/gdb/top.c:1767
  #10 0x000055af4b2f72a7 in quit () at /home/pedro/gdb/binutils-gdb/src/gdb/utils.c:633
  #11 0x000055af4b2f730b in maybe_quit () at /home/pedro/gdb/binutils-gdb/src/gdb/utils.c:657
  #12 0x000055af4b1adb74 in ser_base_wait_for (scb=0x55af4d02e460, timeout=0) at /home/pedro/gdb/binutils-gdb/src/gdb/ser-base.c:236
  #13 0x000055af4b1adf0f in do_ser_base_readchar (scb=0x55af4d02e460, timeout=0) at /home/pedro/gdb/binutils-gdb/src/gdb/ser-base.c:365
  #14 0x000055af4b1ae06d in generic_readchar (scb=0x55af4d02e460, timeout=0, do_readchar=0x55af4b1adeb1 <do_ser_base_readchar(serial*, int)>) at /home/pedro/gdb/binutils-gdb/src/gdb/ser-base.c:444
  ...

The bug is that any_thread_of_inferior incorrectly assumes that
there's always a selected thread.  This fixes it.

gdb/ChangeLog:

	* thread.c (any_thread_of_inferior): Check if there's a selected
	thread before calling inferior_thread().

Change-Id: Ica4b9ec746121a7a7c22bef09baea72103b3853d
2021-03-19 19:35:20 +00:00
H.J. Lu
7b9f985957 elf: Rename EM_INTEL205 to EM_INTELGT
Rename EM_INTEL205 to EM_INTELGT for Intel Graphics Technology.

binutils/

	* readelf.c (get_machine_name): Add EM_INTELGT.

include/

	* elf/common.h (EM_INTEL205): Renamed to ...
	(EM_INTELGT): This.
2021-03-19 05:58:46 -07:00
Alan Modra
826b97d42d gas/app.c don't throw away spaces before slash
I don't know really why we should lose a space before a '/'.  Possibly
it would make sense if '/' started a comment, but otherwise no.

	* app.c (do_scrub_chars): Don't lose spaces before a slash.
2021-03-19 20:12:30 +10:30
Alan Modra
fba7f7533c pr27590 testcase fixes
PR 27590
	* testsuite/ld-elf/pr27590a.d: Match relocs using label, and
	R_MIPS_NONE.
	* testsuite/ld-elf/pr27590b.d: Likewise.
2021-03-19 20:03:56 +10:30
Sourabh Singh Tomar
a088215ae3 Enable macro test for clang compiler
`clang` uses `-fdebug-macro` switch to enable debug-info
for macros.

gdb/testsuite/ChangeLog:

2021-03-19  Sourabh Singh Tomar  <SourabhSingh.Tomar@amd.com>

* gdb.base/info-macros.exp: Append -fdebug-macro to
  additional_flags for clang.
* gdb.base/macscp.exp: Likewise.
* gdb.base/style.exp: Likewise.
* gdb.linespec/macro-relative.exp: Likewise.
2021-03-19 10:44:56 +05:30
H.J. Lu
3818d4ab06 elf: Handle .gnu.debuglto_.debug_* sections
commit 994b251328
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Jan 17 20:01:16 2021 -0800

    ld/elf: Ignore section symbols when matching linkonce with comdat

ignored section symbols when comparing symbols in 2 sections.  Since all
references to debugging sections are done with section symbols, symbols
in debugging sections are ignored and we fail to match symbols in comdat
debugging sections.  Also .gnu.debuglto_.debug_* sections aren't treated
as debugging sections.

1. Treate .gnu.debuglto_.debug_ section as debugging section unless it
is marked with SHF_EXCLUDE.
2. Revert commit 994b251328 in elf_create_symbuf.
3. Ignore section symbols only when matching non-debugging sections or
linkonce section with comdat section.

bfd/

	PR ld/27590
	* elf.c (_bfd_elf_make_section_from_shdr): Treate
	.gnu.debuglto_.debug_ section as debugging section unless it is
	marked with SHF_EXCLUDE.
	* elflink.c (elf_create_symbuf): Revert commit 994b251328.
	(bfd_elf_match_symbols_in_sections): Ignore section symbols when
	matching non-debugging sections or linkonce section with comdat
	section.

ld/

	PR ld/27590
	* testsuite/ld-elf/pr27590.s: New file.
	* testsuite/ld-elf/pr27590a.d: Likewise.
	* testsuite/ld-elf/pr27590b.d: Likewise.
	* testsuite/ld-i386/i386.exp: Also run ld/27193 test with
	--reduce-memory-overheads.
2021-03-18 20:57:02 -07:00
H.J. Lu
51f6e7a9f4 DWARF: Check version >= 3 for DW_FORM_ref_addr
Check version >= 3, instead of version == 3 || version == 4, for
DW_FORM_ref_addr.

bfd/

	PR ld/27587
	* dwarf2.c (read_attribute_value): Check version >= 3 for
	DW_FORM_ref_addr.

ld/

	PR ld/27587
	* testsuite/ld-x86-64/pr27587.err: New file.
	* testsuite/ld-x86-64/pr27587a.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pr27587b.obj.bz2: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/27587 test.
2021-03-18 18:34:48 -07:00
GDB Administrator
fb099b8a51 Automatic date update in version.in 2021-03-19 00:00:07 +00:00
Christian Groessler
3273f9a19e 2021-03-18 Christian Groessler <chris@groessler.org>
* config/tc-z8k.c (apply_fix): Handle 7-bit relocations correctly.
       Problem found by Tadashi G. Takaoka <tadashi.g.takaoka@gmail.com>.
2021-03-18 21:33:51 +01:00
Tom Tromey
15310fd4eb Reimplement dwarf_unit_type_name
I noticed that dwarf_unit_type_name is nearly identical to
get_DW_UT_name from libiberty; but rather than simply replacing it, it
seemed better to have it work like the other DWARF constant
stringification functions -- return a string showing unrecognized
numeric forms rather than nullptr.  (The previous code did include
numeric values for the recognized constants, but this seems to be not
that useful to me.)

2021-03-18  Tom Tromey  <tromey@adacore.com>

	* dwarf2/stringify.c (dwarf_unit_type_name): New function.  Use
	get_DW_UT_name.
	* dwarf2/stringify.h (dwarf_unit_type_name): Declare.
	* dwarf2/comp-unit.c (dwarf_unit_type_name): Remove.
2021-03-18 12:08:41 -06:00
Andrew Burgess
763b8efdcc gdb/doc: fix the example for get_set_string in Python API docs
The small example for gdb.Parameter.get_set_string does not return a
string.  The documentation is very clear that this method must return
a string, and indeed, inspecting the code in gdb/python/py-param.c
shows that a string return value is required (if an exception is not
thrown).

While inspecting the code in gdb/python/py-param.c I noticed that the
comment for the C++ code that invokes the Python get_set_string method
is wrong, so I updated that too.

gdb/ChangeLog:

	* python/py-param.c (get_set_value): Update header comment.

gdb/doc/ChangeLog:

	* python.texinfo (Parameters In Python): Return empty string in
	small example code.
2021-03-18 16:55:37 +00:00
H.J. Lu
538c15fc2a GCC_CET_HOST_FLAGS: Check if host supports multi-byte NOPs
Check if host supports multi-byte NOPs before enabling CET on host.

config/

	PR binutils/27397
	* cet.m4 (GCC_CET_HOST_FLAGS): Check if host supports multi-byte
	NOPs.

libiberty/

	PR binutils/27397
	* configure: Regenerated.
2021-03-18 08:02:46 -07:00
Nick Clifton
835f2fae11 Fix section dumping so that warnings are not issued for missed sections in separate debuginfo files.
PR 27478
	* readelf.c (dump_section_as_strings): Mention separate filename.
	(dump_section_as_bytes): Likewise.
	(dump_section_as_ctf): Likewise.
	(initialise_dumkps_byname): Only issue a warning for missing
	sections if processing the main file.
	(process_section_contents): Only issue a warning for unsumped
	section numbers in the main file.
	(initialise_dump_sects): New function.  Contains code extracted
	from ...
	(process_object): ... here.  Also call initialise_dump_sects for
	separate files.
2021-03-18 14:01:25 +00:00
Nick Alcock
69a284867c libctf: support encodings for enums
The previous commit started to error-check the lookup of
ctf_type_encoding for the underlying type that is internally done when
carrying out a ctf_type_encoding on a slice.

Unfortunately, enums have no encoding, so this has historically been
returning an error (which is ignored) and then populating the cte_format
with uninitialized data.  Now the error is not ignored, this is
returning an error, which breaks linking of CTF containing bitfields of
enumerated type.

CTF format v3 does not record the actual underlying type of a enum, but
we can mock up something that is not *too* wrong, and that is at any
rate better than uninitialized data.

ld/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/slice.c: Check slices of enums too.
	* testsuite/ld-ctf/slice.d: Results adjusted.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-types.c (ctf_type_encoding): Support, after a fashion, for enums.
	* ctf-dump.c (ctf_dump_format_type): Do not report enums' degenerate
	encoding.
2021-03-18 12:40:41 +00:00
Nick Alcock
e4c78f303d libctf: a couple of small error-handling fixes
Out-of-memory errors initializing the string atoms table were
disregarded (though they would have caused a segfault very shortly
afterwards).  Errors hashing types during deduplication were only
reported if they happened on the output dict, which is almost never the
case (most errors are going to be on the dict we're working over, which
is going to be one of the inputs).  (The error was detected in both
cases, but the errno was extracted from the wrong dict.)

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-dedup.c (ctf_dedup_rhash_type): Report errors on the input
	dict properly.
	* ctf-open.c (ctf_bufopen_internal): Report errors initializing
	the atoms table.
2021-03-18 12:40:41 +00:00
Nick Alcock
d7b1416ef2 libctf: types: unify code dealing with small-vs-large struct members
This completes the job of unifying what was once three separate code
paths full of duplication for every function dealing with querying the
properties of struct and union members.  The dynamic code path was
already removed: this change removes the distinction between small and
large members, by adding a helper that copies out members from the vlen,
expanding small members into large ones as it does so.

This makes it possible to have *more* representations of things like
structure members without needing to change the querying functions at
all.  It also lets us check for buffer overruns more effectively,
verifying that we don't accidentally overrun the end of the vlen in
either the dynamic or static type case.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (ctf_next_t) <ctn_tp>: New.
	<u.ctn_mp>: Remove.
	<u.ctn_lmp>: Remove.
	<u.ctn_vlen>: New.
	* ctf-types.c (ctf_struct_member): New.
	(ctf_member_next): Use it, dropping separate large/small code paths.
	(ctf_type_align): Likewise.
	(ctf_member_info): Likewise.
	(ctf_type_rvisit): Likewise.
2021-03-18 12:40:41 +00:00
Nick Alcock
08c428aff4 libctf: eliminate dtd_u, part 5: structs / unions
Eliminate the dynamic member storage for structs and unions as we have
for other dynamic types.  This is much like the previous enum
elimination, except that structs and unions are the only types for which
a full-sized ctf_type_t might be needed.  Up to now, this decision has
been made in the individual ctf_add_{struct,union}_sized functions and
duplicated in ctf_add_member_offset.  The vlen machinery lets us
simplify this, always allocating a ctf_lmember_t and setting the
dtd_data's ctt_size to CTF_LSIZE_SENT: we figure out whether this is
really justified and (almost always) repack things down into a
ctf_stype_t at ctf_serialize time.

This allows us to eliminate the dynamic member paths from the iterators and
query functions in ctf-types.c in favour of always using the large-structure
vlen stuff for dynamic types (the diff is ugly but that's just because of the
volume of reindentation this calls for).  This also means the large-structure
vlen stuff gets more heavily tested, which is nice because it was an almost
totally unused code path before now (it only kicked in for structures of size
>4GiB, and how often do you see those?)

The only extra complexity here is ctf_add_type.  Back in the days of the
nondeduplicating linker this was called a ridiculous number of times for
countless identical copies of structures: eschewing the repeated lookups of the
dtd in ctf_add_member_offset and adding the members directly saved an amazing
amount of time.  Now the nondeduplicating linker is gone, this is extreme
overoptimization: we can rip out the direct addition and use ctf_member_next and
ctf_add_member_offset, just like ctf_dedup_emit does.

We augment a ctf_add_type test to try adding a self-referential struct, the only
thing the ctf_add_type part of this change really perturbs.

This completes the elimination of dtd_u.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (ctf_dtdef_t) <dtu_members>: Remove.
	<dtd_u>: Likewise.
	(ctf_dmdef_t): Remove.
	(struct ctf_next) <u.ctn_dmd>: Remove.
	* ctf-create.c (INITIAL_VLEN): New, more-or-less arbitrary initial
	vlen size.
	(ctf_add_enum): Use it.
	(ctf_dtd_delete): Do not free the (removed) dmd; remove string
	refs from the vlen on struct deletion.
	(ctf_add_struct_sized): Populate the vlen: do it by hand if
	promoting forwards.  Always populate the full-size
	lsizehi/lsizelo members.
	(ctf_add_union_sized): Likewise.
	(ctf_add_member_offset): Set up the vlen rather than the dmd.
	Expand it as needed, repointing string refs via
	ctf_str_move_pending. Add the member names as pending strings.
	Always populate the full-size lsizehi/lsizelo members.
	(membadd): Remove, folding back into...
	(ctf_add_type_internal): ... here, adding via an ordinary
	ctf_add_struct_sized and _next iteration rather than doing
	everything by hand.
	* ctf-serialize.c (ctf_copy_smembers): Remove this...
	(ctf_copy_lmembers): ... and this...
	(ctf_emit_type_sect): ... folding into here. Figure out if a
	ctf_stype_t is needed here, not in ctf_add_*_sized.
	(ctf_type_sect_size): Figure out the ctf_stype_t stuff the same
	way here.
	* ctf-types.c (ctf_member_next): Remove the dmd path and always
	use the vlen.  Force large-structure usage for dynamic types.
	(ctf_type_align): Likewise.
	(ctf_member_info): Likewise.
	(ctf_type_rvisit): Likewise.
	* testsuite/libctf-regression/type-add-unnamed-struct-ctf.c: Add a
	self-referential type to this test.
	* testsuite/libctf-regression/type-add-unnamed-struct.c: Adjusted
	accordingly.
	* testsuite/libctf-regression/type-add-unnamed-struct.lk: Likewise.
2021-03-18 12:40:40 +00:00
Nick Alcock
77d724a7ec libctf: eliminate dtd_u, part 4: enums
This is the first tricky one, the first complex multi-entry vlen
containing strings.  To handle this in vlen form, we have to handle
pending refs moving around on realloc.

We grow vlen regions using a new ctf_grow_vlen function, and iterate
through the existing enums every time a grow happens, telling the string
machinery the distance between the old and new vlen region and letting
it adjust the pending refs accordingly.  (This avoids traversing all
outstanding refs to find the refs that need adjusting, at the cost of
having to traverse one enum: an obvious major performance win.)

Addition of enums themselves (and also structs/unions later) is a bit
trickier than earlier forms, because the type might be being promoted
from a forward, and forwards have no vlen: so we have to spot that and
create it if needed.

Serialization of enums simplifies down to just telling the string
machinery about the string refs; all the enum type-lookup code loses all
its dynamic member lookup complexity entirely.

A new test is added that iterates over (and gets values of) an enum with
enough members to force a round of vlen growth.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (ctf_dtdef_t) <dtd_vlen_alloc>: New.
	(ctf_str_move_pending): Declare.
	* ctf-string.c (ctf_str_add_ref_internal): Fix error return.
	(ctf_str_move_pending): New.
	* ctf-create.c (ctf_grow_vlen): New.
	(ctf_dtd_delete): Zero out the vlen_alloc after free.  Free the
	vlen later: iterate over it and free enum name refs first.
	(ctf_add_generic): Populate dtd_vlen_alloc from vlen.
	(ctf_add_enum): populate the vlen; do it by hand if promoting
	forwards.
	(ctf_add_enumerator): Set up the vlen rather than the dmd.  Expand
	it as needed, repointing string refs via ctf_str_move_pending. Add
	the enumerand names as pending strings.
	* ctf-serialize.c (ctf_copy_emembers): Remove.
	(ctf_emit_type_sect): Copy the vlen into place and ref the
	strings.
	* ctf-types.c (ctf_enum_next): The dynamic portion now uses
	the same code as the non-dynamic.
	(ctf_enum_name): Likewise.
	(ctf_enum_value): Likewise.
	* testsuite/libctf-lookup/enum-many-ctf.c: New test.
	* testsuite/libctf-lookup/enum-many.lk: New test.
2021-03-18 12:40:40 +00:00
Nick Alcock
986e9e3aa0 libctf: do not corrupt strings across ctf_serialize
The preceding change revealed a new bug: the string table is sorted for
better compression, so repeated serialization with type (or member)
additions in the middle can move strings around.  But every
serialization flushes the set of refs (the memory locations that are
automatically updated with a final string offset when the strtab is
updated), so if we are not to have string offsets go stale, we must do
all ref additions within the serialization code (which walks the
complete set of types and symbols anyway). Unfortunately, we were adding
one ref in another place: the type name in the dynamic type definitions,
which has a ref added to it by ctf_add_generic.

So adding a type, serializing (via, say, one of the ctf_write
functions), adding another type with a name that sorts earlier, and
serializing again will corrupt the name of the first type because it no
longer had a ref pointing to its dtd entry's name when its string offset
was shifted later in the strtab to mae way for the other type.

To ensure that we don't miss strings, we also maintain a set of *pending
refs* that will be added later (during serialization), and remove
entries from that set when the ref is finally added.  We always use
ctf_str_add_pending outside ctf-serialize.c, ensure that ctf_serialize
adds all strtab offsets as refs (even those in the dtds) on every
serialization, and mandate that no refs are live on entry to
ctf_serialize and that all pending refs are gone before strtab
finalization.  (Of necessity ctf_serialize has to traverse all strtab
offsets in the dtds in order to serialize them, so adding them as refs
at the same time is easy.)

(Note that we still can't erase unused atoms when we roll back, though
we can erase unused refs: members and enums are still not removed by
rollbacks and might reference strings added after the snapshot.)

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-hash.c (ctf_dynset_elements): New.
	* ctf-impl.h (ctf_dynset_elements): Declare it.
	(ctf_str_add_pending): Likewise.
	(ctf_dict_t) <ctf_str_pending_ref>: New, set of refs that must be
	added during serialization.
	* ctf-string.c (ctf_str_create_atoms): Initialize it.
	(CTF_STR_ADD_REF): New flag.
	(CTF_STR_MAKE_PROVISIONAL): Likewise.
	(CTF_STR_PENDING_REF): Likewise.
	(ctf_str_add_ref_internal): Take a flags word rather than int
	params.  Populate, and clear out, ctf_str_pending_ref.
	(ctf_str_add): Adjust accordingly.
	(ctf_str_add_external): Likewise.
	(ctf_str_add_pending): New.
	(ctf_str_remove_ref): Also remove the potential ref if it is a
	pending ref.
	* ctf-serialize.c (ctf_serialize): Prohibit addition of strings
	with ctf_str_add_ref before serialization.  Ensure that the
	ctf_str_pending_ref set is empty before strtab finalization.
	(ctf_emit_type_sect): Add a ref to the ctt_name.
	* ctf-create.c (ctf_add_generic): Add the ctt_name as a pending
	ref.
	* testsuite/libctf-writable/reserialize-strtab-corruption.*: New test.
2021-03-18 12:40:40 +00:00
Nick Alcock
2a05d50e90 libctf: don't lose track of all valid types upon serialization
One pattern which is rarely done in libctf but which is meant to work is
this:

ctf_create();
ctf_add_*(); // add stuff
ctf_type_*() // look stuff up
ctf_write_*();
ctf_add_*(); // should still work
ctf_type_*() // so should this
ctf_write_*(); // and this

i.e., writing out a dict should not break it and you should be able to
do everything you could do with it before, including writing it out
again.

Unfortunately this has been broken for a while because the field which
indicates the maximum valid type ID was not preserved across
serialization: so type additions after serialization would overwrite
types (obviously disastrous) and type lookups would just fail.

Fix trivial.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-serialize.c (ctf_serialize): Preserve ctf_typemax across
	serialization.
2021-03-18 12:40:40 +00:00
Nick Alcock
755ba58ebe Add install dependencies for ld -> bfd and libctf -> bfd
This stops problems parallel-installing if a relink of libctf is needed.

Also adds corresponding install-strip dependencies.

ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	PR libctf/27482
	* Makefile.def: Add install-bfd dependencies for install-libctf and
	install-ld, and install-strip-bfd dependencies for
	install-strip-libctf and install-strip-ld; move the install-ld
	dependency on install-libctf to join it.
	* Makefile.in: Regenerated.
2021-03-18 12:40:40 +00:00
Nick Alcock
81982d20fa libctf: eliminate dtd_u, part 3: functions
One more member vanishes from the dtd_u, leaving only the member for
struct/union/enum members.

There's not much to do here, since as of commit afd78bd6f0 we use
the same representation (type sizes, etc) in the dtu_argv as we will
use in the final vlen, with one exception: the vlen has alignment
padding, and the dtu_argv did not.  Simplify things by adding suitable
padding in both cases.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (ctf_dtdef_t) <dtd_u.dtu_argv>: Remove.
	* ctf-create.c (ctf_dtd_delete): No longer free it.
	(ctf_add_function): Use the dtd_vlen, not dtu_argv.  Properly align.
	* ctf-serialize.c (ctf_emit_type_sect): Just copy the dtd_vlen.
	* ctf-types.c (ctf_func_type_info): Just use the vlen.
	(ctf_func_type_args): Likewise.
2021-03-18 12:40:40 +00:00
Nick Alcock
534444b1ee libctf: eliminate dtd_u, part 2: arrays
This is even simpler than ints, floats and slices, with the only extra
complication being the need to manually transfer the array parameter in
the rarely-used function ctf_set_array.  (Arrays are unique in libctf in
that they can be modified post facto, not just created and appended to.
I'm not sure why they got this exemption, but it's easy to maintain.)

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (ctf_dtdef_t) <dtd_u.dtu_arr>: Remove.
	* ctf-create.c (ctf_add_array): Use the dtd_vlen, not dtu_arr.
	(ctf_set_array): Likewise.
	* ctf-serialize.c (ctf_emit_type_sect): Just copy the dtd_vlen.
	* ctf-types.c (ctf_array_info): Just use the vlen.
2021-03-18 12:40:40 +00:00
Nick Alcock
7879dd88ef libctf: eliminate dtd_u, part 1: int/float/slice
This series eliminates a lot of special-case code to handle dynamic
types (types added to writable dicts and not yet serialized).

Historically, when such types have variable-length data in their final
CTF representations, libctf has always worked by adding such types to a
special union (ctf_dtdef_t.dtd_u) in the dynamic type definition
structure, then picking the members out of this structure at
serialization time and packing them into their final form.

This has the advantage that the ctf_add_* code doesn't need to know
anything about the final CTF representation, but the significant
disadvantage that all code that looks up types in any way needs two code
paths, one for dynamic types, one for all others.  Historically libctf
"handled" this by not supporting most type lookups on dynamic types at
all until ctf_update was called to do a complete reserialization of the
entire dict (it didn't emit an error, it just emitted wrong results).
Since commit 676c3ecbad, which eliminated ctf_update in favour of
the internal-only ctf_serialize function, all the type-lookup paths
grew an extra branch to handle dynamic types.

We can eliminate this branch again by dropping the dtd_u stuff and
simply writing out the vlen in (close to) its final form at ctf_add_*
time: type lookup for types using this approach is then identical for
types in writable dicts and types that are in read-only ones, and
serialization is also simplified (we just need to write out the vlen
we already created).

The only complexity lies in type kinds for which multiple
vlen representations are valid depending on properties of the type,
e.g. structures.  But we can start simple, adjusting ints, floats,
and slices to work this way, and leaving everything else as is.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (ctf_dtdef_t) <dtd_u.dtu_enc>: Remove.
	<dtd_u.dtu_slice>: Likewise.
	<dtd_vlen>: New.
	* ctf-create.c (ctf_add_generic): Perhaps allocate it.  All
	callers adjusted.
	(ctf_dtd_delete): Free it.
	(ctf_add_slice): Use the dtd_vlen, not dtu_enc.
	(ctf_add_encoded): Likewise.  Assert that this must be an int or
	float.
	* ctf-serialize.c (ctf_emit_type_sect): Just copy the dtd_vlen.
	* ctf-dedup.c (ctf_dedup_rhash_type): Use the dtd_vlen, not
	dtu_slice.
	* ctf-types.c (ctf_type_reference): Likewise.
	(ctf_type_encoding): Remove most dynamic-type-specific code: just
	get the vlen from the right place.  Report failure to look up the
	underlying type's encoding.
2021-03-18 12:40:36 +00:00
Nick Alcock
eefe721ead libctf: fix GNU style for do {} while
It's formatted like this:

do
  {
    ...
  }
while (...);

Not like this:

do
 {
    ...
  } while (...);

or this:

do {
  ...
} while (...);

We used both in various places in libctf.  Fixing it necessitated some
light reindentation.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-archive.c (ctf_archive_next): GNU style fix for do {} while.
	* ctf-dedup.c (ctf_dedup_rhash_type): Likewise.
	(ctf_dedup_rwalk_one_output_mapping): Likewise.
	* ctf-dump.c (ctf_dump_format_type): Likewise.
	* ctf-lookup.c (ctf_symbol_next): Likewise.
	* swap.h (swap_thing): Likewise.
2021-03-18 12:37:55 +00:00
Nick Alcock
b9a964318a libctf: split up ctf_serialize
ctf_serialize and its various pieces may be split out into a separate
file now, but ctf_serialize is still far too long and disordered, mixing
header initialization, sizing of multiple CTF sections, sorting and
emission of multiple CTF sections, strtab construction and ctf_dict_t
copying into a single ugly organically-grown mess.

Fix the worst of this by migrating all section sizing and emission into
separate functions, two per section (or class of section in the case of
the symtypetabs).  Only the variable section is now sized and emitted
directly in ctf_serialize (because it only takes about three lines to do
so).

The section sizes themselves are still maintained by ctf_serialize so
that it can work out the header offsets, but ctf_symtypetab_sect_sizes
and ctf_emit_symtypetab_sects share a lot of extra state: migrate that
into a shared structure, emit_symtypetab_state_t.

(Test results unchanged.)

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-serialize.c: General reshuffling, and...
	(emit_symtypetab_state_t): New, migrated from
	local variables in ctf_serialize.
	(ctf_serialize): Split out most section sizing and
	emission.
	(ctf_symtypetab_sect_sizes): New (split out).
	(ctf_emit_symtypetab_sects): Likewise.
	(ctf_type_sect_size): Likewise.
	(ctf_emit_type_sect): Likewise.
2021-03-18 12:37:55 +00:00
Nick Alcock
01cbfcba4b libctf: fix comment above ctf_dict_t
It is perfectly possible to have dynamically allocated data owned by a
specific dict: you just have to teach ctf_serialize about it.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (ctf_dict_t): Fix comment.
2021-03-18 12:37:54 +00:00
Nick Alcock
bf4c3185a5 libctf: split serialization and file writeout into its own file
The code to serialize CTF dicts just gets bigger and bigger as the
dictionary's complexity grows: adding symtypetabs almost doubled it on
its own.  It's long past time to split this out into its own source
file, accompanied by the functions that do the actual writeout.

This leaves ctf-create.c populated exclusively by functions related to
actual writable dict creation (ctf_add_*, ctf_create etc), and leaves
both files a much more reasonable size.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-create.c (symtypetab_delete_nonstatic_vars): Move
	into ctf-serialize.c.
	(ctf_symtab_skippable): Likewise.
	(CTF_SYMTYPETAB_EMIT_FUNCTION): Likewise.
	(CTF_SYMTYPETAB_EMIT_PAD): Likewise.
	(CTF_SYMTYPETAB_FORCE_INDEXED): Likewise.
	(symtypetab_density): Likewise.
	(emit_symtypetab): Likewise.
	(emit_symtypetab_index): Likewise.
	(ctf_copy_smembers): Likewise.
	(ctf_copy_lmembers): Likewise.
	(ctf_copy_emembers): Likewise.
	(ctf_sort_var): Likewise.
	(ctf_serialize): Likewise.
	(ctf_gzwrite): Likewise.
	(ctf_compress_write): Likewise.
	(ctf_write_mem): Likewise.
	(ctf_write): Likewise.
	* ctf-serialize.c: New file.
	* Makefile.am (libctf_nobfd_la_SOURCES): Add it.
	* Makefile.in: Regenerate.
2021-03-18 12:37:53 +00:00
Nick Alcock
087945261c libctf: fix some tabdamage and move some code around
ctf-link.c is unnecessarily confusing because ctf_link_lazy_open is
positioned near functions that have nothing to do with opening files.

Move it around, and fix some tabdamage that's crept in lately.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-link.c (ctf_link_lazy_open): Move up in the file, to near
	ctf_link_add_ctf.
	* ctf-lookup.c (ctf_lookup_symbol_idx): Repair tabdamage.
	(ctf_lookup_by_sym_or_name): Likewise.
	* testsuite/libctf-lookup/struct-iteration.c: Likewise.
	* testsuite/libctf-regression/type-add-unnamed-struct.c: Likewise.
2021-03-18 12:37:52 +00:00
GDB Administrator
a1f463bedd Automatic date update in version.in 2021-03-18 00:00:07 +00:00
Simon Marchi
f058c5210f gdb: remove unneeded argument in check_multi_target_resumption
If we reach the modified line, resume_target is necessarily nullptr,
because of the check at the beginning of the function.  So we'll
necessarily iterate on all non-exited inferiors (across all targets),
which is what we want.  So just remove the unnecessary argument.

gdb/ChangeLog:

	* infrun.c (check_multi_target_resumption): Remove argument to
	all_non_exited_inferiors.

Change-Id: If95704915dca19599d5f7f4732bbd6ccd20bf6b4
2021-03-17 13:05:55 +00:00
Simon Marchi
d0c99a23b2 gdb/testsuite: add test for run/attach while program is running
A WIP patch series broke the use case of doing "run" or "attach" while
the program is running, but it wasn't caught by the testsuite, which
means it's not covered.  Add a test for that.

gdb/testsuite/ChangeLog:

	* gdb.base/run-attach-while-running.exp: New.
	* gdb.base/run-attach-while-running.c: New.

Change-Id: I77f098ec0b28dc2d4575ea80e941f6a75273e431
2021-03-17 12:51:06 +00:00
GDB Administrator
95557f1e09 Automatic date update in version.in 2021-03-17 00:00:06 +00:00
Nick Clifton
44266f362b Retain .debug_addr sections loaded in the main file.
PR 27534
	* readelf.c (display_debug_section): Also retain .debug_addr
	sections.
2021-03-16 18:01:58 +00:00
Nick Clifton
d6bfbc3981 Re-enable the dislay of debug sections in separate debuginfo files without the need for -P.
PR 27533
	* readelf.c (process_section_contents): Only dump debug
	information for separate files unless process_links is enabled.
	(process_object): Always call process_section_contents for
	separate info files.
2021-03-16 16:39:46 +00:00
Christian Biesinger
383228bc3f Fix cygwin build error
With "gcc version 10.2.0 (GCC)" on cygwin, I get this build error:
  CXX    windows-nat.o
In file included from ../../gdb/../gdbsupport/common-defs.h:129,
                 from ../../gdb/defs.h:28,
                 from ../../gdb/windows-nat.c:24:
../../gdb/windows-nat.c: In function 'void windows_init_thread_list()':
../../gdb/windows-nat.c:513:17: error: zero-length gnu_printf format string [-Werror=format-zero-length]
  513 |   DEBUG_EVENTS ("");
      |                 ^~
../../gdb/../gdbsupport/common-debug.h:65:43: note: in definition of macro 'debug_prefixed_printf_cond'
   65 |  debug_prefixed_printf (module, __func__, fmt, ##__VA_ARGS__); \
      |                                           ^~~
../../gdb/windows-nat.c:513:3: note: in expansion of macro 'DEBUG_EVENTS'
  513 |   DEBUG_EVENTS ("");
      |   ^~~~~~~~~~~~
cc1plus: all warnings being treated as errors

This was introduced in 4ef367bffd, which removed
the function name from this debug message:
-  DEBUG_EVENTS (("gdb: windows_init_thread_list\n"));
+  DEBUG_EVENTS ("");

DEBUG_EVENTS now always includes the function name, so just add a "called"
message to fix the compile error.

gdb/ChangeLog:

2021-03-16  Christian Biesinger  <cbiesinger@google.com>

	* windows-nat.c (windows_init_thread_list): Add message to
	debug log.
2021-03-16 10:49:37 -05:00
Nick Clifton
ee42883cff Fix potentially undefined behaviour use of strcpcy.
* pe-dll.c (pe_find_cdecl_alias_match): Use memmove to overwrite
	lname string.
2021-03-16 14:02:59 +00:00
Nick Clifton
012d442686 Fix a potential buffer overrun qwhen writing out PE aux entries.
* peXXigen.c (_bfd_XXi_swap_aux_out): Avoid potential buffer
	overrun by using sizeof of the destination x_fname field as the
	limit for a memcpy.

	* coff/internal.h (struct internal_auxent): Fix a couple of typos
	in comment describing the x_fname field.
2021-03-16 12:44:50 +00:00
Andrew Burgess
7807d76a1c gdb/python: fix FrameDecorator regression on Python 2
This commit:

  commit d1cab9876d
  Date:   Tue Sep 15 11:08:56 2020 -0600

      Don't use gdb_py_long_from_ulongest

Introduced a regression when GDB is compiled with Python 2.  The frame
filter API expects the gdb.FrameDecorator.function () method to return
either a string (the name of a function) or an address, which GDB then
uses to lookup a msymbol.

If the address returned from gdb.FrameDecorator.function () comes from
gdb.Frame.pc () then before the above commit we would always expect to
see a PyLong object.

After the above commit we might (on Python 2) get a PyInt object.

The GDB code does not expect to see a PyInt, and only checks for a
PyLong, we then see an error message like:

  RuntimeError: FrameDecorator.function: expecting a String, integer or None.

This commit just adds an additional call to PyInt_Check which handle
the missing case.

I had already written a test case to cover this issue before spotting
that the gdb.python/py-framefilter.exp test also triggers this
failure.  As the new test case is slightly different I have kept it
in.

The new test forces the behaviour of gdb.FrameDecorator.function
returning an address.  The reason the existing test case hits this is
due to the behaviour of the builtin gdb.FrameDecorator base class.  If
the base class behaviour ever changed then the return an address case
would only be tested by the new test case.

gdb/ChangeLog:

	* python/py-framefilter.c (py_print_frame): Use PyInt_Check as
	well as PyLong_Check for Python 2.

gdb/testsuite/ChangeLog:

	* gdb.python/py-framefilter-addr.c: New file.
	* gdb.python/py-framefilter-addr.exp: New file.
	* gdb.python/py-framefilter-addr.py: New file.
2021-03-16 09:31:56 +00:00
Andrew Burgess
f302f9e26e gdb/testsuite: squash duplicate test names in gdb.threads/*.exp
Resolve all of the duplicate test names in the gdb.threads/*.exp set
of tests (that I see).  Nothing very exciting here, mostly either
giving tests explicit testnames, or adding with_test_prefix.

The only interesting one is gdb.threads/execl.exp, I believe the
duplicate test name was caused by an actual duplicate test.  I've
remove the simpler form of the test.  I don't believe we've lost any
test coverage with this change.

gdb/testsuite/ChangeLog:

	* gdb.threads/execl.exp: Remove duplicate 'info threads' test.
	Make use of $gdb_test_name instead of creating a separate $test
	variable.
	* gdb.threads/print-threads.exp: Add a with_test_prefix instead of
	adding a '($name)' at the end of each test.  This also catches the
	one place where '($name)' was missing, and so caused a duplicate
	test name.
	* gdb.threads/queue-signal.exp: Give tests unique names to avoid
	duplicate test names based on the command being tested.
	* gdb.threads/signal-command-multiple-signals-pending.exp:
	Likewise.
	* lib/gdb.exp (gdb_compile_shlib_pthreads): Tweak test name to
	avoid duplicate testnames when a test script uses this proc and
	also gdb_compile_pthreads.
	* lib/prelink-support.exp (build_executable_own_libs): Use
	with_test_prefix to avoid duplicate test names when we call
	build_executable twice.
2021-03-16 09:31:06 +00:00
Kuan-Lin Chen
80d49d6a1b RISC-V : Support bitmanip-0.93 ZBA/ZBB/ZBC instructions
bfd/
	* elfxx-riscv.c (riscv_std_z_ext_strtab): Add zba, zbb and zbc.

gas/
	* config/tc-riscv.c (ext_version_table): Add b, zba, zbb and zbc.
	(riscv_multi_subset_supports): Add INSN_CLASS_ZB*.
	* testsuite/gas/riscv/b-ext-64.s: Bitmanip test case.
	* testsuite/gas/riscv/b-ext-64.d: Likewise.
	* testsuite/gas/riscv/b-ext.s: Likewise.
	* testsuite/gas/riscv/b-ext.d: Likewise.

include/
	* opcode/riscv-opc.h: Support zba, zbb and zbc extensions.
	* opcode/riscv.h (riscv_insn_class): Add INSN_CLASS_ZB*.

opcodes/
	* riscv-opc.c (riscv_opcodes): Add zba, zbb and zbc instructions.
2021-03-16 14:38:19 +08:00
GDB Administrator
4ef6d2f424 Automatic date update in version.in 2021-03-16 00:00:09 +00:00
Tom Tromey
675da9a57e Fix GDB build with GCC 4.8.2
PR build/27579 points out that the expression rewrite series
introduced a build failure with GCC 4.8.2.  The bug is that there's no
std::hash specialization for enum exp_opcode.  This patch fixes the
problem by using gdb::hash_enum.

2021-03-15  Tom Tromey  <tromey@adacore.com>

	PR build/27579:
	* rust-exp.y (maker_map): Use gdb::hash_enum.
	* stap-probe.c (stap_maker_map): Use gdb::hash_enum.
2021-03-15 11:30:51 -06:00
Simon Marchi
4800761a71 gdb: remove spurious colon in create_debug_type_hash_table debug print
This printout in create_debug_type_hash_table has an unexpected colon at
the end, remove it:

    [dwarf-read] create_debug_type_hash_table: Reading .debug_info for /home/simark/build/binutils-gdb/gdb/a.out:

gdb/ChangeLog:

	* dwarf2/read.c (create_debug_type_hash_table): Remove colon at
	end of debug print.

Change-Id: I2d707248249daf4d8b6fa8e7064acdc56c90f2dd
2021-03-15 13:27:03 -04:00