Commit Graph

123335 Commits

Author SHA1 Message Date
Jan Beulich
16d95f5ccf x86: make reloc() usable during late phases of assembly
Introduce a clone with extra parameters, to allow subsequent use from
md_estimate_size_before_relax() (or elsewhere, should that turn out
necessary). There flag_code cannot be used and location information
needs to be provided for diagnostics.
2025-09-05 08:32:25 +02:00
Simon Marchi
aaabb796f8 gdb: run black on gdbarch_components.py
Change-Id: Ifcf80faa240c7c235bfea4ddc79f0d6c39858c5e
2025-09-04 21:47:36 -04:00
GDB Administrator
5cce2b7006 Automatic date update in version.in 2025-09-05 00:00:27 +00:00
Thiago Jung Bauermann
11d6498015 GDB: aarch64-linux: Define HWCAP_GCS as unsigned long long value
On platforms where long is 32 bits, this change fixes a build failure:

/home/linux/arm/gdb/src/gdb/aarch64-linux-tdep.c: In function ‘const target_desc* aarch64_linux_core_read_description(gdbarch*, target_ops*, bfd*)’:
/home/linux/arm/gdb/src/gdb/arch/aarch64-gcs-linux.h:27:24: error: left shift count >= width of type [-Werror=shift-count-overflow]
   27 | #define HWCAP_GCS (1UL << 32)
      |                    ~~~~^~~~~
/home/linux/arm/gdb/src/gdb/aarch64-linux-tdep.c:1714:47: note: in expansion of macro ‘HWCAP_GCS’
 1714 |   features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;
      |                                               ^~~~~~~~~

Suggested-by: Tom de Vries <tdevries@suse.de>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33372
2025-09-04 19:54:31 -03:00
Andrew Burgess
44f37db2c6 gdb/testsuite: revert recent changes to gdb.dap/scopes.exp
After the previous commit, the changes to gdb.dap/scopes.exp from the
commit:

  commit 63b862be76
  Date:   Fri Mar 29 16:38:50 2019 +0100

      gdb, gdbserver: Add support of Intel shadow stack pointer register.

Are no longer needed, the test will now happily handle the shadow
stack pointer being unavailable.

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

Reviewed-By: Christina Schimpe <christina.schimpe@intel.com>
2025-09-04 22:19:00 +01:00
Andrew Burgess
650400cb53 gdb/dap: check values are available before converting to int
In VariableReference.to_object, we try to convert a gdb.Value to an
int without checking if the value is actually available.  This came to
light in PR gdb/33345, after the x86 CET shadow stack patches were
merged.

If the x86 CET shadow stack register is available on the machine,
but the shadow stack feature is not enabled at run time, then the
register will show as "<unavailable>".

As the register is of type 'void *', then in the DAP code we try to
add a 'memoryReference' attribute with the value of the register
formatted as hex.  This will fail if the register is unavailable.

To test this change you'll need:

  (a) a machine which support the shadow stack feature, and

  (b) to revert the changes from commit 63b862be76 in the file
      gdb.dap/scopes.exp.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33345
Reviewed-By: Christina Schimpe <christina.schimpe@intel.com>
2025-09-04 22:18:59 +01:00
Andrew Burgess
b652ce7b80 gdb/python: add gdb.Value.is_unavailable attribute
Add a new gdb.Value.is_unavailable attribute.  This is similar to the
existing Value.is_optimized_out attribute, but returns True if any
part of the value is <unavailable>.

The existing Value.is_optimized_out attribute returns true if any part
of the value is optimized out, so I thought that Value.is_unavailable
should work the same way.

There's also a test.

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

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-By: Christina Schimpe <christina.schimpe@intel.com>
2025-09-04 22:18:59 +01:00
Pawel Kupczak
95f21c0d25 gdb, amd64: return after amd64_analyze_register_saves if current_pc reached
Make sure the function bails out early if CURRENT_PC is reached, to
avoid the call to amd64_analyze_stack_alloc.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-09-04 20:44:48 +00:00
Pawel Kupczak
57ce06ac23 gdb, amd64: extend the amd64 prologue analyzer to skip stack alloc
Following the previous patch (gdb, amd64: extend the amd64 prologue
analyzer to skip register pushes), this patch extends the analyzer
further to be able to skip stack space allocation as the next prologue
part, for functions with a frame pointer.  Implementation was based
on the i386 counterpart, which already had that functionality.

As of now, the stack allocation is not skipped.  Examples below use C
source listed below, compiled with gcc 11.4.0.
```
	int foo (int n)
	{
	    int ns[] = { 1, 4, 9, 16, 25 };
	    return ns[n];
	}

	int
	main (int argc, char **argv)
	{
	    return foo (argc);
	}
```

Compiling with "gcc -O0 -fno-omit-frame-pointer" we get:
```
	(gdb) b foo
	Breakpoint 1 at 0x1151
	(gdb) r
	...
	Breakpoint 1, 0x0000555555555151 in foo ()
	(gdb) disassemble
	Dump of assembler code for function foo:
	   0x0000555555555149 <+0>:     endbr64
	   0x000055555555514d <+4>:     push   %rbp
	   0x000055555555514e <+5>:     mov    %rsp,%rbp
	=> 0x0000555555555151 <+8>:     sub    $0x30,%rsp
	   0x0000555555555155 <+12>:    mov    %edi,-0x24(%rbp)
	...
```

With this patch, it gets skipped the same way register pushes are:
```
	(gdb) b foo
	Breakpoint 1 at 0x1155
	(gdb) r
	...
	Breakpoint 1, 0x0000555555555155 in foo ()
	(gdb) disassemble
	Dump of assembler code for function foo:
	   0x0000555555555149 <+0>:     endbr64
	   0x000055555555514d <+4>:     push   %rbp
	   0x000055555555514e <+5>:     mov    %rsp,%rbp
	   0x0000555555555151 <+8>:     sub    $0x30,%rsp
	=> 0x0000555555555155 <+12>:    mov    %edi,-0x24(%rbp)
	...
```

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-09-04 20:44:48 +00:00
Pawel Kupczak
8862ee5886 gdb, amd64: return after amd64_analyze_frame_setup if current_pc reached
Make sure the function bails out early if CURRENT_PC is reached, to
avoid the call to amd64_analyze_register_saves.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-09-04 20:44:48 +00:00
Pawel Kupczak
f9aa48dc54 gdb, amd64: extend the amd64 prologue analyzer to skip register pushes
A typical function's prologue can consist of setting up a frame pointer,
pushing registers onto the stack and allocating space on the stack.
Current amd64 prologue analyzer would stop after the frame setup.
This patch allows GDB to skip past register pushes, while also improving
unwinding pushed registers, for functions with a frame pointer, without
debug info and .cfi directives found in .eh_frame section that are used
for unwinding.  Skipping register pushes was also present for i386
targets before - the proposed changes are based on i386 implementation.

It also improves the unwinding even if .cfi directives are present,
because GDB can only unwind a register if it has reached a corresponding
.cfi directive, which won't be there before the pushes.

Additionally, at least gcc 11.4 and later by default doesn't emit
necessary debug info, which GDB would try to use to find prologue's end.
In that case, extended prologue analyzer would take effect.

Using C source listed below as an example, compiled with gcc 11.4.0:
```
	int __attribute__ ((noinline))
	bar (int a)
	{
	    return a + a;
	}

	int __attribute__ ((noinline))
	foo (int a, int b, int c, int d, int e)
	{
	    int x = bar (a) + bar (b) + bar (c) + bar (d) + bar (e);
	    return x;
	}

	int
	main (int argc, char **argv)
	{
	    return foo (1, 2, 3, 4, 5);
	}
```

Compiling with "gcc -O1 -fno-omit-frame-pointer
-fno-asynchronous-unwind-tables", we get:
```
	(gdb) b foo
	Breakpoint 1 at 0x1139
	(gdb) r
	...
	Breakpoint 1, 0x0000555555555139 in foo ()
	(gdb) disassemble
	Dump of assembler code for function foo:
	   0x0000555555555131 <+0>:     endbr64
	   0x0000555555555135 <+4>:     push   %rbp
	   0x0000555555555136 <+5>:     mov    %rsp,%rbp
	=> 0x0000555555555139 <+8>:     push   %r15
	   0x000055555555513b <+10>:    push   %r14
	   0x000055555555513d <+12>:    push   %r13
	   0x000055555555513f <+14>:    push   %r12
	   0x0000555555555141 <+16>:    push   %rbx
	   0x0000555555555142 <+17>:    sub    $0x8,%rsp
	   0x0000555555555146 <+21>:    mov    %esi,%r15d
	...
	(gdb) ni
	0x000055555555513b in foo ()
	(gdb) p $r15
	$1 = 140737354125376
	(gdb) p $r15=1234
	$2 = 1234
	(gdb) p $r15
	$3 = 1234
	(gdb) up
	#1  0x00005555555551b7 in main ()
	(gdb) p $r15
	$4 = 1234
```

With the proposed changes, breakpoint gets past those register pushes:
```
	(gdb) b foo
	Breakpoint 1 at 0x1142
	(gdb) r
	...
	Breakpoint 1, 0x0000555555555142 in foo ()
	(gdb) disassemble
	Dump of assembler code for function foo:
	   0x0000555555555131 <+0>:     endbr64
	   0x0000555555555135 <+4>:     push   %rbp
	   0x0000555555555136 <+5>:     mov    %rsp,%rbp
	   0x0000555555555139 <+8>:     push   %r15
	   0x000055555555513b <+10>:    push   %r14
	   0x000055555555513d <+12>:    push   %r13
	   0x000055555555513f <+14>:    push   %r12
	   0x0000555555555141 <+16>:    push   %rbx
	=> 0x0000555555555142 <+17>:    sub    $0x8,%rsp
	   0x0000555555555146 <+21>:    mov    %esi,%r15d
	...
```

Also, unwinding pushed registers now works:
```
	...
	Breakpoint 1, 0x0000555555555142 in foo ()
	(gdb) disassemble
	Dump of assembler code for function foo:
	   0x0000555555555131 <+0>:     endbr64
	   0x0000555555555135 <+4>:     push   %rbp
	   0x0000555555555136 <+5>:     mov    %rsp,%rbp
	   0x0000555555555139 <+8>:     push   %r15
	   0x0000555555555139 <+8>:     push   %r15
	   0x000055555555513b <+10>:    push   %r14
	   0x000055555555513d <+12>:    push   %r13
	   0x000055555555513f <+14>:    push   %r12
	   0x0000555555555141 <+16>:    push   %rbx
	=> 0x0000555555555142 <+17>:    sub    $0x8,%rsp
	   0x0000555555555146 <+21>:    mov    %esi,%r15d
	...
	(gdb) p $r15
	$1 = 140737354125376
	(gdb) p $r15=1234
	$2 = 1234
	(gdb) p $r15
	$3 = 1234
	(gdb) up
	#1  0x00005555555551b7 in main ()
	(gdb) p $r15
	$4 = 140737354125376
```

Additionally a new test was added to verify this behavior.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-09-04 20:44:48 +00:00
Tom Tromey
55fc9233a8 Don't require "Bss=" in qOffsets response
The "Bss=" part of the qOffsets response is documented as being
optional, but gdb in fact requires it.  This patch fixes the bug.

I couldn't find a straightforward way to test this.  gdbserver does
send 'Bss=' -- but this code is only enabled for a fairly specific
setup:

    #if (defined(__UCLIBC__)		\
	 && defined(HAS_NOMMU)		\
	 && defined(PT_TEXT_ADDR)		\
	 && defined(PT_DATA_ADDR)		\
	 && defined(PT_TEXT_END_ADDR))
    #define SUPPORTS_READ_OFFSETS
    #endif

I also considered changing gdbserver to not send Bss=, but decided
against this, reasoning that we may as well not break compatibility
with older versions of gdb.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33319
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-04 14:39:32 -06:00
Guinevere Larsen
e90c268b3e gdb/testsuite: fix possible TCL errors in gdb.threads/threadcrash.exp
The test gdb.threads/threadcrash.exp, among other things, creates a list
of the threads seen in the order that the "thread apply all backtrace"
would generate them, tests that this list is the same size as GDB's
count of threads, and then loops over the list to check that each
thread has the expected backtrace.

A problem occurs because the loop iterates on GDB's internal count of
threads, rather than the size of the list, but then attempts to acces
the n-th element of the list. If the list size is smaller than GDB's
internal thread count, it'll access past the end of the list and
generate TCL errors.

This commit fixes this by using the list's length instead.

Approved-By: Tom Tromey <tom@tromey.com>
2025-09-04 14:56:37 -03:00
Andrew Burgess
88d6ee4c9a gdb: remove most global core file accesses from fbsd-tdep.c
This commit removes many places in fbsd-tdep.c where we access the
current core file via current_program_space, and replaces these
accesses with a function argument that is passed in.

There are still two uses of 'current_program_space->core_bfd ()' in
the file, these will be addressed in future work (not in this series
though).

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-04 16:44:34 +01:00
Andrew Burgess
a45b16f16e gdb: pass core file to gdbarch_core_xfer_siginfo
Another patch that aims to remove 'current_program_space->core_bfd ()'
from GDB.  This time I'm passing the core file BFD as an argument to
the gdbarch method gdbarch_core_xfer_siginfo.

In corelow.c the core file is being passed, this does introduce a new
instance of 'current_program_space->core_bfd ()', but this is OK.  My
long term plan is to move the core bfd into core_target, in which case
the call to gdbarch_core_xfer_siginfo will have access to the core bfd
as a member variable.

For now though, this patch moves the accesses via global state up the
call stack, and consolidates the two calls from fbsd-tdep.c and
linux-tdep.c into the one call in corelow.c.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-04 16:43:19 +01:00
Andrew Burgess
a839a42bcd gdb: remove most global core file accesses from record-full.c
This commit continues my ongoing work to reduce the number of global
accesses to the current core file BFD in GDB.  The global accesses I'm
working on removing look like 'current_program_space->core_bfd ()'.

This commit targets record-full.c.  All global accesses are removed
except for two in record_full_open, which is used to implements the
two commands 'target record-full' and 'record full restore'.

All other global accesses to the core file are removed by passing the
core file through as an argument from this one top level function.

As I followed the code through I noticed that record_full_restore,
which currently includes this check:

  if (current_program_space->core_bfd () == nullptr)
    return;

could never actually be called without a core file being set.  As the
argument is now 'struct bfd &', then there is no longer an option for
the incoming argument to be NULL, and the above check is removed.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-04 16:16:01 +01:00
Andrew Burgess
9cede382cb 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>
2025-09-04 16:07:10 +01:00
Tom de Vries
9463d3e756 [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.
2025-09-04 16:15:26 +02:00
Tom de Vries
9651adf4a4 [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.
2025-09-04 16:15:26 +02:00
Tom de Vries
40cd67be49 [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.
2025-09-04 16:15:26 +02:00
Tom de Vries
3638ca4c79 [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
2025-09-04 16:15:26 +02:00
Tom de Vries
fa06ea7498 [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
...
2025-09-04 16:15:26 +02:00
Tom de Vries
eeb28714f7 [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.
2025-09-04 16:15:26 +02:00
Tom de Vries
55050c2f7e [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.
2025-09-04 16:15:26 +02:00
Nelson Chu
519349b57d 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.
2025-09-04 16:33:50 +08:00
Nelson Chu
672a326e2c 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.
2025-09-04 16:32:44 +08:00
Nelson Chu
cea397848b RISC-V: Fixed missed GOT relocation against a symbol that has a defined value
SImilar to aarch64, commit eac4eb8ecb

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 50331d64f1.

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.
2025-09-04 16:32:18 +08:00
Tom de Vries
8b91a77eda [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.
2025-09-04 09:23:13 +02:00
GDB Administrator
980662750f Automatic date update in version.in 2025-09-04 00:00:47 +00:00
Andrew C Aitchison
674628ae3a PR 33360, Correct strings -Ue output
Signed-off-by: Andrew C Aitchison <andrew@aitchison.me.uk>
2025-09-04 07:36:08 +09:30
Alan Modra
5e2ebcf1ea 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.
2025-09-04 07:36:08 +09:30
Tom de Vries
e66c9cb4d1 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.
2025-09-03 19:49:55 +02:00
Tom de Vries
4d47956f3e [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.
2025-09-03 18:56:37 +02:00
Tom de Vries
6a5c1f8020 [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.
2025-09-03 18:20:47 +02:00
Tom de Vries
086e3c9bc2 [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.
2025-09-03 18:09:41 +02:00
Tom de Vries
1eac6d15fd [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.
2025-09-03 17:38:09 +02:00
H.J. Lu
955b8e0939 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>
2025-09-03 08:22:33 -07:00
Tom de Vries
683076ce0d [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.
2025-09-03 16:43:34 +02:00
Tom de Vries
2f88dd1987 [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.
2025-09-03 16:29:37 +02:00
Tom de Vries
09458c89ba [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.
2025-09-03 16:21:18 +02:00
Tom de Vries
95014c4fba [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.
2025-09-03 16:15:37 +02:00
Tom de Vries
e9aaad1984 [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.
2025-09-03 16:05:07 +02:00
Tom de Vries
0fba01ef98 [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.
2025-09-03 15:41:22 +02:00
Tiezhu Yang
213f150cf7 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 208b57e53e ("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 a4242dc3f5 ("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>
2025-09-03 20:56:51 +08:00
Tiezhu Yang
40f41b242f 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>
2025-09-03 20:56:30 +08:00
Tom de Vries
37e9197625 [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.
2025-09-03 14:52:17 +02:00
H.J. Lu
aad80d24d2 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>
2025-09-03 05:49:00 -07:00
H.J. Lu
5d3a6f777d 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>
2025-09-03 05:44:54 -07:00
Tom de Vries
15170022f7 [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.
2025-09-03 14:39:14 +02:00
H.J. Lu
8a94d92a46 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>
2025-09-03 05:38:23 -07:00