]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
14 months agoAutomatic date update in version.in
GDB Administrator [Sun, 14 Apr 2024 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoAutomatic date update in version.in
GDB Administrator [Sat, 13 Apr 2024 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoFix setting watchpoints when current thread is running
Pedro Alves [Tue, 2 May 2023 14:04:28 +0000 (15:04 +0100)] 
Fix setting watchpoints when current thread is running

Currently, when the current thread is running, you can print global
variables.  However, if you try to set a watchpoint on the same
globals, GDB errors out, complaining that the selected thread is
running.  Like so:

 (gdb) c&
 Continuing.
 (gdb) p global
 $1 = 1098377287
 (gdb) watch global
 Selected thread is running.

This patch makes setting the watchpoint work.  You'll now get:

 (gdb) c&
 Continuing.
 (gdb) [New Thread 0x7ffff7d6e640 (LWP 434993)]
 [New Thread 0x7ffff756d640 (LWP 434994)]
 p global
 $1 = 88168
 (gdb) watch global
 Hardware watchpoint 2: global
 (gdb) [Switching to Thread 0x7ffff7d6e640 (LWP 434993)]

 Thread 2 "function0" hit Hardware watchpoint 2: global

 Old value = 185420
 New value = 185423
 int_return () at threads.c:39
 39      }

The problem is that update_watchpoint calls get_selected_frame
unconditionally.  We can skip it if the watchpoint expression is only
watching globals.

This adds a testcase that exercises both all-stop and non-stop, and
also software and hardware watchpoints.  It is kfailed for software
watchpoints, as those require another fix not handled by this patch
(the sw watchpoint doesn't fire because GDB doesn't force the
running-free thread to switch to single-stepping).

Change-Id: I68ca948541aea3edd4f70741f272f543187abe40

14 months agoNew testcase gdb.threads/leader-exit-attach.exp (PR threads/8153)
Pedro Alves [Mon, 25 Mar 2024 15:17:02 +0000 (15:17 +0000)] 
New testcase gdb.threads/leader-exit-attach.exp (PR threads/8153)

Add a new testcase for exercising attaching to a process after its
main thread has exited.

This is not possible on Linux, the kernel does not allow attaching to
a zombie task, so the test is kfailed there.  It is possible however
on Windows at least, and was the scenario addressed by the Windows
backend fix in
https://sourceware.org/legacy-ml/gdb-patches/2003-12/msg00479.html,
nowadays PR threads/8153, back in 2003.

Passes cleanly on Cygwin.
KFAILed on GNU/Linux native and gdbserver.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=8153
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31554
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31555
Change-Id: Ib554f92f68c965bb4603cdf2aadb55ca45ded53b

14 months agoCygwin/testsuite: Avoid infinite hang
Pedro Alves [Tue, 5 Mar 2024 16:03:15 +0000 (16:03 +0000)] 
Cygwin/testsuite: Avoid infinite hang

On Cygwin, the gdb.base/fork-no-detach-follow-child-dlopen.exp
testcase hits a sequence of cascading FAILs:

 (gdb) run
 Starting program: ..../gdb.base/fork-no-detach-follow-child-dlopen/fork-no-detach-follow-child-dlopen
 [New Thread 12672.0x318c]
 [New Thread 12672.0x2844]
 [New Thread 12672.0x714]
 FAIL: gdb.base/fork-no-detach-follow-child-dlopen.exp: runto: run to add (timeout)
 frame
 FAIL: gdb.base/fork-no-detach-follow-child-dlopen.exp: frame (timeout)
 list
 FAIL: gdb.base/fork-no-detach-follow-child-dlopen.exp: list (timeout)

And the test program never makes progress.

... and at this point, Cygwin is completely stuck.  I can't run any
other Cygwin program.

However, if we run the test program outside DejaGnu, we see something
different:

  (gdb) b add
  Function "add" not defined.
  Make breakpoint pending on future shared library load? (y or [n]) y
  Breakpoint 1 (add) pending.
  (gdb) r
  Starting program: ..../gdb.base/fork-no-detach-follow-child-dlopen/fork-no-detach-follow-child-dlopen
  [New Thread 10968.0x834]
  [New Thread 10968.0x29a4]
  [New Thread 10968.0x16b8]
  [New Thread 10968.0xf9c]
  [Switching to Thread 10968.0x16b8]

  Thread 4 "sig" hit Breakpoint 1.2, pending_signals::add (pack=..., this=0x7ffa1e748a40 <sigq>) at /usr/src/debug/cygwin-3.4.9-1/winsup/cygwin/sigproc.cc:1304
  1304      se = sigs + pack.si.si_signo;
  (gdb)

Ah, the test wanted to run to a global "add" function, but managed to
stop at an internal Cygwin method called "add".  And stopping there
deadlocks everything Cygwin in the system.  (I believe some
cygwin1.dll mechanisms use cross-process synchronization or
communication, we're probably blocking something like that.)

Fix this by using "break -q".  The tests FAIL because we don't support
follow-fork for Cygwin, but at least we no longer deadlock the
machine.

Approved-by: Kevin Buettner <kevinb@redhat.com>
Change-Id: I7181d8481c2ae1024b0d73e3bb194f9a4f0a7eb9

14 months agogdb/data-directory: silence output from mkinstalldirs script
Andrew Burgess [Mon, 8 Apr 2024 11:34:39 +0000 (12:34 +0100)] 
gdb/data-directory: silence output from mkinstalldirs script

After my recent changes the data-directory build now uses
silent-rules.mk to reduce the output.

One problem that remains was the use of mkinstalldirs by stamp-python
and stamp-guile for creating some directories, the mkinstalldirs
prints some messages, so we're left with output like this:

    GEN    stamp-python
  mkdir -p -- ./python/gdb
  mkdir -p -- ./python/gdb/command
  mkdir -p -- ./python/gdb/dap
  mkdir -p -- ./python/gdb/function
  mkdir -p -- ./python/gdb/printer

I was looking at adding a --silent option to the mkinstalldirs script,
however, when I took a look at the automake package (which is where
mkinstalldirs comes from) it turns out that mkinstalldirs is
deprecated, at the advice is to use 'install-sh -d' instead.

Just like we carry mkinstalldirs in the top-level directory, we also
carry install-sh, and a version of install-sh which supports the -d
flag.

And best of all, 'install-sh -d' doesn't appear to print any of the
information messages to stdout that mkinstalldirs does, so if we
switch to use that, we get a quieter build.

There should be no changes in what is built after this commit

Approved-By: Tom Tromey <tom@tromey.com>
14 months agoUpdate description of macro keyword argument assignment in assembler documentation.
Nick Clifton [Fri, 12 Apr 2024 15:51:51 +0000 (16:51 +0100)] 
Update description of macro keyword argument assignment in assembler documentation.

  PR 31255

14 months agogas: Fix memory leaks in gen-sframe.c
H.J. Lu [Thu, 11 Apr 2024 11:26:34 +0000 (04:26 -0700)] 
gas: Fix memory leaks in gen-sframe.c

* gen-sframe.c (sframe_xlate_ctx_cleanup): Call XDELETE on
xlate_ctx->cur_fre.
(create_sframe_all): Call XDELETE on xlate_ctx after use.

14 months agoAutomatic date update in version.in
GDB Administrator [Fri, 12 Apr 2024 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoRe: Fix null pointer dereference in process_debug_info()
Alan Modra [Thu, 11 Apr 2024 23:25:02 +0000 (08:55 +0930)] 
Re: Fix null pointer dereference in process_debug_info()

read_bases has a potential null-pointer deref too, and without a
debug_info_p there isn't any point in calling read_bases.

* dwarf.c (process_debug_info): Don't call read_bases when
debug_info_p is NULL.

14 months agoImprove readelf's display of RELR relocs.
Nick Clifton [Thu, 11 Apr 2024 15:57:18 +0000 (16:57 +0100)] 
Improve readelf's display of RELR relocs.

14 months agoAdd -j/--display-section option to readelf.
Nick Clifton [Thu, 11 Apr 2024 14:57:26 +0000 (15:57 +0100)] 
Add -j/--display-section option to readelf.

14 months ago[gdb/testsuite] Fix gdb.threads/access-mem-running-thread-exit.exp with clang
Tom de Vries [Thu, 11 Apr 2024 11:43:52 +0000 (13:43 +0200)] 
[gdb/testsuite] Fix gdb.threads/access-mem-running-thread-exit.exp with clang

When running test-case gdb.threads/access-mem-running-thread-exit.exp with
clang, we run into:
...
(gdb) print global_var = 555^M
No symbol "global_var" in current context.^M
(gdb) FAIL: gdb.threads/access-mem-running-thread-exit.exp: all-stop: \
  access mem (write to global_var, inf=2, iter=1)
...

The problem is that clang removes the unused variable.

Fix this in the same way as done in commit b4f767131f7
("Fix gdb.base/align-*.exp and Clang + LTO and AIX GCC"), by incrementing the
variable.

Tested on x86_64-linux with gcc and clang.

14 months agogas: Fix a CFI label name memory leak in scfi.c
H.J. Lu [Tue, 9 Apr 2024 23:04:16 +0000 (16:04 -0700)] 
gas: Fix a CFI label name memory leak in scfi.c

CFI label name can be freed only after use.

* scfi.c (handle_scfi_dot_cfi): Free CFI label name after use.
* scfidw2gen.c (scfi_process_cfi_label): Add a comment.  Remove
TODO on freeing CFI label name.

14 months agogas: Fix memory leaks in ginsn.c
H.J. Lu [Tue, 9 Apr 2024 23:05:18 +0000 (16:05 -0700)] 
gas: Fix memory leaks in ginsn.c

Free buffer memory after use in ginsn.c.

* ginsn.c (ginsn_dst_print): Free buffer after use.
(ginsn_print): Likewise.

14 months agogdb: fix format in remote.c
Tankut Baris Aktemur [Thu, 11 Apr 2024 11:00:43 +0000 (13:00 +0200)] 
gdb: fix format in remote.c

Fix space-before-parenthesis format at three spots in remote.c.

14 months agoRemove bfdwin.c
Alan Modra [Thu, 11 Apr 2024 02:26:50 +0000 (11:56 +0930)] 
Remove bfdwin.c

In commit b86d3af60ffc and 0ab0435fe672 I fixed SIGBUS errors found by
oss-fuzz now that --with-mmap defaults to enabled.  It turns out there
are further problems with the aout mmap code: aout_read_minisymbols
returns the external symbol array, which is later freed by nm.c.  If
the array is mmaped you can't free it.  Now this could be fixed by
making aout minisymbols an array of pointers, but I figure there's not
much point in expending effort on that.  So delete the aout mmap
support along with bfdwin.c and get_section_contents_in_window.

14 months agoasan: heap buffer overflow elf_link_add_to_first_hash
Alan Modra [Thu, 11 Apr 2024 07:09:18 +0000 (16:39 +0930)] 
asan: heap buffer overflow elf_link_add_to_first_hash

Seen on mmix.
mmix  +FAIL: ld-misc/defsym1
mmix  +FAIL: sysroot-prefix common plain -Lpath, quoted
mmix  +FAIL: sysroot-prefix common plain -Lpath, unquoted
mmix  +FAIL: sysroot-prefix common full-path, quoted
mmix  +FAIL: sysroot-prefix common full-path, unquoted
mmix  +FAIL: sysroot-prefix common plain =-prefixed with empty, quoted
mmix  +FAIL: sysroot-prefix common plain =-prefixed with empty, unquoted
mmix  +FAIL: sysroot-prefix common plain $SYSROOT-prefixed with empty, quoted
mmix  +FAIL: sysroot-prefix common plain $SYSROOT-prefixed with empty, unquoted
mmix  +FAIL: sysroot-prefix common plain =-prefixed -Lpath, quoted
mmix  +FAIL: sysroot-prefix common plain =-prefixed -Lpath, unquoted
mmix  +FAIL: sysroot-prefix common plain $SYSROOT-prefixed -Lpath, quoted
mmix  +FAIL: sysroot-prefix common plain $SYSROOT-prefixed -Lpath, unquoted
mmix  +FAIL: sysroot-prefix common full-path =-prefixed without, quoted
mmix  +FAIL: sysroot-prefix common full-path =-prefixed without, unquoted
mmix  +FAIL: sysroot-prefix common full-path $SYSROOT-prefixed without, quoted
mmix  +FAIL: sysroot-prefix common full-path $SYSROOT-prefixed without, unquoted

==3746597==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6070000007a0 at pc 0x56d87b0d1a40 bp 0x7fffb1629bf0 sp 0x7fffb1629be0
READ of size 8 at 0x6070000007a0 thread T0
    #0 0x56d87b0d1a3f in elf_link_add_to_first_hash /home/alan/src/binutils-gdb/bfd/elflink.c:4312

mmix uses bfd_link_generic_hash_table.

* elflink.c (_bfd_elf_archive_symbol_lookup): Dont use first_hash
unless the hash table is bfd_link_elf_hash_table.
(elf_link_add_archive_symbols): Likewise.

14 months agoRe: Update objcopy's --section-alignment option
Alan Modra [Thu, 11 Apr 2024 03:42:21 +0000 (13:12 +0930)] 
Re: Update objcopy's --section-alignment option

ubsan: shift exponent 255 is too large for 64-bit type

I should have known oss-fuzz wouldn't be satisfied so easily.  The pef
format allows quite silly section alignments in object files.

* objcopy.c (setup_section): Limit shift exponent when checking
vma and lma for alignment.

14 months agox86-64: Use long NOPs for Intel Core processors
H.J. Lu [Mon, 1 Apr 2024 17:03:11 +0000 (10:03 -0700)] 
x86-64: Use long NOPs for Intel Core processors

Use long NOPs for Intel Core processors since they are faster than
multiple NOPs.  Don't use them for 64-bit processors by default since
Intel Atom processors can only decode 4 prefixes in 1 cycle.

* config/tc-i386.c (alt64_9): New.
(alt64_10): Likewise.
(alt64_11): Likewise.
(alt64_12): Likewise.
(alt64_13): Likewise.
(alt64_14): Likewise.
(alt64_15): Likewise.
(alt64_patt): Likewise.
(i386_generate_nops): Use alt64_patt for Intel Core processors
in 64-bit mode.
* testsuite/gas/i386/x86-64-nops-1-core2.d: Expect long NOPs.
* testsuite/gas/i386/x86-64-nops-4-core2.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-1-core2.d: Replace
../x86-64-nops-1.d with ../x86-64-nops-1-core2.d.
* testsuite/gas/i386/ilp32/x86-64-nops-4-core2.d: Replace
../x86-64-nops-4.d with ../x86-64-nops-4-core2.d.

14 months agommap: Fix a memory leak in _bfd_mmap_read_temporary
H.J. Lu [Tue, 9 Apr 2024 23:02:48 +0000 (16:02 -0700)] 
mmap: Fix a memory leak in _bfd_mmap_read_temporary

Return malloced memory in *mmap_base so that _bfd_munmap_readonly_temporary
will free it.

* libbfd.c (_bfd_mmap_read_temporary): Return malloced memory
in *mmap_base.

14 months agoelf: Fix a memory leak in _bfd_elf_add_dynamic_entry
H.J. Lu [Wed, 10 Apr 2024 01:41:59 +0000 (18:41 -0700)] 
elf: Fix a memory leak in _bfd_elf_add_dynamic_entry

Normally, the section contents is allocated by bfd_alloc which is freed
when the object is closed.  But the .dynamic section contents is allocated
by bfd_realloc, which should be freed by calling free.  Add a dynamic
field to elf_link_hash_table for the .dynamic section and free its
contents in _bfd_elf_link_hash_table_free.

* elf-bfd.h (elf_link_hash_table): Add dynamic.
* elflink.c (_bfd_elf_link_create_dynamic_sections): Set the
dynamic field in elf_link_hash_table.
(_bfd_elf_add_dynamic_entry): Use hash_table->dynamic.
(_bfd_elf_strip_zero_sized_dynamic_sections): Likewise.
(bfd_elf_add_dt_needed_tag): Likewise.
(elf_finalize_dynstr): Likewise.
(_bfd_elf_link_hash_table_free): Free htab->dynamic->contents.
(bfd_elf_final_link): Use htab->dynamic.
* elfxx-x86.c (_bfd_x86_elf_finish_dynamic_sections): Use
htab->elf.dynamic.

14 months agoSegfault in _bfd_delete_bfd with USE_MMAP
Alan Modra [Wed, 10 Apr 2024 23:55:13 +0000 (09:25 +0930)] 
Segfault in _bfd_delete_bfd with USE_MMAP

Any of the calls to _bfd_delete_bfd in bfd_fopen will hit this.

* opncls.c (_bfd_delete_bfd): Check for non-NULL xvec before
accessing flavour.

14 months agoAutomatic date update in version.in
GDB Administrator [Thu, 11 Apr 2024 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agogas: scfi: bugfixes for SCFI state propagation
Indu Bhagat [Wed, 10 Apr 2024 20:46:37 +0000 (13:46 -0700)] 
gas: scfi: bugfixes for SCFI state propagation

There are two state propagation functions in SCFI machinery - forward
and backward flow.  The patch addresses two issues:
  - In forward_flow_scfi_state (), the state being compared in forward flow
    must be that at the exit of a prev bb and that at the entry of the
    next bb.  The variable holding the state to be compared was
    previously (erroneously) stale.
  - In cmp_scfi_state (), the assumption that two different control
    flows, leading to the same basic block, cannot have a mismatched
    notion of CFA base register, is not true.  Remove the assertion and
    instead return err if mismatch.

Fixing these issues helps correctly synthesize CFI, when previously
SCFI was erroring out for an otherwise valid input asm.

gas/
* scfi.c (cmp_scfi_state): Remove assertion and return mismatch
in return value as applicable.
(forward_flow_scfi_state): Update state object to be the same as
the exit state of the prev bb before comparing.

gas/testsuite/
* gas/scfi/x86_64/scfi-x86-64.exp: Add new test.
* gas/scfi/x86_64/scfi-cfg-5.d: New test.
* gas/scfi/x86_64/scfi-cfg-5.l: New test.
* gas/scfi/x86_64/scfi-cfg-5.s: New test.

14 months agogas: gcfg: add_bb_at_ginsn must return root_bb
Indu Bhagat [Wed, 10 Apr 2024 20:45:59 +0000 (13:45 -0700)] 
gas: gcfg: add_bb_at_ginsn must return root_bb

A GCFG (ginsn control flow graph) is created for SCFI purposes in GAS.
The existing GCFG creation process was ignoring some paths.

add_bb_at_ginsn () is a recursive function which should return the root
of the added basic blocks.  This property was being violated in some
traversals, e.g., where a taken path involving a sequence of a few basic
blocks eventually culminated in a GINSN_TYPE_RETURN instruction.  This
patch fixes the issue by keeping an explicit variable root_bb to
memorize the bb to be returned.

Next, find_or_make_bb () must either create or find the bb with the
first ginsn as the provided ginsn.  Add a few assertions to ensure
health of the cfg creation process.

Note that the testcase, in its current shape, is not fit for catching
regressions for the issue at hand.  Although the testcase does exercise
the updated code path, the testcase passes even without the current fix,
because the added edge in this specific testcase does not alter the
synthesized CFI.  (The missing edge is the fallthrough edge of the
conditional branch "jne .L13" in the testcase.)

Using a manual gcfg_print (), one can see the missing edge without the
fix.  Lets keep the testcase for now, until there is a better way to
test the GCFG for this issue (e.g., either by dumping the GCFG in
textual format, or a case when the missing edge does cause wrong
synthesized CFI).

gas/
* ginsn.c (bb_add_edge): Fix a code comment.
(find_bb): Likewise.
(find_or_make_bb): Add new assertions to ensure health of cfg
creation process.
(add_bb_at_ginsn): Keep reference to the root_bb and return it.

gas/testsuite/
* gas/scfi/x86_64/scfi-x86-64.exp: Add new test.
* gas/scfi/x86_64/scfi-cfg-4.d: New test.
* gas/scfi/x86_64/scfi-cfg-4.l: New test.
* gas/scfi/x86_64/scfi-cfg-4.s: New test.

14 months agogdb, gdbserver: Add missing install-dvi Makefile target
Christophe Lyon [Thu, 4 Apr 2024 21:51:17 +0000 (21:51 +0000)] 
gdb, gdbserver: Add missing install-dvi Makefile target

For some reason install-dvi is missing although other targets of the
same family are present. This looks like an oversight.

This enables calling 'make install-dvi' from the top-level build
directory.

Fix what looks like another oversight: include 'pdf' in 'all-doc' in
gdb/doc/Makefile.in.

Approved-By: Luis Machado <luis.machado@arm.com>
Tested-By: Luis Machado <luis.machado@arm.com>
14 months agoreadelf: Add -j/--display-section command line option.
Nick Clifton [Wed, 10 Apr 2024 11:23:44 +0000 (12:23 +0100)] 
readelf: Add -j/--display-section command line option.

14 months agommap: Avoid the sanitizer configure check failure
H.J. Lu [Tue, 9 Apr 2024 13:43:36 +0000 (06:43 -0700)] 
mmap: Avoid the sanitizer configure check failure

When -fsanitize=address,undefined is used to build, the mmap configure
check failed with

=================================================================
==231796==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d72b in main /home/alan/build/gas-san/all/bfd/conftest.c:239

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d2e1 in main /home/alan/build/gas-san/all/bfd/conftest.c:190

SUMMARY: AddressSanitizer: 8192 byte(s) leaked in 2 allocation(s).

Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP to avoid the sanitizer
configure check failure.

bfd/

* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.

binutils/

* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.

ld/

* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.

libctf/

* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.

libsframe/

* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.

14 months agommap: Avoid the sanitizer configure check failure
H.J. Lu [Tue, 9 Apr 2024 13:39:21 +0000 (06:39 -0700)] 
mmap: Avoid the sanitizer configure check failure

When -fsanitize=address,undefined is used to build, the mmap configure
check failed with

=================================================================
==231796==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d72b in main /home/alan/build/gas-san/all/bfd/conftest.c:239

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d2e1 in main /home/alan/build/gas-san/all/bfd/conftest.c:190

SUMMARY: AddressSanitizer: 8192 byte(s) leaked in 2 allocation(s).

Define GCC_AC_FUNC_MMAP with export ASAN_OPTIONS=detect_leaks=0 to avoid
the sanitizer configure check failure.

config/

* mmap.m4 (GCC_AC_FUNC_MMAP): New.
* no-executables.m4 (AC_FUNC_MMAP): Renamed to GCC_AC_FUNC_MMAP.
Change AC_FUNC_MMAP to GCC_AC_FUNC_MMAP.

libiberty/

* Makefile.in (aclocal_deps): Add $(srcdir)/../config/mmap.m4.
* acinclude.m4: Change AC_FUNC_MMAP to GCC_AC_FUNC_MMAP.
* aclocal.m4: Regenerated.
* configure: Likewise.

zlib/

* acinclude.m4: Include ../config/mmap.m4.
* Makefile.in: Regenerated.
* configure: Likewise.

14 months agoRe: ld testsuite: Append NOSANITIZE_CFLAGS to CFLAGS_FOR_TARGET
Alan Modra [Tue, 9 Apr 2024 23:57:44 +0000 (09:27 +0930)] 
Re: ld testsuite: Append NOSANITIZE_CFLAGS to CFLAGS_FOR_TARGET

Don't use CC_FOR_TARGET in the bootstrap test, a silly idea aiming at
consistency that made things worse.  The objects being linked were
built using $CC, so $CC should be used to link.

* testsuite/ld-bootstrap/bootstrap.exp: Revert last change.

14 months agoAutomatic date update in version.in
GDB Administrator [Wed, 10 Apr 2024 00:00:22 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoRewrite gdb_bfd_error_handler
Tom Tromey [Tue, 13 Feb 2024 01:38:36 +0000 (18:38 -0700)] 
Rewrite gdb_bfd_error_handler

This patch rewrites gdb_bfd_error_handler to use 'bfd_print_error' to
generate the text of the warning, and then emits it using 'warning'.
The current code in the tree is a bit wrong because it may do the
wrong thing when BFD uses ones of its printf extensions.

This also adds locking to increment_bfd_error_count.  This is
important now that some BFD operations can be done on worker threads.

This approach makes it simpler for worker threads to intercept any
messages.

Regression tested on x86-64 Fedora 38.

14 months agoaarch64: Treat operand "SME list of ZA tiles" as immediate (PR 31561)
Jens Remus [Tue, 9 Apr 2024 15:21:53 +0000 (17:21 +0200)] 
aarch64: Treat operand "SME list of ZA tiles" as immediate (PR 31561)

The AArch64 instruction table (aarch64-tbl.h) defines the operand
"SME list of ZA tiles" (SME_list_of_64bit_tiles) as immediate. During
assembly it is correctly encoded as immediate value (imm.value) in
parse_operands. During disassembly it is first correctly decoded as
immediate value (imm.value) in aarch64_ext_imm called by
aarch64_extract_operand, but then erroneously treated as register
number (reg.regno) in aarch64_print_operand.

This resolves the assembler test case "SME extension (ZERO)" to
erroneously fail on s390. On AArch64 - being little-endian - the struct
aarch64_opnd_info union fields reg.regno and imm.value share their
least-significant bits. On s390 - being big-endian - they do not.

opcodes/
PR binutils/31561
* aarch64-opc.c: Treat operand "SME list of ZA tiles" as
immediate.

Bug: https://sourceware.org/PR31561
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Acked-by: Nick Clifton <nickc@redhat.com>
14 months agos390: Flag conditional branch relative insns as condjump
Jens Remus [Tue, 9 Apr 2024 15:17:02 +0000 (17:17 +0200)] 
s390: Flag conditional branch relative insns as condjump

Flag conditional branch relative (extended) mnemonics clij* and clgij*
as "condjump" for jump visualization in disassembly. They were missed
to be flagged as such in commit c5306fed7d40 ("s390: Support for jump
visualization in disassembly").

opcodes/
* s390-opc.txt: Flag conditional branch relative instructions
clij* and clgij* as condjump for jump visualization in
disassembly.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Acked-by: Nick Clifton <nickc@redhat.com>
14 months agobfd: Define pagesize variables only for mmap
H.J. Lu [Tue, 9 Apr 2024 02:39:23 +0000 (19:39 -0700)] 
bfd: Define pagesize variables only for mmap

Define _bfd_pagesize, _bfd_pagesize_m1 and _bfd_minimum_mmap_size only
if HAVE_MMAP is defined.

* libbfd-in.h (_bfd_pagesize): Declare only if HAVE_MMAP is
defined.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
* libbfd.c (_bfd_pagesize): Define only if HAVE_MMAP is defined.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
(bfd_init_pagesize): Likewise.
* lynx-core.c (lynx_core_file_p): Replace _bfd_pagesize with
getpagesize.

14 months agoarm: Fix disassembly of MVE vq[r]shr[u]n
Alex Coplan [Tue, 2 Apr 2024 13:27:58 +0000 (14:27 +0100)] 
arm: Fix disassembly of MVE vq[r]shr[u]n

This patch fixes the disassembly of vq[r]shr[u]n insns so that the
shift immediate is properly decoded.  See the description of the
previous patch for an example of the incorrect disassembly.

As part of this patch we also fix the mve-vqrshrn.d test which was
testing for the incorrect disassembly of the immediates.  The
disassembly now matches the assembled instructions in that test.

Finally we add an mve-vqshrn test which tests the non-rounding variants
of those insns, whose encoding we fixed with the previous patch in this
series.

14 months agoarm: Fix encoding of MVE vqshr[u]n
Alex Coplan [Tue, 2 Apr 2024 12:42:13 +0000 (13:42 +0100)] 
arm: Fix encoding of MVE vqshr[u]n

As it stands, these insns are incorrectly encoded as vqrshr[u]n.
Concretely, the problem can be seen as follows:

$ cat t.s
vqrshrnb.s16 q0,q0,#8
vqshrnb.s16 q0,q0,#8
$ gas/as-new t.s -march=armv8.1-m.main+mve -o t.o
$ binutils/objdump -d t.o -m armv8.1-m.main

t.o:     file format elf32-littlearm

Disassembly of section .text:

00000000 <.text>:
   0:   ee88 0f41       vqrshrnb.s16    q0, q0, #0
   4:   ee88 0f41       vqrshrnb.s16    q0, q0, #0

Here we assemble these two instructions to the same opcode.  The
encoding of the first is the correct, while the encoding of the second
is incorrect, and the bottom bit should be clear, see the Armv8-M ARM:
https://developer.arm.com/documentation/ddi0553/latest/

There is an additional problem here in that the disassembly of the
immediate is incorrect.  llvm-objdump shows the correct disassembly
here:

t.o:    file format elf32-littlearm

Disassembly of section .text:

00000000 <$t>:
       0: ee88 0f41     vqrshrnb.s16    q0, q0, #8
       4: ee88 0f41     vqrshrnb.s16    q0, q0, #8

Note that we defer adding a test for the correct encoding of these insns
until the next patch which fixes the disassembly issue.

14 months agoarm: Refactor condition for print_mve_shift_n
Alex Coplan [Tue, 2 Apr 2024 13:03:38 +0000 (14:03 +0100)] 
arm: Refactor condition for print_mve_shift_n

This is intended to have no functional change, but refactors the
condition guarding the call to print_mve_shift_n in arm-dis.c ahead of a
later patch which adds additional insns to the set of those whose
shift immediate is disassembled using print_mve_shift_n.

14 months agoRISC-V: Support Zcmp push/pop instructions.
Jiawei [Tue, 27 Feb 2024 03:48:11 +0000 (11:48 +0800)] 
RISC-V: Support Zcmp push/pop instructions.

Support zcmp extension push/pop/popret and popret zero instructions.
The `reg_list' is a list containing 1 to 13 registers, we can use:
"{ra}, {ra, s0}, {ra, s0-s1}, {ra, s0-s2} ... {ra, s0-sN}"
to present this feature.

Passed gcc/binutils regressions of riscv-gnu-toolchain.

Most of work was finished by Sinan Lin.
Co-Authored by: Charlie Keaney <charlie.keaney@embecosm.com>
Co-Authored by: Mary Bennett <mary.bennett@embecosm.com>
Co-Authored by: Nandni Jamnadas <nandni.jamnadas@embecosm.com>
Co-Authored by: Sinan Lin <sinan.lin@linux.alibaba.com>
Co-Authored by: Simon Cook <simon.cook@embecosm.com>
Co-Authored by: Shihua Liao <shihua@iscas.ac.cn>
Co-Authored by: Yulong Shi <yulong@iscas.ac.cn>

bfd/ChangeLog:

        * elfxx-riscv.c (riscv_implicit_subset): Imply zca for zcmp.
(riscv_supported_std_z_ext): Added zcmp with version 1.0.
(riscv_parse_check_conflicts): Zcmp conflicts with d/zcd.
        (riscv_multi_subset_supports): Handle zcmp.
        (riscv_multi_subset_supports_ext): Ditto.

gas/ChangeLog:

* NEWS: Updated.
        * config/tc-riscv.c (regno_to_reg_list): New function, used to map
register to reg_list number.
        (reglist_lookup): Called reglist_lookup_internal.  Return false if
reg_list number is zero, which is an invalid value.
(reglist_lookup_internal): Parse register list, and return the last
register by regno_to_reg_list.
        (validate_riscv_insn):  New operators.
        (riscv_ip): Ditto.
* testsuite/gas/riscv/march-help.l: Updated.
        * testsuite/gas/riscv/zcmp-push-pop-fail.d: New test.
        * testsuite/gas/riscv/zcmp-push-pop-fail.l: New test.
        * testsuite/gas/riscv/zcmp-push-pop-fail.s: New test.
        * testsuite/gas/riscv/zcmp-push-pop.d: New test.
        * testsuite/gas/riscv/zcmp-push-pop.s: New test.

include/ChangeLog:

        * opcode/riscv-opc.h (MATCH/MASK_CM_PUSH): New macros for zcmp.
        (MATCH/MASK_CM_POP): Ditto.
        (MATCH/MASK_CM_POPRET): Ditto.
        (MATCH/MASK_CM_POPRETZ): Ditto.
        (DECLARE_INSN): New declarations for zcmp.
        * opcode/riscv.h (EXTRACT/ENCODE/VALID_ZCMP_SPIMM): Handle spimm
operand for zcmp.
        (OP_MASK_REG_LIST): Handle operand for zcmp register list.
        (OP_SH_REG_LIST): Ditto.
        (ZCMP_SP_ALIGNMENT): New argument, used in riscv_get_sp_base.
        (X_S0, X_S1, X_S2, X_S10, X_S11): New register numbers.
        (enum riscv_insn_class): Added INSN_CLASS_ZCMP.
        (extern riscv_get_sp_base): Added.

opcodes/ChangeLog:

        * riscv-dis.c (print_reg_list): New function, used to get zcmp
reg_list field.
        (riscv_get_spimm): New function, used to get zcmp sp adjustment
immediate.
        (print_insn_args): Handle new operands for zcmp.
        * riscv-opc.c (riscv_get_sp_base): New function, used by gas and
objdump.  Get sp base adjustment.
(riscv_opcodes): Added zcmp instructions.

14 months agoLoongArch: ld: Move .got .got.plt before .data and protect .got with relro
mengqinggang [Wed, 3 Apr 2024 02:20:27 +0000 (10:20 +0800)] 
LoongArch: ld: Move .got .got.plt before .data and protect .got with relro

Move .got .got.plt before .data so .got can be protected with -zrelro.
And the first two entries of .got.plt (_dl_runtime_resolve and link map)
are placed within the relro region.

14 months agoSupport {evex} pseudo prefix for decode evex promoted insns without egpr32.
Hu, Lin1 [Tue, 9 Apr 2024 02:58:39 +0000 (10:58 +0800)] 
Support {evex} pseudo prefix for decode evex promoted insns without egpr32.

This patch is based on APX NF patch and also adds test cases for Checking 64-bit insns not sizeable through
register operands with evex.

gas/ChangeLog:

        * testsuite/gas/i386/x86-64-apx-evex-promoted-intel.d: Added no-egpr testcases for movbe.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-wig.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted.s: Ditto.
        * testsuite/gas/i386/x86-64.exp: Added tests.
        * testsuite/gas/i386/noreg64-evex.d: New test.
        * testsuite/gas/i386/noreg64-evex.e: Ditto.
        * testsuite/gas/i386/noreg64-evex.s: Ditto.
        * testsuite/gas/i386/x86-64-apx_f-evex.d: Ditto.
        * testsuite/gas/i386/x86-64-apx_f-evex.s: Ditto.

opcodes/ChangeLog:

        * i386-dis-evex.h: Added %ME to movbe.
        * i386-dis.c : Added %XE to evex_from_vex instructions to output {evex}.
        (struct dis386): New %ME.
        (putop): Handle %ME and output {evex} for evex_from_legacy instructions.
        * Return early when the instruction name is (bad).

14 months agoRemove dead code in bfdwin.c
Alan Modra [Mon, 8 Apr 2024 23:20:23 +0000 (08:50 +0930)] 
Remove dead code in bfdwin.c

All of bfdwin.c is wrapped in USE_MMAP.  There isn't any point in
HAVE_MMAP tests inside USE_MMAP.

* bfdwin.c (bfd_free_window, bfd_get_file_window): Delete
HAVE_MMAP conditionals.

14 months agold testsuite: Append NOSANITIZE_CFLAGS to CFLAGS_FOR_TARGET
Alan Modra [Sat, 6 Apr 2024 01:16:09 +0000 (11:46 +1030)] 
ld testsuite: Append NOSANITIZE_CFLAGS to CFLAGS_FOR_TARGET

The idea here is build tests without sanitizer flags, so they don't
fail due to many not using the compiler to link and thus result in
undefined symbols, since libasan is not supplied.  We definitely do not
want a compiler to perform linking in most cases, and it's complicated
to supply libasan (and would possibly disturb testcase output).

* testsuite/config/default.exp (CFLAGS_FOR_TARGET),
(CXXFLAGS_FOR_TARGET): Append NOSANITIZE_CFLAGS.
* testsuite/ld-bootstrap/bootstrap.exp: Use CC_FOR_TARGET and
CFLAGS_FOR_TARGET throughout.

14 months agoAutomatic date update in version.in
GDB Administrator [Tue, 9 Apr 2024 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agold: Add PR ld/31615 tests
H.J. Lu [Mon, 8 Apr 2024 02:52:49 +0000 (19:52 -0700)] 
ld: Add PR ld/31615 tests

PR ld/31615
* testsuite/ld-plugin/lto.exp: Run ld/31615 tests.
* testsuite/ld-plugin/pr31615.ver: New file.
* testsuite/ld-plugin/pr31615a.c: Likewise.
* testsuite/ld-plugin/pr31615b.c: Likewise.
* testsuite/ld-plugin/pr31615c.c: Likewise.
* testsuite/ld-plugin/pr31615d.c: Likewise.

14 months agoremote.c: Make packet_ok return struct packet_result
Alexandra Hájková [Thu, 8 Feb 2024 17:06:16 +0000 (18:06 +0100)] 
remote.c: Make packet_ok return struct packet_result

This allows the error message stored in a packet_result to be easily
printed in the calling function.

Approved-By: Andrew Burgess <aburgess@redhat.com>
14 months agoremote.c: Use packet_check_result
Alexandra Hájková [Tue, 30 Jan 2024 14:55:47 +0000 (15:55 +0100)] 
remote.c: Use packet_check_result

when processing the GDBserver reply to qRcmd packet.
Print error message or the error code.
Currently, when qRcmd request returns an error,
GDB just prints:

Protocol error with Rcmd

After this change, GDB will also print the error code:

Protocol error with Rcmd: 01.

Add an accept_msg argument to packet_check result. qRcmd
request (such as many other packets) does not recognise
"E.msg" form as an error right now. We want to recognise
"E.msg" as an error response only for the packets where
it's documented.

Also use packet_check result in remote_read_bytes_1.

Approved-By: Andrew Burgess <aburgess@redhat.com>
14 months agogdb/configure: realign the AC_ARG_ENABLE(sim, ....) block
Andrew Burgess [Mon, 8 Apr 2024 09:56:51 +0000 (10:56 +0100)] 
gdb/configure: realign the AC_ARG_ENABLE(sim, ....) block

Following the suggestion in this review comment:

  https://inbox.sourceware.org/gdb-patches/9420bbb0-2614-4847-9157-8562f8a62d03@simark.ca

this commit realigns the AC_ARG_ENABLE(sim, ....) block.  I've added
additional [...] quoting in a couple of places, which is inline with
how other AC_ARG_ENABLE blocks are formatted within GDB's configure.ac
file.

There should be no change in how GDB configures or builds after this
commit.

14 months agogdb/build: apply silent-rules.mk to the data-directory Makefile.in
Andrew Burgess [Sat, 6 Apr 2024 16:28:37 +0000 (17:28 +0100)] 
gdb/build: apply silent-rules.mk to the data-directory Makefile.in

This commit makes use of gdb/silent-rules.mk in the data-directory
Makefile.in.  I've only updated the rules that actually generate
things, I've not touched the install or uninstall rules, this matches
gdb/Makefile.in.

I've not managed to completely silence all of the recipe output, the
mkinstalldirs command outputs some diagnostic text which looks like
this:

    GEN    stamp-python
  mkdir -p -- ./python/gdb
  mkdir -p -- ./python/gdb/command
  mkdir -p -- ./python/gdb/dap
  mkdir -p -- ./python/gdb/function
  mkdir -p -- ./python/gdb/printer

I have a patch for mkinstalldirs that fixes this (by adding a new
--silent command line flag), but that patch needs to be submitted to
automake, then an updated mkinstalldirs sync'd to the gcc repository,
and then copied into the binutils-gdb repository... so I'm leaving
that for a future project.

Then the guild compiler also emits some diagnostic output, which looks
like this:

    GEN    stamp-guile
  mkdir -p -- ./guile/.
  mkdir -p -- ./guile/gdb
  wrote `./gdb.go'
  wrote `gdb/experimental.go'
  wrote `gdb/iterator.go'
  wrote `gdb/printing.go'
  wrote `gdb/support.go'
  wrote `gdb/types.go'

The 'wrote' lines are from the guild compiler.  The only way to
silence these would be to redirect stdout to /dev/null I think.  I did
prototype this, but wasn't 100% convinced about that part of the
patch, so I've decided to leave that for another day.

I did need to add a new SILENT_ECHO variable to silent-rules.mk, this
is set to a suitable 'echo' command to use within recipes.  When we
are in silent mode then I use the 'true' command, while in verbose
mode we actually use 'echo'.

So, other than the issues outlined above, the output when building the
data-directory is now greatly reduced, and more inline with the output
when building in the gdb/ directory.

There should be no change in what is actually built after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agogdb/configure: use AC_MSG_NOTICE not a direct echo call
Andrew Burgess [Sat, 6 Apr 2024 15:39:34 +0000 (16:39 +0100)] 
gdb/configure: use AC_MSG_NOTICE not a direct echo call

After the recent commits, I noticed that GDB's configure script would
still emit two lines even when run in silent mode.  If you touch
gdb/Makefile.in and then run 'make all' in the gdb/ build directory
you'll see this:

    GEN    config.status
  enable_sim = no
  enableval = no

Obviously the 'no' might be 'yes' depending on how you actually
configured GDB.

This is caused by two direct invocations of 'echo' in GDB's
configure.ac script.

In this commit I replace these calls with use of AC_MSG_NOTICE
instead.  Now when configure is run with the --silent command line
option these lines will not be printed.

There should be no changes in the built GDB after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agogdb/Makefile: Print 'GEN' message, and pass SILENT_FLAG more
Andrew Burgess [Fri, 5 Apr 2024 09:53:00 +0000 (10:53 +0100)] 
gdb/Makefile: Print 'GEN' message, and pass SILENT_FLAG more

The targets that use config.status to regenerate themselves don't
currently follow the silent rules that the rest of GDB's Makefile
does.  For example, touch the gdb/gcore.in file and then 'make all' in
the gdb/ directory prints:

  /bin/sh config.status gcore
  config.status: creating gcore

In this commit I make use of the silent-rules.mk mechanism for these
targets, now we get:

  GEN    gcore

Which matches the rest of our Makefile.  Obviously, if you pass 'V=1'
to the build then you'll get the old output back.

There's no change in what is generated after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agogdb/Makefile: add some missing config.status dependencies
Andrew Burgess [Fri, 5 Apr 2024 09:52:17 +0000 (10:52 +0100)] 
gdb/Makefile: add some missing config.status dependencies

I noticed that for the build targets jit-reader.h, gcore, gdb-gdb.py,
and gdb-gdb.gdb the rules all use the config.status script, but don't
have a dependency on the config.status target.  This means we might
fail to regenerate these targets in a case where config.status, or one
of its dependencies changes.

Two other targets that use config.status do correctly have a
dependency on config.status.

Fixed in this commit by adding the missing dependencies.

There should be no changes in _what_ is generated after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agogdb/Makefile: rewrite dependencies for config.status target
Andrew Burgess [Fri, 5 Apr 2024 09:50:27 +0000 (10:50 +0100)] 
gdb/Makefile: rewrite dependencies for config.status target

I noticed something weird, the rule for the config.status target looks
like this:

  config.status: $(srcdir)/configure configure.nat configure.tgt configure.host ../bfd/development.sh
          $(SHELL) config.status --recheck

What bothered me is that 'configure' is specified as being in
$(srcdir), while all of the other files are not, even though those
files are in the same $(srcdir) as the configure script.

However, I tried touching one of those files, and the config.status
rule does trigger!

This is thanks to the VPATH variable, which is set to $(srcdir), so
make looks in $(srcdir) for any dependencies.

However, this inconsistency bothers me.  Better, I think, to add the
$(srcdir) prefix to each of these files.

I also spotted that the configure script also includes the files
../bfd/config.bfd, yet that is missing from the include list, so in
this commit I plan to add this as a dependency.

The configure script also pulls in two TCL and TK related files:

. ${TCL_BIN_DIR}/tclConfig.sh
. ${TK_BIN_DIR}/tkConfig.sh

However, I don't think ${TCL_BIN_DIR} and ${TK_BIN_DIR} are currently
visible in GDB's Makefile, so I'm not planning to add these
dependencies at this time.

In this commit I add a new variable config_status_deps which holds the
list of all the dependencies for config.status, with the $(srcdir)
prefix included, and then I use this in the config.status rule.

After this commit config.status will regenerate if config.bfd changes,
which it wouldn't before, but nothing else changes.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agogdb/Makefile: add gcore to the 'all' target dependency list
Andrew Burgess [Fri, 5 Apr 2024 08:56:32 +0000 (09:56 +0100)] 
gdb/Makefile: add gcore to the 'all' target dependency list

The gcore script is initially generated by the configure process, just
like gdb-gdb.gdb and gdb-gdb.py.  However if the gdb/gcore.in input
source is modified then 'make all' in the gdb/ directory does not
regenerate the gcore script.

This is different than the gdb-gdb.gdb and gdb-gdb.py files, if their
input is updated then 'make all' will regenerate these files.

The difference is that for gdb-gdb.* there is an explicit dependency
between the 'all' target and the generated file, this dependency is
missing for gcore.

This commit adds the dependency.  Now, if gcore.in is changed, running
'make all' will regenerate the gcore script.

There is no change in _what_ is generated after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agogdb: ignore -Wregister instead of -Wdeprecated-register
Simon Marchi [Mon, 8 Apr 2024 02:57:19 +0000 (22:57 -0400)] 
gdb: ignore -Wregister instead of -Wdeprecated-register

When building GDB on Centos 7 (which has flex 2.5.37) and Clang, I get:

    $ make ada-exp.o
      YACC   ada-exp.c
      LEX    ada-lex.c
      CXX    ada-exp.o
    In file included from /home/smarchi/src/binutils-gdb/gdb/ada-exp.y:1179:
    <stdout>:1106:2: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
     1106 |         register yy_state_type yy_current_state;
          |         ^~~~~~~~

In ada-lex.l, we already use `DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER`,
which for Clang translates to ignoring `-Wdeprecated-register` [1].  I think
that was produced when compiling as C++11, but now that we always compile as
C++17, Clang produces a `-Wregister` error [2].

For GCC, `DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER` already translates to
ignoring `-Wregister`.  So, rename
`DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER` to `DIAGNOSTIC_IGNORE_REGISTER`
and ignore `-Wregister` for Clang too.

[1] https://releases.llvm.org/17.0.1/tools/clang/docs/DiagnosticsReference.html#wdeprecated-register
[2] https://releases.llvm.org/17.0.1/tools/clang/docs/DiagnosticsReference.html#wregister

include/ChangeLog:

* diagnostics.h (DIAGNOSTIC_IGNORE_DEPRECATED_REGISTER): Rename
to...
(DIAGNOSTIC_IGNORE_REGISTER): ... this.  Ignore `-Wregister`
instead of `-Wdeprecated-register`.

Change-Id: I8a4a51c7222c68577fa22ecacdddfcba32d9dbc5

14 months agoRe: PR26978, Inconsistency for strong foo@v1 and weak foo@@v1
Alan Modra [Sun, 7 Apr 2024 22:46:20 +0000 (08:16 +0930)] 
Re: PR26978, Inconsistency for strong foo@v1 and weak foo@@v1

Commit 726d7d1ecf opened a hole that allowed a u.i.link loop to be
created, resulting in _bfd_generic_link_add_one_symbol never
returning.  Fix that.  Note that the MIND case handles two types of
redefinition.  For a new indirect symbol we'll have string non-NULL.
For a new def, string will be NULL.  So moving the string comparison
earlier would work.  However, we've already looked up inh in the first
case so can dispense with name comparisons.  Either way, for a new def
we'll get to the defweak test and possibly cycle.  Which is what we
want here.

PR 31615
PR 26978
* linker.c (_bfd_generic_link_add_one_symbol <MIND>): Test for
exactly matching indirect symbols before cycling on a defweak.

14 months agoAutomatic date update in version.in
GDB Administrator [Mon, 8 Apr 2024 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoSupport APX NF
Cui, Lili [Sun, 7 Apr 2024 09:28:25 +0000 (17:28 +0800)] 
Support APX NF

For the case when NDD and NF are both 0 in evex-promoted format,
we will fully support and test it in another patch.

gas/ChangeLog:

       * NEWS: Support Intel APX NF.
       * config/tc-i386.c (enum i386_error): Add unsupported_nf.
       (struct _i386_insn): Add has_nf.
       (is_apx_evex_encoding): Ditto.
       (build_apx_evex_prefix): Encode the NF bit.
       (md_assemble): Handle unsupported_nf.
       (parse_insn): Handle Prefix_NF and report bad for illegal combination.
       (can_convert_NDD_to_legacy): Replace i.tm.opcode_modifier.nf with i.has_nf.
       (match_template): Support D for APX_F insns and check NF support.
       * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.d: Add bad test for NF bit.
       * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.s: Ditto.
       * testsuite/gas/i386/x86-64-apx-inval.l: Ditto.
       * testsuite/gas/i386/x86-64-apx-inval.s: Ditto.
       * testsuite/gas/i386/x86-64.exp: Add apx nf tests.
       * testsuite/gas/i386/x86-64-apx-nf-intel.d: New test.
       * testsuite/gas/i386/x86-64-apx-nf.d: Ditto.
       * testsuite/gas/i386/x86-64-apx-nf.s: Ditto.

opcodes/ChangeLog:

       * i386-dis-evex.h: Add %NF to the instructions that support APX NF and
       add new instruction imul, popcnt, tzcnt and lzcnt to EVEX table.
       * i386-dis-evex-reg.h: Ditto.
       * i386-dis.c (struct instr_info): Add nf.
       (struct dis386): Add "NF" for EVEX.NF.
       (get_valid_dis386): Set ins->vex.nf and report bad-nf for illegal case.
       (print_insn): Handle ins.vex.nf.
       (putop): Handle "%NF".
       * i386-opc.h (Prefix_NF): New.
       * i386-opc.tbl: Added new entries to support full APX NF instructions.
       * i386-mnem.h: Regenerated.
       * i386-tbl.h: Regenerated.

14 months agoAutomatic date update in version.in
GDB Administrator [Sun, 7 Apr 2024 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoelf: Call bfd_malloc instead xmalloc
H.J. Lu [Sat, 6 Apr 2024 00:10:24 +0000 (17:10 -0700)] 
elf: Call bfd_malloc instead xmalloc

* elflink.c (elf_link_add_object_symbols): Call bfd_malloc
instead of xmalloc.

14 months agoRevert "x86: Restore APX shift-double instructions with omitted shift count"
H.J. Lu [Sat, 6 Apr 2024 12:02:56 +0000 (05:02 -0700)] 
Revert "x86: Restore APX shift-double instructions with omitted shift count"

This reverts commit c2d698fe03a6092d58a07de96068b87836daced0.

GCC 14 has been changed to use explicit shift count in shift-double
instructions by the commit:

06a7e7514af x86: Use explicit shift count in double-precision shifts

gas/

PR gas/31606
* testsuite/gas/i386/x86-64-apx-ndd-wig.d: Updated.
* testsuite/gas/i386/x86-64-apx-ndd.d: Likewise.
* testsuite/gas/i386/x86-64-apx-ndd.s: Remove tests for APX
shift-double instructions with omitted shift count.

opcodes/

PR gas/31606
* i386-opc.tbl: Remove APX shift-double instructions with
omitted shift count.
* i386-tbl.h: Regenerated.

14 months agoDon't have first_hash entries of strings that can be freed.
Alan Modra [Sat, 6 Apr 2024 05:19:44 +0000 (15:49 +1030)] 
Don't have first_hash entries of strings that can be freed.

Seen running "LTO 1" under valgrind.
==1443263== Invalid read of size 1
==1443263==    at 0x484CFE4: strcmp (vg_replace_strmem.c:939)
==1443263==    by 0x56E16C: bfd_hash_lookup (hash.c:564)
==1443263==    by 0x5A3C8F: elf_link_add_to_first_hash (elflink.c:4316)
==1443263==    by 0x5AE60F: elf_link_add_object_symbols (elflink.c:5663)
==1443263==    by 0x5B0672: bfd_elf_link_add_symbols (elflink.c:6333)
==1443263==    by 0x41448F: load_symbols (ldlang.c:3129)
==1443263==    by 0x4149D8: open_input_bfds (ldlang.c:3621)
==1443263==    by 0x414968: open_input_bfds (ldlang.c:3569)
==1443263==    by 0x4166A2: lang_process (ldlang.c:8162)
==1443263==    by 0x4194D5: main (ldmain.c:504)
==1443263==  Address 0x525e230 is 192 bytes inside a block of size 4,064 free'd
==1443263==    at 0x484810F: free (vg_replace_malloc.c:974)
==1443263==    by 0x8D4D87: objalloc_free_block (objalloc.c:248)
==1443263==    by 0x5AEACC: elf_link_add_object_symbols (elflink.c:5790)
==1443263==    by 0x5B0672: bfd_elf_link_add_symbols (elflink.c:6333)
==1443263==    by 0x41448F: load_symbols (ldlang.c:3129)
==1443263==    by 0x4149D8: open_input_bfds (ldlang.c:3621)
==1443263==    by 0x414968: open_input_bfds (ldlang.c:3569)
==1443263==    by 0x4166A2: lang_process (ldlang.c:8162)
==1443263==    by 0x4194D5: main (ldmain.c:504)

PR ld/31482
PR ld/31489
* elflink.c (elf_link_add_to_first_hash): Add "copy" param.
(elf_link_add_object_symbols): Flag that name must be copied
when appending version string to symbol name.

14 months agoAutomatic date update in version.in
GDB Administrator [Sat, 6 Apr 2024 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoelf: Use elf_link_first_hash_entry for first_hash
H.J. Lu [Fri, 5 Apr 2024 23:37:58 +0000 (16:37 -0700)] 
elf: Use elf_link_first_hash_entry for first_hash

Add elf_link_first_hash_entry and use it for first_hash.  Free first_hash
before freeing the main hash table.

PR ld/31482
PR ld/31489
* elf-bfd.h (elf_link_hash_table): Change first_hash to
bfd_hash_table.
* elflink.c (elf_link_first_hash_entry): New.
(elf_link_first_hash_newfunc): Likewise.
(elf_link_add_to_first_hash): Updated.
(elf_link_add_object_symbols): Initialize first_hash with
elf_link_first_hash_newfunc.
(elf_link_add_object_symbols): Updated.
(elf_link_add_archive_symbols): Likewise.
(_bfd_elf_link_hash_table_free): Free first_hash before freeing
the main hash table.

14 months agoelf: Always honor the first definition in shared object and archive
H.J. Lu [Fri, 5 Apr 2024 01:46:40 +0000 (18:46 -0700)] 
elf: Always honor the first definition in shared object and archive

GCC doesn't put builtin function symbol references, which are defined in
the shared C library, in the IR symbol table.  When linker rescans shared
objects and archives for newly added symbol references generated from the
IR inputs, it skips definitions of the builtin functions in shared
objects and archives.

Add first_hash to elf_link_hash_table to track unreferenced definitions
defined first in shared objects and archives.  Always use them to resolve
any references.

bfd/

PR ld/31482
PR ld/31489
* elf-bfd.h (elf_link_hash_table): Add first_hash.
* elflink.c (elf_link_add_to_first_hash): New function.
(elf_link_add_object_symbols): Initialize first_hash for an IR
input.  Always use the first definition in shared object.  Add
the first unreferenced dynamic definition to first_hash.
(_bfd_elf_archive_symbol_lookup): Add the first unreferenced
definition to first_hash..
(elf_link_add_archive_symbols): Use the symbol definition in
archive if symbol is defined first in this archive.
(_bfd_elf_link_hash_table_free): Also free first_hash.

ld/

PR ld/31482
PR ld/31489
* testsuite/ld-plugin/lto.exp: Add PR ld/31482 and PR ld/31489
tests.
* testsuite/ld-elf/pr31482a-no-lto.c: New file.
* testsuite/ld-elf/pr31482b-no-lto.c: Likewise.
* testsuite/ld-elf/pr31482c-no-lto.c: Likewise.
* testsuite/ld-elf/pr31482d-no-lto.c: Likewise.
* testsuite/ld-plugin/pass1.out: Likewise.
* testsuite/ld-plugin/pr31482a.c: Likewise.
* testsuite/ld-plugin/pr31482b.c: Likewise.
* testsuite/ld-plugin/pr31482c.c: Likewise.

14 months agoAdd support for Windows network paths to the UNC support in _bfd_real_open().
Zhiqing Xiong [Fri, 5 Apr 2024 08:41:40 +0000 (09:41 +0100)] 
Add support for Windows network paths to the UNC support in _bfd_real_open().

PR 31527

14 months agoAdd missing install-dvi and install-ps Makefie targets.
Christophe Lyon [Thu, 4 Apr 2024 21:48:12 +0000 (21:48 +0000)] 
Add missing install-dvi and install-ps Makefie targets.

For some reason, these targets are missing although others from the
same family are present. This looks like an oversight.

This enables calling 'make install-dvi' from the top-level build
directory.

14 months agobfd: Munmap readonly memory after bfd_free_cached_info
H.J. Lu [Fri, 5 Apr 2024 01:05:57 +0000 (18:05 -0700)] 
bfd: Munmap readonly memory after bfd_free_cached_info

Munmap readonly memory after bfd_free_cached_info which may use munmapped
readonly memory.

PR ld/31608
* opncls.c (_bfd_delete_bfd): Munmap readonly memory after
bfd_free_cached_info.

14 months agoAutomatic date update in version.in
GDB Administrator [Fri, 5 Apr 2024 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agobfd_mmap_local: Check offset and size
H.J. Lu [Thu, 4 Apr 2024 13:37:18 +0000 (06:37 -0700)] 
bfd_mmap_local: Check offset and size

Update bfd_mmap_local to return NULL if filesize < offset or filesize -
offset < rsize.

* libbfd.c (bfd_mmap_local): Validate offset and size against
the file size.

14 months agobfd: Handle bmmap failure in _bfd_mmap_read_temporary
H.J. Lu [Thu, 4 Apr 2024 13:52:27 +0000 (06:52 -0700)] 
bfd: Handle bmmap failure in _bfd_mmap_read_temporary

iovec->bmmap may return MAP_FAILED, which happens in GDB on objects with
iovec == opncls_iovec.  Update _bfd_mmap_read_temporary to handle
iovec->bmmap failure.

* libbfd.c (_bfd_mmap_read_temporary): Handle iovec->bmmap
failure.

14 months agox86: Restore APX shift-double instructions with omitted shift count
H.J. Lu [Thu, 4 Apr 2024 20:12:12 +0000 (13:12 -0700)] 
x86: Restore APX shift-double instructions with omitted shift count

Restore APX shift-double instructions with omitted shift count since
they are generated by GCC as shown in:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114590

gas/

PR gas/31606
* testsuite/gas/i386/x86-64-apx-ndd-wig.d: Updated.
* testsuite/gas/i386/x86-64-apx-ndd.d: Likewise.
* testsuite/gas/i386/x86-64-apx-ndd.s: Add tests for APX
shift-double instructions with omitted shift count.

opcodes/

PR gas/31606
* i386-opc.tbl: Restore APX shift-double instructions with
omitted shift count.
* i386-tbl.h: Regenerated.

14 months agoAdd flake8 and isort to .pre-commit-config.yaml
Tom Tromey [Tue, 2 Apr 2024 18:04:21 +0000 (12:04 -0600)] 
Add flake8 and isort to .pre-commit-config.yaml

This adds flake8 and isort to .pre-commit-config.yaml.  This way, they
will automatically be run on commit.

I chose the most recent available versions after verifying that they
don't cause any reports or changes in the current tree.

Internally at AdaCore, we also use a few flake8 plugins as well, so
perhaps that's another avenue for investigation.

v2: Also update the various file-selection clauses to pick up
gdb-gdb.py.in; include the isort change made to this file; and finally
add a comment about the exclusions from flake8.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoFix a test failure in gdb.threads/stepi-over-clone.exp
Bernd Edlinger [Mon, 1 Apr 2024 19:22:46 +0000 (21:22 +0200)] 
Fix a test failure in gdb.threads/stepi-over-clone.exp

When the XML support was disabled at compile time,
the test case gdb.threads/stepi-over-clone.exp fails
with lots of time-outs, which can be annoying.
This makes the test case unsupported instead.

Approved-By: Tom Tromey <tom@tromey.com>
14 months agoMIPS HI16 and LO16 reloc howtos
Alan Modra [Fri, 1 Mar 2024 21:40:34 +0000 (08:10 +1030)] 
MIPS HI16 and LO16 reloc howtos

All the HI16 reloc howtos should have a rightshift of 16, and all the
LO16 relocs shouldn't complain on overflow.  This was correct for
R_MIPS_LO16 and R_MIPS_LO16 (at least on the howto_table_rel entries),
and corresponding MIPS16, MICROMIPS and MIPS64 relocs, but not on many
other HI16 and LO16 relocs.

While we're at it, fix the HIGHER and HIGHEST rightshift too.

These changes are necessary to support addends outside the range
[0,32767] when those addends are stored in section contents.  Note
that some of the reloc howtos changed here will always have zero
addends (GOT_HI16, CALL_HI16).  Those don't really need changing, but
use what is clearly correct for hi16 relocs anyway.

PR 19977
* elf32-mips.c: Correct rightshift for HI16, HIGHER and HIGHEST
reloc howtos.  Correct complain_on_overflow for LO16 relocs.
* elf64-mips.c: Likewise.
* elfn32-mips.c: Likewise.

14 months agoRe: Update objcopy's --section-alignment option
Alan Modra [Thu, 4 Apr 2024 10:18:14 +0000 (20:48 +1030)] 
Re: Update objcopy's --section-alignment option

ubsan: left shift of 1 by 31 places cannot be represented in type 'int'

* objcopy.c (setup_section): Avoid undefined behaviour when
checking vma and lma for alignment.

14 months agodlltool: replace unchecked malloc with xmalloc
Nandakumar Edamana [Thu, 4 Apr 2024 05:26:14 +0000 (10:56 +0530)] 
dlltool: replace unchecked malloc with xmalloc

14 months agoMemory corruption with USE_MMAP
Alan Modra [Thu, 4 Apr 2024 04:09:14 +0000 (14:39 +1030)] 
Memory corruption with USE_MMAP

mips64-linux-gnuabi64  +FAIL: GOT page 4 (two files)
mipsel-linux-gnu  +FAIL: GOT page 4 (two files)
mipsisa32el-linux-gnu  +FAIL: GOT page 4 (two files)
mips-linux-gnu  +FAIL: GOT page 4 (two files)
powerpc64-freebsd  +FAIL: relocatable relaxing large
powerpc64le-linux-gnu  +FAIL: relocatable relaxing large
powerpc64-linux-gnu  +FAIL: relocatable relaxing large
powerpc-eabisim  +FAIL: relocatable relaxing large
powerpc-eabivle  +FAIL: relocatable relaxing large
powerpc-freebsd  +FAIL: relocatable relaxing large
powerpcle-elf  +FAIL: relocatable relaxing large
powerpc-linux-gnu  +FAIL: relocatable relaxing large

* elflink.c (bfd_elf_final_link): Heed bed->use_mmap when
sizing buffers, not just USE_MMAP.

14 months agoRe: USE_MMAP fuzzed object file attacks
Alan Modra [Thu, 4 Apr 2024 02:20:17 +0000 (12:50 +1030)] 
Re: USE_MMAP fuzzed object file attacks

I committed a broken patch.

* aoutx.h (aout_get_external_symbols): Remove wrong #else and
unneeded casts.
* pdp11.c (aout_get_external_symbols): Likewise.

14 months agoFix uninitialised variable errors
Alan Modra [Thu, 4 Apr 2024 00:53:32 +0000 (11:23 +1030)] 
Fix uninitialised variable errors

Commit c6291d749aec introduced a number of errors, found by clang.

elf.c:456:7: error: variable 'alloc_ext_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
  if (_bfd_mul_overflow (symcount, extsym_size, &amt))
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elf.c:464:7: error: variable 'alloc_extshndx_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
  if (bfd_seek (ibfd, pos, SEEK_SET) != 0
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elflink.c:2837:11: error: variable 'alloc1_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
      if (internal_relocs == NULL)
          ^~~~~~~~~~~~~~~~~~~~~~~
elflink.c:12595:16: error: variable 'ext_size' set but not used [-Werror,-Wunused-but-set-variable]
                      size_t ext_size = 0;

* elf.c (bfd_elf_get_elf_syms): Fix use of uninitialised variables.
* elflink.c (_bfd_elf_link_info_read_relocs): Likewise.
(bfd_elf_final_link): Fix set but not used warning.

14 months agoUSE_MMAP fuzzed object file attacks
Alan Modra [Wed, 3 Apr 2024 21:21:47 +0000 (07:51 +1030)] 
USE_MMAP fuzzed object file attacks

If mmap is used without sanity checking, then we'll get a SIGBUS if
an access is done to the mmap'd memory corresponding to a page past
end of file.

* aoutx.h (aout_get_external_symbols): Check that mmap regions
are within file contents.  Catch stringsize overflow.
(some_aout_object_p): Don't clear already zeroed fields.  Tidy.
* pdp11.c: As for aoutx.h.  Copy some fixes too.

14 months agoAutomatic date update in version.in
GDB Administrator [Thu, 4 Apr 2024 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

14 months agoelf: Add _bfd_elf_link_m[un]map_section_contents
H.J. Lu [Mon, 11 Mar 2024 16:51:06 +0000 (09:51 -0700)] 
elf: Add _bfd_elf_link_m[un]map_section_contents

To copy input section contents, add _bfd_elf_link_mmap_section_contents
and _bfd_elf_link_munmap_section_contents to mmap in the input sections.

* elf-bfd.h (_bfd_elf_link_mmap_section_contents): New.
(_bfd_elf_link_munmap_section_contents): Likewise.
* elf.c (elf_mmap_section_contents): New.
(_bfd_elf_mmap_section_contents): Use it.
(_bfd_elf_link_mmap_section_contents): New.
(_bfd_elf_link_munmap_section_contents): Likewise.
* elflink.c (elf_link_input_bfd): Call
_bfd_elf_link_mmap_section_contents instead of
bfd_get_full_section_contents.  Call
_bfd_elf_link_munmap_section_contents to munmap the section
contents.
(bfd_elf_final_link): When mmap is used, initialize
max_contents_size to _bfd_minimum_mmap_size and increase it
for compressed or linker created sections or sections whose
rawsize != size.

14 months agoelf: Always keep symbol table and relocation info for eh_frame
H.J. Lu [Sat, 9 Mar 2024 00:21:42 +0000 (16:21 -0800)] 
elf: Always keep symbol table and relocation info for eh_frame

When --no-keep-memory is used, the symbol table and relocation info for
eh_frame are freed after they are retrieved for each text section in the
input object.  If an input object has many text sections, the same data
is retrieved and freed many times which can take a very long time.
Update _bfd_elf_gc_mark to keep the symbol table and relocation info for
eh_frame to avoid it.  Data to link the 3.5GB clang executable in LLVM
17 debug build on Linux/x86-64 with 32GB RAM is:

before after improvement
user 86.31 86.44 -0.2%
system 8.77 8.63 1.6%
total 95.58 96.81 -1.3%
maximum set(GB) 13.1 13.1 0%
page faults 3024752 3028699 -1.3%

and data to link the 275M cc1plus executable in GCC 14 stage 1 build is:

user 5.49 5.46 -0.5%
system 0.73 0.73 0%
total 6.26 6.25 0.3%
maximum set(MB) 964 964 0%
page faults 235173 235796 -0.3%

The memory usage impact is minimum and the link time of the Rust binary
in

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

is reduced from 500+ seconds to 1.44 seconds, a 300x speedup.

PR ld/31466
* elflink.c (init_reloc_cookie): Add a bool argument, keep_memory,
for keeping memory.  Always keep memory if keep_memory is true.
(init_reloc_cookie_rels): Likewise
(init_reloc_cookie_for_section): Add a bool argument for keeping
memory and pass it to init_reloc_cookie and
init_reloc_cookie_rels.
(_bfd_elf_gc_mark_reloc): Pass false to _bfd_elf_gc_mark.
(_bfd_elf_gc_mark): Pass true to init_reloc_cookie_for_section
for the eh_frame section.  Pass false to
init_reloc_cookie_for_section for other sections.
(_bfd_elf_gc_mark_extra_sections): Add Add a bool argument for
keeping memory and pass it to _bfd_elf_gc_mark.
(bfd_elf_parse_eh_frame_entries): Pass false to init_reloc_cookie
and init_reloc_cookie_rels.
(bfd_elf_gc_sections): Pass false to init_reloc_cookie_for_section
and _bfd_elf_gc_mark.
(bfd_elf_discard_info): Pass false to
init_reloc_cookie_for_section and init_reloc_cookie.

14 months agoelf: Don't cache symbol nor relocation tables with mmap
H.J. Lu [Wed, 28 Feb 2024 22:34:33 +0000 (14:34 -0800)] 
elf: Don't cache symbol nor relocation tables with mmap

During a "-j 8" LLVM 17 debug build on a machine with 32GB RAM and 16GB
swap, ld was killed by kernel because of out of memory:

[79437.949336] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/session-9.scope,task=ld,pid=797431,uid=1000
[79437.949349] Out of memory: Killed process 797431 (ld) total-vm:9219600kB, anon-rss:6558156kB, file-rss:1792kB, shmem-rss:0kB, UID:1000 pgtables:17552kB oom_score_adj:0

Don't cache symbol nor relocation tables if they are mapped in.  Data to
link the 3.5GB clang executable in LLVM 17 debug build on Linux/x86-64
with 32GB RAM is:

stdio mmap improvement
user 86.73 87.02 -0.3%
system 9.55 9.21 3.6%
total 100.40 97.66 0.7%
maximum set(GB) 17.34 13.14 24%
page faults 4047667 3042877 25%

and data to link the 275M cc1plus executable in GCC 14 stage 1 build is:

user 5.41 5.44 -0.5%
system 0.80 0.76 5%
total 6.25 6.26 -0.2%
maximum set(MB) 1323 968 27%
page faults 323451 236371 27%

These improve the overall system performance for parallel build by
reducing memory usage and page faults.

Also rename _bfd_link_keep_memory to _bfd_elf_link_keep_memory.  Since
the --no-keep-memory linker option causes:

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

this is opt-in by each backend.

bfd/

* elf32-i386.c (elf_i386_scan_relocs): Remove
_bfd_link_keep_memory.
* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
* elflink.c (_bfd_elf_link_keep_memory): New.
(_bfd_elf_link_iterate_on_relocs): Replace _bfd_link_keep_memory
with _bfd_elf_link_keep_memory.
(elf_link_add_object_symbols): Likewise.
(init_reloc_cookie): Likewise.
(init_reloc_cookie_rels): Likewise.
* libbfd-in.h (_bfd_link_keep_memory): Removed.
* linker.c (_bfd_link_keep_memory): Likewise.
* libbfd.h: Regenerated.

14 months agoelf: Use mmap to map in symbol and relocation tables
H.J. Lu [Sun, 3 Mar 2024 16:44:01 +0000 (08:44 -0800)] 
elf: Use mmap to map in symbol and relocation tables

Add _bfd_mmap_read_temporary to mmap in symbol tables and relocations
whose sizes >= 4 * page size.  For the final link, allocate an external
relocation buffer of 4 * page size to avoid using mmap and munmap on
smaller relocation sections.  Since _bfd_mmap_read_temporary allocates
buffer as needed, its callers don't need to.

When mmap is used to map in all ELF sections, data to link the 3.5GB
clang executable in LLVM 17 debug build on Linux/x86-64 with 32GB RAM
is:

stdio mmap improvement
user 84.79 85.27 -0.5%
system 10.95 9.09 17%
total 97.91 94.90 3%
page faults 4837944 4033778 17%

and data to link the 275M cc1plus executable in GCC 14 stage 1 build
is:

user 5.31 5.33 -0.4%
system 0.86 0.76 12%
total 6.19 6.13 1%
page faults 361273 322491 11%

* elf.c (bfd_elf_get_elf_syms): Don't allocate buffer for external
symbol table.  Replace bfd_read with _bfd_mmap_read_temporary.
* elflink.c (elf_link_read_relocs_from_section): Add 2 arguments
to return mmap memory address and size.
(_bfd_elf_link_info_read_relocs): Don't allocate buffer for
external relocation information.  Replace bfd_read with
_bfd_mmap_read_temporary.
(bfd_elf_final_link): Cache external relocations up to
_bfd_minimum_mmap_size bytes when mmap is used.
* libbfd.c (_bfd_mmap_read_temporary): New.
* libbfd-in.h (_bfd_mmap_read_temporary): Likewise.
* libbfd.h: Regenerated.

14 months agoelf: Add _bfd_elf_m[un]map_section_contents
H.J. Lu [Fri, 1 Mar 2024 14:14:20 +0000 (06:14 -0800)] 
elf: Add _bfd_elf_m[un]map_section_contents

Add _bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents.
A backend must opt-in to use mmap.  It should replace

bfd_malloc_and_get_section -> _bfd_elf_mmap_section_contents
free    -> _bfd_elf_munmap_section_contents

on section contents.

* compress.c (bfd_get_full_section_contents): Don't allocate
buffer if mmapped_p is true.
* elf-bfd.h (elf_backend_data): Add use_mmap.
(bfd_elf_section_data): Add contents_addr and contents_size.
(_bfd_elf_mmap_section_contents): New.
(_bfd_elf_munmap_section_contents): Likewise.
* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Replace
bfd_malloc_and_get_section and free with
_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
on section contents.
* elf-sframe.c (_bfd_elf_parse_sframe): Likewise.
* elf.c (_bfd_elf_make_section_from_shdr): Replace
bfd_malloc_and_get_section and free with
_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
on section contents.
(_bfd_elf_print_private_bfd_data): Likewise.
(_bfd_elf_mmap_section_contents): New.
(_bfd_elf_munmap_section_contents): Likewise.
* elf32-i386.c (elf_i386_scan_relocs): Replace
bfd_malloc_and_get_section and free with
_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
on section contents.
* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
(elf_x86_64_get_synthetic_symtab): Likewise.
* elfcode.h (elf_checksum_contents): Likewise.
* elflink.c (elf_link_add_object_symbols): Likewise.
(bfd_elf_get_bfd_needed_list): Likewise.
* elfxx-target.h (elf_backend_use_mmap): New.
(elfNN_bed): Add elf_backend_use_mmap.
* elfxx-x86.c (elf_x86_size_or_finish_relative_reloc): Replace
bfd_malloc_and_get_section and free with
_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
on section contents.
(_bfd_x86_elf_get_synthetic_symtab): Replace free with
_bfd_elf_munmap_section_contents.
* elfxx-x86.h (elf_backend_use_mmap): New.
* libbfd.c: Include "elf-bfd.h".
(_bfd_generic_get_section_contents): Call bfd_mmap_local for
mmapped_p.
* opncls.c (_bfd_delete_bfd): Also munmap ELF section contents.
* section.c (asection): Add mmapped_p.
(BFD_FAKE_SECTION): Updated.
(bfd_malloc_and_get_section): Add a sanity check for not
mmapped_p.
* bfd-in2.h: Regenerated.

14 months agoelf: Use mmap to map in read-only sections
H.J. Lu [Thu, 29 Feb 2024 19:17:01 +0000 (11:17 -0800)] 
elf: Use mmap to map in read-only sections

There are many linker input files in LLVM debug build with huge string
sections.  All these string sections can be treated as read-only.  But
linker copies all of them into memory which consumes huge amount of
memory and slows down linker significantly.

Add _bfd_mmap_readonly_persistent and _bfd_mmap_readonly_temporary to
mmap in reado-only sections with size >= 4 * page size.

NB: All string sections in valid ELF inputs must be null terminated.
There is no need to terminate it again and string sections are mmapped
as read-only.

* bfd.c (bfd_mmapped_entry): New.
(bfd_mmapped): Likewise.
(bfd): Add mmapped.
* bfdwin.c (bfd_get_file_window): Use _bfd_pagesize.
* cache.c (cache_bmmap): Remove pagesize_m1 and use pagesize_m1
instead.
* elf.c (bfd_elf_get_str_section): Call
_bfd_mmap_readonly_persistent instead of _bfd_alloc_and_read.
Don't terminate the string section again.
(get_hash_table_data): Call _bfd_mmap_readonly_temporary and
_bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
and free.
(_bfd_elf_get_dynamic_symbols): Call _bfd_mmap_readonly_persistent
instead of _bfd_alloc_and_read.  Don't terminate the string
section again.  Call _bfd_mmap_readonly_temporary and
_bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
and free.
(_bfd_elf_slurp_version_tables): Call _bfd_mmap_readonly_temporary
and _bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
and free.
* elflink.c (bfd_elf_link_record_dynamic_symbol): Use bfd_malloc
to get the unversioned symbol.
* libbfd-in.h (_bfd_pagesize): New.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
(_bfd_mmap_readonly_persistent): Likewise.
(_bfd_mmap_readonly_temporary): Likewise.
(_bfd_munmap_readonly_temporary): Likewise.
* libbfd.c
(bfd_allocate_mmapped_page): New.
(_bfd_mmap_readonly_temporary): Likewise.
(_bfd_munmap_readonly_temporary): Likewise.
(_bfd_mmap_readonly_persistent): Likewise.
(_bfd_pagesize): Likewise.
(_bfd_pagesize_m1): Likewise.
(_bfd_minimum_mmap_size): Likewise.
(bfd_init_pagesize): Likewise.
* lynx-core.c (lynx_core_file_p): Use _bfd_pagesize.
* opncls.c (_bfd_delete_bfd): Munmap tracked mmapped memories.
* sysdep.h (MAP_ANONYMOUS): New. Define if undefined.
* bfd-in2.h: Regenerated.
* libbfd.h: Likewise.

14 months agoRevert "gdb/compile: Use std::filesystem::remove_all in cleanup"
Lancelot SIX [Wed, 3 Apr 2024 14:39:10 +0000 (15:39 +0100)] 
Revert "gdb/compile: Use std::filesystem::remove_all in cleanup"

This reverts commit 7bba0ad08576309763e3f41193eaa93025e10b8b.

Tom de Vries reported that 7bba0ad0857 (gdb/compile: Use
std::filesystem::remove_all in cleanup) broke builds with gcc-7.5.0
which mostly supports c++17, but not std::filesystem[1].  As this change
is not critical, revert it to maintain compatibility.

[1] https://inbox.sourceware.org/gdb-patches/a06e6483-aa2e-4b8a-854f-e369a1e961ea@suse.de/

Change-Id: I58150bd27600c95052bdf1bbbd6b44718a5a0bbf
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31420
Approved-By: Tom Tromey <tom@tromey.com>
14 months agodoc: add the missing 'handle' attribute in xml
Tankut Baris Aktemur [Wed, 3 Apr 2024 14:43:53 +0000 (16:43 +0200)] 
doc: add the missing 'handle' attribute in xml

The XML response to the "qXfer:threads:read" packet may include
a "handle" attribute.  The attribute is mentioned in the document
but not shown in the sample XML structure.  Add it.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
14 months agogdb/compile: Use std::filesystem::remove_all in cleanup
Lancelot SIX [Sun, 3 Mar 2024 16:47:56 +0000 (16:47 +0000)] 
gdb/compile: Use std::filesystem::remove_all in cleanup

In a previous review, I noticed that some code in gdb/compile/compile.c
could use c++17's `std::filesystem::remove_all` instead of using some
`system ("rm -rf ...");`.

This patch implements this.

Note that I use the noexcept overload of std::filesystem::remove_all and
explicitly check for an error code.  This means that this code called
during the cleanup procedure cannot throw, and does not risk preventing
other cleanup functions to be called.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31420
Change-Id: If5668bf3e15e66c020e5c3b4fa999f861690e4cf
Approved-By: Tom Tromey <tom@tromey.com>
14 months agogdb: ensure has dwarf info before reading DWZ file
Lancelot SIX [Sat, 30 Mar 2024 11:01:21 +0000 (11:01 +0000)] 
gdb: ensure has dwarf info before reading DWZ file

I recent change (e9b738dfbdc "Avoid race when reading dwz file") moved
the call to dwarf2_read_dwz_file from dwarf2_initialize_objfile to
dwarf2_has_info.

Before that patch, dwarf2_initialize_objfile was only called when
dwarf2_has_info returned true, and since that patch it is always called.

When reading a file that has no debug info (.debug_info/.debug_abbrev
sections), but has a .gnu_debugaltlink section, GDB’s behavior is
different.  I can observe this when loading
/lib/x86_64-linux-gnu/libtinfo.so on Ubuntu 22.04 (or while debugging
any program dynamically loading this library).

Before e9b738dfbdc, we had:

    $ ./gdb/gdb -data-directory ./gdb/data-directory -q  /lib/x86_64-linux-gnu/libtinfo.so
    Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so...
    (No debugging symbols found in /lib/x86_64-linux-gnu/libtinfo.so)
    (gdb)

while after we have:

    $ ./gdb/gdb -data-directory ./gdb/data-directory -q  /lib/x86_64-linux-gnu/libtinfo.so
    Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so...

    warning: could not find '.gnu_debugaltlink' file for /usr/lib/x86_64-linux-gnu/libtinfo.so.6.3
    (No debugging symbols found in /lib/x86_64-linux-gnu/libtinfo.so)
    (gdb)

This patch restores the previous behavior of only trying to load the
DWZ file for objfiles when the main part of the debuginfo is present
(i.e. when dwarf2_has_info returns true).  We still make sure that
dwarf2_read_dwz_file is called at most once per objfile.

A consequence of this change is that the per_bfd->dwz_file optional
object can now remain empty (instead of containing a nullptr), so also
this patch also adjusts dwarf2_get_dwz_file to account for this
possibility.  This effectively reverts the changes to
dwarf2_get_dwz_file done by e9b738dfbdc.

Regression tested on x86_64-linux-gnu Ubuntu 22.04.

Approved-By: Tom Tromey <tom@tromey.com>
14 months agoFix null pointer dereference in process_debug_info()
Nick Clifton [Wed, 3 Apr 2024 10:19:33 +0000 (11:19 +0100)] 
Fix null pointer dereference in process_debug_info()

14 months agoExtend objdump's --show-all-symbols option so that it also shows the extra symbols...
Nick Clifton [Wed, 3 Apr 2024 10:16:23 +0000 (11:16 +0100)] 
Extend objdump's --show-all-symbols option so that it also shows the extra symbols referenced by an instruction.

14 months agoArm64: check tied operand specifier in aarch64-gen
Jan Beulich [Wed, 3 Apr 2024 08:42:44 +0000 (10:42 +0200)] 
Arm64: check tied operand specifier in aarch64-gen

Make sure that field actually matches the specified operands. Don't
follow existing F_PSEUDO checking in using assertions, though. Print
meaningful error messages, thus - while not having a line number
available - at least providing some indication of where things are
wrong.

Fix SVE2.1's extq accordingly, but don't extend the testsuite there:
There are further issues with its operands (SVE_Zm_imm4 doesn't look to
be correct to use there, as that describes an indexed vector register,
while here a separate vector register and immediate operand are to be
specified).

14 months agox86: add missing No_qSuf to non-64-bit PTWRITE
Jan Beulich [Wed, 3 Apr 2024 08:41:30 +0000 (10:41 +0200)] 
x86: add missing No_qSuf to non-64-bit PTWRITE

While largely benign, it still should have been put there when the
original single template was split (commit a04973848dc5).

14 months agox86: drop stray Size64 from WRSSQ
Jan Beulich [Wed, 3 Apr 2024 08:40:57 +0000 (10:40 +0200)] 
x86: drop stray Size64 from WRSSQ

Like for WRUSSQ it's not needed here. The legacy insn had gained it in
the course of zapping Rex64, but that attribute wasn't needed here
either. The APX insn then simply gained it by copy-and-paste, I suppose.

14 months agox86/APX: Remove KEYLOCKER and SHA promotions from EVEX MAP4
Cui, Lili [Tue, 2 Apr 2024 06:40:18 +0000 (14:40 +0800)] 
x86/APX: Remove KEYLOCKER and SHA promotions from EVEX MAP4

APX spec removed KEYLOCKER and SHA promotions from EVEX MAP4.
https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-performance-extensions-apx.html

gas/ChangeLog:

        * NEWS: Mention that remove KEYLOCKER and SHA promotions from EVEX
* MAP4.
        * config/tc-i386.c (process_operands): Removed special handling of
* KEYLOCKER and SHA.
        * testsuite/gas/i386/x86-64-apx-egpr-promote-inval.l: Removed KEYLOCKER
        * and SHA instructions.
        * testsuite/gas/i386/x86-64-apx-egpr-promote-inval.s: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.s: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-intel.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-wig.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted.s: Ditto.

opcodes/ChangeLog:

        * i386-dis-evex-prefix.h: Removed KEYLOCKER and SHA instructions.
        * i386-dis-evex.h: Ditto.
        * i386-opc.tbl: Ditto.
        * i386-dis.c (print_vector_reg): Removed special handling of KEYLOCKER
*  and SHA.

14 months agoAutomatic date update in version.in
GDB Administrator [Wed, 3 Apr 2024 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in