]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
11 months ago[gdb/testsuite] Add xfail in gdb.base/hbreak.exp
Tom de Vries [Tue, 23 Jul 2024 12:38:16 +0000 (14:38 +0200)] 
[gdb/testsuite] Add xfail in gdb.base/hbreak.exp

On an aarch64-linux system with 32-bit userland running in a chroot, and using
target board unix/mthumb I get:
...
(gdb) hbreak hbreak.c:27^M
Hardware assisted breakpoint 2 at 0x4004e2: file hbreak.c, line 27.^M
(gdb) PASS: gdb.base/hbreak.exp: hbreak
continue^M
Continuing.^M
Unexpected error setting breakpoint: Invalid argument.^M
(gdb) FAIL: gdb.base/hbreak.exp: continue to break-at-exit after hbreak
...
due to this call in arm_linux_nat_target::low_prepare_to_resume:
...
          if (ptrace (PTRACE_SETHBPREGS, pid,
              (PTRACE_TYPE_ARG3) ((i << 1) + 1), &bpts[i].address) < 0)
            perror_with_name (_("Unexpected error setting breakpoint"));
...

This problem does not happen if instead we use a 4-byte aligned address.

I'm not sure if this is simply unsupported or if there's a kernel bug of some
sort, but I don't see what gdb can do about this.

Tentatively mark this as xfail.

Tested on aarch64-linux.

Approved-By: Luis Machado <luis.machado@arm.com>
11 months ago[gdb/testsuite] Fix gdb.ada/mi_task_arg.exp on arm-linux
Tom de Vries [Tue, 23 Jul 2024 12:27:36 +0000 (14:27 +0200)] 
[gdb/testsuite] Fix gdb.ada/mi_task_arg.exp on arm-linux

On arm-linux, I run into:
...
PASS: gdb.ada/mi_task_arg.exp: mi runto task_switch.break_me
Expecting: ^(-stack-list-arguments 1[^M
]+)?(\^done,stack-args=\[frame={level="0",args=\[\]},frame={level="1",args=\[{name="<_task>",value="0x[0-9A-Fa-f]+"}(,{name="<_taskL>",value="[0-9]+"})?\]},frame={level="2",args=\[({name="self_id",value="(0x[0-9A-Fa-f]+|<optimized out>)"})?\]},.*[^M
]+[(]gdb[)] ^M
[ ]*)
-stack-list-arguments 1^M
^done,stack-args=[frame={level="0",args=[]},frame={level="1",args=[{name="<_task>",value="0x40bc48"}]},frame={level="2",args=[]}]^M
(gdb) ^M
FAIL: gdb.ada/mi_task_arg.exp: -stack-list-arguments 1 (unexpected output)
...

The problem is that the test-case expects a level 3 frame, but there is none.

This can be reproduced using cli bt:
...
 $ gdb -q -batch outputs/gdb.ada/mi_task_arg/task_switch \
   -ex "b task_switch.break_me" \
   -ex run \
   -ex bt
 Breakpoint 1 at 0x34b4: file task_switch.adb, line 57.

 Thread 3 "my_caller" hit Breakpoint 1, task_switch.break_me () \
   at task_switch.adb:57
 57       null;
 #0  task_switch.break_me () at task_switch.adb:57
 #1  0x00403424 in task_switch.caller (<_task>=0x40bc48) at task_switch.adb:51
 #2  0xf7f95a08 in ?? () from /lib/arm-linux-gnueabihf/libgnarl-12.so
 Backtrace stopped: previous frame identical to this frame (corrupt stack?)
...

The purpose of the test-case is printing the frame at level 1, so I don't
think we should bother about the presence of the frame at level 3.

Fix this by allowing the backtrace to stop at level 2.

Tested on arm-linux.

Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
11 months agoImprove objdump's display of PE header information.
Pali Roh?r [Tue, 23 Jul 2024 07:52:21 +0000 (08:52 +0100)] 
Improve objdump's display of PE header information.

  PR 31953

11 months agoAutomatic date update in version.in
GDB Administrator [Tue, 23 Jul 2024 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

11 months agogdb/unittests/intrusive-list: remove unnecessary local objects
Simon Marchi [Mon, 22 Jul 2024 16:06:29 +0000 (12:06 -0400)] 
gdb/unittests/intrusive-list: remove unnecessary local objects

These objects are not used.

Change-Id: I90127f7b2d1543718c841b54173521d9ab3f652f

11 months agogdb/solib: pass program space to solib_used
Simon Marchi [Mon, 22 Jul 2024 17:20:22 +0000 (17:20 +0000)] 
gdb/solib: pass program space to solib_used

Make the current program space reference bubble up one level.

Change-Id: I6113c9ef57cb31ca8ea129ab58e7c318c09b5123

11 months agogdb/remote: remove an out of date comment
Andrew Burgess [Mon, 22 Jul 2024 15:37:08 +0000 (16:37 +0100)] 
gdb/remote: remove an out of date comment

A comment above an `if` check was accidentally left in place after
this commit:

  commit ddb3f3d89cf62df6be3cb9e110504def19625160
  Date:   Tue Mar 19 12:34:34 2024 +0100

      Add "error_message+" feature to qSupported

The comment relates to how 'E.msg' style remote replies are not
supported by every packet, but after the above commit they are
supported in all cases (that call packet_check_result), and the
comment should have been removed.

11 months agogdb/testsuite: fix minor typo in a comment
Andrew Burgess [Fri, 19 Jul 2024 15:11:44 +0000 (16:11 +0100)] 
gdb/testsuite: fix minor typo in a comment

Fix 'text' to 'test' in a test comment.

11 months agoAutomatic date update in version.in
GDB Administrator [Mon, 22 Jul 2024 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

11 months agoDon't trim trailing newline in run_host_cmd
Alan Modra [Sun, 21 Jul 2024 11:33:22 +0000 (21:03 +0930)] 
Don't trim trailing newline in run_host_cmd

Testcases like ld-elf/pr19719a.c that
    printf ("PASS\n");
on success ought to see the whole output for "string match".
Similarly, the ld-pe/ pdb*.d files shouldn't need to remove the last
newline to match.  For most of the testsuite it doesn't matter whether
the trailing newline is present or not, and there are only a few cases
where we need to remove it.

* testsuite/lib/ld-lib.exp (run_host_cmd): Don't regsub away
output trailing newline.  Do string trim for gcc/ld version checks.
* testsuite/config/default.exp (plug_so): Do string trim output of
run_host_cmd.
* testsuite/ld-elf/shared.exp (mix_pic_and_non_pic): Adjust
string match to include trailing newline.
* testsuite/ld-i386/i386.exp (undefined_weak): Likewise.
* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Likewise.
* testsuite/ld-plugin/libdep.exp (run_test): Likewise.
* testsuite/ld-plugin/lto.exp (PR ld/28138 run): Likewise.
* testsuite/ld-pe/pdb-strings.d,
* testsuite/ld-pe/pdb-syms1-globals.d,
* testsuite/ld-pe/pdb-syms1-records.d,
* testsuite/ld-pe/pdb-syms1-symbols1.d,
* testsuite/ld-pe/pdb-syms1-symbols2.d,
* testsuite/ld-pe/pdb-syms2-symbols1.d,
* testsuite/ld-pe/pdb-types1-hashlist.d,
* testsuite/ld-pe/pdb-types1-skiplist.d,
* testsuite/ld-pe/pdb-types1-typelist.d,
* testsuite/ld-pe/pdb-types2-hashlist.d,
* testsuite/ld-pe/pdb-types2-skiplist.d,
* testsuite/ld-pe/pdb-types2-typelist.d,
* testsuite/ld-pe/pdb-types3-hashlist.d,
* testsuite/ld-pe/pdb-types3-skiplist.d,
* testsuite/ld-pe/pdb-types3-typelist.d,
* testsuite/ld-pe/pdb1-publics.d,
* testsuite/ld-pe/pdb1-sym-record.d,
* testsuite/ld-pe/pdb2-section-contrib.d,
* testsuite/ld-pe/pdb3-c13-info1.d,
* testsuite/ld-pe/pdb3-c13-info2.d,
* testsuite/ld-pe/pdb3-source-info.d: Add trailing newline.

11 months agogdb/testsuite: Add missing 'require allow_gdbserver_tests'
Andrew Burgess [Sun, 21 Jul 2024 08:41:30 +0000 (09:41 +0100)] 
gdb/testsuite: Add missing 'require allow_gdbserver_tests'

The commit:

  commit 22836ca88591ac7efacf06d5b6db191763fd8aba
  Date:   Tue May 21 09:57:49 2024 +0100

      gdb: check for multiple matching build-id files

Was missing a 'require allow_gdbserver_tests' in a gdbserver test.
Add it now.

11 months ago[gdb/testsuite] Fix scopes check in gdb.dap/rust-slices.exp
Tom de Vries [Sun, 21 Jul 2024 08:03:09 +0000 (10:03 +0200)] 
[gdb/testsuite] Fix scopes check in gdb.dap/rust-slices.exp

When running test-case gdb.dap/rust-slices.exp on aarch64-linux
(debian 12/bookworm), I run into:
...
{"request_seq": 6, "type": "response", "command": "scopes", "body": {"scopes": [{"variablesReference": 1, "name": "Locals", "presentationHint": "locals", "expensive": false, "namedVariables": 3, "line": 28, "source": {"name": "rust-slices.rs", "path": "/home/linux/gdb/binutils-gdb.git/gdb/testsuite/gdb.dap/rust-slices.rs"}}, {"variablesReference": 2, "name": "Registers", "presentationHint": "registers", "expensive": false, "namedVariables": 261, "line": 28, "source": {"name": "rust-slices.rs", "path": "/home/linux/gdb/binutils-gdb.git/gdb/testsuite/gdb.dap/rust-slices.rs"}}]}, "success": true, "seq": 20}PASS: gdb.dap/rust-slices.exp: get scopes success
FAIL: gdb.dap/rust-slices.exp: three scopes
PASS: gdb.dap/rust-slices.exp: scope is locals
PASS: gdb.dap/rust-slices.exp: locals presentation hint
PASS: gdb.dap/rust-slices.exp: three vars in scope
...

The test-case expects three scopes due to a rust compiler issue:
...
 # There are three scopes because an artificial symbol ends up in the
 # DWARF.  See https://github.com/rust-lang/rust/issues/125126.
 gdb_assert {[llength $scopes] == 3} "three scopes"
...
but it seems that the version used here (rustc 1.63.0, llvm 14.0.6) doesn't
have this issue.

Fix this by allowing two or three scopes, and changing the test name to
"two scopes".

Tested on aarch64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>
PR testsuite/31983
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31983

11 months agoAutomatic date update in version.in
GDB Administrator [Sun, 21 Jul 2024 00:00:24 +0000 (00:00 +0000)] 
Automatic date update in version.in

11 months agold/testsuite: add missing definition to PDB test
Mark Harmstone [Sat, 13 Jul 2024 14:30:46 +0000 (15:30 +0100)] 
ld/testsuite: add missing definition to PDB test

The file pdb-syms1a.s was missing a definition for T_VOID, which was
causing some types not to be deduplicated. It also meant that the test
couldn't be run against LLVM's lld, which throws an error for this.

This particular test only tests the symbols stream, not the types
stream, which is why the deduplication doesn't result in a change in the
file size.

11 months agold/PDB: use correct hashing algorithm in add_globals_ref
Mark Harmstone [Sat, 13 Jul 2024 14:36:34 +0000 (15:36 +0100)] 
ld/PDB: use correct hashing algorithm in add_globals_ref

add_globals_ref was hashing using CRC32 rather than the hashing
algorithm used for symbols, which meant that windbg was unable to put
breakpoints against unmangled names.

11 months agoCorrect version for binutils 2.43 NEWS entries.
H.J. Lu [Sat, 20 Jul 2024 20:52:50 +0000 (13:52 -0700)] 
Correct version for binutils 2.43 NEWS entries.

Change 2.42 to 2.43 for binutils 2.43 NEWS entries.

binutils/

* NEWS: Change 2.42 to 2.43 for 2.43 NEWS entries.

ld/

* NEWS: Change 2.42 to 2.43 for 2.43 NEWS entries.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
11 months agogdb: remove tracepoint_probe_create_sals_from_location_spec
Andrew Burgess [Fri, 14 Apr 2023 14:16:33 +0000 (15:16 +0100)] 
gdb: remove tracepoint_probe_create_sals_from_location_spec

The tracepoint_probe_create_sals_from_location_spec function just
forwards all its arguments to
bkpt_probe_create_sals_from_location_spec, and is only used in one
place.

Lets delete tracepoint_probe_create_sals_from_location_spec and
replace it with bkpt_probe_create_sals_from_location_spec.

There should be no user visible changes after this commit.

11 months agogdb: remove breakpoint_re_set_one
Andrew Burgess [Fri, 14 Apr 2023 13:45:38 +0000 (14:45 +0100)] 
gdb: remove breakpoint_re_set_one

During a later patch I wanted to reset a single breakpoint, so I
called breakpoint_re_set_one.  However, this is not the right thing to
do.  If we look at breakpoint_re_set then we see that there's a whole
bunch of state that needs to be preserved prior to calling
breakpoint_re_set_one, and after calling breakpoint_re_set_one we
still need to call update_global_location_list.

I could just update the comment on breakpoint_re_set_one to make it
clearer how the function should be used -- or more likely to warn that
the function should only be used as a helper from breakpoint_re_set.

However, breakpoint_re_set_one is only 3 lines long.  So I figure it
might actually be easier to just fold breakpoint_re_set_one into
breakpoint_re_set, then there's no risk of accidentally calling
breakpoint_re_set_one when we shouldn't.

There should be no user visible changes after this commit.

11 months agogdb: don't display inferior list for pending breakpoints
Andrew Burgess [Thu, 13 Apr 2023 14:12:17 +0000 (15:12 +0100)] 
gdb: don't display inferior list for pending breakpoints

I noticed that in the 'info breakpoints' output, GDB sometimes prints
the inferior list for pending breakpoints, this doesn't seem right to
me.  A pending breakpoint has no locations (at least, as far as we
display things in the 'info breakpoints' output), so including an
inferior list seems odd.

Here's what I see right now:

  (gdb) info breakpoint 5
  Num     Type           Disp Enb Address            What
  5       breakpoint     keep y   <PENDING>          foo inf 1
  (gdb)

It's the 'inf 1' at the end of the line that I'm objecting too.

To trigger this behaviour we need to be in a multi-inferior debug
session.  The breakpoint must have been non-pending at some point in
the past, and so have a location assigned to it.

The breakpoint becomes pending again as a result of a shared library
being unloaded.  When this happens the location itself is marked
pending (via bp_location::shlib_disabled).

In print_one_breakpoint_location, in order to print the inferior list
we check that the breakpoint has a location, and that we have multiple
inferiors, but we don't check if the location itself is pending.

This commit adds that check, which means the output is now:

  (gdb) info breakpoint 5
  Num     Type           Disp Enb Address            What
  5       breakpoint     keep y   <PENDING>          foo
  (gdb)

Which I think makes more sense -- indeed, the format without the
inferior list is what we display for a pending breakpoint that has
never had any locations assigned, so I think this change in behaviour
makes GDB more consistent.

11 months agoUpdate after creating 2.43 branch
Nick Clifton [Sat, 20 Jul 2024 12:46:23 +0000 (13:46 +0100)] 
Update after creating 2.43 branch

11 months agoChange version to 2.43.50
Nick Clifton [Sat, 20 Jul 2024 12:16:33 +0000 (13:16 +0100)] 
Change version to 2.43.50

11 months agoAdd markers for 2.43 branch/release
Nick Clifton [Sat, 20 Jul 2024 11:43:19 +0000 (12:43 +0100)] 
Add markers for 2.43 branch/release

11 months agoRe: binutils: Add a test for strip with build notes
Alan Modra [Sat, 20 Jul 2024 02:53:59 +0000 (12:23 +0930)] 
Re: binutils: Add a test for strip with build notes

The new test wasn't being run, and failed due to relocations against
.gnu.build.attributes being stripped by default strip behaviour.
We probably should be keeping these relocations, but I haven't made
that change here.
BTW, the new test fails on ia64-hpux but that's just a repeat of the
existing note-5 fail.

PR 31999
* testsuite/binutils-all/strip-16.d: strip with --strip-unneeded
and --merge-notes.
* testsuite/binutils-all/objcopy.exp: Run the new test.  Sort
other strip tests.

11 months agobinutils: Add a test for strip with build notes
H.J. Lu [Sat, 20 Jul 2024 01:59:53 +0000 (18:59 -0700)] 
binutils: Add a test for strip with build notes

Add a test for strip with build notes.

PR binutils/31999
* testsuite/binutils-all/strip-16.d: New.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
11 months agoPR31999 strip [.gnu.build.attributes]: failed
Alan Modra [Sat, 20 Jul 2024 00:38:32 +0000 (10:08 +0930)] 
PR31999 strip [.gnu.build.attributes]: failed

PR 31999
* objcopy.c (merge_gnu_build_notes): Always set *new_size.

11 months agoAutomatic date update in version.in
GDB Administrator [Sat, 20 Jul 2024 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

11 months agogdb-gdb.py: strip typedefs in intrusive_list printer assertion
Simon Marchi [Wed, 17 Jul 2024 16:10:57 +0000 (12:10 -0400)] 
gdb-gdb.py: strip typedefs in intrusive_list printer assertion

When debugging gdb itself and trying to print a intrusive_list that has
more than one element, I get:

    File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 365, in _children_generator
      node_ptr = self._as_node_ptr(elem_ptr)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 345, in _as_node_ptr
      assert elem_ptr.type.code == gdb.TYPE_CODE_PTR
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError

This is because node_ptr is a typedef
(intrusive_list_base_iterator::pointer).  Add a call to strip_typedefs
to get to the real type.

Enhance gdb.gdb/python-helper.exp with a test that would have caught
this bug.

Change-Id: I3eaca8de5ed06d05756ed979332b6a431e15b700
Approved-By: Andrew Burgess <aburgess@redhat.com>
11 months agoMIPS/opcodes: Replace "y" microMIPS operand code with "x"
Maciej W. Rozycki [Fri, 19 Jul 2024 18:01:53 +0000 (19:01 +0100)] 
MIPS/opcodes: Replace "y" microMIPS operand code with "x"

Replace the "y" microMIPS operand code, used with ALNV.PS only, with "x"
so as to make "y" available for microMIPS MT use.

11 months agoMIPS/opcodes: Mark MT thread context move assembly idioms as aliases
Maciej W. Rozycki [Fri, 19 Jul 2024 18:01:53 +0000 (19:01 +0100)] 
MIPS/opcodes: Mark MT thread context move assembly idioms as aliases

A number of instructions in the regular MIPS opcode table are assembly
idioms for the MT thread context move MFTR and MTTR instructions, so
mark them as aliases accordingly.  Add suitable test cases, which also
cover the PAUSE assembly idiom.

11 months agoMIPS/opcodes: Mark PAUSE as an alias
Maciej W. Rozycki [Fri, 19 Jul 2024 18:01:53 +0000 (19:01 +0100)] 
MIPS/opcodes: Mark PAUSE as an alias

PAUSE is an assembly idiom for 'sll $0,$0,5', so mark it as an alias in
the regular MIPS opcode table, matching the microMIPS opcode table.  A
test case will be supplied separately.

11 months agoMIPS/GAS/testsuite: Run the MT ASE test across architectures
Maciej W. Rozycki [Fri, 19 Jul 2024 18:01:53 +0000 (19:01 +0100)] 
MIPS/GAS/testsuite: Run the MT ASE test across architectures

Verify that MT ASE instructions assemble and disassemble correctly
across the compatible architectures.

11 months agoMIPS/opcodes: Reorder coprocessor moves alphabetically
Maciej W. Rozycki [Fri, 19 Jul 2024 18:01:53 +0000 (19:01 +0100)] 
MIPS/opcodes: Reorder coprocessor moves alphabetically

A number of coprocessor move encodings have been randomly sprinkled over
the regular MIPS and microMIPS opcode tables rather than where they'd be
expected following the alphabetic order.  Fix the ordering, taking into
account precedence where it has to be observed for correct disassembly.
No functional change.

11 months agoMIPS/opcodes: Make AL a shorthand for INSN2_ALIAS
Maciej W. Rozycki [Fri, 19 Jul 2024 18:01:52 +0000 (19:01 +0100)] 
MIPS/opcodes: Make AL a shorthand for INSN2_ALIAS

Make AL a shorthand for INSN2_ALIAS with the regular MIPS and microMIPS
opcode tables, just as with the MIPS16 opcode table, and use it
throughout.  No functional change.

11 months agoMIPS/opcodes: Rename the AL membership shorthand to ALX
Maciej W. Rozycki [Fri, 19 Jul 2024 18:01:52 +0000 (19:01 +0100)] 
MIPS/opcodes: Rename the AL membership shorthand to ALX

Make room for AL as a shorthand for INSN2_ALIAS with the regular MIPS
opcode table, just as with the MIPS16 opcode table.  No functional
change.

11 months agoMIPS/opcodes: Remove the regular MIPS "+t" operand code
YunQiang Su [Fri, 19 Jul 2024 18:01:52 +0000 (19:01 +0100)] 
MIPS/opcodes: Remove the regular MIPS "+t" operand code

The semantics of the regular MIPS "+t" operand code is exactly the same
as that of the "E" operand code, so replace the former with the latter
in the single MFTC0 instruction with implicit 'sel' == 0 encoding where
it's used, matching the encoding with explicit 'sel' as well as other
instructions.

11 months agoMIPS/opcodes: Output thread context registers numerically with MFTR/MTTR
Maciej W. Rozycki [Fri, 19 Jul 2024 18:01:52 +0000 (19:01 +0100)] 
MIPS/opcodes: Output thread context registers numerically with MFTR/MTTR

We print MFTR and MTTR instructions' thread context register operand in
disassembly using the ABI name the register number would correspond to
should the targeted register be a general-purpose register.

However in most cases it is wrong, because general-purpose registers are
only referred when the 'u' and 'sel' operands are 1 and 0 respectively.
And even in these cases the MFGPR and MTGPR aliases take precedence over
the corresponding generic instruction encodings, so you won't see the
valid case to normally trigger.

Conversely decoding the thread context register operand numerically is
always valid, so switch to using it.  Adjust test coverage accordingly.

11 months agoMIPS/opcodes: Discard unused OP_SH, OP_MASK, and OP_OP macros
Maciej W. Rozycki [Fri, 19 Jul 2024 10:42:16 +0000 (11:42 +0100)] 
MIPS/opcodes: Discard unused OP_SH, OP_MASK, and OP_OP macros

As from commit ab90248154ba ("Add structures to describe MIPS
operands"), <https://sourceware.org/ml/binutils/2013-07/msg00135.html>,
the use of numerous regular MIPS and microMIPS OP_SH and OP_MASK macros
has been removed.

Similarly as from commit c3c0747817f4 ("Use operand structures for
MIPS16"), <https://sourceware.org/ml/binutils/2013-07/msg00136.html>,
the use of numerous MIPS16 OP_SH and OP_MASK macros has been removed.

And as from commit 9e12b7a2b022 ("Rewrite main mips_ip parsing loop"),
<https://sourceware.org/ml/binutils/2013-07/msg00139.html>, none of the
OP_OP macros are used anymore.

Discard all the unused macros then and only keep the small subset that
is still referred.  This simplifies maintenance and removes the need to
keep the artificial arrangement where some regular MIPS and microMIPS
macros expand to 0 and are kept for compatibility with the opposite ISA
mode only, as it used to be required before the commit referred.

11 months agoMIPS/opcodes: Correct documentation for R6 operand types
Maciej W. Rozycki [Fri, 19 Jul 2024 10:42:16 +0000 (11:42 +0100)] 
MIPS/opcodes: Correct documentation for R6 operand types

The "-t", "-u", "-v", and "-w" operand types refer 'rt' operand, which
is the target register rather than the source register.  Additionally
the "-x" and "-y" R6 operand types refer 'rs' rather than 'rt' operand
of the BOVC/BNVC and the BEQC/BNEC instructions respectively.  Also the
"-x" operand type does not permit 'rs' to be the same as 'rt'.

Correct inline documentation in opcode/mips.h accordingly.

11 months agoMIPS/opcodes: Exclude $0 from "-x" R6 operand type
Maciej W. Rozycki [Fri, 19 Jul 2024 10:42:16 +0000 (11:42 +0100)] 
MIPS/opcodes: Exclude $0 from "-x" R6 operand type

The "-x" operand type is used for the reverse encoding of the BOVC and
BNVC instructions, where 'rs' and 'rt' have been supplied as the second
and the first operand respectively rather than the order the instruction
expects.

In this case we require the register associated with the "-x" operand to
have a higher number than the register associated with the preceding "t"
operand, which precludes the use of $0.  The case where 'rs' and 'rt'
both refer to the same register is handled by the straight encoding of
the BOVC and BNVC instructions, which come in the opcode table ahead of
the corresponding reverse encoding.

Therefore clear the ZERO_OK flag for the "-x" operand.  No need for an
extra test case as the encodings involved are already covered by "r6"
and its associated GAS tests.

11 months agoSparc: relax gas testsuite whitespace expectations
Jan Beulich [Fri, 19 Jul 2024 09:58:58 +0000 (11:58 +0200)] 
Sparc: relax gas testsuite whitespace expectations

In a subsequent change the scrubber is going to be changed to retain
further whitespace. Test case expectations generally would better not
depend on the specific whitespace treatment by the scrubber, unless of
course a test is specifically about it. Adjust relevant test cases to
permit blanks where those will subsequently appear.

11 months agoTilePro: correct macro use in gas testsuite
Jan Beulich [Fri, 19 Jul 2024 09:58:26 +0000 (11:58 +0200)] 
TilePro: correct macro use in gas testsuite

Whitespace in macro arguments either needs quoting / parenthesizing to
reliably not be mistaken for an argument separator, or respective macro
parameters need to be marked as covering all remaining arguments. The
latter appears more appropriate (and far less intrusive) here.

11 months agoMIPS: correct macro use in gas and ld testsuites
Jan Beulich [Fri, 19 Jul 2024 09:58:04 +0000 (11:58 +0200)] 
MIPS: correct macro use in gas and ld testsuites

Whitespace in macro arguments either needs quoting / parenthesizing to
reliably not be mistaken for an argument separator, or respective macro
parameters need to be marked as covering all remaining arguments. The
former appears more appropriate here, as the macro parameters already
have ":req".

11 months agoia64: correct macro use in gas testsuite
Jan Beulich [Fri, 19 Jul 2024 09:57:12 +0000 (11:57 +0200)] 
ia64: correct macro use in gas testsuite

Whitespace in macro arguments either needs quoting / parenthesizing to
reliably not be mistaken for an argument separator, or respective macro
parameters need to be marked as covering all remaining arguments. The
latter appears more appropriate here.

11 months agobfin: drop _ASSIGN_BANG
Jan Beulich [Fri, 19 Jul 2024 09:56:46 +0000 (11:56 +0200)] 
bfin: drop _ASSIGN_BANG

A few testcases demonstrate that "=!" isn't supposed to be an
individual token, since "= !" is used in a number of places. So far
lexing that to a single token worked because of the scrubber being
overly aggressive in removing whitespace. As that's going to change,
replace uses by separate ASSIGN and BANG.

11 months agobfin: correct macro use in gas testsuite
Jan Beulich [Fri, 19 Jul 2024 09:56:20 +0000 (11:56 +0200)] 
bfin: correct macro use in gas testsuite

Whitespace in macro arguments either needs quoting / parenthesizing to
reliably not be mistaken for an argument separator, or respective macro
parameters need to be marked as covering all remaining arguments. The
latter really isn't an option here.

11 months agoArm: correct macro use in gas testsuite
Jan Beulich [Fri, 19 Jul 2024 09:55:54 +0000 (11:55 +0200)] 
Arm: correct macro use in gas testsuite

The way the inner macro invocations are written doesn't quite work as
expected (and would actually break subsequently): Due to overly
aggressive removal of whitespace by the scrubber, the incoming \sym and
\offset arguments actually get concatenated; an empty 3rd argument is
being passed to ldrtest2. That just so happened to work as intended; any
use of \offset alone would have exposed the problem. Quote the 3rd
argument, thus retaining enough whitespace to be independent of scrubber
internals.

11 months agogas: adjust impossible/bogus M68K/MRI special case when scrubbing
Jan Beulich [Fri, 19 Jul 2024 09:54:45 +0000 (11:54 +0200)] 
gas: adjust impossible/bogus M68K/MRI special case when scrubbing

State 1 is uniformly handled further up. And it is highly questionable
that in state 10 (i.e. after having seen not only a possible label, but
also an opcode), which is about to go away anyway, a line comment char
could still be meant to take effect. With the state checking dropped,
the immediately preceding logic can then also be simplified.

11 months agogas: consistently drop trailing whitespace when scrubbing
Jan Beulich [Fri, 19 Jul 2024 09:54:09 +0000 (11:54 +0200)] 
gas: consistently drop trailing whitespace when scrubbing

From especially the checks for the two separator forms it appears to
follow that the construct being touched is about trailing whitespace. In
such a case, considering that for many targets ordinary and line comment
chars overlap, take into account that line comment chars override
ordinary ones in lex[] (logic elsewhere in do_scrub_chars() actually
depends on that ordering, and also accounts for this overriding).

Plus of course IS_NEWLINE() would better also be consulted. Note also
that the DOUBLESLASH_LINE_COMMENTS change should generally have no
effect just yet; it's a prereq for a later change but better fits here.

Leave respective comments as well, and update documentation to correct
which comment form is actually replaced by a single blank (i.e. neither
the ones starting with what {,tc_}comment_chars[] has nor the ones
starting with what line_comment_chars[] has).

11 months agogas: drop tic6x scrubber special case
Jan Beulich [Fri, 19 Jul 2024 09:53:24 +0000 (11:53 +0200)] 
gas: drop tic6x scrubber special case

Two successive PUT() without a state change in between can't be right:
The first PUT() may take the "goto tofull" path, leading to the
subsequent character being processed later in the previously set state
(1 in this case), rather than the state we were in upon entry to the
switch() (13 in this case).

However, the original purpose of that logic appears to be to not mistake
"|| ^" for "||^". This effect, sadly, looks to not have been achieved.
Therefore drop the special case altogether; something that actually
achieves the (presumably) intended effect may then be introduced down
the road.

11 months agogas: pre-init the scrubber's lex[]
Jan Beulich [Fri, 19 Jul 2024 09:52:50 +0000 (11:52 +0200)] 
gas: pre-init the scrubber's lex[]

While we can't - unlike an old comment suggests - do this fully, we can
certainly do part of this at compile time.

Since it's adjacent, also drop the unnecessary forward declaration of
process_escape().

11 months agox86: accept whitespace inside curly braces
Jan Beulich [Fri, 19 Jul 2024 09:52:21 +0000 (11:52 +0200)] 
x86: accept whitespace inside curly braces

Other than documented /**/ comments currently aren't really converted to
a single space, at least not for x86 in its most common configurations.
That'll be fixed subsequently, at which point blanks may appear where so
far none were expected. Furthermore not permitting blanks immediately
inside curly braces wasn't quite logical anyway - such constructs are
composite ones, and hence components ought to have been permitted to be
separated by whitespace from the very beginning.

With this we also don't care anymore whether the scrubber would remove
whitespace around curly braces, so move them from extra_symbol_chars[]
to operand_special_chars[].

Note: The new testcase doesn't actually exercise much (if any) of the
added code. It is being put in place to ensure that subsequently, when
that code actually comes into play, behavior remains the same.

11 months agox86: undo '{' being a symbol-start character
Jan Beulich [Fri, 19 Jul 2024 09:44:07 +0000 (11:44 +0200)] 
x86: undo '{' being a symbol-start character

Having it that way has undue side effects, in permitting not only
pseudo-prefixes to be parsed correctly, but also permitting odd symbol
names which ought to be possible only when quoted.  Borrow what other
architectures do: Put in place an "unrecognized line" hook to parse off
any pseudo prefixes, while using the "start of line" hook to reject ones
not actually followed by an insn. For that parsing re-use parse_insn()
in yet a slightly different mode (dealing with only pseudo-prefixes).

With that, pp may no longer be cleared from init_globals(), but instead
needs clearing after a line was fully processed. Since md_assemble() has
pretty many return paths, convert that into a local helper, with a
trivial wrapper around it.

Similarly pp may no longer be updated (by check_register()) when
processing anything other than insn operands. To be able to (easily)
recognize the case, clear current_templates.start when done with an insn
(or with .insn).

11 months agox86: split pseudo-prefix state from i386_insn
Jan Beulich [Fri, 19 Jul 2024 09:43:37 +0000 (11:43 +0200)] 
x86: split pseudo-prefix state from i386_insn

Subsequently we will want to update that ahead of md_assemble(), with
that function needing to take into account such earlier updating.
Therefore it'll want resetting separately from i.

11 months agox86/APX: add CMPcc/CTESTcc cases to noreg64 tests
Jan Beulich [Fri, 19 Jul 2024 08:54:22 +0000 (10:54 +0200)] 
x86/APX: add CMPcc/CTESTcc cases to noreg64 tests

This was missed when support for the insns was added. Just like for
DATA16, in

rex64 neg (%rax)
rex64 neg (%r16)
rex64 {nf} neg (%rax)

it is not logical why the last one shouldn't be permitted. Bypassing
that check requires other adjustments, though, to actually properly
consume (and then squash) the prefix.

11 months agobfin: free the allocated memory
zhangxianting [Fri, 19 Jul 2024 08:53:12 +0000 (10:53 +0200)] 
bfin: free the allocated memory

11 months agoMIPS/GAS/testsuite: Also verify trap expansions of multiplication macros
Maciej W. Rozycki [Fri, 19 Jul 2024 08:42:56 +0000 (09:42 +0100)] 
MIPS/GAS/testsuite: Also verify trap expansions of multiplication macros

Provide 'mul' test variants for trap expansions as requested by the
'-trap' command-line option, and run them across all the compatible
architectures.

11 months agoMIPS/GAS/testsuite: Split mul test into 32-bit and 64-bit parts
Maciej W. Rozycki [Fri, 19 Jul 2024 08:42:56 +0000 (09:42 +0100)] 
MIPS/GAS/testsuite: Split mul test into 32-bit and 64-bit parts

Enable full 32-bit and 64-bit multiplication macro verification, by
splitting the 'mul' test into two parts respectively, and run them
across all the compatible architectures.

11 months agoMIPS/GAS/testsuite: Run the mul macro test across architectures
Maciej W. Rozycki [Fri, 19 Jul 2024 08:42:56 +0000 (09:42 +0100)] 
MIPS/GAS/testsuite: Run the mul macro test across architectures

The multiplication macros expand differently based on the ISA chosen, so
run the 'mul' macro test across compatible architectures, adopting the
'mul-ilocks' test orphaned by commit 23fce1e31156 ("MIPS16 intermix test
failure"), <https://sourceware.org/ml/binutils/2009-01/msg00335.html>,
and providing coverage for the expansion variants.

Only run from MIPS III up for now and remove the ISA override from the
source, so that the 64-bit instructions are covered for individual
64-bit architectures.

11 months agoMIPS/GAS/testsuite: Also verify trap expansions of division macros
Maciej W. Rozycki [Fri, 19 Jul 2024 08:42:56 +0000 (09:42 +0100)] 
MIPS/GAS/testsuite: Also verify trap expansions of division macros

Provide 'div' test variants for trap expansions as requested by the
'-trap' command-line option, and run them across all the compatible
architectures.

11 months agoMIPS/GAS/testsuite: Split div test into 32-bit and 64-bit parts
Maciej W. Rozycki [Fri, 19 Jul 2024 08:42:56 +0000 (09:42 +0100)] 
MIPS/GAS/testsuite: Split div test into 32-bit and 64-bit parts

Enable full 32-bit and 64-bit division macro verification, by splitting
the 'div' test into two parts respectively, and run them across all the
compatible architectures.

11 months agoMIPS/GAS/testsuite: Run the div macro test across architectures
Maciej W. Rozycki [Fri, 19 Jul 2024 08:42:56 +0000 (09:42 +0100)] 
MIPS/GAS/testsuite: Run the div macro test across architectures

The division macros expand differently depending on the ISA selected, so
run the 'div' macro test across compatible architectures, adopting the
'div-ilocks' test orphaned by commit 23fce1e31156 ("MIPS16 intermix test
failure"), <https://sourceware.org/ml/binutils/2009-01/msg00335.html>,
and providing coverage for the expansion variants.

Only run from MIPS III up for now and remove the ISA override from the
source, so that the 64-bit instructions are covered for individual
64-bit architectures.

11 months agoMIPS/GAS: Handle --trap command-line option dynamically
Maciej W. Rozycki [Fri, 19 Jul 2024 08:42:56 +0000 (09:42 +0100)] 
MIPS/GAS: Handle --trap command-line option dynamically

We have an ISA check for the '--trap' command-line option that reports
its incompatibility with the MIPS I architecture.  It doesn't prevent
trap instructions from being enabled though, so when attempt is made to
emit one in an expansion of one of the division or multiplication macros
an assertion failure triggers:

.../gas/testsuite/gas/mips/brtr-opt.s: Assembler messages:
.../gas/testsuite/gas/mips/brtr-opt.s:3: Error: trap exception not supported at ISA 1
.../gas/testsuite/gas/mips/brtr-opt.s:9: Warning: divide by zero
.../gas/testsuite/gas/mips/brtr-opt.s:9: Internal error in macro_build at .../gas/config/tc-mips.c:9064.
Please report this bug.

The same assertion failure triggers without an earlier error message
when the initial ISA is compatible with the '--trap', however at the
time an attempt is made to emit a trap instruction from a division or
multiplication macro the ISA has been changed by a '.set' pseudo-op to
an incompatible one.

With the way the situations are mishandled it seems unlikely that anyone
relies on the current semantics and a sane approach is to decide on the
fly according to the currently selected ISA as to whether to emit trap
or breakpoint instructions in the case where '--trap' has been used.

Change our code to do so then and clarify that in the manual, which is
not explicit about how '--trap' is handled with a changing ISA.  Mention
the change in NEWS too since it's a applies to a user option.

11 months agoMIPS/GAS/testsuite: Add R10000 CPU architecture
Maciej W. Rozycki [Fri, 19 Jul 2024 08:42:56 +0000 (09:42 +0100)] 
MIPS/GAS/testsuite: Add R10000 CPU architecture

Add a fully interlocked MIPS IV CPU so that we can have coverage for
MIPS IV instruction sequences with and without instruction separation
required for a HI/LO data anti-dependency.

11 months agoMIPS/GAS/testsuite: Reorder R5900 CPU architecture definition
Maciej W. Rozycki [Fri, 19 Jul 2024 08:42:56 +0000 (09:42 +0100)] 
MIPS/GAS/testsuite: Reorder R5900 CPU architecture definition

The R5900 CPU architecture is based on MIPS III, so move it ahead of
MIPS IV CPU architecture definitions.  No functional change.

11 months agogas: aarch64: testsuite: add new tests for SCFI
Indu Bhagat [Fri, 19 Jul 2024 03:24:44 +0000 (20:24 -0700)] 
gas: aarch64: testsuite: add new tests for SCFI

Similar to the x86_64 testcases, some .s files contain the corresponding
CFI directives.  This helps in validating the synthesized CFI by running
those tests with and without the --scfi=experimental command line
option.

GAS issues some diagnostics, enabled by default, with
--scfi=experimental.  The diagnostics have been added with an intent to
help user correct inadvertent errors in their hand-written asm.  An
error is issued when GAS finds that input asm is not amenable to
accurate CFI synthesis.  The existing scfi-diag-*.s tests in the
gas/testsuite/gas/scfi/x86_64 directory test some SCFI diagnostics
already:

      - (#1) "Warning: SCFI: Asymetrical register restore"
      - (#2) "Error: SCFI: usage of REG_FP as scratch not supported"
      - (#3) "Error: SCFI: unsupported stack manipulation pattern"
      - (#4) "Error: untraceable control flow for func 'XXX'"

In the newly added aarch64 testsuite, further tests for additional
diagnostics have been added:
 - scfi-diag-1.s in this patch highlights an aarch64-specific diagnostic:
   (#5) "Warning: SCFI: ignored probable save/restore op with reg offset"

Additionally, some testcases are added to showcase the (currently)
unsupported patterns, e.g., scfi-unsupported-1.s
        mov     x16, 4384
        sub     sp, sp, x16

gas/testsuite/:
* gas/scfi/README: Update comment to include aarch64.
* gas/scfi/aarch64/scfi-aarch64.exp: New file.
* gas/scfi/aarch64/ginsn-arith-1.l: New test.
* gas/scfi/aarch64/ginsn-arith-1.s: New test.
* gas/scfi/aarch64/ginsn-cofi-1.l: New test.
* gas/scfi/aarch64/ginsn-cofi-1.s: New test.
* gas/scfi/aarch64/ginsn-ldst-1.l: New test.
* gas/scfi/aarch64/ginsn-ldst-1.s: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-1.d: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-1.l: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-1.s: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-2.d: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-2.l: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-2.s: New test.
* gas/scfi/aarch64/scfi-cb-1.d: New test.
* gas/scfi/aarch64/scfi-cb-1.l: New test.
* gas/scfi/aarch64/scfi-cb-1.s: New test.
* gas/scfi/aarch64/scfi-cfg-1.d: New test.
* gas/scfi/aarch64/scfi-cfg-1.l: New test.
* gas/scfi/aarch64/scfi-cfg-1.s: New test.
* gas/scfi/aarch64/scfi-cfg-2.d: New test.
* gas/scfi/aarch64/scfi-cfg-2.l: New test.
* gas/scfi/aarch64/scfi-cfg-2.s: New test.
* gas/scfi/aarch64/scfi-cfg-3.d: New test.
* gas/scfi/aarch64/scfi-cfg-3.l: New test.
* gas/scfi/aarch64/scfi-cfg-3.s: New test.
* gas/scfi/aarch64/scfi-cfg-4.l: New test.
* gas/scfi/aarch64/scfi-cfg-4.s: New test.
* gas/scfi/aarch64/scfi-cond-br-1.d: New test.
* gas/scfi/aarch64/scfi-cond-br-1.l: New test.
* gas/scfi/aarch64/scfi-cond-br-1.s: New test.
* gas/scfi/aarch64/scfi-diag-1.l: New test.
* gas/scfi/aarch64/scfi-diag-1.s: New test.
* gas/scfi/aarch64/scfi-diag-2.l: New test.
* gas/scfi/aarch64/scfi-diag-2.s: New test.
* gas/scfi/aarch64/scfi-diag-3.l: New test.
* gas/scfi/aarch64/scfi-diag-3.s: New test.
* gas/scfi/aarch64/scfi-ldrp-1.d: New test.
* gas/scfi/aarch64/scfi-ldrp-1.l: New test.
* gas/scfi/aarch64/scfi-ldrp-1.s: New test.
* gas/scfi/aarch64/scfi-ldrp-2.d: New test.
* gas/scfi/aarch64/scfi-ldrp-2.l: New test.
* gas/scfi/aarch64/scfi-ldrp-2.s: New test.
* gas/scfi/aarch64/scfi-ldstnap-1.d: New test.
* gas/scfi/aarch64/scfi-ldstnap-1.l: New test.
* gas/scfi/aarch64/scfi-ldstnap-1.s: New test.
* gas/scfi/aarch64/scfi-strp-1.d: New test.
* gas/scfi/aarch64/scfi-strp-1.l: New test.
* gas/scfi/aarch64/scfi-strp-1.s: New test.
* gas/scfi/aarch64/scfi-strp-2.d: New test.
* gas/scfi/aarch64/scfi-strp-2.l: New test.
* gas/scfi/aarch64/scfi-strp-2.s: New test.
* gas/scfi/aarch64/scfi-unsupported-1.l: New test.
* gas/scfi/aarch64/scfi-unsupported-1.s: New test.
* gas/scfi/aarch64/scfi-unsupported-2.l: New test.
* gas/scfi/aarch64/scfi-unsupported-2.s: New test.

11 months agogas: aarch64: add experimental support for SCFI
Indu Bhagat [Fri, 19 Jul 2024 03:24:38 +0000 (20:24 -0700)] 
gas: aarch64: add experimental support for SCFI

For synthesizing CFI (SCFI) for hand-written asm, the SCFI machinery in
GAS works on the generic GAS insns (ginsns).  This patch adds support in
the aarch64 backend to create ginsns for a subset of the supported
machine instructions.  The subset includes the minimal necessary
instructions to ensure SCFI correctness:

- Any potential register saves and unsaves.  Hence, process instructions
  belonging to a variety of iclasses involving str, ldr, stp, ldp.
- Any change of flow instructions.  This includes all conditional and
  unconditional branches, call (bl, blr, etc.) and return.
- Most importantly, any instruction that could affect the two registers
  of interest: REG_SP, REG_FP.  This set includes all pre-indexed and
  post-indexed memory operations, with writeback, on the stack.  This
  set must also include other instructions (e.g., arithmetic insns)
  where the destination register is one of the afore-mentioned registers.

With respect to callee-saved registers in Aarch64, FP/Advanced SIMD
registers D8-D15 are included along with the relevant GPRs.  Calculating
offsets for loads and stores especially for Q registers needs special
attention here.

As an example,
   str q8, [sp, #16]
On big-endian:
   STR Qn stores as a 128-bit integer (MSB first), hence, should record
   D8 as being saved at sp+24 rather than sp+16.
On little-endian:
   should record D8 as being saved at sp+16

D8-D15 are the low 64 bits of Q8-Q15, and of Z8-Z15 if SVE is used;
hence, they remain "interesting" for SCFI purposes in such cases.  A CFI
save slot always represents the low 64 bits, regardless of whether a
save occurs on D, Q or Z registers.  Currently, the ginsn creation
machinery can handle D and Q registers on little-endian and big-endian.

Apart from creating ginsn, another key responsibility of the backend is
to make sure there are safeguards in place to detect and alert if an
instruction of interest may have been skipped.  This is done via
aarch64_ginsn_unhandled () (similar to the x86 backend).  This function
, hence, is also intended to alert when future ISA changes may otherwise
render SCFI results incorrect, because of missing ginsns for the newly
added machine instructions.

At this time, becuase of the complexities wrt endianness in handling Z
register usage, skip sve_misc opclass altogether for now.  The SCFI
machinery will error out (using the aarch64_ginsn_unhandled () code
path) though if Z register usage affects correctness.

The current SCFI machinery does not currently synthesize the
PAC-related, aarch64-specific CFI directives: .cfi_b_key_frame.  The
support for this is planned for near future.

SCFI is enabled for ELF targets only.

gas/
* config/tc-aarch64-ginsn.c: New file.
* config/tc-aarch64.c (md_assemble): Include tc-aarch64-ginsn.c
file.  Invoke aarch64_ginsn_new.
* config/tc-aarch64.h (TARGET_USE_GINSN): Define for SCFI
enablement.
(TARGET_USE_SCFI): Likewise.
(SCFI_MAX_REG_ID): New definition.
(REG_FP): Likewise.
(REG_LR): Likewise.
(REG_SP): Likewise.
(SCFI_INIT_CFA_OFFSET): Likewise.
(SCFI_CALLEE_SAVED_REG_P): Likewise.
(aarch64_scfi_callee_saved_p): New declaration.

11 months agoopcodes: aarch64: enforce checks on subclass flags in aarch64-gen.c
Indu Bhagat [Fri, 19 Jul 2024 03:24:35 +0000 (20:24 -0700)] 
opcodes: aarch64: enforce checks on subclass flags in aarch64-gen.c

Enforce some checks on the newly added subclass flags:
  - If a subclass is set of one insn of an iclass, every insn of that
    iclass must have non-zero subclass field.
  - For all other iclasses, the subclass bits are zero for all insns.

include/
        * opcode/aarch64.h (enum aarch64_insn_class): Identify the
maximum iclass enum value.

opcodes/
        * aarch64-gen.c (iclass_has_subclasses_p): New array of bool.
        (read_table): Enforce checks on subclass flags.

11 months agoopcodes: aarch64: denote subclasses for insns of iclass dp_2src
Indu Bhagat [Fri, 19 Jul 2024 03:24:30 +0000 (20:24 -0700)] 
opcodes: aarch64: denote subclasses for insns of iclass dp_2src

For detecting irg, add a subclass to identify it in the set of
instructions of iclass dp_2src.

opcodes/
* aarch64-tbl.h: Add subclass flag F_DP_TAG_ONLY for irg insn.

11 months agoopcodes: aarch64: add flags to denote subclasses of uncond branches
Indu Bhagat [Fri, 19 Jul 2024 03:24:26 +0000 (20:24 -0700)] 
opcodes: aarch64: add flags to denote subclasses of uncond branches

Use the two new subclass flags: F_BRANCH_CALL, F_BRANCH_RET, to indicate
call to and return from subroutine respectively.

opcodes/
* aarch64-tbl.h: Use the new F_BRANCH_* flags.

11 months agoopcodes: aarch64: add flags to denote subclasses of arithmetic insns
Indu Bhagat [Fri, 19 Jul 2024 03:24:22 +0000 (20:24 -0700)] 
opcodes: aarch64: add flags to denote subclasses of arithmetic insns

Use the three new subclass flags: F_ARITH_ADD, F_ARITH_SUB,
F_ARITH_MOV, to indicate add, sub and mov ops respectively.

These flags for subclasses will later be used for SCFI purposes to
create appropriate ginsns.  At this time, only those iclasses relevant
to SCFI have the new subclass flags specified.

For addg and subg insns, F_SUBCLASS_OTHER is more suitable because these
operations do more than just simple add or sub.

opcodes/
    * aarch64-tbl.h: Use the new F_ARITH_* flags.

11 months agoopcodes: aarch64: add flags to denote subclasses of ldst insns
Indu Bhagat [Fri, 19 Jul 2024 03:24:16 +0000 (20:24 -0700)] 
opcodes: aarch64: add flags to denote subclasses of ldst insns

The existing iclass information tells us the general shape and purpose
of the instructions.  In some cases, however, we need to further disect
the iclass on the basis of other finer-grain information.  E.g., for the
purpose of SCFI, we need to know whether a given insn with iclass
of ldst_* is a load or a store.

At the moment, specify subclasses for only those iclasses relevant to
SCFI: ldst_imm9, ldst_pos, ldstpair_indexed, ldstpair_off and
ldstnapair_offs.

Some insns are best tagged with F_SUBCLASS_OTHER rather than F_LDST_LOAD
or F_LDST_STORE:
  - stg* ops (as they store tag only),
  - prfm,
  - ldpsw, ldrsw (32-bit loads with signed extended value.  Not useful
    for restore operations in context of SCFI.)
  - Use F_SUBCLASS_OTHER for all QL_LDST_R8 and QL_LDST_R16 operands.
    Also use F_SUBLASS_OTHER for strb/ldrb, strh/ldrh opcodes.
    These are not full loads and stores and cannot be allowed for
    register save / restore for the purpose of SCFI.

opcodes/
    * aarch64-tbl.h: Use the new F_LDST_* flags.

11 months agoinclude: opcodes: aarch64: define new subclasses
Indu Bhagat [Fri, 19 Jul 2024 03:24:10 +0000 (20:24 -0700)] 
include: opcodes: aarch64: define new subclasses

The existing iclass information tells us the general shape and purpose
of the instructions.  In some cases, however, we need to further disect
the iclass on the basis of other finer-grain information.  E.g., for the
purpose of SCFI, we need to know whether a given insn with iclass of
ldst_* is a load or a store.  Similarly, whether a particular arithmetic
insn is an add or sub or mov, etc.

This patch defines new flags to demarcate the insns.  Also provide an
access function for subclass lookup.

Later, we will enforce (in aarch64-gen.c) that if an iclass has at least
one instruction with a non-zero subclass, all instructions of the iclass
must have a non-zero subclass information.  If none of the defined
subclasses are applicable (or not required for SCFI purposes),
F_SUBCLASS_OTHER can be used for such instructions.

include/
        * opcode/aarch64.h (F_SUBCLASS): New flag.
        (F_SUBCLASS_OTHER): Likewise.
        (F_LDST_LOAD): Likewise.
        (F_LDST_STORE): Likewise.
        (F_ARITH_ADD): Likewise.
        (F_ARITH_SUB): Likewise.
        (F_ARITH_MOV): Likewise.
        (F_BRANCH_CALL): Likewise.
        (F_BRANCH_RET): Likewise.
(F_DP_TAG_ONLY): Likewise.
        (aarch64_opcode_subclass_p): New definition.

11 months agogas: scfi: make scfi_state_restore_reg function more precise
Indu Bhagat [Fri, 19 Jul 2024 03:24:00 +0000 (20:24 -0700)] 
gas: scfi: make scfi_state_restore_reg function more precise

When the SCFI machinery detects that a register has been restored from
stack, it makes some state changes in the SCFI state object.

Prior to the patch, scfi_state_restore_reg () was setting a value of
(reg, CFI_IN_REG) for (base, state) respectively.  This was causing
issues in the cmp_scfi_state () function:
  - The default state of all (callee-saved) regs at the beginning of
    function is set to (0, CFI_UNDEFINED).
  - If a register is saved and restored on some control path, the state
    of reg is (reg, CFI_IN_REG) on that path.
  - On another control path where the register was perhaps not
    used (or saved/restored on stack) remains (0, CFI_UNDEFINED).
  - The two states should be treated equal, however, at the point in
    program after the register has been restored.

Fix this by resetting the state to (0, CFI_UNDEFINED) in
scfi_state_restore_reg ().

A testcase (scfi-cfg-4.s) for this is added in a subsequent commit.

gas/
        * scfi.c (scfi_state_restore_reg): Reset to 0, CFI_UNDEFINED
for base, state.

11 months agoAutomatic date update in version.in
GDB Administrator [Fri, 19 Jul 2024 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

11 months agogas: minor reformatting in command line help and doc
Matthieu Longo [Thu, 16 May 2024 11:12:24 +0000 (12:12 +0100)] 
gas: minor reformatting in command line help and doc

- help message: add a comma between the short and long option
- as doc:
  - brief summary of how to invoke gas: separate [-w] [-x] on a new line as those
  two options have nothing to do with the warning options.
  - reordering of the warning options to have the same order as the listing.
  - no-warn option description: change an "and" to a "or", as it is either the short
  or long option to use, but not both at the same time.
- remove trailing whitespaces.

11 months agogdb: check for multiple matching build-id files
Andrew Burgess [Tue, 21 May 2024 08:57:49 +0000 (09:57 +0100)] 
gdb: check for multiple matching build-id files

Within the debug-file-directory GDB looks for the existence of a
.build-id directory.

Within the .build-id directory GDB looks for files with the form:

  .build-id/ff/4b4142d62b399499844924d53e33d4028380db.debug

which contain the debug information for the objfile with the build-id
ff4b4142d62b399499844924d53e33d4028380db.

There appear to be two strategies for populating the .build-id
directory.  Ubuntu takes the approach of placing the actual debug
information in this directory, so
4b4142d62b399499844924d53e33d4028380db.debug is an actual file
containing the debug information.

Fedora, RHEL, and SUSE take a slightly different approach, placing the
debug information elsewhere, and then creating symlinks in the
.build-id directory back to the original debug information file.  The
actual debug information is arranged in a mirror of the filesystem
within the debug directory, as an example, if the debug-file-directory
is /usr/lib/debug, then the debug information for /bin/foo can be
found in /usr/lib/debug/bin/foo.debug.

Where this gets interesting is that in some cases a package will
install a single binary with multiple names, in this case a single
binary will be install with either hard-links, or symlinks providing
the alternative names.

The debug information for these multiple binaries will then be placed
into the /usr/lib/debug/ tree, and again, links are created so a
single file can provide debug information for each of the names that
binary presents as.  An example file system might look like this (the
[link] could be symlinks, but are more likely hard-links):

  /bin/
    foo
    bar -> foo [ HARD LINK ]
    baz -> foo [ HARD LINK ]
  /usr/
    lib/
      debug/
        bin/
  foo.debug
  bar.debug -> foo.debug [ HARD LINK ]
  baz.debug -> foo.debug [ HARD LINK ]

In the .build-id tree though we have a problem.  Do we have a single
entry that links to one of the .debug files?  This would work; a user
debugging any of the binaries will find the debug information based on
the build-id, and will get the correct information, after all the
.debug files are identical (same file linked together).  But there is
one problem with this approach.

Sometimes, for *reasons* it's possible that one or more the linked
binaries might get removed, along with its associated debug
information.  I'm honestly not 100% certain under what circumstances
this can happen, but what I observe is that sometime a single name for
a binary, and its corresponding .debug entry, can be missing.  If this
happens to be the entry that the .build-id link is pointing at, then
we have a problem.  The user can no longer find the debug information
based on the .build-id link.

The solution that Fedora, RHEL, & SUSE have adopted is to add multiple
entries in the .build-id tree, with each entry pointing to a different
name within the debug/ tree, a sequence number is added to the
build-id to distinguish the multiple entries.  Thus, we might end up
with a layout like this:

  /bin/
    foo
    bar -> foo [ HARD LINK ]
    baz -> foo [ HARD LINK ]
  /usr/
    lib/
      debug/
        bin/
  foo.debug
  bar.debug -> foo.debug [ HARD LINK ]
  baz.debug -> foo.debug [ HARD LINK ]
      .build-id/
        a3/
          4b4142d62b399499844924d53e33d4028380db.debug -> ../../debug/bin/foo.debug [ SYMLINK ]
          4b4142d62b399499844924d53e33d4028380db.1.debug -> ../../debug/bin/bar.debug [ SYMLINK ]
          4b4142d62b399499844924d53e33d4028380db.2.debug -> ../../debug/bin/baz.debug [ SYMLINK ]

With current master GDB, debug information will only ever be looked up
via the 4b4142d62b399499844924d53e33d4028380db.debug link.  But if
'foo' and its corresponding 'foo.debug' are ever removed, then master
GDB will fail to find the debug information.

Ubuntu seems to have a much better approach for debug information
handling; they place the debug information directly into the .build-id
tree, so there only ever needs to be a single entry for any one
build-id.  I wonder if/how they handle the case where multiple names
might share a single .debug file, if one of those names is then
uninstalled, how do they know the .debug file should be retained or
not ... but I assume that problem either doesn't exist or has been
solved.

Anyway, for a while Fedora has carried a patch that handles the
build-id sequence number logic.  What's presented here is inspired by
the Fedora patch, but has some changes to fix some issues.

I'm aware that this is a patch that applies to only some (probably a
minority) of distros.  However, the logic is contained to only a
single function in build-id.c, and isn't too complex, so I'm hoping
that there wont be too many objections.

For distros that don't have build-id sequence numbers there should be
no impact.  The sequence number approach still leaves the first file
without a sequence number, and this is the first file that GDB (after
this patch) checks for.  The new logic only kicks in if the
non-sequence numbered first file exists, but is a symlink to a non
existent file; in this case GDB checks for the sequence numbered files
instead.

Tests are included.

There is a small fix needed for gdb.base/sysroot-debug-lookup.exp,
after this commit GDB now treats a target: sysroot where the target
file system is local to GDB the same as if the sysroot had no target:
prefix.  The consequence of this is that GDB now resolves a symlink
back to the real filename in the sysroot-debug-lookup.exp test where
it didn't previously.  As this behaviour is inline with the case where
there is no target: prefix I think this is fine.

11 months agogdbserver: add gdbserver support for vFile::stat packet
Andrew Burgess [Tue, 21 May 2024 14:58:41 +0000 (15:58 +0100)] 
gdbserver: add gdbserver support for vFile::stat packet

After the previous two commits, this commit adds support for the
vFile::stat packet to gdbserver.  This is pretty similar to the
handling for vFile::fstat, but instead calls 'lstat'.

There's still no users of target_fileio_stat in GDB, that will come in
a later commit.

11 months agogdb: add GDB side target_ops::fileio_stat implementation
Andrew Burgess [Tue, 21 May 2024 14:58:02 +0000 (15:58 +0100)] 
gdb: add GDB side target_ops::fileio_stat implementation

This commit adds the GDB side of target_ops::fileio_stat.  There's an
implementation for inf_child_target, which just calls 'lstat', and
there's an implementation for remote_target, which sends a new
vFile:stat packet.

The new packet is documented.

There's still no users of target_fileio_stat as I have not yet added
support for vFile::stat to gdbserver.  If these packets are currently
sent to gdbserver then they will be reported as not supported and the
ENOSYS error code will be returned.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
11 months agogdb: add target_fileio_stat, but no implementations yet
Andrew Burgess [Tue, 21 May 2024 14:39:37 +0000 (15:39 +0100)] 
gdb: add target_fileio_stat, but no implementations yet

In a later commit I want target_fileio_stat, that is a call that
operates on a filename rather than an open file descriptor as
target_fileio_fstat does.

This commit adds the initial framework for target_fileio_stat, I've
added the top level target function and the virtual target_ops methods
in the target_ops base class.

At this point no actual targets override target_ops::fileio_stat, so
any attempts to call this function will return ENOSYS error code.

11 months agoX86: Update gas/NEWS for Intel APX.
Cui, Lili [Thu, 18 Jul 2024 07:56:08 +0000 (15:56 +0800)] 
X86: Update gas/NEWS for Intel APX.

gas/ChangeLog:

        * NEWS: Added "APX_F is fully supportted" to gas/NEWS.

11 months agoAutomatic date update in version.in
GDB Administrator [Thu, 18 Jul 2024 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

11 months ago[gdb/testsuite] Fix gdb.arch/arm-pseudo-unwind.exp with unix/mthumb
Tom de Vries [Wed, 17 Jul 2024 15:04:02 +0000 (17:04 +0200)] 
[gdb/testsuite] Fix gdb.arch/arm-pseudo-unwind.exp with unix/mthumb

When running test-case gdb.arch/arm-pseudo-unwind.exp with target board
unix/mthumb, we run into:
...
(gdb) continue^M
Continuing.^M
^M
Program received signal SIGILL, Illegal instruction.^M
0x00400f38 in ?? ()^M
(gdb) FAIL: $exp: continue to breakpoint: continue to callee
...

The test-case attempts to force arm-pseudo-unwind.c to be compiled in arm mode
using additional_flags=-marm, but that's overridden by using target board
unix/mthumb.

This causes function main to be in thumb mode, and consequently function
caller (which is called from main) is is executed as if it's in thumb mode,
while it's actually in arm mode.

Fix this by adding an intermediate function caller_trampoline in
arm-pseudo-unwind.c, and hardcoding it to arm mode using
__attribute__((target("arm"))).

Likewise for test-case gdb.arch/arm-pseudo-unwind-legacy.exp.

Tested on arm-linux.

Approved-By: Luis Machado <luis.machado@arm.com>
11 months agogas: scfi: testsuite: refresh the README
Indu Bhagat [Wed, 17 Jul 2024 06:34:43 +0000 (23:34 -0700)] 
gas: scfi: testsuite: refresh the README

Update some stale text in the README.  Add few more notes to guide
future maintenance of the testsuite.

gas/testsuite/
* gas/scfi/README: Update text.

11 months agoAutomatic date update in version.in
GDB Administrator [Wed, 17 Jul 2024 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

11 months agogdb, gdbserver, gdbsupport: use [[noreturn]] instead of ATTRIBUTE_NORETURN
Simon Marchi [Tue, 16 Jul 2024 20:02:12 +0000 (16:02 -0400)] 
gdb, gdbserver, gdbsupport: use [[noreturn]] instead of ATTRIBUTE_NORETURN

C++ 11 has a built-in attribute for this, no need to use a compat macro.

Change-Id: I90e4220d26e8f3949d91761f8a13cd9c37da3875
Reviewed-by: Lancelot Six <lancelot.six@amd.com>
11 months agogdb: fix indentation in remote.c
Simon Marchi [Tue, 16 Jul 2024 18:05:14 +0000 (14:05 -0400)] 
gdb: fix indentation in remote.c

Change-Id: If344acdf703fdd3892f73f75fc891d5473808b79

11 months agogdb: add ATTRIBUTE_NORETURN to remote_unpush_target
Simon Marchi [Tue, 16 Jul 2024 18:03:27 +0000 (14:03 -0400)] 
gdb: add ATTRIBUTE_NORETURN to remote_unpush_target

My IDE (well, clangd) suggested this.  It doesn't hurt to have it.

Change-Id: If6001983c17dbed3dceebac3078c8deb12c04d6b

11 months ago[gdb/testsuite] Simplify gdb.base/complex-parts.exp
Tom de Vries [Tue, 16 Jul 2024 15:22:04 +0000 (17:22 +0200)] 
[gdb/testsuite] Simplify gdb.base/complex-parts.exp

I noticed a lot of escaping in test-case gdb.base/complex-parts.exp.

Make the test-case more readable by using:
- string_to_regexp, and
- {} instead of "".

Tested on x86_64-linux and aarch64-linux.

11 months agoAutomatic date update in version.in
GDB Administrator [Tue, 16 Jul 2024 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

11 months agogdb: pass program space to overlay_invalidate_all
Simon Marchi [Mon, 15 Jul 2024 15:29:47 +0000 (15:29 +0000)] 
gdb: pass program space to overlay_invalidate_all

Make the current program space bubble up one level.

Change-Id: I5ac1e3290ad266730465cd60aa3672d45ffa6475

11 months agogdb: pass program space to objfile::make
Simon Marchi [Thu, 16 May 2024 21:30:22 +0000 (17:30 -0400)] 
gdb: pass program space to objfile::make

Make the current program space reference bubble up one level.

Change-Id: Iee8b11c853c76e539c991c4785737c69e6a1925c
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
11 months agogdb: pass program space to objfile::objfile
Simon Marchi [Thu, 16 May 2024 21:28:13 +0000 (17:28 -0400)] 
gdb: pass program space to objfile::objfile

Make the current program space reference bubble up one level.

Change-Id: I81e45e89e0cfd87c308f801d49ae811a941348b7
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
11 months agogdb: pass program space to entry_point_address
Simon Marchi [Thu, 16 May 2024 21:04:13 +0000 (17:04 -0400)] 
gdb: pass program space to entry_point_address

Make the current program space reference bubble up one level.

Change-Id: Ifc9b8186abaefb10caf99f79ae09e526fa65c882
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
11 months agogdb: pass program space to entry_point_address_query
Simon Marchi [Thu, 16 May 2024 21:01:47 +0000 (17:01 -0400)] 
gdb: pass program space to entry_point_address_query

Make the current program space bubble up one level.

Change-Id: Ic3ad0869ca1afe41854f605a6f7eb092fca29ff8
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
11 months agogdb: pass program space to objfiles_changed
Simon Marchi [Thu, 16 May 2024 20:59:32 +0000 (16:59 -0400)] 
gdb: pass program space to objfiles_changed

Make the current program space reference bubble up one level.

Change-Id: I9b33c9e0d22c171eb1bb59ce480621b02c7b7bf7
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
11 months agogdb: pass program space to get_current_source_symtab_and_line
Simon Marchi [Thu, 16 May 2024 20:50:22 +0000 (16:50 -0400)] 
gdb: pass program space to get_current_source_symtab_and_line

Make the current program space reference bubble up one level.

Change-Id: I6ba6dc4a2cb188720cbb61b84ab5c954aac105c6
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
11 months agogdb: pass program space to have_{full,partial}_symbols
Simon Marchi [Thu, 16 May 2024 20:37:06 +0000 (16:37 -0400)] 
gdb: pass program space to have_{full,partial}_symbols

Make the current program space reference bubble up one level.

Change-Id: I19c4fc2ca955f9c828ef426a077b43983865697b
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
11 months agogdb: bool-ify a few functions in objfiles.{c,h}
Simon Marchi [Thu, 16 May 2024 20:29:47 +0000 (16:29 -0400)] 
gdb: bool-ify a few functions in objfiles.{c,h}

Change return types to bool, and make a few stylistic adjustments.

Change-Id: I784c3c33af0394a77c25064b06eb3e128e69222f
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
11 months agogdb: pass program space to clear_current_source_symtab_and_line
Simon Marchi [Thu, 16 May 2024 20:21:23 +0000 (16:21 -0400)] 
gdb: pass program space to clear_current_source_symtab_and_line

Make the current program space reference bubble up one level.

Change-Id: I692554474d17e4f4708fd8ad662bf6c0bb964726
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
11 months agogdb: make `program_space::free_all_objfiles` use `this`
Simon Marchi [Thu, 16 May 2024 20:13:20 +0000 (16:13 -0400)] 
gdb: make `program_space::free_all_objfiles` use `this`

Use `this` instead of `current_program_space`.  Presumably, the method
wants to check the solibs of "this" program space, not the current
global program space (although they are likely always the same at the
moment).

Change-Id: Iaf0534f36bfd47c04c53ed0657da332bdb8fb906
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>