Commit Graph

120257 Commits

Author SHA1 Message Date
Simon Marchi
3470a0e144 gdbserver: remove for_each_thread(pid, func)
Remove this overload, prefer to use `process_info::for_each_thread`.  In
many instances, the `process_info` is already available, so this saves a
map lookup.  In other instances, add the `process_info` lookup at the
call site.

In `linux-arm-low.cc` and `win32-i386-low.cc`, use `current_process ()`
instead of `current_thread->id.pid ()`.  I presume that if
`current_process ()` and `current_thread` don't match, it's a bug
orthogonal to this change.

Change-Id: I751ed497cb1f313cf937b35125151bee9316fc51
Reviewed-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
2024-11-08 09:16:23 -05:00
Schimpe, Christina
6672ccafd9 gdb: LoongArch: Remove use of gdbarch_remove_non_address_bits hook
LoongArch doesn't implement the hook gdbarch_remove_non_address_bits, so
there is no need to use the hook in gdb/loongarch-linux-nat.c.

Approved-By: Luis Machado <luis.machado@arm.com>
2024-11-08 13:14:45 +00:00
Guinevere Larsen
9ebb627ed6 gdb: make the error message for unreadable objfiles more informative
When GDB is unable to read an objfile, it prints the error message "I'm
sorry Dave, I can't do that. Symbol format `%s' unknown.". While it is a
great reference, an end user won't have much information about the
problem.

So far this wasn't much of a problem, as it is very uncommon for GDB to
be unable to read an objfile. However, a future patch will allow users
to selectively disable support to some formats, making it somewhat
expected that the message will be seen by end users.

This commit makes the end message more informative and direct.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13299
Approved-By: Tom Tromey <tom@tromey.com>
2024-11-08 08:59:05 -03:00
Matthieu Longo
3a4653efc3 aarch64: add flag OPD_F_UNSIGNED to distinguish signedness of immediate operands
This patch introduces a new operand flag OPD_F_UNSIGNED to signal that
the immediate value should be treated as an unsigned value. The default
signedness of immediate operands is signed.
2024-11-08 11:35:46 +00:00
Matthieu Longo
23cd66ea0e aarch64: testsuite: remove hard-coded instruction addresses 2024-11-08 11:35:46 +00:00
Matthieu Longo
e308b2999c aarch64: remove redundant register type R_N
The register type R_N is redundant with R_ZR_SP. This patch removes it,
and replaces its usage by R_ZR_SP.
2024-11-08 11:35:46 +00:00
Matthieu Longo
46dace1933 aarch64: improve debuggability on array of enum
The current space optmization on enum aarch64_opn_qualifier forced its
encoding using an unsigned char. This "hard-coded" optimization has the
bad consequence of making the array of such enums being completely
unreadable when debugging with GDB because the enum type is lost along
the way.
Keeping this space optimization, and the enum type as well, is possible
when the declaration of the enum is tagged with attribute((packed)).
attribute((packed)) is a GNU extension, and is wrapped in the macro
ATTRIBUTE_PACKED (defined in ansidecl.h), and should be used instead.
2024-11-08 11:35:46 +00:00
Matthieu Longo
c703d0aff5 aarch64: change returned type to bool to match semantic of functions 2024-11-08 11:35:46 +00:00
Matthieu Longo
a924330947 aarch64: constify unchanged char* arguments 2024-11-08 11:35:46 +00:00
Matthieu Longo
f0af85dc9e aarch64: make comment clearer about the location
The enum aarch64_opnd_qualifiers in include/opcode/aarch64.h needs to
stay in sync with the array of struct operand_qualifier_data which
defines various properties for the different type of operands. For
instance, for:
- registers: the size of the register, the number of elements.
- immediates: lower and upper bits to determine the range of values.
2024-11-08 11:35:46 +00:00
Andrew Burgess
dbca1bef47 gdb/testsuite: fix gdb.base/basic-edit-cmd.exp test
In the recent commit:

  commit 31ada87f91
  Date:   Wed Nov 6 22:18:55 2024 +0000

      gdb: fixes and tests for the 'edit' command

the new gdb.base/basic-edit-cmd.exp was added.  The Linaro CI
highlighted an issue with the test which I failed to address before
pushing the above commit.

Part of the test loads a file into GDB and then uses the 'edit'
command with no arguments to edit the default location.  This default
location is expected to be the 'main' function.

On my local machine the line reported is the opening '{' of main, and
that is what the test checks for.

The Linaro CI though appears to see the first code line of main.

I think either result is fine as far as this test is concerned, so
I've expanded the test regexp to check for either line number.  This
should make the CI testing happy again.
2024-11-08 11:19:33 +00:00
Andrew Burgess
31ada87f91 gdb: fixes and tests for the 'edit' command
This commit was inspired by this mailing list post:

  https://inbox.sourceware.org/gdb-patches/osmtfvf5xe3yx4n7oirukidym4cik7lehhy4re5mxpset2qgwt@6qlboxhqiwgm

When reviewing that patch, the first thing I wanted to do was add some
tests for the 'edit' command because, as far as I can tell, there are
no real tests right now.

The approach I've taken for testing is to override the EDITOR
environment variable, setting this to just 'echo'.  Now when the
'edit' command is run, instead of entering an interactive editor, the
shell instead echos back the arguments that GDB is trying to pass to
the editor.  The output might look like this:

  (gdb) edit
  +22 /tmp/gdb/testsuite/gdb.base/edit-cmd.c
  (gdb)

We can then test this like any other normal command.  I then wrote
some basic tests covering a few situations like, using 'edit' before
the inferior is started.  Using 'edit' without any arguments, and
using 'edit' with a line number argument.

There are plenty of cases that are still not tested, for example, the
test program only has a single source file for example.  But we can
always add more tests later.

I then used these tests to validate the fix proposed in the above
patch.

The patch above does indeed fix some cases, specifically, when GDB
stops at a location (e.g. a breakpoint location) and then the 'edit'
command without any arguments is fixed.  But using the 'list' command
to show some other location, and then 'edit' to edit the just listed
location broken before and after the above patch.

I am instead proposing this alternative patch which I think fixes more
cases.  When GDB stops at a location then 'edit' with no arguments
should correctly edit the current line.  And using 'list XX' to list a
specific location, followed by 'edit' should also now edit the just
listed location.

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

Co-Authored-By: Lluís Batlle i Rossell <viric@viric.name>
Approved-By: Tom Tromey <tom@tromey.com>
2024-11-08 10:44:43 +00:00
Mark Wielaard
328f42d85b bfd: Remove unused static find function from doc/chew.c
After commit 2e60790cf7 "Remove the
paramstuff word" there is no caller left of the static find function
in doc/chew.c, so it should be removed.

* doc/chew.c (find): Remove.
2024-11-08 11:08:56 +01:00
Andre Vieira
cfbbd40333 arm, objdump: print obsolote warning when 26-bit set in instructions
Arm has obsoleted the 26-bit addressing mode. Diagnose this when disasembling
these instructions by printing OBSOLETE.
2024-11-08 10:06:57 +00:00
Andre Vieira
2c9d089c90 arm, objdump: Make objdump use bfd's machine detection to drive disassembly
For any arm elf target, disable an old piece of code that forced disassembly to
disassemble for 'unknown architecture' which once upon a time meant it would
disassemble ANY arm instruction.  This is no longer true with the addition of
Armv8.1-M Mainline, as there are conflicting encodings for different thumb
instructions.

BFD however can detect what architecture the object file was assembled for
using information in the notes section.  So if available, we use that,
otherwise we default to the old 'unknown' behaviour.

With the changes above code, a mode changing 'bx lr' assembled for armv4 with
the option --fix-v4bx will result in an object file that is recognized by bfd
as one for the armv4 architecture.  The disassembler now disassembles this
encoding as a BX even for Armv4 architectures, but warns the user when
disassembling for Armv4 that this instruction is only valid from Armv4T
onwards.

Remove the unused and wrongfully defined ARM_ARCH_V8A_CRC, and
define and use a ARM_ARCH_V8R_CRC to make sure instructions enabled by
-march=armv8-r+crc are disassembled correctly.

Patch up some of the tests cases, see a brief explanation for each below.

inst.d:
This test checks the assembly & disassembly of basic instructions in armv3m. I
changed the expected behaviour for teqp, cmnp cmpp and testp instructions to
properly print p when disassembling, whereas before, in the 'unknown' case it
would disassemble these as UNPREDICTABLE as they were changed in later
architectures.

nops.d:
Was missing an -march, added one to make sure we were testing the right
behavior of NOP<c> instructions.

unpredictable.d:
Was missing an -march, added armv6 as that reproduced the behaviour being
tested.
2024-11-08 10:06:38 +00:00
Tom de Vries
39d45a7031 [gdb/tdep] Use raw_supply_zeroed in i387_supply_xsave
Use reg_buffer::raw_supply_zeroed in i387_supply_xsave.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-08 10:00:14 +01:00
Tom de Vries
a452ed5b5c [gdb/tdep] Use raw_supply_zeroed for NIOS r0 reg
Use reg_buffer::raw_supply_zeroed for NIOS register r0.

Tested by rebuilding on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-08 10:00:14 +01:00
Tom de Vries
221d3ac93d [gdb/tdep] Use raw_supply_zeroed for Alpha r31 reg
Use reg_buffer::raw_supply_zeroed for Alpha register r31.

Tested by rebuilding on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-08 10:00:14 +01:00
Tom de Vries
a2578d52bd [gdb/tdep] Use raw_supply_zeroed for PA-RISC r0 reg
Use reg_buffer::raw_supply_zeroed for PA-RISC register r0.

Tested by rebuilding on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-08 10:00:14 +01:00
Tom de Vries
e08e0b3e78 [gdb/tdep] Use raw_supply_zeroed for IA-64 gr0 and fr0 regs
Use reg_buffer::raw_supply_zeroed for IA-64 registers gr0 and fr0.

Tested by rebuilding on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-08 10:00:13 +01:00
GDB Administrator
01086f8a21 Automatic date update in version.in 2024-11-08 00:00:33 +00:00
Andre Simoes Dias Vieira
b6ccbbd5d3 arm: Skip two failing tests for wince & pe targets
We don't seem to support any m-profile assembly/disassembly tests for wince or
pe, so skipping the pacbti one too.

The pr29494 test needs to be skipped because it uses assembly syntax that is
not supported in wince/pe like for instance eabi_attribute directives.
2024-11-07 15:50:52 +00:00
Nick Clifton
aec7815b4b
Deprecate the ARM simulator.
The ARM simulator is no longer able to simulator modern ARM cores, so it
    is being deprecated.  Once this change has been active for a while - and
    assuming that no problems have been found - the ARm simulator codebase
    will be removed.
2024-11-07 14:53:26 +00:00
Stephan Rohr
c26f8fbe79 gdbserver: add process specific thread list and map
Replace the servers global thread list with a process specific thread
list and a ptid -> thread map similar to 'inferior::ptid_thread_map' on
GDB side.  Optimize the 'find_thread' and 'find_thread_ptid' functions
to use std::unordered_map::find for faster lookup of threads without
iterating over all processes and threads, if applicable.  This becomes
important when debugging applications with a large thread count, e.g.,
in the context of GPU debugging.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-11-07 02:50:48 -08:00
Stephan Rohr
9f77b3aa0b gdbserver: change 'all_processes' and 'all_threads' list type
This patch replaces the 'std::list' type of 'all_processes' and
'all_threads' with the more lightweight 'owning_intrusive_list'
type.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-11-07 02:50:48 -08:00
GDB Administrator
8adee4d2ce Automatic date update in version.in 2024-11-07 00:00:53 +00:00
Peter Bergner
56fe851ced PowerPC: Merge rfc2655 and rfc2656 test cases into one future test case
gas/
	* testsuite/gas/ppc/rfc02655.[ds]: Rename from this...
	* testsuite/gas/ppc/future.[ds]: ... to this.
	* testsuite/gas/ppc/rfc02656.[ds]: Delete.  Move tests to future.[ds].
	* testsuite/gas/ppc/ppc.exp: Update for file name changes.
2024-11-06 13:37:10 -06:00
Tom de Vries
1873768e44 [gdb/tdep] Use raw_supply_zeroed for SPARC g0 reg
Use reg_buffer::raw_supply_zeroed for SPARC register g0.

Tested by rebuilding on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-06 16:42:58 +01:00
Klaus Gerlicher
7ea50bf94f gdb: remove exact_match parameter from find_line_symtab
struct symtab *find_line_symtab (struct symtab *, int, int *, bool *);

The last parameter is bool* that when set will receive information
if the match was exact. This parameter is never used by any callsite
and can therefore be removed.

This will become:

symtab *find_line_symtab (symtab *sym_tab, int line, int *index);

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-06 10:15:25 +00:00
GDB Administrator
52a8387dfd Automatic date update in version.in 2024-11-06 00:00:43 +00:00
GDB Administrator
e1e4078ac5 Automatic date update in version.in 2024-11-05 00:00:32 +00:00
Tom Tromey
ae2f3fa758 Turn decode_line_2_compare_items into operator<
This rewrites decode_line_2_compare_items to be an operator< on the
relevant type.  This simplifies the code a little.

Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-11-04 12:56:57 -07:00
Simon Marchi
0b4c9b5057 gdb: cleanup includes in *-typeprint.[ch]
Remove includes reported as unused by clangd.

Include "gdb-hashtab.h" in typeprint.h for the use of "htab_up".

Change-Id: I5b04ec14e71800e2d6ad622838e39b7033e168cf
2024-11-04 13:19:03 -05:00
Simon Marchi
a2d63ac679 gdb: cleanup includes in gdbtypes.h
Remove some includes reported as unused by clangd.

Change-Id: Ifc74f782d5aaafd1d719816821860352090c6667
2024-11-04 13:18:23 -05:00
Tom Tromey
8675d15227 Remove gdb::hash_enum
gdb::hash_enum is a workaround for a small oversight in C++11:
std::hash was not defined for enumeration types.  This was rectified
in C++14 and so we can remove the local workaround.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-11-04 10:49:06 -07:00
Andrew Burgess
ebc73070f4 gdb: use option framework for add-inferior and clone-inferior
Convert the add-inferior and clone-inferior commands to make use of
the option framework.  This improves the tab completion for these
commands.

Previously the add-inferior command used a trick to simulate
completion of -exec argument.  The command use filename completion for
everything on the command line, thus you could do:

  (gdb) add-inferior /path/to/some/fil<TAB>

and GDB would complete the file name, even though add-inferior doesn't
really take a filename as an argument.  This helped a little though
because, if the user did this:

  (gdb) add-inferior -exec /path/to/some/fil<TAB>

then the file name would be completed.  However, GDB didn't really
understand the options, so couldn't offer completion of the options
themselves.

After this commit, the add-inferior command makes use of the recently
added gdb::option::filename_option_def feature.  This means that the
user now has full completion of the option names, and that file names
will still complete for the '-exec' option, but will no longer
complete if the '-exec' option is not used.

I have also converted the clone-inferior command, though this command
does not use any file name options.  This command does now have proper
completion of the command options.
2024-11-04 16:11:51 +00:00
Andrew Burgess
3105b46ed1 gdb: add filename option support
This commit adds support for filename options to GDB's option
sub-system (see cli/cli-option.{c,h}).

The new filename options support quoted and escaped filenames, and tab
completion is fully supported.

This commit adds the new option, and adds these options to the
'maintenance test-options' command as '-filename', along with some
tests that exercise this new option.

I've split the -filename testing into two.  In gdb.base/options.exp we
use the -filename option with some arbitrary strings.  This tests that
GDB can correctly extract the value from a filename option, and that
GDB can complete other options after a filename option.  However,
these tests don't actually pass real filenames, nor do they test
filename completion.

In gdb.base/filename-completion.exp I have added some tests that test
the -filename option with real filenames, and exercise filename tab
completion.

This commit doesn't include any real uses of the new filename options,
that will come in the next commit.
2024-11-04 15:56:01 +00:00
Andrew Burgess
91f8973ba3 gdb/testsuite: spring clean the gdb.stabs/gdb11479.exp test
I had reason to look at the gdb.stabs/gdb11479.exp test script and
figured it could do with a small clean up.  I've:

  - Made use of standard_testfile and the variables it defines.

  - Made use of with_test_prefix and removed the prefix from the end
    of each test name.

  - Avoid overwriting the test binary when we recompile, instead use a
    different name for each recompilation.

  - Add '.' at the end of each comment.

There should be no changes in what is tested with this commit.

Reviewed-By: Keith Seitz <keiths@redhat.com>
2024-11-04 15:51:40 +00:00
Aditya Vidyadhar Kamath
9247f05284 Fix AIX core dump while main thread exits.
Consider the test case:
void *thread_main(void *) {
  std::cout << getpid() << std::endl;
  sleep(20);
  return nullptr;
}

int main(void) {
  pthread_t thread;
  pthread_create(&thread, nullptr, thread_main, nullptr);
  pthread_join(thread, nullptr);

  return 0;
}

This program creates a thread via main that sleeps for 20 seconds.

When we debug this with gdb we get,
Reading symbols from ./test...
(gdb) b main
Breakpoint 1 at 0x10000934: file test.c, line 11.
(gdb) r
Starting program: /read_only_gdb/binutils-gdb/gdb/test

Breakpoint 1, main () at test.c:11
11   pthread_create(&thread, nullptr, thread_main, nullptr);
(gdb) c
Continuing.
15335884
[New Thread 258 (tid 31130079)]
Thread 2 received signal SIGINT, Interrupt.
[Switching to Thread 258 (tid 31130079)]
0xd0611d70 in _p_nsleep () from /usr/lib/libpthread.a(_shr_xpg5.o)
(gdb) thread 1
[Switching to thread 1 (Thread 1 (tid 25493845))]
(gdb) c
Continuing.
[Thread 1 (tid 25493845) exited]
[Thread 258 (tid 31130079) exited]
inferior.c:405: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----

There are two bugs here. One is the core dump. The other is the main thread information
not captured.

So, while I was debugging the first part the reason, the reason I figured out was
the last for loop in sync_threadlists ().

Once both my threads exit we delete them as below:

for (struct thread_info *it : all_threads ())
      {
if (in_queue_threads.count (priv->pdtid) == 0
        && in_thread_list (proc_target, it->ptid)
        && pid == it->ptid.pid ())
      {
        delete_thread (it);
        data->exited_threads.insert (priv->pdtid);

But once these two threads are deleted, all_threads ()
has one more thread whose tid and pid are 0.

gdb) c
Continuing.
In for loop 8782296 is pid, 19857879 is tid
[Thread 1 (tid 19857879) exited]
In for loop 8782296 is pid, 30933401 is tid
[Thread 258 (tid 30933401) exited]
In for loop 0 is pid, 0 is tid
[Inferior 1 (process 8782296) exited normally]
(gdb) q

I used a printf in the for loop mentioned above for explaination.

You see the loop enters the third time with 0 as pid.

The reason being though the threads are removed but not deleted since they are
not deletable ().

Hence we use all_threads_safe () iterator instead.

The second part to the bug is the lack of information of the main thread.
Andrew was right here (https://sourceware.org/pipermail/gdb-patches/2024-September/211875.html)
Thank you Andrew.

The thread has loaded but then ptrace () call when we tried to fetch_regs_kernel_thread
failed. This returned EPERM as errno.

if (!ptrace32 (PTT_READ_GPRS, tid, (uintptr_t) gprs32, 0, NULL))
        memset (gprs32, 0, sizeof (gprs32));

Hence all registers were set to 0 and we did not get the required infromation.
This issue will be fixed within the AIX ptrace call.

Approved By: Ulrich Weigand <ulrich.weigand@de.ibm.com>.
2024-11-04 02:42:05 -06:00
GDB Administrator
55e32b3c68 Automatic date update in version.in 2024-11-04 00:00:32 +00:00
GDB Administrator
69a9577358 Automatic date update in version.in 2024-11-03 00:00:17 +00:00
GDB Administrator
22d7506fb9 Automatic date update in version.in 2024-11-02 00:00:22 +00:00
Vladimir Mezentsev
d25ba4596e gprofng: use gprofng- prefix for gprofng binaries
gprofng application names have a gp- prefix (gp-display-text, gp-archive, etc.).
But our man pages use the gprofng- prefix (gprofng-display-text,
gprofng-archive, etc.).
I renamed the gprofng binaries and temporarily created the gp-* links for
compatibility with the old gprofng-gui.
We plan to remove these links in version 2.46.

gprofng/ChangeLog
2024-10-31  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	* doc/gprofng-archive.texi: Rename gprofng application names.
	* doc/gprofng-collect-app.texi: Likewise.
	* doc/gprofng-display-html.texi: Likewise.
	* doc/gprofng-display-src.texi: Likewise.
	* doc/gprofng-display-text.texi: Likewise.
	* doc/gprofng.texi: Likewise.
	* doc/gprofng_ug.texi: Likewise.
	* gp-display-html/Makefile.am: Likewise.
	* gp-display-html/gp-display-html.in: Likewise.
	* libcollector/collector.c: Likewise.
	* src/Application.cc: Likewise.
	* src/Experiment.cc: Likewise.
	* src/Makefile.am: Likewise.
	* src/gp-archive.cc: Likewise.
	* src/gp-collect-app.cc: Likewise.
	* src/gp-display-src.cc: Likewise.
	* src/gp-display-text.cc: Likewise.
	* src/gprofng.cc: Likewise.
	* src/Makefile.in: Rebuild.
	* gp-display-html/Makefile.in: Rebuild.
2024-11-01 16:46:21 -07:00
Vladimir Mezentsev
e0c182c3ac Fix 32303 ./configure --help: replace --enable-gprofng with --disable-gprofng
ChangeLog
2024-10-31  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	PR 32303
	* configure.ac: Replace --enable-gprofng with --disable-gprofng
	* configure: Rebuild.
2024-11-01 16:32:33 -07:00
Indu Bhagat
47c88752f9 ld: generate SFrame stack trace info for .plt.got
PR/32298 sframe: no SFrame stack trace info generated for .plt.got

Add support to generate SFrame stack trace info for .plt.got section.
Enhance the current definition of struct elf_x86_sframe_plt to include
initialized SFrame FDE/FREs applicable for .plt.got section.  There are
two variants of .plt.got entries: 16 byte and 8 byte.

8 byte:
    ff 25 00 00 00 00     jmpq  *name@GOTPCREL(%rip)
    66 90                 xchg  %ax,%ax

16 byte:
    f3 0f 1e fa           endbr64
    ff 25 66 2f 00 00     jmpq  *name@GOTPCREL(%rip)
    66 0f 1f 44 00 00     nopw   0x0(%rax,%rax,1)

For the testcase, define some application symbols such that their PLT
entry is placed in .plt.got and ensure SFrame information is generated
with and without -z ibtplt.

ChangeLog:
	PR/32298
	* bfd/elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties):
	PLT GOT entry size is different for IBT vs non IBT PLTs.
	* bfd/elfxx-x86.c (enum dynobj_sframe_plt_type): New enum for
	SFRAME_PLT_GOT.
	(_bfd_x86_elf_create_sframe_plt): Handle SFRAME_PLT_GOT.
	(_bfd_x86_elf_write_sframe_plt): Likewise.
	(_bfd_x86_elf_late_size_sections): Likewise.
	(_bfd_x86_elf_finish_dynamic_sections): Likewise.
	* bfd/elfxx-x86.h (struct elf_x86_sframe_plt): Add new members
	to keep information about PLT GOT entries.
	(struct elf_x86_link_hash_table): Add support for creating
	SFrame section for .plt.got.
	* ld/testsuite/ld-x86-64/x86-64.exp: Add new tests.
	* ld/testsuite/ld-x86-64/sframe-pltgot-1.d: New test.
	* ld/testsuite/ld-x86-64/sframe-pltgot-1.s: New test.
	* ld/testsuite/ld-x86-64/sframe-pltgot-2.d: New test.
2024-11-01 15:36:35 -07:00
Josh Poimboeuf
938fb51218 ld: fix wrong SFrame info for lazy IBT PLT
Fix PR/32296 sframe: wrong SFrame info for pltN and .plt.sec for -z ibtplt

The x86 psABI defines a 2-PLT scheme for IBT which uses .plt and
.plt.sec entries.  It was observed that SFrame information for .plt.sec
section was incorrect.  The erroneous assumption was that SFrame stack
trace information for .plt.sec with lazy binding is the same as SFrame
stack trace information for .plt with lazy binding.  This is corrected
now by initializing a new SFrame PLT helper object
elf_x86_64_sframe_ibt_plt for lazy PLT with IBT.

Add a testcase where linking with -z ibtplt generates .plt.sec entries and
ensure correct SFrame information for it.

Committed by Indu Bhagat.

ChangeLog:
	PR/32296
	* bfd/elf64-x86-64.c (elf_x86_64_sframe_ibt_pltn_fre2): New
	definition elf_x86_64_sframe_ibt_plt.  Use it in
	elf_x86_64_sframe_plt.
	(elf_x86_64_link_setup_gnu_properties): Lazy IBT PLT entries are
	different from lazy PLT.
        * bfd/elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Adjust for
	SFrame for IBT PLT.
        * ld/testsuite/ld-x86-64/x86-64.exp: Add new test.
        * ld/testsuite/ld-x86-64/sframe-ibt-plt-1.d: New test.
2024-11-01 15:36:03 -07:00
Josh Poimboeuf
1785837a25 ld: fix PR/32297
When _creating_ SFrame information for the linker created .plt.sec, the
code correctly checks for presence of .plt.sec.  When _writing_ the
SFrame section for the corresponding .plt.sec, however, the conditionals
were wrongly checking for splt.  This was causing an assertion at link
time.

This issue has been known to affect glibc build with SFrame enabled.

No testcase is added just yet.  A later commit ensures correct SFrame
stack trace information is created for .plt.got. A test case (where only
.plt and .plt.got are created) is added then.

PR/32297 sframe: bfd assertion with empty main on IBT enabled system

Committed by Indu Bhagat.

ChangeLog:
	PR/32297
	* bfd/elfxx-x86.c (_bfd_x86_elf_late_size_sections): Check for
	  plt_second member not for splt.
2024-11-01 15:31:21 -07:00
H.J. Lu
360f74a101 x86-64: Add a test for hidden undefined symbol
Linker should report an error for hidden undefined symbol when building
a shared library without the "recompile with -fPIC" message:

$ cat x.c
extern int foo __attribute__ ((visibility ("hidden")));

int
func (void)
{
  return foo;
}
$ gcc -c -fPIC -O2 x.c
$ objdump -dwr x.o

x.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <func>:
   0:	8b 05 00 00 00 00    	mov    0x0(%rip),%eax        # 6 <func+0x6>	2: R_X86_64_PC32	foo-0x4
   6:	c3                   	ret
$ ld -shared -o x.so x.o
ld: x.o: in function `func':
x.c:(.text+0x2): undefined reference to `foo'
ld: x.o: relocation R_X86_64_PC32 against undefined hidden symbol `foo' can not be used when making a shared object
ld: final link failed: bad value
$

since -fPIC has been used.

	* testsuite/ld-x86-64/hidden6.d: New file.
	* testsuite/ld-x86-64/hidden6.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run hidden6.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-11-02 05:27:48 +08:00
Andrew Oates
086a2beb15 Fix compile error due to [[noreturn]] with clang
Since commit d9deb60b2e, I get the
following compiler error when building binutils (cross-compiling) on
macos:

 CXX    remote-sim.o
../../gdb/remote-sim.c:334:28: error: assigning to 'void (*)(host_callback *, const char *, ...) __attribute__((noreturn))' (aka 'void (*)(host_callback_struct *, const char *, ...) __attribute__((noreturn))') from incompatible type 'void (host_callback
*, const char *, ...)' (aka 'void (host_callback_struct *, const char *, ...)')
      gdb_callback.error = gdb_os_error;
                           ^~~~~~~~~~~~
1 error generated.

This appears to be due to the mismatch between ATTRIBUTE_NORETURN and
[[noreturn]] on gdb_os_error.  Reverting the change for gdb_os_error
resolves the issue.  Removing ATTTRIBUTE_NORETURN on the
declaration of host_callback::error also works, but deprives the
compiler of data.

Tested by compiling on macos both with the system clang, as well as with
GCC 14.  With clang, remote-sim.c does not compile (per above) without
this patch.  With GCC, it compiles with and without the patch (it
doesn't link, but AFAICT that is unrelated).

The clang bug is reported upstream at
https://github.com/llvm/llvm-project/issues/113511

Approved-By: Tom Tromey <tom@tromey.com>
2024-11-01 11:13:54 -06:00
Tom Tromey
76367d2314 Add gdb.events.tui_enabled
This adds a new event source so that Python scripts can track whether
or not the TUI is presently enabled.

v2 of the patch renames "status" -> "enabled".

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32162
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-11-01 11:06:47 -06:00