binutils-gdb.git
4 years agogdb: make gdbarch_make_corefile_notes return a unique ptr
Simon Marchi [Wed, 21 Oct 2020 14:43:48 +0000 (10:43 -0400)]
gdb: make gdbarch_make_corefile_notes return a unique ptr

This patch starts by making the gdbarch_make_corefile_notes function
return a gdb::unique_xmalloc_ptr<char> and takes care of the fallouts,
mostly in linux-tdep.c and fbsd-tdep.c.

The difficulty in these files is that they use the BFD API for writing
core files, where you pass in a pointer to a malloc-ed buffer (or NULL
in the beginning), it re-allocs it if needed, and returns you the
possibly updated pointer.  I therefore used this pattern everywhere:

  note_data.reset (elfcore_write_note (obfd, note_data.release (), ...)

This hands over the ownership of note_data to the BFD function for the
duration of the call, and then puts its back in note_data right after
the call.

gdb/ChangeLog:

* gdbarch.sh (make_corefile_notes): Return unique pointer.
* gdbarch.c: Re-generate.
* gdbarch.h: Re-generate.
* gcore.c (write_gcore_file_1): Adjust.
* fbsd-tdep.c (struct fbsd_collect_regset_section_cb_data): Add
constructor.
<note_data>: Change type to unique pointer.
<abort_iteration>: Change type to bool.
(fbsd_collect_regset_section_cb): Adjust to unique pointer.
(fbsd_collect_thread_registers): Return void, adjust.
(struct fbsd_corefile_thread_data): Add construtor.
<note_data>: Change type to unique pointer.
(fbsd_corefile_thread): Adjust.
(fbsd_make_corefile_notes): Return unique pointer, adjust.
* linux-tdep.c (linux_make_mappings_corefile_notes): Change type
to unique pointer, adjust.
(struct linux_collect_regset_section_cb_data): Add constructor.
<note_data>: Change type to unique pointer.
<abort_iteration>: Change type to bool.
(linux_collect_thread_registers): Return void, adjust.
(struct linux_corefile_thread_data): Add constructor.
<note_data>: Change type to unique pointer.
(linux_corefile_thread): Adjust.
(linux_make_corefile_notes): Return unique pointer, adjust.

Change-Id: I1e03476bb47b87c6acb3e12204d193f38cc4e02b

4 years agogdbserver: fix overlap in sprintf argument and buffer
Simon Marchi [Wed, 21 Oct 2020 14:41:12 +0000 (10:41 -0400)]
gdbserver: fix overlap in sprintf argument and buffer

While trying to build on Cygwin (gcc 10.2.0), I got:

      CXX    server.o
    /home/Baube/src/binutils-gdb/gdbserver/server.cc: In function 'void handle_general_set(char*)':
    /home/Baube/src/binutils-gdb/gdbserver/server.cc:832:12: error: 'sprintf' argument 3 overlaps destination object 'own_buf' [-Werror=restrict]
      832 |    sprintf (own_buf, "E.Unknown thread-events mode requested: %s\n",
          |    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      833 |      mode);
          |      ~~~~~
    /home/Baube/src/binutils-gdb/gdbserver/server.cc:553:27: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
      553 | handle_general_set (char *own_buf)
          |                     ~~~~~~^~~~~~~

There is indeed a problem: mode points somewhere into own_buf.  And by
the time mode gets formatted as a %s, whatever it points to has been
overwritten.  I hacked gdbserver to coerce it into that error path, and
this is the resulting message:

    (gdb) p own_buf
    $1 = 0x629000000200 "E.Unknown thread-events mode requested: ad-events mode requested: 00;10:9020fdf7ff7f0000;thread:p49388.49388;core:e;\n"

Fix it by formatting the error string in an std::string first.

gdbserver/ChangeLog:

* server.cc (handle_general_set): Don't use sprintf with
argument overlapping buffer.

Change-Id: I4fdf05c0117f63739413dd67ddae7bd6ee414824

4 years agoFix gdb.mi/mi-fullname-deleted.exp with Clang
Gary Benson [Wed, 21 Oct 2020 08:54:31 +0000 (09:54 +0100)]
Fix gdb.mi/mi-fullname-deleted.exp with Clang

gdb.mi/mi-fullname-deleted.exp attempts to generate an executable
with a doubled slash in the source filename recorded in its debug
info.  This attempt fails when compiling using Clang, causing the
substituted filename test to fail.  This commit fixes this issue.
It also expands the comments in the file, to clarify what the test
is attempting to do, and to document where it doesn't succeed.

gdb/testsuite/ChangeLog:

* gdb.mi/mi-fullname-deleted.exp: Fix substituted
fullname test with Clang.  Also expand comments generally.

4 years agoAutomatic date update in version.in
GDB Administrator [Wed, 21 Oct 2020 00:00:08 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogdb: make gdbarch_displaced_step_hw_singlestep return bool
Simon Marchi [Tue, 20 Oct 2020 21:39:47 +0000 (17:39 -0400)]
gdb: make gdbarch_displaced_step_hw_singlestep return bool

Replace the int-used-as-a-bool with a bool.

gdb/ChangeLog:

* gdbarch.sh (displaced_step_hw_singlestep): Return bool.
* gdbarch.c: Re-generate.
* gdbarch.h: Re-generate.
* aarch64-tdep.c (aarch64_displaced_step_hw_singlestep): Return
bool.
* aarch64-tdep.h (aarch64_displaced_step_hw_singlestep):
Likewise.
* arch-utils.h (default_displaced_step_hw_singlestep): Likewise.
* arch-utils.c (default_displaced_step_hw_singlestep): Likewise.
* rs6000-tdep.c (ppc_displaced_step_hw_singlestep): Likewise.
* s390-tdep.c (s390_displaced_step_hw_singlestep): Likewise.

Change-Id: I76a78366dc5c0afb03f8f4bddf9f4e8d68fe3114

4 years agogdb: make gdbarch predicates return bool
Simon Marchi [Tue, 20 Oct 2020 21:34:30 +0000 (17:34 -0400)]
gdb: make gdbarch predicates return bool

gdbarch predicates (functions suffixed _p to check whether a gdbarch
implements a given method) currently return int.  Make them return bool.
There is no expected behavior change.

gdb/ChangeLog:

* gdbarch.sh: Make generated predicates return bool.
* gdbarch.c: Re-generate.
* gdbarch.h: Re-generate.

Change-Id: Ie7ebc1acae62df83da9085ba69327fca551c5a30

4 years agoRemove varobj_item typedef
Tom Tromey [Tue, 20 Oct 2020 21:28:22 +0000 (15:28 -0600)]
Remove varobj_item typedef

While working on some minor varobj cleanups, I noticed this obvious
one: the varobj_item typedef isn't redundant in C++, and so can be
removed.

gdb/ChangeLog
2020-10-20  Tom Tromey  <tom@tromey.com>

* varobj-iter.h (struct varobj_item): Remove typedef.

4 years agoAdd AMD znver3 processor support
Ganesh Gopalasubramanian [Tue, 20 Oct 2020 18:26:58 +0000 (23:56 +0530)]
Add AMD znver3 processor support

gas/

* config/tc-i386.c (cpu_arch): Add CPU_ZNVER3_FLAGS flags.
(i386_align_code): Add PROCESSOR_ZNVER cases.
* doc/c-i386.texi: Add znver3, snp, invlpgb and tlbsync.
* gas/i386/i386.exp: Add new znver3 test cases.
* gas/i386/arch-14-znver3.d: New.
* gas/i386/arch-14.d: New.
* gas/i386/arch-14.s: New.
* gas/i386/invlpgb.d: New.
* gas/i386/invlpgb64.d: New.
* gas/i386/invlpgb.s: New.
* gas/i386/snp.d: New.
* gas/i386/snp64.d: New.
* gas/i386/snp.s: New.
* gas/i386/tlbsync.d: New.
* gas/i386/tlbsync.s: New.
* gas/i386/x86-64-arch-4-znver3.d: New.
* gas/i386/x86-64-arch-4.d: New.
* gas/i386/x86-64-arch-4.s: New.

opcodes/

* i386-dis.c (rm_table): Add tlbsync, snp, invlpgb.
* i386-gen.c (cpu_flag_init): Add new CPU_INVLPGB_FLAGS,
CPU_TLBSYNC_FLAGS, and CPU_SNP_FLAGS.
Add CPU_ZNVER3_FLAGS.
(cpu_flags): Add CpuINVLPGB, CpuTLBSYNC, CpuSNP.
* i386-opc.h: Add CpuINVLPGB, CpuTLBSYNC, CpuSNP.
* i386-opc.tbl: Add invlpgb, tlbsync, psmash, pvalidate,
rmpupdate, rmpadjust.
* i386-init.h: Re-generated.
* i386-tbl.h: Re-generated.

4 years agogdb: change some int to bool in infrun.c
Simon Marchi [Tue, 20 Oct 2020 20:31:57 +0000 (16:31 -0400)]
gdb: change some int to bool in infrun.c

Change these int-used-as-a-bool to bool.  I searched for "static int" in
that file and changed what I found.

gdb/ChangeLog:

* infrun.c (currently_stepping): Change int to bool
(maybe_software_singlestep): Likewise.
(show_stop_on_solib_events): Likewise.
(stepping_past_nonsteppable_watchpoint): Likewise.
(displaced_step_in_progress_any_inferior): Likewise.
(displaced_step_in_progress_thread): Likewise.
(keep_going_stepped_thread): Likewise.
(thread_still_needs_step_over): Likewise.
(start_step_over): Likewise.
(do_target_resume): Likewise.
(resume_1): Likewise.
(clear_proceed_status): Likewise.
(thread_still_needs_step_over_bp): Likewise.
(proceed): Likewise.
(switch_back_to_stepped_thread): Likewise.
(adjust_pc_after_break): Likewise.
(stepped_in_from): Likewise.
(handle_stop_requested): Likewise.
(handle_syscall_event): Likewise.
(handle_no_resumed): Likewise.
(handle_inferior_event): Likewise.
(finish_step_over): Likewise.
(handle_signal_stop): Likewise.
(process_event_stop_test): Likewise.

Change-Id: I897527c4a3da5e647f9d97f7d4477649985b8b77

4 years agogdb: fix comment of get_displaced_stepping_state
Simon Marchi [Tue, 20 Oct 2020 20:10:42 +0000 (16:10 -0400)]
gdb: fix comment of get_displaced_stepping_state

The comment mentions PID instead of INF, fix that.

gdb/ChangeLog:

* infrun.c (get_displaced_stepping_state): Fix comment.

Change-Id: Id9554807c50792db1fcdb7c14590397d1fa6f8f7

4 years agoFix undefined behavior in gdbserver
Tom Tromey [Tue, 20 Oct 2020 16:28:58 +0000 (10:28 -0600)]
Fix undefined behavior in gdbserver

PR gdb/26742 points out some undefined behavior in gdbserver.  The bug
is that remove_thread does:

  free_one_thread (thread);
  if (current_thread == thread)
    current_thread = NULL;

However, the equality check is undefined, because "thread" has already
been freed.

This patch fixes the bug by moving the check earlier.

Tested on x86-64 Fedora 32.

2020-10-20  Tom Tromey  <tromey@adacore.com>

PR gdb/26742:
* inferiors.cc (remove_thread): Clear current_thread before
freeing the thread.

4 years agoFix help string of alias command
Andreas Schwab [Mon, 19 Oct 2020 18:55:06 +0000 (20:55 +0200)]
Fix help string of alias command

* cli/cli-cmds.c (_initialize_cli_cmds): Fix alias command help.

4 years ago[gdb/testsuite] Remove superfluous marker in pr13961.S
Tom de Vries [Tue, 20 Oct 2020 08:20:25 +0000 (10:20 +0200)]
[gdb/testsuite] Remove superfluous marker in pr13961.S

When looking at readelf output for test-case gdb.dwarf2/pr13961.exp, we have:
...
$ readelf -wi ./outputs/gdb.dwarf2/pr13961/pr13961
   ...
 <0><14c>: Abbrev Number: 0
readelf: Warning: Bogus end-of-siblings marker detected at offset 14c in \
  .debug_info section
...

Fix this by removing the superfluous end-of-siblings marker.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-10-20  Tom de Vries  <tdevries@suse.de>

* gdb.dwarf2/pr13961.S: Remove superfluous end-of-siblings marker.

4 years ago[gdb/testsuite] Use main.c in gdb.dwarf2
Tom de Vries [Tue, 20 Oct 2020 08:20:25 +0000 (10:20 +0200)]
[gdb/testsuite] Use main.c in gdb.dwarf2

Eliminate copies of main.c in gdb.dwarf2.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-10-20  Tom de Vries  <tdevries@suse.de>

* gdb.dwarf2/arr-stride.c: Remove.
* gdb.dwarf2/arr-stride.exp: Use main.c.
* gdb.dwarf2/arr-subrange.c: Remove.
* gdb.dwarf2/arr-subrange.exp: Use main.c.
* gdb.dwarf2/bad-regnum.c: Remove.
* gdb.dwarf2/bad-regnum.exp: Use main.c.
* gdb.dwarf2/corrupt.c: Remove.
* gdb.dwarf2/corrupt.exp: Use main.c.
* gdb.dwarf2/dw2-bad-elf.c: Remove.
* gdb.dwarf2/dw2-bad-elf.exp: Use main.c.
* gdb.dwarf2/dw2-icycle.c: Remove.
* gdb.dwarf2/dw2-icycle.exp: Use main.c.
* gdb.dwarf2/formdata16.c: Remove.
* gdb.dwarf2/formdata16.exp: Use main.c.
* gdb.dwarf2/implptrconst.c: Remove.
* gdb.dwarf2/implptrconst.exp: Use main.c.
* gdb.dwarf2/info-locals-optimized-out.c: Remove.
* gdb.dwarf2/info-locals-optimized-out.exp: Use main.c.
* gdb.dwarf2/opaque-type-lookup.c: Remove.
* gdb.dwarf2/opaque-type-lookup.exp: Use main.c.

4 years ago[gdb/testsuite] Clean up redundant info in gdb.dwarf2
Tom de Vries [Tue, 20 Oct 2020 08:20:24 +0000 (10:20 +0200)]
[gdb/testsuite] Clean up redundant info in gdb.dwarf2

In gdb.dwarf2/ada-valprint-error.exp we find:
...
    untested ${testfile}.exp
...
such that we have:
...
UNTESTED: gdb.dwarf2/ada-valprint-error.exp: ada-valprint-error.exp
...

Fix this and a likewise unsupported message in
gdb.dwarf2/dw2-dir-file-name.exp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-10-20  Tom de Vries  <tdevries@suse.de>

* gdb.dwarf2/ada-valprint-error.exp: Remove redundant mention of .exp
file.
* gdb.dwarf2/dw2-dir-file-name.exp: Same.

4 years ago[gdb/testsuite] Use $gdb_test_file_name in gdb.dwarf2
Tom de Vries [Tue, 20 Oct 2020 08:20:24 +0000 (10:20 +0200)]
[gdb/testsuite] Use $gdb_test_file_name in gdb.dwarf2

In f.i. gdb.dwarf2/dw2-line-number-zero.exp we find:
...
    verbose "Skipping dw2-line-number-zero test."
...

Make the skip messages use the gdb_test_file_name variable, to reduce the
amount of changes that needs to be made when coping a test-case.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-10-20  Tom de Vries  <tdevries@suse.de>

* gdb.dwarf2/dw2-error.exp: Use $gdb_test_file_name.
* gdb.dwarf2/dw2-line-number-zero.exp: Same.
* gdb.dwarf2/dw2-main-no-line-number.exp: Same.
* gdb.dwarf2/dw2-ranges-base.exp: Same.
* gdb.dwarf2/dw2-ranges.exp: Same.
* gdb.dwarf2/dw2-vendor-extended-opcode.exp: Same.
* gdb.dwarf2/var-access.exp: Same.

4 years agoreadelf.c display_lto_symtab offset outside bounds of constant string
Alan Modra [Tue, 20 Oct 2020 04:29:40 +0000 (14:59 +1030)]
readelf.c display_lto_symtab offset outside bounds of constant string

Using gcc-10 or current mainline gcc, binutils configured with
--disable-nls results in:

readelf.c: In function 'display_lto_symtab':
readelf.c:12283:26: error: offset '17' outside bounds of constant string [-Werror=array-bounds]
12283 |   SECTION_NAME (section) + strlen (".gnu.lto_.symtab.")) > 0
      |                          ^

Which is actually a bogus warning in this case because we've already
checked the name string for validity, so SECTION_NAME won't ever be
"<none>", "<no-strings>" or "<corrupt>".  This patch fixes the problem
by making SECTION_NAME simply return the string from the string table.
Other places also shouldn't be trying to match any of the error
strings against a section name, so fix them too.

* readelf.c: Delete whitespace at end of line throughout.
(SECTION_NAME, SECTION_NAME_VALID): New.
(SECTION_NAME_PRINT): Rename from SECTION_NAME.  Formatting.
(printable_section_name, dump_relocations): Use SECTION_NAME_PRINT.
(process_section_headers, process_section_groups): Likewise.
(shdr_to_ctf_sect): Likewise.
(find_section, find_section_in_set): Use SECTION_NAME_VALID.
(ia64_process_unwind, hppa_process_unwind): Likewise.
(display_debug_section, initialise_dumps_byname): Likewise.
(process_lto_symbol_tables): Likewise.  Check trailing period of
lto symbol table names.
(display_lto_symtab): Use sizeof instead of strlen.

4 years agobinutils: Add myself as RISC-V co-maintainer.
Nelson Chu [Tue, 20 Oct 2020 04:34:36 +0000 (12:34 +0800)]
binutils: Add myself as RISC-V co-maintainer.

binutils/
* MAINTAINERS (RISC-V): Add myself as RISC-V co-maintainer.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 20 Oct 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoDon't erase TUI source window when switching focus
Tom Tromey [Mon, 19 Oct 2020 13:45:05 +0000 (07:45 -0600)]
Don't erase TUI source window when switching focus

PR tui/26719 points out that switching the focus can erase the TUI
source window.  This is a regression introduced by the patch to switch
the source window to using a pad.

This patch fixes the bug by arranging to call prefresh whenever the
window is refreshed.

2020-10-19  Tom Tromey  <tromey@adacore.com>

PR tui/26719
* tui/tui-winsource.h (struct tui_source_window_base)
<refresh_window>: Rename from refresh_pad.
* tui/tui-winsource.c (tui_source_window_base::refresh_window):
Rename from refresh_pad.
(tui_source_window_base::show_source_content)
(tui_source_window_base::do_scroll_horizontal): Update.

gdb/testsuite/ChangeLog
2020-10-19  Tom Tromey  <tromey@adacore.com>

PR tui/26719
* gdb.tui/list.exp: Check source window contents after focus
change.

4 years agogdb/thread: fine-tune 'info threads' help text
Tankut Baris Aktemur [Mon, 19 Oct 2020 15:23:26 +0000 (17:23 +0200)]
gdb/thread: fine-tune 'info threads' help text

The help text of 'info threads' is below:

  (gdb) help info threads
  Display currently known threads.
  Usage: info threads [OPTION]... [ID]...

  Options:
    -gid
      Show global thread IDs.If ID is given, it is a space-separated list of IDs of threads to display.
  Otherwise, all threads are displayed.
  (gdb)

I think the "If ID is given ..." info should have come right below
the the usage line.  This patch reorganizes the text so that we get

  (gdb) help info threads
  Display currently known threads.
  Usage: info threads [OPTION]... [ID]...
  If ID is given, it is a space-separated list of IDs of threads to display.
  Otherwise, all threads are displayed.

  Options:
    -gid
      Show global thread IDs.
  (gdb)

gdb/ChangeLog:
2020-10-19  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* thread.c (_initialize_thread): Fine-tune the help text of
'info threads'.

4 years agogdb/frame: remove an unused type alias
Tankut Baris Aktemur [Mon, 19 Oct 2020 15:17:30 +0000 (17:17 +0200)]
gdb/frame: remove an unused type alias

Tested by rebuilding.

gdb/ChangeLog:
2020-10-19  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* frame.c: Remove the unused 'uinteger_option_def' type alias.

4 years agogdb: get jiter objfile from a bound minsym
Mihails Strasuns [Wed, 14 Oct 2020 08:44:36 +0000 (10:44 +0200)]
gdb: get jiter objfile from a bound minsym

This fixes a regression introduced by the following commit:

fe053b9e853 gdb/jit: pass the jiter objfile as an argument to jit_event_handler

In the refactoring `handle_jit_event` function was changed to pass a matching
objfile pointer to the `jit_event_handler` explicitly, rather using internal
storage:

```
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5448,8 +5448,9 @@ handle_jit_event (void)

   frame = get_current_frame ();
   gdbarch = get_frame_arch (frame);
+  objfile *jiter = symbol_objfile (get_frame_function (frame));

-  jit_event_handler (gdbarch);
+  jit_event_handler (gdbarch, jiter);
```

This was needed to add support for multiple jiters.  However it has also
introduced a regression, because `get_frame_function (frame)` here may
return `nullptr`, resulting in a crash.

A more resilient way would be to use an approach mirroring
`jit_breakpoint_re_set` - to find a minimal symbol matching the
breakpoint location and use its object file.  We know that this
breakpoint event comes from a breakpoint set by `jit_breakpoint_re_set`,
thus using the reverse approach should be reliable enough.

gdb/Changelog:
2020-10-14  Mihails Strasuns  <mihails.strasuns@intel.com>

* breakpoint.c (handle_jit_event): Add an argument, change how
`jit_event_handler` is called.

4 years agoReadelf: Add --lto-syms option to display LTO symbol tables.
Nick Clifton [Mon, 19 Oct 2020 14:27:58 +0000 (15:27 +0100)]
Readelf: Add --lto-syms option to display LTO symbol tables.

* readelf.c (do_lto_syms): New local.
(long_option_values): Add OPTION_LTO_SYMS.
(options): Add --lto-syms.
(usage): Mention the new option.
(parse_args): Parse the new option.
(get_lto_kind): New function.
(get_lto_visibility): New function.
(get_lto_sym_type): New function.
(display_lto_symtab): New function - displays the contents of an
LTo symbol table section.
(process_lto_symbol_tables): New functions.  Calls
dipslay_lto_symtab on any LTO symbol table section.
(process_object_file): Call process_lto_symbol_tables.
* doc/binutils.texi: Document the new option.
* NEWS: Mention the new feature.

4 years agoProvide dummy libraries for alpha-vms
Alan Modra [Sun, 18 Oct 2020 22:19:32 +0000 (08:49 +1030)]
Provide dummy libraries for alpha-vms

alpha-dec-vms always loads a number of libraries, -limagelib,
-lstarlet, and -lsys$public_vectors.  When running the ld testsuite
without a full cross-build environment, those libraries are missing
and cause fails.  This patch provides dummies, and tidies default.exp
a little.

* testsuite/config/default.exp: Provide dummy libraries for
alpha-dec-vms.
(compiler_supports): New proc.  Use it for compiler tests.
* testsuite/lib/ld-lib.exp (default_ld_assemble): Don't die if
subdir not set.
(run_ld_link_tests): Pass LDFLAGS to ld.
* testsuite/ld-checks/checks.exp (section_check): Likewise.
* testsuite/ld-scripts/assert.exp: Likewise.
* testsuite/ld-scripts/extern.exp: Likewise.
* testsuite/ld-scripts/log2.exp: Likewise.
* testsuite/ld-scripts/map-address.exp: Likewise.
* testsuite/ld-scripts/script.exp: Likewise.
* testsuite/ld-scripts/sizeof.exp: Likewise.

4 years agoAutomatic date update in version.in
GDB Administrator [Mon, 19 Oct 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoAutomatic date update in version.in
GDB Administrator [Sun, 18 Oct 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoHave partial symbol tables own psymbol vectors
Tom Tromey [Sat, 17 Oct 2020 18:34:53 +0000 (12:34 -0600)]
Have partial symbol tables own psymbol vectors

Currently pointers to all partial symbols are stored in two vectors;
and then indices into these vectors are stored in each partial_symtab.

This patch changes this so that each partial symtab instead has
vectors of symbols.  add_psymbol_to_list can now be changed into a
method on partial_symtab as well.

My main motivation for doing this is that I am looking into calling
sort_pst_symbols in the background.  However, I haven't actually
implemented this yet.  (Also this may make it more feasible to also
sort the static psymbols, though I haven't tried that either.)

Also, though, this lets us remove the "current_global_psymbols"
vector, because now the callers can simply refer directly to the
psymtab that they are modifying (formerly this was implicit).

The main drawback of this patch is that it increases the size of
partial symtab.

gdb/ChangeLog
2020-10-17  Tom Tromey  <tom@tromey.com>

* xcoffread.c (xcoff_end_psymtab): Use partial_symtab::empty.
(scan_xcoff_symtab): Update.
* psymtab.h (class psymtab_storage) <global_psymbols,
static_psymbols, current_global_psymbols,
current_static_psymbols>: Remove.
* psymtab.c (require_partial_symbols, find_pc_sect_psymbol)
(match_partial_symbol, lookup_partial_symbol): Update.
(print_partial_symbols): Change parameters.
(dump_psymtab, recursively_search_psymtabs)
(psym_fill_psymbol_map, psym_find_compunit_symtab_by_address)
(sort_pst_symbols, partial_symtab::partial_symtab): Update.
(concat): Remove.
(end_psymtab_common): Simplify.
(append_psymbol_to_list): Change parameters.
(partial_symtabs::add_psymbol): Rename from add_psymbol_to_list.
(init_psymbol_list): Simplify.
(maintenance_info_psymtabs, maintenance_check_psymtabs): Update.
* psympriv.h (struct partial_symtab) <empty>: New method.
<globals_offset, n_global_syms, statics_offset, n_static_syms>:
Remove.
<global_psymbols, static_psymbols>: New members.
<add_psymbol>: New methods.
(add_psymbol_to_list): Don't declare.
(psymbol_placement): Move earlier.
* mdebugread.c (parse_partial_symbols): Update.
(handle_psymbol_enumerators): Change parameters.
(mdebug_expand_psymtab): Update.
* dwarf2/read.c (process_psymtab_comp_unit_reader)
(add_partial_symbol): Update.
* dwarf2/index-write.c (write_psymbols): Change parameters.
(write_one_signatured_type): Update.
(recursively_count_psymbols): Update.
(recursively_write_psymbols): Update.
(class debug_names) <recursively_write_psymbols>: Update.
<write_psymbols>: Change parameters.
<write_one_signatured_type>: Update.
* dbxread.c (read_dbx_symtab): Update.
(dbx_end_psymtab): Use partial_symtab::empty.
* ctfread.c (struct ctf_context) <pst>: New member.
(create_partial_symtab): Set it.
(ctf_psymtab_type_cb, ctf_psymtab_var_cb): Update.
(scan_partial_symbols): Use the psymtab's context.  Update.

4 years agoMake range types inherit signed-ness from base type
Tom Tromey [Sat, 17 Oct 2020 17:41:59 +0000 (11:41 -0600)]
Make range types inherit signed-ness from base type

I ran across this comment in valprint.c:

      /* FIXME: create_static_range_type does not set the unsigned bit in a
         range type (I think it probably should copy it from the target
         type), so we won't print values which are too large to
         fit in a signed integer correctly.  */

It seems to me that a range type ought to inherit its signed-ness from
the underlying type, so this patch implements this change, and removes
the comment.  (It was also copied into m2-valprint.c.)

I also remove the comment about handling ranges of enums, because I
think that comment is incorrect.

gdb/ChangeLog
2020-10-17  Tom Tromey  <tom@tromey.com>

* valprint.c (generic_value_print): Remove comment.
* m2-valprint.c (m2_value_print_inner): Remove comment.
* gdbtypes.c (create_range_type): Set TYPE_UNSIGNED from base
type.

4 years agogas: Add a -gdwarf-5 debug_line test with .s file
H.J. Lu [Sat, 17 Oct 2020 12:52:13 +0000 (05:52 -0700)]
gas: Add a -gdwarf-5 debug_line test with .s file

PR gas/25878
PR gas/26740
* testsuite/gas/i386/dwarf5-line-4.d: New file.
* testsuite/gas/i386/dwarf5-line-4.s: Likewise.
* testsuite/gas/i386/i386.exp: Run dwarf5-line-4.

4 years agogas: Replace dwarf5-line-2.S with dwarf5-line-3.S
H.J. Lu [Sat, 17 Oct 2020 12:35:23 +0000 (05:35 -0700)]
gas: Replace dwarf5-line-2.S with dwarf5-line-3.S

PR gas/25878
PR gas/26740
* testsuite/gas/i386/dwarf5-line-3.s: Replace dwarf5-line-2.S
with dwarf5-line-3.S.
* testsuite/gas/i386/dwarf5-line-3.d: Updated.

4 years agogas: Always use as_where for preprocessed assembly codes
H.J. Lu [Sat, 17 Oct 2020 11:24:22 +0000 (04:24 -0700)]
gas: Always use as_where for preprocessed assembly codes

Always clear the slot 1 if it was assigned to the input file before the
first .file <NUMBER> directive has been seen.  Always use as_where to
generate the correct debug infor for preprocessed assembly codes.

PR gas/25878
PR gas/26740
* dwarf2dbg.c (allocate_filename_to_slot): Don't reuse the slot 1
here.
(dwarf2_where): Restore as_where.
(dwarf2_directive_filename): Clear the slot 1 if it was assigned
to the input file.
* testsuite/gas/i386/dwarf5-line-2.d: New file.
* testsuite/gas/i386/dwarf5-line-2.s: Likewise.
* testsuite/gas/i386/dwarf5-line-3.d: Likewise.
* testsuite/gas/i386/dwarf5-line-3.s: Likewise.
* testsuite/gas/i386/i386.exp: Run dwarf5-line-2 and
dwarf5-line-3.

4 years agoAutomatic date update in version.in
GDB Administrator [Sat, 17 Oct 2020 00:00:08 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years ago[gdb/symtab] Handle setting line bp without debug line info
Tom de Vries [Fri, 16 Oct 2020 22:10:31 +0000 (00:10 +0200)]
[gdb/symtab] Handle setting line bp without debug line info

When setting a breakpoint on a line in an executable without debug line info,
we run into an abort.

The problem occurs when calling set_default_source_symtab_and_line, which
calls select_source_symtab (0), which is where we try to find the line number
for main:
...
  /* Make the default place to list be the function `main'
     if one exists.  */
  block_symbol bsym = lookup_symbol (main_name (), 0, VAR_DOMAIN, 0);
  if (bsym.symbol != nullptr && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK)
    {
      symtab_and_line sal = find_function_start_sal (bsym.symbol, true);
      loc->set (sal.symtab, std::max (sal.line - (lines_to_list - 1), 1));
      return;
    }
...

However, due to the missing debug line info, find_function_start_sal returns a
sal with sal.symtab == 0:
...
(gdb) p /x sal
$2 = {pspace = 0x1a4a7f0, symtab = 0x0, symbol = 0x1d9e480, section = 0x1d5b398,
  msymbol = 0x0, line = 0x0, pc = 0x4004ab, end = 0x0, explicit_pc = 0x0,
  explicit_line = 0x0, is_stmt = 0x0, prob = 0x0, objfile = 0x0}
...
which eventually causes an segfault in create_sals_line_offset because
self->default_symtab->filename is accessed while self->default_symtab == NULL.

Fix this by handling sal.symtab == NULL in select_source_symtab.

Tested on x86_64-linux.

gdb/ChangeLog:

2020-10-17  Tom de Vries  <tdevries@suse.de>

PR symtab/26317
* source.c (select_source_symtab): Handling sal.symtab == NULL for
symbol main.

gdb/testsuite/ChangeLog:

2020-10-17  Tom de Vries  <tdevries@suse.de>

PR symtab/26317
* gdb.dwarf2/dw2-main-no-line-number.exp: New file.

4 years ago[gdb/testsuite] Remove hardcoded filenames in gdb.dwarf2/*.exp
Tom de Vries [Fri, 16 Oct 2020 22:10:31 +0000 (00:10 +0200)]
[gdb/testsuite] Remove hardcoded filenames in gdb.dwarf2/*.exp

There's a common occurance in dwarf assembly test-cases, where a file test.exp
contains:
...
standard_testfile test.c test-dw.S
...

The "test.c" arg can be abbreviated to ".c".

Make standard_testfile treat args with "-" prefix the same as with "." prefix,
such that we can write:
...
standard_testfile .c -dw.S
...
and apply this in gdb.dwarf2/*.exp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-10-17  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (standard_testfile): Also treat args starting with '-'
as suffix.
* gdb.dwarf2/atomic.c: Rename to ...
* gdb.dwarf2/atomic-type.c: ... this.
* gdb.dwarf2/dw2-ranges2.c: Rename to ...
* gdb.dwarf2/dw2-ranges-2.c: ... this.
* gdb.dwarf2/dw2-ranges3.c: Rename to ...
* gdb.dwarf2/dw2-ranges-3.c: ... this.
* gdb.dwarf2/fission-mix2.c: Rename to ...
* gdb.dwarf2/fission-mix-2.c: ... this.
* gdb.dwarf2/ada-linkage-name.exp: Use more suffix args for
standard_testfile.
* gdb.dwarf2/ada-valprint-error.exp: Same.
* gdb.dwarf2/arr-stride.exp: Same.
* gdb.dwarf2/arr-subrange.exp: Same.
* gdb.dwarf2/atomic-type.exp: Same.
* gdb.dwarf2/bad-regnum.exp: Same.
* gdb.dwarf2/break-inline-psymtab.exp: Same.
* gdb.dwarf2/clang-debug-names-2.exp: Same.
* gdb.dwarf2/clang-debug-names.exp: Same.
* gdb.dwarf2/comp-unit-lang.exp: Same.
* gdb.dwarf2/corrupt.exp: Same.
* gdb.dwarf2/count.exp: Same.
* gdb.dwarf2/cpp-linkage-name.exp: Same.
* gdb.dwarf2/data-loc.exp: Same.
* gdb.dwarf2/dw2-align.exp: Same.
* gdb.dwarf2/dw2-bad-elf.exp: Same.
* gdb.dwarf2/dw2-bad-mips-linkage-name.exp: Same.
* gdb.dwarf2/dw2-bad-unresolved.exp: Same.
* gdb.dwarf2/dw2-case-insensitive.exp: Same.
* gdb.dwarf2/dw2-cp-infcall-ref-static.exp: Same.
* gdb.dwarf2/dw2-ifort-parameter.exp: Same.
* gdb.dwarf2/dw2-inline-many-frames.exp: Same.
* gdb.dwarf2/dw2-inline-param.exp: Same.
* gdb.dwarf2/dw2-inline-small-func.exp: Same.
* gdb.dwarf2/dw2-inline-stepping.exp: Same.
* gdb.dwarf2/dw2-is-stmt-2.exp: Same.
* gdb.dwarf2/dw2-is-stmt.exp: Same.
* gdb.dwarf2/dw2-line-number-zero.exp: Same.
* gdb.dwarf2/dw2-namespaceless-anonymous.exp: Same.
* gdb.dwarf2/dw2-opt-structptr.exp: Same.
* gdb.dwarf2/dw2-param-error.exp: Same.
* gdb.dwarf2/dw2-ranges-base.exp: Same.
* gdb.dwarf2/dw2-ranges.exp: Same.
* gdb.dwarf2/dw2-unusual-field-names.exp: Same.
* gdb.dwarf2/dw2-vendor-extended-opcode.exp: Same.
* gdb.dwarf2/dw4-sig-types.exp: Same.
* gdb.dwarf2/dynarr-ptr.exp: Same.
* gdb.dwarf2/enum-type.exp: Same.
* gdb.dwarf2/fission-mix.exp: Same.
* gdb.dwarf2/formdata16.exp: Same.
* gdb.dwarf2/implptrconst.exp: Same.
* gdb.dwarf2/implptrpiece.exp: Same.
* gdb.dwarf2/info-locals-optimized-out.exp: Same.
* gdb.dwarf2/main-subprogram.exp: Same.
* gdb.dwarf2/method-ptr.exp: Same.
* gdb.dwarf2/missing-sig-type.exp: Same.
* gdb.dwarf2/nonvar-access.exp: Same.
* gdb.dwarf2/opaque-type-lookup.exp: Same.
* gdb.dwarf2/shortpiece.exp: Same.
* gdb.dwarf2/staticvirtual.exp: Same.
* gdb.dwarf2/subrange.exp: Same.
* gdb.dwarf2/symtab-producer.exp: Same.
* gdb.dwarf2/typedef-void-finish.exp: Same.
* gdb.dwarf2/var-access.exp: Same.
* gdb.dwarf2/variant.exp: Same.
* gdb.dwarf2/void-type.exp: Same.
* gdb.dwarf2/dw2-ranges-psym.exp: Same.  Use main.c instead of
dw2-ranges-main.c.
* gdb.dwarf2/dw2-ranges-main.c: Remove.

4 years agold: Allow symbols from PROVIDE to be use in MEMORY regions
Andrew Burgess [Wed, 7 Oct 2020 13:27:56 +0000 (14:27 +0100)]
ld: Allow symbols from PROVIDE to be use in MEMORY regions

I wanted to write a linker script like this:

  PROVIDE(mem_origin = 0x1000);
  PROVIDE(mem_length = 0x1000);

  MEMORY
  {
    REGION : ORIGIN = mem_origin, LENGTH = mem_length
  }

  ....

Then when I link using this script I can optionally supply:

  --defsym=mem_origin=..... --defsym=mem_length=....

to override the defaults.

And though passing `--defsym' does work, if I remove the use of
`--defsym' and just rely on the defaults I get an error:

  ld-new: invalid origin for memory region REGION

Interestingly, if I make the above error non-fatal and dump a linker
map file I see that (a) REGION has origin 0x0, and length 0xffff...,
and (b) the symbol from the PROVIDE is provided.

An examination of ldlang.c:lang_process shows us what the issue is,
the origin and length of all memory regions are set as a result of a
single call to lang_do_memory_regions, this call is done after calling
open_input_bfds.

During the open_input_bfds call provide statements can be converted to
provided statements if we know that the assigned symbol is needed, but
for symbols that are only used in the memory regions we are unaware
that we need these symbols.

What I propose in this patch is to make two calls to
lang_do_memory_regions, in the first call we process the expressions
for the origin and length fields of each region, however, errors,
especially undefined symbols, will be ignored.  The origin and length
values are not updated.  However, by evaluating the expressions any
symbols we need will be added to the symbol table.

Now when we call open_input_bfds, when we process the provide
statements, we will see that the assigned symbol is needed add its new
value to the symbol table.

Finally we reach the original call to lang_do_memory_regions, in
this (now second) call we again process the expressions, and this time
update the origin and length values.  Any errors encountered now are
reported to the user.

ld/ChangeLog:

* ldlang.c (lang_process): Add extra call to
lang_do_memory_regions, and pass parameter.
(lang_do_memory_regions): Add parameter, only define origin and
length when requested.  Reindent.
* testsuite/ld-scripts/provide-10.d: New file.
* testsuite/ld-scripts/provide-10.map: New file.
* testsuite/ld-scripts/provide-11.d: New file.
* testsuite/ld-scripts/provide-11.map: New file.
* testsuite/ld-scripts/provide-12.d: New file.
* testsuite/ld-scripts/provide-12.map: New file.
* testsuite/ld-scripts/provide-9.d: New file.
* testsuite/ld-scripts/provide-9.map: New file.
* testsuite/ld-scripts/provide-9.t: New file.

4 years agold: More documentation for --defsym
Andrew Burgess [Tue, 6 Oct 2020 14:30:15 +0000 (15:30 +0100)]
ld: More documentation for --defsym

The ordering of command line options --defsym and -T is important,
however, the description of --defsym in the manual doesn't mention
this.

This commit adds more text to the description of --defsym to try and
explain this ordering requirement.

ld/ChangeLog:

* ld.texi (Options): Extend the description of --defsym.

4 years agogas: Reuse the input file entry in the file table
H.J. Lu [Fri, 16 Oct 2020 11:03:20 +0000 (04:03 -0700)]
gas: Reuse the input file entry in the file table

Some instructions can be emitted (dwarf2_emit_insn is called) before the
first .file <NUMBER> directive has been seen, which allocates the input
file as the first file entry.  Reuse the input file entry in the file
table.

PR gas/25878
PR gas/26740
* dwarf2dbg.c (file_entry): Remove auto_assigned.
(assign_file_to_slot): Remove the auto_assign argument.
(allocate_filenum): Updated.
(allocate_filename_to_slot): Reuse the input file entry in the
file table.
(dwarf2_where): Replace as_where with as_where_physical.
* testsuite/gas/i386/dwarf5-line-1.d: New file.
* testsuite/gas/i386/dwarf5-line-1.s: Likewise.
* testsuite/gas/i386/i386.exp: Run dwarf5-line-1.

4 years agoAdd a new option to the linker: --error-handling-script=<NAME>. Run the script ...
Nick Clifton [Fri, 16 Oct 2020 10:37:26 +0000 (11:37 +0100)]
Add a new option to the linker: --error-handling-script=<NAME>.  Run the script <NAME> if an undefined symbol or unfound library error is encountered.

PR 26626
* ldmain.c (undefined_symbol): If an error handlign script is
available, call it.
* ldfile.c  (error_handling_script): Declare.
(ldfile_open_file): If a library cannot be found and an error
handling script is available, call it.
* ldmain.h  (error_handling_script): Prototype.
* ldlex.h (OPTION_ERROR_HANDLING_SCRIPT): Define.
* lexsup.c (ld_options): Add --error-handling-script.
(parse_args): Add support for --errror-handling-script.
* ld.texi: Document the new feature.
* configure.ac: Add --error-handling-script option to disable
support for the new feature.
* NEWS: Mention the new feature.
* config.in: Regenerate.
* configure: Regenerate.

4 years ago[gdb/testsuite] Fix function comment for gdb_breakpoint
Tom de Vries [Fri, 16 Oct 2020 10:06:11 +0000 (12:06 +0200)]
[gdb/testsuite] Fix function comment for gdb_breakpoint

Commit 5b7d00507b adds a mention at gdb_breakpoint of a supported argument
"passfail".  There's no corresponding argument handling though.

Remove the mention of the "passfail" argument.

gdb/testsuite/ChangeLog:

2020-10-16  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_breakpoint): Remove mention of "passfail".

4 years ago[gdb/testsuite] Be more verbose about abort in gdb_breakpoint
Tom de Vries [Fri, 16 Oct 2020 09:39:02 +0000 (11:39 +0200)]
[gdb/testsuite] Be more verbose about abort in gdb_breakpoint

I noticed that an abort when setting a breakpoint does not result in more
than:
...
(gdb) break 27^M
FAIL: gdb.a/b.exp: setting breakpoint at 27 (eof)
...

Handle this more verbosely, as is done in gdb_test_multiple, such that we have
instead:
...
(gdb) break 27^M
ERROR: GDB process no longer exists
GDB process exited with wait status 29309 exp9 0 0 CHILDKILLED SIGABRT SIGABRT
UNRESOLVED: gdb.a/b.exp: setting breakpoint at 27 (eof)
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-10-16  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_breakpoint): Handle eof as in gdb_test_multiple.

4 years agoEnhancement for avx-vnni patch
Cui,Lili [Thu, 15 Oct 2020 02:45:08 +0000 (10:45 +0800)]
Enhancement for avx-vnni patch

1. Rename CpuVEX_PREFIX to PseudoVexPrefix and
   move it from cpu_flags to opcode_modifiers.
2. Delete {vex2} invalid test.
3. Use VexW0 and VexVVVV in the AVX-VNNI instructions.

gas/
* config/tc-i386.c: Move Pseudo Prefix check to match_template.
* testsuite/gas/i386/avx-vnni-inval.l: New file.
* testsuite/gas/i386/avx-vnni-inval.s: Likewise.
* testsuite/gas/i386/avx-vnni.d: Delete invalid {vex2} test.
* testsuite/gas/i386/avx-vnni.s: Likewise.
* testsuite/gas/i386/i386.exp: Add AVX VNNI invalid tests.
* testsuite/gas/i386/x86-64-avx-vnni-inval.l: New file.
* testsuite/gas/i386/x86-64-avx-vnni-inval.s: Likewise.
* testsuite/gas/i386/x86-64-avx-vnni.d: Delete invalid {vex2} test.
* testsuite/gas/i386/x86-64-avx-vnni.s: Likewise.

opcodes/
* i386-opc.tbl: Rename CpuVEX_PREFIX to PseudoVexPrefix
and move it from cpu_flags to opcode_modifiers.
Use VexW0 and VexVVVV in the AVX-VNNI instructions.
* i386-gen.c: Likewise.
* i386-opc.h: Likewise.
* i386-opc.h: Likewise.
* i386-init.h: Regenerated.
* i386-tbl.h: Likewise.

4 years agoRISC-V: Fix that IRELATIVE relocs may be inserted to the wrong place.
Nelson Chu [Wed, 7 Oct 2020 03:48:23 +0000 (20:48 -0700)]
RISC-V: Fix that IRELATIVE relocs may be inserted to the wrong place.

For the ifunc symbol, which is referenced by GOT rather than PLT relocs,
we should add the dynamic reloc (usually IRELATIVE) into the .rel.iplt
when generating the static executable.  But if we use riscv_elf_append_rela
to add the dynamic relocs into .rela.iplt, this may cause the overwrite
problem.

The reason is that we don't handle the `reloc_index` of .rela.iplt, but
the riscv_elf_append_rela adds the relocs to the place that are calculated
from the reloc_index (in seqential).  Therefore, we may overwrite the
dynamic relocs when the `reloc_index` of .rela.iplt isn't handled correctly.

One solution is that we can add these dynamic relocs (GOT ifunc) from
the last of .rela.iplt section.  But I'm not sure if it is the best way.

bfd/
* elfnn-riscv.c (riscv_elf_link_hash_table): Add last_iplt_index.
(riscv_elf_size_dynamic_sections): Initialize the last_iplt_index.
(riscv_elf_relocate_section): Use riscv_elf_append_rela.
(riscv_elf_finish_dynamic_symbol): If the use_elf_append_rela is
false, then we should add the dynamic relocs from the last of
the .rela.iplt, and don't use the riscv_elf_append_rela to add.

ld/
* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite.s: New testcase.
* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite-exe.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite-pic.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite-pie.rd: Likewise.
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.

4 years agoRISC-V: Support GNU indirect functions.
Nelson Chu [Wed, 7 Oct 2020 03:48:22 +0000 (20:48 -0700)]
RISC-V: Support GNU indirect functions.

Generally, glibc dynamic linker should have two ways to deal with ifunc
- one is to handle the IRELATIVE relocations for the non-preemtive ifunc
symbols, the other is to handle the R_RISCV_32/64 and R_RISCV_JUMP_SLOT
relocations with the STT_IFUNC preemtive symbols.  No matter which method
is used, both of them should get the resolved ifunc symbols at runtime.
Therefore, linker needs to generate the correct dynamic relocations for
ifunc to make sure the the dynamic linker works well.  For now, there are
thirteen relocations are supported for ifunc in GNU ld,

* R_RISCV_CALL and R_RISCV_CALL_PLT:
The RISC-V compiler won't generate R_RISCV_JAL directly to jump to an
ifunc.  Besides, we disable the relaxations for the relocation referenced
to ifunc, so just handling the R_RISCV_CALL and R_RISCV_CALL_PLT should be
enough.  Linker should generate a .plt entry and a .got.plt entry for it,
and also needs to insert a dynamic IRELATIVE in the .got.plt enrty, or
insert a R_RISCV_JUMP_SLOT when generating shared library.

* R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO12_I/S:
LA/LLA pattern with local fPIC ifunc symbol, or any non-PIC ifunc symbol.
The PC-relative relocation.  The current linker will deal with them in
the same way as R_RISCV_CALL_PLT.

* R_RISCV_GOT_HI20 and R_RISCV_PCREL_LO12_I/S:
LA pattern with global PIC ifunc symbol.  Linker should insert a dynamic
IRELATIVE in the .got entry, or insert a R_RISCV_32/64 when generating
shared library.

* R_RISCV_32 and R_RISCV_64:
Store the ifunc symbol into the data section.  Linker should insert a
dynamic IRELATIVE in the data section, or insert a R_RISCV_32/64 when
generating shared library.

* R_RISCV_HI20 and R_RISCV_LO12_I/S:
The LUI + ADDI/LW/SW patterns.  The absolute access relocation.  The
medlow model without the -fPIC compiler option should generate them.
The ld ifunc testsuites "Build pr23169a" and "Build pr23169d" need the
relocations, they are in the ld/testsuite/ld-ifunc/, and need compiler
support.

However, we also made some optimizations with reference to x86,

* If GOT and PLT relocations refer to the same ifunc symbol when generating
pie, then they can actually share a .got entry without creating two entries
to store the same value and relocation.

* If GOT, PLT and DATA relocations refer to the same ifunc symbol when
generating position dependency executable, then linker will fill the address
of .plt entry into the corresponding .got entry and data section, without
insert any dynamic relocations for the GOT and DATA relocations.

For the ifunc testcases, there are three types of them,

1. ifunc-reloc-*: Only check the single type of relocation refers to
ifunc symbol.
* ifunc-reloc-call: R_RISCV_CALL and R_RISCV_CALL_PLT.
* ifunc-reloc-data: R_RISCV_32 and R_RISCV_64.
* ifunc-reloc-got: R_RISCV_GOT_HI20 and R_RISCV_PCREL_LO_I/S.
* ifunc-reloc-pcrel: R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO_I/S.

2. ifunc-[nonplt|plt]-*: If we don't have PLT relocs, then don't need to
create the PLT and it's .plt entries.
* ifunc-nonplt: Combine R_RISCV_GOT_HI20 and R_RISCV_32/64.
* ifunc-plt: Combine all ifunc relocations.

3. ifunc-seperate-*: If we link the ifunc caller and resolver into the
same module (link the objects), then the results are the same as the
ifunc-reloc-* and ifunc-[noplt|plt]-* testcases.  Consider the cases that
the ifunc callers and resolver are in the different modules, that is, we
compile the ifunc resolver to the shared library first, and then link it
with the ifunc callers.  The output of ifunc callers should be the same as
the normal STT_FUNC cases, and the shared ifunc resolver should define the
symbols as STT_IFUNC.

The R_RISCV_PCREL_HI20 reloc is special.  It should be linked and resolved
locally, so if the ifunc resolver is defined in other modules (other shared
libraries), then the R_RISCV_PCREL_HI20 is unresolvable, and linker should
issue an unresolvable reloc error.

bfd/
* elfnn-riscv.c: Include "objalloc.h" since we need objalloc_alloc.
(riscv_elf_link_hash_table): Add loc_hash_table and loc_hash_memory
for local STT_GNU_IFUNC symbols.
(riscv_elf_got_plt_val): Removed.
(riscv_elf_local_htab_hash, riscv_elf_local_htab_eq): New functions.
Use to compare local hash entries.
(riscv_elf_get_local_sym_hash): New function.  Find a hash entry for
local symbol, and create a new one if needed.
(riscv_elf_link_hash_table_free): New function.  Destroy an riscv
elf linker hash table.
(riscv_elf_link_hash_table_create): Create hash table for local ifunc.
(riscv_elf_check_relocs): Create a fake global symbol to track the
local ifunc symbol.  Add support to check and handle the relocations
reference to ifunc symbols.
(allocate_dynrelocs): Let allocate_ifunc_dynrelocs and
allocate_local_ifunc_dynrelocs to handle the ifunc symbols if they
are defined and referenced in a non-shared object.
(allocate_ifunc_dynrelocs): New function.  Allocate space in .plt,
.got and associated reloc sections for ifunc dynamic relocs.
(allocate_local_ifunc_dynrelocs): Likewise, but for local ifunc
dynamic relocs.
(riscv_elf_relocate_section): Add support to handle the relocation
referenced to ifunc symbols.
(riscv_elf_size_dynamic_sections): Updated.
(riscv_elf_adjust_dynamic_symbol): Updated.
(riscv_elf_finish_dynamic_symbol): Finish up the ifunc handling,
including fill the PLT and GOT entries for ifunc symbols.
(riscv_elf_finish_local_dynamic_symbol): New function.  Called by
riscv_elf_finish_dynamic_symbol to handle the local ifunc symbols.
(_bfd_riscv_relax_section): Don't do the relaxation for ifunc.
* elfxx-riscv.c: Add R_RISCV_IRELATIVE.
* configure.ac: Link elf-ifunc.lo to use the generic ifunc support.
* configure: Regenerated.

include/
* elf/riscv.h: Add R_RISCV_IRELATIVE to 58.

ld/
* emulparams/elf32lriscv-defs.sh: Add IREL_IN_PLT.
* testsuite/ld-ifunc/ifunc.exp: Enable ifunc tests for RISC-V.
* testsuite/ld-riscv-elf/ld-riscv-elf.exp (run_dump_test_ifunc):
New dump test for ifunc.  There are two arguments, 'target` and
`output`.  The `target` is rv32 or rv64, and the `output` is used
to choose which output you want to test (exe, pie or .so).
* testsuite/ld-riscv-elf/ifunc-reloc-call-01.s: New testcase.
* testsuite/ld-riscv-elf/ifunc-reloc-call-01.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-call-01-exe.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-call-01-pic.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-call-01-pie.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-call-02.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-call-02.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-call-02-exe.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-call-02-pic.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-call-02-pie.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-data.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-data.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-data-exe.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-data-pic.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-data-pie.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-got.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-got.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-got-exe.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-got-pic.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-got-pie.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-pcrel.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-pcrel.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-pcrel-exe.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-pcrel-pic.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-reloc-pcrel-pie.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-nonplt.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-nonplt.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-nonplt-exe.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-nonplt-pic.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-nonplt-pie.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-01.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-01.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-01-exe.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-01-pic.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-01-pie.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-02.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-02.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-02-exe.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-02-pic.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-plt-02-pie.rd: Likewise.
* testsuite/ld-riscv-elf/ifunc-seperate-resolver.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-seperate-caller.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-seperate-exe.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-seperate-pic.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-seperate-pie.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-seperate-caller-pcrel.s: Likewise.
* testsuite/ld-riscv-elf/ifunc-seperate-pcrel-pic.d: Likewise.
* testsuite/ld-riscv-elf/ifunc-seperate-pcrel-pie.d: Likewise.

4 years agoelf32-arc.c: Don't cast between function pointer and void pointer
Alan Modra [Thu, 15 Oct 2020 23:45:57 +0000 (10:15 +1030)]
elf32-arc.c: Don't cast between function pointer and void pointer

Casts should be avoided if at all possible, and in particular the C
standard doesn't promise that function pointers can be cast to void*
or vice-versa.  It is only mentioned under J.5 Common extensions,
saying "The following extensions are widely used in many systems, but
are not portable to all implementations."

* elf32-arc.c (replace_func): Correct return type.
(get_replace_function): Use a replace_func function pointer rather
than void*.  Update associated ARC_RELOC_HOWTO define.

4 years agoAutomatic date update in version.in
GDB Administrator [Fri, 16 Oct 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoelf32-cr16.c tidy
Alan Modra [Thu, 15 Oct 2020 22:57:10 +0000 (09:27 +1030)]
elf32-cr16.c tidy

Prompted by two occurrences of -Wmisleading-indentation warnings.

* elf32-cr16.c: Formatting.
(cr16_elf_final_link_relocate): Sign extend rather than clumsy
"add or subtract" of offset value.  Simplify range checks.  Move
common code out of "if" branches.  Don't refetch insn fields
needlessly.

4 years agoR_PPC64_GOT_LO_DS and R_PPC64_GOT_HA sanity check
Alan Modra [Thu, 15 Oct 2020 22:56:32 +0000 (09:26 +1030)]
R_PPC64_GOT_LO_DS and R_PPC64_GOT_HA sanity check

The previous sanity check allowed a ld on the HA reloc and addis
on the LO_DS.

* elf64-ppc.c (ppc64_elf_relocate_section): Tighten sanity check
on R_PPC64_GOT_LO_DS and R_PPC64_GOT_HA instructions.

4 years agoAutomatic date update in version.in
GDB Administrator [Thu, 15 Oct 2020 00:00:09 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogdb/gdbserver: add dependencies for distclean-gnulib
Andrew Burgess [Mon, 12 Oct 2020 15:04:32 +0000 (16:04 +0100)]
gdb/gdbserver: add dependencies for distclean-gnulib

After commit:

  commit 361cb219351d8b7e39e1962fe77f40aa80657b27
  Date:   Tue Oct 6 10:09:06 2020 +0100

      gnulib: Ensure all libraries are used when building gdb/gdbserver

We now get an error when, at the top level of the build tree, we do
'make distclean'.

The reason for this is that the gnulib directory is cleaned before the
gdb directory, cleaning gnulib deletes Makefile.gnulib.inc from the
gnulib build directory, which is currently pulled in by the gdb
Makefile.in using 'include'.

This commit adds a dependency between distclean-gnulib and both
distclean-gdb and distclean-gdbserver.  This means that gdb and
gdbserver will be cleaned before gnulib, as a result the
Makefile.gnulib.inc file should exist when needed.

ChangeLog:

* Makefile.in: Rebuild.
* Makefile.def: Make distclean-gnulib depend on distclean-gdb and
distclean-gdbserver.

4 years agox86: Support Intel AVX VNNI
H.J. Lu [Wed, 14 Oct 2020 12:02:13 +0000 (05:02 -0700)]
x86: Support Intel AVX VNNI

Intel AVX VNNI instructions are marked with CpuVEX_PREFIX.  Without the
pseudo {vex} prefix, mnemonics of Intel VNNI instructions are encoded
with the EVEX prefix.  The pseudo {vex} prefix can be used to encode
mnemonics of Intel VNNI instructions with the VEX prefix.

gas/

* NEWS: Add Intel AVX VNNI.
* config/tc-i386.c (cpu_arch): Add .avx_vnni and noavx_vnni.
(cpu_flags_match): Support CpuVEX_PREFIX.
* doc/c-i386.texi: Document .avx_vnni, noavx_vnni and how to
encode Intel VNNI instructions with VEX prefix.
* testsuite/gas/i386/avx-vnni.d: New file.
* testsuite/gas/i386/avx-vnni.s: Likewise.
* testsuite/gas/i386/x86-64-avx-vnni.d: Likewise.
* testsuite/gas/i386/x86-64-avx-vnni.s: Likewise.
* testsuite/gas/i386/i386.exp: Run AVX VNNI tests.

opcodes/

* i386-dis.c (PREFIX_VEX_0F3850): New.
(PREFIX_VEX_0F3851): Likewise.
(PREFIX_VEX_0F3852): Likewise.
(PREFIX_VEX_0F3853): Likewise.
(VEX_W_0F3850_P_2): Likewise.
(VEX_W_0F3851_P_2): Likewise.
(VEX_W_0F3852_P_2): Likewise.
(VEX_W_0F3853_P_2): Likewise.
(prefix_table): Add PREFIX_VEX_0F3850, PREFIX_VEX_0F3851,
PREFIX_VEX_0F3852 and PREFIX_VEX_0F3853.
(vex_table): Add VEX_W_0F3850_P_2, VEX_W_0F3851_P_2,
VEX_W_0F3852_P_2 and VEX_W_0F3853_P_2.
(putop): Add support for "XV" to print "{vex3}" pseudo prefix.
* i386-gen.c (cpu_flag_init): Clear the CpuAVX_VNNI bit in
CPU_UNKNOWN_FLAGS.  Add CPU_AVX_VNNI_FLAGS and
CPU_ANY_AVX_VNNI_FLAGS.
(cpu_flags): Add CpuAVX_VNNI and CpuVEX_PREFIX.
* i386-opc.h (CpuAVX_VNNI): New.
(CpuVEX_PREFIX): Likewise.
(i386_cpu_flags): Add cpuavx_vnni and cpuvex_prefix.
* i386-opc.tbl: Add Intel AVX VNNI instructions.
* i386-init.h: Regenerated.
* i386-tbl.h: Likewise.

4 years agox86: Add support for Intel HRESET instruction
Lili Cui [Wed, 14 Oct 2020 11:52:11 +0000 (04:52 -0700)]
x86: Add support for Intel HRESET instruction

gas/

* NEWS: Add Intel HRESET.
* config/tc-i386.c (cpu_arch): Add .hreset.
(cpu_noarch): Likewise.
* doc/c-i386.texi: Document .hreset, nohreset.
* testsuite/gas/i386/i386.exp: Run HRESET tests.
* testsuite/gas/i386/hreset.d: New file.
* testsuite/gas/i386/x86-64-hreset.d: Likewise.
* testsuite/gas/i386/hreset.s: Likewise.

opcodes/

* i386-dis.c (PREFIX_0F3A0F): New.
(MOD_0F3A0F_PREFIX_1): Likewise.
(REG_0F3A0F_PREFIX_1_MOD_3): Likewise.
(RM_0F3A0F_P_1_MOD_3_REG_0): Likewise.
(prefix_table): Add PREFIX_0F3A0F.
(mod_table): Add MOD_0F3A0F_PREFIX_1.
(reg_table): Add REG_0F3A0F_PREFIX_1_MOD_3.
(rm_table): Add RM_0F3A0F_P_1_MOD_3_REG_0.
* i386-gen.c (cpu_flag_init): Add HRESET_FLAGS,
CPU_ANY_HRESET_FLAGS.
(cpu_flags): Add CpuHRESET.
(output_i386_opcode): Allow 4 byte base_opcode.
* i386-opc.h (enum): Add CpuHRESET.
(i386_cpu_flags): Add cpuhreset.
* i386-opc.tbl: Add Intel HRESET instruction.
* i386-init.h: Regenerate.
* i386-tbl.h: Likewise.

4 years agox86: Support Intel UINTR
Lili Cui [Wed, 14 Oct 2020 11:31:54 +0000 (04:31 -0700)]
x86: Support Intel UINTR

gas/

* NEWS: Add Intel UINTR.
* config/tc-i386.c (cpu_arch): Add .uintr.
(cpu_noarch): Likewise.
* doc/c-i386.texi: Document .uintr and nouintr.
* testsuite/gas/i386/i386.exp: Run UINTR tests.
* testsuite/gas/i386/x86-64-uintr.d: Likewise.
* testsuite/gas/i386/x86-64-uintr.s: Likewise.

opcodes/

* i386-dis.c (enum): Add
PREFIX_MOD_3_0F01_REG_5_RM_4,
PREFIX_MOD_3_0F01_REG_5_RM_5,
PREFIX_MOD_3_0F01_REG_5_RM_6,
PREFIX_MOD_3_0F01_REG_5_RM_7,
X86_64_0F01_REG_5_MOD_3_RM_4_PREFIX_1,
X86_64_0F01_REG_5_MOD_3_RM_5_PREFIX_1,
X86_64_0F01_REG_5_MOD_3_RM_6_PREFIX_1,
X86_64_0F01_REG_5_MOD_3_RM_7_PREFIX_1,
X86_64_0FC7_REG_6_MOD_3_PREFIX_1.
(prefix_table): New instructions (see prefixes above).
(rm_table): Likewise
* i386-gen.c (cpu_flag_init): Add CPU_UINTR_FLAGS,
CPU_ANY_UINTR_FLAGS.
(cpu_flags): Add CpuUINTR.
* i386-opc.h (enum): Add CpuUINTR.
(i386_cpu_flags): Add cpuuintr.
* i386-opc.tbl: Add UINTR insns.
* i386-init.h: Regenerate.
* i386-tbl.h: Likewise.

4 years agox86: Remove the prefix byte from non-VEX/EVEX base_opcode
H.J. Lu [Wed, 14 Oct 2020 11:17:54 +0000 (04:17 -0700)]
x86: Remove the prefix byte from non-VEX/EVEX base_opcode

Replace the prefix byte in non-VEX/EVEX base_opcode with PREFIX_0X66,
PREFIX_0XF2 or PREFIX_0XF3.

gas/

* config/tc-i386.c (load_insn_p): Check opcodeprefix == 0 for
base_opcode == 0xfc7.
(match_template): Likewise.
(process_suffix): Check opcodeprefix == PREFIX_0XF2 for CRC32.
(check_byte_reg): Likewise.
(output_insn): Don't add the 0xf3 prefix twice for PadLock
instructions.  Don't add prefix from non-VEX/EVEX base_opcode.

opcodes/

* i386-gen.c (process_i386_opcode_modifier): Return 1 for
non-VEX/EVEX/prefix encoding.
(output_i386_opcode): Fail if non-VEX/EVEX/prefix base_opcode
has a prefix byte.
* i386-opc.tbl: Replace the prefix byte in non-VEX/EVEX
base_opcode with PREFIX_0X66, PREFIX_0XF2 or PREFIX_0XF3.
* i386-tbl.h: Regenerated.

4 years ago[gdb/testsuite] Fix gdb.ada/mi_catch_ex{,_hand}.exp FAILs
Tom de Vries [Wed, 14 Oct 2020 11:17:58 +0000 (13:17 +0200)]
[gdb/testsuite] Fix gdb.ada/mi_catch_ex{,_hand}.exp FAILs

The test-case gdb.ada/mi_catch_ex.exp tests two scenarios.

The two scenarios are separated by:
- a mi_run_to_main (before commit b75d55d4d2 "Eliminate mi_run_to_main,
  introduce mi_clean_restart")
- a mi_runto_main (after that commit)

The now removed mi_run_to_main contained a mi_delete_breakpoints, while
mi_runto_main does not, which causes FAILs in the second scenario.

Fix this by adding the missing mi_delete_breakpoints in the test-case, and
likewise in gdb.ada/mi_catch_ex_hand.exp.

Reg-tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-10-14  Tom de Vries  <tdevries@suse.de>

PR testsuite/26732
* gdb.ada/mi_catch_ex.exp: Do mi_delete_breakpoints before running
scenario 2.
* gdb.ada/mi_catch_ex_hand.exp: Same.

4 years ago[gdb] Fix segfault in solib_contains_address_p
Tom de Vries [Wed, 14 Oct 2020 10:24:42 +0000 (12:24 +0200)]
[gdb] Fix segfault in solib_contains_address_p

Starting commit bb2a67773c "Use a std::vector in target_section_table" we run
into:
...
ERROR: GDB process no longer exists
GDB process exited with wait status 22239 exp12 0 0 CHILDKILLED SIGABRT
UNRESOLVED: gdb.base/exec-invalid-sysroot.exp: continue to exec catchpoint
...
which reproduces as:
...
Thread 1 "gdb" received signal SIGSEGV, Segmentation fault.
solib_contains_address_p (address=4196111, solib=0x1dd9970)
    at /home/vries/gdb_versions/devel/src/gdb/solib.c:1120
1120      for (target_section &p : solib->sections->sections)
(gdb) p solib->sections->sections
Cannot access memory at address 0x0
...

Fix this by handling solib->sections == nullptr in solib_contains_address_p.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-10-14  Tom de Vries  <tdevries@suse.de>

PR gdb/26733
* solib.c (solib_contains_address_p): Handle
'solib->sections == nullptr'.

4 years agox86: Rename VexOpcode to OpcodePrefix
H.J. Lu [Wed, 14 Oct 2020 02:28:58 +0000 (19:28 -0700)]
x86: Rename VexOpcode to OpcodePrefix

Rename VexOpcode to OpcodePrefix so that OpcodePrefix can be used for
regular encoding prefix.

gas/

* config/tc-i386.c (build_vex_prefix): Replace vexopcode with
opcodeprefix.
(build_evex_prefix): Likewise.
(is_any_vex_encoding): Don't check vexopcode.
(output_insn): Handle opcodeprefix.

opcodes/

* i386-gen.c (opcode_modifiers): Replace VexOpcode with
OpcodePrefix.
* i386-opc.h (VexOpcode): Renamed to ...
(OpcodePrefix): This.
(PREFIX_NONE): New.
(PREFIX_0X66): Likewise.
(PREFIX_0XF2): Likewise.
(PREFIX_0XF3): Likewise.
* i386-opc.tbl (Prefix_0X66): New.
(Prefix_0XF2): Likewise.
(Prefix_0XF3): Likewise.
Replace VexOpcode= with OpcodePrefix=.  Use Prefix_0X66 on xorpd.
Use Prefix_0XF3 on cvtdq2pd.  Use Prefix_0XF2 on cvtpd2dq.
* i386-tbl.h: Regenerated.

4 years agoAutomatic date update in version.in
GDB Administrator [Wed, 14 Oct 2020 00:00:10 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoEliminate mi_run_to_main, introduce mi_clean_restart
Pedro Alves [Sun, 11 Oct 2020 20:58:31 +0000 (21:58 +0100)]
Eliminate mi_run_to_main, introduce mi_clean_restart

Since we now have mi_runto_main which is like runto_main, eliminate
mi_run_to_main, in favor of a new MI clean_restart counterpart --
mi_clean_restart -- and mi_runto_main.

This makes MI testcases look a bit more like CLI testcases.

gdb/testsuite/ChangeLog:

* lib/mi-support.exp (mi_clean_restart): New.
(mi_run_to_main): Delete.
All callers adjust to use mi_clean_restart / mi_runto_main.

Change-Id: I34920bab4fea1f23fb752928c2969c1f6ad714b6

4 years agogdb/testsuite/: Use "-qualified" in explicit "break main", etc.
Pedro Alves [Thu, 3 Sep 2020 14:38:12 +0000 (15:38 +0100)]
gdb/testsuite/: Use "-qualified" in explicit "break main", etc.

Similar to the previous patch, but this time add "-q" to tests that do
"break main", "list main", etc. explicitly.

gdb/testsuite/ChangeLog:

* config/monitor.exp: Use "list -q".
* gdb.arch/gdb1558.exp: Use "break -q".
* gdb.arch/i386-permbkpt.exp: Use "break -q".
* gdb.arch/i386-prologue-skip-cf-protection.exp: Use "break -q".
* gdb.base/break.exp: Use "break -q", "list -q" and "tbreak -q".
* gdb.base/commands.exp: Use "break -q".
* gdb.base/condbreak.exp: Use "break -q".
* gdb.base/ctf-ptype.exp: Use "list -q".
* gdb.base/define.exp: Use "break -q".
* gdb.base/del.exp: Use "break -q".
* gdb.base/fullname.exp: Use "break -q".
* gdb.base/hbreak-in-shr-unsupported.exp: Use "hbreak -q".
* gdb.base/hbreak-unmapped.exp: Use "hbreak -q".
* gdb.base/hbreak2.exp: Use "hbreak -q" and "list -q".
* gdb.base/hw-sw-break-same-address.exp: Use "break -q" and
"hbreak -q".
* gdb.base/included.exp: Use "list -q".
* gdb.base/label.exp: Use "break -q".
* gdb.base/lineinc.exp: Use "break -q".
* gdb.base/list.exp: Use "list -q".
* gdb.base/macscp.exp: Use "list -q".
* gdb.base/pending.exp: Use "break -q".
* gdb.base/prologue-include.exp: Use "break -q".
* gdb.base/ptype.exp: Use "list -q".
* gdb.base/sepdebug.exp: Use "break -q", "list -q" and "tbreak -q".
* gdb.base/server-del-break.exp: Use "break -q".
* gdb.base/style.exp: Use "break -q".
* gdb.base/symbol-without-target_section.exp: Use "list -q".
* gdb.base/watchpoint-reuse-slot.exp: Use "hbreak -q".
* gdb.cp/exception.exp: Use "tbreak -q".
* gdb.dwarf2/dw2-error.exp: Use "break -q".
* gdb.dwarf2/fission-mix.exp: Use "break -q".
* gdb.dwarf2/fission-reread.exp: Use "break -q".
* gdb.dwarf2/pr13961.exp: Use "break -q".
* gdb.linespec/explicit.exp: Use "list -q".
* gdb.linespec/linespec.exp: Use "break -q".
* gdb.mi/mi-simplerun.exp: Use "--qualified".
* gdb.python/py-mi-objfile-gdb.py: Use "list -q".
* gdb.server/bkpt-other-inferior.exp: Use "break -q".
* gdb.server/connect-without-multi-process.exp: Use "break -q".
* gdb.trace/change-loc.exp: Use "break -q".
* gdb.trace/pending.exp: Use "break -q".
* gdb.tui/basic.exp: Use "list -q".
* gdb.tui/list-before.exp: Use "list -q".
* gdb.tui/list.exp: Use "list -q".
* lib/gdb.exp (gdb_has_argv0): Use "break -q".

Change-Id: Iab9408e90ed71cbb111cd737d2d81b5ba8adb108

4 years agogdb/testsuite/: Use -qualified in runto_main / mi_runto_main
Pedro Alves [Wed, 2 Sep 2020 22:20:45 +0000 (23:20 +0100)]
gdb/testsuite/: Use -qualified in runto_main / mi_runto_main

In some runtimes, there may be a "main" function in some class or
namespace.  The breakpoint created by runto_main may therefore have
unexpected locations on some other functions than the actual main.
These breakpoint locations can unexpectedly get hit during tests and
lead to failures.

I saw this while playing with AMD's ROCm toolchain -- I wrote a board
file to run the testsuite against device kernels.  There, the runtime
calls a "main" function before the device kernel code is reached:

 Thread 4 "bit_extract" hit Breakpoint 1, 0x00007ffeea140960 in lld::elf::LinkerDriver::main(llvm::ArrayRef<char const*>) () from /opt/rocm/lib/libamd_comgr.so.1
 (gdb) bt
 #0  0x00007ffeea140960 in lld::elf::LinkerDriver::main(llvm::ArrayRef<char const*>) () from /opt/rocm/lib/libamd_comgr.so.1
 #1  0x00007ffeea2257a5 in lld::elf::link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&, llvm::raw_ostream&) () from /opt/rocm/lib/libamd_comgr.so.1
 #2  0x00007ffeea1bc374 in COMGR::linkWithLLD(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&) () from /opt/rocm/lib/libamd_comgr.so.1
 #3  0x00007ffeea1bfb09 in COMGR::InProcessDriver::execute(llvm::ArrayRef<char const*>) () from /opt/rocm/lib/libamd_comgr.so.1
 #4  0x00007ffeea1c4da9 in COMGR::AMDGPUCompiler::linkToExecutable() () from /opt/rocm/lib/libamd_comgr.so.1
 #5  0x00007ffeea1fde20 in dispatchCompilerAction(amd_comgr_action_kind_s, COMGR::DataAction*, COMGR::DataSet*, COMGR::DataSet*, llvm::raw_ostream&) () from /opt/rocm/lib/libamd_comgr.so.1
 #6  0x00007ffeea203a87 in amd_comgr_do_action () from /opt/rocm/lib/libamd_comgr.so.1
 ...

To avoid that, pass "qualified" to runto, in runto_main, so that
gdb_breakpoint ends up creating a breakpoint with -qualified.  This
avoids creating breakpoints locations for other unrelated "main"
functions.

Note: I first tried making runto itself use "-qualified", but that
caused regressions in the gdb.ada/ tests, which use runto without
specifying the whole fully-qualified function name (i.e., without the
package).  So I end up restricting the -qualified to
runto_main/mi_runto_main.

The gdb.base/ui-redirect.exp change is necessary because that testcase
is looking at what "save breakpoint" generates.

gdb/testsuite/ChangeLog:

* gdb.base/ui-redirect.exp: Expect "break -qualified main" in
saved breakpoints file.
* gdb.guile/scm-breakpoint.exp: Expect "-qualified main" when
inspecting breakpoint list.
* lib/gdb.exp (runto_main): Add "qualified" to options.
* lib/mi-support.exp (mi_runto_helper): Add 'qualified' parameter,
and handle it.
(mi_runto_main): Pass 1 as qualified argument.

Change-Id: I51468359ab0a518f05f7c0394c97f7e33b45fe69

4 years agoIntroduce mi_runto_main
Pedro Alves [Wed, 2 Sep 2020 22:06:19 +0000 (23:06 +0100)]
Introduce mi_runto_main

This adds an mi_runto_main routine, very much like the runto_main CLI
counterpart.

Note there's already a mi_run_to_main (extra underscore in "run_to"),
but unlike its intro comment says, that does more than the CLI's
runto_main -- it also starts GDB.  I would like to eliminate that
other one by introducing a mi_clean_restart function instead.  That is
done later in the series.

gdb/testsuite/ChangeLog:

* lib/mi-support.exp (mi_runto_main): New proc.
(mi_run_to_main): Use it.
* gdb.mi/mi-catch-cpp-exceptions.exp: Likewise.
* gdb.mi/mi-var-cmd.exp: Likewise.
* gdb.mi/mi-var-invalidate.exp: Likewise.
* mi-var-list-children-invalid-grandchild.exp: Likewise.
* gdb.mi/mi2-amd64-entry-value.exp: Likewise.
* gdb.mi/new-ui-mi-sync.exp: Likewise.
* gdb.mi/user-selected-context-sync.exp: Likewise.
* gdb.opt/inline-cmds.exp: Likewise.
* gdb.python/py-framefilter-mi.exp: Likewise.
* gdb.python/py-mi.exp: Likewise.

Change-Id: I2e49ca7b0b61cea57c1202e5dfa32417e6a4403d

4 years ago'runto main' -> 'runto_main' throughout
Pedro Alves [Wed, 2 Sep 2020 21:57:54 +0000 (22:57 +0100)]
'runto main' -> 'runto_main' throughout

This commit does 's/runto main/runto_main/g' throughout.

gdb/testsuite/ChangeLog:

* gdb.ada/fun_in_declare.exp: Use "runto_main" instead of
"runto main".
* gdb.ada/small_reg_param.exp: Likewise.
* gdb.arch/powerpc-d128-regs.exp: Likewise.
* gdb.base/annota1.exp: Likewise.
* gdb.base/anon.exp: Likewise.
* gdb.base/breakpoint-in-ro-region.exp: Likewise.
* gdb.base/dprintf-non-stop.exp: Likewise.
* gdb.base/dprintf.exp: Likewise.
* gdb.base/gdb11530.exp: Likewise.
* gdb.base/gdb11531.exp: Likewise.
* gdb.base/gnu_vector.exp: Likewise.
* gdb.base/interrupt-noterm.exp: Likewise.
* gdb.base/memattr.exp: Likewise.
* gdb.base/step-over-syscall.exp: Likewise.
* gdb.base/watch-cond-infcall.exp: Likewise.
* gdb.base/watch-read.exp: Likewise.
* gdb.base/watch-vfork.exp: Likewise.
* gdb.base/watch_thread_num.exp: Likewise.
* gdb.base/watchpoint-stops-at-right-insn.exp: Likewise.
* gdb.guile/scm-frame-inline.exp: Likewise.
* gdb.linespec/explicit.exp: Likewise.
* gdb.opt/inline-break.exp: Likewise.
* gdb.python/py-frame-inline.exp: Likewise.
* gdb.reverse/break-precsave.exp: Likewise.
* gdb.reverse/break-reverse.exp: Likewise.
* gdb.reverse/consecutive-precsave.exp: Likewise.
* gdb.reverse/consecutive-reverse.exp: Likewise.
* gdb.reverse/finish-precsave.exp: Likewise.
* gdb.reverse/finish-reverse.exp: Likewise.
* gdb.reverse/fstatat-reverse.exp: Likewise.
* gdb.reverse/getresuid-reverse.exp: Likewise.
* gdb.reverse/i386-precsave.exp: Likewise.
* gdb.reverse/i386-reverse.exp: Likewise.
* gdb.reverse/i386-sse-reverse.exp: Likewise.
* gdb.reverse/i387-env-reverse.exp: Likewise.
* gdb.reverse/i387-stack-reverse.exp: Likewise.
* gdb.reverse/insn-reverse.exp: Likewise.
* gdb.reverse/machinestate-precsave.exp: Likewise.
* gdb.reverse/machinestate.exp: Likewise.
* gdb.reverse/pipe-reverse.exp: Likewise.
* gdb.reverse/readv-reverse.exp: Likewise.
* gdb.reverse/recvmsg-reverse.exp: Likewise.
* gdb.reverse/rerun-prec.exp: Likewise.
* gdb.reverse/s390-mvcle.exp: Likewise.
* gdb.reverse/solib-precsave.exp: Likewise.
* gdb.reverse/solib-reverse.exp: Likewise.
* gdb.reverse/step-precsave.exp: Likewise.
* gdb.reverse/step-reverse.exp: Likewise.
* gdb.reverse/time-reverse.exp: Likewise.
* gdb.reverse/until-precsave.exp: Likewise.
* gdb.reverse/until-reverse.exp: Likewise.
* gdb.reverse/waitpid-reverse.exp: Likewise.
* gdb.reverse/watch-precsave.exp: Likewise.
* gdb.reverse/watch-reverse.exp: Likewise.
* gdb.threads/kill.exp: Likewise.
* gdb.threads/tid-reuse.exp: Likewise.

Change-Id: I70f457253836019880b4d7fb981936afa56724c2

4 years agogdb: don't pass TARGET_WNOHANG to targets that can't async (PR 26642)
Simon Marchi [Tue, 13 Oct 2020 16:01:19 +0000 (12:01 -0400)]
gdb: don't pass TARGET_WNOHANG to targets that can't async (PR 26642)

Debugging with "maintenance set target-async off" on Linux has been
broken since 5b6d1e4fa4f ("Multi-target support").

The issue is easy to reproduce:

    $ ./gdb -q --data-directory=data-directory -nx ./test
    Reading symbols from ./test...
    (gdb) maintenance set target-async off
    (gdb) start
    Temporary breakpoint 1 at 0x1151: file test.c, line 5.
    Starting program: /home/simark/build/binutils-gdb/gdb/test

... and it hangs there.

The difference between pre-5b6d1e4fa4f and 5b6d1e4fa4f is that
fetch_inferior_event now calls target_wait with TARGET_WNOHANG for
non-async-capable targets, whereas it didn't before.

For non-async-capable targets, this is how it's expected to work when
resuming execution:

1. we call resume
2. the infrun async handler is marked in prepare_to_wait, to immediately
   wake up the event loop when we get back to it
3. fetch_inferior_event calls the target's wait method without
   TARGET_WNOHANG, effectively blocking until the target has something
   to report

However, since we call the target's wait method with TARGET_WNOHANG,
this happens:

1. we call resume
2. the infrun async handler is marked in prepare_to_wait, to immediately
   wake up the event loop when we get back to it
3. fetch_inferior_event calls the target's wait method with
   TARGET_WNOHANG, the target has nothing to report yet
4. we go back to blocking on the event loop
5. SIGCHLD finally arrives, but the event loop is not woken up, because
   we are not in async mode.  Normally, we should have been stuck in
   waitpid the SIGCHLD would have unblocked us.

We end up in this situation because these two necessary conditions are
met:

1. GDB uses the TARGET_WNOHANG option with a target that can't do async.
   I don't think this makes sense.  I mean, it's technically possible,
   the doc for TARGET_WNOHANG is:

  /* Return immediately if there's no event already queued.  If this
     options is not requested, target_wait blocks waiting for an
     event.  */
  TARGET_WNOHANG = 1,

   ... which isn't in itself necessarily incompatible with synchronous
   targets.  It could be possible for a target to support non-blocking
   polls, while not having a way to asynchronously wake up the event
   loop, which is also necessary to support async.  But as of today,
   we don't expect GDB and sync targets to work this way.

2. The linux-nat target, even in the mode where it emulates a
   synchronous target (with "maintenance set target-async off") respects
   TARGET_WNOHANG.  Other non-async targets, such as windows_nat_target,
   simply don't check / support TARGET_WNOHANG, so their wait method is
   always blocking.

Fix the first issue by avoiding using TARGET_WNOHANG on non-async
targets, in do_target_wait_1.  Add an assert in target_wait to verify it
doesn't happen.

The new test gdb.base/maint-target-async-off.exp is a simple test that
just tries running to main and then to the end of the program, with
"maintenance set target-async off".

gdb/ChangeLog:

PR gdb/26642
* infrun.c (do_target_wait_1): Clear TARGET_WNOHANG if the
target can't do async.
* target.c (target_wait): Assert that we don't pass
TARGET_WNOHANG to a target that can't async.

gdb/testsuite/ChangeLog:

PR gdb/26642
* gdb.base/maint-target-async-off.c: New test.
* gdb.base/maint-target-async-off.exp: New test.

Change-Id: I69ad3a14598863d21338a8c4e78700a58ce7ad86

4 years agoRemove unneeded netbsd_add_process()
Kamil Rytarowski [Fri, 2 Oct 2020 02:17:57 +0000 (04:17 +0200)]
Remove unneeded netbsd_add_process()

Currently it does not add any value.

The netbsd_tdesc local variable is no longer needed. Remove it.
The tdesc value is set by the low target now.

gdbserver/ChangeLog:

        * netbsd-low.cc (netbsd_tdesc): Remove.
        (netbsd_add_process): Likewise.
        (netbsd_process_target::create_inferior): Update.

4 years agogold: Skip some incremental tests
H.J. Lu [Tue, 13 Oct 2020 12:22:55 +0000 (05:22 -0700)]
gold: Skip some incremental tests

Skip incremental_test_2, incremental_test_3, incremental_test_4,
incremental_test_5, incremental_copy_test, incremental_common_test_1
and incremental_comdat_test_1 when -fcf-protection is used to compile
gold since gold doesn't properly support -fcf-protection on Intel CET
enabled OS.

Also skip incremental_copy_test and incremental_comdat_test_1 for GCC 9
or later since they failed with GCC 9 or later.

PR gold/23539
* configure.ac: Check for GCC 9 or later and for -fcf-protection.
* configure: Regenerated.
* testsuite/Makefile.am (check_PROGRAMS): Skip incremental_test_2,
incremental_test_3, incremental_test_4, incremental_test_5,
incremental_copy_test, incremental_common_test_1 and
incremental_comdat_test_1 for -fcf-protection.  Also Skip
incremental_copy_test and incremental_comdat_test_1 for GCC 9 or
later.
* testsuite/Makefile.in: Regenerated.

4 years agogold: Discard .note.gnu.property section
H.J. Lu [Tue, 13 Oct 2020 12:21:53 +0000 (05:21 -0700)]
gold: Discard .note.gnu.property section

Discard .note.gnu.property section since it changes the expected section
order.

PR gold/23503
* testsuite/Makefile.am (justsyms_lib): Pass
-T $(srcdir)/justsyms_lib.t to gold.
* testsuite/Makefile.in: Regenerated.
* testsuite/justsyms_lib.t: New file.
* testsuite/script_test_10.t: Discard .note.gnu.property section.

4 years agogold: Update GNU_PROPERTY_X86_XXX macros
H.J. Lu [Tue, 13 Oct 2020 12:20:49 +0000 (05:20 -0700)]
gold: Update GNU_PROPERTY_X86_XXX macros

This patch updates GNU_PROPERTY_X86_XXX macros for gold:

1. GNU_PROPERTY_X86_UINT32_AND_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in all relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_AND_LO      0xc0000002
 #define GNU_PROPERTY_X86_UINT32_AND_HI      0xc0007fff

2. GNU_PROPERTY_X86_UINT32_OR_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in any relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_OR_LO    0xc0008000
 #define GNU_PROPERTY_X86_UINT32_OR_HI    0xc000ffff

3. GNU_PROPERTY_X86_UINT32_OR_AND_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in any relocatable inputs and the property is
present in all relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_OR_AND_LO   0xc0010000
 #define GNU_PROPERTY_X86_UINT32_OR_AND_HI   0xc0017fff

4. GNU_PROPERTY_X86_FEATURE_2_NEEDED, GNU_PROPERTY_X86_FEATURE_2_USED
and GNU_PROPERTY_X86_FEATURE_2_XXX bits.

GNU_PROPERTY_X86_FEATURE_1_AND is unchanged.  GNU_PROPERTY_X86_ISA_1_USED
and GNU_PROPERTY_X86_ISA_1_NEEDED are updated to better support targeted
processors since GNU_PROPERTY_X86_ISA_1_?86 aren't isn't very useful.
A new set of GNU_PROPERTY_X86_ISA_1_XXX bits are defined.  The previous
GNU_PROPERTY_X86_ISA_1_XXX macros are deprecated and renamed to
GNU_PROPERTY_X86_COMPAT_ISA_1_XXX and GNU_PROPERTY_X86_COMPAT_2_ISA_1_XXX.

elfcpp/

* elfcpp.h (GNU_PROPERTY_X86_ISA_1_USED): Renamed to ...
(GNU_PROPERTY_X86_COMPAT_ISA_1_USED): This.
(GNU_PROPERTY_X86_ISA_1_NEEDED): Renamed to ...
(GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED): This.
(GNU_PROPERTY_X86_UINT32_AND_LO): New.
(GNU_PROPERTY_X86_UINT32_AND_HI): Likewise.
(GNU_PROPERTY_X86_UINT32_OR_LO): Likewise.
(GNU_PROPERTY_X86_UINT32_OR_HI): Likewise.
(GNU_PROPERTY_X86_UINT32_OR_AND_LO): Likewise.
(GNU_PROPERTY_X86_UINT32_OR_AND_HI): Likewise.
(GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED): New.
(GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED): Likewise.
(GNU_PROPERTY_X86_FEATURE_1_AND): Updated to
(GNU_PROPERTY_X86_UINT32_AND_LO + 0).
(GNU_PROPERTY_X86_ISA_1_NEEDED): New.  Defined to
GNU_PROPERTY_X86_UINT32_OR_LO + 2.
(GNU_PROPERTY_X86_FEATURE_2_NEEDED): New.  Defined to
(GNU_PROPERTY_X86_UINT32_OR_LO + 1).
(GNU_PROPERTY_X86_ISA_1_USED): New.  Defined to
GNU_PROPERTY_X86_UINT32_OR_AND_LO + 2.
(GNU_PROPERTY_X86_FEATURE_2_USED): New.  Defined to
(GNU_PROPERTY_X86_UINT32_OR_AND_LO + 1).

gold/

* x86_64.cc (Target_x86_64::Target_x86_64): Initialize
feature_2_used_, feature_2_needed_ and object_feature_2_used_.
(Target_x86_64::feature_2_used_): New data member.
(Target_x86_64::feature_2_needed_): Likewise.
(Target_x86_64::object_isa_1_used_): Likewise.
(Target_x86_64::record_gnu_property): Support
GNU_PROPERTY_X86_COMPAT_ISA_1_USED,
GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED,
GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED,
GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED,
GNU_PROPERTY_X86_FEATURE_2_USED and
GNU_PROPERTY_X86_FEATURE_2_NEEDED.
(Target_x86_64::merge_gnu_properties): Merge FEATURE_2_USED bits.
Initialize object_feature_2_used_.
(Target_x86_64::do_finalize_gnu_properties): Support
GNU_PROPERTY_X86_FEATURE_2_USED and
GNU_PROPERTY_X86_FEATURE_2_NEEDED.
* testsuite/gnu_property_a.S (GNU_PROPERTY_X86_ISA_1_USED): Set
to 0xc0010002.
(GNU_PROPERTY_X86_ISA_1_NEEDED): Set to 0xc0008002.
* testsuite/gnu_property_b.S (GNU_PROPERTY_X86_ISA_1_USED): Set
to 0xc0010002.
(GNU_PROPERTY_X86_ISA_1_NEEDED): Set to 0xc0008002.
* testsuite/gnu_property_c.S (GNU_PROPERTY_X86_ISA_1_USED): Set
to 0xc0010002.
(GNU_PROPERTY_X86_ISA_1_NEEDED): Set to 0xc0008002.
* testsuite/gnu_property_test.sh: Updated.

4 years agogold: Properly align the NT_GNU_PROPERTY_TYPE_0 note
H.J. Lu [Tue, 13 Oct 2020 12:18:13 +0000 (05:18 -0700)]
gold: Properly align the NT_GNU_PROPERTY_TYPE_0 note

The NT_GNU_PROPERTY_TYPE_0 note should be aligned to 8 bytes for 64-bit
ELF as specified by gABI.  A note section can be only placed in a PT_NOTE
segment with the same alignment.

PR gold/22914
PR gold/23535
* layout.cc (Layout::attach_allocated_section_to_segment): Place
a note section in a PT_NOTE segment with the same alignment.  Set
the alignment of the PT_NOTE segment from the alignment of the
note section.
(Layout::create_note): Align the NT_GNU_PROPERTY_TYPE_0 note to 8
bytes for 64-bit ELF.
(Layout::segment_precedes): Place segments with larger alignments
first.
* output.cc (Output_segment::Output_segment): Initialize align_.
* output.h (Output_segment): Add align, set_align and align_.
* testsuite/Makefile.am (gnu_property_test.stdout): Pass -lhSWn
to $(TEST_READELF).
(gnu_property_test): Pass --build-id to ld.
* testsuite/Makefile.in: Regenerated.
* testsuite/gnu_property_test.sh (check_alignment): New.
Use check_alignment to check the NT_GNU_PROPERTY_TYPE_0 note
alignment.  Verify that there are 2 PT_NOTE segments.

4 years agoGold: Enable safe ICF for shared object on x86-64
H.J. Lu [Tue, 13 Oct 2020 12:10:24 +0000 (05:10 -0700)]
Gold: Enable safe ICF for shared object on x86-64

With

commit 4aebb6312eb5dcd12f2f8420028547584b708907
Author: Rahul Chaudhry <rahulchaudhry@google.com>
Date:   Wed Feb 15 00:37:10 2017 -0800

    Improved support for --icf=safe when used with -pie.

we now check opcode with R_X86_64_PC32 relocation, which tell branches
from other instructions.  We can enable safe ICF for shared object on
x86-64.  Also, global symbols with non-default visibility should be
folded like local symbols.

PR gold/21452
* x86_64.cc (Scan::local_reloc_may_be_function_pointer): Remove
check for shared library.
(Scan::global_reloc_may_be_function_pointer): Remove check for
shared library and symbol visibility.
* testsuite/icf_safe_so_test.cc (bar_static): New function.
(main): Take function address of bar_static and use it.
* testsuite/icf_safe_so_test.sh (arch_specific_safe_fold): Also
check fold on x86-64.  Check bar_static isn't folded.

4 years agoGold: Skip zero-sized sections for ICF
H.J. Lu [Tue, 13 Oct 2020 12:08:25 +0000 (05:08 -0700)]
Gold: Skip zero-sized sections for ICF

Skip zero-sized sections since there is no need to do ICF on them.

* icf.cc (Icf::find_identical_sections): Skip zero-sized sections.

4 years agoNormalize names of the NetBSD files
Kamil Rytarowski [Tue, 6 Oct 2020 19:36:22 +0000 (21:36 +0200)]
Normalize names of the NetBSD files

The files used to be named 'nbsd', which incorrectly reflects
the name of the OS and confuses it with other BSD derived OSes.

gdb/ChangeLog:

        * Makefile.in (ALL_64_TARGET_OBS, ALL_TARGET_OBS)
        HFILES_NO_SRCDIR, ALLDEPFILES): Rename files.
        * alpha-bsd-nat.c: Adjust include.
        * alpha-bsd-tdep.h: Adjust comment.
        * alpha-nbsd-tdep.c: Rename to ...
        * alpha-netbsd-tdep.c: ... this, adjust include.
        * amd64-nbsd-nat.c: Rename to ...
        * amd64-netbsd-nat.c: ... this, adjust include.
        * amd64-nbsd-tdep.c: Rename to ...
        * amd64-netbsd-tdep.c: ... this, adjust include.
        * amd64-tdep.h: Adjust include.
        * arm-nbsd-nat.c: Rename to ...
        * arm-netbsd-nat.c: ... this, adjust include.
        * arm-nbsd-tdep.c: Rename to ...
        * arm-netbsd-tdep.c: ... this, adjust include.
        * arm-nbsd-tdep.h: Rename to ...
        * arm-netbsd-tdep.h: ... this, adjust include.
        * configure.nat: Adjust file lists.
        * configure.tgt: Likewise.
        * hppa-nbsd-nat.c: Rename to ...
        * hppa-netbsd-nat.c: ... this, adjust include.
        * hppa-nbsd-tdep.c: Rename to ...
        * hppa-netbsd-tdep.c: ... this, adjust include.
        * i386-nbsd-nat.c: Rename to ...
        * i386-netbsd-nat.c: ... this, adjust include.
        * i386-nbsd-tdep.c: Rename to ...
        * i386-netbsd-tdep.c: ... this, adjust include.
        * m68k-bsd-nat.c: Adjust include.
        * mips-nbsd-nat.c: Rename to ...
        * mips-netbsd-nat.c: ... this, adjust include.
        * mips-nbsd-tdep.c: Rename to ...
        * mips-netbsd-tdep.c: ... this, adjust include.
        * mips-nbsd-tdep.h: Rename to ...
        * mips-netbsd-tdep.h: ... this.
        * nbsd-nat.c: Rename to ...
        * netbsd-nat.c: ... this, adjust include.
        * nbsd-nat.h: Rename to ...
        * netbsd-nat.h: ... this, adjust include.
        * nbsd-tdep.c: Rename to ...
        * netbsd-tdep.c: ... this, adjust include.
        * nbsd-tdep.h: Rename to ...
        * netbsd-tdep.h: ... this.
        * ppc-nbsd-nat.c: Rename to ...
        * ppc-netbsd-nat.c: ... this, adjust include.
        * ppc-nbsd-tdep.c: Rename to ...
        * ppc-netbsd-tdep.c: ... this, adjust include and comment.
        * ppc-nbsd-tdep.h: Rename to ...
        * ppc-netbsd-tdep.h: ... this.
        * sh-nbsd-nat.c: Rename to ...
        * sh-netbsd-nat.c: ... this, adjust include.
        * sh-nbsd-tdep.c: Rename to ...
        * sh-netbsd-tdep.c: ... this, adjust include.
        * sparc-nbsd-nat.c: Rename to ...
        * sparc-netbsd-nat.c: ... this.
        * sparc-nbsd-tdep.c: Rename to ...
        * sparc-netbsd-tdep.c: ... this, adjust include.
        * sparc64-nbsd-nat.c: Rename to ...
        * sparc64-netbsd-nat.c: ... this.
        * sparc64-nbsd-tdep.c: Rename to ...
        * sparc64-netbsd-tdep.c: ... this, adjust include.
        * sparc64-tdep.h: Adjust comment.
        * vax-bsd-nat.c: Adjust include.
        * vax-nbsd-tdep.c: Rename to ...
        * vax-netbsd-tdep.c: ... this, adjust include.

4 years agoChange target_section_table to std::vector alias
Tom Tromey [Mon, 12 Oct 2020 21:53:16 +0000 (15:53 -0600)]
Change target_section_table to std::vector alias

Because target_section_table only holds a vector, and because it is
used in an "open" way, this patch makes it just be an alias for the
std::vector specialization.  This makes the code less wordy.  If we do
ever want to add more specialized behavior to this type, it's simple
enough to convert it back to a struct with the few needed methods
implied by this change.

gdb/ChangeLog
2020-10-12  Tom Tromey  <tom@tromey.com>

* target.h (struct target_ops) <get_section_table>: Update.
(target_get_section_table): Update.
* target.c (target_get_section_table, target_section_by_addr)
(memory_xfer_partial_1): Update.
* target-section.h (target_section_table): Now an alias.
* target-delegates.c: Rebuild.
* target-debug.h (target_debug_print_target_section_table_p):
Rename from target_debug_print_struct_target_section_table_p.
* symfile.c (build_section_addr_info_from_section_table): Update.
* solib.c (solib_map_sections, solib_contains_address_p): Update.
* solib-svr4.c (scan_dyntag): Update.
* solib-dsbt.c (scan_dyntag): Update.
* remote.c (remote_target::remote_xfer_live_readonly_partial):
Update.
* record-full.c (record_full_core_target::xfer_partial): Update.
* progspace.h (struct program_space) <target_sections>: Update.
* exec.h (print_section_info): Update.
* exec.c (exec_target::close, build_section_table)
(add_target_sections, add_target_sections_of_objfile)
(remove_target_sections, exec_on_vfork)
(section_table_available_memory)
(section_table_xfer_memory_partial)
(exec_target::get_section_table, exec_target::xfer_partial)
(print_section_info, set_section_command)
(exec_set_section_address, exec_target::has_memory): Update.
* corelow.c (core_target::build_file_mappings)
(core_target::xfer_partial, core_target::info_proc_mappings)
(core_target::info_proc_mappings): Update.
* bfd-target.c (class target_bfd): Update

4 years agoRemove clear_section_table
Tom Tromey [Mon, 12 Oct 2020 21:53:16 +0000 (15:53 -0600)]
Remove clear_section_table

The call to clear_section_table in ~program_space is now clearly not
needed -- the section table will clear itself.  This patch removes
this call and then inlines the one remaining call to
clear_section_table.

gdb/ChangeLog
2020-10-12  Tom Tromey  <tom@tromey.com>

* progspace.c (program_space::~program_space): Don't call
clear_section_table.
* exec.h (clear_section_table): Don't declare.
* exec.c (exec_target::close): Update.
(clear_section_table): Remove.

4 years agoSimplify add_target_sections_of_objfile
Tom Tromey [Mon, 12 Oct 2020 21:53:16 +0000 (15:53 -0600)]
Simplify add_target_sections_of_objfile

Now that target_section_table uses std::vector,
add_target_sections_of_objfile does not need to loop twice.  This
patch simplifies this code to have just a single loop.  Also, the
passed-in objfile can never be NULL, so this changes this function to
assert that.

gdb/ChangeLog
2020-10-12  Tom Tromey  <tom@tromey.com>

* exec.c (add_target_sections_of_objfile): Simplify.

4 years agobuild_section_table cannot fail
Tom Tromey [Mon, 12 Oct 2020 21:53:16 +0000 (15:53 -0600)]
build_section_table cannot fail

I noticed that build_section_table cannot fail.  This patch changes it
to return a target_section_table and then removes the dead code.

gdb/ChangeLog
2020-10-12  Tom Tromey  <tom@tromey.com>

* solib.c (solib_map_sections): Update.
* record-full.c (record_full_core_open_1): Update.
* exec.h (build_section_table): Return a target_section_table.
* exec.c (exec_file_attach): Update.
(build_section_table): Return a target_section_table.
* corelow.c (core_target::core_target): Update.
* bfd-target.c (target_bfd::target_bfd): Update.

4 years agoUse a std::vector in target_section_table
Tom Tromey [Mon, 12 Oct 2020 21:53:16 +0000 (15:53 -0600)]
Use a std::vector in target_section_table

This changes target_section_table to wrap a std::vector.  This
simplifies some code, and also enables the simplifications coming in
the subsequent patches.

Note that for solib, I chose to have it use a pointer to a
target_section_table.  This is more convoluted than would be ideal,
but I didn't want to convert solib to new/delete as a prerequisite for
this series.

gdb/ChangeLog
2020-10-12  Tom Tromey  <tom@tromey.com>

* target.c (target_section_by_addr, memory_xfer_partial_1):
Update.
* target-section.h (struct target_section_table): Use
std::vector.
* symfile.h (build_section_addr_info_from_section_table): Take a
target_section_table.
* symfile.c (build_section_addr_info_from_section_table): Take a
target_section_table.
* solist.h (struct so_list) <sections>: Change type.
<sections_end>: Remove.
* solib.c (solib_map_sections, clear_so, solib_read_symbols)
(solib_contains_address_p): Update.
* solib-svr4.c (scan_dyntag): Update.
* solib-dsbt.c (scan_dyntag): Update.
* remote.c (remote_target::remote_xfer_live_readonly_partial):
Update.
* record-full.c (record_full_core_start, record_full_core_end):
Remove.
(record_full_core_sections): New global.
(record_full_core_open_1, record_full_core_target::xfer_partial):
Update.
* exec.h (build_section_table, section_table_xfer_memory_partial)
(add_target_sections): Take a target_section_table.
* exec.c (exec_file_attach, clear_section_table): Update.
(resize_section_table): Remove.
(build_section_table, add_target_sections): Take a
target_section_table.
(add_target_sections_of_objfile, remove_target_sections)
(exec_on_vfork): Update.
(section_table_available_memory): Take a target_section_table.
(section_table_read_available_memory): Update.
(section_table_xfer_memory_partial): Take a target_section_table.
(print_section_info, set_section_command)
(exec_set_section_address, exec_target::has_memory): Update.
* corelow.c (class core_target) <m_core_section_table,
m_core_file_mappings>: Remove braces.
<~core_target>: Remove.
(core_target::core_target): Update.
(core_target::~core_target): Remove.
(core_target::build_file_mappings)
(core_target::xfer_memory_via_mappings)
(core_target::xfer_partial, core_target::info_proc_mappings):
Update.
* bfd-target.c (target_bfd::xfer_partial): Update.
(target_bfd::target_bfd): Update.
(target_bfd::~target_bfd): Remove.

4 years agoIntroduce target-section.h
Tom Tromey [Mon, 12 Oct 2020 21:53:16 +0000 (15:53 -0600)]
Introduce target-section.h

This introduces a new target-section.h file.  This makes some of the
later patches in this series a bit cleaner, because new includes of
target.h won't be required.  Also I think it's better to have small
header files for each separate data structure.

gdb/ChangeLog
2020-10-12  Tom Tromey  <tom@tromey.com>

* target.h (struct target_section, struct target_section_table):
Move to target-section.h.
* target-section.h: New file.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 13 Oct 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoPowerPC testsuite fails and duplicates
Alan Modra [Mon, 12 Oct 2020 02:27:58 +0000 (12:57 +1030)]
PowerPC testsuite fails and duplicates

binutils commit 5fbec329ec3 changed disassembly of mfvsrd and mtvsrd
to be consistent with the mfvsrwz and mtvsrw/mtvsrwz, which favour
output of the fp/vr extended mnemonic and regs over the vsx form.
This patch fixes the following, and removes some duplicates.

FAIL: gdb.arch/powerpc-power8.exp: found: mfvsrd  r12,vs62
FAIL: gdb.arch/powerpc-power8.exp: found: mtvsrd  vs48,r11
FAIL: gdb.arch/powerpc-vsx2.exp: found: mfvsrd  r12,vs30
FAIL: gdb.arch/powerpc-vsx2.exp: found: mfvsrd  r12,vs30
FAIL: gdb.arch/powerpc-vsx2.exp: found: mfvsrd  r12,vs62
FAIL: gdb.arch/powerpc-vsx2.exp: found: mfvsrd  r12,vs62
FAIL: gdb.arch/powerpc-vsx2.exp: found: mtvsrd  vs11,r28
FAIL: gdb.arch/powerpc-vsx2.exp: found: mtvsrd  vs11,r28
FAIL: gdb.arch/powerpc-vsx2.exp: found: mtvsrd  vs43,r29
FAIL: gdb.arch/powerpc-vsx2.exp: found: mtvsrd  vs43,r29

* gdb.arch/powerpc-altivec.s,
* gdb.arch/powerpc-power7.s,
* gdb.arch/powerpc-power8.s,
* gdb.arch/powerpc-power9.s,
* gdb.arch/powerpc-vsx.s,
* gdb.arch/powerpc-vsx2.s: Remove duplicate instructions.
* gdb.arch/powerpc-altivec.exp,
* gdb.arch/powerpc-power7.exp,
* gdb.arch/powerpc-power8.exp,
* gdb.arch/powerpc-power9.exp,
* gdb.arch/powerpc-vsx.exp,
* gdb.arch/powerpc-vsx2.exp: Likewise, and update expected
disassembly of mfvsrd/mtvsrd.

4 years agoRe: gdb: Improve formatting of 'show architecture' messages
Alan Modra [Mon, 12 Oct 2020 01:02:21 +0000 (11:32 +1030)]
Re: gdb: Improve formatting of 'show architecture' messages

Commit ccb9eba6a25 updated the testsuite for some targets without
running the testsuite on those targets.  This patch corrects the
update, in most cases just adding the expected full-stop.

On powerpc64le-linux, fixes these:
FAIL: gdb.arch/powerpc-d128-regs.exp: checking for PPC arch
FAIL: gdb.arch/powerpc-disassembler-options.exp: set architecture powerpc:common64
FAIL: gdb.arch/powerpc-disassembler-options.exp: set architecture rs6000:6000
FAIL: gdb.arch/ppc64-symtab-cordic.exp: show architecture

I also verified that arm-linuxeabi and s390x-linux cross-builds now
pass their disassembler-options.exp tests.

* gdb.arch/arm-disassembler-options.exp: Adjust expected
"target architecture" output.
* gdb.arch/powerpc-d128-regs.exp: Likewise.
* gdb.arch/powerpc-disassembler-options.exp: Likewise.
* gdb.arch/ppc64-symtab-cordic.exp: Likewise.
* gdb.arch/s390-disassembler-options.exp: Likewise.

4 years agoReject ambiguous C++ field accesses (PR exp/26602)
Pedro Alves [Fri, 28 Aug 2020 20:10:59 +0000 (21:10 +0100)]
Reject ambiguous C++ field accesses (PR exp/26602)

The gdb.cp/ambiguous.exp testcase had been disabled for many years,
but recently it was re-enabled.  However, it is failing everywhere.
That is because it is testing an old feature that is gone from GDB.

The testcase is expecting to see an ambiguous field warning, like:

 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
 send_gdb "print x.x\n"
 gdb_expect {
    -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
pass "print x.x"
    }
    -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
pass "print x.x"
    }
    -re ".*$gdb_prompt $" { fail "print x.x" }
    timeout { fail "(timeout) print x.x" }
  }

However, GDB just accesses one of the candidates without warning or
error:

 print x.x
 $1 = 1431655296
 (gdb) FAIL: gdb.cp/ambiguous.exp: print x.x

(The weird number is because the testcase does not initialize the
variables.)

The testcase come in originally with the big HP merge:

 +Sun Jan 10 23:44:11 1999  David Taylor  <taylor@texas.cygnus.com>
 +
 +
 +       The following files are part of the HP merge; some had longer
 +       names at HP, but have been renamed to be no more than 14
 +       characters in length.

Looking at the tree back then, we find that warning:

 /* Helper function used by value_struct_elt to recurse through baseclasses.
    Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes,
    and search in it assuming it has (class) type TYPE.
    If found, return value, else return NULL.

    If LOOKING_FOR_BASECLASS, then instead of looking for struct fields,
    look for a baseclass named NAME.  */

 static value_ptr
 search_struct_field (name, arg1, offset, type, looking_for_baseclass)
      char *name;
      register value_ptr arg1;
      int offset;
      register struct type *type;
      int looking_for_baseclass;
 {
   int found = 0;
   char found_class[1024];
   value_ptr v;
   struct type *vbase = NULL;

   found_class[0] = '\000';

   v = search_struct_field_aux (name, arg1, offset, type, looking_for_baseclass, &found, found_class, &vbase);
   if (found > 1)
     warning ("%s ambiguous; using %s::%s. Use a cast to disambiguate.",
              name, found_class, name);

   return v;
 }

However, in current GDB, search_struct_field does not handle the
ambiguous field case, nor is that warning found anywhere.  Somehow it
got lost over the years.  That seems like a regression, because the
compiler (as per language rules) rejects the ambiguous accesses as
well.  E.g.:

 gdb.cp/ambiguous.cc:98:5: error: request for member 'x' is ambiguous
    98 |   x.x = 1;
       |     ^
 gdb.cp/ambiguous.cc:10:7: note: candidates are: 'int A2::x'
    10 |   int x;
       |       ^
 gdb.cp/ambiguous.cc:4:7: note:                 'int A1::x'
     4 |   int x;
       |       ^

This patch restores the feature, though implemented differently and
with better user experience, IMHO.  An ambiguous access is now an
error instead of a warning, and also GDB shows you all the candidates,
like:

 (gdb) print x.x
 Request for member 'x' is ambiguous in type 'X'. Candidates are:
   'int A1::x' (X -> A1)
   'int A2::x' (X -> A2)
 (gdb) print j.x
 Request for member 'x' is ambiguous in type 'J'. Candidates are:
   'int A1::x' (J -> K -> A1)
   'int A1::x' (J -> L -> A1)

Users can then fix their commands by casting or by specifying the
baseclass explicitly, like:

 (gdb) p x.A1::x
 $1 = 1
 (gdb) p x.A2::x
 $2 = 2
 (gdb) p ((A1) x).x
 $3 = 1
 (gdb) p ((A2) x).x
 $4 = 2
 (gdb) p j.K::x
 $12 = 1
 (gdb) p j.L::x
 $13 = 2
 (gdb) p j.A1::x
 base class 'A1' is ambiguous in type 'J'

The last error I've not touched; could be improved to also list the
baseclass candidates.

The showing the class "path" for each candidate was inspired by GCC's
output when you try an ambiguous cast:

  gdb.cp/ambiguous.cc:161:8: error: ambiguous conversion from derived class 'const JVA1' to base class 'const A1':
      class JVA1 -> class KV -> class A1
      class JVA1 -> class A1
    (A1) jva1;
 ^~~~

I did not include the "class" word as it seemed unnecessarily
repetitive, but I can include it if people prefer it:

 (gdb) print j.x
 Request for member 'x' is ambiguous in type 'J'. Candidates are:
   'int A1::x' (class J -> class K -> class A1)
   'int A1::x' (class J -> class L -> class A1)

The testcase is adjusted accordingly.  I also took the chance to
modernize it at the same time.

Also, as mentioned above, the testcase doesn't currently initialize
the tested variables.  This patch inializes them all, giving each
field a distinct value, so that we can be sure that GDB is accessing
the right fields / offsets.  The testcase is extended accordingly.

Unfortunately, this exposes a bug, not addressed in this patch.  The
bug is around a class that inherits from A1 directly and also inherits
from two other distinct base classes that inherit virtually from A1 in
turn:

 print jva1.KV::x
 $51 = 1431665544
 (gdb) FAIL: gdb.cp/ambiguous.exp: all fields: print jva1.KV::x
 print jva1.KV::y
 $52 = 21845
 (gdb) FAIL: gdb.cp/ambiguous.exp: all fields: print jva1.KV::y

 (gdb) print /x (KV)jva1
 $4 = {<A1> = <invalid address>, _vptr.KV = 0x555555557b88 <vtable for JVA1+24>, i = 0x457}
 (gdb) print /x (A1)(KV)jva1
 Cannot access memory at address 0x0

Since that's an orthogonal issue, I filed PR c++/26550 and kfailed the
tests that fail because of it.

gdb/ChangeLog:

PR exp/26602
* valops.c (struct struct_field_searcher): New.
(update_search_result): Rename to ...
(struct_field_searcher::update_result): ... this.  Simplify
prototype.  Record all found fields.
(do_search_struct_field): Rename to ...
(struct_field_searcher::search): ... this.  Simplify prototype.
Maintain stack of visited baseclass path.  Call update_result for
fields too.  Keep searching fields in baseclasses instead of
stopping at the first found field.
(search_struct_field): Use struct_field_searcher.  When looking
for fields, report ambiguous access attempts.

gdb/testsuite/ChangeLog:

PR exp/26602
PR c++/26550
* gdb.cp/ambiguous.cc (marker1): Delete.
(main): Initialize all the fields of the locals.  Replace marker1
call with a "set breakpoint here" marker.
* gdb.cp/ambiguous.exp: Modernize.  Use gdb_continue_to_breakpoint
instead of running to marker1.  Add tests printing all the
variables and all the fields of the variables.
(test_ambiguous): New proc, expecting the new GDB output when a
field access is ambiguous.  Change all "warning: X ambiguous"
tests to use it.

4 years agoFix testcases with required but unreferenced functions and variables
Gary Benson [Mon, 12 Oct 2020 09:35:23 +0000 (10:35 +0100)]
Fix testcases with required but unreferenced functions and variables

A number of testcases define variables and/or functions which are
referenced by GDB during the test, but which are not referenced from
within the test executable.  Clang correctly recognizes that these
variables and functions are unused, and optimizes them out, causing
the testcases in question to fail.  This commit adds __attribute__
((used)) in various places to prevent this.

gdb/testsuite/ChangeLog:

* gdb.base/msym-bp.c (foo): Add __attribute__ ((used)).
* gdb.base/msym-bp-2.c (foo): Likewise.
* gdb.base/msym-lang.c (foo): Likewise.
* gdb.base/msym-lang-main.c (foo): Likewise.
* gdb.base/symtab-search-order-1.c (static_global): Likewise.
* gdb.guile/scm-pretty-print.c (eval_func): Likewise.
* gdb.mi/mi-sym-info-1.c (global_f1): Likewise.
* gdb.mi/mi-sym-info-2.c (global_f1, var1, var2): Likewise.
* gdb.multi/watchpoint-multi-exit.c (globalvar): Likewise.
* gdb.python/py-as-string.c (enum_valid, enum_invalid): Likewise.
* gdb.python/py-objfile.c (static_var): Likewise.
* gdb.python/py-symbol.c (rr): Likewise.
* gdb.python/py-symbol-2.c (anon, rr): Likewise.
* gdb.mi/mi-sym-info.exp (lineno1, lineno2): Updated.

4 years agoAutomatic date update in version.in
GDB Administrator [Mon, 12 Oct 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogdb: detect main function even when there's no matching msymbol
Andrew Burgess [Thu, 8 Oct 2020 11:28:19 +0000 (12:28 +0100)]
gdb: detect main function even when there's no matching msymbol

Currently, GDB will only stop the backtrace at the main function if
there is a minimal symbol with the matching name.  In Fortran programs
compiled with gfortran this is not the case.  The main function is
present in the DWARF, and as marked as DW_AT_main_subprogram, but
there's no minimal symbol.

This commit extends `inside_main_func` to check the full symbols if no
matching minimal symbol is found.

There's an updated test case that covers this change.

gdb/ChangeLog:

* frame.c (inside_main_func): Check full symbols as well as
minimal symbols.

gdb/testsuite/ChangeLog:

* gdb.fortran/mixed-lang-stack.exp (run_tests): Update expected
output of backtrace.

4 years agoAutomatic date update in version.in
GDB Administrator [Sun, 11 Oct 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoAutomatic date update in version.in
GDB Administrator [Sat, 10 Oct 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoada-lang.c::advance_wild_match improve doc and parameter+temporaries types
Joel Brobecker [Fri, 9 Oct 2020 20:30:48 +0000 (13:30 -0700)]
ada-lang.c::advance_wild_match improve doc and parameter+temporaries types

This commit fixes the type of one of the parameters as well as a couple
of temporaries.

While at it, the function's description is slightly rewritten to make it
a little clearer what the function does.

gdb/ChangeLog:

        * ada-lang.c (advance_wild_match): Rewrite the function's
        description.  Change the type of target0, t0 and t1 to char.

4 years agoFix bit offset regression
Tom Tromey [Tue, 6 Oct 2020 14:56:54 +0000 (08:56 -0600)]
Fix bit offset regression

The type-safe attribute patch introduced a regression that can occur
when the DW_AT_bit_offset value is negative.  This can happen with
some Ada programs.

This patch fixes the problem.  It also fixes a minor oddity in the
existing scalar storage test -- this test was intended to assign a
smaller number of bits to the field.

2020-10-09  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.c (dwarf2_add_field): Handle signed offsets.

gdb/testsuite/ChangeLog
2020-10-09  Tom Tromey  <tromey@adacore.com>

* gdb.ada/scalar_storage/storage.adb (Another_Range): New type.
(Rec): Add field.  Fix range.
* gdb.ada/scalar_storage.exp: Update.

4 years agoReturn std::string from ada_encode
Tom Tromey [Fri, 9 Oct 2020 14:27:30 +0000 (08:27 -0600)]
Return std::string from ada_encode

This changes ada_encode to return a std::string.  This simplifies it
somewhat, removes a use of GROW_VECT, and is also simpler for callers
to use.

gdb/ChangeLog
2020-10-09  Tom Tromey  <tromey@adacore.com>

* ada-lang.h (ada_encode): Return std::string.
* ada-lang.c (ada_encode_1): Return std::string.
(ada_encode): Likewise.
(type_from_tag, ada_lookup_name_info::ada_lookup_name_info):
Update.
* ada-exp.y (block_lookup, write_var_or_type): Update.

4 years ago[GOLD] Power10 segv due to wild r2
Alan Modra [Fri, 9 Oct 2020 06:26:33 +0000 (16:56 +1030)]
[GOLD] Power10 segv due to wild r2

Calling non-pcrel functions from pcrel code requires a stub to set up
r2.  Gold created the stub, but an "optimisation" made the stub jump
to the function local entry, ie. r2 was not initialised.

This patch fixes that long branch stub problem, and another that might
occur for plt call stubs to local functions.

bfd/
* elf64-ppc.c (write_plt_relocs_for_local_syms): Don't do local
entry offset optimisation.
gold/
* powerpc.cc (Powerpc_relobj::do_relocate_sections): Don't do
local entry offset optimisation for lplt_section.
(Target_powerpc::Branch_info::make_stub): Don't add local
entry offset to long branch dest passed to
add_long_branch_entry.  Do pass st_other bits.
(Stub_table::Branch_stub_ent): Add "other_" field.
(Stub_table::add_long_branch_entry): Add "other" param, and
save.
(Stub_table::branch_stub_size): Adjust long branch offset.
(Stub_table::do_write): Likewise.
(Target_powerpc::Relocate::relocate): Likewise.

4 years ago[GOLD] internal error in relocate, at powerpc.cc:10473
Alan Modra [Fri, 9 Oct 2020 00:29:33 +0000 (10:59 +1030)]
[GOLD] internal error in relocate, at powerpc.cc:10473

GOT relocations can refer directly to a function in a fixed position
executable, unlike ADDR64 which needs a global entry stub, or branch
relocs, which need PLT stubs.

* powerpc.cc (is_got_reloc): New function.
(Target_powerpc::Relocate::relocate): Use it here, exclude GOT
relocs when looking for stubs.

4 years agox86: Support GNU_PROPERTY_X86_ISA_1_V[234] marker
H.J. Lu [Fri, 9 Oct 2020 12:05:57 +0000 (05:05 -0700)]
x86: Support GNU_PROPERTY_X86_ISA_1_V[234] marker

GCC 11 supports -march=x86-64-v[234] to enable x86 micro-architecture ISA
levels:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97250

Update GNU_PROPERTY_X86_ISA_1_XXX macros:

https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/13

in x86 ELF binaries to indicate that micro-architecture ISA levels
required to execute the binary:

 #define GNU_PROPERTY_X86_ISA_1_NEEDED (GNU_PROPERTY_X86_UINT32_OR_LO + 2)
 #define GNU_PROPERTY_X86_ISA_1_USED (GNU_PROPERTY_X86_UINT32_OR_AND_LO + 2)
 #define GNU_PROPERTY_X86_ISA_1_V2 (1U << 0)
 #define GNU_PROPERTY_X86_ISA_1_V3 (1U << 1)
 #define GNU_PROPERTY_X86_ISA_1_V4 (1U << 2)

The previous GNU_PROPERTY_X86_ISA_1_XXX  macros are deprecated and renamed
to GNU_PROPERTY_X86_COMPAT_2_ISA_1_XXX.

In addition to EM_X86_64, GNU_PROPERTY_X86_ISA_1_V[234] marker can be used
by ld.so to detect the x86-64-v4 shared library placed in an x86-64-v2
directory by mistake on an x86-64-v2 machine to avoid crashes on x86-64-v4
instructions.

Add -z x86-64-v[234] linker command line option to mark x86-64-v[234]
ISA level as needed.

Also add

 #define GNU_PROPERTY_X86_FEATURE_2_MASK (1U << 11)

for mask registers.

bfd/

PR gas/26703
* elf-linker-x86.h (elf_linker_x86_params): Add isa_level.
* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Merge
GNU_PROPERTY_X86_ISA_1_V[234].
(_bfd_x86_elf_link_setup_gnu_properties): Generate
GNU_PROPERTY_X86_ISA_1_V[234] for -z x86-64-v[234].

binutils/

PR gas/26703
* readelf.c (decode_x86_compat_2_isa): New function.
(decode_x86_isa): Updated for new X86_ISA_1_XXX bits.
(decode_x86_feature_1): Handle GNU_PROPERTY_X86_FEATURE_2_MASK.
(print_gnu_property_note): Handle X86_COMPAT_2_ISA_1_USED,
and X86_COMPAT_2_ISA_1_NEEDED.
* testsuite/binutils-all/i386/pr21231b.s: Updated to the current
GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED
values.
* testsuite/binutils-all/x86-64/pr21231b.s: Likewise.
* testsuite/binutils-all/x86-64/pr23494a.s: Likewise.
* testsuite/binutils-all/x86-64/pr23494b.s: Likewise.
* testsuite/binutils-all/x86-64/pr23494c.s: Likewise.
* testsuite/binutils-all/i386/empty.d: Updated.
* testsuite/binutils-all/i386/ibt.d: Likewise.
* testsuite/binutils-all/i386/pr21231a.d: Likewise.
* testsuite/binutils-all/i386/pr21231b.d: Likewise.
* testsuite/binutils-all/i386/shstk.d: Likewise.
* testsuite/binutils-all/x86-64/empty-x32.d: Likewise.
* testsuite/binutils-all/x86-64/empty.d: Likewise.
* testsuite/binutils-all/x86-64/ibt-x32.d: Likewise.
* testsuite/binutils-all/x86-64/ibt.d: Likewise.
* testsuite/binutils-all/x86-64/pr21231a.d: Likewise.
* testsuite/binutils-all/x86-64/pr21231b.d: Likewise.
* testsuite/binutils-all/x86-64/pr23494a-x32.d: Likewise.
* testsuite/binutils-all/x86-64/pr23494a.d: Likewise.
* testsuite/binutils-all/x86-64/pr23494c-x32.d: Likewise.
* testsuite/binutils-all/x86-64/pr23494c.d: Likewise.
* testsuite/binutils-all/x86-64/pr23494d-x32.d: Likewise.
* testsuite/binutils-all/x86-64/pr23494d.d: Likewise.
* testsuite/binutils-all/x86-64/pr23494e-x32.d: Likewise.
* testsuite/binutils-all/x86-64/pr23494e.d: Likewise.
* testsuite/binutils-all/x86-64/shstk-x32.d: Likewise.
* testsuite/binutils-all/x86-64/shstk.d: Likewise.

gas/

PR gas/26703
* config/tc-i386.c (xstate): Add xstate_mask.
(md_assemble): Check i.types[j], instead of i.tm.operand_types[j],
for xstate.  Set xstate_mask, instead of xstate_zmm, for RegMask.
(output_insn): Update for GNU_PROPERTY_X86_ISA_1_V[234].  Update
xstate for mask register and VSIB.
* testsuite/gas/i386/i386.exp: Run more GNU_PROPERTY tests.
* testsuite/gas/i386/property-1.s: Updated to the current
GNU_PROPERTY_X86_ISA_1_USED value.
* testsuite/gas/i386/property-2.s: Only keep cmove.
* testsuite/gas/i386/property-3.s: Changed to addsubpd.
* testsuite/gas/i386/property-1.d: Updated.
* testsuite/gas/i386/property-2.d: Likewise.
* testsuite/gas/i386/property-3.d: Likewise.
* testsuite/gas/i386/property-4.d: Likewise.
* testsuite/gas/i386/property-5.d: Likewise.
* testsuite/gas/i386/property-6.d: Likewise.
* testsuite/gas/i386/x86-64-property-1.d: Likewise.
* testsuite/gas/i386/x86-64-property-2.d: Likewise.
* testsuite/gas/i386/x86-64-property-3.d: Likewise.
* testsuite/gas/i386/x86-64-property-4.d: Likewise.
* testsuite/gas/i386/x86-64-property-5.d: Likewise.
* testsuite/gas/i386/x86-64-property-6.d: Likewise.
* testsuite/gas/i386/x86-64-property-7.d: Likewise.
* testsuite/gas/i386/x86-64-property-8.d: Likewise.
* testsuite/gas/i386/x86-64-property-9.d: Likewise.
* testsuite/gas/i386/property-11.d: New file.
* testsuite/gas/i386/property-11.s: Likewise.
* testsuite/gas/i386/property-12.d: Likewise.
* testsuite/gas/i386/property-12.s: Likewise.
* testsuite/gas/i386/property-13.d: Likewise.
* testsuite/gas/i386/property-13.s: Likewise.
* testsuite/gas/i386/x86-64-property-11.d: Likewise.
* testsuite/gas/i386/x86-64-property-12.d: Likewise.
* testsuite/gas/i386/x86-64-property-13.d: Likewise.
* testsuite/gas/i386/x86-64-property-14.d: Likewise.
* testsuite/gas/i386/x86-64-property-14.s: Likewise.

include/

PR gas/26703
* elf/common.h (GNU_PROPERTY_X86_ISA_1_USED): Renamed to ...
(GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED): This.
(GNU_PROPERTY_X86_ISA_1_NEEDED): Renamed to ...
(GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED): This.
(GNU_PROPERTY_X86_ISA_1_XXX): Renamed to ...
(GNU_PROPERTY_X86_COMPAT_2_ISA_1_XXX): This.
(GNU_PROPERTY_X86_ISA_1_NEEDED): New.
(GNU_PROPERTY_X86_ISA_1_USED): Likewise.
(GNU_PROPERTY_X86_ISA_1_V2): Likewise.
(GNU_PROPERTY_X86_ISA_1_V3): Likewise.
(GNU_PROPERTY_X86_ISA_1_V4): Likewise.
(GNU_PROPERTY_X86_FEATURE_2_MASK): Likewise.

ld/

PR gas/26703
* NEWS: Mention -z x86-64-v[234].
* ld.texi: Document -z x86-64-v[234].
* emulparams/elf32_x86_64.sh: Use x86-64-level.sh.
* emulparams/elf_i386.sh: Likewise.
* emulparams/elf_x86_64.sh: Likewise.
* emulparams/x86-64-level.sh: New file.
* testsuite/ld-elf/x86-feature-1a.rd: Update.
* testsuite/ld-elf/x86-feature-1b.rd: Likewise.
* testsuite/ld-elf/x86-feature-1c.rd: Likewise.
* testsuite/ld-elf/x86-feature-1d.rd: Likewise.
* testsuite/ld-elf/x86-feature-1e.rd: Likewise.
* testsuite/ld-i386/pr23372c.d: Likewise.
* testsuite/ld-i386/pr23486c.d: Likewise.
* testsuite/ld-i386/pr23486d.d: Likewise.
* testsuite/ld-i386/pr24322a.d: Likewise.
* testsuite/ld-i386/pr24322b.d: Likewise.
* testsuite/ld-i386/property-1a.r: Likewise.
* testsuite/ld-i386/property-2a.r: Likewise.
* testsuite/ld-i386/property-3.r: Likewise.
* testsuite/ld-i386/property-3a.r: Likewise.
* testsuite/ld-i386/property-4.r: Likewise.
* testsuite/ld-i386/property-4a.r: Likewise.
* testsuite/ld-i386/property-5.r: Likewise.
* testsuite/ld-i386/property-5a.r: Likewise.
* testsuite/ld-i386/property-7a.r: Likewise.
* testsuite/ld-i386/property-x86-3.d: Likewise.
* testsuite/ld-i386/property-x86-4a.d: Likewise.
* testsuite/ld-i386/property-x86-5.d: Likewise.
* testsuite/ld-i386/property-x86-cet1.d: Likewise.
* testsuite/ld-i386/property-x86-cet2a.d: Likewise.
* testsuite/ld-i386/property-x86-cet5a.d: Likewise.
* testsuite/ld-i386/property-x86-cet5b.d: Likewise.
* testsuite/ld-i386/property-x86-ibt1a.d: Likewise.
* testsuite/ld-i386/property-x86-ibt1b.d: Likewise.
* testsuite/ld-i386/property-x86-ibt2.d: Likewise.
* testsuite/ld-i386/property-x86-ibt3a.d: Likewise.
* testsuite/ld-i386/property-x86-ibt3b.d: Likewise.
* testsuite/ld-i386/property-x86-ibt4.d: Likewise.
* testsuite/ld-i386/property-x86-ibt5.d: Likewise.
* testsuite/ld-i386/property-x86-shstk1a.d: Likewise.
* testsuite/ld-i386/property-x86-shstk1b.d: Likewise.
* testsuite/ld-i386/property-x86-shstk2.d: Likewise.
* testsuite/ld-i386/property-x86-shstk3a.d: Likewise.
* testsuite/ld-i386/property-x86-shstk3b.d: Likewise.
* testsuite/ld-i386/property-x86-shstk4.d: Likewise.
* testsuite/ld-i386/property-x86-shstk5.d: Likewise.
* testsuite/ld-x86-64/pr23372c-x32.d: Likewise.
* testsuite/ld-x86-64/pr23372c.d: Likewise.
* testsuite/ld-x86-64/pr23486c.d: Likewise.
* testsuite/ld-x86-64/pr23486d-x32.d: Likewise.
* testsuite/ld-x86-64/pr23486d.d: Likewise.
* testsuite/ld-x86-64/pr24322a-x32.d: Likewise.
* testsuite/ld-x86-64/pr24322a.d: Likewise.
* testsuite/ld-x86-64/pr24322b-x32.d: Likewise.
* testsuite/ld-x86-64/pr24322b.d: Likewise.
* testsuite/ld-x86-64/pr24458a-x32.d: Likewise.
* testsuite/ld-x86-64/pr24458a.d: Likewise.
* testsuite/ld-x86-64/pr24458b-x32.d: Likewise.
* testsuite/ld-x86-64/pr24458b.d: Likewise.
* testsuite/ld-x86-64/pr24458c-x32.d: Likewise.
* testsuite/ld-x86-64/pr24458c.d: Likewise.
* testsuite/ld-x86-64/property-1a.r: Likewise.
* testsuite/ld-x86-64/property-2a.r: Likewise.
* testsuite/ld-x86-64/property-3.r: Likewise.
* testsuite/ld-x86-64/property-3a.r: Likewise.
* testsuite/ld-x86-64/property-4.r: Likewise.
* testsuite/ld-x86-64/property-4a.r: Likewise.
* testsuite/ld-x86-64/property-5.r: Likewise.
* testsuite/ld-x86-64/property-5a.r: Likewise.
* testsuite/ld-x86-64/property-7a.r: Likewise.
* testsuite/ld-x86-64/property-x86-3-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-3.d: Likewise.
* testsuite/ld-x86-64/property-x86-4a-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-4a.d: Likewise.
* testsuite/ld-x86-64/property-x86-5-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-5.d: Likewise.
* testsuite/ld-x86-64/property-x86-cet1-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-cet1.d: Likewise.
* testsuite/ld-x86-64/property-x86-cet2a-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-cet2a.d: Likewise.
* testsuite/ld-x86-64/property-x86-cet5a-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-cet5a.d: Likewise.
* testsuite/ld-x86-64/property-x86-cet5b-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-cet5b.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt1a-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt1a.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt1b-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt1b.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt2-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt2.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt3a-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt3a.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt3b-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt3b.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt4-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt4.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt5-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-ibt5.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk1a-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk1a.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk1b-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk1b.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk2-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk2.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk3a-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk3a.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk3b-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk3b.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk4-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk4.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk5-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-shstk5.d: Likewise.
* testsuite/ld-i386/i386.exp: Run property-x86-6,
property-x86-isa1, property-x86-isa2 and property-x86-isa3.
* testsuite/ld-i386/property-x86-1.S: Updated to the current
GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED
values.
* testsuite/ld-i386/property-x86-2.S: Likewise.
* testsuite/ld-i386/property-x86-3.s: Likewise.
* testsuite/ld-x86-64/pr23372d.s: Likewise.
* testsuite/ld-x86-64/pr23372e.s: Likewise.
* testsuite/ld-x86-64/pr23372f.s: Likewise.
* testsuite/ld-x86-64/pr23486c.s: Likewise.
* testsuite/ld-x86-64/pr23486d.s: Likewise.
* testsuite/ld-x86-64/property-x86-1.S: Likewise.
* testsuite/ld-x86-64/property-x86-2.S: Likewise.
* testsuite/ld-x86-64/property-x86-3.s: Likewise.
* testsuite/ld-x86-64/property-x86-5a.s: Likewise.
* testsuite/ld-x86-64/property-x86-5b.s: Likewise.
* testsuite/ld-i386/property-x86-6.d: New file.
* testsuite/ld-i386/property-x86-isa1.d: Likewise.
* testsuite/ld-i386/property-x86-isa2.d: Likewise.
* testsuite/ld-i386/property-x86-isa3.d: Likewise.
* testsuite/ld-x86-64/property-x86-6-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-6.d: Likewise.
* testsuite/ld-x86-64/property-x86-6.s: Likewise.
* testsuite/ld-x86-64/property-x86-isa1-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-isa1.d: Likewise.
* testsuite/ld-x86-64/property-x86-isa1.s: Likewise.
* testsuite/ld-x86-64/property-x86-isa2-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-isa2.d: Likewise.
* testsuite/ld-x86-64/property-x86-isa3-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-isa3.d: Likewise.
* testsuite/ld-x86-64/simple.s: Likewise.
* ld/testsuite/ld-x86-64/x86-64.exp: Run property-x86-6,
property-x86-6-x32, property-x86-isa1, property-x86-isa1-x32,
property-x86-isa2, property-x86-isa2-x32, property-x86-isa3-x32
and property-x86-isa3.

4 years agoHandle void results as unformatted prints
Hannes Domani [Thu, 8 Oct 2020 15:38:32 +0000 (17:38 +0200)]
Handle void results as unformatted prints

When printing void results without any format letter, they are output
as expected:
(gdb) p $abcd
$1 = void
(gdb) p (void)10
$2 = void

But if any format letter (besides s) is used, it always outputs zero:
(gdb) p/x $abcd
$3 = 0x0
(gdb) p/x (void)10
$4 = 0x0

So this adds void results to the types handled like unformatted prints.

gdb/ChangeLog:

2020-10-09  Hannes Domani  <ssbssa@yahoo.de>

PR exp/26714
* printcmd.c (print_formatted): Handle void results as
unformatted prints.

gdb/testsuite/ChangeLog:

2020-10-09  Hannes Domani  <ssbssa@yahoo.de>

PR exp/26714
* gdb.base/printcmds.exp: Add tests for void results.

4 years agogdb: Delay releasing target_desc_up in more cases
Andrew Burgess [Thu, 8 Oct 2020 09:44:55 +0000 (10:44 +0100)]
gdb: Delay releasing target_desc_up in more cases

After commit:

  commit 51a948fdf0e14fb69ab9e0c79ae8b2415801f9a3
  Date:   Mon Jul 20 14:18:04 2020 +0100

      gdb: Have allocate_target_description return a unique_ptr

There were a few places where we could (should?) have delayed
releasing the target_desc_up until a little later.  This commit
catches these cases.

In the case of ARC, the target_desc_up is now exposed right out to
gdbserver, which means making a small change there too.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* arch/aarch32.c (aarch32_create_target_description): Release the
target_desc_up as late as possible.
* arch/aarch64.c (aarch64_create_target_description): Likewise.
* arch/amd64.c (amd64_create_target_description): Likewise.
* arch/arc.c (arc_create_target_description): Return a
target_desc_up, don't release it.
* arch/arc.h (arc_create_target_description): Update declaration.
(arc_lookup_target_description): Move target_desc_up into the
cache, and return a borrowed pointer.
* arch/arm.c (arm_create_target_description): Release the
target_desc_up as late as possible.
* arch/i386.c (i386_create_target_description): Likewise.
* arch/riscv.h (riscv_create_target_description): Update
declaration to match definition.
* arch/tic6x.c (tic6x_create_target_description): Release the
target_desc_up as late as possible.

gdbserver/ChangeLog:

* linux-arc-low.cc (arc_linux_read_description): Release the
unique_ptr returned from arc_create_target_description.

4 years agognulib: Ensure all libraries are used when building gdb/gdbserver
Andrew Burgess [Tue, 6 Oct 2020 09:09:06 +0000 (10:09 +0100)]
gnulib: Ensure all libraries are used when building gdb/gdbserver

An issue was reported here related to building GDB on MinGW:

  https://sourceware.org/pipermail/gdb/2020-September/048927.html

It was suggested here:

  https://sourceware.org/pipermail/gdb/2020-September/048931.html

that the solution might be to make use of $(LIB_GETRANDOM), a variable
defined in the gnulib makefile, when linking GDB.

In fact I think the issue is bigger than just LIB_GETRANDOM.  When
using the script binutils-gdb/gnulib/update-gnulib.sh to reimport
gnulib there is a lot of output from gnulib's gnulib-tool.  Part of
that output is this:

  You may need to use the following makefile variables when linking.
  Use them in <program>_LDADD when linking a program, or
  in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library.
    $(FREXPL_LIBM)
    $(FREXP_LIBM)
    $(INET_NTOP_LIB)
    $(LIBTHREAD)
    $(LIB_GETLOGIN)
    $(LIB_GETRANDOM)
    $(LIB_HARD_LOCALE)
    $(LIB_MBRTOWC)
    $(LIB_SETLOCALE_NULL)
    $(LTLIBINTL) when linking with libtool, $(LIBINTL) otherwise

What I think this is telling us is that we should be including the
value of all these variables on the link line for gdb and gdbserver.

The problem though is that these variables are define in gnulib's
makefile, but are not (necessarily) defined in GDB's makefile.

One solution would be to recreate the checks that gnulib performs in
order to recreate these variables in both gdb's and gdbserver's
makefile.  Though this shouldn't be too hard, most (if not all) of
these checks are in the form macros defined in m4 files in the gnulib
tree, so we could just reference these as needed.  However, in this
commit I propose a different solution.

Currently, in the top level makefile, we give gdb and gdbserver a
dependency on gnulib.  Once gnulib has finished building gdb and
gdbserver can start, these projects then have a hard coded (relative)
path to the compiled gnulib library in their makefiles.

In this commit I extend the gnulib configure script to install a new
makefile fragment in the gnulib build directory.  This new file will
have the usual variable substitutions applied to it, and so can
include the complete list (see above) of all the extra libraries that
are needed when linking against gnulib.

In fact the new makefile fragment defines three variables, these are:

LIBGNU: The path to the archive containing gnulib.  Can be used as a
       dependency as when this file changes gdb/gdbserver should be
       relinked.

LIBGNU_EXTRA_LIBS: A list of linker -l.... flags that should be
       included in the link line of gdb/gdbserver.  These are
       libraries that $(LIBGNU) depends on.  This list is taken from
       the output of gnulib-tool, which is run by our
       gnulib/update-gnulib.sh script.

INCGNU: A list of -I.... include paths that should be passed to the
       compiler, these are where the gnulib headers can be found.

Now both gdb and gdbserver can include the makefile fragment and make
use of these variables.

The makefile fragment relies on the variable GNULIB_BUILDDIR being
defined.  This is checked for in the fragment, and was already defined
in the makefiles of gdb and gdbserver.

gdb/ChangeLog:

* Makefile.in: Include Makefile.gnulib.inc.  Don't define LIBGNU
or INCGNU.  Make use of LIBGNU_EXTRA_LIBS when linking.

gdbserver/ChangeLog:

* Makefile.in: Include Makefile.gnulib.inc.  Don't define LIBGNU
or INCGNU.  Make use of LIBGNU_EXTRA_LIBS when linking.

gnulib/ChangeLog:

* Makefile.gnulib.inc.in: New file.
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Install the new file.

4 years agoNotify observers that directories have changed when using "directory" CLI command
Jan Vrany [Fri, 9 Oct 2020 05:47:30 +0000 (06:47 +0100)]
Notify observers that directories have changed when using "directory" CLI command

gdb/ChangeLog

* source.c (directory_command): Notify observers that "directories"
parameter has changed.

gdb/testsuite/ChangeLog

* gdb.mi/mi-cmd-param-changed.exp: Check that notification is
is emmited for both 'set directories' and 'directory' commands.

4 years agoStyle more output of "disassemble" command
Tom Tromey [Fri, 9 Oct 2020 01:41:45 +0000 (19:41 -0600)]
Style more output of "disassemble" command

I noticed a couple of spots where the "disassemble" could style its
output, but currently does not.  This patch adds styling to the
function name at the start of the disassembly, and any addresses
printed there.

gdb/ChangeLog
2020-10-08  Tom Tromey  <tom@tromey.com>

* cli/cli-cmds.c (print_disassembly): Style function name and
addresses.  Add _() wrappers.

gdb/testsuite/ChangeLog
2020-10-08  Tom Tromey  <tom@tromey.com>

* gdb.base/style.exp: Check that "main"'s name is styled.

4 years agoAutomatic date update in version.in
GDB Administrator [Fri, 9 Oct 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogold: Update testsuite/split_[i386|x32|x86_64].sh
H.J. Lu [Thu, 8 Oct 2020 11:54:26 +0000 (04:54 -0700)]
gold: Update testsuite/split_[i386|x32|x86_64].sh

Update testsuite/split_i386.sh, testsuite/split_x32.sh and
testsuite/split_x86_64.sh for

commit f9ff65d4dffbaf342dce7a8760059c27683cd962
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Oct 8 10:27:43 2020 +1030

    [GOLD] Increase --split-stack-adjust-size

* testsuite/split_i386.sh: Updated for --split-stack-adjust-size
default change.
* testsuite/split_x32.sh: Likewise.
* testsuite/split_x86_64.sh: Likewise.