Commit Graph

120614 Commits

Author SHA1 Message Date
GDB Administrator
20e8a322b1 Automatic date update in version.in 2024-12-04 00:00:15 +00:00
Tom de Vries
c99444905e [gdb/testsuite] Fix DUPLICATE in gdb.arch/pr25124.exp
With test-case gdb.arch/pr25124.exp, I run into:
...
PASS: gdb.arch/pr25124.exp: disassemble thumb instruction (1st try)
PASS: gdb.arch/pr25124.exp: disassemble thumb instruction (2nd try)
DUPLICATE: gdb.arch/pr25124.exp: disassemble thumb instruction (2nd try)
...

Fix this by using a comma instead of parentheses.

Tested on arm-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-12-03 23:03:03 +01:00
Tom de Vries
6a02aa77d8 [gdb/python] Issue warning if python fails to initialize
A common problem is that python may fail to initialize if PYTHONHOME is
set incorrectly, or points to incompatible default libraries.

Likewise if PYTHONPATH points to incompatible modules.

For instance, say PYTHONHOME is foo, then we get:
...
$ gdb -q
Python path configuration:
  PYTHONHOME = 'foo'
  PYTHONPATH = (not set)
  program name = '/usr/bin/python'
  isolated = 0
  environment = 1
  user site = 1
  safe_path = 0
  import site = 1
  is in build tree = 0
  stdlib dir = 'foo/lib64/python3.12'
  sys._base_executable = '/usr/bin/python'
  sys.base_prefix = 'foo'
  sys.base_exec_prefix = 'foo'
  sys.platlibdir = 'lib64'
  sys.executable = '/usr/bin/python'
  sys.prefix = 'foo'
  sys.exec_prefix = 'foo'
  sys.path = [
    'foo/lib64/python312.zip',
    'foo/lib64/python3.12',
    'foo/lib64/python3.12/lib-dynload',
  ]
Python Exception <class 'ModuleNotFoundError'>: No module named 'encodings'
Python not initialized
$
...

In this case, it might be easy to figure out what went wrong because of the
obviously incorrect pathnames, but that might not be the case if PYTHONHOME
points to an incompatible python installation.

Fix this by adding a warning with a description of the possible cause and what
to do about it:
...
Python initialization failed: \
  failed to get the Python codec of the filesystem encoding
gdb: warning: Python failed to initialize with PYTHONHOME set.  Maybe because \
  it is set incorrectly? Maybe because it points to incompatible standard \
  libraries? Consider changing or unsetting it, or ignoring it using "set \
  python ignore-environment on" at early initialization.
...

Likewise for PYTHONPATH:
...
Python initialization failed: \
  failed to get the Python codec of the filesystem encoding
gdb: warning: Python failed to initialize with PYTHONPATH set.  Maybe because \
  it points to incompatible modules? Consider changing or unsetting it, or \
  ignoring it using "set python ignore-environment on" at early \
  initialization.
...

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>

PR python/32379
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32379
2024-12-03 22:58:47 +01:00
Tom de Vries
922ab963e1 [gdb/python] Handle empty PYTHONDONTWRITEBYTECODE
When using PYTHONDONTWRITEBYTECODE with an empty string we get:
...
$ PYTHONDONTWRITEBYTECODE= gdb -q -batch -ex "show python dont-write-bytecode"
Python's dont-write-bytecode setting is auto (currently on).
...

This is incorrect, it should be off.

The actual setting is correct, that was already fixed in commit 24d2cbc42c
("set/show python dont-write-bytecode fixes"), in function
python_write_bytecode.

Fix this by:
- factoring out new function env_python_dont_write_bytecode out of
  python_write_bytecode, and
- using it in show_python_dont_write_bytecode.

Tested on x86_64-linux, using test-case gdb.python/py-startup-opt.exp and:
- PYTHONDONTWRITEBYTECODE=
- PYTHONDONTWRITEBYTECODE=1
- unset PYTHONDONTWRITEBYTECODE

Approved-By: Tom Tromey <tom@tromey.com>

PR python/32389
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32389
2024-12-03 22:54:23 +01:00
Tom de Vries
1dc13c7e9f [gdb/testsuite] Fix gdb.python/py-startup-opt.exp with empty PYTHONDONTWRITEBYTECODE
When running test-case gdb.python/py-startup-opt.exp with empty
PYTHONDONTWRITEBYTECODE:
...
$ cd build/gdb/testsuite
$ PYTHONDONTWRITEBYTECODE= make check \
    RUNTESTFLAGS=gdb.python/py-startup-opt.exp
...
I get:
...
end^M
dont_write_bytecode is off^M
(gdb) FAIL: $exp: attr=dont_write_bytecode: testname: input 6: end
...

The problem is that the test-case expects dont_write_bytecode to be
on, which is incorrect because PYTHONDONTWRITEBYTECODE only has effect if set
to a non-empty string [1].

Fix this by correctly setting expectations in the test-case.

Tested on x86_64-linux, with:
- PYTHONDONTWRITEBYTECODE=
- PYTHONDONTWRITEBYTECODE=1
- unset PYTHONDONTWRITEBYTECODE

Approved-By: Tom Tromey <tom@tromey.com>

[1] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE
2024-12-03 22:54:23 +01:00
Tom de Vries
348290c7ef [gdb/python] Warn and ignore ineffective python settings
Configuration flags "python dont-write-bytecode" and
"python ignore-environment" have effect only at Python initialization.

For instance, setting "python dont-write-bytecode" here has no effect:
...
$ gdb -q
(gdb) show python dont-write-bytecode
Python's dont-write-bytecode setting is auto (currently off).
(gdb) python import sys
(gdb) python print (sys.dont_write_bytecode)
False
(gdb) set python dont-write-bytecode on
(gdb) python print (sys.dont_write_bytecode)
False
...

This is not clear in the code: we set Py_DontWriteBytecodeFlag and
Py_IgnoreEnvironmentFlag in set_python_ignore_environment and
set_python_dont_write_bytecode.  Fix this by moving the setting of those
variables to py_initialization.

Furthermore, this is not clear to the user: after Python initialization, the
user can still modify the configuration flags, and observe the changed setting:
...
$ gdb -q
(gdb) show python ignore-environment
Python's ignore-environment setting is off.
(gdb) set python ignore-environment on
(gdb) show python ignore-environment
Python's ignore-environment setting is on.
(gdb)
...

Fix this by emitting a warning when trying to set these configuration flags
after Python initialization:
...
$ gdb -q
(gdb) set python ignore-environment on
warning: Setting python ignore-environment after Python initialization has \
  no effect, try setting this during early initialization
(gdb) set python dont-write-bytecode on
warning: Setting python dont-write-bytecode after Python initialization has \
  no effect, try setting this during early initialization, or try setting \
  sys.dont_write_bytecode
...
and by keeping the values constant after Python initialization.

Since the auto setting for python dont-write-bytecode depends on the current
value of environment variable PYTHONDONTWRITEBYTECODE, we simply avoid it
after Python initialization:
...
$ gdb -q -batch \
    -eiex "show python dont-write-bytecode" \
    -iex "show python dont-write-bytecode"
Python's dont-write-bytecode setting is auto (currently off).
Python's dont-write-bytecode setting is off.
...

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>

PR python/32388
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32388
2024-12-03 22:49:40 +01:00
Tom de Vries
c9b37bc997 [gdb/python] Drop ATTRIBUTE_UNUSED on py_initialize_catch_abort
I added ATTRIBUTE_UNUSED to py_initialize_catch_abort as a quick fix to deal
with it being unused for PY_VERSION_HEX >= 0x030a0000, but forgot to fix this
before committing.

Fix this now, by removing the attribute and using
'#if PY_VERSION_HEX < 0x030a0000' instead.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-12-03 22:49:40 +01:00
Tom de Vries
125f702105 [gdb/python] Factor out and refactor py_initialize
Function do_start_initialization has a large part dedicated to initializing
the python interpreter, as opposed to the rest of the function where
gdb-specific python support is initialized.

Factor out this part, as new function py_initialize, and rename the existing
py_initialize to py_initialize_catch_abort.

Refactor the new function py_initialize by getting rid of the nested:
...
 #ifdef WITH_PYTHON_PATH
 #if PY_VERSION_HEX < 0x030a0000
 #else
 #endif
 #else
 #endif
...

In particular, this changes behaviour for the "!defined (WITH_PYTHON_PATH)"
case.

For the "defined (WITH_PYTHON_PATH)" case, we've started using
Py_InitializeFromConfig () for PY_VERSION_HEX >= 0x030a0000 to deal with the
deprecation of Py_SetProgramName in 3.11.

For the "!defined (WITH_PYTHON_PATH)" case, we don't use Py_SetProgramName so
we stuck with Py_Initialize ().

However, in 3.12 Py_DontWriteBytecodeFlag and Py_IgnoreEnvironmentFlag got
deprecated and also here we need Py_InitializeFromConfig () to deal with this,
but the "!defined (WITH_PYTHON_PATH)" case didn't get updated.

This should be taken care of, now that we have this behavior:
- for PY_VERSION_HEX < 0x030a0000 we use Py_Initialize
- for PY_VERSION_HEX >= 0x030a0000 we use Py_InitializeFromConfig

I'm not sure how to test the "!defined (WITH_PYTHON_PATH)" though.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-12-03 22:49:40 +01:00
Simon Marchi
22a7a2d12a gdb: restore nullptr check in compunit_symtab::find_call_site
Commit de2b4ab50d ("Convert dwarf2_cu::call_site_htab to new hash
table") removed this nullptr check for no good reason.  This causes a
crash if `m_call_site_htab` is not set, as shown in PR 32410.  My guess
is that when doing this change, I tried to make `m_call_site_htab` not a
pointer, removed this check, then realized it wasn't so obvious, and
forgot to re-add the check.

Change-Id: I455e00cdc0519dfb412dc7826d17a839b77aae69
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32410
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom de Vries <tdevries@suse.de>
2024-12-03 14:18:59 -05:00
Guinevere Larsen
c3b15d468c gdb/testsuite: make gdb.reverse/i386-avx-reverse.exp require avx
The test gdb.reverse/i386-avx-reverse.exp was assuming that if the CPU
was like x86, it would have AVX instructions because I didn't know how
to check for AVX instruction support explicitly.  This commit updates
that to use the pre-existing TCL proc have_avx.

Also update the comment at the top of the test, since it was a copy of a
different test.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-12-03 15:16:40 -03:00
Guinevere Larsen
ab3cca2687 gdb/dbx: Remove stabsect_build_psymtab as it was unused
The function stabsect_build_psymtabs, defined in the dbxread file, is no
longer used in any parts of GDB, so this commit just removes it.

Tested by rebuilding.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-12-03 15:12:28 -03:00
Tom de Vries
d556cf2ec7 [gdb/testsuite] Fix gdb.base/reset-catchpoint-cond.exp with --with-expat=no
When building gdb with --with-expat=no and running test-case
gdb.base/reset-catchpoint-cond.exp we get:
...
(gdb) catch syscall write^M
warning: Can not parse XML syscalls information; \
  XML support was disabled at compile time.^M
Unknown syscall name 'write'.^M
(gdb) FAIL: $exp: mode=syscall: catch syscall write
...

Fix this by skipping the test for --with-expat=no.

Tested on x86_64-linux.
2024-12-03 16:53:14 +01:00
Tom de Vries
6804a0969d [gdb/testsuite] Fix gdb.python/python.exp with --disable-tui
When building gdb with --disable-tui, we run into:
...
(gdb) python print(type(gdb.TuiWindow))^M
Python Exception <class 'AttributeError'>: \
  module 'gdb' has no attribute 'TuiWindow'^M
Error occurred in Python: module 'gdb' has no attribute 'TuiWindow'^M
(gdb) FAIL: gdb.python/python.exp: gdb.TuiWindow is registered
...

Fix this by skipping the test for --disable-tui.

Tested on x86_64-linux.
2024-12-03 16:53:14 +01:00
Guinevere Larsen
32e3f1a0aa gdb: fix crash when GDB can't read an objfile
If a user starts an inferior composed of objfiles that GDB is unable to
read, there is an error thrown in find_sym_fns, printing the famous "I'm
sorry, Dave, I can't do that" and the objfile stops being read. However,
the objfile will already have been linked to the program space, and
future interactions with the objfile will assume that it is readable.

Relevant to this commit, if GDB tries to find out the section that
contains a PC, and this section happens to land in the unreadable
objfile, GDB will try to create a section mapping, eventually calling
update_section_map. Since that function uses bfd to calculate the
sections, it'll think there are sections to be ordered, but when trying
to access the objfile::section_offsets, it'll be indexing a size 0
std::vector, which will end up segfaulting.

Currently, it isn't easy to trigger this crash, but the upcoming
possibility to disable support for some file formats would make the
crash very easy to reproduce, by attempting to debug an unsupported
inferior and using "break *<instruction>" command, or simply connecting
to a gdbserver loaded with an unsupported inferior.

The struct objfile_up seems to have been created to catch these kinds of
errors and unlink the partially-read objfile from the program space, as
the objfile isn't useful to GDB anymore, but it seems to have been added
before find_sym_fns would throw errors for unreadable objfiles, as the
instance in syms_from_objfile_1 (that could save GDB from this crash) is
declared well after find_sym_fns, too late to guard us. This commit
moves the declaration up to the top of the function, so it works as
intended.

Further discussion on the mailing list also agreed that the name
"objfile_up" implies some level of ownership of the pointer, which this
struct doesn't have. So this commit renames the struct to
scoped_objfile_unlinker, which is more descriptive of what the struct is
actually meant to do.

The final change this commit does is add an assertion to
objfile::section_offset and objfile::set_section_offset, which ensures
that the section_offsets vector is large enough to return the desired
offset. This ensures that we won't misteriously segfault or worse,
continue going with garbage data.

Reported-By: Andrew Burgess <aburgess@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-12-03 11:31:22 -03:00
Jens Remus
2639ca087d gas: Re-enable .org test 1 on all targets except kvx
It got erroneously disabled for all targets including kvx instead of
excluding kvx only.

gas/testsuite/
	* gas/all/org-1.d: Re-enable on all targets except kvx.

Fixes: 6e712424f5 ("kvx: New port.")
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-12-03 14:33:32 +01:00
Jens Remus
8a00d45f0b s390: Enable .bss/.struct data allocation directives tests
This reduces the number of unsupported tests on s390 by two.

gas/testsuite/
	* gas/elf/bss.d: Enable for s390*-*-*.
	* gas/elf/bad-bss.d: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-12-03 14:33:32 +01:00
Surya Kumari Jangala
2b6770659e PowerPC: Add support for RFC02680 - PQC Acceleration Instructions
opcodes/
	* ppc-opc.c (powerpc_opcodes): Add xvadduwm, xvadduhm, xvsubuwm,
	xvsubuhm, xvmuluwm, xvmuluhm, xvmulhsw, xvmulhsh, xvmulhuw,
	xvmulhuh.
gas/
	* testsuite/gas/ppc/future.s: New test.
	* testsuite/gas/ppc/future.d: Likewise.
2024-12-03 08:17:44 -05:00
Nick Clifton
37a850cafa Updated Russian translation and new Malay translation for the BFD sub-directory 2024-12-03 12:44:36 +00:00
Lulu Cai
eb06e39641 LoongArch: Fix the infinite loop caused by calling undefweak symbol
The undefweak symbol value of non-default visibility is 0 and does
not use plt entry, and will not be relocated in the relocate_secion
function. As a result, an infinite loop is generated because
bl %plt(sym) => bl 0.

Fix this by converting the call into a jump address 0.
2024-12-03 19:52:35 +08:00
Andrew Burgess
6da1842770 gdb: fix comment for gdbarch_stack_grows_down
The comment for gdbarch_stack_grows_down was wrong.  Fixed in this
commit.

There should be no user visible changes after this commit.
2024-12-03 10:38:59 +00:00
Jan Beulich
a3a47415b7 gas: partly restore how current_location() had worked
Commit 4a826962e7 changed its behavior without saying why, and without
putting in place any testcase demonstrating the required behavior.
Firmly latch the current position unless deferred-evaluation mode is in
effect.
2024-12-03 10:48:16 +01:00
Jan Beulich
5ea62b98d9 MMIX: use current_location() directly
It's no longer a static function, so it can be used without involving a
wrapper function plus an indirect function call.
2024-12-03 10:47:53 +01:00
Jan Beulich
29f84cf8a2 gas: streamline expr_build_dot()
There's no point involving symbol_clone_if_forward_ref(), just for it to
replace dot_symbol by one obtained from symbol_temp_new_now(). For the
abs-section case also produce a slightly more "complete" (as in: all
potentially relevant fields filled) expression by going through
expr_build_uconstant().

Move the function next to current_location(), for it to be easier to see
the (dis)similarities. Correct the function's comment while there.
2024-12-03 10:47:36 +01:00
Kong Lingling
98439a80cc Support Intel AVX10.2 BF16 instructions
In this patch, we will support AVX10.2 BF16 instructions. All of them
are new instructions forms. In current documentation, it is still
VSCALEFPBF16, but it will change to VSCALEFNEPBF16 eventually.

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

gas/Changelog:

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

opcodes/

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

Co-authored-by: Haochen Jiang <haochen.jiang@intel.com>
2024-12-03 15:34:05 +08:00
GDB Administrator
5772296755 Automatic date update in version.in 2024-12-03 00:00:18 +00:00
Simon Marchi
3eccfdce99 gdb/configure.ac: remove elf_hp.h check
The comment says this is for HP/UX, which is no longer supported.  There
should be no functional changes with this, since nothing checks
HAVE_ELF_HP_H.

Change-Id: Ie897fc64638c9fea28463e1bf69e450c3673fd84
2024-12-02 11:44:37 -05:00
Simon Marchi
11fdaff161 gdb, gdbserver, gdbsupport: flatten and sort some list in configure files
This makes the lists easier sort read and modify.  There are no changes
in the generated config.h files, so I'm confident this brings no
functional changes.

Change-Id: Ib6b7fc532bcd662af7dbb230070fb1f4fc75f86b
2024-12-02 11:44:37 -05:00
Matthieu Longo
4de92ce8b2 aarch64: add tests for combinations of GCS options and marked/unmarked inputs 2024-12-02 15:18:41 +00:00
Matthieu Longo
9957996fa8 aarch64: add tests to check the correct merge of the GCS feature with others. 2024-12-02 15:18:41 +00:00
Srinath Parvathaneni
b75ce33f0c aarch64: GCS feature check in GNU note properties for input objects
This patch adds support for Guarded Control Stack in AArch64 linker.

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

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

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

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

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

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

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

Co-authored-by: Matthieu Longo <matthieu.longo@arm.com>
Co-authored-by: Yury Khrustalev <yury.khrustalev@arm.com>
2024-12-02 15:18:41 +00:00
Matthieu Longo
f1cd84f4c5 aarch64: rename BTI error/warning message
The previous message for missing BTI feature in GNU properties was
not very clear. The new message explains that a missing GNU property
marking is lacking on this specific input.
2024-12-02 15:18:41 +00:00
Matthieu Longo
3c3c758747 aarch64: delete duplicated BTI tests 2024-12-02 15:18:41 +00:00
Matthieu Longo
83c22eb44e aarch64: improve test coverage for combination of BTI options 2024-12-02 15:18:41 +00:00
Matthieu Longo
82061f8093 aarch64: limit number of reported issues on missing GNU properties
This patch attempts to make the linker output more friendly for the
developers by limiting the number of emitted warning/error messages
related to BTI issues.

Every time an error/warning related to BTI is emitted, the logger
also increments the BTI issues counter. A batch of errors/warnings is
limited to a maximum of 20 explicit errors/warnings. At the end of
the merge, a summary of the total of errors/warning is given if the
number exceeds the limit of 20 invidual messages.
2024-12-02 15:18:40 +00:00
Matthieu Longo
ddbd1a4c98 aarch64: bugfix when finding 1st bfd input with GNU property
The current implementation of searching the first input BFD with GNU
properties has a bug. The search was not filtering on object inputs
belonging to the output link unit only, but was also including dynamic
objects, BFD plugins, and linker-created files.
This means that the initial initialization of the output properties
were skewed, and warnings on input files that should have been emitted
were not.

This patch fixes the filtering to exclude the object input files not
belonging to the output link unit, not having the same ELF class, and
not the same target architecture.
2024-12-02 15:18:40 +00:00
Matthieu Longo
2ad1fffee5 aarch64: remove early exit when setting up GNU properties with partial linking
There is an early exit in _bfd_aarch64_elf_link_setup_gnu_properties
that is enabled when the output link unit is relocatable, i.e. ld
generates an output file that can in turn serve as input to ld. (see
ld manual, -r,--relocatable for more details).

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

Given that there is currently no comment for explain why the exit is
there, and that there might in the future be cases were these properties
affect relocatable links, it is preferrable to drop the early exit.
2024-12-02 15:18:40 +00:00
Matthieu Longo
827a2b93fe aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 5)
Use _bfd_aarch64_elf_check_bti_report to report any BTI issue on the
first input object.
2024-12-02 15:18:40 +00:00
Matthieu Longo
d350b15017 aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 4)
Move the code related to the creation of the gnu.note section to a
separate function: _bfd_aarch64_elf_create_gnu_property_section
2024-12-02 15:18:40 +00:00
Matthieu Longo
061040ffc3 aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 3)
Move the code related to the search of the first bfd input with GNU
properties to a separate function:
_bfd_aarch64_elf_find_1st_bfd_input_with_gnu_property
2024-12-02 15:18:40 +00:00
Matthieu Longo
518976f135 aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 2)
Simplify this for-loop with too many "break" instructions inside.
2024-12-02 15:18:40 +00:00
Matthieu Longo
d364a2ddb4 aarch64: refactoring _bfd_aarch64_elf_check_bti_report
Before this patch, warnings were reported normally, and errors
(introduced by a previous patch adding '-z bti-report' option)
were logged as error but were not provoking a link failure.
The root of the issue was a misuse of _bfd_error_handler to
report the errors.
Replacing _bfd_error_handler by info->callbacks->einfo, with the
addition of the formatter '%X' for errors fixed the issue.
2024-12-02 15:18:40 +00:00
Matthieu Longo
946b753836 aarch64: refactoring _bfd_aarch64_elf_link_setup_gnu_properties (part 1)
Exposing the output GNU property as a parameter of
_bfd_aarch64_elf_link_setup_gnu_properties seems to break the
encapsulation. The output GNU property update should be part of the
function that sets up the GNU properties.
This patch removes the parameter, and perform the update of the GNU
property on the output object inside the function.
2024-12-02 15:18:40 +00:00
Matthieu Longo
fc569c422f aarch64: rename gnu_and_prop to gnu_property_aarch64_feature_1_and 2024-12-02 15:18:40 +00:00
Matthieu Longo
b4377af729 aarch64: simplify condition in elfNN_aarch64_merge_gnu_properties
The current condition used to check if a GNU feature property is set
on an input object before the merge is a bit confusing.

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

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

  (!aprop || !<something about aprop>)
2024-12-02 15:18:40 +00:00
Matthieu Longo
aa993e9731 aarch64: rename parameter of _bfd_aarch64_elf_merge_gnu_properties
The current naming of the AArch64 feature GNU property of the output bfd
does not reflect what it is. This patch renames it from "prop" to
"outprop".
2024-12-02 15:18:40 +00:00
Matthieu Longo
1bd9dbeaf3 aarch64: update ld documentation with bti and pac options 2024-12-02 15:18:40 +00:00
Matthieu Longo
caded0cf73 aarch64: use only one type for feature marking report 2024-12-02 15:18:40 +00:00
Matthieu Longo
23189e9db7 aarch64: group software protection options under a same struct.
- declare a new struc aarch_protection_opts to store all the
  configuration options related to software protections (i.e. bti-plt,
  pac-plt, bti-report level).
- add a new option "-z bti-report" to configure the log level of reported
  issues when BTI PLT is forced.
- encapsulate the BTI report inside _bfd_aarch64_elf_check_bti_report.
2024-12-02 15:18:40 +00:00
Matthieu Longo
79aff6ea0e aarch64: adapt BTI tests to use selectable GNU properties 2024-12-02 15:18:40 +00:00
Matthieu Longo
8949929a51 aarch64: adapt bti-far* tests to use selectable GNU properties 2024-12-02 15:18:40 +00:00