binutils-gdb.git
15 months agobinutils sprintf optimisation
Alan Modra [Thu, 3 Aug 2023 03:02:40 +0000 (12:32 +0930)]
binutils sprintf optimisation

Avoid the use of sprintf with a "%s" format string, replacing with
strcpy or stpcpy.  Use sprintf return value rather than a later
strlen.  Don't use strcat where we can keep track of the end of a
string output buffer.

* dlltool.c (look_for_prog): memcpy prefix and strcpy prog_name.
* dllwrap.c (look_for_prog): Likewise.
* resrc.c (look_for_default): Likewise.  Add quotes with memmove
rather than allocating another buffer.
* size.c (size_number): Use sprintf return value.
* stabs.c (parse_stab_argtypes): Likewise.
* windmc.c (write_bin): Likewes, and use stpcpy.
* wrstabs.c: Similarly throughout.

15 months agocris: sprintf optimisation
Alan Modra [Thu, 3 Aug 2023 02:56:46 +0000 (12:26 +0930)]
cris: sprintf optimisation

Since I was poking at cris-dis.c to avoid the sanitizer warning,
I figure I might as well make use of stpcpy and sprintf return value
in other places in this file.

* cris-dis.c (format_hex): Use sprintf return value.
(format_reg): Use stpcpy and sprintf return, avoiding strlen.
(format_sup_reg): Likewise.

15 months agoarm: sanitizer stringop-overflow
Alan Modra [Wed, 2 Aug 2023 23:30:05 +0000 (09:00 +0930)]
arm: sanitizer stringop-overflow

In function 'memset',
    inlined from 'create_unwind_entry' at /home/alan/src/binutils-gdb/gas/config/tc-arm.c:27881:3:
/usr/include/bits/string_fortified.h:59:10: error: '__builtin_memset' specified size between 2147483652 and 4294967295 exceeds maximum object size 2147483647 [-Werror=stringop-overflow=]
   59 |   return __builtin___memset_chk (__dest, __ch, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   60 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~

* config/tc-arm.c (create_unwind_entry): Return after bad size,
and bad opcode count.

15 months agoxtensa: sprintf sanitizer null destination pointer
Alan Modra [Wed, 2 Aug 2023 23:26:24 +0000 (08:56 +0930)]
xtensa: sprintf sanitizer null destination pointer

* config/tc-xtensa.c (xtensa_add_config_info): Use auto buffer
rather than malloc.  Use sprintf return value.

15 months agold: sprintf sanitizer null destination pointer
Alan Modra [Wed, 2 Aug 2023 23:10:12 +0000 (08:40 +0930)]
ld: sprintf sanitizer null destination pointer

* configure.ac (stpcpy): AC_CHECK_DECLS.
* sysdep.h (stpcpy): Add fallback declaraion.
* config.in: Regenerate.
* configure: Regenerate.
* emultempl/pe.em (open_dynamic_archive): Use
stpcpy rather than sprintf plus strlen.
* emultempl/pep.em (open_dynamic_archive): Likewise.
* emultempl/xtensaelf.em (elf_xtensa_before_allocation): Use
auto rather than malloc'd buffer.  Use sprintf count.
* ldelf.c (ldelf_search_needed): Use memcpy in place of sprintf.
* pe-dll.c (pe_process_import_defs): Use string already formed
for alias match rather than recreating.

15 months agogprof: sprintf sanitizer null destination pointer
Alan Modra [Wed, 2 Aug 2023 22:53:51 +0000 (08:23 +0930)]
gprof: sprintf sanitizer null destination pointer

* basic_blocks.c (annotate_with_count): Use output of sprintf
rather than strlen.

15 months agoresrc: sprintf sanitizer null destination pointer
Alan Modra [Wed, 2 Aug 2023 22:48:13 +0000 (08:18 +0930)]
resrc: sprintf sanitizer null destination pointer

* resrc.c (read_rc_file): Use stpcpy rather than sprintf
followed by strlen.  Tidy.

15 months agodlltool: sprintf sanitizer null destination pointer
Alan Modra [Wed, 2 Aug 2023 22:45:12 +0000 (08:15 +0930)]
dlltool: sprintf sanitizer null destination pointer

* dlltool.c (gen_lib_file): Avoid bogus sanitizer error.

15 months agowrstabs: sprintf sanitizer null destination pointer
Alan Modra [Wed, 2 Aug 2023 22:37:54 +0000 (08:07 +0930)]
wrstabs: sprintf sanitizer null destination pointer

gcc-2.12 seems to be ignoring __attribute__((__returns_nonnull__))
on xmalloc.

* wrstabs.c (stab_method_type): Use stpcpy rather than sprintf
or strcat.

15 months agocris: sprintf sanitizer null destination pointer
Alan Modra [Wed, 2 Aug 2023 22:29:47 +0000 (07:59 +0930)]
cris: sprintf sanitizer null destination pointer

Simplify the sprintf calls, and use sprintf return value.  Older code
in binutils avoided using the sprintf return count of chars printed,
because with some older C libraries it wasn't reliable.  Nowadays it
should be OK to use (and we already use the return value elsewhere).
sprintf can't return an error status of -1 here.

* cris-dis.c (format_dec): Avoid sanitizer warning.  Use sprintf
return value rather than calling strlen.

15 months agoobjdump, nm: sprintf sanitizer null destination pointer
Alan Modra [Wed, 2 Aug 2023 21:59:58 +0000 (07:29 +0930)]
objdump, nm: sprintf sanitizer null destination pointer

Seen on Ubuntu 23.04 x86_64-linux using gcc-12.2 and gcc-12.3 with
CFLAGS="-m32 -g -O2 -fsanitize=address,undefined".

  CC       objdump.o
In file included from /usr/include/stdio.h:906,
                 from /home/alan/src/binutils-gdb/binutils/sysdep.h:24,
                 from /home/alan/src/binutils-gdb/binutils/objdump.c:51:
In function 'sprintf',
    inlined from 'display_utf8' at /home/alan/src/binutils-gdb/binutils/objdump.c:621:14,
    inlined from 'sanitize_string.part.0' at /home/alan/src/binutils-gdb/binutils/objdump.c:742:11:
/usr/include/bits/stdio2.h:30:10: error: null destination pointer [-Werror=format-overflow=]
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

The warning is bogus of course.  xmalloc is guaranteed to return
non-NULL, but apparently this isn't seen in display_utf6.  The same
doesn't happen with -m64, maybe due to inlining differences, I haven't
investigated fully.  Easily avoided as we hardly need to use sprintf
for a single char, or a two char string.

* objdump.c (display_utf8): Avoid bogus sprintf sanitizer warning.
Use hex ESC to switch back to default colour.
(sanitize_string): Comment.  Bump buffer size by one.  Fix overlong
line.
* nm.c (display_utf8, sanitize_string): As above.

15 months agogdb: fix possible nullptr dereference in a remote_debug_printf call
Andrew Burgess [Tue, 18 Jul 2023 12:52:20 +0000 (13:52 +0100)]
gdb: fix possible nullptr dereference in a remote_debug_printf call

While working on another patch I triggered a segfault from within the
function remote_target::discard_pending_stop_replies.  Turns out this
was caused by a cut&paste error introduced in this commit:

  commit df5ad102009c41ab4dfadbb8cfb8c8b2a02a4f78
  Date:   Wed Dec 1 09:40:03 2021 -0500

      gdb, gdbserver: detach fork child when detaching from fork parent

This commit adds a remote_debug_printf call that was copied from
earlier in the function, however, the new call wasn't updated to use
the appropriate local variable.  The local variable that it is using
might be nullptr, in which case we trigger undefined behaviour, and
could crash, which is what I was seeing.

Fixed by updating to use the correct local variable.

15 months ago Fix Wlto-type-mismatch in opcodes/ft32-dis.c
Tom de Vries [Thu, 3 Aug 2023 08:48:39 +0000 (09:48 +0100)]
 Fix Wlto-type-mismatch in opcodes/ft32-dis.c

15 months agoRISC-V: Add support for 'Zvfh' and 'Zvfhmin'
Tsukasa OI [Thu, 3 Aug 2023 05:35:53 +0000 (05:35 +0000)]
RISC-V: Add support for 'Zvfh' and 'Zvfhmin'

This commit adds support for recently ratified vector FP16 extensions:
'Zvfh' and 'Zvfhmin'.

This is based on:
<https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#zvfhmin-vector-extension-for-minimal-half-precision-floating-point>
<https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#zvfh-vector-extension-for-half-precision-floating-point>

Despite not having any new instructions, it will be necessary since those
extensions are already implemented in GCC.

Note that however, in this commit, following dependencies are implemented.

1.  'Zvfhmin' -> 'Zve32f'
2.  'Zvfh' -> 'Zvfhmin' (not 'Zvfh' -> 'Zve32f' as in the documentation)
3.  'Zvfh' -> 'Zfhmin'

This is because the instructions and configurations supported by the
'Zvfh' extension is a strict superset of the 'Zvfhmin' extension and
'Zvfh' -> 'Zve32f' dependency is indirectly derived from that fact.

bfd/ChangeLog:

* elfxx-riscv.c (riscv_implicit_subsets): Add implications
related to 'Zvfh' and 'Zvfhmin' extensions.
(riscv_supported_std_z_ext) Add 'Zvfh' and 'Zvfhmin' to the list.

15 months agoRISC-V: Imply 'Zicsr' from 'Zve32x'
Tsukasa OI [Wed, 2 Aug 2023 23:50:27 +0000 (23:50 +0000)]
RISC-V: Imply 'Zicsr' from 'Zve32x'

Further clarification is made so that 'Zve32x' implies 'Zicsr' (the same
implication is already implemented in LLVM).

See related issue (the author raised) on the vector specification:
<https://github.com/riscv/riscv-v-spec/issues/908>
and its resolution:
<https://github.com/riscv/riscv-v-spec/issues/909>

bfd/ChangeLog:

* elfxx-riscv.c (riscv_implicit_subsets): Add 'Zve32x' -> 'Zicsr'.

15 months agoAutomatic date update in version.in
GDB Administrator [Thu, 3 Aug 2023 00:00:40 +0000 (00:00 +0000)]
Automatic date update in version.in

15 months ago[gdb] Initialize main_thread_id earlier
Tom de Vries [Wed, 2 Aug 2023 21:17:35 +0000 (23:17 +0200)]
[gdb] Initialize main_thread_id earlier

I wrote a patch using is_main_thread (), and found it returning false in the
main thread due to main_thread_id not being initialized yet.

Initialization currently takes place in _initialize_run_on_main_thread, but
that's too late for earlier uses.

Fix this by initializing, either:
- when entering main, or
- on an earlier first use.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
15 months ago[gdb/dap] Disable DAP for python <= 3.5
Tom de Vries [Wed, 2 Aug 2023 21:14:58 +0000 (23:14 +0200)]
[gdb/dap] Disable DAP for python <= 3.5

DAP requires python module typing, which is supported starting python 3.5.

Make this formal by:
- disabling the dap interpreter for python version < 3.5
- returning 0 in allow_dap_tests for python version < 3.5

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

15 months agoAvoid failures in fixed_points.exp with older GCC
Tom Tromey [Tue, 1 Aug 2023 14:33:42 +0000 (08:33 -0600)]
Avoid failures in fixed_points.exp with older GCC

Tom de Vries pointed out that my recent change to fixed_points.exp
failed with older versions of GCC.  This patch fixes the problem by
skipping the new test in this situation.

15 months agoRevert "2.41 Release sources"
Sam James [Wed, 2 Aug 2023 11:06:23 +0000 (12:06 +0100)]
Revert "2.41 Release sources"

This reverts commit 675b9d612cc59446e84e2c6d89b45500cb603a8d.

See https://sourceware.org/pipermail/binutils/2023-August/128761.html.

15 months ago2.41 Release sources
Nick Clifton [Wed, 2 Aug 2023 08:23:36 +0000 (09:23 +0100)]
2.41 Release sources

15 months agogprofng: Fix build with 64bit file offset on 32bit machines
Khem Raj [Mon, 31 Jul 2023 22:31:40 +0000 (15:31 -0700)]
gprofng: Fix build with 64bit file offset on 32bit machines

gprofng/ChangeLog
2023-07-31  Khem Raj <raj.khem@gmail.com>

* libcollector/iotrace.c: Define open64, fgetpos64, and fsetpos64
  only when __USE_LARGEFILE64 and __USE_FILE_OFFSET64 are not
  defined.

15 months agoAutomatic date update in version.in
GDB Administrator [Wed, 2 Aug 2023 00:00:29 +0000 (00:00 +0000)]
Automatic date update in version.in

15 months agoDon't declare xmalloc and others in ldmisc.h
Alan Modra [Tue, 1 Aug 2023 22:24:47 +0000 (07:54 +0930)]
Don't declare xmalloc and others in ldmisc.h

* ldmisc.h (xmalloc, xrealloc, xexit, yyerror): Don't declare.
* emultempl/pdp11.em: Include libiberty.h.
* emultempl/ticoff.em: Likewise.
* emultempl/vms.em: Likewise.
* ldctor.c: Likewise.
* ldelfgen.c: Likewise.
* ldgram.y: Likewise.
(yyerror): Prototype and make static.

15 months agoDon't declare xmalloc or xrealloc in bucomm.h
Alan Modra [Tue, 1 Aug 2023 22:23:26 +0000 (07:53 +0930)]
Don't declare xmalloc or xrealloc in bucomm.h

It's better to include the proper header, which has declarations with
various attributes.  Commit 096aefc040 in 1994 introduced this wart.

* bucomm.h (xmalloc, xrealloc): Delete declaration.
* od-macho.c: Include libiberty.h.
* od-xcoff.c: Include libiberty.h.

15 months agoRegen ld/configure
Alan Modra [Tue, 1 Aug 2023 22:13:50 +0000 (07:43 +0930)]
Regen ld/configure

For commit 3d05c80b5dc4.

15 months agoImplement DAP "source" request
Tom Tromey [Thu, 27 Jul 2023 20:27:05 +0000 (14:27 -0600)]
Implement DAP "source" request

This implements the DAP "source" request.  I renamed the
"loadedSources" function from "sources" to "loaded_sources" to avoid
any confusion.  I also moved the loadedSources test to the new
sources.exp.

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

15 months agoHandle Source in DAP breakpointLocations
Tom Tromey [Thu, 27 Jul 2023 20:21:13 +0000 (14:21 -0600)]
Handle Source in DAP breakpointLocations

This changes the DAP breakpointLocations request to accept a Source
and to decode it properly.

15 months agoIntroduce sourceReference handling in DAP
Tom Tromey [Thu, 27 Jul 2023 20:04:31 +0000 (14:04 -0600)]
Introduce sourceReference handling in DAP

This changes the gdb DAP implementation to emit a real
sourceReference, rather than emitting 0.  Sources are tracked in some
maps in sources.py, and a new helper function is introduced to compute
the "Source" object that can be sent to the client.

15 months agoDon't supply DAP 'path' for non-file shared libraries
Tom Tromey [Tue, 25 Jul 2023 16:55:14 +0000 (10:55 -0600)]
Don't supply DAP 'path' for non-file shared libraries

The DAP 'module' event may include a 'path' component.  I noticed that
this is supplied even when the module in question does not come from a
file.

This patch only emits this field when the objfile corresponds to a
real file.

No test case, because I wasn't sure how to write a portable one.
However, it's clear from gdb.log on Linux:

{"type": "event", "event": "module", "body": {"reason": "new", "module": {"id": "system-supplied DSO at 0x7ffff7fc4000", "name": "system-supplied DSO at 0x7ffff7fc4000"}}, "seq": 21}

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

15 months agoImplement ValueFormat for DAP
Tom Tromey [Tue, 25 Jul 2023 16:13:52 +0000 (10:13 -0600)]
Implement ValueFormat for DAP

This patch implements ValueFormat for DAP.  Currently this only means
supporting "hex".

Note that StackFrameFormat is defined to have many more options, but
none are currently recognized.  It isn't entirely clear how these
should be handled.  I'll file a new gdb bug for this, and perhaps an
upstream DAP bug as well.

New in v2:
- I realized that the "hover" context was broken, and furthermore
  that we only had tests for "hover" failing, not for it succeeding.
  This version fixes the oversight and adds a test.

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

15 months agoRespect supportsMemoryReferences in DAP
Tom Tromey [Thu, 27 Jul 2023 19:06:38 +0000 (13:06 -0600)]
Respect supportsMemoryReferences in DAP

I noticed that the support for memoryReference in the "variables"
output is gated on the client "supportsMemoryReferences" capability.

This patch implements this and makes some other changes to the DAP
memory reference code:

* Remove the memoryReference special case from _SetResult.
  Upstream DAP fixed this oversight in response to
  https://github.com/microsoft/debug-adapter-protocol/issues/414

* Don't use the address of a variable as its memoryReference -- only
  emit this for pointer types.  There's no spec support for the
  previous approach.

* Use strip_typedefs to handle typedefs of pointers.

15 months agoAdd DAP support for C++ exceptions
Tom Tromey [Tue, 25 Jul 2023 16:48:13 +0000 (10:48 -0600)]
Add DAP support for C++ exceptions

This adds DAP support for the various C++ exception-catching
operations.

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

15 months agoImplement DAP 'terminated' event
Tom Tromey [Tue, 25 Jul 2023 15:16:35 +0000 (09:16 -0600)]
Implement DAP 'terminated' event

This implements the DAP 'terminated' event.  Vladimir Makaev noticed
that VSCode will not report the debug session as over unless this is
sent.

It's not completely clear when exactly this event ought to be sent.
Here I've done it when the inferior exits.

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

15 months agoDo not send "new breakpoint" event when breakpoint is set
Tom Tromey [Mon, 24 Jul 2023 19:28:58 +0000 (13:28 -0600)]
Do not send "new breakpoint" event when breakpoint is set

When the DAP client sets a breakpoint, gdb currently sends a "new
breakpoint" event.  However, Vladimir Makaev discovered that this
causes VSCode to think there are two breakpoints.

This patch changes gdb to suppress the event in this case.

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

15 months agoMove DAP breakpoint event code to breakpoint.py
Tom Tromey [Tue, 25 Jul 2023 13:04:45 +0000 (07:04 -0600)]
Move DAP breakpoint event code to breakpoint.py

A subsequent patch will add the ability to suppress breakpoint events
to DAP.  My first attempt at this ended up with recurse imports,
causing Python failures.  So, this patch moves all the DAP breakpoint
event code to breakpoint.py in preparation for the change.

I've renamed breakpoint_descriptor here as well, because it can now be
private to breakpoint.py.

15 months agoFull paths in DAP stackTrace responses
Tom Tromey [Mon, 24 Jul 2023 14:48:00 +0000 (08:48 -0600)]
Full paths in DAP stackTrace responses

Vladimir Makaev noticed that, in some cases, a DAP stackTrace response
would include a relative path name for the "path" component.

This patch changes the frame decorator code to add a new DAP-specific
decorator, and changes the DAP entry point to frame filters to use it.
This decorator prefers the symtab's full name, and does not fall back
to the solib's name.

I'm not entirely happy with this patch, because if a user frame filter
uses FrameDecorator, it may still do the wrong thing.  It would be
better to have frame filters return symtab-like objects instead, or to
have a separate method to return the full path to the source file.

I also tend to think that the solib fallback behavior of
FrameDecorator is a mistake.  If this is ever needed, it seems to me
that it should be a separate method.

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

15 months agoAdd "cwd" parameter to DAP launch request
Tom Tromey [Mon, 24 Jul 2023 15:14:20 +0000 (09:14 -0600)]
Add "cwd" parameter to DAP launch request

This adds the "cwd" parameter to the DAP launch request.

This came up here:
    https://github.com/eclipse-cdt-cloud/cdt-gdb-adapter/issues/90
... and seemed like a good idea.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
15 months agoRefactor dap_launch
Tom Tromey [Mon, 24 Jul 2023 16:12:17 +0000 (10:12 -0600)]
Refactor dap_launch

This patch refactors dap_launch to make it more extensible and also
easier to use.

15 months agoRename private member of FrameDecorator
Tom Tromey [Mon, 24 Jul 2023 14:41:23 +0000 (08:41 -0600)]
Rename private member of FrameDecorator

In Python, a member name starting with "__" is specially handled to
make it "more private" to the class -- it isn't truly private, but it
is renamed to make it less likely to be reused by mistake.  This patch
ensures that this is done for the private method of FrameDecorator.

15 months agoAdd thread exited event
Simon Farre [Mon, 5 Jun 2023 12:56:54 +0000 (14:56 +0200)]
Add thread exited event

Reports a thread exit according to the DAP spec:
https://microsoft.github.io/debug-adapter-protocol/specification#Events_Thread

This patch requires the ThreadExitedEvent to be checked in,
in order to work. That patch is found here https://sourceware.org/pipermail/gdb-patches/2023-June/200071.html

Formatted correctly using black

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

Approved-By: Tom Tromey <tom@tromey.com>
15 months agoFix "--only-keep-debug for ELF relocatables" binutils test for compilers which add...
Nick Clifton [Tue, 1 Aug 2023 13:37:04 +0000 (14:37 +0100)]
Fix "--only-keep-debug for ELF relocatables" binutils test for compilers which add .debug_macro sections to object files.

  PR 30699
  * binutils/testsuite/binutils-all/objcopy.exp (keep_debug_symbols_for_elf_relocatable): Do not add sections containing the string "debug_" to the list of non-debug sections.

15 months agogas: rework timestamp preservation on doc/asconfig.texi
Jan Beulich [Tue, 1 Aug 2023 10:39:44 +0000 (12:39 +0200)]
gas: rework timestamp preservation on doc/asconfig.texi

PR 28909

Sadly "cp -p", doing more than just preserving the time stamp, can fail
e.g. upon trying to preserve ownership (which we don't care about), as
can be observed on e.g. Cygwin. Replace the use of -p by a use of touch,
this way also only preserving modification time.

15 months agoAdd note to check that all changes have been pushed before creating the source tarballs
Nick Clifton [Tue, 1 Aug 2023 09:41:58 +0000 (10:41 +0100)]
Add note to check that all changes have been pushed before creating the source tarballs

15 months agold: Fix test failures with --enable-textrel-check=error
Sam James [Tue, 1 Aug 2023 08:44:48 +0000 (09:44 +0100)]
ld: Fix test failures with --enable-textrel-check=error

15 months agogprofng: create a list of available views
Vladimir Mezentsev [Wed, 26 Jul 2023 20:56:48 +0000 (13:56 -0700)]
gprofng: create a list of available views

In our GUI project (https://savannah.gnu.org/projects/gprofng-gui), we use
the output of gp-display-text to display the data.
gp-display-text did not report available views.

gprofng/ChangeLog
2023-07-26  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* src/Command.cc: Add commands for gprofng GUI.
* src/gprofng.rc: Set defaults for gprofng GUI.

15 months agoAutomatic date update in version.in
GDB Administrator [Tue, 1 Aug 2023 00:00:36 +0000 (00:00 +0000)]
Automatic date update in version.in

15 months ago[gdb/testsuite] Set TSAN_OPTIONS by default to history_size=7
Tom de Vries [Mon, 31 Jul 2023 19:35:35 +0000 (21:35 +0200)]
[gdb/testsuite] Set TSAN_OPTIONS by default to history_size=7

I build gdb with -fsanitize=thread and ran the testsuite, and ran into the
case that a race is detected, but we see the full stack trace only for one of
the two accesses, and the other one is showing "failed to restore the stack".

Try to prevent this by setting ThreadSanitizer flag history_size [1] to the
maximum (7) by default, as suggested here [2].

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
[1] https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags
[2] https://groups.google.com/g/thread-sanitizer/c/VzSWE7UxhIE

15 months agoFix bug in fixed-point handling
Tom Tromey [Tue, 18 Jul 2023 16:02:14 +0000 (10:02 -0600)]
Fix bug in fixed-point handling

Alexandre Oliva found a bug in gdb's handling of fixed-point -- a
certain Ada fixed-point type would be misintepreted.  The bug was that
the DW_AT_small looked like:

 <1><13cd>: Abbrev Number: 16 (DW_TAG_constant)
    <13ce>   DW_AT_GNU_numerator: 1
    <13cf>   DW_AT_GNU_denominator: 0x8000000000000000

... but gdb interpreted the denominator as a negative value.

15 months agold: fix typo in --enable-warn-rwx-segments help
Sam James [Mon, 31 Jul 2023 15:00:32 +0000 (16:00 +0100)]
ld: fix typo in --enable-warn-rwx-segments help

15 months agogdb/amdgpu: Fix debugging multiple inferiors using the ROCm runtime
Lancelot Six [Mon, 31 Jul 2023 09:59:44 +0000 (09:59 +0000)]
gdb/amdgpu: Fix debugging multiple inferiors using the ROCm runtime

When debugging a multi-process application where a parent spawns
multiple child processes using the ROCm runtime, I see the following
assertion failure:

    ../../gdb/amd-dbgapi-target.c:1071: internal-error: process_one_event: Assertion `runtime_state == AMD_DBGAPI_RUNTIME_STATE_UNLOADED' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    ----- Backtrace -----
    0x556e9a318540 gdb_internal_backtrace_1
            ../../gdb/bt-utils.c:122
    0x556e9a318540 _Z22gdb_internal_backtracev
            ../../gdb/bt-utils.c:168
    0x556e9a730224 internal_vproblem
            ../../gdb/utils.c:396
    0x556e9a7304e0 _Z15internal_verrorPKciS0_P13__va_list_tag
            ../../gdb/utils.c:476
    0x556e9a87aeb4 _Z18internal_error_locPKciS0_z
            ../../gdbsupport/errors.cc:58
    0x556e9a29f446 process_one_event
            ../../gdb/amd-dbgapi-target.c:1071
    0x556e9a29f446 process_event_queue
            ../../gdb/amd-dbgapi-target.c:1156
    0x556e9a29faf2 _ZN17amd_dbgapi_target4waitE6ptid_tP17target_waitstatus10enum_flagsI16target_wait_flagE
            ../../gdb/amd-dbgapi-target.c:1262
    0x556e9a6b0965 _Z11target_wait6ptid_tP17target_waitstatus10enum_flagsI16target_wait_flagE
            ../../gdb/target.c:2586
    0x556e9a4c221f do_target_wait_1
            ../../gdb/infrun.c:3876
    0x556e9a4d8489 operator()
            ../../gdb/infrun.c:3935
    0x556e9a4d8489 do_target_wait
            ../../gdb/infrun.c:3964
    0x556e9a4d8489 _Z20fetch_inferior_eventv
            ../../gdb/infrun.c:4365
    0x556e9a87b915 gdb_wait_for_event
            ../../gdbsupport/event-loop.cc:694
    0x556e9a87c3a9 gdb_wait_for_event
            ../../gdbsupport/event-loop.cc:593
    0x556e9a87c3a9 _Z16gdb_do_one_eventi
            ../../gdbsupport/event-loop.cc:217
    0x556e9a521689 start_event_loop
            ../../gdb/main.c:412
    0x556e9a521689 captured_command_loop
            ../../gdb/main.c:476
    0x556e9a523c04 captured_main
            ../../gdb/main.c:1320
    0x556e9a523c04 _Z8gdb_mainP18captured_main_args
            ../../gdb/main.c:1339
    0x556e9a24b1bf main
            ../../gdb/gdb.c:32
    ---------------------
    ../../gdb/amd-dbgapi-target.c:1071: internal-error: process_one_event: Assertion `runtime_state == AMD_DBGAPI_RUNTIME_STATE_UNLOADED' failed.
    A problem internal to GDB has been detected,

Before diving into why this error appears, let's explore how things are
expected to work in normal circumstances.  When a process being debugged
starts using the ROCm runtime, the following happens:

- The runtime registers itself to the driver.
- The driver creates a "runtime loaded" event and notifies the debugger
  that a new event is available by writing to a file descriptor which is
  registered in GDB's main event loop.
- GDB core calls the callback associated with this file descriptor
  (dbgapi_notifier_handler).  Because the amd-dbgapi-target is not
  pushed at this point, the handler pulls the "runtime loaded" event
  from the driver (this is the only event which can be available at this
  point) and eventually pushes the amd-dbgapi-target on the inferior's
  target stack.

In a nutshell, this is the expected AMDGPU runtime activation process.

From there, when new events are available regarding the GPU threads, the
same file descriptor is written to.  The callback sees that the
amd-dbgapi-target is pushed so marks the amd_dbgapi_async_event_handler.
This will later cause amd_dbgapi_target::wait to be called.  The wait
method pulls all the available events from the driver and handles them.
The wait method returns the information conveyed by the first event, the
other events are cached for later calls of the wait method.

Note that because we are under the wait method, we know that the
amd-dbgapi-target is pushed on the inferior target stack.  This implies
that the runtime activation event has been seen already.  As a
consequence, we cannot receive another event indicating that the runtime
gets activated.  This is what the failing assertion checks.

In the case when we have multiple inferiors however, there is a flaw in
what have been described above.  If one inferior (let's call it inferior
1) already has the amd-dbgapi-target pushed to its target stack and
another inferior (inferior 2) activates the ROCm runtime, here is what
can happen:

- The driver creates the runtime activation for inferior 2 and writes to
  the associated file descriptor.
- GDB has inferior 1 selected and calls target_wait for some reason.
- This prompts amd_dbgapi_target::wait to be called.  The method pulls
  all events from the driver, including the runtime activation event for
  inferior 2, leading to the assertion failure.

The fix for this problem is simple.  To avoid such problem, we need to
make sure that amd_dbgapi_target::wait only pulls events for the current
inferior from the driver.  This is what this patch implements.

This patch also includes a testcase which could fail before this patch.

This patch has been tested on a system with multiple GPUs which had more
chances to reproduce the original bug.  It has also been tested on top
of the downstream ROCgdb port which has more AMDGPU related tests.  The
testcase has been tested with `make check check-read1 check-readmore`.

Approved-By: Pedro Alves <pedro@palves.net>
15 months agogdb/testsuite/rocm: Add the hip_devices_support_debug_multi_process proc
Lancelot Six [Mon, 31 Jul 2023 09:59:44 +0000 (09:59 +0000)]
gdb/testsuite/rocm: Add the hip_devices_support_debug_multi_process proc

It is not possible to debug multiple processes simultaneously on all
generations of AMDGPU devices.  As some tests will need to debug
multiple inferiors using AMDGPU devices, we need to ensure that all
devices available have the required capability.  Failing to do so would
result in GDB not being able to debug all inferiors properly.

Add the hip_devices_support_debug_multi_process helper function used to
ensure that all devices available can debug multiple processes.

Approved-By: Pedro Alves <pedro@palves.net>
15 months agoSet PYTHONMALLOC in the test suite
Tom Tromey [Fri, 28 Jul 2023 12:25:11 +0000 (06:25 -0600)]
Set PYTHONMALLOC in the test suite

Setting PYTHONMALLOC helped me locate an earlier bug.  It seems to me
that there aren't big downsides to always setting this during testing,
and it might help find other bugs in the future.

15 months agobpf: opcodes: fix regression in BPF disassembler
Jose E. Marchesi [Mon, 31 Jul 2023 13:44:36 +0000 (15:44 +0200)]
bpf: opcodes: fix regression in BPF disassembler

This patch fixes a regression recently introduced in the BPF
disassembler, that was assuming an abfd was always available in
info->section->owner.  Apparently this is not so in GDB, and therefore
https://sourceware.org/bugzilla/show_bug.cgi?id=30705.

Tested in bpf-unkonwn-none.

opcodes/ChangeLog:

2023-07-31  Jose E. Marchesi  <jose.marchesi@oracle.com>

PR 30705
* bpf-dis.c (print_insn_bpf): Check that info->section->owner is
actually available before using it.

15 months agoUpdated Spanish translation for the gprof directory
Nick Clifton [Mon, 31 Jul 2023 12:53:23 +0000 (13:53 +0100)]
Updated Spanish translation for the gprof directory

15 months agoRestore previous sigmask in gdb.block_signals
Tom Tromey [Fri, 28 Jul 2023 18:02:38 +0000 (12:02 -0600)]
Restore previous sigmask in gdb.block_signals

Tom de Vries found a bug where, sometimes, a SIGCHLD would be
delivered to a non-main thread, wreaking havoc.

The problem is that gdb.block_signals after first blocking a set of
signals, then unblocked the same set rather than restoring the initial
situation.  This function being called from the DAP thread lead to
SIGCHLD being unblocked there.

This patch fixes the problem by restoring the previous set of signals
instead.

Tested-by: Tom de Vries <tdevries@suse.de>
Reviewed-By: Tom de Vries <tdevries@suse.de>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30680

15 months agoRISC-V: Fix typo in the test case name
Tsukasa OI [Mon, 31 Jul 2023 10:22:21 +0000 (10:22 +0000)]
RISC-V: Fix typo in the test case name

gas/ChangeLog:

* testsuite/gas/riscv/rouding-fail.s: Moved to...
* testsuite/gas/riscv/rounding-fail.s: ...here.
* testsuite/gas/riscv/rouding-fail.d: Moved to...
* testsuite/gas/riscv/rounding-fail.d: ...here.
* testsuite/gas/riscv/rouding-fail.l: Moved to...
* testsuite/gas/riscv/rounding-fail.l: ...here.

15 months agobpf: sim: do not overflow instruction immediates in tests
Jose E. Marchesi [Mon, 31 Jul 2023 09:08:32 +0000 (11:08 +0200)]
bpf: sim: do not overflow instruction immediates in tests

This patch fixes some instructions in the BPF tests that overflow the
signed immediates.  Note that this happened to work before by chance,
as GAS would silently truncate.

Tested in bpf-unknown-none.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
15 months agoAutomatic date update in version.in
GDB Administrator [Mon, 31 Jul 2023 00:00:25 +0000 (00:00 +0000)]
Automatic date update in version.in

15 months agoGDB Global Maintainer update (3 maintainers stepping down)
Joel Brobecker [Sun, 30 Jul 2023 23:09:32 +0000 (16:09 -0700)]
GDB Global Maintainer update (3 maintainers stepping down)

Doug Evans, Yao Qi and myself are stepping down as GDB Global
Maintainers. This commit therefore moves our entries to the
"Past Maintainers" section.

I've also removed myself as Ada maintainer, as well as MIPS
authorized committer.

15 months agobpf: include, bfd, opcodes: add EF_BPF_CPUVER ELF header flags
Jose E. Marchesi [Sun, 30 Jul 2023 20:39:30 +0000 (22:39 +0200)]
bpf: include, bfd, opcodes: add EF_BPF_CPUVER ELF header flags

This patch adds support for EF_BPF_CPUVER bits in the ELF
machine-dependent header flags.  These bits encode the BPF CPU
version for which the object file has been compiled for.

The BPF assembler is updated so it annotates the object files it
generates with these bits.

The BPF disassembler is updated so it honors EF_BPF_CPUVER to use the
appropriate ISA version if the user didn't specify an explicit ISA
version in the command line.  Note that a value of zero in
EF_BPF_CPUVER is interpreted by the disassembler as "use the later
supported version" (the BPF CPU versions start with v1.)

The readelf utility is updated to pretty print EF_BPF_CPUVER when it
prints out the ELF header:

   $ readelf -h a.out
   ELF Header:
     ...
     Flags:                             0x4, CPU Version: 4

Tested in bpf-unknown-none.

include/ChangeLog:

2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

* elf/bpf.h (EF_BPF_CPUVER): Define.
* opcode/bpf.h (BPF_XBPF): Change from 0xf to 0xff so it fits in
EF_BPF_CPUVER.

binutils/ChangeLog:

2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

* readelf.c (get_machine_flags): Recognize and pretty print BPF
machine flags.

opcodes/ChangeLog:

2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

* bpf-dis.c: Initialize asm_bpf_version to -1.
(print_insn_bpf): Set BPF ISA version from the cpu version ELF
header flags if no explicit version set in the command line.
* disassemble.c (disassemble_init_for_target): Remove unused code.

gas/ChangeLog:

2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

* config/tc-bpf.h (elf_tc_final_processing): Define.
* config/tc-bpf.c (bpf_elf_final_processing): New function.

15 months agobpf: gas: add field overflow checking to the BPF assembler
Jose E. Marchesi [Sun, 30 Jul 2023 19:01:03 +0000 (21:01 +0200)]
bpf: gas: add field overflow checking to the BPF assembler

This patch makes the BPF assembler to throughfully check for overflow
in immediates.  This includes relaxed instructions.

Tested in bpf-unknown-none.

gas/ChangeLog:

2023-07-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

* config/tc-bpf.c (signed_overflow): Copy function from
tc-aarch64.c.
(encode_insn): Check for overflow in constant immediates.
(add_relaxed_insn): Pass relax argument to encode_insn.
(add_fixed_insn): Likewise.
* testsuite/gas/bpf/disp16-overflow.d: New file.
* testsuite/gas/bpf/disp16-overflow.s: Likewise.
* testsuite/gas/bpf/disp16-overflow.l: Likewise.
* testsuite/gas/bpf/disp32-overflow.d: Likewise.
* testsuite/gas/bpf/disp32-overflow.s: Likewise.
* testsuite/gas/bpf/disp32-overflow.l: Likewise.
* testsuite/gas/bpf/imm32-overflow.d: Likewise.
* testsuite/gas/bpf/imm32-overflow.s: Likewise.
* testsuite/gas/bpf/imm32-overflow.l: Likewise.
* testsuite/gas/bpf/offset16-overflow.d: Likewise.
* testsuite/gas/bpf/offset16-overflow.s: Likewise.
* testsuite/gas/bpf/offset16-overflow.l: Likewise.
* testsuite/gas/bpf/disp16-overflow-relax.d: Likewise.
* testsuite/gas/bpf/disp16-overflow-relax.l: Likewise.
* testsuite/gas/bpf/disp16-overflow-relax.s: Likewise.
* testsuite/gas/bpf/jump-relax-jump-be.d: New file.
* testsuite/gas/bpf/bpf.exp: Run new tests.

15 months agoUpdate how to make a release document after the 2.41 release
Nick Clifton [Sun, 30 Jul 2023 15:07:09 +0000 (16:07 +0100)]
Update how to make a release document after the 2.41 release

15 months agoAutomatic date update in version.in
GDB Administrator [Sun, 30 Jul 2023 00:00:25 +0000 (00:00 +0000)]
Automatic date update in version.in

15 months agoAutomatic date update in version.in
GDB Administrator [Sat, 29 Jul 2023 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

15 months agobpf: remove spurious comment from tc-bpf.c
Jose E. Marchesi [Fri, 28 Jul 2023 20:20:41 +0000 (22:20 +0200)]
bpf: remove spurious comment from tc-bpf.c

15 months agobpf: gas: support relaxation of V4 jump instructions
Jose E. Marchesi [Thu, 27 Jul 2023 16:17:35 +0000 (18:17 +0200)]
bpf: gas: support relaxation of V4 jump instructions

The BPF jump-always instruction (JA), like all other jump instructions
in the ISA, get a signed 16-bit displacement target argument denoted
in number of 64-bit words minus one.  This can sometimes be overflown.

The BPF V4 ISA thus introduced support for a jump-always
instruction (JAL) that gets a signed 32-bit displacement instead.

This patch makes the BPF assembler to perform the following
relaxations when the disp16 field gets overflown, unless the option
-mno-relax is specified:

  JA disp16  -> JAL disp32
  Jxx disp16 -> Jxx +1; JA +1; JAL disp32

Documentation and tests added.
Tested in bpf-unknown-none.

gas/ChangeLog:

2023-07-28  Jose E. Marchesi  <jose.marchesi@oracle.com>

PR gas/30690
* config/tc-bpf.c (struct bpf_insn): Add fields is_relaxable and
relaxed_exp.
(enum options): Add OPTION_NO_RELAX.
(md_longopts): Likewise for -mno-relax.
(do_relax): New global.
(md_parse_option): Handle OPTION_NO_RELAX.
(RELAX_BRANCH_ENCODE): Define.
(RELAX_BRANCH_P): Likewise.
(RELAX_BRANCH_LENGTH): Likewise.
(RELAX_BRANCH_CONST): Likewise.
(RELAX_BRANCH_UNCOND): Likewise.
(relaxed_branch_length): New function.
(md_estimate_size_before_relax): Likewise.
(read_insn_word): Likewise.
(encode_int16): Likewise.
(encode_int32): Likewise.
(write_insn_bytes): Likewise.
(md_convert_frag): Likewise.
(encode_insn): Likewise.
(install_insn_fixups): Likewise.
(add_fixed_insn): Likewise.
(add_relaxed_insn): Likewise.
(md_assemble): Move instruction encoding logic to the above
new functions.
* testsuite/gas/bpf/jump-relax-ja.d: New test.
* testsuite/gas/bpf/jump-relax-ja-be.d: Likewise.
* testsuite/gas/bpf/jump-relax-ja.s: And corresponding source.
* testsuite/gas/bpf/jump-relax-jump.d: New test.
* testsuite/gas/bpf/jump-relax-jump-be.d: Likewise.
* testsuite/gas/bpf/jump-relax-jump.s: And corresponding source.
* testsuite/gas/bpf/bpf.exp: Run new tests.
* doc/c-bpf.texi (BPF Options): Document -mno-relax.

16 months ago[gdb] Rename variable main_thread to main_thread_id
Tom de Vries [Fri, 28 Jul 2023 14:01:51 +0000 (16:01 +0200)]
[gdb] Rename variable main_thread to main_thread_id

I noticed that the variable main_thread:
...
/* The main thread.  */

static std::thread::id main_thread;
...
has a confusing name and corresponding comment, because it doesn't contain the
main thread, but rather the main thread's std::thread::id.

Fix this by renaming to main_thread_id.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
16 months agoRe-acquire GIL earlier in gdbpy_parse_and_eval
Tom Tromey [Thu, 27 Jul 2023 13:54:18 +0000 (07:54 -0600)]
Re-acquire GIL earlier in gdbpy_parse_and_eval

Tom de Vries filed a bug about an intermittent gdb DAP failure -- and
coincidentally, at the same time, Alexandra Hájková sent email about a
somewhat similar failure.

After looking into this for a while (with no results) using ASan and
valgrind, I found that setting PYTHONMALLOC=malloc_debug found the bug
instantly.

The problem is that gdbpy_parse_and_eval releases the GIL while
calling parse_and_eval, but fails to re-acquire it before calling
value_to_value_object.  This is easily fixed by introducing a new
scope.

I wonder whether the test suite should unconditionally set
PYTHONMALLOC=malloc_debug.

Tested-by: Tom de Vries <tdevries@suse.de>
Reviewed-By: Tom de Vries <tdevries@suse.de>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30686

16 months agogas: amend X_unsigned uses
Jan Beulich [Fri, 28 Jul 2023 10:34:30 +0000 (12:34 +0200)]
gas: amend X_unsigned uses

PR gas/30688

X_unsigned being clear does not indicate a negative number; it merely
indicates a signed one (whose sign may still be clear). Amend two uses
by an actual value check.

16 months agoMIPS: Support `-gnuabi64' target triplet suffix for 64-bit Linux targets
YunQiang Su [Fri, 28 Jul 2023 05:00:37 +0000 (06:00 +0100)]
MIPS: Support `-gnuabi64' target triplet suffix for 64-bit Linux targets

Make the n64 ABI the default for 64-bit Linux targets specified with
`-gnuabi64' suffix included in the target triplet, for configurations
such as the Debian mips64el and mips64r6el ports.  Adjust testsuite
configuration accordingly.

There are the following regressions with the new target triplet:

mips64-linux-gnuabi64  +FAIL: readelf -S bintest
mips64-linux-gnuabi64  +FAIL: MIPS reloc estimation 1
mips64el-linux-gnuabi64  +FAIL: readelf -S bintest
mips64el-linux-gnuabi64  +FAIL: MIPS reloc estimation 1

The `readelf' issue comes from a difference in section headers produced
that the `binutils/testsuite/binutils-all/readelf.s-64' pattern template
does not match.  While there has been a precedent it does not appear to
me that there is a clear advantage from adding more and more variations
to the template rather than forking the existing template into multiple
ones for a more exact match.  So this is best deferred to a separate
discussion.

The MIPS reloc estimation issue is an actual bug in `objdump', which
discards a number of trailing entries from output here for n64 composed
relocations:

DYNAMIC RELOCATION RECORDS
OFFSET           TYPE              VALUE
0000000000000000 R_MIPS_NONE       *ABS*
0000000000000000 R_MIPS_NONE       *ABS*

and consequently `ld/testsuite/ld-mips-elf/reloc-estimate-1.d' does not
match even though ELF output produced is correct according to `readelf':

Relocation section '.rel.dyn' at offset 0x10400 contains 2 entries:
  Offset          Info           Type           Sym. Value    Sym. Name
000000000000  000000000000 R_MIPS_NONE
                    Type2: R_MIPS_NONE
                    Type3: R_MIPS_NONE
000000010000  000300001203 R_MIPS_REL32      0000000000010010 foo@@V2
                    Type2: R_MIPS_64
                    Type3: R_MIPS_NONE

As a genuine bug this has to be handled separately.

Co-Authored by: Maciej W. Rozycki <macro@orcam.me.uk>

bfd/
* config.bfd: Add `mips64*el-*-linux*-gnuabi64' and
`mips64*-*-linux*-gnuabi64' targets.

binutils/
* testsuite/binutils-all/mips/mips.exp: Handle `*-*-*-gnuabi64'
targets.
* testsuite/binutils-all/objcopy.exp: Handle
`mips64*-*-*-gnuabi64' targets.
* testsuite/binutils-all/remove-relocs-01.d: Likewise.
* testsuite/binutils-all/remove-relocs-04.d: Likewise.
* testsuite/binutils-all/remove-relocs-05.d: Likewise.
* testsuite/binutils-all/remove-relocs-06.d: Likewise.

gas/
* configure.ac: Handle `mips64*-linux-gnuabi64' targets.
* configure: Regenerate.
* testsuite/gas/mips/compact-eh-eb-7.d: Handle
`mips64*-*-*-gnuabi64' targets.
* testsuite/gas/mips/compact-eh-el-7.d: Likewise.

ld/
* configure.tgt: Add `mips64*el-*-linux-gnuabi64' and
`mips64*-*-linux-gnuabi64' targets.
* testsuite/ld-undefined/undefined.exp: Handle
`mips64*-*-*-gnuabi64' targets.
* testsuite/ld-mips-elf/attr-gnu-4-10.d: Likewise.
* testsuite/ld-mips-elf/compact-eh6.d: Likewise.
* testsuite/ld-mips-elf/mips-elf.exp: Handle `*-*-*-gnuabi64'
targets.

16 months agoMIPS/GAS/testsuite: Fix n64 compact EH failures
YunQiang Su [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/GAS/testsuite: Fix n64 compact EH failures

Expect a `.MIPS.options' section alternatively to `.reginfo' and ignore
contents of either as irrelevant for all the affected compact EH tests,
removing these regressions:

mips64-openbsd  -FAIL: Compact EH EB #1 with personality ID and FDE data
mips64-openbsd  -FAIL: Compact EH EB #2 with personality routine and FDE data
mips64-openbsd  -FAIL: Compact EH EB #3 with personality id and large FDE data
mips64-openbsd  -FAIL: Compact EH EB #4 with personality id, FDE data and LSDA
mips64-openbsd  -FAIL: Compact EH EB #5 with personality routine, FDE data and LSDA
mips64-openbsd  -FAIL: Compact EH EB #6 with personality id, LSDA and large FDE data
mips64-openbsd  -FAIL: Compact EH EL #1 with personality ID and FDE data
mips64-openbsd  -FAIL: Compact EH EL #2 with personality routine and FDE data
mips64-openbsd  -FAIL: Compact EH EL #3 with personality id and large FDE data
mips64-openbsd  -FAIL: Compact EH EL #4 with personality id, FDE data and LSDA
mips64-openbsd  -FAIL: Compact EH EL #5 with personality routine, FDE data and LSDA
mips64-openbsd  -FAIL: Compact EH EL #6 with personality id, LSDA and large FDE data
mips64el-openbsd  -FAIL: Compact EH EB #1 with personality ID and FDE data
mips64el-openbsd  -FAIL: Compact EH EB #2 with personality routine and FDE data
mips64el-openbsd  -FAIL: Compact EH EB #3 with personality id and large FDE data
mips64el-openbsd  -FAIL: Compact EH EB #4 with personality id, FDE data and LSDA
mips64el-openbsd  -FAIL: Compact EH EB #5 with personality routine, FDE data and LSDA
mips64el-openbsd  -FAIL: Compact EH EB #6 with personality id, LSDA and large FDE data
mips64el-openbsd  -FAIL: Compact EH EL #1 with personality ID and FDE data
mips64el-openbsd  -FAIL: Compact EH EL #2 with personality routine and FDE data
mips64el-openbsd  -FAIL: Compact EH EL #3 with personality id and large FDE data
mips64el-openbsd  -FAIL: Compact EH EL #4 with personality id, FDE data and LSDA
mips64el-openbsd  -FAIL: Compact EH EL #5 with personality routine, FDE data and LSDA
mips64el-openbsd  -FAIL: Compact EH EL #6 with personality id, LSDA and large FDE data

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>
gas/
* testsuite/gas/mips/compact-eh-eb-1.d: Accept `.MIPS.options'
section as an alternative to `.reginfo' and ignore contents of
either.
* testsuite/gas/mips/compact-eh-eb-2.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-3.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-4.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-5.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-6.d: Likewise.
* testsuite/gas/mips/compact-eh-el-1.d: Likewise.
* testsuite/gas/mips/compact-eh-el-2.d: Likewise.
* testsuite/gas/mips/compact-eh-el-3.d: Likewise.
* testsuite/gas/mips/compact-eh-el-4.d: Likewise.
* testsuite/gas/mips/compact-eh-el-5.d: Likewise.
* testsuite/gas/mips/compact-eh-el-6.d: Likewise.

16 months agotestsuite: Handle composed R_MIPS_NONE relocations
YunQiang Su [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
testsuite: Handle composed R_MIPS_NONE relocations

MIPS n64 ABI has a peculiarity where all relocations are composed of
three, with subsequent relocation types set to R_MIPS_NONE if further
calculation is not required.  Example output produced by `readelf' and
`objdump' for such relocations is:

  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000000  000800000002 R_MIPS_32         0000000000000000 foo + 0
                    Type2: R_MIPS_NONE
                    Type3: R_MIPS_NONE

and:

OFFSET           TYPE              VALUE
0000000000000000 R_MIPS_32         foo
0000000000000000 R_MIPS_NONE       *ABS*
0000000000000000 R_MIPS_NONE       *ABS*

respectively.  The presence of these extra R_MIPS_NONE entries is not
relevant for generic or even some MIPS tests, so optionally match them
with the respective dump patterns, also discarding `xfail' annotation
for MIPS/OpenBSD targets from gas/elf/missing-build-notes.d, removing
these regressions:

mips64-openbsd  -FAIL: readelf -r bintest
mips64-openbsd  -FAIL: forward expression
mips64-openbsd  -FAIL: assignment tests
mips64-openbsd  -FAIL: gas/all/none
mips64-openbsd  -XFAIL: gas/elf/missing-build-notes
mips64-openbsd  -FAIL: macro test 2
mips64-openbsd  -FAIL: macro irp
mips64-openbsd  -FAIL: macro rept
mips64-openbsd  -FAIL: nested irp/irpc/rept
mips64-openbsd  -FAIL: macro vararg
mips64-openbsd  -FAIL: mips jalx
mips64-openbsd  -FAIL: ST Microelectronics Loongson-2F workarounds of Jump Instruction issue
mips64el-openbsd  -FAIL: readelf -r bintest
mips64el-openbsd  -FAIL: forward expression
mips64el-openbsd  -FAIL: assignment tests
mips64el-openbsd  -FAIL: gas/all/none
mips64el-openbsd  -XFAIL: gas/elf/missing-build-notes
mips64el-openbsd  -FAIL: macro test 2
mips64el-openbsd  -FAIL: macro irp
mips64el-openbsd  -FAIL: macro rept
mips64el-openbsd  -FAIL: nested irp/irpc/rept
mips64el-openbsd  -FAIL: macro vararg
mips64el-openbsd  -FAIL: mips jalx
mips64el-openbsd  -FAIL: ST Microelectronics Loongson-2F workarounds of Jump Instruction issue

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>
binutils/
* testsuite/binutils-all/readelf.r-64: Optionally match extra
R_MIPS_NONE pairs.

gas/
* testsuite/gas/all/assign.d: Optionally match extra
R_MIPS_NONE pairs.
* testsuite/gas/all/fwdexp.d: Likewise.
* testsuite/gas/all/none.d: Likewise.
* testsuite/gas/macros/irp.d: Likewise.
* testsuite/gas/macros/repeat.d: Likewise.
* testsuite/gas/macros/rept.d: Likewise.
* testsuite/gas/macros/test2.d: Likewise.
* testsuite/gas/macros/vararg.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-1.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-2.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-3.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-4.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-5.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-6.d: Likewise.
* testsuite/gas/mips/compact-eh-el-1.d: Likewise.
* testsuite/gas/mips/compact-eh-el-2.d: Likewise.
* testsuite/gas/mips/compact-eh-el-3.d: Likewise.
* testsuite/gas/mips/compact-eh-el-4.d: Likewise.
* testsuite/gas/mips/compact-eh-el-5.d: Likewise.
* testsuite/gas/mips/compact-eh-el-6.d: Likewise.
* testsuite/gas/mips/loongson-2f-3.d: Likewise.
* testsuite/gas/mips/mips-jalx.d: Likewise.
* testsuite/gas/elf/missing-build-notes.d: Likewise.  Remove
the `xfail' tag.

ld/
* testsuite/ld-mips-elf/reloc-estimate-1.d: Optionally match
extra R_MIPS_NONE pairs.

16 months agoMIPS/testsuite: Handle 64-bit addresses
YunQiang Su [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/testsuite: Handle 64-bit addresses

Several MIPS test cases are suitable for the n64 ABI if not for the
extra leading zeros or spaces in addresses not handled by dump patterns.
Match the characters then, removing these regressions:

mips64-openbsd  -FAIL: .set arch=FOO
mips64-openbsd  -FAIL: ST Microelectronics Loongson-2F workarounds of nop issue
mips64-openbsd  -FAIL: MIPS DSP ASE for MIPS64
mips64-openbsd  -FAIL: gas/mips/align2
mips64-openbsd  -FAIL: gas/mips/align2-el
mips64-openbsd  -FAIL: Locally-resolvable PC-relative code references
mips64-openbsd  -FAIL: MIPS jalx-1
mips64-openbsd  -FAIL: JAL overflow 2
mips64el-openbsd  -FAIL: .set arch=FOO
mips64el-openbsd  -FAIL: ST Microelectronics Loongson-2F workarounds of nop issue
mips64el-openbsd  -FAIL: MIPS DSP ASE for MIPS64
mips64el-openbsd  -FAIL: gas/mips/align2
mips64el-openbsd  -FAIL: gas/mips/align2-el
mips64el-openbsd  -FAIL: Locally-resolvable PC-relative code references
mips64el-openbsd  -FAIL: MIPS jalx-1
mips64el-openbsd  -FAIL: JAL overflow 2

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>
gas/
* testsuite/gas/mips/align2-el.d: Match extra leading zeros
with addresses.
* testsuite/gas/mips/align2.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-1.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-2.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-3.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-4.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-5.d: Likewise.
* testsuite/gas/mips/compact-eh-eb-6.d: Likewise.
* testsuite/gas/mips/compact-eh-el-1.d: Likewise.
* testsuite/gas/mips/compact-eh-el-2.d: Likewise.
* testsuite/gas/mips/compact-eh-el-3.d: Likewise.
* testsuite/gas/mips/compact-eh-el-4.d: Likewise.
* testsuite/gas/mips/compact-eh-el-5.d: Likewise.
* testsuite/gas/mips/compact-eh-el-6.d: Likewise.
* testsuite/gas/mips/loongson-2f-2.d: Likewise.
* testsuite/gas/mips/loongson-2f-3.d: Likewise.
* testsuite/gas/mips/mips-jalx.d: Likewise.
* testsuite/gas/mips/mips64-dsp.d: Likewise.
* testsuite/gas/mips/pcrel-1.d: Likewise.
* testsuite/gas/mips/set-arch.d: Likewise.

ld/
* testsuite/ld-mips-elf/jaloverflow-2.d: Match extra leading
zeros and spaces with addresses as appropriate.
* testsuite/ld-mips-elf/jalx-1.d: Likewise.
* testsuite/ld-mips-elf/reloc-estimate-1.d: Likewise.

16 months agotestsuite: Also discard the `.MIPS.options' section
YunQiang Su [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
testsuite: Also discard the `.MIPS.options' section

Also discard the `.MIPS.options' section, used with n64 MIPS binaries,
along with similar other MIPS sections (`.reginfo', `.MIPS.abiflags')
not relevant for the test cases concerned, fixing these regressions:

mips64-openbsd  -FAIL: ld-elf/group3a
mips64-openbsd  -FAIL: ld-elf/group3b
mips64-openbsd  -FAIL: Place orphan sections (map file check)
mips64-openbsd  -FAIL: ld-elf/orphan-region
mips64-openbsd  -FAIL: ld-elf/orphan
mips64-openbsd  -FAIL: overlay size (map file check)
mips64-openbsd  -FAIL: overlay size
mips64el-openbsd  -FAIL: ld-elf/group3a
mips64el-openbsd  -FAIL: ld-elf/group3b
mips64el-openbsd  -FAIL: Place orphan sections (map file check)
mips64el-openbsd  -FAIL: ld-elf/orphan-region
mips64el-openbsd  -FAIL: ld-elf/orphan
mips64el-openbsd  -FAIL: overlay size (map file check)
mips64el-openbsd  -FAIL: overlay size

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>
binutils/
* testsuite/binutils-all/strip-3.d: Add `-R .MIPS.options' to
the `strip' tag.

ld/
* testsuite/ld-elf/group.ld: Also discard `.MIPS.options'.
* testsuite/ld-elf/orphan-region.ld: Likewise.
* testsuite/ld-elf/orphan.ld: Likewise.
* testsuite/ld-mips-elf/got-page-1.ld: Likewise.
* testsuite/ld-scripts/overlay-size.t: Likewise.

16 months agoMIPS/LD/testsuite: Fix MIPS16 interlinking test IRIX 6 regressions
Maciej W. Rozycki [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/LD/testsuite: Fix MIPS16 interlinking test IRIX 6 regressions

IRIX 6 does not have MIPS16 stub section support in its n32 linker
scripts, causing such input sections to be propagated to the respective
output sections rather than `.text', causing dump pattern mismatches.

Expect IRIX 6 to fail with n32 testing then, removing this regression:

mips-sgi-irix6  -FAIL: MIPS16 interlinking for local functions 1 (n32)

We may choose to update IRIX 6 n32 linker scripts sometime, as it seems
a harmless change.

ld/
* testsuite/ld-mips-elf/mips-elf.exp: Expect IRIX 6 to fail with
n32 `mips16-local-stubs-1' testing.

16 months agoMIPS/LD/testsuite: Fix MIPS16 interlinking test n64 regressions
YunQiang Su [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/LD/testsuite: Fix MIPS16 interlinking test n64 regressions

The MIPS16 interlinking test for local functions expects to be assembled
with 32-bit addressing, otherwise causing assembly warnings:

.../ld/testsuite/ld-mips-elf/mips16-local-stubs-1.s: Assembler messages:
.../ld/testsuite/ld-mips-elf/mips16-local-stubs-1.s:16: Warning: la used to load 64-bit address; recommend using dla instead

Use the per-ABI framework then to run the test explicitly for o32 and
n32 ABIs only, replacing the `-mips4' option from the `as' tag with
`.module mips4' pseudo-op within the source itself so as to avoid
assembly errors:

Assembler messages:
Error: -mips4 conflicts with the other architecture options, which imply -mips3

with n32 testing for some targets, and ultimately removing these
regressions:

mips64-openbsd  -FAIL: MIPS16 interlinking for local functions 1
mips64el-openbsd  -FAIL: MIPS16 interlinking for local functions 1

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>
ld/
* testsuite/ld-mips-elf/mips16-local-stubs-1.d: Remove `-mips4'
from the `as' tag.
* testsuite/ld-mips-elf/mips16-local-stubs-1.s: Add `.module
mips4'.
* testsuite/ld-mips-elf/mips-elf.exp: Run `mips16-local-stubs-1'
for o32 and n32 ABIs only.

16 months agoMIPS/GAS/testsuite: Force o32 for tests expecting 32-bit addressing
YunQiang Su [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/GAS/testsuite: Force o32 for tests expecting 32-bit addressing

A few GAS tests expect to be assembled with 32-bit addressing, otherwise
causing an assembly warning:

.../gas/testsuite/gas/mips/fix-rm7000-2.s:11: Warning: la used to load 64-bit address; recommend using dla instead

or pattern dump mismatches against 32-bit address calculations, however
these tests do not enforce their expectation in any.  For none of them
the specific ABI used is of any relevance however, so select the o32 ABI
unconditionally, removing these failures with OpenBSD targets:

mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (micromips)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips3)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips4)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips5)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips64)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips64r2)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips64r3)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips64r5)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (octeon)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (octeon2)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (octeon3)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (octeonp)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (r4000)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (sb1)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (vr5400)
mips64-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (xlr)
mips64-openbsd  -FAIL: MIPS-OCTEON octeon_saa_saad (octeon2)
mips64-openbsd  -FAIL: MIPS-OCTEON octeon_saa_saad (octeon3)
mips64-openbsd  -FAIL: MIPS-OCTEON octeon_saa_saad (octeonp)
mips64-openbsd  -FAIL: Full MIPS R5900
mips64-openbsd  -FAIL: MIPS R5900 VU0
mips64-openbsd  -FAIL: Paired LL/SC for mips64r6 (mips64r6)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (micromips)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips3)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips4)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips5)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips64)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips64r2)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips64r3)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (mips64r5)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (octeon)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (octeon2)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (octeon3)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (octeonp)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (r4000)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (sb1)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (vr5400)
mips64el-openbsd  -FAIL: MIPS RM7000 workarounds test 2 (xlr)
mips64el-openbsd  -FAIL: MIPS-OCTEON octeon_saa_saad (octeon2)
mips64el-openbsd  -FAIL: MIPS-OCTEON octeon_saa_saad (octeon3)
mips64el-openbsd  -FAIL: MIPS-OCTEON octeon_saa_saad (octeonp)
mips64el-openbsd  -FAIL: Full MIPS R5900
mips64el-openbsd  -FAIL: MIPS R5900 VU0
mips64el-openbsd  -FAIL: Paired LL/SC for mips64r6 (mips64r6)

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>
gas/
* testsuite/gas/mips/fix-rm7000-2.d: Add `-32' to the `as' tag.
* testsuite/gas/mips/micromips@fix-rm7000-2.d: Likewise.
* testsuite/gas/mips/r5900-full.d: Likewise.
* testsuite/gas/mips/r5900-vu0.d: Likewise.
* testsuite/gas/mips/llpscp-64.d: Add `as' tag with `-32'.
* testsuite/gas/mips/octeon-saa-saad.d: Likewise.

16 months agoMIPS/LD/testsuite: Run `got-dump-1' for o32/n32 ABIs
Maciej W. Rozycki [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/LD/testsuite: Run `got-dump-1' for o32/n32 ABIs

The `got-dump-1' test case uses 32-bit addressing, so it makes no sense
to run it with the n64 ABI.  And there is a corresponding `got-dump-2'
test already for the n64 ABI.

Use the per-ABI framework then to run the `got-dump-1' test explicitly
for o32 and n32 ABIs only.

ld/
* testsuite/ld-mips-elf/mips-elf.exp: Run `got-dump-1' for o32
and n32 ABIs only.

16 months agoMIPS/LD/testsuite: Fix `attr-gnu-4-10' failures with OpenBSD targets
Maciej W. Rozycki [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/LD/testsuite: Fix `attr-gnu-4-10' failures with OpenBSD targets

OpenBSD targets produce ELF64 files while the pattern dump expects ELF32
output and specific header sizes.  Disable it for `mips64*-*-openbsd*'
for these targets then, removing these failures:

mips64-openbsd  -FAIL: ld-mips-elf/attr-gnu-4-10
mips64el-openbsd  -FAIL: ld-mips-elf/attr-gnu-4-10

ld/
* testsuite/ld-mips-elf/attr-gnu-4-10.d: Add `notarget' tag with
`mips64*-*-openbsd*'.

16 months agoMIPS/LD/testsuite: Fix `attr-gnu-4-10' failures with IRIX targets
Maciej W. Rozycki [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/LD/testsuite: Fix `attr-gnu-4-10' failures with IRIX targets

IRIX targets do not enable the production of a `.pdr' section in GAS by
default, which causes a failure with the `attr-gnu-4-10' test case due
to a difference resulting in the number and indices of sections produced
in linker output.

As the presence or absence of this section is not relevant to this test
case, just enable it unconditionally, fixing these regressions:

mips-sgi-irix5  -FAIL: ld-mips-elf/attr-gnu-4-10
mips-sgi-irix6  -FAIL: ld-mips-elf/attr-gnu-4-10

ld/
* testsuite/ld-mips-elf/attr-gnu-4-10.d: Add `as' tag with
`-mpdr'.

16 months agoMIPS/LD/testsuite: Fix JALR relaxation test failure with IRIX 6
Maciej W. Rozycki [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/LD/testsuite: Fix JALR relaxation test failure with IRIX 6

The `mips-sgi-irix6' target only supports IRIX linker emulations, but
most JALR relaxation tests request the relevant traditional emulation
instead, causing a link failure:

./ld-new: unrecognised emulation mode: elf32btsmipn32
Supported emulations: elf32bmipn32 elf32bsmip elf64bmip

This is clearly an omission from the conversion to use the per-ABI
framework made with commit 78da84f99405 ("MIPS/LD/testsuite: Correct
mips-elf.exp test ABI/emul/endian arrangement").  These tests are also
endianness agnostic, which was missed in the conversion as well.

Remove the unnecessary explicit ABI and endianness options then and rely
on the per-ABI framework to get things right, removing this regression:

mips-sgi-irix6  -FAIL: MIPS relax-jalr-shared n32

ld/
* testsuite/ld-mips-elf/relax-jalr-n32-shared.d: Remove flags
related to ABI and endianness selection from the `as' and `ld'
tags.
* testsuite/ld-mips-elf/relax-jalr-n64.d: Likewise.
* testsuite/ld-mips-elf/relax-jalr-n64-shared.d: Likewise.
* testsuite/ld-mips-elf/mips-elf.exp: Remove `as' and `ld' tag
additions from the invocation of JALR relaxation tests.

16 months agoMIPS/LD/testsuite: Fix unaligned JALX failures with OpenBSD targets
Maciej W. Rozycki [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/LD/testsuite: Fix unaligned JALX failures with OpenBSD targets

There are only n64 linker emulations included with `mips64*-*-openbsd*'
targets, however the unaligned JALX tests insist on running across all
targets and force the n32 ABI, causing link errors with the targets
concerned, e.g.:

./ld-new: tmpdir/unaligned-jalx-0.o: ABI is incompatible with that of the selected emulation
./ld-new: failed to merge target specific data of file tmpdir/unaligned-jalx-0.o
./ld-new: tmpdir/unaligned-insn.o: ABI is incompatible with that of the selected emulation
./ld-new: failed to merge target specific data of file tmpdir/unaligned-insn.o

Convert the tests then to use the per-ABI framework and run them for the
o32 and n32 ABIs, removing these regressions:

mips64-openbsd  -FAIL: MIPS JALX to unaligned symbol 0
mips64-openbsd  -FAIL: MIPS JALX to unaligned symbol 1
mips64-openbsd  -FAIL: MIPS JALX to unaligned symbol 2
mips64-openbsd  -FAIL: MIPS JALX to unaligned symbol 3
mips64-openbsd  -FAIL: MIPS16 JALX to unaligned symbol 0
mips64-openbsd  -FAIL: MIPS16 JALX to unaligned symbol 1
mips64-openbsd  -FAIL: microMIPS JALX to unaligned symbol 0
mips64-openbsd  -FAIL: microMIPS JALX to unaligned symbol 1
mips64el-openbsd  -FAIL: MIPS JALX to unaligned symbol 0
mips64el-openbsd  -FAIL: MIPS JALX to unaligned symbol 1
mips64el-openbsd  -FAIL: MIPS JALX to unaligned symbol 2
mips64el-openbsd  -FAIL: MIPS JALX to unaligned symbol 3
mips64el-openbsd  -FAIL: MIPS16 JALX to unaligned symbol 0
mips64el-openbsd  -FAIL: MIPS16 JALX to unaligned symbol 1
mips64el-openbsd  -FAIL: microMIPS JALX to unaligned symbol 0
mips64el-openbsd  -FAIL: microMIPS JALX to unaligned symbol 1

Similar tests for the n64 ABI can be added separately, using suitable
dump patterns.

ld/
* testsuite/ld-mips-elf/unaligned-jalx-0.d: Remove `-32' from
the `as' tag.
* testsuite/ld-mips-elf/unaligned-jalx-1.d: Likewise.
* testsuite/ld-mips-elf/unaligned-jalx-2.d: Likewise.
* testsuite/ld-mips-elf/unaligned-jalx-3.d: Likewise.
* testsuite/ld-mips-elf/unaligned-jalx-mips16-0.d: Likewise.
* testsuite/ld-mips-elf/unaligned-jalx-mips16-1.d: Likewise.
* testsuite/ld-mips-elf/unaligned-jalx-micromips-0.d: Likewise.
* testsuite/ld-mips-elf/unaligned-jalx-micromips-1.d: Likewise.
* testsuite/ld-mips-elf/mips-elf.exp: Run unaligned JALX tests
with `run_dump_test_o32' and `run_dump_test_n32' rather than
`run_dump_test'.

16 months agoMIPS/GAS/testsuite: Disable compact EH #7 tests with OpenBSD targets
Maciej W. Rozycki [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/GAS/testsuite: Disable compact EH #7 tests with OpenBSD targets

Compact EH #7 tests use output templates that are not suitable for the
n64 ABI, which `mips64*-*-openbsd*' targets use by default, because the
contents of the sections examined are expected to be differnt.  Disable
the tests then, removing these regressions:

mips64-openbsd  -FAIL: Compact EH EB #7 with personality id and fallback FDE
mips64-openbsd  -FAIL: Compact EH EL #7 with personality id and fallback FDE
mips64el-openbsd  -FAIL: Compact EH EB #7 with personality id and fallback FDE
mips64el-openbsd  -FAIL: Compact EH EL #7 with personality id and fallback FDE

Suitable corresponding tests for the n64 ABI can be added separately.

gas/
* testsuite/gas/mips/compact-eh-eb-7.d: Exclude for
`mips64*-*-openbsd*'.
* testsuite/gas/mips/compact-eh-el-7.d: Likewise.

16 months agoMIPS/LD: Include n64 `.interp' with INITIAL_READONLY_SECTIONS
YunQiang Su [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
MIPS/LD: Include n64 `.interp' with INITIAL_READONLY_SECTIONS

In ld/emulparams/elf64bmip-defs.sh there is no explicit handling of the
`.interp' section, which causes it to be positioned in output at an odd
place.

Let's include it with INITIAL_READONLY_SECTIONS, just like o32/n32 do,
fixing a regression from commit 5a8e7be242f3 ("INITIAL_READONLY_SECTIONS
in elf.sc"), where the handling of n64 was missed due to an unfortunate
sequence of events where ld/emulparams/elf64bmip-defs.sh was only added
with commit 94bb04b3c611 ("Use .reginfo rather than .MIPS.options in n32
linker scripts") the day before.

Add test cases covering section ordering across the three ABIs.  This
change also fixes ld/pr23658-2:

FAIL: Build pr23658-2

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>
ld/ChangeLog:
* emulparams/elf64bmip-defs.sh: Include `.interp' with
INITIAL_READONLY_SECTIONS.
* testsuite/ld-mips-elf/pie-n64.d: Adjust addresses.
* testsuite/ld-mips-elf/sections-1-o32.rd: New test.
* testsuite/ld-mips-elf/sections-1-o32t.rd: New test.
* testsuite/ld-mips-elf/sections-1-n32.rd: New test.
* testsuite/ld-mips-elf/sections-1-n32t.rd: New test.
* testsuite/ld-mips-elf/sections-1-n32p.rd: New test.
* testsuite/ld-mips-elf/sections-1-n64.rd: New test.
* testsuite/ld-mips-elf/sections-1-n64t.rd: New test.
* testsuite/ld-mips-elf/sections-2-o32.rd: New test.
* testsuite/ld-mips-elf/sections-2-o32t.rd: New test.
* testsuite/ld-mips-elf/sections-2-n32.rd: New test.
* testsuite/ld-mips-elf/sections-2-n32t.rd: New test.
* testsuite/ld-mips-elf/sections-2-n32p.rd: New test.
* testsuite/ld-mips-elf/sections-2-n64.rd: New test.
* testsuite/ld-mips-elf/sections-2-n64t.rd: New test.
* testsuite/ld-mips-elf/sections.s: New test source.
* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.

16 months agoRevert "MIPS: support mips*64 as CPU and gnuabi64 as ABI"
Maciej W. Rozycki [Fri, 28 Jul 2023 05:00:36 +0000 (06:00 +0100)]
Revert "MIPS: support mips*64 as CPU and gnuabi64 as ABI"

This reverts commit 32f1c80375ebe8ad25d9805ee5889f0006c51e59.  It had
two unrelated changes lumped together, one of which changed the meaning
of the `mipsisa64*-*-linux*' target triplets, which was not properly
evaluated.

16 months agoldscripts/empty-address vs. xcoff
Alan Modra [Fri, 28 Jul 2023 03:36:17 +0000 (13:06 +0930)]
ldscripts/empty-address vs. xcoff

The empty-address tests check that if a section is removed by ld due
to being empty then properties of that section don't affect following
addresses.  The xcoff backend doesn't remove the empty .data section
created by empty-address-2* and empty-address-3* for some reason, and
therefore fails the test.

* testsuite/ld-scripts/empty-address-1.d: Accept more symbols.
* testsuite/ld-scripts/empty-address-2a.d: xfail for xcoff.
* testsuite/ld-scripts/empty-address-2b.d: Likewise.
* testsuite/ld-scripts/empty-address-3a.d: Likewise.
* testsuite/ld-scripts/empty-address-3b.d: Likewise.

16 months agoFix recent x86 pe/coff testsuite regressions
Alan Modra [Fri, 28 Jul 2023 03:33:46 +0000 (13:03 +0930)]
Fix recent x86 pe/coff testsuite regressions

* testsuite/gas/i386/sha512-intel.d: Accept section nop padding.
* testsuite/gas/i386/sha512.d: Likewise.
* testsuite/gas/i386/sm3-intel.d: Likewise.
* testsuite/gas/i386/sm3.d: Likewise.
* testsuite/gas/i386/x86-64-pbndkb-intel.d: Likewise.
* testsuite/gas/i386/x86-64-pbndkb.d: Likewise.
* testsuite/gas/i386/x86-64-sha512-intel.d: Likewise.
* testsuite/gas/i386/x86-64-sha512.d: Likewise.
* testsuite/gas/i386/x86-64-sm3-intel.d: Likewise.
* testsuite/gas/i386/x86-64-sm3.d: Likewise.

16 months agocoff/pe/xcoff and --extract-symbols
Alan Modra [Fri, 28 Jul 2023 03:14:17 +0000 (12:44 +0930)]
coff/pe/xcoff and --extract-symbols

This fixes failure of the "extract symbols" test for rs6000, where
--extract-symbols generates a non-zero sized .text.  By the look of
coffcode.h the same problem might occur for coff/pe too, but doesn't
happen to trigger a test failure.

bfd/
* coffcode.h (coff_compute_section_file_positions): Don't
adjust size of !SEC_LOAD sections.
binutils/
* objcopy.c (setup_section): Clear SEC_LOAD for --extract-symbol.

16 months agoRISC-V: Add actual 'Zvkt' extension support
Tsukasa OI [Wed, 26 Jul 2023 01:39:44 +0000 (01:39 +0000)]
RISC-V: Add actual 'Zvkt' extension support

The 'Zvkt' extension is listed on the added extensions in the GNU Binutils
version 2.41 (see binutils/NEWS).  However, the support of this extension
was actually missing.

This commit adds actual support of this extension and adds implications
from 'Zvkn' and 'Zvks' superset extensions.

bfd/ChangeLog:

* elfxx-riscv.c (riscv_implicit_subsets) Add implications from
'Zvkn' and 'Zvks'.  (riscv_supported_std_z_ext): Add 'Zvkt' to
the supported extension list.

16 months agoFix typo in riscv-dis.c comment
Tsukasa OI [Fri, 28 Jul 2023 03:33:39 +0000 (03:33 +0000)]
Fix typo in riscv-dis.c comment

Don't go "past" the start of the section.

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

16 months agogdb: remove trailing empty line in target-delegates.c
Simon Marchi [Thu, 27 Jul 2023 17:32:38 +0000 (13:32 -0400)]
gdb: remove trailing empty line in target-delegates.c

In a review [1], I pointed out that applying the patch, git would say:

    .git/rebase-apply/patch:147: new blank line at EOF.

However, since the empty line is in target-delegates.c (a generated
file), there's nothing the author can do about it.  To avoid this
comment coming up again in the future, change make-target-delegates.py
to avoid the trailing empty line.  Do this by making it output empty
lines before each entity, not after.

Since this needs removing a newline output in gdbcopyright, adjust
ada-unicode.py and gdbarch.py to avoid changes in the files they
generate.

[1] https://inbox.sourceware.org/gdb-patches/20230427210113.45380-1-jhb@FreeBSD.org/T/#m083598405bef19157f67c9d97846d3dd90dc7d1c

Change-Id: Ic4c648f06443b432168cb76603402c918aa6e5d2
Approved-By: Tom Tromey <tom@tromey.com>
16 months agoReport supportsBreakpointLocationsRequest
Tom Tromey [Thu, 27 Jul 2023 16:31:32 +0000 (10:31 -0600)]
Report supportsBreakpointLocationsRequest

While looking at the DAP spec, I noticed that the breakpointLocations
request is gated behind a capability.  This patch changes gdb to
report this capability.

I've also added a comment to explain the fact that arguments to
breakpointLocations are not optional, even though the spec says they
are.

16 months ago/DISCARD/ in ld testsuite
Alan Modra [Thu, 27 Jul 2023 08:33:49 +0000 (18:03 +0930)]
/DISCARD/ in ld testsuite

The canonical form to discard all sections not mentioned earlier in
the script is
  /DISCARD/ : { *(*) }
not
  /DISCARD/ : { *(.*) }
".*" happens to work with the usual section names starting with a dot,
but let's not promote something not quite right.

16 months agosh: uninitialised sh_operand_info.type in get_specific
Alan Modra [Wed, 26 Jul 2023 23:43:56 +0000 (09:13 +0930)]
sh: uninitialised sh_operand_info.type in get_specific

Seen when running gas/testsuite/gas/sh/err-at.s

* config/tc-sh.c (get_operands): Always init operand type.
* testsuite/gas/sh/err-at.s: Expect unnecessary extra errors.

16 months agoSupport Intel PBNDKB
Hu, Lin1 [Mon, 24 Jul 2023 03:10:03 +0000 (11:10 +0800)]
Support Intel PBNDKB

gas/ChangeLog:

* NEWS: Support Intel PBNDKB.
* config/tc-i386.c: Add pbndkb.
* doc/c-i386.texi: Document .pbndkb.
* testsuite/gas/i386/i386.exp: Add PBNDKB tests.
* testsuite/gas/i386/x86-64.exp: Ditto.
* testsuite/gas/i386/pbndkb-inval.l: New test.
* testsuite/gas/i386/pbndkb-inval.s: Ditto.
* testsuite/gas/i386/x86-64-pbndkb-intel.d: Ditto.
* testsuite/gas/i386/x86-64-pbndkb.d: Ditto.
* testsuite/gas/i386/x86-64-pbndkb.s: Ditto.

opcodes/ChangeLog:

* i386-dis.c (X86_64_0F01_REG_0_MOD_3_RM_7): New.
(X86_64_0F01_REG_0_MOD_3_RM_7_P_0): Ditto.
(prefix_table): Add PREFIX_0F01_REG_0_MOD_3_RM_7.
(x86_64_table): Add X86_64_0F01_REG_0_MOD_3_RM_7_P_0.
(rm_table): New entry for pbndkb.
* i386-gen.c (cpu_flag): Add PBNDKB.
* i386-init.h: Regenerated.
* i386-mnem.h: Ditto.
* i386-opc.h (CpuPBNDKB): New.
(i386_cpu_flags): Add cpupbndkb.
* i386-opc.tbl: Add PBNDKB instructions.
* i386-tbl.h: Regenerated.

16 months agoSupport Intel SM4
Haochen Jiang [Mon, 24 Jul 2023 03:09:57 +0000 (11:09 +0800)]
Support Intel SM4

gas/ChangeLog:

* NEWS: Support Intel SM4.
* config/tc-i386.c: Add sm4.
* doc/c-i386.texi: Document .sm4.
* testsuite/gas/i386/i386.exp: Run SM4 tests.
* testsuite/gas/i386/x86-64.exp: Ditto.
* testsuite/gas/i386/sm4-intel.d: Add SM4 tests.
* testsuite/gas/i386/sm4.d: Ditto.
* testsuite/gas/i386/sm4.s: Ditto.
* testsuite/gas/i386/x86-64-sm4-intel.d: Ditto.
* testsuite/gas/i386/x86-64-sm4.d: Ditto.
* testsuite/gas/i386/x86-64-sm4.s: Ditto.

opcodes/ChangeLog:

* i386-dis.c (prefix_table): Add SM4 instructions.
* i386-gen.c (isa_dependencies): Add SM4.
(cpu_flags): Ditto.
* i386-init.h: Regenerated.
* i386-mnem.h: Ditto.
* i386-opc.h (CpuSM4): New.
(i386_cpu_flags): Add cpusm4.
* i386-opc.tbl: Add SM4 instructions.
* i386-tbl.h: Regenerated.

16 months agoSupport Intel SM3
Haochen Jiang [Mon, 24 Jul 2023 03:09:49 +0000 (11:09 +0800)]
Support Intel SM3

gas/ChangeLog:

* NEWS: Support Intel SM3.
* config/tc-i386.c: Add sm3.
* doc/c-i386.texi: Document .sm3.
* testsuite/gas/i386/i386.exp: Run sm3 tests.
* testsuite/gas/i386/x86-64.exp: Ditto.
* testsuite/gas/i386/sm3-intel.d: New test.
* testsuite/gas/i386/sm3.d: Ditto.
* testsuite/gas/i386/sm3.s: Ditto.
* testsuite/gas/i386/x86-64-sm3-intel.d: Ditto.
* testsuite/gas/i386/x86-64-sm3.d: Ditto.
* testsuite/gas/i386/x86-64-sm3.s: Ditto.

opcodes/ChangeLog:

* i386-dis.c (PREFIX_VEX_0F38DA_W_0): New.
(VEX_LEN_0F38DA_W_0_P_0): Ditto.
(VEX_LEN_0F38DA_W_0_P_2): Ditto.
(VEX_LEN_0F3ADE_W_0): Ditto.
(VEX_W_0F38DA): Ditto.
(VEX_W_0F3ADE): Ditto.
(prefix_table): Add PREFIX_VEX_0F38DA_W_0.
(vex_len_table): Add VEX_LEN_0F38DA_W_0_P_0,
VEX_LEN_0F38DA_W_0_P_2, VEX_LEN_0F3ADE_W_0.
(vex_w_table): Add VEX_W_0F38DA, VEX_W_0F3ADE.
* i386-gen.c (isa_dependencies): Add SM3.
(cpu_flags): Ditto.
* i386-init.h: Regenerated.
* i386-mnem.h: Ditto.
* i386-opc.h (CpuSM3): New.
(i386_cpu_flags): Add cpusm3.
* i386-opc.tbl: Add SM3 instructions.
* i386-tbl.h: Regenerated.

16 months agoSupport Intel SHA512
Haochen Jiang [Mon, 24 Jul 2023 03:09:43 +0000 (11:09 +0800)]
Support Intel SHA512

gas/ChangeLog:

* NEWS: Support Intel SHA512.
* config/tc-i386.c: Add sha512.
* doc/c-i386.texi: Document .sha512.
* testsuite/gas/i386/disassem.d: Add SHA512 tests.
* testsuite/gas/i386/disassem.s: Ditto.
* testsuite/gas/i386/i386.exp: Run SHA512 tests.
* testsuite/gas/i386/x86-64.exp: Ditto.
* testsuite/gas/i386/sha512-intel.d: New test.
* testsuite/gas/i386/sha512-inval.l: Ditto.
* testsuite/gas/i386/sha512-inval.s: Ditto.
* testsuite/gas/i386/sha512.d: Ditto.
* testsuite/gas/i386/sha512.s: Ditto.
* testsuite/gas/i386/x86-64-sha512-intel.d: Ditto.
* testsuite/gas/i386/x86-64-sha512-inval.l: Ditto.
* testsuite/gas/i386/x86-64-sha512-inval.s: Ditto.
* testsuite/gas/i386/x86-64-sha512.d: Ditto.
* testsuite/gas/i386/x86-64-sha512.s: Ditto.

opcodes/ChangeLog:

* i386-dis.c (Rxmmq): New.
(Rymm): Ditto.
(PREFIX_VEX_0F38CB): Ditto.
(PREFIX_VEX_0F38CC): Ditto.
(PREFIX_VEX_0F38CD): Ditto.
(VEX_LEN_0F38CB_P_3_W_0): Ditto.
(VEX_LEN_0F38CC_P_3_W_0): Ditto.
(VEX_LEN_0F38CD_P_3_W_0): Ditto.
(VEX_W_0F38CB_P_3): Ditto.
(VEX_W_0F38CC_P_3): Ditto.
(VEX_W_0F38CD_P_3): Ditto.
(prefix_table): Add PREFIX_VEX_0F38CB, PREFIX_VEX_0F38CC,
PREFIX_VEX_0F38CD.
(vex_len_table): Add VEX_LEN_0F38CB_P_3_W_0,
VEX_LEN_0F38CC_P_3_W_0, VEX_LEN_0F38CD_P_3_W_0.
(vex_w_table): Add VEX_W_0F38CB_P_3, VEX_W_0F38CC_P_3, VEX_W_0F38CD_P_3.
* i386-gen.c (isa_dependencies): Add SHA512.
(cpu_flags): Ditto.
* i386-init.h: Regenerated.
* i386-mnem.h: Ditto.
* i386-opc.h (CpuSHA512): New.
(i386_cpu_flags): Add cpusha512.
* i386-opc.tbl: Add SHA512 instructions.
* i386-tbl.h: Regenerated.