]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
4 weeks agogdb: remove some dead code from core_target_open
Andrew Burgess [Wed, 27 Aug 2025 18:51:56 +0000 (19:51 +0100)] 
gdb: remove some dead code from core_target_open

In core_target_open we call target_preopen which pops all targets
above the file_stratum, this will include the core_target, if the core
target is currently loaded.

Currently, the core file BFD is stored in the program_space of an
inferior.  The only way to set the core file BFD is by creating a
core_target (in core_target_open).  And when a core_target is closed
the core file BFD within the program_space is reset to nullptr (see
core_target::close and core_target::clear_core, both in corelow.c).

What this means is that, if there is no core_target loaded then there
will be no core file BFD in the program_space.  And in
core_target_open, after the call to target_preopen, there will be no
core_target loaded, and thus, no core file BFD in the program_space.

There is currently code in core_target_open which checks to see if
there is a core file BFD set in the current program space.  For the
reasons given above, I believe this is dead code and can be removed.

I've added some asserts to validate my assumptions.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/*.exp
Tom de Vries [Thu, 4 Sep 2025 14:15:26 +0000 (16:15 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/*.exp

Fix clean_restart <absolute filename> in gdb.arch/*.exp.

The fixed test-cases are supported on archs sh, ia64, mips, pa and sparc.

I haven't tested these.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/powerpc*.exp
Tom de Vries [Thu, 4 Sep 2025 14:15:26 +0000 (16:15 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/powerpc*.exp

Fix clean_restart <absolute filename> in gdb.arch/powerpc*.exp.

Likewise in gdb.arch/ppc*.exp, gdb.arch/altivec*.exp, gdb.arch/e500*.exp and
gdb.arch/vsx*.exp.

Tested on ppc64le-linux.

The following test-cases only run on 32-bit ppc:
- gdb.arch/e500-abi.exp
- gdb.arch/e500-prologue.exp
- gdb.arch/e500-regs.exp
- gdb.arch/powerpc-aix-prologue.exp
- gdb.arch/powerpc-prologue.exp
- gdb.arch/powerpc-prologue-frame.exp
- gdb.arch/powerpc-trap.exp
so these haven't been tested.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/thumb*.exp
Tom de Vries [Thu, 4 Sep 2025 14:15:26 +0000 (16:15 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/thumb*.exp

Fix clean_restart <absolute filename> in gdb.arch/thumb*.exp.

Likewise in test-case gdb.arch/pr25124.exp.

Tested on arm-linux, target boards unix/-marm and unix/-mthumb.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/arm*.exp
Tom de Vries [Thu, 4 Sep 2025 14:15:26 +0000 (16:15 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/arm*.exp

Fix clean_restart <absolute filename> in gdb.arch/arm*.exp.

Tested on:
- arm-linux, target boards unix/-marm and unix/-mthumb
- aarch64-linux

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/aarch64*.exp
Tom de Vries [Thu, 4 Sep 2025 14:15:26 +0000 (16:15 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/aarch64*.exp

Fix clean_restart <absolute filename> in gdb.arch/aarch64*.exp.

Tested on aarch64-linux, M1 system.

There's a large number (44) of unsupported, for the following reasons:
- allow_aarch64_gcs_tests
- allow_aarch64_mops_tests
- allow_aarch64_sve_tests / target does not support SVE
- memory tagging unsupported

Consequently, we mostly use the simple substitution:
...
clean_restart $binfile
->
clean_restart
gdb_load $binfile
...

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/i386*.exp
Tom de Vries [Thu, 4 Sep 2025 14:15:26 +0000 (16:15 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/i386*.exp

Fix clean_restart <absolute filename> in gdb.arch/i386*.exp.

Tested on x86_64-linux, with target board unix/-m32 and gcc 15.

The only unsupported test-case is gdb.arch/i386-avx512.exp, which isn't
changed by this commit.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/amd64*.exp
Tom de Vries [Thu, 4 Sep 2025 14:15:26 +0000 (16:15 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.arch/amd64*.exp

Fix clean_restart <absolute filename> in gdb.arch/amd64*.exp.

Tested on x86_64-linux, with kernel version 6.16.3.

The only unsupported test-case is gdb.arch/amd64-lam.exp, which isn't changed
by this commit.

4 weeks agoRISC-V: Don't generate R_RISCV_RELATIVE if symbol referenced section is SH_ABS
Nelson Chu [Thu, 21 Aug 2025 04:33:04 +0000 (12:33 +0800)] 
RISC-V: Don't generate R_RISCV_RELATIVE if symbol referenced section is SH_ABS

It's werid if it's absolute symbol but have a relative reloc for got entry
under pie.  So don't generate relative reloc if symbol referenced section is
SH_ABS.  However, x86 allows the absolute symbol defined in linker script has
a relative reloc, not sure if risc-v needs this or not.

4 weeks agoRISC-V: Don't overwrite got entry to zero for IRELATIVE/RELATIVE relocation
Nelson Chu [Thu, 21 Aug 2025 04:33:03 +0000 (12:33 +0800)] 
RISC-V: Don't overwrite got entry to zero for IRELATIVE/RELATIVE relocation

Even the final result is correct since we encode the relocation into r_addend,
so glibc won't need to get the content of got entry when resolving relative
relocation, it still werid that finish_dynamic_symbol cleans what we filled in
the relocate_section.

4 weeks agoRISC-V: Fixed missed GOT relocation against a symbol that has a defined value
Nelson Chu [Thu, 14 Aug 2025 04:01:38 +0000 (12:01 +0800)] 
RISC-V: Fixed missed GOT relocation against a symbol that has a defined value

SImilar to aarch64, commit eac4eb8ecb26

There are two problems when GOT relocation against a symbol that has a defined
value,
1. Pesudo la with pic and pseudo lga lost the relocations.
2. %got_pcrel_hi generates R_RISCV_GOT_HI20 with addend, which is wrong since
   commit 50331d64f108.

The solution is to use deferred_expression for GOT relocation.  Maybe other
relocations also have same problem and need the deferred_expression, but we can
add in the future patches.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.ada
Tom de Vries [Thu, 4 Sep 2025 07:23:13 +0000 (09:23 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.ada

Fix clean_restart <absolute filename> in the test-cases in gdb.ada.

Tested on x86_64-linux with gcc 14.

4 weeks agoAutomatic date update in version.in
GDB Administrator [Thu, 4 Sep 2025 00:00:47 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 weeks agoPR 33360, Correct strings -Ue output
Andrew C Aitchison [Wed, 3 Sep 2025 14:08:33 +0000 (15:08 +0100)] 
PR 33360, Correct strings -Ue output

Signed-off-by: Andrew C Aitchison <andrew@aitchison.me.uk>
4 weeks agomips: remove unnecessary obstack_finish
Alan Modra [Wed, 3 Sep 2025 21:45:28 +0000 (07:15 +0930)] 
mips: remove unnecessary obstack_finish

It isn't necessary to call obstack_finish before obstack_free of an
unwanted string.

* config/tc-mips.c (mips_parse_arguments): Replace obstack_finsih
with obstack_base.

4 weeks agogdb/testsuite] Fix clean_restart <absolute filename> in gdb.compile
Tom de Vries [Wed, 3 Sep 2025 17:49:55 +0000 (19:49 +0200)] 
gdb/testsuite] Fix clean_restart <absolute filename> in gdb.compile

Fix clean_restart <absolute filename> in the test-cases in gdb.compile.

Tested on x86_64-linux, fedora rawhide.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.cp
Tom de Vries [Wed, 3 Sep 2025 16:56:37 +0000 (18:56 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.cp

Fix clean_restart <absolute filename> in the test-cases in gdb.cp.

Tested on x86_64-linux.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.debuginfod
Tom de Vries [Wed, 3 Sep 2025 16:20:47 +0000 (18:20 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.debuginfod

Fix clean_restart <absolute filename> in the test-cases in gdb.debuginfod.

Tested on x86_64-linux.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.disasm
Tom de Vries [Wed, 3 Sep 2025 16:09:41 +0000 (18:09 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.disasm

Fix clean_restart <absolute filename> in the test-cases in gdb.disasm.

The changed test-cases:
- gdb.disasm/am33.exp
- gdb.disasm/hppa.exp
- gdb.disasm/mn10300.exp
- gdb.disasm/sh3.exp
are unsupported for me, but the changes are trivial.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.dwarf2
Tom de Vries [Wed, 3 Sep 2025 15:38:09 +0000 (17:38 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.dwarf2

Fix clean_restart <absolute filename> in the test-cases in gdb.dwarf2.

Tested on x86_64-linux using gcc-14.

Tested these test-cases on x86_64-linux with target board unix/-m32:
- gdb.dwarf2/valop.exp
- gdb.dwarf2/callframecfa.exp
- gdb.dwarf2/implptr.exp
- gdb.dwarf2/watch-notconst.exp
- gdb.dwarf2/pieces.exp
- gdb.dwarf2/pieces-optimized-out.exp

Tested these test-cases on x86_64-linux with target board fission-dwp:
- gdb.dwarf2/dwp-symlink.exp
- gdb.dwarf2/dwp-sepdebug.exp

Tested test-case gdb.dwarf2/gdb-index-tilde.exp on x86_64-linux by disabling a
too strict home directory check, see PR testsuite/33364.

4 weeks agoreadelf: Don't change the symbol table
H.J. Lu [Wed, 3 Sep 2025 13:48:24 +0000 (06:48 -0700)] 
readelf: Don't change the symbol table

1. Update dump_relr_relocations not to change the symbol table.
2. Update count_relr_relocations and dump_relr_relocations not to
retrieve the same data twice.

binutils/

PR binutils/33328
* readelf.c (count_relr_relocations): Add an argument to return
the retrieved data and remove the FIXME in comments.
(dump_relr_relocations): Add an argument for the retrieved data.
Retrieve the data if needed.  Don't change the symbol table and
remove the FIXME in comments.
(display_relocations): Get the data from count_relr_relocations
and pass it to dump_relr_relocations call.
(process_relocs): Pass NULL to dump_relr_relocations.

ld/

PR binutils/33328
* testsuite/ld-i386/dt-relr-2.d: New file.
* testsuite/ld-i386/dt-relr-2.s: Likewise.
* testsuite/ld-x86-64/dt-relr-2-x32.d: Likewise.
* testsuite/ld-x86-64/dt-relr-2.d: Likewise.
* testsuite/ld-x86-64/dt-relr-2.s: Likewise.
* testsuite/ld-i386/i386.exp: Run dt-relr-2.
* testsuite/ld-x86-64/x86-64.exp: Run dt-relr-2 and dt-relr-2-x32.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.fortran
Tom de Vries [Wed, 3 Sep 2025 14:43:34 +0000 (16:43 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.fortran

Fix clean_restart <absolute filename> in the test-cases in gdb.fortran.

Tested on x86_64-linux, with gcc 14.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.gdb
Tom de Vries [Wed, 3 Sep 2025 14:29:37 +0000 (16:29 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.gdb

Fix clean_restart <absolute filename> in the test-cases in gdb.gdb.

Tested on x86_64-linux.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.guile
Tom de Vries [Wed, 3 Sep 2025 14:21:18 +0000 (16:21 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.guile

Fix clean_restart <absolute filename> in the test-cases in gdb.guile.

Tested on x86_64-linux.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.linespec
Tom de Vries [Wed, 3 Sep 2025 14:15:37 +0000 (16:15 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.linespec

Fix clean_restart <absolute filename> in the test-cases in gdb.linespec.

Tested on x86_64-linux.

4 weeks ago[gdb/testsuite] Fix mi_clean_restart <absolute filename> in gdb.mi
Tom de Vries [Wed, 3 Sep 2025 14:05:07 +0000 (16:05 +0200)] 
[gdb/testsuite] Fix mi_clean_restart <absolute filename> in gdb.mi

Fix mi_clean_restart <absolute filename> in the test-cases in gdb.mi.

Tested on x86_64-linux.

Also tested test-case gdb.mi/mi-dprintf.exp with target boards
native-gdbserver and native-extended-gdbserver.

Since test-case gdb.mi/mi-regs.exp requires istarget "sparc-*-*", I didn't
test the trivial change in that test-case.

4 weeks ago[gdb/testsuite] Fix mi_clean_restart <absolute filename> in gdb.trace
Tom de Vries [Wed, 3 Sep 2025 13:41:22 +0000 (15:41 +0200)] 
[gdb/testsuite] Fix mi_clean_restart <absolute filename> in gdb.trace

Fix mi_clean_restart <absolute filename> in the test-cases in gdb.trace.

Tested on x86_64-linux, with target boards unix, native-gdbserver and
native-extended-gdbserver.

4 weeks agogdb: LoongArch: Restrict breakpoint outside of atomic sequence
Tiezhu Yang [Mon, 1 Sep 2025 01:29:56 +0000 (09:29 +0800)] 
gdb: LoongArch: Restrict breakpoint outside of atomic sequence

We can't put a breakpoint in the middle of a ll/sc atomic sequence,
so look for the end of the sequence and put the breakpoint there,
it has been handled in the commit 208b57e53ed9 ("gdb: LoongArch:
Deal with atomic sequence").

Especially, maybe there is a conditional branch instruction in the
middle of a ll/sc atomic sequence, its destination address may be
current pc + 4 which is inside the atomic sequence, it should not
put a breakpoint in its destination address in this case, this has
been handled in the commit a4242dc3f5fa ("gdb: LoongArch: Improve
the handling of atomic sequence").

Additionally, if there is a conditional branch instruction in the
middle of a ll/sc atomic sequence, its destination address may be
not current pc + 4 but still inside the atomic sequence, it should
not put a breakpoint in its destination address in this case.

So in order to avoid putting a breakpoint in the middle of a ll/sc
atomic sequence in any case, just look for the start and end of the
sequence, and restrict the breakpoint outside of the atomic sequence.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
4 weeks agogdb: LoongArch: Add and use cond_branch_destination_address()
Tiezhu Yang [Mon, 1 Sep 2025 01:29:55 +0000 (09:29 +0800)] 
gdb: LoongArch: Add and use cond_branch_destination_address()

In the current loongarch_deal_with_atomic_sequence(), it is just a loop
through a ll/sc atomic instruction sequence, the instructions before the
condition branch are not actually executed, thus the condition register
value is not proper to determine the destination address.

Add a new function cond_branch_destination_address() to calculate the
destination address of a condition branch instruction under an assumed
true condition, then only put a breakpoint at this address when it is
outside of the ll/sc atomic instruction sequence.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.multi
Tom de Vries [Wed, 3 Sep 2025 12:52:17 +0000 (14:52 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.multi

Fix clean_restart <absolute filename> in the test-cases in gdb.multi.

Tested on x86_64-linux.

4 weeks agox86: Check plt_got_offset for lazy IBT PLT
H.J. Lu [Tue, 2 Sep 2025 18:26:57 +0000 (11:26 -0700)] 
x86: Check plt_got_offset for lazy IBT PLT

Lazy IBT PLT entries look like

static const bfd_byte elf_i386_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
{
  0xf3, 0x0f, 0x1e, 0xfb,       /* endbr32                    */
  0x68, 0, 0, 0, 0,             /* pushl immediate            */
  0xe9, 0, 0, 0, 0,             /* jmp relative               */
  0x66, 0x90                    /* xchg %ax,%ax               */
};

static const bfd_byte elf_x86_64_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
{
  0xf3, 0x0f, 0x1e, 0xfa,       /* endbr64                    */
  0x68, 0, 0, 0, 0,             /* pushq immediate            */
  0xe9, 0, 0, 0, 0,             /* jmpq relative              */
  0x66, 0x90                    /* xchg %ax,%ax               */
};

They only have

unsigned int plt_reloc_offset;  /* ... offset into relocation table. */

and don't have

unsigned int plt_got_offset;    /* ... address of this symbol in .got. */

We should use plt_reloc_offset, not plt_got_offset, to check IBT PLT.

PR binutils/33358
* elf32-i386.c (elf_i386_get_synthetic_symtab): Check
plt_reloc_offset for lazy IBT PLT.
* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks agoreadelf: Run --got-contents only on ET_DYN/ET_EXEC files
H.J. Lu [Wed, 3 Sep 2025 01:07:23 +0000 (18:07 -0700)] 
readelf: Run --got-contents only on ET_DYN/ET_EXEC files

Update "readelf --got-contents" to skip on non-ET_DYN/ET_EXEC files.

* readelf.c (process_got_section_contents): Skip if not
ET_DYN/ET_EXEC files.
* testsuite/binutils-all/readelf-got.d: Removed.
* testsuite/binutils-all/readelf.exp: Don't run readelf-got.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.objc
Tom de Vries [Wed, 3 Sep 2025 12:39:14 +0000 (14:39 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.objc

Fix clean_restart <absolute filename> in the test-cases in gdb.objc.

Tested on x86_64-linux, using 'lappend options "nowarnings"' in
gdb_compile_shlib_pthreads.  See also PR testsuite/24807.

4 weeks agoreadelf: Call qsort only if all_relocations_count > 1
H.J. Lu [Mon, 1 Sep 2025 13:55:00 +0000 (06:55 -0700)] 
readelf: Call qsort only if all_relocations_count > 1

Don't call qsort if all_relocations_count < 1.

PR binutils/33351
* readelf.c (process_got_section_contents): Call qsort only if
all_relocations_count > 1.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks ago[gdb/testsuite] Fix clean_restart in gdb.opencl/callfuncs.exp
Tom de Vries [Wed, 3 Sep 2025 12:18:35 +0000 (14:18 +0200)] 
[gdb/testsuite] Fix clean_restart in gdb.opencl/callfuncs.exp

In test-case gdb.opencl/callfuncs.exp I noticed:
...
clean_restart [standard_testfile $testfile]
...

This doesn't have the desired effect of starting gdb with $testfile because
standard_testfile doesn't return anything.

Fix this by using "clean_restart $testfile".

While we're at it:
- move standard_testfile to the start of the file
- drop the redundant 'set testfile "callfuncs"'
- use standard_testfile .cl to properly define $srcfile
- use $srcfile instead of $testfile.cl

Tested on x86_64-linux, using the demonstrator patch in PR testsuite/33363.

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

4 weeks agogdb/testsuite: Fix gdb.base/gcore-memory-usage with address sanitizer
Guinevere Larsen [Tue, 2 Sep 2025 12:58:32 +0000 (09:58 -0300)] 
gdb/testsuite: Fix gdb.base/gcore-memory-usage with address sanitizer

The test gdb.base/gcore-memory-usage is meant to show that the memory
requirements of GDB's gcore command don't grow with the memory usage
of the inferior.  It was using hardcoded values for memory, but the
values were too small when building GDB with address sanitizer.  This
commit fixes one of the failures by increasing the limit on the first
gcore call.

But, rather than just increasing the hardcoded limit for the second
call, we instead save the amount of memory used in the first call and
ensure that the second call doesn't use more memory than the first.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33148
Approved-By: Tom de Vries <tdevries@suse.de>
4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.opt
Tom de Vries [Wed, 3 Sep 2025 11:03:02 +0000 (13:03 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.opt

Fix clean_restart <absolute filename> in the test-cases in gdb.opt.

Tested on x86_64-linux using gcc 14.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.perf
Tom de Vries [Wed, 3 Sep 2025 10:31:20 +0000 (12:31 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.perf

Fix clean_restart <absolute filename> in the test-cases in gdb.perf.

Tested on x86_64-linux using check-perf.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.python
Tom de Vries [Wed, 3 Sep 2025 09:53:08 +0000 (11:53 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.python

Fix clean_restart <absolute filename> in the test-cases in gdb.python.

Tested on x86_64-linux.

4 weeks agoDisable eh_frame optimisation if code detected in .eh_frame
Alan Modra [Wed, 3 Sep 2025 00:24:50 +0000 (09:54 +0930)] 
Disable eh_frame optimisation if code detected in .eh_frame

Fuzzers stress the assembler in ways no sane programmer would ever do.
One x86 oss-fuzz testcase (cleaned up a litte) was:
 .sect .debug_frame
 call x
 .long x,0
 .space 1
 .long 0,0
The call insn leaves the frag data corresponding to a CIE
uninitialised until later in assembly, leading to reports of
uninitialised data access in ehopt.c:check_eh_frame.

Hack around this problem by noticing an insn has been assembled in
dwarf2_emit_insn.  The existing frag has_code can't be used as that
leads to alignment complaints, so add a new segment_info flag.

* subsegs.h (struct segment_info_struct): Move bss and hadone
later.  Rename hadone to stab_seen.  Add insn_seen bitfield.
* dwarf2dbg.c (dwarf2_emit_insn): Set insn_seen.
* ehopt.c (check_eh_frame): Disable optimisation if insn_seen.
* stabs.c (s_stab_generic): Adjust for hadone rename.

4 weeks agofrag_alloc use of obstack_alloc
Alan Modra [Wed, 3 Sep 2025 01:29:54 +0000 (10:59 +0930)] 
frag_alloc use of obstack_alloc

Avoid the alignment hackery necessary when obstack_alloc is used.
obstack_alloc expands to obstack_blank plus obstack_finish, and the
latter call is where alignment of the tail of the obstack happens.

The docs say obstack_alloc "is invoked almost like malloc", which
implies a fixed size allocation and you don't need other obstack calls
in its use.  So I think trying to use obstack_alloc in frag_alloc was
always a poor choice.

* frags.c (frag_alloc): Replace obstack_alloc with obstack_blank.

4 weeks agoExplain frag alignment hacks
Alan Modra [Wed, 3 Sep 2025 00:20:17 +0000 (09:50 +0930)] 
Explain frag alignment hacks

"the weird alignment hackery" comment doesn't help anyone understand
the code.  Explain what is going on.  Replace the zero length
obstack_alloc with obstack_finish, which by inspection of obstack.h is
all the zero length alloc does.

* frags.c (frag_alloc): Comment.  Replace zero length
obstack_alloc with obstack_finish.
(frag_new): Remove unnecessary obstack_finish.
* write.c (compress_frag, compress_debug): Likewise.

4 weeks agomake frag fr_type a bitfield
Alan Modra [Tue, 2 Sep 2025 12:38:29 +0000 (22:08 +0930)] 
make frag fr_type a bitfield

For better packing of struct frag.

* frags.h (struct frag <fr_type>): Use ENUM_BITFIELD.

4 weeks agotidy tilegx and tilepro MAX_MEM_FOR_RS_ALIGN_CODE
Alan Modra [Tue, 2 Sep 2025 12:15:39 +0000 (21:45 +0930)] 
tidy tilegx and tilepro MAX_MEM_FOR_RS_ALIGN_CODE

These weren't wrong, but should use the BUNDLE_SIZE macros, in case
they ever change.

* config/tc-tilegx.h (MAX_MEM_FOR_RS_ALIGN_CODE): Use
TILEGX_BUNDLE_SIZE_IN_BYTES.
* config/tc-tilepro.h (MAX_MEM_FOR_RS_ALIGN_CODE): Use
TILEPRO_BUNDLE_SIZE_IN_BYTES.

4 weeks agovisium MAX_MEM_FOR_RS_ALIGN_CODE
Alan Modra [Tue, 2 Sep 2025 09:43:36 +0000 (19:13 +0930)] 
visium MAX_MEM_FOR_RS_ALIGN_CODE

Commit 7ca6020a4e52 "tidy target HANDLE_ALIGN" didn't account for
the "fix" amount emitted by visium_handle_align.  This didn't show up
as a problem due to frag alignment hiding the error, until I started
messing with struct frag.

* config/tc-visium.h (MAX_MEM_FOR_RS_ALIGN_CODE): Correct.

4 weeks agocsky disassembler leak
Alan Modra [Mon, 1 Sep 2025 07:34:43 +0000 (17:04 +0930)] 
csky disassembler leak

* csky-dis.c (parse_csky_dis_options): Free copy of options.

4 weeks agoAutomatic date update in version.in
GDB Administrator [Wed, 3 Sep 2025 00:01:01 +0000 (00:01 +0000)] 
Automatic date update in version.in

4 weeks agoPowerPC: Vector Instructions for Deeply Compressed Weight for AI (RFC02691)
Abhay Kandpal [Tue, 2 Sep 2025 23:36:42 +0000 (23:36 +0000)] 
PowerPC: Vector Instructions for Deeply Compressed Weight for AI (RFC02691)

opcodes/
* ppc-opc.c: (VXSEL5, VXSEL4, VXSEL3, VXSEL2, UIMM1): New defines.
(powerpc_opcodes): <vucmprhn, vucmprln, vucmprhb, vucmprlb,
vucmprhh, vucmprlh, vupkhsntob, vupklsntob, vupkint4tobf16,
vupkint8tobf16, vupkint4tofp32, vupkint8tofp32>: New instructions.

gas/
* gas/testsuite/gas/ppc/future.s: Add new testcases.
* gas/testsuite/gas/ppc/future.d: Likewise.

4 weeks agogdb/remote: call target_pre_inferior in remote_target::remote_add_inferior
Simon Marchi [Tue, 8 Jul 2025 20:54:45 +0000 (16:54 -0400)] 
gdb/remote: call target_pre_inferior in remote_target::remote_add_inferior

Since commit 3cb6bc13e328 ("gdb/progspace: add solib_ops pointer in
program_space"), and with the previous patch applied ("gdb/remote: use
scoped_restore_current_program_space in remote_unpush_target"), we get
this failure:

    $ make check TESTS="gdb.server/extended-remote-restart.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver"

In gdb.log:

    (gdb) PASS: gdb.server/extended-remote-restart.exp: kill: 0, follow-child 1: disconnect
    target extended-remote localhost:2348
    Remote debugging using localhost:2348
    /home/smarchi/src/binutils-gdb/gdb/progspace.h:240: internal-error: set_solib_ops: Assertion `m_solib_ops == nullptr' failed.

When connecting to a remote that has one or more inferior already
running, the remote target (the GDB-side code) tries to re-use existing
GDB inferiors that are unused.  The problem is that the program space of
the inferior that gets re-used unexpectedly has its solib_ops set.

I think that the problem is that when connecting to a remote target that
has multiple inferiors, target_pre_inferior only gets called for the
currently selected (client-side) inferior.  It happens here:

    #0  target_pre_inferior () at /home/smarchi/src/wt/amd/gdb/target.c:2454
    #1  0x0000559c832a350a in target_preopen (from_tty=1) at /home/smarchi/src/wt/amd/gdb/target.c:2510
    #2  0x0000559c82e1b8f1 in remote_target::open_1 (name=0x50200006eb58 ":2345", from_tty=1, extended_p=1) at /home/smarchi/src/wt/amd/gdb/remote.c:6171
    #3  0x0000559c82e18a5d in extended_remote_target::open (name=0x50200006eb58 ":2345", from_tty=1) at /home/smarchi/src/wt/amd/gdb/remote.c:5446
    #4  0x0000559c8329a43e in open_target (args=0x50200006eb58 ":2345", from_tty=1, command=0x512000072c40) at /home/smarchi/src/wt/amd/gdb/target.c:839

I think that target_pre_inferior should be called for the other
inferiors that gain execution as a result of connecting to the remote
target, to make sure inferior or program space-specific data from
previous executions gets cleared.  target_pre_inferior is what clears
any previous solib_ops.

It is possible to observe the problem by adding this print in
target_pre_inferior:

  printf (">>> target_pre_inferior called for inferior %d\n",
          current_inferior ()->num);

Then, starting a gdbserver:

    $ gdbserver --multi localhost:2345

Then, this gdb command that starts two remote inferiors, disconnects
(leaving gdbserver and the inferiors running), then reconnects:

    $ ./gdb -nx --data-directory=data-directory -q \
  -ex 'set sysroot /' \
  -ex 'target extended-remote :2345' \
  -ex 'file testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart' \
  -ex 'set remote exec-file testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart' \
  -ex 'b main' \
  -ex r \
  -ex 'add-inferior' \
  -ex 'inferior 2' \
  -ex 'file testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart' \
  -ex 'run' \
  -ex 'inferior 1' \
  -ex 'disconnect' \
  -ex 'echo About to reconnect\n' \
  -ex 'target extended-remote :2345'
    >>> target_pre_inferior called for inferior 1
    Remote debugging using :2345
    Reading symbols from /home/smarchi/build/wt/amd/gdb/testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart...
    Breakpoint 1 at 0x11fc: file /home/smarchi/src/wt/amd/gdb/testsuite/gdb.server/extended-remote-restart.c, line 50.
    >>> target_pre_inferior called for inferior 1
    Starting program: /home/smarchi/build/wt/amd/gdb/testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart

    Breakpoint 1, main () at /home/smarchi/src/wt/amd/gdb/testsuite/gdb.server/extended-remote-restart.c:50
    50        pid = fork ();
    [New inferior 2]
    Added inferior 2 on connection 1 (extended-remote :2345)
    [Switching to inferior 2 [<null>] (<noexec>)]
    Reading symbols from /home/smarchi/build/wt/amd/gdb/testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart...
    >>> target_pre_inferior called for inferior 2
    Starting program: /home/smarchi/build/wt/amd/gdb/testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart

    Thread 2.1 "extended-remote" hit Breakpoint 1.2, main () at /home/smarchi/src/wt/amd/gdb/testsuite/gdb.server/extended-remote-restart.c:50
    50        pid = fork ();
    [Switching to inferior 1 [process 2591936] (/home/smarchi/build/wt/amd/gdb/testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart)]
    [Switching to thread 1.1 (Thread 2591936.2591936)]
    #0  main () at /home/smarchi/src/wt/amd/gdb/testsuite/gdb.server/extended-remote-restart.c:50
    50        pid = fork ();
    Ending remote debugging.
    About to reconnect
    >>> target_pre_inferior called for inferior 1
    Remote debugging using :2345
    main () at /home/smarchi/src/wt/amd/gdb/testsuite/gdb.server/extended-remote-restart.c:50
    50        pid = fork ();

We can see that target_pre_inferior is only called for inferior 1 when
reconnecting (after the "About to reconnect" message).

After adding the call to target_pre_inferior in remote_add_inferior, we
get (just the last bit):

    About to reconnect
    >>> target_pre_inferior called for inferior 1
    Remote debugging using :2345
    >>> target_pre_inferior called for inferior 1
    >>> target_pre_inferior called for inferior 2
    Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...
    (No debugging symbols found in /lib/x86_64-linux-gnu/libc.so.6)
    Reading symbols from /lib64/ld-linux-x86-64.so.2...
    (No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
    main () at /home/smarchi/src/wt/amd/gdb/testsuite/gdb.server/extended-remote-restart.c:50
    50        pid = fork ();

The duplicate calls to target_pre_inferior for inferior 1 are due to the
existing call in target_preopen.  It might be possible to get rid of it:
with the call I added in remote_target::remote_add_inferior, I presume
it's now unnecessary for the remote target to have the call in
target_preopen as well.  But since target_preopen is used by other
targets, I prefer to leave it there to be safe, for the moment.  Calling
target_pre_inferior multiple times should not be a problem, as it should
be idempotent.

However, once I added that, test gdb.server/stop-reply-no-thread.exp
started failing, with this in the logs:

    target remote localhost:2347
    Remote debugging using localhost:2347
    Remote 'g' packet reply is too long (expected 560 bytes, got 820 bytes): 000000... <truncated>

It became apparent that the new call to target_pre_inferior would wipe a
previously fetched target description.  I fixed that by adding calls to
target_find_description in two callers of remote_add_inferior.  I'm not
100% sure of what I'm doing here, but it seems somewhat correct that
when we map a remote inferior to an existing client-side inferior, we
wipe out any previous target description (which would have been left by
a previous execution) and fetch a new one.

The other call to remote_add_inferior is in
extended_remote_target::attach, where there is already a call to
target_find_description shortly after.

Change-Id: I85426bfff286a67d5fb74bbf978df80060ee6deb

4 weeks agogdb/remote: use scoped_restore_current_program_space in remote_unpush_target
Simon Marchi [Tue, 8 Jul 2025 20:54:44 +0000 (16:54 -0400)] 
gdb/remote: use scoped_restore_current_program_space in remote_unpush_target

Since commit 3cb6bc13e328 ("gdb/progspace: add solib_ops pointer in
program_space"), this fails with an internal error:

    $ make check TESTS="gdb.server/extended-remote-restart.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver"

In gdb.log:

    (gdb) PASS: gdb.server/extended-remote-restart.exp: kill: 1, follow-child 0: disconnect
    target extended-remote localhost:2347
    Remote debugging using localhost:2347
    /home/smarchi/src/binutils-gdb/gdb/progspace.h:240: internal-error: set_solib_ops: Assertion `m_solib_ops == nullptr' failed.

The issue is that remote_unpush_target uses
scoped_restore_current_inferior to save the context, which only restores
the current inferior on exit.  But it then uses
switch_to_inferior_no_thread, which switches the inferior and the
program space.  The program space is therefore left unrestored.  This
can leave the current inferior and current program space out of sync.

With two inferiors, let's say we enter with current inferior == 1 and
current program space == 1.  When calling switch_to_inferior_no_thread
for inferior 2, we set the current inferior to 2 and current program
space to 2.  On exit, only the original inferior is restored, so we end
up with current inferior == 1 and current program space == 2.

The problem can be observed manually by starting two remote inferiors
and disconnecting while inferior 1 is selected:

    $ ./gdb -nx --data-directory=data-directory -q \
  -ex 'set sysroot /' \
  -ex 'target extended-remote | gdbserver --multi --once -' \
  -ex 'file /home/smarchi/build/wt/amd/gdb/testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart' \
  -ex 'set remote exec-file /home/smarchi/build/wt/amd/gdb/testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart' \
  -ex 'b main' \
  -ex r \
  -ex 'add-inferior' \
  -ex 'inferior 2' \
  -ex 'file /home/smarchi/build/wt/amd/gdb/testsuite/outputs/gdb.server/extended-remote-restart/extended-remote-restart' \
  -ex 'run' \
  -ex 'inferior 1' \
  -ex 'disconnect'

Then, connecting top-gdb to that gdb, we see the inconsistency:

    (top-gdb) p current_inferior_.m_obj.num
    $1 = 1
    (top-gdb) p current_program_space.num
    $2 = 2

When the test tries to connect to a remote target again, GDB maps the
remote inferior to inferior 1, but tries to set the solib_ops of program
space 2, which already has an solib_ops set, causing the internal error.

Fix this by using scoped_restore_current_program_space in addition to
scoped_restore_current_inferior.  With this patch applied, we get:

    (top-gdb) p current_inferior_.m_obj.num
    $1 = 1
    (top-gdb) p current_program_space.num
    $2 = 1

With this patch, we then hit another internal error, fixed by the
following patch.

Change-Id: If916f581a223d6611f7f23a9cbbf1825d2cdd0ba
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.replay
Tom de Vries [Tue, 2 Sep 2025 16:41:10 +0000 (18:41 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.replay

Fix clean_restart <absolute filename> in the test-case in gdb.replay.

Tested on x86_64-linux, with target boards unix, native-gdbserver and
native-extended-gdbserver.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.reverse
Tom de Vries [Tue, 2 Sep 2025 16:29:58 +0000 (18:29 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.reverse

Fix clean_restart <absolute filename> in the test-cases in gdb.reverse.

Tested on:
- x86_64-linux, target boards unix and unix/-m32
- aarch64-linux
- ppc64le-linux
- s390x-linux

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.rocm
Tom de Vries [Tue, 2 Sep 2025 15:39:11 +0000 (17:39 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.rocm

Fix clean_restart <absolute filename> in the test-cases in gdb.rocm.

Since these test-cases are unsupported for me, do the simple substitution:
...
clean_restart $binfile
->
clean_restart
gdb_load $binfile
...

4 weeks agoreadelf: Report if no GOT section found
H.J. Lu [Mon, 1 Sep 2025 18:00:43 +0000 (11:00 -0700)] 
readelf: Report if no GOT section found

Update "readelf --got-contents" to report if no GOT section found.

* readelf.c (process_got_section_contents): Report if no GOT
section found.
* testsuite/binutils-all/readelf-got.d: New file.
* testsuite/binutils-all/readelf.exp: Run readelf-got.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.server
Tom de Vries [Tue, 2 Sep 2025 15:24:15 +0000 (17:24 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.server

Fix clean_restart <absolute filename> in the test-cases in gdb.server.

Tested on x86_64-linux.

4 weeks agoarm: rework fix for PR gas/15273
Richard Earnshaw [Mon, 1 Sep 2025 15:52:54 +0000 (16:52 +0100)] 
arm: rework fix for PR gas/15273

PR gas/15273

The apparent intent of the original code added in
https://sourceware.org/pipermail/binutils/2012-August/078044.html was
to emit an error message if the instruction was obsolete and only to
emit a deprecation warning if an error hadn't already been emitted.
However, when the insn has not yet been obsoleted, the code would
generate a warning with a (null) message body if the selected CPU was
'any'.

The previous fix for this bug was to remove the support for the
obsoletion message entirely, which was probably the wrong approach.  A
better fix is to only call check_obsolete if obs_msg is non-null; we
can use this as a proxy for the instruction not being obsolete on any
architecture.

While we are here, fix an incorrect capitalization in the deprecation
message ('This' to 'this').

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.testsuite
Tom de Vries [Tue, 2 Sep 2025 14:15:49 +0000 (16:15 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.testsuite

Fix clean_restart <absolute filename> in the test-cases in gdb.testsuite.

Tested on x86_64-linux.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.threads
Tom de Vries [Tue, 2 Sep 2025 12:42:05 +0000 (14:42 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.threads

Fix clean_restart <absolute filename> in the test-cases in gdb.threads.

Tested on x86_64-linux.

4 weeks agoFix host_file_normalize_mingw
Pedro Alves [Fri, 29 Aug 2025 19:05:48 +0000 (20:05 +0100)] 
Fix host_file_normalize_mingw

Tom de Vries ran the testsuite on msys2-ucrt64 with mount point map:
...
  /bin C:/msys64/usr/bin
  /c   C:
  /    C:/msys64
...
and ran into the problem that host_file_normalize didn't translate:
...
  /home/user/gdb/build/gdb/testsuite/temp/n/x
...
into:
...
  C:/msys64/home/user/gdb/build/gdb/testsuite/temp/n/x
...

The problem is that host_file_normalize_mingw mishandles a
file/directory under the root mount point.  A simpler reproducer is
"/foo".  If we add that as a test to
gdb.testsuite/mount-point-map.exp, we see:

 input:    /foo
 expected: C:/msys64/foo/
 got:      /foo
 FAIL: gdb.testsuite/mount-point-map.exp: /foo

For a mount point that ends in /, this line in
host_file_normalize_mingw:

  } elseif {[string index $filename $mount_len] eq "/"} {

... is always false, because the character at $mount_len is the one
_after_ the slash.

Notice that the "/" mount point is the only one that ends in "/".
This is even if you try to create one explicitly with a trailing /.

On MSYS2:

 $ mount c:/foo /foo/
 mount: warning - /foo/ does not exist.
 $ mount
 C:/foo on /foo type ntfs (binary,user)
 ...

So fix this by special casing the "/" mount point.

And then... while playing with fixing this, I noticed I had done
something strange with this case:

  if {[string length $filename] == $mount_len} {
      return "$win_filename/"

The intent was to append the slash when the mount is a drive letter,
like 'cygpath -ma' does:

 $ cygpath -ma /c
 C:/

Other cases do not get a trailing slash:

 $ cygpath -ma /c/foo
 C:/foo

I think this is because on Windows, every drive letter has a current
directory, and really "C:" means "current directory of drive letter
C:", not "root of C:".  Resolving it to "C:/" makes it unambiguous.

However, I mishandled that in a63213cd374d ('MSYS2+MinGW testing: Unix
<-> Windows path conversion').  The original version of that patch
when I posted it to the mailing list only supported drive mounts,
which turned out incorrect, and then I generalized it to work with all
mount points before it was merged.  In the process, I inadvertently
made the code append the slash whenever the input filename matches a
mount exactly, any mount.

I also now noticed that TCL's "file normalize" on Linux always removes
the trailing slash, and since host_file_normalize is an abstraction
for it, I think host_file_normalize_mingw should do the same.
Likewise for duplicate slashes, "file normalize" gets rid of them.

Fix all this in host_file_normalize_mingw, and add corresponding tests
to gdb.testsuite/mount-point-map.exp.

I smoke tested this here with a few of the testcases that required
tweaking in the patch that added host_file_normalize, like
gdb.base/source-dir.exp and gdb.base/fullname.exp and they still pass.

Tom ran gdb.testsuite/mount-point-map.exp on both x86_64-linux and
msys2-ucrt64, and it passed in both cases.

Change-Id: I852a8662f0cb8b0ee4e683e9b157618cf6955477

4 weeks agoAdd gdb.testsuite/mount-point-map.exp
Tom de Vries [Tue, 2 Sep 2025 10:41:02 +0000 (11:41 +0100)] 
Add gdb.testsuite/mount-point-map.exp

Proc host_file_normalize is structured like this:
...
proc host_file_normalize {filename} {
    if {[ishost *-*-mingw*]} {
        ...
    }

    return [file normalize $filename]
...
so a testcase exercising the mingw specific part can only be run on a
mingw host.

Factor out a new proc host_file_normalize_mingw, which can be used on
any host platform.

Add testcase gdb.testsuite/mount-point-map.exp, exercising
host_file_normalize_mingw.

Tested on aarch64-linux, x86-64-linux, msys2-ucrt64, and msys2-mingw.

Co-Authored-By: Pedro Alves <pedro@palves.net>
Change-Id: Ia130de5c12c940852b6367c422d04896863bfc02

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.trace
Tom de Vries [Tue, 2 Sep 2025 11:28:46 +0000 (13:28 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.trace

Fix clean_restart <absolute filename> in the test-cases in gdb.trace.

Tested on x86_64-linux, with target boards unix, native-gdbserver and
native-extended-gdbserver.

4 weeks ago[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.tui
Tom de Vries [Tue, 2 Sep 2025 08:55:02 +0000 (10:55 +0200)] 
[gdb/testsuite] Fix clean_restart <absolute filename> in gdb.tui

Fix clean_restart <absolute filename> in the test-cases in gdb.tui.

Tested on x86_64-linux.

4 weeks agox86/testsuite: Adjust unused FRED and MOVRS tests [PR33348]
Haochen Jiang [Mon, 1 Sep 2025 02:54:28 +0000 (10:54 +0800)] 
x86/testsuite: Adjust unused FRED and MOVRS tests [PR33348]

The tests mentioned in PR33348 needs different care.

For FRED tests, we could simply remove them since there are
no operands and the tests are the same as AT&T Syntax.

For MOVRS tests, we allowed suffixes for AT&T suffixes although
we could tell the difference according to register operand to
align with legacy mov. Thus, the suffixes tests are needed for
AT&T Syntax while not needed for Intel Syntax. Adjust them
accordingly.

gas/ChangeLog:

PR ld/33348
* testsuite/gas/i386/x86-64-movrs-suffix.d: Describe the
test with more precise.
* testsuite/gas/i386/x86-64-movrs-suffix.s: Remove Intel
Syntax part.
* testsuite/gas/i386/x86-64.exp: Add MOVRS suffix tests.
* testsuite/gas/i386/x86-64-fred-intel.d: Removed.
* testsuite/gas/i386/x86-64-movrs-suffix-intel.d: Ditto.

4 weeks agoLoongArch: Fix incorrect display of FDEs address ranges when using objdump -Wf
Lulu Cai [Tue, 26 Aug 2025 09:19:47 +0000 (17:19 +0800)] 
LoongArch: Fix incorrect display of FDEs address ranges when using objdump -Wf

When parsing FDEs in `.eh_frame` using `objdump -Wf`, it is necessary to
resolve `BFD_RELOC_LARCH_32_PCREL` to determine the address ranges of
the FDEs. Set the `pcrel_offset` field of `BFD_RELOC_LARCH_32_PCREL` to
help `objdump` correctly compute the address ranges of the FDEs.

Apply the same modification to BFD_RELOC_LARCH_64_PCREL.

4 weeks agoAutomatic date update in version.in
GDB Administrator [Tue, 2 Sep 2025 00:01:09 +0000 (00:01 +0000)] 
Automatic date update in version.in

5 weeks agoaarch64: Fix -i option for aarch64-gen
acazuc [Mon, 1 Sep 2025 10:48:42 +0000 (12:48 +0200)] 
aarch64: Fix -i option for aarch64-gen

Only the long option --gen-idx was recognized to generate aarch64-tbl-2.h

5 weeks agoRe: readelf: Add --got-contents option
Alan Modra [Mon, 1 Sep 2025 01:30:17 +0000 (11:00 +0930)] 
Re: readelf: Add --got-contents option

The cris ld testsuite uses readelf -a.  The extra output now means
that a number of tests fail.  Fix that by not using -a, but rather
the options corresponding to output checked in the dump files.

* testsuite/ld-cris/tls-local-63.d: Replace -a option with -r -s.
Remove now unnecessary #... and superfluous unwind message.
* testsuite/ld-cris/tls-local-64.d: Likewise.
* testsuite/ld-cris/tls-und-38.d: Likewise.
* testsuite/ld-cris/tls-und-42.d: Likewise.
* testsuite/ld-cris/tls-und-46.d: Likewise.
* testsuite/ld-cris/tls-und-50.d: Likewise.
* testsuite/ld-cris/weakref3.d: Replace -a with -S -r -s, and
remove unwind message.
* testsuite/ld-cris/weakref4.d: Likewise.

5 weeks ago[gdb] Fix handling of aborted inferior call
Tom de Vries [Mon, 1 Sep 2025 07:07:11 +0000 (09:07 +0200)] 
[gdb] Fix handling of aborted inferior call

PR gdb/33069 reports the following behavior:
...
$ gdb -q ls -ex starti -ex "b *1"
Reading symbols from ls...
(No debugging symbols found in ls)
Starting program: /usr/bin/ls

Program stopped.
0x00007ffff7fe4f00 in _start () from /lib64/ld-linux-x86-64.so.2
Breakpoint 1 at 0x1
(gdb) p (int)strlen("abc")
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x1

Command aborted.
An error occurred while in a function called from GDB.
Evaluation of the expression containing the function
(malloc@plt) will be abandoned.
When the function is done executing, GDB will silently stop.

[1]+  Stopped                 gdb -q ls -ex starti -ex "b *1"
$ fg
gdb -q ls -ex starti -ex "b *1"
(gdb)
...
with gdb being unresponsive to further input.

PR gdb/33068 reports a similar problem, but using gdbserver, and in that case
gdb doesn't go into the background, but is likewise unresponsive.

This is a regression since commit b1c0ab20809 ("gdb: avoid double stop after
failed breakpoint condition check"), and consequently since release gdb 14.1.

The commit changed this in run_inferior_call:
...
   if (current_ui->prompt_state == PROMPT_BLOCKED)
-    current_ui->unregister_file_handler ();
-  else
-    current_ui->register_file_handler ();
+    {
+      if (call_thread->thread_fsm ()->finished_p ())
+ async_disable_stdin ();
+      else
+ async_enable_stdin ();
+    }
...
which means current_ui->register_file_handler is no longer called in the
current_ui->prompt_state == PROMPT_NEEDED case.

Fix this by:
- restoring this behavior, fixing the unresponsiveness, and
- adding target_terminal::ours alongside it, fixing the problem that gdb goes
  into the background.

Add a new test-case gdb.base/infcall-failure-2.exp, a regression test for the
unresponsiveness issue.  The problem of gdb going into the background did not
reproduce in the test-case.

Tested on x86_64-linux.

Reviewed-By: Keith Seitz <keiths@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33068
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33069

5 weeks agoAutomatic date update in version.in
GDB Administrator [Mon, 1 Sep 2025 00:01:12 +0000 (00:01 +0000)] 
Automatic date update in version.in

5 weeks agold: Move Solaris/sparcv9 TEXT_START_ADDR to elf64_sparc_sol2.sh
Rainer Orth [Sun, 31 Aug 2025 10:14:36 +0000 (12:14 +0200)] 
ld: Move Solaris/sparcv9 TEXT_START_ADDR to elf64_sparc_sol2.sh

While looking at the Solaris versions of the program header p_vaddr and
p_align values of the text and data segments, I noticed that the
Solaris/sparcv9 version of TEXT_START_ADDR is defined in a shared file.
Since there's a Solaris/sparcv9 specific file now
(ld/emulparams/elf64_sparc_sol2.sh), it seems cleaner to move it there.

Tested on {sparcv9,sparc}-sun-solaris2.11 and
{sparc64,sparc}-unknown-linux-gnu.

2025-07-29  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

ld:
* emulparams/elf64_sparc.sh (TEXT_START_ADDR): Move ...
* emulparams/elf64_sparc_sol2.sh (TEXT_START_ADDR): ... here.

5 weeks agogdbsupport: remove unecessary template on iterator_range constructor
Simon Marchi [Sun, 31 Aug 2025 03:03:45 +0000 (23:03 -0400)] 
gdbsupport: remove unecessary template on iterator_range constructor

This is a copy-pasto.

Change-Id: I947772f6a694b33e393762dbf2931ebe2031c1c5

5 weeks agoAutomatic date update in version.in
GDB Administrator [Sun, 31 Aug 2025 00:01:10 +0000 (00:01 +0000)] 
Automatic date update in version.in

5 weeks agogdb: fix include guard in arch/aarch64-gcs-linux.h
Simon Marchi [Sat, 30 Aug 2025 13:22:00 +0000 (09:22 -0400)] 
gdb: fix include guard in arch/aarch64-gcs-linux.h

Fix:

    $ gdb/check-include-guards.py gdb/arch/aarch64-gcs-linux.h
    gdb/arch/aarch64-gcs-linux.h:20: wrong symbol in ifndef

Change-Id: I7586d5c22abe11501f59439df2b4a73bff7d201e

5 weeks agogdb/testsuite: run black on gdb.base/inline-frame-cycle-unwind.py
Simon Marchi [Sat, 30 Aug 2025 13:20:33 +0000 (09:20 -0400)] 
gdb/testsuite: run black on gdb.base/inline-frame-cycle-unwind.py

Change-Id: Ib15ecd6c03fce9d50a0121bbcb910e2fa05cc5f9

5 weeks agogdb/testsuite: remove leftover debug print
Simon Marchi [Sat, 30 Aug 2025 12:39:55 +0000 (08:39 -0400)] 
gdb/testsuite: remove leftover debug print

Change-Id: Ifb1dab85891200cadb4b4f59661450a03b0c6abd

5 weeks agogdb/solib-svr4: update default debug base in svr4_solib_ops::current_sos
Simon Marchi [Fri, 29 Aug 2025 20:05:27 +0000 (16:05 -0400)] 
gdb/solib-svr4: update default debug base in svr4_solib_ops::current_sos

Commit d33a66a31134 ("gdb/solib-svr4: fix wrong namespace id for dynamic
linker") regressed test gdb.base/break-probes.exp with the native-gdbserver
board:

    Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/break-probes.exp ...
    FAIL: gdb.base/break-probes.exp: run til our library loads (the program exited)
    FAIL: gdb.base/break-probes.exp: call (int) foo(23)

In the logs, we see this:

    Stopped due to shared library event:
      Inferior unloaded target:/lib64/ld-linux-x86-64.so.2
      Inferior loaded target:/lib64/ld-linux-x86-64.so.2

When we should see this:

    Stopped due to shared library event (no libraries added or removed)

In the unexpected output, GDB claims that the inferior unloaded and then
loaded the dynamic linker.  This is obviously not true.

Commit d33a66a31134 changed the svr4_same function to consider the debug
bases the solibs come from.  Two solibs with the same inferior address but
different debug base (such as the multiple solibs representing the dynamic
linker in all the namespaces) now compare unequal.

That commit also introduced a mechanism to update the debug base of an
existing solib (more precisely, field lm_info_svr4::debug_base) when that
value becomes known.  The solib for the dynamic linker view in the default
namespace starts with a debug base of 0, and is then changed to have the
real debug base address later on.

With the particular code path taken when connecting to a remote target,
nothing triggers the update of the debug base of the dynamic linker solib
initially created with a debug base of 0.  So when
svr4_solib_ops::current_sos returns a list with an solib for the dynamic
linker with the real debug base value, the core sees this as an unload and
a load.

This happens specifically when debuggin remotely, because,
svr4_solib_ops::current_sos_direct takes the "using_xfer" branch, which
doesn't do any svr4_solib_ops::default_debug_base call.  In local, we don't
take that branch, which leads us to a call to default_debug_base.

The way I propose to fix it is to add a call to
svr4_solib_ops::default_debug_base at the beginning of
svr4_solib_ops::current_sos.  The rationale to put it there is that if the
core is requesting a fresh list of libraries, and then compare that list
with what it had previously, then we better make sure that the core's list
has received the debug base update, if one is needed.

Change-Id: If09c5a7b3d956e18d4b9514466226267c85f12a6
Approved-by: Kevin Buettner <kevinb@redhat.com>
5 weeks agoAutomatic date update in version.in
GDB Administrator [Sat, 30 Aug 2025 00:00:28 +0000 (00:00 +0000)] 
Automatic date update in version.in

5 weeks agoGDB: doc: Document Linux AArch64 support for Guarded Control Stacks
Thiago Jung Bauermann [Sat, 14 Jun 2025 02:26:23 +0000 (23:26 -0300)] 
GDB: doc: Document Linux AArch64 support for Guarded Control Stacks

Add NEWS entry and new sections to the "Configuration-Specific Information"
and "Standard Target Features" parts of the manual.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Luis Machado <luis.machado@arm.com>
5 weeks agoGDB: aarch64-linux: Support unwinding the GCSPR
Thiago Jung Bauermann [Tue, 17 Jun 2025 00:10:37 +0000 (21:10 -0300)] 
GDB: aarch64-linux: Support unwinding the GCSPR

The GCSPR is almost always updated implicitly by the hardware, so the
compiler doesn't generate DWARF unwind information for it.  Therefore add
an unwinding function that calculates the value of the GCSPR in the
previous frame based on its value in this frame.  Some sanity checking is
done by confirming that the calculated value is within a Guarded Control
Stack memory area.

This function is the same as amd64_linux_dwarf2_prev_ssp, written by
Christina Schimpe to unwind Intel's SSP register.

The gdb.arch/aarch64-gcs-return.exp testcase is lightly adapted from
gdb.arch/amd64-shadow-stack-cmds.exp.

Reviewed-By: Christina Schimpe <christina.schimpe@intel.com>
Approved-By: Luis Machado <luis.machado@arm.com>
5 weeks agoGDB: aarch64-linux: Implement GCS support in displaced stepping
Thiago Jung Bauermann [Fri, 2 May 2025 00:36:18 +0000 (21:36 -0300)] 
GDB: aarch64-linux: Implement GCS support in displaced stepping

When doing displaced step on a branch and link instruction with the Guarded
Control Stack enabled, it's necessary to manually push and pop the GCS
entry for the function call since GDB writes a simple branch instruction
rather than a branch and link instruction in the displaced step buffer.

The testcase exercises GCS with displaced stepping by putting the
breakpoint on the bl instruction to force GDB to copy it to the
displaced stepping buffer.  In this situation GDB needs to manually
manage the Guarded Control Stack.

Reviewed-By: Christina Schimpe <christina.schimpe@intel.com>
Approved-By: Luis Machado <luis.machado@arm.com>
5 weeks agoGDB: aarch64-linux: GCS support in Linux signals
Thiago Jung Bauermann [Fri, 2 May 2025 00:24:01 +0000 (21:24 -0300)] 
GDB: aarch64-linux: GCS support in Linux signals

The signal frame can have a GCS context, so teach GDB how to use it.

Also, there's a new SEGV sigcode when the inferior does an illegal
memory access in the Guarded Control Stack, so display a message when
that is the case.

Reviewed-By: Christina Schimpe <christina.schimpe@intel.com>
Approved-By: Luis Machado <luis.machado@arm.com>
5 weeks agoGDB, gdbserver: aarch64-linux: Initial Guarded Control Stack support
Thiago Jung Bauermann [Thu, 1 May 2025 21:12:19 +0000 (18:12 -0300)] 
GDB, gdbserver: aarch64-linux: Initial Guarded Control Stack support

Add the org.gnu.gdb.aarch64.gcs feature with the GCSPR register, and the
org.gnu.gdb.aarch64.gcs.linux feature with "registers" to represent the
Linux kernel ptrace and prctl knobs that enable and lock specific GCS
functionality.

This code supports GCS only in Linux userspace applications, so the
GCSPR that is exposed is the one at EL0.

Also, support for calling inferior functions is enabled by adding an
implementation for the shadow_stack_push gdbarch method.

If for some reason a target description contains the
org.gnu.gdb.aarch64.gcs feature but not the
org.gnu.gdb.aarch64.gcs.linux feature then GCS support is disabled and
GDB continues the debugging session.  Features that need GCS
support (for example, calling inferior functions) will not work and the
inferior will get a segmentation fault signal instead.  There's a
testcase for this scenario but it only checks the native debugging case,
even though in practice this problem would only occur in remote
debugging with a broken stub or gdbserver.  I tested manually with a
gdbserver hacked to send a broken target description and it worked as
described.

Testcases gdb.arch/aarch64-gcs.exp, gdb.arch/aarch64-gcs-core.exp and
gdb.arch/aarch64-gcs-wrong-tdesc.exp are included to cover the added
functionality.

Reviewed-By: Christina Schimpe <christina.schimpe@intel.com>
Approved-By: Luis Machado <luis.machado@arm.com>
5 weeks agogdb/objfiles: use filtered_iterator as objfile::section_iterator
Simon Marchi [Thu, 28 Aug 2025 15:10:51 +0000 (11:10 -0400)] 
gdb/objfiles: use filtered_iterator as objfile::section_iterator

objfile::section_iterator looks like a good candidate to be implemented
with filtered_iterator.  Following the enhancements to filtered_iterator
in the previous patch, it's pretty straighforward.

I removed the non-const version of objfile::sections, because it didn't
seem useful to have the two methods returning the exact same type and
value.  Having just the const version achieves the same thing.

Change-Id: I2f29c2fb3f95605cb816cc1ff8935c10e0496052
Approved-By: Tom Tromey <tom@tromey.com>
5 weeks agogdbsupport: make filtered_iterator work with pointers
Simon Marchi [Thu, 28 Aug 2025 15:10:50 +0000 (11:10 -0400)] 
gdbsupport: make filtered_iterator work with pointers

It's currently not possible to use filtered_iterator with a pointer as
the base iterator type.  This patch makes it possible.  The indended
usage is:

  Foo array[12];
  Foo *begin = array;
  Foo *end = array + ARRAY_SIZE (array);
  filtered_iterator<Foo *, FooFilter> (begin, end);

Here are the things that needed changing:

 - Give filtered_iterator a constructor where the caller provides
   already constructed begin and end iterators.  filtered_iterator
   currently assumes that default-constructing a BaseIterator will
   produce a valid "end" iterator.  This is not the case if BaseIterator
   is a pointer.  The caller needs to pass in the end of the array /
   region to iterate on as the end.

 - Typedefs of member types like wouldn't work:

     typedef typename BaseIterator::value_type value_type;

   The compiler would complain that it's not possible to apply `::` to
   type `BaseIterator` (aka `Foo *`).  Use std::iterator_traits to fix
   it [1].

 - Similarly, the compiler would complain about the use of
   `BaseIterator::operator*` in the return type of
   `filtered_iterator::operator*`.  Fix this by using `decltype(auto)`
   as the return type.  This lets the compiler deduce the return type
   from the return statement.  Unlike `auto`, `decltype(auto)` perfectly
   preserves the "cvref-ness" of the deduced return type.  If the return
   expression yields a `Foo &`, then the function will return a `Foo &`
   (which is what we want), whereas it would return a `Foo` if we used
   just `auto`.

Improve the filtered_iterator unit tests to run the same tests but with
pointers as iterators.  Because the filtered_iterator objects are
initialized differently in the two scenarios, I chose to copy the
existing code and adapt it.  It would probably be possible to add a
layer of abstraction to avoid code duplication, but it would end up more
complicated and messy.  If we ever add a third scenario, we can revisit
that.

[1] https://en.cppreference.com/w/cpp/iterator/iterator_traits.html

Change-Id: Id962ffbcd960a705a82bc5eb4808b4fe118a2761
Approved-By: Tom Tromey <tom@tromey.com>
5 weeks agogdb: Enable displaced stepping with shadow stack on amd64 linux.
Christina Schimpe [Fri, 18 Feb 2022 11:09:46 +0000 (03:09 -0800)] 
gdb: Enable displaced stepping with shadow stack on amd64 linux.

Currently, if displaced stepping is active and the single stepped instruction
is a call instruction, the return address atop the stack is the address
following the copied instruction.  However, to allow normal program execution
it has to be the address following the original instruction.  Due to that
reason, the return address is corrected in amd64_displaced_step_fixup and
i386_displaced_step_fixup.

For programs that are shadow-stack enabled we see a control-protection
exception, as the address on the shadow stack does not match the address
atop the stack.

Fix this by correcting the shadow stack top address as well.

Approved-By: Andrew Burgess <aburgess@redhat.com>
Approved-By: Luis Machado <luis.machado@arm.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
5 weeks agogdb, gdbarch: Introduce gdbarch method to get the shadow stack pointer.
Christina Schimpe [Tue, 27 Feb 2024 16:48:00 +0000 (11:48 -0500)] 
gdb, gdbarch: Introduce gdbarch method to get the shadow stack pointer.

This patch is required by the following commit
"gdb: Enable displaced stepping with shadow stack on amd64 linux."

Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
5 weeks agogdb: Implement amd64 linux shadow stack support for inferior calls.
Christina Schimpe [Thu, 11 Apr 2024 09:55:01 +0000 (05:55 -0400)] 
gdb: Implement amd64 linux shadow stack support for inferior calls.

This patch enables inferior calls to support Intel's Control-Flow
Enforcement Technology (CET), which provides the shadow stack feature
for the x86 architecture.
Following the restriction of the linux kernel, enable inferior calls
for amd64 only.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
5 weeks agogdb, gdbarch: Enable inferior calls for shadow stack support.
Christina Schimpe [Thu, 11 Apr 2024 09:53:35 +0000 (05:53 -0400)] 
gdb, gdbarch: Enable inferior calls for shadow stack support.

Inferior calls in GDB reset the current PC to the beginning of the function
that is called.  As no call instruction is executed the new return address
needs to be pushed to the shadow stack and the shadow stack pointer needs
to be updated.

This commit adds a new gdbarch method to push an address on the shadow
stack.  The method is used to adapt the function 'call_function_by_hand_dummy'
for inferior call shadow stack support.

Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
5 weeks agogdb: Handle shadow stack pointer register unwinding for amd64 linux.
Christina Schimpe [Mon, 8 Apr 2024 15:57:34 +0000 (11:57 -0400)] 
gdb: Handle shadow stack pointer register unwinding for amd64 linux.

Unwind the $pl3_ssp register.
We now have an updated value for the shadow stack pointer when
moving up or down the frame level.  Note that $pl3_ssp can
become unavailable when moving to a frame before the shadow
stack enablement.  In the example below, shadow stack is enabled
in the function 'call1'.  Thus, when moving to a frame level above
the function, $pl3_ssp will become unavaiable.
Following the restriction of the linux kernel, implement the unwinding
for amd64 linux only.

Before this patch:
~~~
Breakpoint 1, call2 (j=3) at sample.c:44
44   return 42;
(gdb) p $pl3_ssp
$1 = (void *) 0x7ffff79ffff8
(gdb) up
55   call2 (3);
(gdb) p $pl3_ssp
$2 = (void *) 0x7ffff79ffff8
(gdb) up
68   call1 (43);
(gdb) p $pl3_ssp
$3 = (void *) 0x7ffff79ffff8
~~~

After this patch:
~~~
Breakpoint 1, call2 (j=3) at sample.c:44
44   return 42;
(gdb) p $pl3_ssp
$1 = (void *) 0x7ffff79ffff8
(gdb) up
55   call2 (3);
(gdb) p $pl3_ssp
$2 = (void *) 0x7ffff7a00000
(gdb) up
68   call1 (43i);
(gdb) p $pl3_ssp
$3 = <unavailable>
~~~

As we now have an updated value for each selected frame, the
return command is now enabled for shadow stack enabled programs, too.

We therefore add a test for the return command and shadow stack support,
and for an updated shadow stack pointer after a frame level change.

Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
5 weeks agogdb: amd64 linux coredump support with shadow stack.
Christina Schimpe [Thu, 11 Feb 2021 11:01:46 +0000 (12:01 +0100)] 
gdb: amd64 linux coredump support with shadow stack.

Intel's Control-Flow Enforcement Technology (CET) provides the shadow
stack feature for the x86 architecture.

This commit adds support to write and read the shadow-stack node in
corefiles.  This helps debugging return address violations post-mortem.
The format is synced with the linux kernel commit "x86: Add PTRACE
interface for shadow stack".  As the linux kernel restricts shadow
stack support to 64-bit, apply the fix for amd64 only.

Co-Authored-By: Christina Schimpe <christina.schimpe@intel.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
---
The code and testcase are lightly adapted from:

[PATCH v3 5/9] GDB, gdbserver: aarch64-linux: Initial Guarded Control Stack support

https://sourceware.org/pipermail/gdb-patches/2025-June/218892.html

5 weeks agogdb, gdbserver: Add support of Intel shadow stack pointer register.
Christina Schimpe [Fri, 29 Mar 2019 15:38:50 +0000 (16:38 +0100)] 
gdb, gdbserver: Add support of Intel shadow stack pointer register.

This patch adds the user mode register PL3_SSP which is part of the
Intel(R) Control-Flow Enforcement Technology (CET) feature for support
of shadow stack.
For now, only native and remote debugging support for shadow stack
userspace on amd64 linux are covered by this patch including 64 bit and
x32 support.  32 bit support is not covered due to missing Linux kernel
support.

This patch requires fixing the test gdb.base/inline-frame-cycle-unwind
which is failing in case the shadow stack pointer is unavailable.
Such a state is possible if shadow stack is disabled for the current thread
but supported by HW.

This test uses the Python unwinder inline-frame-cycle-unwind.py which fakes
the cyclic stack cycle by reading the pending frame's registers and adding
them to the unwinder:

~~~
for reg in pending_frame.architecture().registers("general"):
     val = pending_frame.read_register(reg)
     unwinder.add_saved_register(reg, val)
     return unwinder
~~~

However, in case the python unwinder is used we add a register (pl3_ssp) that is
unavailable.  This leads to a NOT_AVAILABLE_ERROR caught in
gdb/frame-unwind.c:frame_unwind_try_unwinder and it is continued with standard
unwinders.  This destroys the faked cyclic behavior and the stack is
further unwinded after frame 5.

In the working scenario an error should be triggered:
~~~
bt
0  inline_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:49^M
1  normal_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:32^M
2  0x000055555555516e in inline_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:45^M
3  normal_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:32^M
4  0x000055555555516e in inline_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:45^M
5  normal_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:32^M
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) PASS: gdb.base/inline-frame-cycle-unwind.exp: cycle at level 5: backtrace when the unwind is broken at frame 5
~~~

To fix the Python unwinder, we simply skip the unavailable registers.

Also it makes the test gdb.dap/scopes.exp fail.  The shadow stack feature is
disabled by default, so the pl3_ssp register which is added with my CET
shadow stack series will be shown as unavailable and we see a TCL error:
~~
>>> {"seq": 12, "type": "request", "command": "variables", "arguments": {"variablesReference": 2, "count": 85}}
Content-Length: 129^M
^M
{"request_seq": 12, "type": "response", "command": "variables", "success": false, "message": "value is not available", "seq": 25}FAIL: gdb.dap/scopes.exp: fetch all registers success
ERROR: tcl error sourcing /tmp/gdb/testsuite/gdb.dap/scopes.exp.
ERROR: tcl error code TCL LOOKUP DICT body
ERROR: key "body" not known in dictionary
    while executing
"dict get $val body variables"
    (file "/tmp/gdb/testsuite/gdb.dap/scopes.exp" line 152)
    invoked from within
"source /tmp/gdb/testsuite/gdb.dap/scopes.exp"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 source /tmp/gdb/testsuite/gdb.dap/scopes.exp"
    invoked from within
"catch "uplevel #0 source $test_file_name" msg"
UNRESOLVED: gdb.dap/scopes.exp: testcase '/tmp/gdb/testsuite/gdb.dap/scopes.exp' aborted due to Tcl error
~~

I am fixing this by enabling the test for CET shadow stack, in case we
detect that the HW supports it:
~~~
    # If x86 shadow stack is supported we need to configure GLIBC_TUNABLES
    # such that the feature is enabled and the register pl3_ssp is
    # available.  Otherwise the reqeust to fetch all registers will fail
    # with "message": "value is not available".
    if { [allow_ssp_tests] } {
append_environment GLIBC_TUNABLES "glibc.cpu.hwcaps" "SHSTK"
    }
~~~

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
5 weeks agogdb, gdbserver: Use xstate_bv for target description creation on x86.
Christina Schimpe [Tue, 3 Dec 2024 16:32:10 +0000 (08:32 -0800)] 
gdb, gdbserver: Use xstate_bv for target description creation on x86.

The XSAVE function set is organized in state components, which are a set of
registers or parts of registers.  So-called XSAVE-supported features are
organized using state-component bitmaps, each bit corresponding to a
single state component.

The Intel Software Developer's Manual uses the term xstate_bv for a
state-component bitmap, which is defined as XCR0 | IA32_XSS.  The control
register XCR0 only contains a state-component bitmap that specifies user state
components, while IA32_XSS contains a state-component bitmap that specifies
supervisor state components.

Until now, XCR0 is used as input for target description creation in GDB.
However, a following patch will add userspace support for the CET shadow
stack feature by Intel.  The CET state is configured in IA32_XSS and consists
of 2 state components:
- State component 11 used for the 2 MSRs controlling user-mode
  functionality for CET (CET_U state)
- State component 12 used for the 3 MSRs containing shadow-stack pointers
  for privilege levels 0-2 (CET_S state).

Reading the CET shadow stack pointer register on linux requires a separate
ptrace call using NT_X86_SHSTK.  To pass the CET shadow stack enablement
state we would like to pass the xstate_bv value instead of xcr0 for target
description creation.  To prepare for that, we rename the xcr0 mask
values for target description creation to xstate_bv.  However, this
patch doesn't add any functional changes in GDB.

Future states specified in IA32_XSS such as CET will create a combined
xstate_bv_mask including xcr0 register value and its corresponding bit in
the state component bitmap.  This combined mask will then be used to create
the target descriptions.

Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Luis Machado <luis.machado@arm.com>
5 weeks agogdb: Sync up x86-gcc-cpuid.h with cpuid.h from gcc 14 branch.
Christina Schimpe [Thu, 22 Feb 2024 10:34:47 +0000 (05:34 -0500)] 
gdb: Sync up x86-gcc-cpuid.h with cpuid.h from gcc 14 branch.

This is required for a later commit which requires "bit_SHSTK".

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Luis Machado <luis.machado@arm.com>
5 weeks agogdbserver: Add assert in x86_linux_read_description.
Christina Schimpe [Tue, 6 Feb 2024 18:37:27 +0000 (13:37 -0500)] 
gdbserver: Add assert in x86_linux_read_description.

On x86 the PTRACE_GETREGSET request is currently only used for the xstate regset.
The size of the xstate regset is initialized to 0 such that it can be reset to
the appropriate size once we know it is supported for the current target
in x86_linux_read_description.

However, this configuration would not just affect the xstate regset but any regset
with PTRACE_GETREGSET request that is added in the future.  The new regset  would be
misconfigured with the xstate regset size.  To avoid this we add an assert for
unsupported regsets and check explicitly for the note type of the register set.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Luis Machado <luis.machado@arm.com>
5 weeks agogdbserver: Add optional runtime register set type.
Christina Schimpe [Mon, 18 Dec 2023 17:47:09 +0000 (18:47 +0100)] 
gdbserver: Add optional runtime register set type.

Some register sets can be activated and deactivated by the OS during the runtime of
a process.  One example register is the Intel CET shadow stack pointer.  This patch
adds a new type of register set to handle such cases.  We shouldn't deactivate these
regsets and should not show a warning if the register set is not active but supported
by the kernel.  However, it is safe to deactivate them, if they are unsupported by the
kernel.  To differentiate those scenarios we can use the errno returned by the ptrace
call.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Luis Machado <luis.machado@arm.com>
5 weeks agogdb, testsuite: Extend core_find procedure to save program output.
Christina Schimpe [Fri, 27 Jun 2025 16:09:17 +0000 (09:09 -0700)] 
gdb, testsuite: Extend core_find procedure to save program output.

From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>

The change comes from ARM's GCS series:

[PATCH v3 5/9] GDB, gdbserver: aarch64-linux: Initial Guarded Control Stack support.

We need it for testing coredump files, too.  So include it in this patch series.

Abridged-by: Christina Schimpe <christina.schimpe@intel.com>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
---
This is the patch mentioned above:

https://sourceware.org/pipermail/gdb-patches/2025-June/218892.html

Minus everything except for the change in gdb.exp's corefind procedure.

5 weeks agogdb/objfiles: make objfile::sections yield references
Simon Marchi [Wed, 27 Aug 2025 14:38:13 +0000 (10:38 -0400)] 
gdb/objfiles: make objfile::sections yield references

I wrote this as a preparatory patch while attempting to make
objfile::section_iterator use filtered_iterator.  It turned out not so
easy, so I have put it aside for now.  But now I have this patch, so I
thought I'd send it by itself.

Since the `obj_section *` yielded by the iterator can't be nullptr, I
think it makes sense for the iterator to yield references instead.
Just like you would get if you iterated on an std::vector<obj_section>.

Change-Id: I7bbee50ed52599e64c4f3b06bdbbde597feba9aa

5 weeks ago[gdb/testsuite] Fix overlapping CUs in gdb.dwarf2/dw2-linkage-name-trust.exp
Tom de Vries [Fri, 29 Aug 2025 15:31:58 +0000 (17:31 +0200)] 
[gdb/testsuite] Fix overlapping CUs in gdb.dwarf2/dw2-linkage-name-trust.exp

When running test-case gdb.dwarf2/dw2-linkage-name-trust.exp with target board
cc-with-gdb-index, I get:
...
(gdb) file dw2-linkage-name-trust^M
Reading symbols from dw2-linkage-name-trust...^M
warning: .gdb_index address table has a range (0x4006ac - 0x4006cc) that \
  overlaps with an earlier range, ignoring .gdb_index^M
(gdb) delete breakpoints^M
...

Fix this by compiling with nodebug.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
PR testsuite/33315
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33315

5 weeks ago[gdb/testsuite] Fix overlapping CUs in gdb.dwarf2/dw2-entry-points.exp
Tom de Vries [Fri, 29 Aug 2025 15:31:58 +0000 (17:31 +0200)] 
[gdb/testsuite] Fix overlapping CUs in gdb.dwarf2/dw2-entry-points.exp

When running test-case gdb.dwarf2/dw2-entry-points.exp with target board
cc-with-gdb-index, I get:
...
(gdb) file dw2-entry-points^M
Reading symbols from dw2-entry-points...^M
warning: .gdb_index address table has a range (0x40066c - 0x4006e4) that \
  overlaps with an earlier range, ignoring .gdb_index^M
(gdb) delete breakpoints^M
...

Fix this by copying function bar_helper to barso_helper, and using it where
appropriate.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
PR testsuite/33315
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33315

5 weeks agogdb: use kill() in gdbpy_interrupt for hosts with signal support
Andrew Burgess [Mon, 4 Aug 2025 14:44:04 +0000 (15:44 +0100)] 
gdb: use kill() in gdbpy_interrupt for hosts with signal support

For background, see this thread:

  https://inbox.sourceware.org/gdb-patches/20250612144607.27507-1-tdevries@suse.de

Tom describes the issue clearly in the above thread, here's what he
said:

  Once in a while, when running test-case gdb.base/bp-cmds-continue-ctrl-c.exp,
  I run into:
  ...
  Breakpoint 2, foo () at bp-cmds-continue-ctrl-c.c:23^M
  23        usleep (100);^M
  ^CFAIL: $exp: run: stop with control-c (unexpected) (timeout)
  FAIL: $exp: run: stop with control-c
  ...

  This is PR python/32167, observed both on x86_64-linux and powerpc64le-linux.

  This is not a timeout due to accidental slowness, gdb actually hangs.

  The backtrace at the hang is (on cfarm120 running AlmaLinux 9.6):
  ...
  (gdb) bt
   #0  0x00007fffbca9dd94 in __lll_lock_wait () from
       /lib64/glibc-hwcaps/power10/libc.so.6
   #1  0x00007fffbcaa6ddc in pthread_mutex_lock@@GLIBC_2.17 () from
       /lib64/glibc-hwcaps/power10/libc.so.6
   #2  0x000000001067aee8 in __gthread_mutex_lock ()
       at /usr/include/c++/11/ppc64le-redhat-linux/bits/gthr-default.h:749
   #3  0x000000001067afc8 in __gthread_recursive_mutex_lock ()
       at /usr/include/c++/11/ppc64le-redhat-linux/bits/gthr-default.h:811
   #4  0x000000001067b0d4 in std::recursive_mutex::lock ()
       at /usr/include/c++/11/mutex:108
   #5  0x000000001067b380 in std::lock_guard<std::recursive_mutex>::lock_guard ()
       at /usr/include/c++/11/bits/std_mutex.h:229
   #6  0x0000000010679d3c in set_quit_flag () at gdb/extension.c:865
   #7  0x000000001066b6dc in handle_sigint () at gdb/event-top.c:1264
   #8  0x00000000109e3b3c in handler_wrapper () at gdb/posix-hdep.c:70
   #9  <signal handler called>
   #10 0x00007fffbcaa6d14 in pthread_mutex_lock@@GLIBC_2.17 () from
       /lib64/glibc-hwcaps/power10/libc.so.6
   #11 0x000000001067aee8 in __gthread_mutex_lock ()
       at /usr/include/c++/11/ppc64le-redhat-linux/bits/gthr-default.h:749
   #12 0x000000001067afc8 in __gthread_recursive_mutex_lock ()
       at /usr/include/c++/11/ppc64le-redhat-linux/bits/gthr-default.h:811
   #13 0x000000001067b0d4 in std::recursive_mutex::lock ()
       at /usr/include/c++/11/mutex:108
   #14 0x000000001067b380 in std::lock_guard<std::recursive_mutex>::lock_guard ()
       at /usr/include/c++/11/bits/std_mutex.h:229
   #15 0x00000000106799cc in set_active_ext_lang ()
       at gdb/extension.c:775
   #16 0x0000000010b287ac in gdbpy_enter::gdbpy_enter ()
       at gdb/python/python.c:232
   #17 0x0000000010a8e3f8 in bpfinishpy_handle_stop ()
       at gdb/python/py-finishbreakpoint.c:414
  ...

  What happens here is the following:
  - the gdbpy_enter constructor attempts to set the current extension language
    to python using set_active_ext_lang
  - set_active_ext_lang attempts to lock ext_lang_mutex
  - while doing so, it is interrupted by sigint_wrapper (the SIGINT handler),
    handling a SIGINT
  - sigint_wrapper calls handle_sigint, which calls set_quit_flag, which also
    tries to lock ext_lang_mutex
  - since std::recursive_mutex::lock is not async-signal-safe, things go wrong,
    resulting in a hang.

  The hang bisects to commit 8bb8f834672 ("Fix gdb.interrupt race"), which
  introduced the lock, making PR python/32167 a regression since gdb 15.1.

  Commit 8bb8f834672 fixes PR dap/31263, a race reported by ThreadSanitizer:
  ...
  WARNING: ThreadSanitizer: data race (pid=615372)

    Read of size 1 at 0x00000328064c by thread T19:
      #0 set_active_ext_lang(extension_language_defn const*) gdb/extension.c:755
      #1 scoped_disable_cooperative_sigint_handling::scoped_disable_cooperative_sigint_handling()
         gdb/extension.c:697
      #2 gdbpy_interrupt gdb/python/python.c:1106
      #3 cfunction_vectorcall_NOARGS <null>

    Previous write of size 1 at 0x00000328064c by main thread:
      #0 scoped_disable_cooperative_sigint_handling::scoped_disable_cooperative_sigint_handling()
         gdb/extension.c:704
      #1 fetch_inferior_event() gdb/infrun.c:4591
      ...

    Location is global 'cooperative_sigint_handling_disabled' of size 1 at 0x00000328064c

    ...

  SUMMARY: ThreadSanitizer: data race gdb/extension.c:755 in \
    set_active_ext_lang(extension_language_defn const*)
  ...

  The problem here is that gdb.interrupt is called from a worker thread, and its
  implementation, gdbpy_interrupt races with the main thread on some variable.

The fix presented here is based on the fix that Tom proposed, but
fills in the missing Mingw support.

The problem is basically split into two: hosts that support unix like
signals, and Mingw, which doesn't support signals.

For signal supporting hosts, I've adopted the approach that Tom
suggests, gdbpy_interrupt uses kill() to send SIGINT to the GDB
process.  This is then handled in the main thread as if the user had
pressed Ctrl+C.  For these hosts no locking is required, so the
existing lock is removed.  However, everywhere the lock currently
exists I've added an assert:

    gdb_assert (is_main_thread ());

If this assert ever triggers then we're setting or reading the quit
flag on a worker thread, this will be a problem without the mutex.

For Mingw, the current mutex is retained.  This is fine as there are
no signals, so no chance of the mutex acquisition being interrupted by
a signal, and so, deadlock shouldn't be an issue.

To manage the complexity of when we need an assert, and when we need
the mutex, I've created 'struct ext_lang_guard', which can be used as
a RAII object.  This object either performs the assertion check, or
acquires the mutex, depending on the host.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32167
Co-Authored-By: Tom de Vries <tdevries@suse.de>
Approved-By: Tom Tromey <tom@tromey.com>