Commit Graph

118468 Commits

Author SHA1 Message Date
Alexandra Hájková
3623271997 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>
2024-04-08 13:39:51 +02:00
Andrew Burgess
36192c2be1 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.
2024-04-08 10:56:51 +01:00
Andrew Burgess
76bbe1f597 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>
2024-04-08 10:25:42 +01:00
Andrew Burgess
ff69d6e9af 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>
2024-04-08 10:25:41 +01:00
Andrew Burgess
b6a12c1451 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>
2024-04-08 10:25:40 +01:00
Andrew Burgess
cb1bef582e 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>
2024-04-08 10:25:39 +01:00
Andrew Burgess
766f411f08 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>
2024-04-08 10:25:38 +01:00
Andrew Burgess
cc7ae3ac7e 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>
2024-04-08 10:25:37 +01:00
Simon Marchi
ecc3c38667 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
2024-04-07 22:57:39 -04:00
Alan Modra
248b6326a4 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.
2024-04-08 11:27:42 +09:30
GDB Administrator
261d6a6776 Automatic date update in version.in 2024-04-08 00:00:09 +00:00
Cui, Lili
dd74a60337 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.
2024-04-07 17:28:25 +08:00
GDB Administrator
bc0d0a5596 Automatic date update in version.in 2024-04-07 00:00:10 +00:00
H.J. Lu
c411ee9883 elf: Call bfd_malloc instead xmalloc
* elflink.c (elf_link_add_object_symbols): Call bfd_malloc
	instead of xmalloc.
2024-04-06 05:07:33 -07:00
H.J. Lu
cca46dea4d Revert "x86: Restore APX shift-double instructions with omitted shift count"
This reverts commit c2d698fe03.

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.
2024-04-06 05:07:18 -07:00
Alan Modra
e7e05a9dd0 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.
2024-04-06 16:35:35 +10:30
GDB Administrator
82475fa2fa Automatic date update in version.in 2024-04-06 00:00:09 +00:00
H.J. Lu
816fd3dced 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.
2024-04-05 16:49:09 -07:00
H.J. Lu
c0419c024b 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.
2024-04-05 05:02:38 -07:00
Zhiqing Xiong
eac88f3298 Add support for Windows network paths to the UNC support in _bfd_real_open().
PR 31527
2024-04-05 09:41:40 +01:00
Christophe Lyon
54e2d897a6 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.
2024-04-05 07:02:56 +00:00
H.J. Lu
37eac4810b 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.
2024-04-04 18:52:58 -07:00
GDB Administrator
c069de3491 Automatic date update in version.in 2024-04-05 00:00:11 +00:00
H.J. Lu
0ffdc37b98 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.
2024-04-04 15:35:48 -07:00
H.J. Lu
360d244b24 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.
2024-04-04 15:35:31 -07:00
H.J. Lu
c2d698fe03 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.
2024-04-04 13:16:20 -07:00
Tom Tromey
16810e455f 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>
2024-04-04 06:43:39 -06:00
Bernd Edlinger
b0ca740e8f 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>
2024-04-04 14:26:19 +02:00
Alan Modra
f38e992147 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.
2024-04-04 21:02:40 +10:30
Alan Modra
fab240554b 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.
2024-04-04 21:02:29 +10:30
Nandakumar Edamana
1bc2544b89 dlltool: replace unchecked malloc with xmalloc 2024-04-04 17:58:50 +10:30
Alan Modra
b43b352837 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.
2024-04-04 14:43:49 +10:30
Alan Modra
0ab0435fe6 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.
2024-04-04 13:19:42 +10:30
Alan Modra
9fd82d9142 Fix uninitialised variable errors
Commit c6291d749a 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.
2024-04-04 11:33:13 +10:30
Alan Modra
b86d3af60f 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.
2024-04-04 10:30:47 +10:30
GDB Administrator
7e217ee2c0 Automatic date update in version.in 2024-04-04 00:00:08 +00:00
H.J. Lu
a9505c7420 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.
2024-04-03 09:11:03 -07:00
H.J. Lu
3428c771ae 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.
2024-04-03 09:11:03 -07:00
H.J. Lu
d41b764855 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.
2024-04-03 09:11:03 -07:00
H.J. Lu
c6291d749a 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.
2024-04-03 09:11:03 -07:00
H.J. Lu
584b30e4b3 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.
2024-04-03 09:11:03 -07:00
H.J. Lu
9ba56acee5 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.
2024-04-03 09:11:00 -07:00
Lancelot SIX
f89ae595dd Revert "gdb/compile: Use std::filesystem::remove_all in cleanup"
This reverts commit 7bba0ad085.

Tom de Vries reported that 7bba0ad085 (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>
2024-04-03 16:30:48 +01:00
Tankut Baris Aktemur
3d7d77d747 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>
2024-04-03 16:44:43 +02:00
Lancelot SIX
7bba0ad085 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>
2024-04-03 13:53:32 +01:00
Lancelot SIX
e73b04d265 gdb: ensure has dwarf info before reading DWZ file
I recent change (e9b738dfbd "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 e9b738dfbd, 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 e9b738dfbd.

Regression tested on x86_64-linux-gnu Ubuntu 22.04.

Approved-By: Tom Tromey <tom@tromey.com>
2024-04-03 13:47:03 +01:00
Nick Clifton
301bfc45ab Fix null pointer dereference in process_debug_info() 2024-04-03 11:19:33 +01:00
Nick Clifton
28b24770bb Extend objdump's --show-all-symbols option so that it also shows the extra symbols referenced by an instruction. 2024-04-03 11:17:19 +01:00
Jan Beulich
b1c4af2086 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).
2024-04-03 10:42:44 +02:00
Jan Beulich
ef9a6314d8 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 a04973848d).
2024-04-03 10:41:30 +02:00