]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
6 months ago[wip] Fix range end handling of inlined subroutines users/aburgess/gdb-opt-code-debug
Bernd Edlinger [Mon, 2 Sep 2024 15:00:12 +0000 (17:00 +0200)] 
[wip] Fix range end handling of inlined subroutines

Currently there is a problem when debugging
optimized code when the inferior stops at an inline
sub-range end PC.  It is unclear if that location
is from the inline function or from the calling
function.  Therefore the call stack is often
wrong.

This patch detects the "weak" line table entries
which are likely part of the previous inline block,
and if we have such a location, it assumes the
location belongs to the previous block.

Additionally it may happen that the infrun machinery
steps from one inline range to another inline range
of the same inline function.  That can look like
jumping back and forth from the calling program
to the inline function, while really the inline
function just jumps from a hot to a cold section
of the code, i.e. error handling.

Additionally it may happen that one inline sub-range
is empty or the inline is completely empty.  But
filtering that information away is not the right
solution, since although there is no actual code
from the inline, it is still possible that variables
from an inline function can be inspected here.

The issue with the empty ranges is also discussed here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94474

Conceptually this patch uses a heuristic to work around
a deficiency in the dwarf-4 and dwarf-5 rnglists structure.
There should be a location view number for each inline
sub-range begin PC and end PC, similar to the DW_AT_GNU_entry_view
which is the location view for the inline entry point.

6 months ago[wip] Introduce a new line table flag is_weak
Bernd Edlinger [Mon, 2 Sep 2024 14:58:51 +0000 (16:58 +0200)] 
[wip] Introduce a new line table flag is_weak

This introduces a new line table flag is_weak.
The line entries at the end of a subroutine range,
use this to indicate that they may possibly
be part of the previous subroutine.

When there is a sequence of line entries at the
same address where an inline range ends, and the
last item has is_stmt = 0, we force all previous
items to have is_weak = 1.

Additionally this adds a "fake" end sequence to the
record_line function, that is line number -1.
That will be used in the next patch.

Finally this adds a handling for empty ranges to
record_block_range.  Currently this function is
not called with empty ranges, but that will be used
in the next patch.

There should be no functional changes after this commit.

Well, except the new is-weak flag in the line table of course.
As an example consider the following test code:

$ cat test.c
inline int test ()
{
  asm ("nop");
  return 0;
}

int main ()
{
  int x = test ();
  return x;
}
$ gcc -g -O2 test.c

This will receive the following line table:

(gdb) maintenance info line-table
INDEX  LINE   REL-ADDRESS        UNREL-ADDRESS      IS-STMT IS-WEAK PROLOGUE-END EPILOGUE-BEGIN
0      8      0x0000555555555040 0x0000000000001040 Y
1      9      0x0000555555555040 0x0000000000001040 Y
2      1      0x0000555555555040 0x0000000000001040 Y
3      3      0x0000555555555040 0x0000000000001040 Y
4      4      0x0000555555555041 0x0000000000001041 Y       Y
5      4      0x0000555555555041 0x0000000000001041         Y  <---+ set is_weak
6      10     0x0000555555555041 0x0000000000001041 Y       Y      ^
7      11     0x0000555555555041 0x0000000000001041           <----+ no is-stmt
8      END    0x0000555555555044 0x0000000000001044 Y

6 months ago[wip] gdb/testsuite: all the optimised code test cases
Andrew Burgess [Thu, 19 Sep 2024 13:41:16 +0000 (14:41 +0100)] 
[wip] gdb/testsuite: all the optimised code test cases

All the test cases pulled from this series:

  https://inbox.sourceware.org/gdb-patches/AS1PR01MB946510286FBF2497A6F03E83E4922@AS1PR01MB9465.eurprd01.prod.exchangelabs.com

Rebased on top of current HEAD.  Some of these tests are probably
duplicates of tests that have been upstreamed into other locations,
e.g. see recent additions to gdb.opt/

Also, I moved these tests into their own commit to make it easier for
me to move them between branches for testing, but when it comes to
upstreaming, these tests should be merged into the appropriate GDB
related commit, and not left as a commit on their own.

6 months agogdb: improve line number lookup around inline functions
Andrew Burgess [Fri, 26 Jul 2024 15:32:33 +0000 (16:32 +0100)] 
gdb: improve line number lookup around inline functions

This commit aims to fix an issue where GDB would report the wrong line
for frames other than #0 if a previous frame had just left an inline
function.

Consider this example which is compiled at -Og:

  volatile int global = 0;

  static inline int bar (void) { asm (""); return 1; }

  static void foo (int count)
  { global += count; }

  int main (void)
  {
    foo (bar ());
    return 0;
  }

Used in this GDB session:

  (gdb) break foo
  Breakpoint 1 at 0x401106: file test.c, line 6.
  (gdb) run
  Starting program: /tmp/inline-bt/test.x

  Breakpoint 1, foo (count=count@entry=1) at test.c:6
  6 { global += count; }
  (gdb) frame 1
  #1  0x0000000000401121 in main () at test.c:3
  3 static inline int bar (void) { asm (""); return 1; }

Notice that GDB incorrectly reports frame #1 as being at line 3 when
it should really be reporting this line:

  foo (bar ());

The cause of this problem is in find_pc_sect_line (symtab.c).  This
function is passed a PC for which GDB must find the symtab_and_line
information.  The function can be called in two modes based on the
NOTCURRENT argument.

When NOTCURRENT is false then we are looking for information about the
current PC, i.e. the PC at which the inferior is currently stopped
at.

When NOTCURRENT is true we are looking for information about a PC that
it not the current PC, but is instead the PC for a previous frame.
The interesting thing in this case is that the PC passed in will be
the address after the address we actually want to lookup information
for, this is because as we unwind the program counter from frame #0
what we get is the return address in frame #1.  The return address is
often (or sometimes) on the line after the calling line, and so in
find_pc_sect_line, when NOTCURRENT is true, we subtract 1 from PC and
then proceed as normal looking for information about this new PC
value.

Now lets look at the x86-64 disassembly for 'main' from the above
example.  The location marker (=>) represents the return address in
'main' after calling 'foo':

  (gdb) run
  Starting program: /tmp/inline-bt/test.x

  Breakpoint 1, foo (count=count@entry=1) at test.c:6
  6 { global += count; }
  #0  foo (count=count@entry=1) at test.c:6
  #1  0x000000000040111f in main () at test.c:3
  (gdb) up
  #1  0x000000000040111f in main () at test.c:3
  3 static inline int bar (void) { asm (""); return 1; }
  (gdb) disassemble
  Dump of assembler code for function main:
     0x0000000000401115 <+0>: mov    $0x1,%edi
     0x000000000040111a <+5>: call   0x401106 <foo>
  => 0x000000000040111f <+10>: mov    $0x0,%eax
     0x0000000000401124 <+15>: ret
  End of assembler dump.

And the corresponding line table:

  (gdb) maintenance info line-table
  objfile: /tmp/inline-bt/test.x ((struct objfile *) 0x59405a0)
  compunit_symtab: test.c ((struct compunit_symtab *) 0x53ad320)
  symtab: /tmp/inline-bt/test.c ((struct symtab *) 0x53ad3a0)
  linetable: ((struct linetable *) 0x53adc90):
  INDEX  LINE   REL-ADDRESS        UNREL-ADDRESS      IS-STMT PROLOGUE-END EPILOGUE-BEGIN
  0      6      0x0000000000401106 0x0000000000401106 Y
  1      6      0x0000000000401106 0x0000000000401106 Y
  2      6      0x0000000000401106 0x0000000000401106
  3      6      0x0000000000401114 0x0000000000401114
  4      9      0x0000000000401115 0x0000000000401115 Y
  5      10     0x0000000000401115 0x0000000000401115 Y
  6      3      0x0000000000401115 0x0000000000401115 Y
  7      3      0x0000000000401115 0x0000000000401115 Y
  8      3      0x0000000000401115 0x0000000000401115 Y
  9      10     0x0000000000401115 0x0000000000401115
  10     11     0x000000000040111f 0x000000000040111f Y
  11     12     0x000000000040111f 0x000000000040111f
  12     END    0x0000000000401125 0x0000000000401125 Y

When looking for the line information of frame #1 we start with the
return address 0x40111f, however, as this is not the current program
counter value we subtract one and look for line information for
0x40111e.

We will find the entry at index 9, this is the last entry with an
address less than the address we're looking for, the next entry has an
address greater than the one we're looking for.  The entry at index 9
is for line 10 which is the correct line, but GDB reports line 3, so
what's going on?

Having found a matching entry GDB checks to see if the entry is marked
as is-stmt (is statement).  In our case index 9 (line 10) is not a
statement, and so GDB looks backwards for entries at the same address,
if any of these are marked is-stmt then GDB will use the last of these
instead.  In our case the previous entry at index 8 is marked is-stmt,
and so GDB uses that.  The entry at index 8 is for line 3, and that is
why GDB reports the wrong line.  So why perform the backward is-stmt
check?

When NOTCURRENT is false (not our case) the backward scan makes
sense.  If the inferior has just stopped at some new location, and we
want to report that location to the user, then it is better (I think)
to select an is-stmt entry.  In this way we will report a line number
for a line which the inferior is just about to start executing, and
non of the side effects of that line have yet taken place.  The line
GDB prints will correspond with the reported line, and if the user
queries the inferior state, the inferior should (assuming the compiler
emitted correct is-stmt markers) correspond to the line in question
having not yet been started.

However, in our case NOTCURRENT is true.  We're looking back to
previous frames that are currently in-progress.  If upon return to the
previous frame we are about to execute the next line then (is seems to
me) that this indicates we must be performing the very last action
from the previous line.  As such, looking back through the line table
in order to report a line that has not yet started is the wrong thing
to do.  We really want to report the very last line table entry for
the previous address as this is (I think) most likely to represent the
previous line that is just about to complete.

Further, in the NOTCURRENT case, we should care less about reporting
an is-stmt line.  When a user looks back to a previous frame I don't
think they expect the line being reported to have not yet started.  In
fact I think the expectation is the reverse ... after all, the
previous line must have executed enough to call the current frame.

So my proposal is that the backward scan of the line table looking for
an is-stmt entry should not be performed when NOTCURRENT is true.  In
the case above this means we will report the entry at index 9, which
is for line 10, which is correct.

For testing this commit I have:

 1. Extended the existing gdb.opt/inline-bt.exp test.  I've extended
 the source code to include a test similar to the example above.  I
 have also extended the script so that the test is compiled at a
 variety of optimisation levels (O0, Og, O1, O2).

 2. Added a new DWARF assembler test which hard codes a line table
 similar to the example given above.  My hope is that even if test
 case (1) changes (due to compiler changes) this test will continue to
 test the specific case I'm interested in.

I have tested the gdb.opt/inline-bt.exp test with gcc versions 8.4.0,
9.3.1, 10.5.0, 11.5.0, 12.2.0, and 14.2.0, in each case the test will
fail (with the expected error) without this patch applied, and will
pass with this patch applied.

I was inspired to write this patch while reviewing these patches:

  https://inbox.sourceware.org/gdb-patches/AS8P193MB1285C58F6F09502252CEC16FE4DF2@AS8P193MB1285.EURP193.PROD.OUTLOOK.COM
  https://inbox.sourceware.org/gdb-patches/AS8P193MB12855708DFF59A5309F5B19EE4DF2@AS8P193MB1285.EURP193.PROD.OUTLOOK.COM

though this patch only covers one of the issues addressed by these
patches, and the approach taken is quite different.  Still, those
patches are worth reading for the history of this fix.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25987

6 months agogdb: handle empty ranges for inline subroutines
Andrew Burgess [Fri, 20 Sep 2024 12:56:27 +0000 (13:56 +0100)] 
gdb: handle empty ranges for inline subroutines

The work in this patch is based on changes found in this series:

  https://inbox.sourceware.org/gdb-patches/AS1PR01MB946510286FBF2497A6F03E83E4922@AS1PR01MB9465.eurprd01.prod.exchangelabs.com

That series has the fixes here merged along with other changes, and
takes a different approach for how to handle the issue addressed here.

Credit for identifying the original issue belongs with Bernd, the
author of the original patch, who I have included as a co-author on
this patch.  A brief description of how the approach taken in this
patch differs from the approach Bernd took can be found at the end of
this commit message.

When compiling with optimisation, it can often happen that gcc will
emit an inline function instance with an empty range associated.  This
can happen in two ways.  The inline function might have a DW_AT_low_pc
and DW_AT_high_pc, where the high-pc is an offset from the low-pc, but
the high-pc offset is given as 0 by gcc.

Alternatively, the inline function might have a DW_AT_ranges, and one
of the sub-ranges might be empty, though usually in this case, other
ranges will be non-empty.

The second case is made worse in that sometimes gcc will specify a
DW_AT_entry_pc value which points to the address of the empty
sub-range.

My understanding of the DWARF spec is that empty ranges as seen in
these examples indicate that no instructions are associated with the
inline function, and indeed, this is how GDB handles these cases,
rejecting blocks and sub-ranges which are empty.

  DWARF-5, 2.17.2, Contiguous Address Range:
    The value of the DW_AT_low_pc attribute is the address of the
    first instruction associated with the entity. If the value of the
    DW_AT_high_pc is of class address, it is the address of the first
    location past the last instruction associated with the entity...

  DWARF-5, 2.17.3, Non-Contiguous Address Ranges:
    A bounded range entry whose beginning and ending address offsets
    are equal (including zero) indicates an empty range and may be
    ignored.

As a consequence, an attempt by the user to place a breakpoint on an
inline function with an empty low/high address range will trigger
GDB's pending breakpoint message:

  (gdb) b foo
  Function "foo" not defined.
  Make breakpoint pending on future shared library load? (y or [n]) n

While, having the entry-pc point at an empty range forces GDB to
ignore the given entry-pc and select a suitable alternative.

If instead of ignoring these empty ranges, we instead teach GDB to
treat these as non-empty, what we find is that, in all the cases I've
seen, the debug experience is improved.

As a minimum, in the low/high case, GDB now knows about the inline
function, and can place breakpoints that will be hit.  Further, in
most cases, local variables from the inline function can be accessed.

If we do start treating empty address ranges as non-empty then we are
deviating from the DWARF spec.  It is not clear if we are working
around a gcc bug (I suspect so), or if gcc actually considers the
inline function gone, and we're just getting lucky that the debug
experience seems improved.

My proposed strategy for handling these empty address ranges is to
only perform this work around if the compiler is gcc, so far I've not
seen this issue with Clang (the only other compiler I've tested),
though extending this to other compilers in the future would be
trivial.

Additionally, I only apply the work around for
DW_TAG_inlined_subroutine DIEs, as I've only seen the issue for
inline functions.

If we find a suitable empty address range then the fix-up is to give
the address range a length of 1 byte.

Now clearly, in most cases, 1 byte isn't even going to cover a single
instruction, but so far this doesn't seem to be a problem. An
alternative to using a 1-byte range would be to try and disassemble
the code at the given address, calculate the instruction length, and
use that, the length of one instruction.  But this means that the
DWARF parser now needs to make use of the disassembler, which feels
like a big change that I'd rather avoid if possible.

The other alternative is to allow blocks to be created with zero
length address ranges and then change the rest of GDB to allow for
lookup of zero sized blocks to succeed.  This is the approach taken by
the original patch series that I linked above.

The results achieved by the original patch are impressive, and Bernd,
the original patch author, makes a good argument that at least some of
the problems relating to empty ranges are a result of deficiencies in
the DWARF specification rather than issues with gcc.

However, I remain unconvinced.  But even if I accept that the issue is
with DWARF itself rather than gcc, the question still remains; should
we fix the problem by synthesising new DWARF attributes and/or accept
non-standard DWARF during the dwarf2/read.c phase, and then update GDB
to handle the new reality, or should we modify the incoming DWARF as
we read it to make it fit GDB's existing algorithms.

The original patch, I believe, took the former approach, while I
favour the later, and so, for now, I propose that the single byte
range proposal is good enough, at least until we find counter examples
where this doesn't work.

This leaves just one question: what about the remaining work in the
original patch.  That work deals with problems around the end address
of non-empty ranges.  The original patch handled that case using the
same algorithm changes, which is neat, but I think there are
alternative solutions that should be investigated.  If the
alternatives don't end up working out, then it's trivial to revert
this patch in the future and adopt the original proposal.

For testing I have two approaches, C/C++ test compiled with
optimisation that show the problems discussed.  These are good because
they show that these issues do crop up in compiled code.  But they are
bad in that the next compiler version might change the way the test is
optimised such that the problem no longer shows.

And so I've backed up the real code tests with DWARF assembler tests
which reproduce each issue.

The DWARF assembler tests are not really impacted by which gcc version
is used, but I've run all of these tests using gcc versions 8.4.0,
9.5.0, 10.5.0, 11.5.0, 12.2.0, and 14.2.0.  I see failures in all of
the new tests when using an unpatched GDB, and no failures when using
a patched GDB.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25987
Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de>
6 months agogdb: fix comment for gdbarch_stack_grows_down
Andrew Burgess [Tue, 3 Dec 2024 10:38:03 +0000 (10:38 +0000)] 
gdb: fix comment for gdbarch_stack_grows_down

The comment for gdbarch_stack_grows_down was wrong.  Fixed in this
commit.

There should be no user visible changes after this commit.

6 months agogas: partly restore how current_location() had worked
Jan Beulich [Tue, 3 Dec 2024 09:48:16 +0000 (10:48 +0100)] 
gas: partly restore how current_location() had worked

Commit 4a826962e760 changed its behavior without saying why, and without
putting in place any testcase demonstrating the required behavior.
Firmly latch the current position unless deferred-evaluation mode is in
effect.

6 months agoMMIX: use current_location() directly
Jan Beulich [Tue, 3 Dec 2024 09:47:53 +0000 (10:47 +0100)] 
MMIX: use current_location() directly

It's no longer a static function, so it can be used without involving a
wrapper function plus an indirect function call.

6 months agogas: streamline expr_build_dot()
Jan Beulich [Tue, 3 Dec 2024 09:47:36 +0000 (10:47 +0100)] 
gas: streamline expr_build_dot()

There's no point involving symbol_clone_if_forward_ref(), just for it to
replace dot_symbol by one obtained from symbol_temp_new_now(). For the
abs-section case also produce a slightly more "complete" (as in: all
potentially relevant fields filled) expression by going through
expr_build_uconstant().

Move the function next to current_location(), for it to be easier to see
the (dis)similarities. Correct the function's comment while there.

6 months agoSupport Intel AVX10.2 BF16 instructions
Kong Lingling [Tue, 3 Dec 2024 07:34:05 +0000 (15:34 +0800)] 
Support Intel AVX10.2 BF16 instructions

In this patch, we will support AVX10.2 BF16 instructions. All of them
are new instructions forms. In current documentation, it is still
VSCALEFPBF16, but it will change to VSCALEFNEPBF16 eventually.

In disassembler part, we added %XB to reduce W table pass since all
of them get evex.w=0.

gas/Changelog:

* testsuite/gas/i386/i386.exp: Add AVX10.2 tests.
* testsuite/gas/i386/x86-64.exp: Ditto.
* testsuite/gas/i386/avx10_2-256-bf16-intel.d: New.
* testsuite/gas/i386/avx10_2-256-bf16.d: Ditto.
* testsuite/gas/i386/avx10_2-256-bf16.s: Ditto.
* testsuite/gas/i386/avx10_2-512-bf16-intel.d: Ditto.
* testsuite/gas/i386/avx10_2-512-bf16.d: Ditto.
* testsuite/gas/i386/avx10_2-512-bf16.s: Ditto.
* testsuite/gas/i386/x86-64-avx10_2-256-bf16-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx10_2-256-bf16.d: Ditto.
* testsuite/gas/i386/x86-64-avx10_2-256-bf16.s: Ditto.
* testsuite/gas/i386/x86-64-avx10_2-512-bf16-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx10_2-512-bf16.d: Ditto.
* testsuite/gas/i386/x86-64-avx10_2-512-bf16.s: Ditto.

opcodes/

* i386-dis-evex-prefix.h: Update PREFIX_EVEX_0F3A08, PREFIX_EVEX_0F3A26,
PREFIX_EVEX_0F3A56, PREFIX_EVEX_0F3A66, PREFIX_EVEX_0F3AC2,
PREFIX_EVEX_MAP5_2F, PREFIX_EVEX_MAP5_51, PREFIX_EVEX_MAP5_58,
PREFIX_EVEX_MAP5_59, PREFIX_EVEX_MAP5_5C, PREFIX_EVEX_MAP5_5D,
PREFIX_EVEX_MAP5_5E, PREFIX_EVEX_MAP5_5F.
Add PREFIX_EVEX_MAP6_2C, PREFIX_EVEX_MAP6_4C, PREFIX_EVEX_MAP6_4E,
PREFIX_EVEX_MAP6_98, PREFIX_EVEX_MAP6_9A, PREFIX_EVEX_MAP6_9C,
PREFIX_EVEX_MAP6_9E, PREFIX_EVEX_MAP6_A8, PREFIX_EVEX_MAP6_AA,
PREFIX_EVEX_MAP6_AC, PREFIX_EVEX_MAP6_AE, PREFIX_EVEX_MAP6_B8,
PREFIX_EVEX_MAP6_BA, PREFIX_EVEX_MAP6_BC, PREFIX_EVEX_MAP6_BE.
* i386-dis-evex.h (evex_table): Update PREFIX_EVEX_MAP6_2C,
PREFIX_EVEX_MAP6_42, PREFIX_EVEX_MAP6_4C, PREFIX_EVEX_MAP6_4E,
PREFIX_EVEX_MAP6_98, PREFIX_EVEX_MAP6_9A, PREFIX_EVEX_MAP6_9C,
PREFIX_EVEX_MAP6_9E, PREFIX_EVEX_MAP6_A8, PREFIX_EVEX_MAP6_AA,
PREFIX_EVEX_MAP6_AC, PREFIX_EVEX_MAP6_AE, PREFIX_EVEX_MAP6_B8,
PREFIX_EVEX_MAP6_BA, PREFIX_EVEX_MAP6_BC, PREFIX_EVEX_MAP6_BE.
* i386-dis.c (PREFIX_EVEX_MAP6_2C): New enum.
(PREFIX_EVEX_MAP6_42): Ditto.
(PREFIX_EVEX_MAP6_4C): Ditto.
(PREFIX_EVEX_MAP6_4E): Ditto.
(PREFIX_EVEX_MAP6_98): Ditto.
(PREFIX_EVEX_MAP6_9A): Ditto.
(PREFIX_EVEX_MAP6_9C): Ditto.
(PREFIX_EVEX_MAP6_9E): Ditto.
(PREFIX_EVEX_MAP6_A8): Ditto.
(PREFIX_EVEX_MAP6_AA): Ditto.
(PREFIX_EVEX_MAP6_AC): Ditto.
(PREFIX_EVEX_MAP6_AE): Ditto.
(PREFIX_EVEX_MAP6_B8): Ditto.
(PREFIX_EVEX_MAP6_BA): Ditto.
(PREFIX_EVEX_MAP6_BC): Ditto.
(PREFIX_EVEX_MAP6_BE): Ditto.
(putop): Handle %XB.
* i386-opc.tbl: Add AVX10.2 instructions.
* i386-mnem.h: Regenerated.
* i386-tbl.h: Ditto.

Co-authored-by: Haochen Jiang <haochen.jiang@intel.com>
6 months agoAutomatic date update in version.in
GDB Administrator [Tue, 3 Dec 2024 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

6 months agogdb/configure.ac: remove elf_hp.h check
Simon Marchi [Mon, 2 Dec 2024 16:42:10 +0000 (11:42 -0500)] 
gdb/configure.ac: remove elf_hp.h check

The comment says this is for HP/UX, which is no longer supported.  There
should be no functional changes with this, since nothing checks
HAVE_ELF_HP_H.

Change-Id: Ie897fc64638c9fea28463e1bf69e450c3673fd84

6 months agogdb, gdbserver, gdbsupport: flatten and sort some list in configure files
Simon Marchi [Mon, 2 Dec 2024 15:35:23 +0000 (10:35 -0500)] 
gdb, gdbserver,  gdbsupport: flatten and sort some list in configure files

This makes the lists easier sort read and modify.  There are no changes
in the generated config.h files, so I'm confident this brings no
functional changes.

Change-Id: Ib6b7fc532bcd662af7dbb230070fb1f4fc75f86b

6 months agoaarch64: add tests for combinations of GCS options and marked/unmarked inputs
Matthieu Longo [Thu, 7 Nov 2024 13:13:20 +0000 (13:13 +0000)] 
aarch64: add tests for combinations of GCS options and marked/unmarked inputs

6 months agoaarch64: add tests to check the correct merge of the GCS feature with others.
Matthieu Longo [Thu, 7 Nov 2024 10:33:45 +0000 (10:33 +0000)] 
aarch64: add tests to check the correct merge of the GCS feature with others.

6 months agoaarch64: GCS feature check in GNU note properties for input objects
Srinath Parvathaneni [Mon, 28 Oct 2024 18:13:08 +0000 (18:13 +0000)] 
aarch64: GCS feature check in GNU note properties for input objects

This patch adds support for Guarded Control Stack in AArch64 linker.

This patch implements the following:
1) Defines GNU_PROPERTY_AARCH64_FEATURE_1_GCS bit for GCS in
GNU_PROPERTY_AARCH64_FEATURE_1_AND macro.

2) Adds readelf support to read and print the GCS feature in GNU
properties in AArch64.

Displaying notes found in: .note.gnu.property
[      ]+Owner[        ]+Data size[    ]+Description
  GNU                  0x00000010      NT_GNU_PROPERTY_TYPE_0
      Properties: AArch64 feature: GCS

3) Adds support for the "-z gcs" linker option and document all the values
allowed with this option (-z gcs[=always|never|implicit]) where "-z gcs" is
equivalent to "-z gcs=always". When '-z gcs' option is omitted from the
command line, it defaults to "implicit" and relies on the GCS feature
marking in GNU properties.

4) Adds support for the "-z gcs-report" linker option and document all the
values allowed with this option (-z gcs-report[=none|warning|error]) where
"-z gcs-report" is equivalent to "-z gcs-report=warning". When this option
is omitted from the command line, it defaults to "warning".

The ABI changes adding GNU_PROPERTY_AARCH64_FEATURE_1_GCS to the GNU
property GNU_PROPERTY_AARCH64_FEATURE_1_AND is merged into main and
can be found in [1].

[1] https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst

Co-authored-by: Matthieu Longo <matthieu.longo@arm.com>
Co-authored-by: Yury Khrustalev <yury.khrustalev@arm.com>
6 months agoaarch64: rename BTI error/warning message
Matthieu Longo [Thu, 7 Nov 2024 14:33:09 +0000 (14:33 +0000)] 
aarch64: rename BTI error/warning message

The previous message for missing BTI feature in GNU properties was
not very clear. The new message explains that a missing GNU property
marking is lacking on this specific input.

6 months agoaarch64: delete duplicated BTI tests
Matthieu Longo [Mon, 2 Dec 2024 09:44:54 +0000 (09:44 +0000)] 
aarch64: delete duplicated BTI tests

6 months agoaarch64: improve test coverage for combination of BTI options
Matthieu Longo [Mon, 2 Dec 2024 09:46:21 +0000 (09:46 +0000)] 
aarch64: improve test coverage for combination of BTI options

6 months agoaarch64: limit number of reported issues on missing GNU properties
Matthieu Longo [Tue, 5 Nov 2024 13:22:31 +0000 (13:22 +0000)] 
aarch64: limit number of reported issues on missing GNU properties

This patch attempts to make the linker output more friendly for the
developers by limiting the number of emitted warning/error messages
related to BTI issues.

Every time an error/warning related to BTI is emitted, the logger
also increments the BTI issues counter. A batch of errors/warnings is
limited to a maximum of 20 explicit errors/warnings. At the end of
the merge, a summary of the total of errors/warning is given if the
number exceeds the limit of 20 invidual messages.

6 months agoaarch64: bugfix when finding 1st bfd input with GNU property
Matthieu Longo [Wed, 6 Nov 2024 17:59:46 +0000 (17:59 +0000)] 
aarch64: bugfix when finding 1st bfd input with GNU property

The current implementation of searching the first input BFD with GNU
properties has a bug. The search was not filtering on object inputs
belonging to the output link unit only, but was also including dynamic
objects, BFD plugins, and linker-created files.
This means that the initial initialization of the output properties
were skewed, and warnings on input files that should have been emitted
were not.

This patch fixes the filtering to exclude the object input files not
belonging to the output link unit, not having the same ELF class, and
not the same target architecture.

6 months agoaarch64: remove early exit when setting up GNU properties with partial linking
Matthieu Longo [Thu, 14 Nov 2024 17:35:24 +0000 (17:35 +0000)] 
aarch64: remove early exit when setting up GNU properties with partial linking

There is an early exit in _bfd_aarch64_elf_link_setup_gnu_properties
that is enabled when the output link unit is relocatable, i.e. ld
generates an output file that can in turn serve as input to ld. (see
ld manual, -r,--relocatable for more details).

At this stage, the GNU properties have already been merged and errors
or warnings (if any) have already been issued. However, OUTPROP has
not been updated yet.
Not updating OUTPROP means that implicits enablement of BTI PLTs via
the GNU properties will be ignored for final links. Indeed, the
enablement of BTI PLTs is checked inside _bfd_aarch64_add_call_stub_entries
by looking up at gnu_property_aarch64_feature_1_and (OUTPROP).
Since the final link does not happen in the case of partial linking,
the behaviour with or without the early exit should be the same.

Given that there is currently no comment for explain why the exit is
there, and that there might in the future be cases were these properties
affect relocatable links, it is preferrable to drop the early exit.

6 months agoaarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 5)
Matthieu Longo [Thu, 14 Nov 2024 17:34:04 +0000 (17:34 +0000)] 
aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 5)

Use _bfd_aarch64_elf_check_bti_report to report any BTI issue on the
first input object.

6 months agoaarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 4)
Matthieu Longo [Thu, 14 Nov 2024 17:08:27 +0000 (17:08 +0000)] 
aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 4)

Move the code related to the creation of the gnu.note section to a
separate function: _bfd_aarch64_elf_create_gnu_property_section

6 months agoaarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 3)
Matthieu Longo [Thu, 14 Nov 2024 16:56:27 +0000 (16:56 +0000)] 
aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 3)

Move the code related to the search of the first bfd input with GNU
properties to a separate function:
_bfd_aarch64_elf_find_1st_bfd_input_with_gnu_property

6 months agoaarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 2)
Matthieu Longo [Thu, 14 Nov 2024 16:51:46 +0000 (16:51 +0000)] 
aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 2)

Simplify this for-loop with too many "break" instructions inside.

6 months agoaarch64: refactoring _bfd_aarch64_elf_check_bti_report
Matthieu Longo [Thu, 28 Nov 2024 23:21:05 +0000 (23:21 +0000)] 
aarch64: refactoring _bfd_aarch64_elf_check_bti_report

Before this patch, warnings were reported normally, and errors
(introduced by a previous patch adding '-z bti-report' option)
were logged as error but were not provoking a link failure.
The root of the issue was a misuse of _bfd_error_handler to
report the errors.
Replacing _bfd_error_handler by info->callbacks->einfo, with the
addition of the formatter '%X' for errors fixed the issue.

6 months agoaarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 1)
Matthieu Longo [Thu, 14 Nov 2024 16:41:05 +0000 (16:41 +0000)] 
aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 1)

Exposing the output GNU property as a parameter of
_bfd_aarch64_elf_link_setup_gnu_properties seems to break the
encapsulation. The output GNU property update should be part of the
function that sets up the GNU properties.
This patch removes the parameter, and perform the update of the GNU
property on the output object inside the function.

6 months agoaarch64: rename gnu_and_prop to gnu_property_aarch64_feature_1_and
Matthieu Longo [Thu, 14 Nov 2024 16:12:05 +0000 (16:12 +0000)] 
aarch64: rename gnu_and_prop to gnu_property_aarch64_feature_1_and

6 months agoaarch64: simplify condition in elfNN_aarch64_merge_gnu_properties
Matthieu Longo [Thu, 28 Nov 2024 15:36:51 +0000 (15:36 +0000)] 
aarch64: simplify condition in elfNN_aarch64_merge_gnu_properties

The current condition used to check if a GNU feature property is set
on an input object before the merge is a bit confusing.

  (aprop && !<something about aprop>) || !aprop

It seems easier to understand if it is changed as follows:

  (!aprop || !<something about aprop>)

6 months agoaarch64: rename parameter of _bfd_aarch64_elf_merge_gnu_properties
Matthieu Longo [Thu, 14 Nov 2024 16:05:27 +0000 (16:05 +0000)] 
aarch64: rename parameter of _bfd_aarch64_elf_merge_gnu_properties

The current naming of the AArch64 feature GNU property of the output bfd
does not reflect what it is. This patch renames it from "prop" to
"outprop".

6 months agoaarch64: update ld documentation with bti and pac options
Matthieu Longo [Fri, 8 Nov 2024 23:06:16 +0000 (23:06 +0000)] 
aarch64: update ld documentation with bti and pac options

6 months agoaarch64: use only one type for feature marking report
Matthieu Longo [Thu, 28 Nov 2024 11:13:23 +0000 (11:13 +0000)] 
aarch64: use only one type for feature marking report

6 months agoaarch64: group software protection options under a same struct.
Matthieu Longo [Mon, 28 Oct 2024 18:12:38 +0000 (18:12 +0000)] 
aarch64: group software protection options under a same struct.

- declare a new struc aarch_protection_opts to store all the
  configuration options related to software protections (i.e. bti-plt,
  pac-plt, bti-report level).
- add a new option "-z bti-report" to configure the log level of reported
  issues when BTI PLT is forced.
- encapsulate the BTI report inside _bfd_aarch64_elf_check_bti_report.

6 months agoaarch64: adapt BTI tests to use selectable GNU properties
Matthieu Longo [Sat, 30 Nov 2024 10:27:41 +0000 (10:27 +0000)] 
aarch64: adapt BTI tests to use selectable GNU properties

6 months agoaarch64: adapt bti-far* tests to use selectable GNU properties
Matthieu Longo [Fri, 29 Nov 2024 15:26:16 +0000 (15:26 +0000)] 
aarch64: adapt bti-far* tests to use selectable GNU properties

6 months agoaarch64: adapt tests for PAC PLT to use selectable GNU properties
Matthieu Longo [Fri, 29 Nov 2024 14:59:50 +0000 (14:59 +0000)] 
aarch64: adapt tests for PAC PLT to use selectable GNU properties

6 months agoaarch64: delete old tests for PAC & BTI PLT
Matthieu Longo [Fri, 29 Nov 2024 12:15:16 +0000 (12:15 +0000)] 
aarch64: delete old tests for PAC & BTI PLT

6 months agoaarch64: new tests for BTI & PAC PLT to use selectable GNU properties
Matthieu Longo [Fri, 29 Nov 2024 12:12:32 +0000 (12:12 +0000)] 
aarch64: new tests for BTI & PAC PLT to use selectable GNU properties

6 months agoaarch64: adapt bti-plt-so to use selectable GNU properties
Matthieu Longo [Fri, 29 Nov 2024 15:27:04 +0000 (15:27 +0000)] 
aarch64: adapt bti-plt-so to use selectable GNU properties

6 months agoaarch64: delete old tests covering the merge of feature markings
Matthieu Longo [Fri, 29 Nov 2024 10:28:31 +0000 (10:28 +0000)] 
aarch64: delete old tests covering the merge of feature markings

6 months agoaarch64: new tests covering the merge of feature markings
Matthieu Longo [Fri, 29 Nov 2024 15:24:20 +0000 (15:24 +0000)] 
aarch64: new tests covering the merge of feature markings

6 months agoaarch64: move tests for AArch64 protections (BTI, PAC) into a subfolder
Matthieu Longo [Mon, 28 Oct 2024 13:59:55 +0000 (13:59 +0000)] 
aarch64: move tests for AArch64 protections (BTI, PAC) into a subfolder

- moved all the BTI and PAC tests into a new subfolder: "protections".
    bti-far-*
    bti-plt-*
    bti-pac-plt-*
- move several procedures used only for AArch64 linker tests to a new exp
  library file aarch64-elf-lib.exp in ld/testsuite/ld-aarch64/lib.
- use aarch64-elf-lib.exp in aarch64-ld.exp and aarch64-protections.exp.

6 months agogdb: handle DW_AT_entry_pc pointing at an empty sub-range
Andrew Burgess [Tue, 19 Nov 2024 21:43:06 +0000 (21:43 +0000)] 
gdb: handle DW_AT_entry_pc pointing at an empty sub-range

The test gdb.cp/step-and-next-inline.exp creates a test binary called
step-and-next-inline-no-header.  This test includes a function
`tree_check` which is inlined 3 times.

When testing with some older versions of gcc (I've tried 8.4.0, 9.3.1)
we see the following DWARF representing one of the inline instances of
tree_check:

 <2><8d9>: Abbrev Number: 38 (DW_TAG_inlined_subroutine)
    <8da>   DW_AT_abstract_origin: <0x9ee>
    <8de>   DW_AT_entry_pc    : 0x401165
    <8e6>   DW_AT_GNU_entry_view: 0
    <8e7>   DW_AT_ranges      : 0x30
    <8eb>   DW_AT_call_file   : 1
    <8ec>   DW_AT_call_line   : 52
    <8ed>   DW_AT_call_column : 10
    <8ee>   DW_AT_sibling     : <0x92d>

 ...

 <1><9ee>: Abbrev Number: 46 (DW_TAG_subprogram)
    <9ef>   DW_AT_external    : 1
    <9ef>   DW_AT_name        : (indirect string, offset: 0xe8): tree_check
    <9f3>   DW_AT_decl_file   : 1
    <9f4>   DW_AT_decl_line   : 38
    <9f5>   DW_AT_decl_column : 1
    <9f6>   DW_AT_linkage_name: (indirect string, offset: 0x2f2): _Z10tree_checkP4treei
    <9fa>   DW_AT_type        : <0x9e8>
    <9fe>   DW_AT_inline      : 3       (declared as inline and inlined)
    <9ff>   DW_AT_sibling     : <0xa22>

 ...

 Contents of the .debug_ranges section:

    Offset   Begin    End
    ...
    00000030 0000000000401165 0000000000401165 (start == end)
    00000030 0000000000401169 0000000000401173
    00000030 0000000000401040 0000000000401045
    00000030 <End of list>
    ...

Notice that one of the sub-ranges of tree-check is empty, this is the
line marked 'start == end'.  As the end address is the first address
after the range, this range cover absolutely no code.

But notice too that the DW_AT_entry_pc for the inline instance points
at this empty range.

Further, notice that despite the ordering of the sub-ranges, the empty
range is actually in the middle of the region defined by the lowest
address to the highest address.  The ordering is not a problem, the
DWARF spec doesn't require that ranges be in any particular order.

However, this empty range is causing issues with GDB newly acquire
DW_AT_entry_pc support.

GDB already rejects, and has done for a long time, empty sub-ranges,
after all, the DWARF spec is clear that such a range covers no code.

The recent DW_AT_entry_pc patch also had GDB reject an entry-pc which
was outside of the low/high bounds of a block.

But in this case, the entry-pc value is within the bounds of a block,
it's just not within any useful sub-range.  As a consequence, GDB is
storing the entry-pc value, and making use of it, but when GDB stops,
and tries to work out which block the inferior is in, it fails to spot
that the inferior is within tree_check, and instead reports the
function into which tree_check was inlined.

I've tested with newer versions of gcc (12.2.0 and 14.2.0) and with
these versions gcc is still generating the empty sub-range, but now
this empty sub-range is no longer the entry point.  Here's the
corresponding ranges table from gcc 14.2.0:

  Contents of the .debug_rnglists section:

   Table at Offset: 0:
    Length:          0x56
    DWARF version:   5
    Address size:    8
    Segment size:    0
    Offset entries:  0
      Offset   Begin    End
      ...
      00000021 0000000000401165 000000000040116f
      0000002b 0000000000401040 (base address)
      00000034 0000000000401040 0000000000401040  (start == end)
      00000037 0000000000401041 0000000000401046
      0000003a <End of list>
      ...

The DW_AT_entry_pc is 0x401165, but this is not the empty sub-range,
as a result, when GDB stops at the entry-pc, GDB will correctly spot
that the inferior is in the tree_check function.

The fix I propose here is, instead of rejecting entry-pc values that
are outside the block's low/high range, instead reject entry-pc values
that are not inside any of the block's sub-ranges.

Now, GDB will ignore the prescribed entry-pc, and will instead select
a suitable default entry-pc based on either the block's low-pc value,
or the first address of the first range.

I have extended the gdb.cp/step-and-next-inline.exp test to check this
case, but this does depend on the compiler version being used (newer
compilers will always pass, even without the fix).

So I have also added a DWARF assembler test to cover this case.

Reviewed-By: Kevin Buettner <kevinb@redhat.com>
6 months agox86: default to not accepting MPX insns
Jan Beulich [Mon, 2 Dec 2024 08:39:23 +0000 (09:39 +0100)] 
x86: default to not accepting MPX insns

Gcc9 had MPX support removed. While we don't want to remove support,
require these deprecated insns (and registers) to be enabled explicitly.

6 months agox86: always set ISA_1_BASELINE property for 64-bit objects
Jan Beulich [Mon, 2 Dec 2024 08:38:47 +0000 (09:38 +0100)] 
x86: always set ISA_1_BASELINE property for 64-bit objects

The baseline was, afaik, specifically chosen to align with the baseline
ISA of x86-64. It therefore makes no sense to emit that property only
conditionally; if anything it confuses tools analyzing the difference
between generated object files, which may result from just
added / changed / removed (entirely ISA-independent) code, without any
change to the enabled extensions. Compilers, after all, are free to use
these baseline "extensions" when generating 64-bit code.

While changing the one testcase that needs adjustment, also correct its
misleading name (to be in sync with the filename).

6 months agox86/COFF: support section-index relocations in insn operands
Jan Beulich [Mon, 2 Dec 2024 08:38:15 +0000 (09:38 +0100)] 
x86/COFF: support section-index relocations in insn operands

On the grounds of the principle put down near the bottom of [1], along
with image and section relative operations, let's also support as insn
operands what .secidx is for on the data side (of course like elsewhere
the reloc operator can then also be used for data generation, albeit a
small tweak to x86_cons() is needed for this to work).

[1] https://sourceware.org/pipermail/binutils/2024-November/137617.html

6 months agox86/COFF: support RVA (image-relative) relocations in insn operands
Jan Beulich [Mon, 2 Dec 2024 08:37:34 +0000 (09:37 +0100)] 
x86/COFF: support RVA (image-relative) relocations in insn operands

As was pointed out in [1] compilers produce code using such constructs,
and hence we'd better support this. In analogy to the .rva directive
permit @rva to be used for this, and in analogy with other architectures
(plus to not diverge from e.g. Clang's integrated assembler, albeit I
haven't been able myself to confirm it knows this form) also permit
@imgrel.

While there also adjust the operand type specifier for the adjacent
@secrel32 - 64-bit fields cannot be used with a 32-bit relocation.

Further while there also deal with *-*-pe* in x86-64.exp, even if (right
now) perhaps only for completeness.

[1] https://sourceware.org/pipermail/binutils/2024-November/137548.html

6 months agotestsuite, threads: add missing return statements
Rohr, Stephan [Wed, 31 Jan 2024 14:33:37 +0000 (06:33 -0800)] 
testsuite, threads: add missing return statements

Add missing return statements in

  * gdb.threads/process-exit-status-is-leader-exit-status.c
  * gdb.threads/next-fork-exec-other-thread.c

to fix 'no return statement' compiler warnings, e.g.:

  process-exit-status-is-leader-exit-status.c: In function ‘start’:
  process-exit-status-is-leader-exit-status.c:46:1: warning: no return
    statement in function returning non-void [-Wreturn-type]
     46 | }
        | ^

Approved-By: Simon Marchi <simon.marchi@efficios.com>
6 months agoRISC-V: Add support for ssdbltrp and smdbltrp extension.
Dongyan Chen [Thu, 28 Nov 2024 12:35:36 +0000 (20:35 +0800)] 
RISC-V: Add support for ssdbltrp and smdbltrp extension.

This implements the ssdbltrp extensons, version 1.0[1] and the smdbltrp
extensions, version1.0[2].

[1] https://github.com/riscv/riscv-isa-manual/blob/main/src/ssdbltrp.adoc
[2] https://github.com/riscv/riscv-isa-manual/blob/main/src/smdbltrp.adoc

bfd/ChangeLog:

* elfxx-riscv.c: Add 'ssdbltrp' and 'smdbltrp' to the list of konwn
  standard extensions.

gas/ChangeLog:

* NEWS: Updated.
* testsuite/gas/riscv/imply.d: Ditto.
* testsuite/gas/riscv/imply.s: Ditto.
* testsuite/gas/riscv/march-help.l: Ditto.

6 months agoAutomatic date update in version.in
GDB Administrator [Mon, 2 Dec 2024 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

6 months agoCorrect hpux-core.c thread_section_p signature
Alan Modra [Sun, 1 Dec 2024 09:41:30 +0000 (20:11 +1030)] 
Correct hpux-core.c thread_section_p signature

Fix fallout from commit 0a1b45a20eaa.

6 months agoRe: PR32399, buffer overflow printing core_file_failing_command
Alan Modra [Sat, 30 Nov 2024 06:11:14 +0000 (16:41 +1030)] 
Re: PR32399, buffer overflow printing core_file_failing_command

Fix more potential buffer overflows, and correct trad-code.c and
cisco-core.c where they should be using bfd_{z}alloc rather than
bfd_{z}malloc.  To stop buffer overflows with fuzzed objects that
don't have a terminator on the core_file_failing_command string, this
patch allocates an extra byte at the end of the entire header buffer
rather than poking a NUL at the end of the name array (u_comm[] or
similar) because (a) it's better to not overwrite the file data, and
(b) it is possible that some core files make use of fields in struct
user beyond the end of u_comm to extend the command name.  The patch
also changes some unnecessary uses of bfd_zalloc to bfd_alloc.
There's not much point in clearing memeory that will shortly be
completely overwritten.

PR 32399
* aix5ppc-core.c (xcoff64_core_p): Allocate an extra byte to
ensure the core_file_failing_command string is terminated.
* netbsd-core.c (netbsd_core_file_p): Likewise.
* ptrace-core.c (ptrace_unix_core_file_p): Likewise.
* rs6000-core.c (rs6000coff_core_p): Likewise.
* trad-core.c (trad_unix_core_file_p): Likewise, and bfd_alloc
tdata rather than bfd_zmalloc.
* cisco-core.c (cisco_core_file_validate): bfd_zalloc tdata.

6 months agoRemove more remnants of old Mach-O workaround
oltolm [Fri, 29 Nov 2024 21:02:07 +0000 (22:02 +0100)] 
Remove more remnants of old Mach-O workaround

Remove another adjustment for section address, this time for the
offset into .debug_str{,.dwo} read from .debug_str_offsets{,.dwo} by
fetch_indexed_string.

Signed-off-by: oltolm <oleg.tolmatcev@gmail.com>
6 months agoAutomatic date update in version.in
GDB Administrator [Sun, 1 Dec 2024 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

6 months agoAutomatic date update in version.in
GDB Administrator [Sat, 30 Nov 2024 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

6 months agos390: Fix linker test TLS -fpic and -fno-pic exec transitions
Jens Remus [Fri, 29 Nov 2024 15:52:13 +0000 (16:52 +0100)] 
s390: Fix linker test TLS -fpic and -fno-pic exec transitions

Commit 36bbf8646c8b ("s390: Treat addressing operand sequence as one in
disassembler") changed how plain "nop" gets disassembled and missed to
update any affected linker tests accordingly.

ld/testsuite/
* ld-s390/tlsbin.dd: "nop" disassembles into "nop".

Fixes: 36bbf8646c8b ("s390: Treat addressing operand sequence as one in disassembler")
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
6 months agos390: Simplify parsing of omitted index register operand
Jens Remus [Fri, 29 Nov 2024 14:37:19 +0000 (15:37 +0100)] 
s390: Simplify parsing of omitted index register operand

The index register operand X in D(X,B) can optionally be omitted by
coding D(,B) or D(B).  Simplify the parsing logic.

gas/
* config/tc-s390.c (md_gather_operands): Rename
omitted_base_or_index to omitted_index and simplify logic.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
6 months agos390: Treat addressing operand sequence as one in disassembler
Jens Remus [Fri, 29 Nov 2024 14:37:19 +0000 (15:37 +0100)] 
s390: Treat addressing operand sequence as one in disassembler

Reuse logic introduced with the preceding commit in the assembler to
treat addressing operand sequences D(X,B), D(B), and D(L,B) as one
with regards to optional last operands (i.e. optparm and optparm2).

With this "nop" now disassembles into "nop" instead of "nop 0".

opcodes/
* s390-dis.c (operand_count): New helper to count the remaining
operands, treating D(X,B), D(B), and D(L,B) as one.
(skip_optargs_p): New helper to test whether remaining operands
 are optional.
(skip_optargs_zero_p): New helper to test whether remaining
operands are optional and their values are zero.
(s390_print_insn_with_opcode): Use skip_optargs_zero_p to skip
optional last operands with a value of zero.

gas/testsuite/
* gas/s390/zarch-optargs.d (nop): Adjust test case accordingly.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
6 months agos390: Treat addressing operand sequence as one in assembler
Jens Remus [Fri, 29 Nov 2024 14:37:19 +0000 (15:37 +0100)] 
s390: Treat addressing operand sequence as one in assembler

The assembler erroneously treated any number of operands as optional,
if the instruction was flagged to have one or two optional operands
(i.e. optparm or optparm2).

Only treat the exact specified number of operands as optional while
treating addressing operand sequences D(X,B), D(B), and D(L,B) as one
operand.

gas/
* config/tc-s390.c (operand_count): New helper to count the
remaining operands, treating D(X,B), D(B), and D(L,B) as one.
(skip_optargs_p): Use new helper operand_count to treat
D(X,B), D(B), and D(L,B) as one operand.
(md_gather_operands): Use skip_optargs_p to skip only the
optional last operands.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
6 months agos390: Fix disassembly of optional addressing operands
Jens Remus [Fri, 29 Nov 2024 14:37:19 +0000 (15:37 +0100)] 
s390: Fix disassembly of optional addressing operands

"nop D1(B1)" erroneously disassembled into "nop D1(B1" (missing
closing parenthesis).  "nop D1(X1,0)" and "nop D1(X1,)" erroneously
disassembled into "nop D1(X1)" (missing zero base register) instead
of "nop D1(X1,0)".

Do not skip disassembly of optional operands if they are index (X)
or base (B) registers or length (L) in an addressing operand sequence
"D(X,B)",  "D(B)", or "D(L,B).  Index and base register operand values
of zero are being handled separately, as they may not be omitted
unconditionally.  For instance a base register value of zero must be
printed in above mentioned case, to distinguish the index from the
base register.  This also ensures proper formatting of addressing
operand sequences.

While at it add further test cases for instructions with optional
operands.

opcodes/
* s390-dis.c (s390_print_insn_with_opcode): Do not
unconditionally skip disassembly of optional operands with a
value of zero, if within an addressing operand sequence.

gas/testsuite/
* gas/s390/zarch-optargs.d: Add further test cases for
instructions with optional operands.
* gas/s390/zarch-optargs.s: Likewise.

Reported-by: Florian Krohm <flo2030@eich-krohm.de>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
6 months agox86: restrict gas'es recognition of -s to Solaris
Jan Beulich [Fri, 29 Nov 2024 08:37:33 +0000 (09:37 +0100)] 
x86: restrict gas'es recognition of -s to Solaris

When there for Solaris compatibility only, also recognize it only there.
This way the option becomes available for other possible uses.

While adjusting md_shortopts[], also re-arrange things such that we have
only a single, uniform definition of it.

6 months agox86/Solaris: support Sun form of CMOVcc
Jan Beulich [Fri, 29 Nov 2024 08:37:13 +0000 (09:37 +0100)] 
x86/Solaris: support Sun form of CMOVcc

Sun specifies an alternative form for CMOVcc [1], which for some reason
we never cared to support, even if - as per gcc's configure checking for
it - it may have been the only permitted form at some point.

While documentation doesn't indicate FCMOVcc to have similar alternative
forms, gcc assumes so. Hence cover FCMOVcc as well.

[1] https://docs.oracle.com/cd/E37838_01/html/E61064/ennbz.html#XALRMeoizm

6 months agox86: purge most *avx512*ig*-intel tests
Jan Beulich [Fri, 29 Nov 2024 08:35:58 +0000 (09:35 +0100)] 
x86: purge most *avx512*ig*-intel tests

Having just one each (AVX512F) ought to be sufficient to cover Intel
syntax disassembly.

In x86-64.exp also reorder tests some, so that related ones are again
next to each other, rather than being interspersed with APX ones.

6 months agox86: SETcc doesn't permit W suffix
Jan Beulich [Fri, 29 Nov 2024 08:35:25 +0000 (09:35 +0100)] 
x86: SETcc doesn't permit W suffix

Accidentally I had removed No_wSuf when cloning the extra template.

6 months agoMAINTAINERS: Update Peter Bergner's e-mail address
Surya Kumari Jangala [Fri, 22 Nov 2024 09:02:18 +0000 (04:02 -0500)] 
MAINTAINERS: Update Peter Bergner's e-mail address

6 months agoPR32399, buffer overflow printing core_file_failing_command
Alan Modra [Thu, 28 Nov 2024 23:48:36 +0000 (10:18 +1030)] 
PR32399, buffer overflow printing core_file_failing_command

Assorted targets do not check, as the ELF targets do, that the program
name in a core file is NUL terminated.  Fix some of them.  I haven't
attempted to fix all targets because editing host specific code can
easily result in build bugs, which aren't discovered until someone
build binutils for that host.  (Of the files edited here, I can't
easily compile hpux-core.c and osf-core.c on a linux system.)

PR 32399
* hppabsd-core.c (hppabsd_core_core_file_p): Ensure core_command
string is terminated.
* hpux-core.c (hpux_core_core_file_p): Likewise.
* irix-core.c (irix_core_core_file_p): Likewise.
* lynx-core.c (lynx_core_file_p): Likewise.
* osf-core.c (osf_core_core_file_p): Likewise.
* mach-o.c (bfd_mach_o_core_file_failing_command): Likewise.

6 months agoAutomatic date update in version.in
GDB Administrator [Fri, 29 Nov 2024 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoSync include/dwarf.h with gcc up to commit c4073a3d154
Alexandra Hájková [Mon, 25 Nov 2024 16:44:05 +0000 (17:44 +0100)] 
Sync include/dwarf.h with gcc up to commit c4073a3d154

Approved-by: Kevin Buettner <kevinb@redhat.com>
7 months ago[gdb/syscalls] Add syscalls {set,get,list,remove}xattrat
Tom de Vries [Thu, 28 Nov 2024 12:53:04 +0000 (13:53 +0100)] 
[gdb/syscalls] Add syscalls {set,get,list,remove}xattrat

In commit 58776901074 ("[gdb/syscalls] Update to linux v6.11") I updated to
linux v6.11, but a recent submission for loongarch [1] used a current trunk
version, so it makes sense to do this as well elsewhere.

Using linux current trunk with update-linux-from-src.sh gets us 4 more
syscalls:
- setxattrat
- getxattrat
- listxattrat
- removexattrat

Tested on x86_64-linux.

[1] https://sourceware.org/pipermail/gdb-patches/2024-November/213613.html

7 months agoAutomatic date update in version.in
GDB Administrator [Thu, 28 Nov 2024 00:00:42 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoFix 32392 [2.44 Regression] gprofng fails to build on i686-linux-gnu
Vladimir Mezentsev [Wed, 27 Nov 2024 03:51:23 +0000 (19:51 -0800)] 
Fix 32392 [2.44 Regression] gprofng fails to build on i686-linux-gnu

gprofng/ChangeLog
2024-11-26  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

PR gprofng/32392
* libcollector/libcol_util.c (__collector_util_init): Fix warning.

7 months agogprofng: skip unrecognized input command
Vladimir Mezentsev [Wed, 27 Nov 2024 03:40:16 +0000 (19:40 -0800)] 
gprofng: skip unrecognized input command

gprofng crashes when the GUI sends an invalid command.
Skip unrecognized commands and return an error status to the GUI.

gprofng/ChangeLog
2024-11-26  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* src/ipc.cc (ipc_doWork): Skip unrecognized commands.
* src/ipcio.cc (writeError): New function.
* src/ipcio.h: Add RESPONSE_STATUS_ERROR.

7 months agogdb/testsuite: skip gdb.threads/omp-par-scope.exp with clang
Guinevere Larsen [Mon, 25 Nov 2024 18:15:36 +0000 (15:15 -0300)] 
gdb/testsuite: skip gdb.threads/omp-par-scope.exp with clang

Since 2020 it has been reported to clang[1] that the debug information
around OpenMP is insufficient.  The OpenMP section is not declared
within the correct scope, and instead clang marks as if the section was
a function in the global scope.  This causes several failures in the
test gdb.threads/omp-par-scope.exp when using clang to test GDB.

Since this isn't a true failure of GDB, and there is little expectation
that clang will be able to fix this soon, this commit disables the
aforementioned test when clang is being used.

[1] https://github.com/llvm/llvm-project/issues/44236

Approved-by: Kevin Buettner <kevinb@redhat.com>
7 months ago[gdb/symtab] Fix parent map dump
Tom de Vries [Wed, 27 Nov 2024 17:48:43 +0000 (18:48 +0100)] 
[gdb/symtab] Fix parent map dump

Before the fix for PR symtab/32225, the parent map dump showed a mapping from
section offsets to cooked index entries:
...
  0x0000000000000035 0x3ba9560 (0x34: sp1::A)
...
but now that's no longer the case:
...
  0x00000000406f5405 0x410a04d0 (0x34: sp1::A)
...

Fix this by extending the annotation somewhat, such that we get:
...
map start:
  0x0000000012c52405 0x135fd550
(section: .debug_info, offset: 0x35) -> (0x34: sp1::A)
...

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32225

7 months ago[gdb/testsuite] Add gdb.dwarf2/dw2-tu-dwarf-4-5.exp
Tom de Vries [Wed, 27 Nov 2024 17:48:43 +0000 (18:48 +0100)] 
[gdb/testsuite] Add gdb.dwarf2/dw2-tu-dwarf-4-5.exp

Add a regression test for PR symtab/32225.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32225

7 months ago[gdb/symtab] Fix parent map when handling .debug_info and .debug_types
Author: Tom Tromey [Wed, 27 Nov 2024 17:48:43 +0000 (18:48 +0100)] 
[gdb/symtab] Fix parent map when handling .debug_info and .debug_types

Consider test-case:
...
$ cat test.c
namespace sp1 {
  class A {
    int i;
    const int f1 = 1;
    ...
    const int f29 = 1;
  };
}
sp1::A a;
void _start (void) {}
$ cat test2.c
namespace sp2 {
  class B {
    float f;
    const float f1 = 1;
    ...
    const float f29 = 1;
  };
}
sp2::B b;
...
compiled like this:
...
$ g++ test.c -gdwarf-4 -c -g -fdebug-types-section
$ g++ test2.c -gdwarf-5 -c -g -fdebug-types-section
$ g++ -g test.o test2.o -nostdlib
...

Using:
...
$ gdb -q -batch -iex "maint set worker-threads 0" a.out -ex "maint print objfiles"
...
we get a cooked index entry with incorrect parent:
...
    [29] ((cooked_index_entry *) 0x3c57d1a0)
    name:       B
    canonical:  B
    qualified:  sp1::A::B
    DWARF tag:  DW_TAG_class_type
    flags:      0x0 []
    DIE offset: 0x154
    parent:     ((cooked_index_entry *) 0x3c57d110) [A]
...

The problem is that the parent map assumes that all offsets are in the same
section.

Fix this by using dwarf2_section_info::buffer-relative addresses instead,
which get us instead:
...
    [29] ((cooked_index_entry *) 0x3f0962b0)
    name:       B
    canonical:  B
    qualified:  sp2::B
    DWARF tag:  DW_TAG_class_type
    flags:      0x0 []
    DIE offset: 0x154
    parent:     ((cooked_index_entry *) 0x3f096280) [sp2]
...

Tested on x86_64-linux.

PR symtab/32225
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32225

7 months ago[gdb/tdep] s390: Add arch15 record/replay support
Andreas Arnez [Tue, 19 Nov 2024 17:24:06 +0000 (18:24 +0100)] 
[gdb/tdep] s390: Add arch15 record/replay support

Enable recording of the new "arch15" instructions on z/Architecture
targets.

7 months agoPE LD: Merge .CRT .ctors and .dtors into .rdata
Liu Hao [Wed, 27 Nov 2024 14:27:53 +0000 (14:27 +0000)] 
PE LD: Merge .CRT .ctors and .dtors into .rdata

PR 32264

7 months agoTidy up the default ELF linker script
Nick Clifton [Wed, 27 Nov 2024 11:23:38 +0000 (11:23 +0000)] 
Tidy up the default ELF linker script

7 months agoRe: nios2: Remove binutils support for Nios II target
Alan Modra [Tue, 26 Nov 2024 22:12:06 +0000 (08:42 +1030)] 
Re: nios2: Remove binutils support for Nios II target

Remove a now unused config file, regenerate POTFILES to remove nios2
refs, and modify config.bfd to report the target is obsolete.

7 months agoAutomatic date update in version.in
GDB Administrator [Wed, 27 Nov 2024 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agonios2: Remove binutils support for Nios II target.
Sandra Loosemore [Tue, 26 Nov 2024 19:13:07 +0000 (19:13 +0000)] 
nios2: Remove binutils support for Nios II target.

The Nios II architecture has been EOL'ed by the vendor.  This patch
removes all binutils, bfd, gas, binutils, and opcodes support for this
target with the exception of the readelf utility.  (The ELF EM_*
number remains valid and the relocation definitions from the Nios II
ABI will never change in future, so retaining the readelf support
seems consistent with its purpose as a utility that tries to parse the
headers in any ELF file provided as an argument regardless of target.)

7 months agonios2: Remove all GDB support for Nios II targets.
Sandra Loosemore [Tue, 26 Nov 2024 19:13:07 +0000 (19:13 +0000)] 
nios2: Remove all GDB support for Nios II targets.

Intel has EOL'ed the Nios II architecture, and it's time to remove support
from all toolchain components before it gets any more bit-rotten from
lack of maintenance or regular testing.

7 months ago[gdb/syscalls] Update aarch64-linux.xml to linux v6.11
Tom de Vries [Tue, 26 Nov 2024 12:29:12 +0000 (13:29 +0100)] 
[gdb/syscalls] Update aarch64-linux.xml to linux v6.11

Use gdb/syscalls/update-linux.sh to update aarch64-linux.xml.in to linux
v6.11, and update aarch64-linux.xml by running make.

Noteworthy changes are removal of entries:
- arch_specific_syscall
- syscalls
which look like they were added accidentally.

I modified update-linux.sh to keep the copyright start date.  Verified with
shellcheck.

Tested-By: Luis Machado <luis.machado@arm.com>
Approved-By: Luis Machado <luis.machado@arm.com>
7 months agoPR32387 ppc64 TLS optimization bug with -fno-plt code
Alan Modra [Mon, 25 Nov 2024 21:54:19 +0000 (08:24 +1030)] 
PR32387 ppc64 TLS optimization bug with -fno-plt code

The inline plt code emitted by gcc is incompatible with the
linker/ld.so --tls-get-addr-optimize scheme.  This is the runtime
optimisation where the first call to __tls_get_addr results in
__tls_get_addr updating the tls_index pair, then the special linker
stub using that to short-circuit second and subsequent calls for a
given tls symbol.  Enabled by default when the linker sees
__tls_get_addr_opt is preseent, and enabled in ld.so when DT_PPC64_OPT
has PPC64_OPT_TLS set.  Note that this is distinct from link-time tls
optimisation.

PR 32387
* elf64-ppc.c (ppc64_elf_check_relocs): Disable tls_get_addr_opt
on detecting inline plt calls to __tls_get_addr.

7 months ago[gdb/syscalls] Sync with strace v6.12
Tom de Vries [Tue, 26 Nov 2024 09:02:37 +0000 (10:02 +0100)] 
[gdb/syscalls] Sync with strace v6.12

I ran gdb/syscalls/update-linux-defaults.sh with strace sources v6.12, and got
one difference in gdb/syscalls/linux-defaults.xml.in:
...
+  <syscall name="mseal" groups="memory"/>
...

Rerun make to propagate this change to the xml files.

7 months ago[gdb/syscalls] Use update-linux-from-src.sh for arm-linux
Tom de Vries [Tue, 26 Nov 2024 08:49:29 +0000 (09:49 +0100)] 
[gdb/syscalls] Use update-linux-from-src.sh for arm-linux

I tried to use arm-linux.py to regenerate arm-linux.xml.in, but it didn't work.

Fix this by:
- adding handling of arm-linux.xml.in in update-linux-from-src.sh,
- regenerating arm-linux.xml.in using update-linux-from-src.sh and linux 6.11
  sources,
- regenerating arm-linux.xml using make, and
- removing arm-linux.py.

This changes the name "oldolduname" into "olduname".

Tested on arm-linux.  Verified with shellcheck.

7 months ago[gdb/syscalls] Restructure update-linux-from-src.sh
Tom de Vries [Tue, 26 Nov 2024 08:49:29 +0000 (09:49 +0100)] 
[gdb/syscalls] Restructure update-linux-from-src.sh

Restructure update-linux-from-src.sh to do the generation of each line
in the script it self rather than in awk.

Tested on aarch64-linux.  Verified with shellcheck.

7 months ago[gdb/syscalls] Improve update-linux-from-src.sh
Tom de Vries [Tue, 26 Nov 2024 08:49:29 +0000 (09:49 +0100)] 
[gdb/syscalls] Improve update-linux-from-src.sh

Some improvements in gdb/syscalls/update-linux-from-src.sh:
- use bash instead of sh
- use local to distinguish between local and global vars
  (which brings to light that pre uses the global rather than the local
  start_date)
- factor out main and parse_args
- factor out regen
- iterate over *.xml.in instead of *.in

Tested on aarch64-linux.  Verified with shellcheck.

7 months ago[gdb/syscalls] Update to linux v6.11
Tom de Vries [Tue, 26 Nov 2024 08:49:29 +0000 (09:49 +0100)] 
[gdb/syscalls] Update to linux v6.11

Regenerate some gdb/syscalls/*.xml.in files using
gdb/syscalls/update-linux-from-src.sh and linux v6.11 sources.

Regenerate the corresponding gdb/syscalls/*.xml using make.

Tested on aarch64-linux.

7 months agoConvert dwarf2_per_objfile::die_type_hash to new hash table
Simon Marchi [Mon, 4 Nov 2024 18:27:56 +0000 (13:27 -0500)] 
Convert dwarf2_per_objfile::die_type_hash to new hash table

Convert dwarf2_per_objfile::die_type_hash, which maps debug info
offsets to `type *`, to gdb::unordered_map.

Change-Id: I5c174af64ee46d38a465008090e812acf03704ec
Approved-By: Tom Tromey <tom@tromey.com>
7 months agoConvert dwarf2_cu::call_site_htab to new hash table
Simon Marchi [Mon, 4 Nov 2024 18:27:55 +0000 (13:27 -0500)] 
Convert dwarf2_cu::call_site_htab to new hash table

Convert one use of htab_t, mapping (unrelocated) pc to call_site
objects, to `gdb::unordered_map<unrelocated_addr, call_site *>`.

Change-Id: I40a0903253a8589dbdcb75d52ad4d233931f6641
Approved-By: Tom Tromey <tom@tromey.com>
7 months agoConvert dwarf_cu::die_hash to new hash table
Simon Marchi [Mon, 4 Nov 2024 18:27:54 +0000 (13:27 -0500)] 
Convert dwarf_cu::die_hash to new hash table

Convert one use of htab_t, mapping offsets to die_info object, to
`gdb::unordered_set`.

Change-Id: Ic80df22bda551e2d4c2511d167e057f4d6cd2b3e
Approved-By: Tom Tromey <tom@tromey.com>
7 months agoConvert gdb_bfd.c to new hash table
Simon Marchi [Mon, 4 Nov 2024 18:27:53 +0000 (13:27 -0500)] 
Convert gdb_bfd.c to new hash table

This converts the BFD cache in gdb_bfd.c to use the new hash table.

Change-Id: Ib6257fe9d4f7f8ef793a2c82d53935a8d2c245a3
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agoConvert more DWARF code to new hash table
Simon Marchi [Mon, 4 Nov 2024 18:27:52 +0000 (13:27 -0500)] 
Convert more DWARF code to new hash table

This converts more code in the DWARF reader to use the new hash table.

Change-Id: I86f8c0072f0a09642de3d6f033fefd0c8acbc4a3
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agoConvert all_bfds to new hash table
Simon Marchi [Mon, 4 Nov 2024 18:27:51 +0000 (13:27 -0500)] 
Convert all_bfds to new hash table

This converts gdb_bfd.c to use the new hash table for all_bfds.

This patch slightly changes the htab_t pretty-printer test, which was
relying on all_bfds.  Note that with the new hash table, gdb-specific
printers aren't needed; the libstdc++ printers suffice -- in fact,
they are better, because the true types of the contents are available.

Change-Id: I48b7bd142085287b34bdef8b6db5587581f94280
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agoConvert typedef hash to new hash table
Simon Marchi [Mon, 4 Nov 2024 18:27:50 +0000 (13:27 -0500)] 
Convert typedef hash to new hash table

This converts the typedef hash to use the new hash table.

This patch found a latent bug in the typedef code.  Previously, the
hash function looked at the type name, but the hash equality function
used types_equal -- but that strips typedefs, meaning that equality of
types did not imply equality of hashes.  This patch fixes the problem
and updates the relevant test.

Change-Id: I0d10236b01e74bac79621244a1c0c56f90d65594
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agoConvert abbrevs to new hash table
Simon Marchi [Mon, 4 Nov 2024 18:27:49 +0000 (13:27 -0500)] 
Convert abbrevs to new hash table

This converts the DWARF abbrevs themselves to use the new hash table.

Change-Id: I0320a733ecefe2cffeb25c068f17322dd3ab23e2
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agoConvert abbrev cache to new hash table
Simon Marchi [Mon, 4 Nov 2024 18:27:48 +0000 (13:27 -0500)] 
Convert abbrev cache to new hash table

This converts the DWARF abbrev cache to use the new hash table.

Change-Id: I5e88cd4030715954db2c43f873b77b6b8e73f5aa
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>