]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
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

14 months agolibiberty: Invoke D demangler when --format=auto
Tom Tromey [Sat, 30 Mar 2024 19:48:30 +0000 (13:48 -0600)] 
libiberty: Invoke D demangler when --format=auto

Investigating GDB PR d/31580 showed that the libiberty demangler
doesn't automatically demangle D mangled names.  However, I think it
should -- like C++ and Rust (new-style), D mangled names are readily
distinguished by the leading "_D", and so the likelihood of confusion
is low.  The other non-"auto" cases in this code are Ada (where the
encoded form could more easily be confused by ordinary programs) and
Java (which is long gone, but which also shared the C++ mangling and
thus was just an output style preference).

This patch also fixed another GDB bug, though of course that part
won't apply to the GCC repository.

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

libiberty
* cplus-dem.c (cplus_demangle): Try the D demangler with
"auto" format.
* testsuite/d-demangle-expected: Add --format=auto test.

14 months agoPrint type name when printing Rust slice
Tom Tromey [Thu, 7 Mar 2024 19:57:07 +0000 (12:57 -0700)] 
Print type name when printing Rust slice

The recent change to how unsized Rust values are printed included a
small regression from past behavior.  Previously, a slice's type would
be printed, like:

    (gdb) print slice
    $80 = &[i32] [3]

The patch changed this to just

    (gdb) print slice
    $80 = [3]

This patch restores the previous behavior.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30330
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31517

14 months agoConstify ada-lex.l:attributes
Tom Tromey [Thu, 14 Mar 2024 18:25:42 +0000 (12:25 -0600)] 
Constify ada-lex.l:attributes

While examining the Ada parser globals with 'nm', I noticed that the
lexer's "attributes" array should be const.  This change moves it into
read-only storage.

14 months agoRemove "numbuf" global
Tom Tromey [Thu, 14 Mar 2024 18:28:26 +0000 (12:28 -0600)] 
Remove "numbuf" global

The lexer has a "numbuf" global that is only used for temporary
storage.  This patch removes the global and redeclares it at the
points of use.

14 months agoMove "returned_complete" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:30:28 +0000 (12:30 -0600)] 
Move "returned_complete" into ada_parse_state

This moves the "returned_complete" global into ada_parse_state.

14 months agoMove "paren_depth" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:29:40 +0000 (12:29 -0600)] 
Move "paren_depth" into ada_parse_state

This moves the "paren_depth" global into ada_parse_state.

14 months agoMove "temp_parse_space" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:22:04 +0000 (12:22 -0600)] 
Move "temp_parse_space" into ada_parse_state

This patch moves the "temp_parse_space" global into ada_parse_state.
It is also renamed to remove the redundant "parse".  Finally, it is
changed to an auto_obstack to avoid the need for any manual
management.

14 months agoMove "iterated_associations" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:19:22 +0000 (12:19 -0600)] 
Move "iterated_associations" into ada_parse_state

This patch moves the "iterated_associations" global into
ada_parse_state.

14 months agoMove "assignments" global into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:17:30 +0000 (12:17 -0600)] 
Move "assignments" global into ada_parse_state

This patch moves the "assignments" global into ada_parse_state.

14 months agoMove "components" and "associations" into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:16:43 +0000 (12:16 -0600)] 
Move "components" and "associations" into ada_parse_state

This patch moves the "components" and "associations" globals into
ada_parse_state.

14 months agoMove "int_storage" global into ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:13:30 +0000 (12:13 -0600)] 
Move "int_storage" global into ada_parse_state

This patch moves the "int_storage" global into ada_parse_state.

14 months agoIntroduce ada_parse_state
Tom Tromey [Thu, 14 Mar 2024 18:09:55 +0000 (12:09 -0600)] 
Introduce ada_parse_state

This patch introduces the ada_parse_state class and the ada_parser
global.  It also changes find_completion_bounds to be a method of this
new type.

Note that find_completion_bounds never used its parameter; and because
it is generally fine to use the 'pstate' global throughout the parser,
this patch removes the parameter entirely.

14 months agoImplement Ada 2022 iterated assignment
Tom Tromey [Tue, 5 Mar 2024 14:59:55 +0000 (07:59 -0700)] 
Implement Ada 2022 iterated assignment

Ada 2022 includes iterated assignment for array initialization.  This
patch implements a subset of this for gdb.  In particular, only arrays
with integer index types really work -- currently there's no decent
way to get the index type in EVAL_AVOID_SIDE_EFFECTS mode during
parsing.  Fixing this probably requires the Ada parser to take a
somewhat more sophisticated approach to type resolution; and while
this would help fix another bug in this area, this patch is already
useful without it.

14 months agoIntroduce and use aggregate_assigner type
Tom Tromey [Tue, 5 Mar 2024 14:25:08 +0000 (07:25 -0700)] 
Introduce and use aggregate_assigner type

This patch is a refactoring to add a new aggregate_assigner type.
This type is passed to Ada aggregate assignment operations in place of
passing a number of separate arguments.  This new approach makes it
simpler to change some aspects of aggregate assignment behavior.

14 months agoRun isort
Tom Tromey [Wed, 20 Mar 2024 15:03:04 +0000 (09:03 -0600)] 
Run isort

This patch is the result of running 'isort .' in the gdb directory.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoPrepare gdb for isort
Tom Tromey [Wed, 20 Mar 2024 15:36:40 +0000 (09:36 -0600)] 
Prepare gdb for isort

This patch prepares gdb for isort: it adds a couple of isort marker
comments where needed, and it adds an isort clause to setup.cfg.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoDo not use bare "except"
Tom Tromey [Tue, 19 Mar 2024 17:11:05 +0000 (11:11 -0600)] 
Do not use bare "except"

flake8 warns about a bare "except".  The docs point out that this will
also catch KeyboardInterrupt and SystemExit exceptions, which is
normally undesirable.  Using "except Exception" catches everything
reasonable, so this patch makes this change.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoSuppress some "undefined" warnings from flake8
Tom Tromey [Tue, 19 Mar 2024 17:08:34 +0000 (11:08 -0600)] 
Suppress some "undefined" warnings from flake8

flake8 warns about some identifiers in __init__.py, because it does
not realize these come from the star-imported _gdb module.  This patch
suppresses these warnings.

14 months agoSpecify ImportError in styling.py
Tom Tromey [Tue, 19 Mar 2024 16:56:34 +0000 (10:56 -0600)] 
Specify ImportError in styling.py

styling.py has a long try/except surrounding most of the body.  flake8
warns about the final bare "except".  However, this except is really
only there to catch the situation where the host doesn't have Pygments
installed.  This patch changes this to only catch ImportError.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoSuppress star import errors
Tom Tromey [Tue, 19 Mar 2024 16:55:30 +0000 (10:55 -0600)] 
Suppress star import errors

flake8 warns about the "from _gdb.disassembler import *" line in
disassembler.py, and a similar line from __init__.py.  These line are
needed to re-export names from the corresponding C++ module, so this
patch applies the appropriate "noqa" flags.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoRemove bare "except" from disassembler.py
Tom Tromey [Tue, 19 Mar 2024 16:49:20 +0000 (10:49 -0600)] 
Remove bare "except" from disassembler.py

flake8 complains about a bare "except" in disassembler.py.  In this
case, the code purports to guard against some kind of user error
involving data structure corruption.  I think it's better here to just
let the error occur -- py-disasm.c will show a stack trace in this
case.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoRemove unused import from gdb/__init__.py
Tom Tromey [Tue, 19 Mar 2024 16:44:04 +0000 (10:44 -0600)] 
Remove unused import from gdb/__init__.py

flake8 points out that the import of _gdb in gdb/__init__.py is
unused.  Remove it.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoIgnore unsed import in dap/__init__.py
Tom Tromey [Tue, 19 Mar 2024 16:27:56 +0000 (10:27 -0600)] 
Ignore unsed import in dap/__init__.py

flake8 warns about dap/__init__.py because it has a number of unused
imports.  Most of these are intentional: the import is done to ensure
that the a DAP request is registered with the server object.

This patch applies a "noqa" comment to these imports, and also removes
one import that is truly unnecessary.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoFix flake8 errors in dap/server.py
Tom Tromey [Tue, 19 Mar 2024 16:24:41 +0000 (10:24 -0600)] 
Fix flake8 errors in dap/server.py

Commit 032d23a6 ("Fix stray KeyboardInterrupt after cancel")
introduced some errors into dap/server.py.  A function is called but
not imported, and the wrong variable name is used.  This patch
corrects both errors.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months agoRemove .flake8
Tom Tromey [Tue, 19 Mar 2024 16:21:01 +0000 (10:21 -0600)] 
Remove .flake8

I re-ran flake8 today and was puzzled to see W503 warnings.
Eventually I found out that the setup.cfg config overrides .flake8.
This patch merges the two and removes .flake8, to avoid future
confusion.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 months ago[gdb/testsuite] Add missing include in gdb.base/ctf-ptype.c
Tom de Vries [Tue, 2 Apr 2024 14:22:46 +0000 (16:22 +0200)] 
[gdb/testsuite] Add missing include in gdb.base/ctf-ptype.c

On fedora rawhide, when running test-case gdb.base/ctf-ptype.exp, I get:
...
gdb compile failed, ctf-ptype.c: In function 'main':
ctf-ptype.c:242:29: error: implicit declaration of function 'malloc' \
  [-Wimplicit-function-declaration]
  242 |   v_char_pointer = (char *) malloc (1);
      |                             ^~~~~~
ctf-ptype.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'malloc'
  +++ |+#include <stdlib.h>
    1 | /* This test program is part of GDB, the GNU debugger.
...

Fix this by adding the missing include.

Tested on aarch64-linux.

14 months ago[gdb/testsuite] Fix gdb.ada/verylong.exp on 32-bit target
Tom de Vries [Tue, 2 Apr 2024 14:14:39 +0000 (16:14 +0200)] 
[gdb/testsuite] Fix gdb.ada/verylong.exp on 32-bit target

In an aarch32-linux chroot on an aarch64-linux system, I run into:
...
(gdb) print x^M
$1 = 9223372036854775807^M
(gdb) FAIL: gdb.ada/verylong.exp: print x
...

A passing version on aarch64-linux looks like:
...
(gdb) print x^M
$1 = 170141183460469231731687303715884105727^M
(gdb) PASS: gdb.ada/verylong.exp: print x
...

The difference is caused by the size of the type Long_Long_Long_Integer, which
is:
- a 128-bit signed on 64-bit targets, and
- a 64-bit signed on 32-bit target.

Fix this by detecting the size of the Long_Long_Long_Integer type, and
handling it.

Tested on aarch64-linux and aarch32-linux.

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

[1] https://gcc.gnu.org/onlinedocs/gnat_rm/Implementation-Defined-Characteristics.html

14 months agoUpdate objcopy's --section-alignment option so that it sets the alignment flag on...
Nick Clifton [Tue, 2 Apr 2024 14:08:07 +0000 (15:08 +0100)] 
Update objcopy's --section-alignment option so that it sets the alignment flag on PE sections.   Add a check for aligned sections not matching their VMAs.

14 months ago[gdb/tui] Fix centering and highlighting of current line
Tom de Vries [Tue, 2 Apr 2024 14:09:10 +0000 (16:09 +0200)] 
[gdb/tui] Fix centering and highlighting of current line

After starting TUI like this with a hello world a.out:
...
$ gdb -q a.out -ex start -ex "tui enable"
...
we get:
...
┌─hello.c──────────────────────────────┐
│        5 {                           │
│        6   printf ("hello\n");       │
│        7                             │
│        8   return 0;                 │
│        9 }                           │
│                                      │
└──────────────────────────────────────┘
...

This is a regression since commit ee1e9bbb513 ("[gdb/tui] Fix displaying main
after resizing"), before which we had instead:
...
┌─hello.c──────────────────────────────┐
│        4 main (void)                 │
│        5 {                           │
│  >     6 \e[7m  printf ("hello\n");\e[0m       │
│        7                             │
│        8   return 0;                 │
│        9 }                           │
└──────────────────────────────────────┘
...

In other words, the problems are:
- the active line (source line 6) is no longer highlighted, and
- the active line is not vertically centered (screen line 2 out 6 instead of
  screen line 3 out of 6).

Fix these problems respectively by:
- in tui_enable, instead of "tui_show_frame_info (0)" using
  'tui_show_frame_info (deprecated_safe_get_selected_frame ())", and
- in tui_source_window_base::rerender, adding centering functionality.

Tested on aarch64-linux.

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

14 months agoPR31458, FAIL: MIPS eh-frame 3 with --no-keep-memory
H.J. Lu [Thu, 7 Mar 2024 16:28:29 +0000 (08:28 -0800)] 
PR31458, FAIL: MIPS eh-frame 3 with --no-keep-memory

PR 31458
bfd/
* elf-bfd.h (_bfd_elf_link_read_relocs),
(_bfd_elf_link_info_read_relocs): Constify section.
* elflink.c: Likewise.
* elfxx-mips.c (_bfd_mips_elf_eh_frame_address_size): Read
relocs again in case --no-keep-memory.
ld/
* testsuite/ld-mips-elf/mips-elf.exp: Run --no-keep-memory
version of eh-frame3 test.

14 months agoPR 30569, delete _bfd_mips_elf_early_size_sections
Alan Modra [Thu, 28 Mar 2024 10:03:32 +0000 (20:33 +1030)] 
PR 30569, delete _bfd_mips_elf_early_size_sections

PR30569 was triggered by a patch of mine 6540edd52cc0 moving the call
to always_size_sections in bfd_elf_size_dynamic_sections earlier, made
to support the x86 DT_RELR implementation.  This broke mips16 code
handling stubs when --export-dynamic is passed to the linker, because
numerous symbols then became dynamic after always_size_sections.  The
mips backend fiddles with symbols in its always_size_sections.  Maciej
in 902e9fc76a0e had moved the call to always_size_sections to after
the export-dynamic code.  Prior to that, Nathan in 04c3a75556c0 moved
it before the exec stack code, back to the start of
bfd_elf_size_dynamic_sections which was where Ian put it originally
in ff12f303355b.  So the call has moved around a little.  I'm leaving
it where it is, and instead calling mips_elf_check_symbols from
late_size_sections (the old size_dynamic_sections) which is now always
called.  In fact, the whole of _bfd_mips_elf_early_size_sections can
be merged into _bfd_mips_elf_late_size_sections.

14 months agoPR 30569, always call elf_backend_size_dynamic_sections
Alan Modra [Thu, 28 Mar 2024 08:55:42 +0000 (19:25 +1030)] 
PR 30569, always call elf_backend_size_dynamic_sections

This largely mechanical patch is preparation for a followup patch.

For quite some time I've thought that it would be useful to call
elf_backend_size_dynamic_sections even when no dynamic objects are
seen by the linker.  That's what this patch does, with some renaming.
There are no functional changes to the linker, just a move of the
dynobj test in bfd_elf_size_dynamic_sections to target backend
functions, replacing the asserts/aborts already there.  No doubt some
of the current always_size_sections functions could be moved to
size_dynamic_sections but I haven't made that change.

Because both hooks are now always called, I have renamed
always_size_sections to early_size_sections and size_dynamic_sections
to late_size_sections.  I condisdered calling late_size_sections plain
size_sections, since this is the usual target dynamic section sizing
hook, but decided that searching the sources for "size_sections" would
then hit early_size_sections and other functions.