binutils-gdb.git
4 years agoFix a potential infinite loop in the Windows resource parser.
Joel Anderson [Fri, 5 Jun 2020 10:11:03 +0000 (11:11 +0100)]
Fix a potential infinite loop in the Windows resource parser.

PR 26082
* mclex.c (yylex): Add test for an empty input stream.

4 years agoFix a use before initialization bug in the pdp11.c source file.
Nick Clifton [Fri, 5 Jun 2020 09:08:26 +0000 (10:08 +0100)]
Fix a use before initialization bug in the pdp11.c source file.

* pdp11.c (aout_link_add_symbols): Fix use before initialisation
bug.

4 years agobpf stack smashing detected
Alan Modra [Fri, 5 Jun 2020 06:48:47 +0000 (16:18 +0930)]
bpf stack smashing detected

* cgen-dis.c (hash_insn_array): Increase size of buf.  Assert
size is large enough.

4 years agoFix unresolved test in binutils for pdp11.
Stephen Casner [Fri, 5 Jun 2020 06:41:57 +0000 (23:41 -0700)]
Fix unresolved test in binutils for pdp11.

* binutils/testsuite/binutils-all/pr25662-pdp11.s: Alternate source file
for test using section pseudo-ops compatible with pdp11.
* binutils/testsuite/binutils-all/objcopy.exp: Select alternate source.

4 years agoRISC-V: The object without priv spec attributes can be linked with any object.
Nelson Chu [Fri, 29 May 2020 08:56:36 +0000 (16:56 +0800)]
RISC-V: The object without priv spec attributes can be linked with any object.

bfd/
* elfnn-riscv.c (riscv_merge_attributes): Add new boolean
priv_may_conflict, in_priv_zero and out_priv_zero to decide whether
the object can be linked according to it's priv attributes.  The object
without any priv spec attributes can be linked with others.  If the first
input object doesn't contain any priv attributes, then we need to copy
the setting from the next input one.  Also report more detailed error
messages to user.

ld/
* testsuite/ld-riscv-elf/attr-merge-priv-spec.d: Rename to
attr-merge-priv-spec-01.d.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-c.s: Set priv spec
to 1.11.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-d.s: Empty priv spec
setting.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d: New testcase.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d: Likewise.
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.

4 years agoRISC-V: Don't generate the ELF privilege attributes when no CSR are used.
Nelson Chu [Fri, 29 May 2020 07:31:46 +0000 (15:31 +0800)]
RISC-V: Don't generate the ELF privilege attributes when no CSR are used.

gas/
* config/tc-riscv.c (explicit_csr): New static boolean.
Used to indicate CSR are explictly used.
(riscv_ip): Set explicit_csr to TRUE if any CSR is used.
(riscv_write_out_attrs): If we already have set elf priv
attributes, then generate them.  Otherwise, don't generate
them when no CSR are used.

* testsuite/gas/riscv/attribute-01.d: Remove the priv attributes.
* testsuite/gas/riscv/attribute-02.d: Likewise.
* testsuite/gas/riscv/attribute-03.d: Likewise.
* testsuite/gas/riscv/attribute-04.d: Likewise.
* testsuite/gas/riscv/attribute-05.d: Likewise.
* testsuite/gas/riscv/attribute-06.d: Likewise.
* testsuite/gas/riscv/attribute-07.d: Likewise.
* testsuite/gas/riscv/attribute-08.d: Likewise.
* testsuite/gas/riscv/attribute-09.d: Likewise.
* testsuite/gas/riscv/attribute-10.d: Likewise.
* testsuite/gas/riscv/attribute-unknown.d: Likewise.
* testsuite/gas/riscv/attribute-11.s: New testcase.
* testsuite/gas/riscv/attribute-11.d: New testcase.  The CSR is
used, so we should output the ELF priv attributes.
* testsuite/gas/riscv/attribute-12.d: New testcase.  The CSR is
used, so output the priv attributes according to the -mpriv-spec.
* testsuite/gas/riscv/attribute-13.d: New testcase.  The CSR isn't
used, so ignore the -mpriv-spec setting.

ld/
* testsuite/ld-riscv-elf/attr-merge-arch-01.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-02.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-stack-align.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-01.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-02.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-04.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-05.d: Likewise.
* testsuite/ld-riscv-elf/call-relax.d: Add -mno-arch-attr.

4 years agoExtend pdp11-aout symbol table format and code for .stab symbols.
Stephen Casner [Fri, 5 Jun 2020 01:12:32 +0000 (18:12 -0700)]
Extend pdp11-aout symbol table format and code for .stab symbols.

* bfd/pdp11.c (pdp11_external_nlist): Repurposed e_unused to e_desc.
(N_STAB, is_stab): Needed new function is_stab to disambiguate
normal vs. .stab symbol table type values, replacing N_STAB mask.
(translate_from_native_sym_flags): Determine correct section for
different .stab types.
(translate_to_native_sym_flags): Leave .stab types intact.
(translate_symbol_table): Error if symbol indicates overlay;
store desc field from .stab symbols.
(write_syms): Output desc field with symbol.
(aout_link_check_ar_symbols): Skip .stab symbols.
(aout_link_add_symbols): Correctly distinguish .stab symbols.
(aout_link_write_other_symbol): Write 0 for desk and ovly fields.
(aout_link_write_symbols): Write 0 for desk and ovly fields;
correctly distinguish .stab symbols and select calculate their
section and value; and copy desc and ovly fields from input symbol
to output symbol.

4 years agoAutomatic date update in version.in
GDB Administrator [Fri, 5 Jun 2020 00:00:19 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agoCorrect a comment.
Stephen Casner [Thu, 4 Jun 2020 19:34:17 +0000 (12:34 -0700)]
Correct a comment.

* bfd/aoutx.h (translate_symbol_table): Comment had external and
internal swapped.
* bfd/pdp11.c (translate_symbol_table): Likewise.

4 years agogas: Fix ip2k-elf and xstormy16-elf build
H.J. Lu [Thu, 4 Jun 2020 18:15:06 +0000 (11:15 -0700)]
gas: Fix ip2k-elf and xstormy16-elf build

Fix ip2k-elf and xstormy16-elf build due to

commit e9bffec9afc45cf7c49308f0b4b8cc6bf68f58f2
Author: Jose E. Marchesi <jose.marchesi@oracle.com>
Date:   Thu Jun 4 16:15:53 2020 +0200

    opcodes: discriminate endianness and insn-endianness in CGEN ports

* config/tc-ip2k. (ip2k_apply_fix): Pass endianness to
cgen_get_insn_value.
* config/tc-xstormy16.c (xstormy16_md_apply_fix): Pass
endianness to cgen_get_insn_value and cgen_put_insn_value.

4 years agogdb: really share partial symtabs when using .gdb_index or .debug_names
Simon Marchi [Thu, 4 Jun 2020 17:56:55 +0000 (13:56 -0400)]
gdb: really share partial symtabs when using .gdb_index or .debug_names

Fix/follow-up to commit 17ee85fc2a ("Share DWARF partial symtabs").

In the non-index case, where GDB builds partial symbols from scratch,
two objfiles around the same BFD correctly share partial symtabs.  The
first objfile, which has to do all the work, saves a reference to the
created partial symtabs in the shared per_bfd object (at the end of
dwarf2_build_psymtabs).  The second objfile, when it reaches
dwarf2_build_psymtabs, sees that there are already partial symtabs built
for this BFD and just uses it.

However, that commit missed implementing the same sharing for cases
where GDB uses .gdb_index or .debug_names to build the partial symtabs.

This patch fixes it by having the first objfile to use the BFD set
per_bfd->partial_symtabs at the end of dwarf2_read_gdb_index /
dwarf2_read_debug_names.  For the subsequent objfiles using that BFD,
the partial symtabs are then picked up in dwarf2_initialize_objfile.

This patch adds a test that mimics how the issue was originally
triggered:

  1. Load the test file twice, such that the second objfile re-uses the
     per_bfd object created for the first objfile.
  2. Run to some point where in the backtrace there is a frame for a
     function that's in a CU that's not yet read in.
  3. Check that this frame's information is complete in the "backtrace"
     output.

Step 2 requires an address -> symbol lookup which uses the addrmap at
objfile->partial_symtabs->psymtabs_addrmap.  If the
objfile->partial_symtabs link is not properly setup (as is the case
before this patch), the symbol for that frame won't be found and we'll
get a frame with incomplete information.

The test fails without the fix when using boards "cc-with-gdb-index" and
"cc-with-debug-names".

gdb/ChangeLog:

* dwarf2/read.c (dwarf2_read_gdb_index): Save partial_symtabs in
the per_bfd object.
(dwarf2_read_debug_names): Likewise.
(dwarf2_initialize_objfile): Use partial_symtabs from per_bfd
object when re-using a per_bfd object with an index.

gdb/testsuite/ChangeLog:

* gdb.dwarf2/share-psymtabs-bt.exp: New file.
* gdb.dwarf2/share-psymtabs-bt.c: New file.
* gdb.dwarf2/share-psymtabs-bt-2.c: New file.

Change-Id: Ibb26210e2dfc03b80ba9fa56b875ba4cc58c0352

4 years agox86: Remove target_id from elf_x86_link_hash_table
H.J. Lu [Thu, 4 Jun 2020 16:56:25 +0000 (09:56 -0700)]
x86: Remove target_id from elf_x86_link_hash_table

Since target_id in elf_x86_link_hash_table is the same as hash_table_id
in elf_link_hash_table, we can use elf.hash_table_id instead of target_id.

* elfxx-x86.h (elf_x86_link_hash_table): Remove target_id.
(is_x86_elf): Check elf.hash_table_id instead of target_id.
* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Updated.

4 years ago[gdb/testsuite] Remove path names from error messages in gdb_file_cmd
Tom de Vries [Thu, 4 Jun 2020 15:37:53 +0000 (17:37 +0200)]
[gdb/testsuite] Remove path names from error messages in gdb_file_cmd

In gdb_file_cmd, perror is called with error message strings using $arg and
$GDB, both of which contain path names, which makes comparison of gdb.sum
files more difficult.

Fix this by using:
- [file tail $arg] instead of $arg
- GDB instead of $GDB.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-06-04  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_file_cmd): Avoid path names in error messages.

4 years agogas: simplify code in tc-bpf.c:md_apply_fix
Jose E. Marchesi [Thu, 4 Jun 2020 14:33:34 +0000 (16:33 +0200)]
gas: simplify code in tc-bpf.c:md_apply_fix

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

* config/tc-bpf.c (md_apply_fix): Simplify and avoid using
cgen_put_insn_value.

4 years ago[gdb/testsuite] Fix error handling in gdb_file_cmd
Tom de Vries [Thu, 4 Jun 2020 14:33:55 +0000 (16:33 +0200)]
[gdb/testsuite] Fix error handling in gdb_file_cmd

Consider a gdb_load patch to call the gdb_file_cmd twice:
...
 proc gdb_load { arg } {
     if { $arg != "" } {
+       set res [gdb_file_cmd $arg]
+       if { $res != 0 } {
+           return $res
+       }
        return [gdb_file_cmd $arg]
     }
     return 0
 }
...

When running test-case gdb.base/index-cache.exp, we run into:
...
ERROR: Couldn't load outputs/gdb.base/index-cache/index-cache, other program \
  already loaded (timeout).
FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: check index-cache \
  stats (GDB internal error)
ERROR: Couldn't load outputs/gdb.base/index-cache/index-cache, other program \
  already loaded (timeout).
...

The first timeout in more detail:
...
(gdb) file outputs/gdb.base/index-cache/index-cache^M
Load new symbol table from "index-cache"? (y or n) y^M
Reading symbols from index-cache...^M
src/gdb/dwarf2/read.c:2540: internal-error: \
  void create_cus_from_index(dwarf2_per_bfd*, const gdb_byte*, offset_type, \
                             const gdb_byte*, offset_type): \
  Assertion `per_bfd->all_comp_units.empty ()' failed.^M
A problem internal to GDB has been detected,^M
further debugging may prove unreliable.^M
Quit this debugging session? (y or n) ERROR: Couldn't load index-cache, \
  other program already loaded (timeout).
...

Proc gdb_file_cmd has a gdb_expect handling the result of the file command,
and if the result is a "Load new symbol table from index-cache? (y or n) "
prompt, it sends a "y" and enters in a nested gdb_expect to handle the
result.

The first gdb_expect contains code to handle "A problem internal to GDB has
been detected", but the second one doesn't, which causes the timeout.

Fix this by removing the nested gdb_expect, and using exp_continue instead,
such that we have instead:
...
ERROR: Couldn't load outputs/gdb.base/index-cache/index-cache -- with new \
  symbol table into gdb (GDB internal error).
ERROR: Couldn't load outputs/gdb.base/index-cache/index-cache -- with new \
  symbol table into gdb (GDB internal error).
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-06-04  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_file_cmd): Replace incomplete gdb_expect by
exp_continue.

4 years agocpu,gas,opcodes: remove no longer needed workaround from the BPF port
Jose E. Marchesi [Thu, 4 Jun 2020 14:17:07 +0000 (16:17 +0200)]
cpu,gas,opcodes: remove no longer needed workaround from the BPF port

cpu/ChangeLog:

2020-06-02  Jose E. Marchesi  <jose.marchesi@oracle.com>

* bpf.cpu (define-bpf-isa): Set base-insn-bitsize to 64.
* bpf.opc (bpf_print_insn): Do not set endian_code here.

gas/ChangeLog:

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

* config/tc-bpf.c (md_begin): Pass CGEN_CPU_OPEN_INSN_ENDIAN to
bpf_cgen_cpu_open.
(md_assemble): Remove no longer needed hack.

opcodes/ChangeLog:

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

* disassemble.c (disassemble_init_for_target): Set endian_code for
bpf targets.
* bpf-desc.c: Regenerate.
* bpf-opc.c: Likewise.
* bpf-dis.c: Likewise.

4 years agoopcodes: discriminate endianness and insn-endianness in CGEN ports
Jose E. Marchesi [Thu, 4 Jun 2020 14:15:53 +0000 (16:15 +0200)]
opcodes: discriminate endianness and insn-endianness in CGEN ports

The CGEN support code in opcodes accesses instruction contents using a
couple of functions defined in cgen-opc.c: cgen_get_insn_value and
cgen_put_insn_value.  These functions use the "instruction endianness"
in the CPU description to order the read/written bytes.

The process of writing an instruction to the object file is:

  a) cgen_put_insn_value        ;; Writes out the opcodes.
  b) ARCH_cgen_insert_operand
       insert_normal
         insert_1
           cgen_put_insn_value  ;; Writes out the bytes of the
                                ;; operand.

Likewise, the process of reading an instruction from the object file
is:

  a) cgen_get_insn_value        ;; Reads the opcodes.
  b) ARCH_cgen_extract_operand
       extract_normal
         extract_1
           cgen_get_insn_value  ;; Reads in the bytes of the
                                ;; operand.

As can be seen above, cgen_{get,put}_insn_value are used to both
process the instruction opcodes (the constant fields conforming the
base instruction) and also the values of the instruction operands,
such as immediates.

This is problematic for architectures in which the endianness of
instructions is different to the endianness of data.  An example is
BPF, where instructions are always encoded big-endian but the data may
be either big or little.

This patch changes the cgen_{get,put}_insn_value functions in order to
get an extra argument with the endianness to use, and adapts the
existin callers to these functions in order to provide cd->endian or
cd->insn_endian, whatever appropriate.  Callers like extract_1 and
insert_1 pass cd->endian (since they are reading/writing operand
values) while callers reading/writing the base instruction pass
cd->insn_endian instead.

A few little adjustments have been needed in some existing CGEN based
ports:
* The BPF assembler uses cgen_put_insn_value.  It has been adapted to
  pass the new endian argument.
* The mep port has code in mep.opc that uses cgen_{get,put}_insn_value.
  It has been adapted to pass the new endianargument.  Ditto for a
  call in the assembler.

Tested with --enable-targets=all.
Regested in all supported targets.
No regressions.

include/ChangeLog:

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

* opcode/cgen.h: Get an `endian' argument in both
cgen_get_insn_value and cgen_put_insn_value.

opcodes/ChangeLog:

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

* cgen-opc.c (cgen_get_insn_value): Get an `endian' argument.
(cgen_put_insn_value): Likewise.
(cgen_lookup_insn): Pass endianness to cgen_{get,put}_insn_value.
* cgen-dis.in (print_insn): Likewise.
* cgen-ibld.in (insert_1): Likewise.
(insert_1): Likewise.
(insert_insn_normal): Likewise.
(extract_1): Likewise.
* bpf-dis.c: Regenerate.
* bpf-ibld.c: Likewise.
* bpf-ibld.c: Likewise.
* cgen-dis.in: Likewise.
* cgen-ibld.in: Likewise.
* cgen-opc.c: Likewise.
* epiphany-dis.c: Likewise.
* epiphany-ibld.c: Likewise.
* fr30-dis.c: Likewise.
* fr30-ibld.c: Likewise.
* frv-dis.c: Likewise.
* frv-ibld.c: Likewise.
* ip2k-dis.c: Likewise.
* ip2k-ibld.c: Likewise.
* iq2000-dis.c: Likewise.
* iq2000-ibld.c: Likewise.
* lm32-dis.c: Likewise.
* lm32-ibld.c: Likewise.
* m32c-dis.c: Likewise.
* m32c-ibld.c: Likewise.
* m32r-dis.c: Likewise.
* m32r-ibld.c: Likewise.
* mep-dis.c: Likewise.
* mep-ibld.c: Likewise.
* mt-dis.c: Likewise.
* mt-ibld.c: Likewise.
* or1k-dis.c: Likewise.
* or1k-ibld.c: Likewise.
* xc16x-dis.c: Likewise.
* xc16x-ibld.c: Likewise.
* xstormy16-dis.c: Likewise.
* xstormy16-ibld.c: Likewise.

gas/ChangeLog:

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

* cgen.c (gas_cgen_finish_insn): Pass the endianness to
cgen_put_insn_value.
(gas_cgen_md_apply_fix): Likewise.
(gas_cgen_md_apply_fix): Likewise.
* config/tc-bpf.c (md_apply_fix): Pass data endianness to
cgen_put_insn_value.
* config/tc-mep.c (mep_check_ivc2_scheduling): Pass endianness to
cgen_put_insn_value.

cpu/ChangeLog:

2020-06-02  Jose E. Marchesi  <jose.marchesi@oracle.com>

* mep.opc (print_slot_insn): Pass the insn endianness to
cgen_get_insn_value.

4 years agoopcodes: support insn endianness in cgen_cpu_open
Jose E. Marchesi [Thu, 4 Jun 2020 14:14:41 +0000 (16:14 +0200)]
opcodes: support insn endianness in cgen_cpu_open

This patch adds support for a new CGEN_OPEN_INSN_ENDIAN argument
for @arch@_cgen_cpu_open.  This is useful for architectures in
which the endianness of the instruction words is not the same
than the endianness used for data.

An accompanying patch has been sent to the CGEN mailing list that
adds support for this argument on the CGEN side [1].  Its been
already pre-approved [2], and will be applied simultaneously with
this binutils series.

[1] https://sourceware.org/pipermail/cgen/2020q2/002733.html
[2] https://sourceware.org/pipermail/cgen/2020q2/002737.html

include/ChangeLog:

2020-06-04  Jose E. Marchesi  <jemarch@gnu.org>

* opcode/cgen.h (enum cgen_cpu_open_arg): New value
CGEN_CPU_OPEN_INSN_ENDIAN.

opcodes/ChangeLog:

2020-06-04  Jose E. Marchesi  <jemarch@gnu.org>

* cgen-dis.in (cpu_desc_list): New field `insn_endian'.
(print_insn_): Handle instruction endian.
* bpf-dis.c: Regenerate.
* bpf-desc.c: Regenerate.
* epiphany-dis.c: Likewise.
* epiphany-desc.c: Likewise.
* fr30-dis.c: Likewise.
* fr30-desc.c: Likewise.
* frv-dis.c: Likewise.
* frv-desc.c: Likewise.
* ip2k-dis.c: Likewise.
* ip2k-desc.c: Likewise.
* iq2000-dis.c: Likewise.
* iq2000-desc.c: Likewise.
* lm32-dis.c: Likewise.
* lm32-desc.c: Likewise.
* m32c-dis.c: Likewise.
* m32c-desc.c: Likewise.
* m32r-dis.c: Likewise.
* m32r-desc.c: Likewise.
* mep-dis.c: Likewise.
* mep-desc.c: Likewise.
* mt-dis.c: Likewise.
* mt-desc.c: Likewise.
* or1k-dis.c: Likewise.
* or1k-desc.c: Likewise.
* xc16x-dis.c: Likewise.
* xc16x-desc.c: Likewise.
* xstormy16-dis.c: Likewise.
* xstormy16-desc.c: Likewise.

binutils/ChangeLog:

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

* objdump.c (disassemble_data): Set disasm_info.endian_code to
        disasm_info.endian after the latter is initialized to the
        endianness reported by BFD.

4 years ago[gdb/testsuite] Fix use of fail in gdb_cmd_file
Tom de Vries [Thu, 4 Jun 2020 14:13:14 +0000 (16:13 +0200)]
[gdb/testsuite] Fix use of fail in gdb_cmd_file

When building gdb using this patch:
...
 static void
 file_command (const char *arg, int from_tty)
 {
+  gdb_assert (0);
...
and running the testsuite, we run into:
...
Running src/gdb/testsuite/gdb.ada/O2_float_param.exp ...
PASS: gdb.ada/O2_float_param.exp: compilation foo.adb
FAIL: gdb.ada/O2_float_param.exp: (outputs/gdb.ada/O2_float_param/foo) \
  (GDB internal error)
PATH: gdb.ada/O2_float_param.exp: (outputs/gdb.ada/O2_float_param/foo) \
  (GDB internal error)
FAIL: gdb.ada/O2_float_param.exp: frame
...

The FAIL detecting the GDB internal error is generated by this clause in
gdb_file_cmd:
...
       -re "A problem internal to GDB has been detected" {
           fail "($arg) (GDB internal error)"
           gdb_internal_error_resync
           return -1
       }
...

The fail message has no text outside parenthesis, and could be considered
empty.  Also, it's the only clause in the gdb_expect that uses fail, the
rest uses perror.

Fix this by replacing the fail by perror, such that we have:
...
Running src/gdb/testsuite/gdb.ada/O2_float_param.exp ...
PASS: gdb.ada/O2_float_param.exp: compilation foo.adb
ERROR: Couldn't load outputs/gdb.ada/O2_float_param/foo into \
  gdb (GDB internal error).
UNRESOLVED: gdb.ada/O2_float_param.exp: frame
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-06-04  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_file_cmd): Use perror instead of fail.

4 years agoELF: Don't check relocations in non-loaded, non-alloced sections
H.J. Lu [Thu, 4 Jun 2020 12:58:34 +0000 (05:58 -0700)]
ELF: Don't check relocations in non-loaded, non-alloced sections

Don't do anything special with non-loaded, non-alloced sections.
In particular, any relocs in such sections should not affect GOT
and PLT reference counting (ie. we don't allow them to create GOT
or PLT entries), there's no possibility or desire to optimize TLS
relocs, and there's not much point in propagating relocs to shared
libs that the dynamic linker won't relocate.

Since check_relocs is no longer called on non-loaded, non-alloced
sections, remove SEC_ALLOC check.  Resolve relocation in debug section
against symbol defined in shared library to 0.

bfd/

PR ld/26080
* elf-m10300.c (mn10300_elf_relocate_section): Resolve relocation
in debug section against symbol defined in shared library to 0.
* elf32-i386.c (elf_i386_check_relocs): Remove SEC_ALLOC check.
* elf32-lm32.c (lm32_elf_check_relocs): Likewise.
* elf32-m32r.c (m32r_elf_check_relocs): Likewise.
* elf32-nds32.c (nds32_elf_check_relocs): Likewise.
* elf32-nios2.c (nios2_elf32_check_relocs): Likewise.
* elf32-or1k.c (or1k_elf_check_relocs): Likewise.
* elf32-ppc.c (ppc_elf_check_relocs): Likewise.
* elf32-sh.c (sh_elf_check_relocs): Likewise.
* elf32-xtensa.c (elf_xtensa_check_relocs): Likewise.
* elf64-alpha.c (elf64_alpha_check_relocs): Likewise.
* elf64-ppc.c (ppc64_elf_check_relocs): Likewise.
* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.
* elf32-vax.c (elf_vax_check_relocs): Set non_got_ref for non-GOT
reference.
(elf_vax_adjust_dynamic_symbol): Generate a copy reloc only if
there is non-GOT reference.
* elflink.c (_bfd_elf_link_check_relocs): Skip non-loaded,
non-alloced sections.

ld/

PR ld/26080
* testsuite/ld-elf/comm-data.exp: Remove copy_reloc.
* testsuite/ld-elf/comm-data2r.rd: Removed.
* testsuite/ld-elf/comm-data2r.sd: Likewise.
* testsuite/ld-elf/comm-data2r.xd: Likewise.

4 years agotcl global directive outside proc body does nothing (gas)
Alan Modra [Thu, 4 Jun 2020 06:30:46 +0000 (16:00 +0930)]
tcl global directive outside proc body does nothing (gas)

* testsuite/config/default.exp: Remove global directive outside
proc body.
* testsuite/gas/mep/complex-relocs.exp: Likewise.
* testsuite/gas/microblaze/relax_size.exp: Likewise.
* testsuite/gas/microblaze/reloc_sym.exp: Likewise.
* testsuite/gas/mt/relocs.exp: Likewise.
* testsuite/gas/rx/rx.exp: Likewise.

4 years agotcl global directive outside proc body does nothing (binutils)
Alan Modra [Thu, 4 Jun 2020 06:26:33 +0000 (15:56 +0930)]
tcl global directive outside proc body does nothing (binutils)

* testsuite/binutils-all/i386/i386.exp
* testsuite/binutils-all/x86-64/objects.exp
* testsuite/binutils-all/x86-64/x86-64.exp

4 years agotcl global directive outside proc body does nothing (ld)
Alan Modra [Thu, 4 Jun 2020 05:27:12 +0000 (14:57 +0930)]
tcl global directive outside proc body does nothing (ld)

* testsuite/config/default.exp: Remove global directive outside
proc body.
* testsuite/ld-bootstrap/bootstrap.exp: Likewise.
* testsuite/ld-elf/compress.exp: Likewise.
* testsuite/ld-elf/elf.exp: Likewise.
* testsuite/ld-elf/exclude.exp: Likewise.
* testsuite/ld-elf/frame.exp: Likewise.
* testsuite/ld-elf/indirect.exp: Likewise.
* testsuite/ld-elf/linux-x86.exp: Likewise.
* testsuite/ld-elf/shared.exp: Likewise.
* testsuite/ld-elf/tls.exp: Likewise.
* testsuite/ld-elf/tls_common.exp: Likewise.
* testsuite/ld-elfcomm/elfcomm.exp: Likewise.
* testsuite/ld-elfweak/elfweak.exp: Likewise.
* testsuite/ld-frv/fdpic.exp: Likewise.
* testsuite/ld-frv/tls.exp: Likewise.
* testsuite/ld-gc/gc.exp: Likewise.
* testsuite/ld-i386/i386.exp: Likewise.
* testsuite/ld-i386/no-plt.exp: Likewise.
* testsuite/ld-ifunc/ifunc.exp: Likewise.
* testsuite/ld-mips-elf/mips-elf-flags.exp: Likewise.
* testsuite/ld-nios2/nios2.exp: Likewise.
* testsuite/ld-plugin/lto.exp: Likewise.
* testsuite/ld-plugin/plugin.exp: Likewise.
* testsuite/ld-powerpc/export-class.exp: Likewise.
* testsuite/ld-scripts/align.exp: Likewise.
* testsuite/ld-scripts/crossref.exp: Likewise.
* testsuite/ld-scripts/defined.exp: Likewise.
* testsuite/ld-scripts/overlay-size.exp: Likewise.
* testsuite/ld-scripts/provide.exp: Likewise.
* testsuite/ld-scripts/weak.exp: Likewise.
* testsuite/ld-selective/selective.exp: Likewise.
* testsuite/ld-sh/rd-sh.exp: Likewise.
* testsuite/ld-size/size.exp: Likewise.
* testsuite/ld-srec/srec.exp: Likewise.
* testsuite/ld-x86-64/mpx.exp: Likewise.
* testsuite/ld-x86-64/no-plt.exp: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Likewise.

4 years agold-dynamic test fixes
Alan Modra [Thu, 4 Jun 2020 03:11:46 +0000 (12:41 +0930)]
ld-dynamic test fixes

* testsuite/ld-dynamic/export-dynamic-symbol-2.d: Match output for
mips-sgi-irix6.
* testsuite/ld-dynamic/export-dynamic-symbol-glob.d: Likewise.
* testsuite/ld-dynamic/export-dynamic-symbol-list-2.d: Likewise.
* testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d: Likewise.
* testsuite/ld-dynamic/export-dynamic-symbol.exp: Exclude targets
with poor PIE support.

4 years agold testsuite fails with default-PIE compiler
Alan Modra [Wed, 3 Jun 2020 13:39:48 +0000 (23:09 +0930)]
ld testsuite fails with default-PIE compiler

* testsuite/ld-plugin/lto.exp (pr12758.exe): Add NOPIE_LDFLAGS.
* testsuite/ld-unique/unique.exp: Add NOPIE_LDFLAGS to unique
executable and dynamic executable tests.

4 years agoCorrect PR number in changelog
Alan Modra [Wed, 3 Jun 2020 22:59:41 +0000 (08:29 +0930)]
Correct PR number in changelog

4 years agoCopy several years of fixes from bfd/aoutx.h to bfd/pdp11.c.
Stephen Casner [Thu, 4 Jun 2020 00:43:45 +0000 (17:43 -0700)]
Copy several years of fixes from bfd/aoutx.h to bfd/pdp11.c.

* pdp11.c (some_aout_object_p): 4c1534c7a2a - Don't set EXEC_P for
files with relocs.
(aout_get_external_symbols): 6b8f0fd579d - Return if count is zero.
0301ce1486b PR 22306 - Handle stringsize of zero, and error for any
other size that doesn't qcover the header word.
bf82069dce1 PR 23056 - Allocate an extra byte at the end of the
string table, and zero it.
(translate_symbol_table): 0d329c0a83a PR 22887 - Print an error
message and set bfd_error on finding an invalid name string offset.
(add_to_stringtab): INLINE -> inline
(pdp11_aout_swap_reloc_in): 116acb2c268 PR 22887 - Correct r_index
bound check.
(squirt_out_relocs): e2996cc315d PR 20921 - Check for and report
any relocs that could not be recognised.
92744f05809 PR 20929 - Check for relocs without an associated symbol.
(find_nearest_line):  808346fcfcf PR 23055 - Check that the symbol
name exists and is long enough, before attempting to see if it is
for a .o file.
c3864421222 - Correct case for N_SO being the last symbol.
50455f1ab29 PR 20891 - Handle the case where the main file name
and the directory name are both empty.
e82ab856bb4 PR 20892 - Handle the case where function name is empty.
(aout_link_add_symbols): e517df3dbf7 PR 19629 - Check for out of
range string table offsets.
531336e3a0b PR 20909 - Fix off-by-one error in check for an
illegal string offset.
(aout_link_includes_newfunc): Add comment.
(pdp11_aout_link_input_section): ad756e3f9e6 - Return with an error
on unexpected relocation type rather than ASSERT.

4 years agoAutomatic date update in version.in
GDB Administrator [Thu, 4 Jun 2020 00:00:15 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years ago[gdb/symtab] Fix missing breakpoint location for inlined function
Tom de Vries [Wed, 3 Jun 2020 21:50:16 +0000 (23:50 +0200)]
[gdb/symtab] Fix missing breakpoint location for inlined function

Consider the test-case contained in this patch.

With -readnow, we have two breakpoint locations:
...
$ gdb -readnow -batch breakpoint-locs -ex "b N1::C1::baz" -ex "info break"
Breakpoint 1 at 0x4004cb: N1::C1::baz. (2 locations)
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   <MULTIPLE>
1.1                         y   0x00000000004004cb in N1::C1::baz() \
                                                     at breakpoint-locs.h:6
1.2                         y   0x00000000004004f0 in N1::C1::baz() \
                                                     at breakpoint-locs.h:6
...

But without -readnow, we have instead only one breakpoint location:
...
$ gdb -batch breakpoint-locs -ex "b N1::C1::baz" -ex "info break"
Breakpoint 1 at 0x4004f0: file breakpoint-locs.h, line 6.
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00000000004004f0 in N1::C1::baz() \
                                                     at breakpoint-locs.h:6
...

The relevant dwarf is this bit:
...
 <0><d2>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <d8>   DW_AT_name        : breakpoint-locs.cc
 <1><f4>: Abbrev Number: 2 (DW_TAG_namespace)
    <f5>   DW_AT_name        : N1
 <2><fe>: Abbrev Number: 3 (DW_TAG_class_type)
    <ff>   DW_AT_name        : C1
 <3><109>: Abbrev Number: 4 (DW_TAG_subprogram)
    <10a>   DW_AT_name        : baz
    <110>   DW_AT_linkage_name: _ZN2N12C13bazEv
 <2><116>: Abbrev Number: 5 (DW_TAG_subprogram)
    <117>   DW_AT_name        : foo
    <11d>   DW_AT_linkage_name: _ZN2N13fooEv
 <1><146>: Abbrev Number: 8 (DW_TAG_subprogram)
    <147>   DW_AT_specification: <0x116>
    <14b>   DW_AT_low_pc      : 0x4004c7
    <153>   DW_AT_high_pc     : 0x10
 <2><161>: Abbrev Number: 9 (DW_TAG_inlined_subroutine)
    <162>   DW_AT_abstract_origin: <0x194>
    <166>   DW_AT_low_pc      : 0x4004cb
    <16e>   DW_AT_high_pc     : 0x9
 <1><194>: Abbrev Number: 12 (DW_TAG_subprogram)
    <195>   DW_AT_specification: <0x109>
    <199>   DW_AT_inline      : 3       (declared as inline and inlined)
...

The missing breakpoint location is specified by DIE 0x161, which is ignored by
the partial DIE reader because it's a child of a DW_TAG_subprogram DIE (at
0x146, for foo).

Fix this by not ignoring the DIE during partial DIE reading.

Tested on x86_64-linux.

gdb/ChangeLog:

2020-06-03  Tom de Vries  <tdevries@suse.de>

PR symtab/26046
* dwarf2/read.c (scan_partial_symbols): Recurse into DW_TAG_subprogram
children for C++.
(load_partial_dies): Don't skip DW_TAG_inlined_subroutine child of
DW_TAG_subprogram.

gdb/testsuite/ChangeLog:

2020-06-03  Tom de Vries  <tdevries@suse.de>

PR symtab/26046
* gdb.cp/breakpoint-locs-2.cc: New test.
* gdb.cp/breakpoint-locs.cc: New test.
* gdb.cp/breakpoint-locs.exp: New file.
* gdb.cp/breakpoint-locs.h: New test.

4 years ago* gas/doc/c-riscv.texi (RISC-V-Options): Fix non-ASCII apostrophe.
Stephen Casner [Wed, 3 Jun 2020 20:42:54 +0000 (13:42 -0700)]
* gas/doc/c-riscv.texi (RISC-V-Options): Fix non-ASCII apostrophe.

4 years agonios2: Call _bfd_elf_maybe_set_textrel to set DF_TEXTREL
H.J. Lu [Wed, 3 Jun 2020 16:25:51 +0000 (09:25 -0700)]
nios2: Call _bfd_elf_maybe_set_textrel to set DF_TEXTREL

Call _bfd_elf_maybe_set_textrel to set DF_TEXTREL by scanning dynamic
relocations in read-only section.

PR ld/26066
* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Call
_bfd_elf_maybe_set_textrel to set DF_TEXTREL.

4 years agonios2: Don't check relocations in non-loaded, non-alloced sections
H.J. Lu [Wed, 3 Jun 2020 16:21:03 +0000 (09:21 -0700)]
nios2: Don't check relocations in non-loaded, non-alloced sections

Don't do anything special with non-loaded, non-alloced sections.
In particular, any relocs in such sections should not affect GOT
and PLT reference counting (ie. we don't allow them to create GOT
or PLT entries), there's no possibility or desire to optimize TLS
relocs, and there's not much point in propagating relocs to shared
libs that the dynamic linker won't relocate.

PR ld/26066
* elf32-nios2.c (nios2_elf32_check_relocs): Skip non-loaded,
non-alloced sections.

4 years agofrv: Don't generate dynamic relocation for non SEC_ALLOC sections
H.J. Lu [Wed, 3 Jun 2020 16:12:40 +0000 (09:12 -0700)]
frv: Don't generate dynamic relocation for non SEC_ALLOC sections

Don't generate dynamic relocations for non SEC_ALLOC sections because
run-time loader won't process them.

* elf32-frv.c (elf32_frv_relocate_section): Don't generate
dynamic relocations for non SEC_ALLOC sections.

4 years agoarc: Don't generate dynamic relocation for non SEC_ALLOC sections
H.J. Lu [Wed, 3 Jun 2020 16:09:40 +0000 (09:09 -0700)]
arc: Don't generate dynamic relocation for non SEC_ALLOC sections

Don't generate dynamic relocations for non SEC_ALLOC sections because
run-time loader won't process them.

* elf32-arc.c (elf_arc_relocate_section): Don't generate dynamic
relocations for non SEC_ALLOC sections.

4 years ago[PATCH] fix windmc typedef bug
Joel Anderson [Wed, 3 Jun 2020 15:44:37 +0000 (16:44 +0100)]
[PATCH] fix windmc typedef bug

While a typedef can be specified in message files for the messages following
with the `MessageIdTypedef` directive, only the last typedef was honored by
windmc. This corrects this behavior, matching mc.exe functionality.

* windmc.h (struct mc_node): Add id_typecast field.
* mcparse.y (message): Initialise the id_typecast field.
* windmc.c (write_dbg): Use the id_typecast field as a parameter
when calling write_dbg_define.
(write_header): Likewise.

4 years ago[gdb/testsuite] Fix use of verbose in gdb/jit-*.exp
Tom de Vries [Wed, 3 Jun 2020 15:18:52 +0000 (17:18 +0200)]
[gdb/testsuite] Fix use of verbose in gdb/jit-*.exp

When running the gdb/jit-*.exp tests with runtest -v, I get:
...
ERROR: internal buffer is full.
UNRESOLVED: gdb.base/jit-elf-so.exp: one_jit_test-1: maintenance print objfiles
ERROR: internal buffer is full.
UNRESOLVED: gdb.base/jit-elf-so.exp: one_jit_test-2: maintenance print objfiles
ERROR: internal buffer is full.
UNRESOLVED: gdb.base/jit-elf.exp: one_jit_test-1: maintenance print objfiles
ERROR: internal buffer is full.
UNRESOLVED: gdb.base/jit-elf.exp: one_jit_test-2: maintenance print objfiles
ERROR: internal buffer is full.
UNRESOLVED: gdb.base/jit-elf.exp: attach: one_jit_test-2: maintenance print objfiles
ERROR: internal buffer is full.
UNRESOLVED: gdb.base/jit-elf.exp: PIE: one_jit_test-1: maintenance print objfiles
FAIL: gdb.base/jit-reader.exp: jit-reader-load
FAIL: gdb.base/jit-reader.exp: with jit-reader: before mangling: bt works
FAIL: gdb.base/jit-reader.exp: with jit-reader: after mangling: bt works
FAIL: gdb.base/jit-reader.exp: with jit-reader again: jit-reader-load
FAIL: gdb.base/jit-reader.exp: with jit-reader again: bt
...

This is the consequence of the use of global verbose in these tests, which is
used to change the actual test, rather than be more verbose about it.

Fix this by defining a global test_verbose in each test, and using that
instead.

Tested on x86_64-linux using runtest -v.

gdb/testsuite/ChangeLog:

2020-06-03  Tom de Vries  <tdevries@suse.de>

PR testsuite/25609
* gdb.base/jit-elf-so.exp: Don't modify testing behaviour based on
value of global verbose.
* gdb.base/jit-elf.exp: Same.
* gdb.base/jit-reader.exp: Same.

4 years agoUpdated Serbian translation for the opcodes sub-directory
Nick Clifton [Wed, 3 Jun 2020 14:29:09 +0000 (15:29 +0100)]
Updated Serbian translation for the opcodes sub-directory

4 years agoThis patch set for the generic BFD a.out backend removes a dead #define and makes...
Gunther Nikl [Wed, 3 Jun 2020 14:24:58 +0000 (15:24 +0100)]
This patch set for the generic BFD a.out backend removes a dead #define and makes aoutx.h self-contained:  [PATCH 1/2]: bfd: remove unused NO_WRITE_HEADER_KLUDGE #define  [PATCH 2/2]: bfd: make aoutx.h self-contained

* aout64.c (BMAGIC, QMAGIC): Do not define.
* aoutx.h (N_IS_BMAGIC, N_SET_QMAGIC): New defines.
(NAME (aout, some_aout_object_p)): Use N_IS_QMAGIC and N_IS_BMAGIC
to check the file format.
(adjust_z_magic): Use N_SET_QMAGIC to set file format.
* i386aout.c (NO_WRITE_HEADER_KLUDGE): Delete define.
* libaout.h (NO_WRITE_HEADER_KLUDGE): Do not define.

4 years agoELF: Consolidate maybe_set_textrel
H.J. Lu [Wed, 3 Jun 2020 14:07:09 +0000 (07:07 -0700)]
ELF: Consolidate maybe_set_textrel

All maybe_set_textrel implementations are the same.  Consolidate them
to a single _bfd_elf_maybe_set_textrel.

* elf-bfd.h (_bfd_elf_maybe_set_textrel): New
* elf32-arm.c (maybe_set_textrel): Removed.
(elf32_arm_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-csky.c (maybe_set_textrel): Removed.
(csky_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-hppa.c (maybe_set_textrel): Removed.
(elf32_hppa_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-lm32.c (maybe_set_textrel): Removed.
(lm32_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-m32r.c (maybe_set_textrel): Removed.
(m32r_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-metag.c (maybe_set_textrel): Removed.
(elf_metag_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-nds32.c (maybe_set_textrel): Removed.
(nds32_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-or1k.c (maybe_set_textrel): Removed.
(or1k_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-ppc.c (maybe_set_textrel): Removed.
(ppc_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-s390.c (maybe_set_textrel): Removed.
(elf_s390_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-sh.c (maybe_set_textrel): Removed.
(sh_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-tic6x.c (maybe_set_textrel): Removed.
(elf32_tic6x_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf32-tilepro.c (maybe_set_textrel): Removed.
(tilepro_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf64-ppc.c (maybe_set_textrel): Removed.
(ppc64_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elf64-s390.c (maybe_set_textrel): Removed.
(elf_s390_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elfnn-aarch64.c (maybe_set_textrel): Removed.
(elfNN_aarch64_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elfnn-riscv.c (maybe_set_textrel): Removed.
(riscv_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elfxx-sparc.c (maybe_set_textrel): Removed.
(_bfd_sparc_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elfxx-tilegx.c (maybe_set_textrel): Removed.
(tilegx_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elfxx-x86.c (maybe_set_textrel): Removed.
(_bfd_x86_elf_size_dynamic_sections): Replace maybe_set_textrel
with _bfd_elf_maybe_set_textrel.
* elflink.c (_bfd_elf_maybe_set_textrel): New.

4 years agoELF: Copy dyn_relocs in _bfd_elf_link_hash_copy_indirect
H.J. Lu [Wed, 3 Jun 2020 14:03:45 +0000 (07:03 -0700)]
ELF: Copy dyn_relocs in _bfd_elf_link_hash_copy_indirect

Copy dyn_relocs in _bfd_elf_link_hash_copy_indirect instead of in each
target backend.

PR ld/26067
* elf32-arm.c (elf32_arm_copy_indirect_symbol): Don't copy
dyn_relocs.
* elf32-csky.c (csky_elf_copy_indirect_symbol): Likewise.
* elf32-hppa.c (elf32_hppa_copy_indirect_symbol): Likewise.
* elf32-metag.c (elf_metag_copy_indirect_symbol): Likewise.
* elf32-microblaze.c (microblaze_elf_copy_indirect_symbol):
Likewise.
* elf32-nds32.c (nds32_elf_copy_indirect_symbol): Likewise.
* elf32-nios2.c (nios2_elf32_copy_indirect_symbol): Likewise.
* elf32-or1k.c (or1k_elf_copy_indirect_symbol): Likewise.
* elf32-s390.c (elf_s390_copy_indirect_symbol): Likewise.
* elf32-sh.c (sh_elf_copy_indirect_symbol): Likewise.
* elf32-tilepro.c (tilepro_elf_copy_indirect_symbol): Likewise.
* elf64-s390.c (elf_s390_copy_indirect_symbol): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_copy_indirect_symbol): Likewise.
* elfnn-riscv.c (riscv_elf_copy_indirect_symbol): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_copy_indirect_symbol): Likewise.
* elfxx-tilegx.c (tilegx_elf_copy_indirect_symbol): Likewise.
* elfxx-x86.c (_bfd_x86_elf_copy_indirect_symbol): Likewise.
* elf32-lm32.c (lm32_elf_copy_indirect_symbol): Removed.
(elf_backend_copy_indirect_symbol): Likewise.
* elf32-m32r.c (m32r_elf_copy_indirect_symbol): Removed.
(elf_backend_copy_indirect_symbol): Likewise.
* elflink.c (_bfd_elf_link_hash_copy_indirect): Copy dyn_relocs.

4 years agoELF: Consolidate readonly_dynrelocs
H.J. Lu [Wed, 3 Jun 2020 14:00:55 +0000 (07:00 -0700)]
ELF: Consolidate readonly_dynrelocs

All readonly_dynrelocs implementations are the same.  Consolidate them
to a single _bfd_elf_readonly_dynrelocs.

PR ld/26067
* elf-bfd.h (_bfd_elf_readonly_dynrelocs): New.
* elf32-arm.c (readonly_dynrelocs): Removed.
(maybe_set_textrel): Replace readonly_dynrelocs with
_bfd_elf_readonly_dynrelocs.
* elf32-csky.c (readonly_dynrelocs): Removed.
(maybe_set_textrel): Replace readonly_dynrelocs with
_bfd_elf_readonly_dynrelocs.
*  elf32-hppa.c(readonly_dynrelocs): Removed.
(alias_readonly_dynrelocs): Replace readonly_dynrelocs with
_bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elf32-lm32.c (readonly_dynrelocs): Removed.
(lm32_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elf32-m32r.c (readonly_dynrelocs): Removed.
(m32r_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elf32-metag.c (readonly_dynrelocs): Removed.
(elf_metag_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elf32-microblaze.c (readonly_dynrelocs): Removed.
(microblaze_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
* elf32-nds32.c (readonly_dynrelocs): Removed.
(nds32_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elf32-or1k.c (readonly_dynrelocs): Removed.
(or1k_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
* elf32-ppc.c (readonly_dynrelocs): Removed.
(alias_readonly_dynrelocs): Replace readonly_dynrelocs with
_bfd_elf_readonly_dynrelocs.
(ppc_elf_adjust_dynamic_symbol): Likewise.
(maybe_set_textrel): Likewise.
* elf32-s390.c (readonly_dynrelocs): Removed.
(elf_s390_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elf32-sh.c (readonly_dynrelocs): Removed.
(sh_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs with
_bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elf32-tic6x.c (readonly_dynrelocs): Removed.
(maybe_set_textrel): Replace readonly_dynrelocs with
_bfd_elf_readonly_dynrelocs.
* elf32-tilepro.c (readonly_dynrelocs): Removed.
(tilepro_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elf64-ppc.c (readonly_dynrelocs): Removed.
(alias_readonly_dynrelocs): Replace readonly_dynrelocs with
_bfd_elf_readonly_dynrelocs.
(ppc64_elf_adjust_dynamic_symbol): Likewise.
(maybe_set_textrel): Likewise.
* elf64-s390.c (readonly_dynrelocs): Removed.
(elf_s390_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elflink.c (_bfd_elf_readonly_dynrelocs): New.
* elfnn-aarch64.c (readonly_dynrelocs): Removed.
(maybe_set_textrel): Replace readonly_dynrelocs with
_bfd_elf_readonly_dynrelocs.
* elfnn-riscv.c (readonly_dynrelocs): Removed.
(riscv_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elfxx-sparc.c (readonly_dynrelocs): Removed.
(_bfd_sparc_elf_adjust_dynamic_symbol): Replace
readonly_dynrelocs with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elfxx-tilegx.c (readonly_dynrelocs): Removed.
(tilegx_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
with _bfd_elf_readonly_dynrelocs.
(maybe_set_textrel): Likewise.
* elfxx-x86.c (readonly_dynrelocs): Removed.
(maybe_set_textrel): Replace readonly_dynrelocs with
_bfd_elf_readonly_dynrelocs.
(_bfd_x86_elf_adjust_dynamic_symbol): Likewise.

4 years agold: Pass -fno-sanitize=all to tests with linker
H.J. Lu [Wed, 3 Jun 2020 13:47:38 +0000 (06:47 -0700)]
ld: Pass -fno-sanitize=all to tests with linker

When binutils is compiled with -fsanitize=undefined, many tests with
linker, instead of $CC, fail with undefined symbol references to sanitize
library.  Define NOSANTIZE_CFLAGS to -fno-sanitize=all if target compiler
supports it and compile such tests with $NOSANTIZE_CFLAGS.

* testsuite/config/default.exp (NOSANTIZE_CFLAGS): New.
* testsuite/ld-elf/linux-x86.exp: Add $NOSANTIZE_CFLAGS to
tests with run_ld_link_exec_tests.
* testsuite/ld-elf/shared.exp: Add $NOSANTIZE_CFLAGS to tests
with run_ld_link_tests.
* testsuite/ld-elf/tls.exp: Likewise.
* testsuite/ld-elfweak/elfweak.exp: Add $NOSANTIZE_CFLAGS to
tests with ld_link.
* testsuite/ld-gc/gc.exp: Add $NOSANTIZE_CFLAGS to cflags.
* testsuite/ld-plugin/lto.exp: Add $NOSANTIZE_CFLAGS to tests
with run_ld_link_tests.a
* testsuite/ld-plugin/plugin.exp: Append $NOSANTIZE_CFLAGS to
CFLAGS.
* testsuite/ld-selective/selective.exp: Add $NOSANTIZE_CFLAGS
to cflags and cxxflags.
* testsuite/ld-srec/srec.exp: Append $NOSANTIZE_CFLAGS to CC
and CXX.
* testsuite/ld-x86-64/plt-main-ibt-x32.dd: Updated for
-fsanitize=undefined.
* testsuite/ld-x86-64/plt-main-ibt.dd: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Add $NOSANTIZE_CFLAGS to
tests with run_cc_link_tests and run_ld_link_tests.

4 years agold: Add --export-dynamic-symbol and --export-dynamic-symbol-list
Fangrui Song [Wed, 3 Jun 2020 13:37:39 +0000 (06:37 -0700)]
ld: Add --export-dynamic-symbol and --export-dynamic-symbol-list

--export-dynamic-symbol-list is like a dynamic list, but without
the symbolic property for unspecified symbols.

When creating an executable, --export-dynamic-symbol-list is treated
like --dynamic-list.

When creating a shared library, it is treated like --dynamic-list if
-Bsymbolic or --dynamic-list are used,  otherwise, it is ignored, so
that references to matched symbols will not be bound to the definitions
within the shared library.

PR ld/25910
* NEWS: Mention --export-dynamic-symbol[-list].
* ld.texi: Document --export-dynamic-symbol[-list].
* ldgram.y: Pass current_dynamic_list_p to
lang_append_dynamic_list.
* ldlang.c (current_dynamic_list_p): New.
(ang_append_dynamic_list): Updated to take a pointer to
struct bfd_elf_dynamic_list * argument instead of using
link_info.dynamic_list.
(lang_append_dynamic_list_cpp_typeinfo): Pass
&link_info.dynamic_list to ang_append_dynamic_list.
(lang_append_dynamic_list_cpp_new): Likewise.
* ldlang.h (current_dynamic_list_p): New.
(lang_append_dynamic_list): Add a pointer to
struct bfd_elf_dynamic_list * argument.
* ldlex.h (option_values): Add OPTION_EXPORT_DYNAMIC_SYMBOL and
OPTION_EXPORT_DYNAMIC_SYMBOL_LIST.
* lexsup.c (ld_options): Add entries for
OPTION_EXPORT_DYNAMIC_SYMBOL and
OPTION_EXPORT_DYNAMIC_SYMBOL_LIST.
(parse_args): Handle --export-dynamic-symbol and
--export-dynamic-symbol-list.
* testsuite/ld-dynamic/export-dynamic-symbol-1.d: New.
* testsuite/ld-dynamic/export-dynamic-symbol-2.d: New.
* testsuite/ld-dynamic/export-dynamic-symbol-glob.d: New.
* testsuite/ld-dynamic/export-dynamic-symbol-list-1.d: New.
* testsuite/ld-dynamic/export-dynamic-symbol-list-2.d: New.
* testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d: New.
* testsuite/ld-dynamic/export-dynamic-symbol.exp: New.
* testsuite/ld-dynamic/export-dynamic-symbol.s: New.
* testsuite/ld-dynamic/foo-bar.list: New.
* testsuite/ld-dynamic/foo.list: New.
* testsuite/ld-dynamic/foo.s: New.
* testsuite/ld-dynamic/fstar.list: New.
* testsuite/ld-elf/dlempty.list: New.
* testsuite/ld-elf/shared.exp: Add tests for
--export-dynamic-symbol and --export-dynamic-symbol-list.

4 years agox86: Silence -fsanitize=undefined
H.J. Lu [Wed, 3 Jun 2020 13:32:24 +0000 (06:32 -0700)]
x86: Silence -fsanitize=undefined

Replace "&(EH)->elf" with "(struct elf_link_hash_entry *) (EH)" to
silence -fsanitize=undefined.

* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): Replace
"&(EH)->elf" with "(struct elf_link_hash_entry *) (EH)".

4 years agold: fix ld-elf/linux-x86.exp for r/o source tree
Jan Beulich [Wed, 3 Jun 2020 09:54:11 +0000 (11:54 +0200)]
ld: fix ld-elf/linux-x86.exp for r/o source tree

Since the copying ofthe individual files gets done more than once, make
sure the destinations can be copied to on subsequent copying attempts.

4 years agoPR26069, strip/objcopy misaligned address accesses
Alan Modra [Wed, 3 Jun 2020 07:28:55 +0000 (16:58 +0930)]
PR26069, strip/objcopy misaligned address accesses

PR 26069
PR 18758
* peicode.h (pe_ILF_make_a_section): Align data for compilers
other than gcc.
(pe_ILF_build_a_bfd): Likewise.

4 years agoPR26069, strip/objcopy memory leaks
Alan Modra [Wed, 3 Jun 2020 07:25:39 +0000 (16:55 +0930)]
PR26069, strip/objcopy memory leaks

PR 26069
* objcopy.c (copy_relocations_in_section): Free relpp on error.
Don't accidentally free isection->orelocation.

4 years agoPR26069, strip/objcopy memory leaks
Alan Modra [Wed, 3 Jun 2020 06:03:01 +0000 (15:33 +0930)]
PR26069, strip/objcopy memory leaks

PR 26029
* elf.c (_bfd_elf_close_and_cleanup): Free elf_shstrtab for
core files as well as objects.

4 years agoRISC-V: Fix minor bugs in .insn docs.
Jim Wilson [Wed, 3 Jun 2020 01:36:14 +0000 (18:36 -0700)]
RISC-V: Fix minor bugs in .insn docs.

This fixes some minor bugs in the docs for the .insn directive pointed out
by Frédéric Pétrot, and I added a few more cleanups since I was changing
the docs.

gas/
PR 26051
* doc/c-riscv.texi (RISC-V-Formats): Add missing I format using
simm12(rs1).  Correct S format to use simm12(rs1).  Drop SB and B
formats using simm12(rs1).  Correct SB and B to use rs1 and rs2.
Move B before SB.  Move J before UJ.

4 years agoRISC-V: Fix the error when building RISC-V linux native gdbserver.
Nelson Chu [Tue, 2 Jun 2020 01:44:13 +0000 (09:44 +0800)]
RISC-V: Fix the error when building RISC-V linux native gdbserver.

The original report is as follow,
https://sourceware.org/pipermail/binutils/2020-June/111383.html

Inlcude the bfd.h in the include/opcode/riscv.h may cause gdbserver fail
to build.  I just want to use the `bfd_boolean` in the opcodes/riscv-opc.c,
but I didn't realize this cause the build failed.  Fortunately, I can also
use the `int` as the function return types just like others in the
opcodes/riscv-opc.c.

include/
* opcode/riscv.h: Remove #include "bfd.h".  And change the return
types of riscv_get_isa_spec_class and riscv_get_priv_spec_class
from bfd_boolean to int.

opcodes/
* riscv-opc.c (riscv_get_isa_spec_class): Change bfd_boolean to int.
(riscv_get_priv_spec_class): Likewise.

4 years agoAutomatic date update in version.in
GDB Administrator [Wed, 3 Jun 2020 00:00:09 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogdb: Convert language skip_trampoline field to a method
Andrew Burgess [Thu, 14 May 2020 22:19:48 +0000 (23:19 +0100)]
gdb: Convert language skip_trampoline field to a method

This commit changes the language_data::skip_trampoline function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Delete skip_trampoline
initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(cplus_language::skip_trampoline): New member function.
(asm_language_data): Delete skip_trampoline initializer.
(minimal_language_data): Likewise.
* d-lang.c (d_language_data): Likewise.
* f-lang.c (f_language_data): Likewise.
* go-lang.c (go_language_data): Likewise.
* language.c (unk_lang_trampoline): Delete function.
(skip_language_trampoline): Update.
(unknown_language_data): Delete skip_trampoline initializer.
(auto_language_data): Likewise.
* language.h (language_data): Delete skip_trampoline field.
(language_defn::skip_trampoline): New function.
* m2-lang.c (m2_language_data): Delete skip_trampoline
initializer.
* objc-lang.c (objc_skip_trampoline): Delete function, move
implementation to objc_language::skip_trampoline.
(objc_language_data): Delete skip_trampoline initializer.
(objc_language::skip_trampoline): New member function with
implementation from objc_skip_trampoline.
* opencl-lang.c (opencl_language_data): Delete skip_trampoline
initializer.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.

4 years agogdb: Convert language la_demangle field to a method
Andrew Burgess [Thu, 14 May 2020 18:03:45 +0000 (19:03 +0100)]
gdb: Convert language la_demangle field to a method

This commit changes the language_data::la_demangle function pointer
member variable into a member function of language_defn.

The only slightly "weird" change in this commit is in f-lang.c, where
I have given the Fortran language a demangle method that is identical
to the default language_defn::demangle.  The only reason for this is
to give me somewhere to copy the comment that was previously embedded
within the f_language_data structure.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Delete la_demangle initializer.
(ada_language::demangle): New member function.
* c-lang.c (c_language_data): Delete la_demangle initializer.
(cplus_language_data): Delete la_demangle initializer.
(cplus_language::demangle): New member function.
(asm_language_data): Delete la_demangle initializer.
(minimal_language_data): Delete la_demangle initializer.
* d-lang.c (d_language_data): Delete la_demangle initializer.
(d_language::demangle): New member function.
* f-lang.c (f_language_data): Delete la_demangle initializer.
(f_language::demangle): New member function.
* go-lang.c (go_language_data): Delete la_demangle initializer.
(go_language::demangle): New member function.
* language.c (language_demangle): Update.
(unk_lang_demangle): Delete.
(unknown_language_data): Delete la_demangle initializer.
(unknown_language::demangle): New member function.
(auto_language_data): Delete la_demangle initializer.
(auto_language::demangle): New member function.
* language.h (language_data): Delete la_demangle field.
(language_defn::demangle): New function.
* m2-lang.c (m2_language_data): Delete la_demangle initializer.
* objc-lang.c (objc_language_data): Delete la_demangle
initializer.
(objc_language::demangle): New member function.
* opencl-lang.c (opencl_language_data): Delete la_demangle
initializer.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.
(rust_language::demangle): New member functi

4 years agogdb: Convert language la_print_type field to a method
Andrew Burgess [Thu, 14 May 2020 17:41:39 +0000 (18:41 +0100)]
gdb: Convert language la_print_type field to a method

This commit changes the language_data::la_print_type function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Delete la_print_type
initializer.
(ada_language::print_type): New member function.
* c-lang.c (c_language_data): Delete la_print_type initializer.
(c_language::print_type): New member function.
(cplus_language_data): Delete la_print_type initializer.
(cplus_language::print_type): New member function.
(asm_language_data): Delete la_print_type initializer.
(asm_language::print_type): New member function.
(minimal_language_data): Delete la_print_type initializer.
(minimal_language::print_type): New member function.
* d-lang.c (d_language_data): Delete la_print_type initializer.
(d_language::print_type): New member function.
* f-lang.c (f_language_data): Delete la_print_type initializer.
(f_language::print_type): New member function.
* go-lang.c (go_language_data): Delete la_print_type initializer.
(go_language::print_type): New member function.
* language.c (unk_lang_print_type): Delete.
(unknown_language_data): Delete la_print_type initializer.
(unknown_language::print_type): New member function.
(auto_language_data): Delete la_print_type initializer.
(auto_language::print_type): New member function.
* language.h (language_data): Delete la_print_type field.
(language_defn::print_type): New function.
(LA_PRINT_TYPE): Update.
* m2-lang.c (m2_language_data): Delete la_print_type initializer.
(m2_language::print_type): New member function.
* objc-lang.c (objc_language_data): Delete la_print_type
initializer.
(objc_language::print_type): New member function.
* opencl-lang.c (opencl_print_type): Delete, implementation moved
to opencl_language::print_type.
(opencl_language_data): Delete la_print_type initializer.
(opencl_language::print_type): New member function, implementation
from opencl_print_type.
* p-lang.c (pascal_language_data): Delete la_print_type
initializer.
(pascal_language::print_type): New member function.
* rust-lang.c (rust_print_type): Delete, implementation moved to
rust_language::print_type.
(rust_language_data): Delete la_print_type initializer.
(rust_language::print_type): New member function, implementation
from rust_print_type.

4 years agogdb: Convert language la_sniff_from_mangled_name field to a method
Andrew Burgess [Wed, 13 May 2020 17:04:30 +0000 (18:04 +0100)]
gdb: Convert language la_sniff_from_mangled_name field to a method

This commit changes the language_data::la_sniff_from_mangled_name
function pointer member variable into a member function of
language_defn.

Previously the la_sniff_from_mangled_name pointer was NULL for some
languages, however, all uses of this function pointer were through the
function language_sniff_from_mangled_name which provided a default
implementation.

This default implementation now becomes the implementation in the base
class language_defn, which is then overridden as required in various
language sub-classes.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_sniff_from_mangled_name): Delete function,
implementation moves to...
(ada_language::sniff_from_mangled_name): ...here.  Update return
type.
(ada_language_data): Delete la_sniff_from_mangled_name
initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(cplus_language::sniff_from_mangled_name): New member function,
implementation taken from gdb_sniff_from_mangled_name.
(asm_language_data): Delete la_sniff_from_mangled_name
initializer.
(minimal_language_data): Likewise.
* cp-support.c (gdb_sniff_from_mangled_name): Delete,
implementation moves to cplus_language::sniff_from_mangled_name.
* cp-support.h (gdb_sniff_from_mangled_name): Delete declaration.
* d-lang.c (d_sniff_from_mangled_name): Delete, implementation
moves to...
(d_language::sniff_from_mangled_name): ...here.
(d_language_data): Delete la_sniff_from_mangled_name initializer.
* f-lang.c (f_language_data): Likewise.
* go-lang.c (go_sniff_from_mangled_name): Delete, implementation
moves to...
(go_language::sniff_from_mangled_name): ...here.
(go_language_data): Delete la_sniff_from_mangled_name initializer.
* language.c (language_sniff_from_mangled_name): Delete.
(unknown_language_data): Delete la_sniff_from_mangled_name
initializer.
(auto_language_data): Likewise.
* language.h (language_data): Delete la_sniff_from_mangled_name
field.
(language_defn::sniff_from_mangled_name): New function.
(language_sniff_from_mangled_name): Delete declaration.
* m2-lang.c (m2_language_data): Delete la_sniff_from_mangled_name
field.
* objc-lang.c (objc_sniff_from_mangled_name): Delete,
implementation moves to...
(objc_language::sniff_from_mangled_name): ...here.
(objc_language_data): Delete la_sniff_from_mangled_name initializer.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_sniff_from_mangled_name): Delete,
implementation moves to...
(rust_language::sniff_from_mangled_name): ...here.
(rust_language_data): Delete la_sniff_from_mangled_name
initializer.
* symtab.c (symbol_find_demangled_name): Call
sniff_from_mangled_name member function.

4 years agogdb: Convert language la_search_name_hash field to a method
Andrew Burgess [Sat, 2 May 2020 09:24:05 +0000 (10:24 +0100)]
gdb: Convert language la_search_name_hash field to a method

This commit changes the language_data::la_search_name_hash
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Delete la_search_name_hash
initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(cplus_language::search_name_hash): New member function.
(asm_language_data): Delete la_search_name_hash initializer.
(minimal_language_data): Likewise.
* d-lang.c (d_language_data): Likewise.
* dictionary.c (default_search_name_hash): Rename to...
(language_defn::search_name_hash): ...this.
* f-lang.c (f_language_data): Likewise.
(f_language::search_name_hash): New member function.
* go-lang.c (go_language_data): Delete la_search_name_hash
initializer.
* language.c (unknown_language_data): Likewise.
(auto_language_data): Likewise.
* language.h (struct language_data): Delete la_search_name_hash
field.
(language_defn::search_name_hash): Declare new member function.
(default_search_name_hash): Delete declaration.
* m2-lang.c (m2_language_data): Delete la_search_name_hash
initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.
* symtab.c (search_name_hash): Update call.

4 years agogdb: Convert language la_get_compile_instance field to a method
Andrew Burgess [Sat, 2 May 2020 08:12:30 +0000 (09:12 +0100)]
gdb: Convert language la_get_compile_instance field to a method

This commit changes the language_data::la_get_compile_instance
function pointer member variable into a member function of
language_defn.  Unlike previous commits converting fields of
language_data to member function in language_defn, this field is NULL
for some languages.  As a result I had to change the API slightly so
that the base language_defn class provides an implementation.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Delete la_get_compile_instance
initializer.
* c-lang.c (class compile_instance): Declare.
(c_language_data): Delete la_get_compile_instance initializer.
(c_language::get_compile_instance): New member function.
(cplus_language_data): Delete la_get_compile_instance initializer.
(cplus_language::get_compile_instance): New member function.
(asm_language_data): Delete la_get_compile_instance initializer.
(minimal_language_data): Likewise.
* c-lang.h (c_get_compile_context): Update comment.
(cplus_get_compile_context): Update comment.
* compile/compile.c (compile_to_object): Update calls, don't rely
on function pointer being NULL.
* d-lang.c (d_language_data): Delete la_get_compile_instance
initializer.
* f-lang.c (f_language_data): Likewise.
* go-lang.c (go_language_data): Likewise.
* language.c (unknown_language_data): Likewise.
(auto_language_data): Likewise.
* language.h (language_data): Delete la_get_compile_instance field.
(language_defn::get_compile_instance): New member function.
* m2-lang.c (m2_language_data): Delete la_get_compile_instance
initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.

4 years agogdb: Convert language la_iterate_over_symbols field to a method
Andrew Burgess [Fri, 1 May 2020 21:42:21 +0000 (22:42 +0100)]
gdb: Convert language la_iterate_over_symbols field to a method

This commit changes the language_data::la_iterate_over_symbols
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_add_all_symbols): Update comment.
(ada_iterate_over_symbols): Delete, move implementation to...
(ada_language::iterate_over_symbols): ...here, a new member
function, rewrite to use range based for loop.
(ada_language_data): Delete la_iterate_over_symbols initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(asm_language_data): Likewise.
(minimal_language_data): Likewise.
* d-lang.c (d_language_data): Likewise.
* f-lang.c (f_language_data): Likewise.
* go-lang.c (go_language_data): Likewise.
* language.c (unknown_language_data): Likewise.
(auto_language_data): Likewise.
* language.h (language_data): Delete la_iterate_over_symbols field.
(language_defn::iterate_over_symbols): New member function.
(LA_ITERATE_OVER_SYMBOLS): Update.
* linespec.c (iterate_over_all_matching_symtabs): Update.
* m2-lang.c (m2_language_data): Delete la_iterate_over_symbols
initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.

4 years agogdb: Convert language la_lookup_transparent_type field to a method
Andrew Burgess [Fri, 1 May 2020 21:12:12 +0000 (22:12 +0100)]
gdb: Convert language la_lookup_transparent_type field to a method

This commit changes the language_data::la_lookup_transparent_type
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Delete
la_lookup_transparent_type initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(cplus_language::lookup_transparent_type): New member function.
(asm_language_data): Delete la_lookup_transparent_type
initializer.
(minimal_language_data): Likewise.
* d-lang.c (d_language_data): Likewise.
* f-lang.c (f_language_data): Likewise.
* go-lang.c (go_language_data): Likewise.
* language.c (unknown_language_data): Likewise.
(auto_language_data): Likewise.
* language.h (struct language_data): Delete
la_lookup_transparent_type field.
(language_defn::lookup_transparent_type): New member function.
* m2-lang.c (m2_language_data): Delete la_lookup_transparent_type
initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.
* symtab.c (symbol_matches_domain): Update call.

4 years agogdb: Convert language la_language_arch_info field to a method
Andrew Burgess [Fri, 1 May 2020 20:51:15 +0000 (21:51 +0100)]
gdb: Convert language la_language_arch_info field to a method

This commit changes the language_data::la_language_arch_info function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_arch_info): Delete function, move
implementation to...
(ada_language::language_arch_info): ...here, a new member
function.
(ada_language_data): Delete la_language_arch_info.
* c-lang.c (c_language_data): Likewise.
(c_language::language_arch_info): New member function.
(cplus_language_arch_info): Delete function, move
implementation to...
(cplus_language::language_arch_info): ...here, a new member
function.
(cplus_language_data): Delete la_language_arch_info.
(asm_language_data): Likewise.
(asm_language::language_arch_info): New member function.
(minimal_language_data): Delete la_language_arch_info.
(minimal_language::language_arch_info): New member function.
* d-lang.c (d_language_arch_info): Delete function, move
implementation to...
(d_language::language_arch_info): ...here, a new member
function.
(d_language_data): Delete la_language_arch_info.
* f-lang.c (f_language_arch_info): Delete function, move
implementation to...
(f_language::language_arch_info): ...here, a new member
function.
(f_language_data): Delete la_language_arch_info.
* go-lang.c (go_language_arch_info): Delete function, move
implementation to...
(go_language::language_arch_info): ...here, a new member
function.
(go_language_data): Delete la_language_arch_info.
* language.c (unknown_language_data): Likewise.
(unknown_language::language_arch_info): New member function.
(auto_language_data): Delete la_language_arch_info.
(auto_language::language_arch_info): New member function.
(language_gdbarch_post_init): Update call to
la_language_arch_info.
* language.h (language_data): Delete la_language_arch_info
function pointer.
(language_defn::language_arch_info): New function.
* m2-lang.c (m2_language_arch_info): Delete function, move
implementation to...
(m2_language::language_arch_info): ...here, a new member
function.
(m2_language_data): Delete la_language_arch_info.
* objc-lang.c (objc_language_arch_info): Delete function, move
implementation to...
(objc_language::language_arch_info): ...here, a new member
function.
(objc_language_data): Delete la_language_arch_info.
* opencl-lang.c (opencl_language_arch_info): Delete function, move
implementation to...
(opencl_language::language_arch_info): ...here, a new member
function.
(opencl_language_data): Delete la_language_arch_info.
* p-lang.c (pascal_language_arch_info): Delete function, move
implementation to...
(pascal_language::language_arch_info): ...here, a new member
function.
(pascal_language_data): Delete la_language_arch_info.
* rust-lang.c (rust_language_arch_info): Delete function, move
implementation to...
(rust_language::language_arch_info): ...here, a new member
function.
(rust_language_data): Delete la_language_arch_info.

4 years agogdb: Convert language la_pass_by_reference field to a method
Andrew Burgess [Fri, 1 May 2020 20:20:06 +0000 (21:20 +0100)]
gdb: Convert language la_pass_by_reference field to a method

This commit changes the language_data::la_pass_by_reference function
pointer member variable into a member function of language_defn.

The interesting thing in this commit is that I have removed the
default_pass_by_reference function entirely.  This function only ever
returned a language_pass_by_ref_info struct in its default state, so
all uses of this function can be replaced by just default
initialisation of a language_pass_by_ref_info variable.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Delete la_pass_by_reference
initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(cplus_language::pass_by_reference_info): New method.
(asm_language_data): Delete la_pass_by_reference initializer.
(minimal_language_data): Likewise.
* cp-abi.c (cp_pass_by_reference): Remove use of
default_pass_by_reference.
* d-lang.c (d_language_data): Likewise.
* f-lang.c (f_language_data): Likewise.
* gnu-v3-abi.c (gnuv3_pass_by_reference): Remove use of
default_pass_by_reference.
* go-lang.c (go_language_data): Likewise.
* language.c (language_pass_by_reference): Update.
(default_pass_by_reference): Delete.
(unknown_language_data): Delete la_pass_by_reference
initializer.
(auto_language_data): Likewise.
* language.h (struct language_data): Delete la_pass_by_reference
field.
(language_defn::pass_by_reference_info): New member function.
(default_pass_by_reference): Delete declaration.
* m2-lang.c (m2_language_data): Delete la_pass_by_reference
initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.

4 years agogdb: Convert language la_read_var_value field to a method
Andrew Burgess [Fri, 1 May 2020 16:33:22 +0000 (17:33 +0100)]
gdb: Convert language la_read_var_value field to a method

This commit changes the language_data::la_read_var_value function
pointer member variable into a member function of language_defn.

An interesting aspect of this change is that the implementation of
language_defn::read_var_value is actually in findvar.c.  This is
partly historical, the new language_defn::read_var_value is a rename
of default_read_var_value, which was already in that file, but also,
that is the file that contains the helper functions needed by the
read_var_value method, so it makes sens that the method implementation
should continue to live there (I think).

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_read_var_value): Delete function, move
implementation to...
(ada_language::read_var_value): ...here.
(ada_language_data): Delete la_read_var_value initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(minimal_language_data): Likewise.
* d-lang.c (d_language_data): Likewise.
* f-lang.c (f_language_data): Likewise.
* findvar.c (default_read_var_value): Rename to...
(language_defn::read_var_value): ...this.
* findvar.c (read_var_value): Update header comment, and change to
call member function instead of function pointer.
* go-lang.c (go_language_data): Likewise.
* language.c (unknown_language_data): Delete la_read_var_value
initializer.
(auto_language_data): Likewise.
* language.h (struct language_data): Delete la_read_var_value
field.
(language_defn::read_var_value): New member function.
(default_read_var_value): Delete declaration.
* m2-lang.c (m2_language_data): Delete la_read_var_value
initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.
* value.h (default_read_var_value): Delete declaration.

4 years agogdb: Convert language la_print_array_index field to a method
Andrew Burgess [Fri, 1 May 2020 16:18:36 +0000 (17:18 +0100)]
gdb: Convert language la_print_array_index field to a method

This commit changes the language_data::la_print_array_index function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_print_array_index): Delete function, move
implementation to...
(ada_language::print_array_index): ...here.
(ada_language_data): Delete la_print_array_index initializer.
* c-lang.c (c_language_data): Likewise.
(cplus_language_data): Likewise.
(minimal_language_data): Likewise.
* d-lang.c (d_language_data): Likewise.
* f-lang.c (f_language_data): Likewise.
* go-lang.c (go_language_data): Likewise.
* language.c (default_print_array_index): Delete function, move
implementation to...
(language_defn::print_array_index): ...here.
(unknown_language_data): Delete la_print_array_index initializer.
(auto_language_data): Likewise.
* language.h (struct language_data): Delete la_print_array_index
field.
(language_defn::print_array_index): New member function.
(LA_PRINT_ARRAY_INDEX): Update.
(default_print_array_index): Delete declaration.
* m2-lang.c (m2_language_data): Delete la_print_array_index
initializer.
* objc-lang.c (objc_language_data): Likewise.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.

4 years agogdb: Represent all languages as sub-classes of language_defn
Andrew Burgess [Fri, 1 May 2020 11:16:58 +0000 (12:16 +0100)]
gdb: Represent all languages as sub-classes of language_defn

This commit converts all languages to sub-classes of a language_defn
base class.

The motivation for this change is to make it easier to add new methods
onto languages without having to update all of the individual language
structures.  In the future it might be possible to move more things,
like expression parsing, into the language class(es) for better
encapsulation, however I have no plans to tackle this in the short
term.

This commit sets up a strategy for transitioning from the current
language system, where each language is an instance of the
language_defn structure, to the class hierarchy system.

The plan is to rename the existing language_defn into language_data,
and make this a base class for the new language_defn class, something
like this:

  struct language_data
  {
    ... old language_defn fields here ...
  };

  struct language_defn : public language_data
  {
    language_defn (const language_data d)
      : language_data (d)
    { .... }
  };

Then each existing language, for example ada_language_defn can be
converted into an instance of language_data, and passed into the
constructor of a new language class, something like this:

  language_data ada_language_data =
  {
    ... old ada_language_defn values here ...
  };

  struct ada_language : public language_defn
  {
    ada_language (ada_language_data)
    { .... }
  };

What this means is that immediately after the conversion nothing much
changes.  Every language is now its own class, but all the old
language fields still exist and can be accessed in the same way.

In later commits I will convert function pointers from the old
language_defn structure into real class methods on language_defn, with
overrides on sub-classes where needed.

At this point I imagine that those fields of the old language_defn
structure that contained only data will probably remain as data fields
within the new language_data base structure, it is only the methods
that I plan to change initially.

I tweaked how we manage the list of languages a bit, each language is
now registered as it is created, and this resulted in a small number
of changes in language.c.

Most of the changes in the *-lang.c files are identical.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* gdb/ada-lang.c (ada_language_defn): Convert to...
(ada_language_data): ...this.
(class ada_language): New class.
(ada_language_defn): New static global.
* gdb/c-lang.c (c_language_defn): Convert to...
(c_language_data): ...this.
(class c_language): New class.
(c_language_defn): New static global.
(cplus_language_defn): Convert to...
(cplus_language_data): ...this.
(class cplus_language): New class.
(cplus_language_defn): New static global.
(asm_language_defn): Convert to...
(asm_language_data): ...this.
(class asm_language): New class.
(asm_language_defn): New static global.
(minimal_language_defn): Convert to...
(minimal_language_data): ...this.
(class minimal_language): New class.
(minimal_language_defn): New static global.
* gdb/d-lang.c (d_language_defn): Convert to...
(d_language_data): ...this.
(class d_language): New class.
(d_language_defn): New static global.
* gdb/f-lang.c (f_language_defn): Convert to...
(f_language_data): ...this.
(class f_language): New class.
(f_language_defn): New static global.
* gdb/go-lang.c (go_language_defn): Convert to...
(go_language_data): ...this.
(class go_language): New class.
(go_language_defn): New static global.
* gdb/language.c (unknown_language_defn): Remove declaration.
(current_language): Initialize to nullptr, real initialization is
moved to _initialize_language.
(languages): Delete global.
(language_defn::languages): Define.
(set_language_command): Use language_defn::languages.
(set_language): Likewise.
(range_error): Likewise.
(language_enum): Likewise.
(language_def): Likewise.
(add_set_language_command): Use language_def::languages for the
language list, and language_def to lookup language pointers.
(skip_language_trampoline): Use language_defn::languages.
(unknown_language_defn): Convert to...
(unknown_language_data): ...this.
(class unknown_language): New class.
(unknown_language_defn): New static global.
(auto_language_defn): Convert to...
(auto_language_data): ...this.
(class auto_language): New class.
(auto_language_defn): New static global.
(language_gdbarch_post_init): Use language_defn::languages.
(_initialize_language): Initialize current_language.
* gdb/language.h (struct language_defn): Rename to...
(struct language_data): ...this.
(struct language_defn): New.
(auto_language_defn): Delete.
(unknown_language_defn): Delete.
(minimal_language_defn): Delete.
(ada_language_defn): Delete.
(asm_language_defn): Delete.
(c_language_defn): Delete.
(cplus_language_defn): Delete.
(d_language_defn): Delete.
(f_language_defn): Delete.
(go_language_defn): Delete.
(m2_language_defn): Delete.
(objc_language_defn): Delete.
(opencl_language_defn): Delete.
(pascal_language_defn): Delete.
(rust_language_defn): Delete.
* gdb/m2-lang.c (m2_language_defn): Convert to...
(m2_language_data): ...this.
(class m2_language): New class.
(m2_language_defn): New static global.
* gdb/objc-lang.c (objc_language_defn): Convert to...
(objc_language_data): ...this.
(class objc_language): New class.
(objc_language_defn): New static global.
* gdb/opencl-lang.c (opencl_language_defn): Convert to...
(opencl_language_data): ...this.
(class opencl_language): New class.
(opencl_language_defn): New static global.
* gdb/p-lang.c (pascal_language_defn): Convert to...
(pascal_language_data): ...this.
(class pascal_language): New class.
(pascal_language_defn): New static global.
* gdb/rust-exp.y (rust_lex_tests): Use language_def to find
language pointer, update comment format.
* gdb/rust-lang.c (rust_language_defn): Convert to...
(rust_language_data): ...this.
(class rust_language): New class.
(rust_language_defn): New static global.

4 years ago[gdb/testsuite] Fix scrolling in gdb.dwarf2/multidictionary.exp
Tom de Vries [Tue, 2 Jun 2020 12:20:25 +0000 (14:20 +0200)]
[gdb/testsuite] Fix scrolling in gdb.dwarf2/multidictionary.exp

Consider a gdb_load patch to call the gdb_file_cmd twice:
...
 proc gdb_load { arg } {
     if { $arg != "" } {
+       set res [gdb_file_cmd $arg]
+       if { $res != 0 } {
+           return $res
+       }
        return [gdb_file_cmd $arg]
     }
     return 0
 }
...

With this patch, I run into:
...
(gdb) kill^M
The program is not being run.^M
(gdb) ^M</outputs/gdb.dwarf2/multidictionary/multidictionary^M
<.dwarf2/multidictionary/multidictionary"? (y or n)
ERROR: Couldn't load outputs/gdb.dwarf2/multidictionary/multidictionary \
  into gdb (timeout).
p 1^M
Please answer y or n.^M
<.dwarf2/multidictionary/multidictionary"? (y or n) n^M
Not confirmed.^M
(gdb) UNRESOLVED: gdb.dwarf2/multidictionary.exp: GDB is alive \
  (got interactive prompt)
...

The problem is that the second file command results in a prompt, which is
normally handled by gdb_file_cmd, but not recognized because the initial part
of the prompt is scrolled out.

This in turn is caused by using gdb_spawn_with_cmdline_opts without a
subsequent "set width 0".

Fix this by avoiding gdb_spawn_with_cmdline_opts, and forcing -readline by
temporarily modifying GDBFLAGS instead.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-06-02  Tom de Vries  <tdevries@suse.de>

* gdb.dwarf2/multidictionary.exp: Don't use
gdb_spawn_with_cmdline_opts.

4 years agobinutils archive tests
Alan Modra [Tue, 2 Jun 2020 05:30:14 +0000 (15:00 +0930)]
binutils archive tests

There are a number of targets that don't support thin archives (*),
and vms doesn't even support file name extensions other than .obj for
archives containing object files.  This patch adjusts the testsuite
to cater for the vms restriction, and reenables testing for non-ELF
alpha targets.  That adds a few alpha-dec-vms fails and one
alpha-linuxecoff fail but testsuite fails on those targets are nothing
new.

(*) It might seem like they do if binutils is built with
--enable-plugins but the plugin archive support is broken, causing the
wrong type of archives to be created by ar for those targets.

* testsuite/binutils-all/ar.exp (obj): Set up object file name
extension.  Use throughout.  Don't completely exclude non-ELF
alpha targets.  Run long_filenames test for tic30.  Exclude thin
archive tests for aix, ecoff and vms.
* estsuite/binutils-all/objdump.exp (obj): Set up object file name
extension.  Use throughout.  Don't exclude non-ELF alpha targets
from "bintest.a".

4 years agoELF: Move dyn_relocs to struct elf_link_hash_entry
H.J. Lu [Tue, 2 Jun 2020 01:18:43 +0000 (18:18 -0700)]
ELF: Move dyn_relocs to struct elf_link_hash_entry

All ELF backends with shared library support have

  /* Track dynamic relocs copied for this symbol.  */
  struct elf_dyn_relocs *dyn_relocs;

in symbol hash entry.  Move dyn_relocs to struct elf_link_hash_entry
to reduce code duplication.

PR ld/26067
* elf-bfd.h (elf_link_hash_entry): Add dyn_relocs after size.
* elf-s390-common.c (s390_elf_allocate_ifunc_dyn_relocs):
Updated.
* elf32-arc.c (elf_arc_link_hash_entry): Remove dyn_relocs.
(elf_arc_link_hash_newfunc): Updated.
* elf32-arm.c (elf32_arm_link_hash_entry): Remove dyn_relocs.
(elf32_arm_link_hash_newfunc): Updated.
(elf32_arm_copy_indirect_symbol): Likewise.
(elf32_arm_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs_for_symbol): Likewise.
* elf32-csky.c (csky_elf_link_hash_entry): Remove dyn_relocs.
(csky_elf_link_hash_newfunc): Updated.
(csky_allocate_dynrelocs): Likewise.
(readonly_dynrelocs): Likewise.
(csky_elf_copy_indirect_symbol): Likewise.
* elf32-hppa.c (elf32_hppa_link_hash_entry): Remove dyn_relocs.
(hppa_link_hash_newfunc): Updated.
(elf32_hppa_copy_indirect_symbol): Likewise.
(elf32_hppa_hide_symbol): Likewise.
(elf32_hppa_adjust_dynamic_symbol): Likewise.
(allocate_dynrelocs): Likewise.
(elf32_hppa_relocate_section): Likewise.
* elf32-i386.c (elf_i386_check_relocs): Likewise.
* elf32-lm32.c (elf_lm32_link_hash_entry): Removed.
(lm32_elf_link_hash_newfunc): Likewise.
(lm32_elf_link_hash_table_create): Updated.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
(lm32_elf_copy_indirect_symbol): Likewise.
* elf32-m32r.c (elf_m32r_link_hash_entry): Removed.
(m32r_elf_link_hash_newfunc): Likewise.
(m32r_elf_link_hash_table_create): Updated.
(m32r_elf_copy_indirect_symbol): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-metag.c (elf_metag_link_hash_entry): Remove dyn_relocs.
(metag_link_hash_newfunc): Updated.
(elf_metag_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-microblaze.c (elf32_mb_link_hash_entry): Remove
dyn_relocs.
(link_hash_newfunc): Updated.
(microblaze_elf_check_relocs): Likewise.
(microblaze_elf_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-nds32.c (elf_nds32_link_hash_entry): Remove dyn_relocs.
(nds32_elf_link_hash_newfunc): Updated.
(nds32_elf_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
(nds32_elf_check_relocs): Likewise.
* elf32-nios2.c (elf32_nios2_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(nios2_elf32_copy_indirect_symbol): Likewise.
(nios2_elf32_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-or1k.c (elf_or1k_link_hash_entry): Remove dyn_relocs.
(or1k_elf_link_hash_newfunc): Updated.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
(or1k_elf_copy_indirect_symbol): Likewise.
* elf32-ppc.c (ppc_elf_link_hash_entry): Remove dyn_relocs.
(ppc_elf_link_hash_newfunc): Updated.
(ppc_elf_copy_indirect_symbol): Likewise.
(ppc_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(ppc_elf_adjust_dynamic_symbol): Likewise.
(allocate_dynrelocs): Likewise.
(ppc_elf_relocate_section): Likewise.
* elf32-s390.c (elf_s390_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(elf_s390_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(elf_s390_adjust_dynamic_symbol): Likewise.
(allocate_dynrelocs): Likewise.
* elf32-sh.c (elf_sh_link_hash_entry): Remove dyn_relocs.
(sh_elf_link_hash_newfunc): Updated.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
(sh_elf_copy_indirect_symbol): Likewise.
(sh_elf_check_relocs): Likewise.
* elf32-tic6x.c (elf32_tic6x_link_hash_entry): Removed.
(elf32_tic6x_link_hash_newfunc): Likewise.
(elf32_tic6x_link_hash_table_create): Updated.
(readonly_dynrelocs): Likewise.
(elf32_tic6x_check_relocs): Likewise.
(elf32_tic6x_allocate_dynrelocs): Likewise.
* elf32-tilepro.c (tilepro_elf_link_hash_entry): Remove
dyn_relocs.
(link_hash_newfunc): Updated.
(tilepro_elf_copy_indirect_symbol): Likewise.
(tilepro_elf_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf64-ppc.c (ppc_link_hash_entry): Remove dyn_relocs.
(ppc64_elf_copy_indirect_symbol): Updated.
(ppc64_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(ppc64_elf_adjust_dynamic_symbol): Likewise.
(dec_dynrel_count): Likewise.
(allocate_dynrelocs): Likewise.
(ppc64_elf_relocate_section): Likewise.
* elf64-s390.c (elf_s390_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(elf_s390_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
* elfnn-aarch64.c (elf_aarch64_link_hash_entry): Remove
dyn_relocs.
(elfNN_aarch64_link_hash_newfunc): Updated.
(elfNN_aarch64_copy_indirect_symbol): Likewise.
(readonly_dynrelocs): Likewise.
(need_copy_relocation_p): Likewise.
(elfNN_aarch64_allocate_dynrelocs): Likewise.
(elfNN_aarch64_allocate_ifunc_dynrelocs): Likewise.
* elfnn-riscv.c (riscv_elf_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(riscv_elf_copy_indirect_symbol): Likewise.
(riscv_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_link_hash_entry): Remove
dyn_relocs.
(link_hash_newfunc): Updated.
(_bfd_sparc_elf_copy_indirect_symbol): Likewise.
(_bfd_sparc_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elfxx-tilegx.c (tilegx_elf_link_hash_entry): Remove dyn_relocs.
(link_hash_newfunc): Updated.
(tilegx_elf_copy_indirect_symbol): Likewise.
(tilegx_elf_check_relocs): Likewise.
(readonly_dynrelocs): Likewise.
(allocate_dynrelocs): Likewise.
* elfxx-x86.c (elf_x86_allocate_dynrelocs): Likewise.
(readonly_dynrelocs): Likewise.
(_bfd_x86_elf_copy_indirect_symbol): Likewise.
* elfxx-x86.h (elf_x86_link_hash_entry): Remove dyn_relocs.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 2 Jun 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogas: Fix checking for backwards .org with negative offset
Alex Coplan [Fri, 29 May 2020 15:04:50 +0000 (16:04 +0100)]
gas: Fix checking for backwards .org with negative offset

This patch fixes internal errors in (at least) arm and aarch64 GAS
when assembling code that attempts a negative .org.  The bug appears
to be a regression introduced in binutils-2.29 by commit 9875b36538d.

* write.c (relax_segment): Fix handling of negative offset when
relaxing an rs_org frag.
* testsuite/gas/aarch64/org-neg.d: New test.
* testsuite/gas/aarch64/org-neg.l: Error output for test.
* testsuite/gas/aarch64/org-neg.s: Input for test.
* testsuite/gas/arm/org-neg.d: New test.
* testsuite/gas/arm/org-neg.l: Error output for test.
* testsuite/gas/arm/org-neg.s: Input for test.

4 years agoalpha-vms: ETIR checks
Alan Modra [Mon, 1 Jun 2020 04:51:50 +0000 (14:21 +0930)]
alpha-vms: ETIR checks

Better validity checks, and remove a fuzzer vulnerability of sorts that
targeted the store-immediate-repeat command with a zero length but
very large repeat counts to chew cpu.

* vms-alpha.c (_bfd_vms_slurp_etir): Check bound for the current
command against cmd_length, not the end of record.  For
ETIR__C_STO_IMMR check size against cmd_length, mask repeat count
to 32-bits and break out on zero size.  Add ETIR__C_STC_LP_PSB
cmd_length test.

4 years agoRegen opcodes/bpf-desc.c
Alan Modra [Sat, 30 May 2020 02:46:43 +0000 (12:16 +0930)]
Regen opcodes/bpf-desc.c

The last regen used an old version of cgen.

* bpf-desc.c: Regenerate.

4 years agogdb: Preserve is-stmt lines when switch between files
Andrew Burgess [Fri, 3 Apr 2020 19:32:38 +0000 (20:32 +0100)]
gdb: Preserve is-stmt lines when switch between files

After the is-stmt support commit:

  commit 8c95582da858ac981f689a6f599acacb8c5c490f
  Date:   Mon Dec 30 21:04:51 2019 +0000

      gdb: Add support for tracking the DWARF line table is-stmt field

A regression was observed where a breakpoint could no longer be placed
in some cases.

Consider a line table like this:

  File 1: test.c
  File 2: test.h

  | Addr | File | Line | Stmt |
  |------|------|------|------|
  | 1    | 1    | 16   | Y    |
  | 2    | 1    | 17   | Y    |
  | 3    | 2    | 21   | Y    |
  | 4    | 2    | 22   | Y    |
  | 4    | 1    | 18   | N    |
  | 5    | 2    | 23   | N    |
  | 6    | 1    | 24   | Y    |
  | 7    | 1    | END  | Y    |
  |------|------|------|------|

Before the is-stmt patch GDB would ignore any non-stmt lines, so GDB
built two line table structures:

  File 1                 File 2
  ------                 ------

  | Addr | Line |        | Addr | Line |
  |------|------|        |------|------|
  | 1    | 16   |        | 3    | 21   |
  | 2    | 17   |        | 4    | 22   |
  | 3    | END  |        | 6    | END  |
  | 6    | 24   |        |------|------|
  | 7    | END  |
  |------|------|

After the is-stmt patch GDB now records non-stmt lines, so the
generated line table structures look like this:

  File 1                   File 2
  ------                   ------

  | Addr | Line | Stmt |  | Addr | Line | Stmt |
  |------|------|------|  |------|------|------|
  | 1    | 16   | Y    |  | 3    | 21   | Y    |
  | 2    | 17   | Y    |  | 4    | 22   | Y    |
  | 3    | END  | Y    |  | 4    | END  | Y    |
  | 4    | 18   | N    |  | 5    | 23   | N    |
  | 5    | END  | Y    |  | 6    | END  | Y    |
  | 6    | 24   | Y    |  |------|------|------|
  | 7    | END  | Y    |
  |------|------|------|

The problem is that in 'File 2', end END marker at address 4 causes
the previous line table entry to be discarded, so we actually end up
with this:

  File 2
  ------

  | Addr | Line | Stmt |
  |------|------|------|
  | 3    | 21   | Y    |
  | 4    | END  | Y    |
  | 5    | 23   | N    |
  | 6    | END  | Y    |
  |------|------|------|

When a user tries to place a breakpoint in file 2 at line 22, this is
no longer possible.

The solution I propose here is that we ignore line table entries that
would trigger a change of file if:

  1. The new line being added is at the same address as the previous
  line, and

  2. We have previously seen an is-stmt line at the current address.

The result of this is that GDB switches file, and knows that some line
entry (or entries) are going to be discarded, prefer to keep is-stmt
lines and discard non-stmt lines.

After this commit the lines tables are now:

  File 1                   File 2
  ------                   ------

  | Addr | Line | Stmt |  | Addr | Line | Stmt |
  |------|------|------|  |------|------|------|
  | 1    | 16   | Y    |  | 3    | 21   | Y    |
  | 2    | 17   | Y    |  | 4    | 22   | Y    |
  | 3    | END  | Y    |  | 5    | 23   | N    |
  | 5    | END  | Y    |  | 6    | END  | Y    |
  | 6    | 24   | Y    |  |------|------|------|
  | 7    | END  | Y    |
  |------|------|------|

We've lost the non-stmt entry for file 1, line 18, but retained the
is-stmt entry for file 2, line 22.  The user can now place a
breakpoint at that location.

One problem that came from this commit was the test
gdb.cp/step-and-next-inline.exp, which broke in several places.  After
looking at this test again I think that in some cases this test was
only ever passing by pure luck.  The debug GCC is producing for this
test is pretty broken.  I raised this GCC bug:

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

for this and disabled one entire half of the test.  There are still
some cases in here that do pass, and if/when GCC is fixed it would be
great to enable this test again.

gdb/ChangeLog:

* dwarf2/read.c (class lnp_state_machine) <m_last_address>: New
member variable.
<m_stmt_at_address>: New member variable.
(lnp_state_machine::record_line): Don't record some lines, update
tracking of is_stmt at the same address.
(lnp_state_machine::lnp_state_machine): Initialise new member
variables.

gdb/testsuite/ChangeLog:

* gdb.cp/step-and-next-inline.exp (do_test): Skip all tests in the
use_header case.
* gdb.dwarf2/dw2-inline-header-1.exp: New file.
* gdb.dwarf2/dw2-inline-header-2.exp: New file.
* gdb.dwarf2/dw2-inline-header-3.exp: New file.
* gdb.dwarf2/dw2-inline-header-lbls.c: New file.
* gdb.dwarf2/dw2-inline-header.c: New file.
* gdb.dwarf2/dw2-inline-header.h: New file.

4 years agohurd: Add shared mig declarations
Samuel Thibault [Mon, 1 Jun 2020 07:50:14 +0000 (07:50 +0000)]
hurd: Add shared mig declarations

We are using -Werror=missing-declarations, and the _S.h files generated
by mig do not currently include a declaration for the server routine.
gnu-nat.c used to have its own external declarations, but better just
share them between gnu-nat.c and the _S.c files.

Fixes

exc_request_S.c:177:24: error: no previous declaration for ‘exc_server’ [-Werror=missing-declarations]
  177 | mig_external boolean_t exc_server

gdb/ChangeLog:

* config/i386/i386gnu.mn [%_S.o %_U.o] (COMPILE.post): Add
"-include gnu-nat-mig.h".
* gnu-nat-mig.h: New file.
* gnu-nat.c: Include "gnu-nat-mig.h".
(exc_server, msg_reply_server, notify_server,
process_reply_server): Remove declarations.

4 years agoAutomatic date update in version.in
GDB Administrator [Mon, 1 Jun 2020 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agognu-nat: Move local functions inside gnu_nat_target class
Samuel Thibault [Sun, 31 May 2020 07:42:10 +0000 (07:42 +0000)]
gnu-nat: Move local functions inside gnu_nat_target class

This allows to have the process_stratum_target object at hand for future use in
the gdb API, and only use gnu_target from external calls.

gdb/Changelog:

* gnu-nat.h (inf_validate_procs, inf_suspend, inf_set_traced,
steal_exc_port, proc_get_state, inf_clear_wait, inf_cleanup,
inf_startup, inf_update_suspends, inf_set_pid, inf_steal_exc_ports,
inf_validate_procinfo, inf_validate_task_sc, inf_restore_exc_ports,
inf_set_threads_resume_sc, inf_set_threads_resume_sc_for_signal_thread,
inf_resume, inf_set_step_thread, inf_detach, inf_attach, inf_signal,
inf_continue, make_proc, proc_abort, _proc_free, proc_update_sc,
proc_get_exception_port, proc_set_exception_port, _proc_get_exc_port,
proc_steal_exc_port, proc_restore_exc_port, proc_trace): Move functions
to gnu_nat_target class.
* gnu-nat.c: Likewise.
(inf_update_procs, S_proc_wait_reply, set_task_pause_cmd,
set_task_exc_port_cmd, set_signals_cmd, set_thread_pause_cmd,
set_thread_exc_port_cmd): Call inf_validate_procs through gnu_target
object.
(gnu_nat_target::create_inferior, gnu_nat_target::detach): Pass `this'
instead of `gnu_target'.

4 years agoAutomatic date update in version.in
GDB Administrator [Sun, 31 May 2020 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agohurd: unwinding support over signal trampolines
Samuel Thibault [Sat, 30 May 2020 18:45:30 +0000 (18:45 +0000)]
hurd: unwinding support over signal trampolines

This allows to get full backtrace from signal handlers, otherwise the
backtrace stops at the trampoline that calls the handler.

This needs special knowledge how the trampoline records register context
for the sigreturn call after signal handling.

gdb/ChangeLog:

* i386-gnu-tdep.c: Include "gdbcore.h"
(gnu_sigtramp_code, i386_gnu_sc_reg_offset): New arrays.
        (GNU_SIGTRAMP_LEN, GNU_SIGTRAMP_TAIL,
        I386_GNU_SIGCONTEXT_THREAD_STATE_OFFSET): New macros
        (i386_gnu_sigtramp_start, i386_gnu_sigtramp_p,
        i386_gnu_sigcontext_addr): New functions
        (i386gnu_init_abi): Register i386_gnu_sigtramp_p,
        i386_gnu_sigcontext_addr, and i386_gnu_sc_reg_offset in the gdbarch
        tdep.

4 years agohurd: fix pushing target on inferior creation
Samuel Thibault [Sat, 30 May 2020 18:44:17 +0000 (18:44 +0000)]
hurd: fix pushing target on inferior creation

This fixes creating inferiors, which was broken since 5b6d1e4fa
('Multi-target support')

gdb/ChangeLog:

* gnu-nat.c (gnu_nat_target::create_inferior): Move push_target call
before fork_inferior call. Avoid calling it if target_is_pushed returns
true.

4 years agohurd: add gnu_target pointer to fix thread API calls
Samuel Thibault [Sat, 30 May 2020 18:43:25 +0000 (18:43 +0000)]
hurd: add gnu_target pointer to fix thread API calls

Fixes

../../gdb/gnu-nat.c:1110:28: error: cannot convert ‘ptid_t’ to ‘process_stratum_target*’
 1110 |        thread_change_ptid (inferior_ptid, ptid);

and others related to 5b6d1e4fa ("Multi-target support")

gdb/ChangeLog:

* gnu-nat.h (gnu_target): New variable declaration.
* i386-gnu-nat.c (_initialize_i386gnu_nat): Initialize
gnu_target.
* gnu-nat.c (gnu_target): New variable.
(inf_validate_procs): Pass gnu_target to thread_change_ptid,
add_thread_silent, and add_thread calls.
(gnu_nat_target::create_inferior): Pass gnu_target to
add_thread_silent, thread_change_ptid call.
(gnu_nat_target::detach): Pass gnu_target to detach_inferior
call.

4 years agohurd: remove unused variables
Samuel Thibault [Sat, 30 May 2020 18:42:17 +0000 (18:42 +0000)]
hurd: remove unused variables

Fixes

../../gdb/gnu-nat.c:2554:7: error: unused variable ‘res’ [-Werror=unused-variable]
 2554 |   int res;
../../gdb/gnu-nat.c:2644:20: error: unused variable ‘old_address’ [-Werror=unused-variable]
 2644 |       vm_address_t old_address = region_address;

gdb/ChangeLog:

* gnu-nat.c (gnu_xfer_auxv): Remove unused `res' variable.
(gnu_nat_target::find_memory_regions): Remove unused
`old_address' variable.

4 years agohurd: add missing include
Samuel Thibault [Sat, 30 May 2020 18:41:30 +0000 (18:41 +0000)]
hurd: add missing include

Fixes

../../gdb/gnu-nat.c:2522:14: error: ‘target_gdbarch’ was not declared in this scope; did you mean ‘target_detach’?
 2522 |    paddress (target_gdbarch (), memaddr), pulongest (len),

gdb/Changelog:

* gnu-nat.c: Include "gdbarch.h".

4 years agohurd: make function cast stronger
Samuel Thibault [Sat, 30 May 2020 18:38:46 +0000 (18:38 +0000)]
hurd: make function cast stronger

Fixes

process_reply_S.c:104:23: error: function called through a non-compatible type [-Werror]
  104 |      OutP->RetCode = (*(kern_return_t (*)(mach_port_t, kern_return_t)) S_proc_setmsgport_reply) (In0P->Head.msgh_request_port, In0P-

As the existing comment says, it is in general not safe to drop some
parameters like this, but this is the error handling case, where the
called function does not actually read them, and mig is currently planned
to be used on i386 and x86_64 only, where this is not a problem. As the
existing comment says, fixing it properly would be far from trivial:
we can't just pass 0 for them, as they might not be scalar.

gdb/ChangeLog:

* reply_mig_hack.awk (Error return): Cast function through
void *, to bypass compiler function call check.

4 years agohurd: add missing awk script dependency
Samuel Thibault [Sat, 30 May 2020 18:37:54 +0000 (18:37 +0000)]
hurd: add missing awk script dependency

To make sure the *_reply_S.[ch] files get regenerated whenever we change
the awk script.

gdb/ChangeLog:

* config/i386/i386gnu.mn (%_reply_S.c): Add dependency on
$(srcdir)/reply_mig_hack.awk.

4 years agohurd: fix gnu_debug_flag type
Samuel Thibault [Sat, 30 May 2020 18:35:59 +0000 (18:35 +0000)]
hurd: fix gnu_debug_flag type

Fixes

../../gdb/gnu-nat.c:96:6: error: conflicting declaration ‘bool gnu_debug_flag’
   96 | bool gnu_debug_flag = false;
../../gdb/gnu-nat.c: In function ‘void _initialize_gnu_nat()’:
../../gdb/gnu-nat.c:3511:7: error: cannot

gdb/ChangeLog:

* gnu-nat.h (gnu_debug_flag): Set type to bool.

4 years agogdb: change bug URL to https
Jonny Grant [Sat, 30 May 2020 15:17:28 +0000 (11:17 -0400)]
gdb: change bug URL to https

gdb/ChangeLog:

* configure.ac (ACX_BUGURL): change bug URL to https.

Signed-off-by: Jonny Grant <jg@jguk.org>
Change-Id: If8d939e50c830e3e452c3e8f7a7aee06d9c96645

4 years agoreplace_typedefs: handle templates in namespaces
Pedro Alves [Sat, 30 May 2020 13:20:10 +0000 (14:20 +0100)]
replace_typedefs: handle templates in namespaces

GDB currently crashes with infinite recursion, if you set a breakpoint
on a function inside a namespace that includes a template on its fully
qualified name, and, the template's name is also used as typedef in
the global scope that expands to a name that includes the template
name in its qualified name.  For example, from the testcase added by
this commit:

 namespace NS1 { namespace NS2 {

 template<typename T> struct Templ1
 {
   T x;

   Templ1 (object_p) {}
 }} // namespace NS1::NS2

 using Templ1 = NS1::NS2::Templ1<unsigned>;

Setting a breakpoint like so:

(gdb) break NS1::NS2::Templ1<int>::Templ1(NS1::NS2::object*)

Results in infinite recursion, with this cycle (started by
cp_canonicalize_string_full) repeating until the stack is exhausted:

 ...
 #1709 0x000000000055533c in inspect_type (info=0x38ff720, ret_comp=0xd83be10, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:267
 #1710 0x0000000000555a6f in replace_typedefs (info=0x38ff720, ret_comp=0xd83be10, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:475
 #1711 0x0000000000555a36 in replace_typedefs (info=0x38ff720, ret_comp=0xd83be70, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:470
 #1712 0x0000000000555800 in replace_typedefs_qualified_name (info=0x38ff720, ret_comp=0xd839470, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:389
 #1713 0x0000000000555a8c in replace_typedefs (info=0x38ff720, ret_comp=0xd839470, finder=0x0, data=0x0) at /home/pedro/gdb/mygit/src/gdb/cp-support.c:479
 ...

The demangle component tree for that symbol name looks like this:

d_dump tree for NS1::NS2::Templ1<int>::Templ1(NS1::NS2::object*):
typed name
  qualified name
    name 'NS1'
    qualified name
      name 'NS2'
      qualified name
        template                  <<<<<<<<<<
          name 'Templ1'
          template argument list
            builtin type int
        name 'Templ1'
  function type
    argument list
      pointer
        qualified name
          name 'NS1'
          qualified name
            name 'NS2'
            name 'object'

The recursion starts at replace_typedefs_qualified_name, which doesn't
handle the "template" node, and thus doesn't realize that the template
name actually has the fully qualified name NS1::NS2::Templ1.
replace_typedefs_qualified_name calls into replace_typedefs on the
template node, and that ends up in inspect_type looking up for a
symbol named "Templ1", which finds the global namespace typedef, which
itself expands to NS1::NS2::Templ1.  GDB then tries replacing typedefs
in that newly expanded name, which ends up again in
replace_typedefs_qualified_name, trying to expand a fully qualified
name with "NS::NS2::Templ1<unsigned>" in its name, which results in
recursion whenever the template node is reached.

Fix this by teaching replace_typedefs_qualified_name how to handle
template nodes.  It needs handling in two places: the first spot
handles the symbol above; the second spot handles a symbol like this,
from the new test:

(gdb) b NS1::NS2::grab_it(NS1::NS2::Templ1<int>*)
d_dump tree for NS1::NS2::grab_it(NS1::NS2::Templ1<int>*):
typed name
  qualified name
    name 'NS1'
    qualified name
      name 'NS2'
      name 'grab_it'
  function type
    argument list
      pointer
        qualified name
          name 'NS1'
          qualified name
            name 'NS2'
            template             <<<<<<<<
              name 'Templ1'
              template argument list
                builtin type int

What's different in this case is that the template node appears on the
right child node of a qualified name, instead of on the left child.

The testcase includes a test that checks whether template aliases are
correctly replaced by GDB too.  That fails with GCC due to GCC PR
95437, which makes GDB not know about a typedef for
"NS1::NS2::AliasTempl<int>".  GCC emits a typedef named
"NS1::NS2::AliasTempl" instead, with no template parameter info.  The
test passes with Clang (5.0.2 at least).  See more details here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95437

gdb/ChangeLog:
2020-05-30  Pedro Alves  <palves@redhat.com>

* cp-support.c (replace_typedefs_template): New.
(replace_typedefs_qualified_name): Handle
DEMANGLE_COMPONENT_TEMPLATE.

gdb/testsuite/ChangeLog:
2020-05-30  Pedro Alves  <palves@redhat.com>

* gdb.linespec/cp-replace-typedefs-ns-template.cc: New.
* gdb.linespec/cp-replace-typedefs-ns-template.exp: New.

4 years agoAutomatic date update in version.in
GDB Administrator [Sat, 30 May 2020 00:00:19 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agogdb: rename dwarf2_per_objfile variables/fields to per_objfile
Simon Marchi [Fri, 29 May 2020 19:15:10 +0000 (15:15 -0400)]
gdb: rename dwarf2_per_objfile variables/fields to per_objfile

While doing the psymtab-sharing patchset, I avoided renaming variables
unnecessarily to avoid adding noise to patches, but I'd like to do it
now.  Basically, we have these dwarf2 per-something structures:

  - dwarf2_per_objfile
  - dwarf2_per_bfd
  - dwarf2_per_cu_data

I named the instances of dwarf2_per_bfd `per_bfd` and most of instances
of dwarf2_per_cu_data are called `per_cu`.  Most pre-existing instances
of dwarf2_per_objfile are named `dwarf2_per_objfile`.  For consistency
with the other type, I'd like to rename them to just `per_objfile`.  The
`dwarf2_` prefix is superfluous, since it's already clear we are in
dwarf2 code.  It also helps reducing the line wrapping by saving 7
precious columns.

gdb/ChangeLog:

* dwarf2/comp-unit.c, dwarf2/comp-unit.h, dwarf2/index-cache.c,
dwarf2/index-cache.h, dwarf2/index-write.c,
dwarf2/index-write.h, dwarf2/line-header.c,
dwarf2/line-header.h, dwarf2/macro.c, dwarf2/macro.h,
dwarf2/read.c, dwarf2/read.h: Rename struct dwarf2_per_objfile
variables and fields from `dwarf2_per_objfile` to just
`per_objfile` throughout.

Change-Id: I3c45cdcc561265e90df82cbd36b4b4ef2fa73aef

4 years agoFix build errors in with clang in gdb.compile/compile-cplus.c
Gary Benson [Fri, 29 May 2020 16:43:17 +0000 (17:43 +0100)]
Fix build errors in with clang in gdb.compile/compile-cplus.c

Clang fails to compile the file, with the following error:
  fatal error: 'iostream' file not found

This prevents the following testcase from executing:
  gdb.compile/compile-cplus.exp

The testcase sets additional_flags when building with GCC, which
this commit causes to also be set when building with clang.  This
makes the testcase fail to build with a different error:
  warning: treating 'c' input as 'c++' when in C++ mode, this behavior
  is deprecated [-Wdeprecated]
so this commit adds -Wno-deprecated in two places to sidestep this.
Note that, while allowing the testcase to build, this commit reveals
failures when the testsuite is built using clang.

gdb/testsuite/ChangeLog:

* gdb.compile/compile-cplus.exp (additional_flags): Also
set when building with clang.
(additional_flags, srcfilesoptions): Pass -Wno-deprecated
when building with clang.

4 years agoFix file-not-found error with clang in gdb.arch/i386-{avx,sse}.c
Gary Benson [Fri, 29 May 2020 16:15:13 +0000 (17:15 +0100)]
Fix file-not-found error with clang in gdb.arch/i386-{avx,sse}.c

Clang fails to compile two testcases with the following error:
  fatal error: 'nat/x86-cpuid.h' file not found

This prevents the following testcases from executing:
  gdb.arch/i386-avx.exp
  gdb.arch/i386-sse.exp

Both testcases set additional_flags when building with GCC.
This commit causes the additional_flags to also be used when
building with clang.  Note that, while fixing the build, this
commit reveals several new failures when using clang to build
the testsuite.

gdb/testsuite/ChangeLog:

* gdb.arch/i386-avx.exp (additional_flags): Also set when
building with clang.
* gdb.arch/i386-sse.exp (additional_flags): Likewise.

4 years agoBuild two gdb.cp testcases with -Wno-unused-comparison
Gary Benson [Fri, 29 May 2020 13:03:01 +0000 (14:03 +0100)]
Build two gdb.cp testcases with -Wno-unused-comparison

Clang fails to compile two testcases with the following error:
  warning: equality comparison result unused [-Wunused-comparison]

This prevents the following testcases from executing:
  gdb.cp/koenig.exp
  gdb.cp/operator.exp

This commit builds those testcases with -Wno-unused-comparison, to
avoid the failure.  Note that this commit reveals a new failure,
"FAIL: gdb.cp/koenig.exp: p foo (p_union)" when the testsuite is
compiled using clang.

gdb/testsuite/ChangeLog:

* gdb.cp/koenig.exp (prepare_for_testing): Add
additional_flags=-Wno-unused-comparison.
* gdb.cp/operator.exp (prepare_for_testing): Likewise.

4 years agobinutils: Add myself as Xtensa maintainer
Max Filippov [Fri, 29 May 2020 04:05:46 +0000 (21:05 -0700)]
binutils: Add myself as Xtensa maintainer

2020-05-28  Max Filippov  <jcmvbkbc@gmail.com>
binutils/
* MAINTAINERS (Xtensa): Add myself as maintainer.

4 years agoAutomatic date update in version.in
GDB Administrator [Fri, 29 May 2020 00:00:14 +0000 (00:00 +0000)]
Automatic date update in version.in

4 years agobfd: fix handling of R_BPF_INSN_{32,64} relocations.
David Faust [Thu, 28 May 2020 18:53:29 +0000 (20:53 +0200)]
bfd: fix handling of R_BPF_INSN_{32,64} relocations.

2020-05-28  David Faust  <david.faust@oracle.com>

* elf64-bpf.c (bpf_elf_relocate_section): Fix handling of
R_BPF_INSN_{32,64} relocations.

4 years agocpu,opcodes: add instruction semantics to bpf.cpu and minor fixes
Jose E. Marchesi [Thu, 28 May 2020 14:53:54 +0000 (16:53 +0200)]
cpu,opcodes: add instruction semantics to bpf.cpu and minor fixes

This patch adds semantic RTL descriptions to the eBPF instructions
defined in cpu/bpf.cpu.  It also contains a couple of minor
improvements.

Tested in bpf-unknown-none targets.
No regressions.

cpu/ChangeLog:

2020-05-28  Jose E. Marchesi  <jose.marchesi@oracle.com>
    David Faust <david.faust@oracle.com>

* bpf.cpu (define-alu-insn-un): Add definitions of semantics.
(define-alu-insn-mov): Likewise.
(daib): Likewise.
(define-alu-instructions): Likewise.
(define-endian-insn): Likewise.
(define-lddw): Likewise.
(dlabs): Likewise.
(dlind): Likewise.
(dxli): Likewise.
(dxsi): Likewise.
(dsti): Likewise.
(define-ldstx-insns): Likewise.
(define-st-insns): Likewise.
(define-cond-jump-insn): Likewise.
(dcji): Likewise.
(define-condjump-insns): Likewise.
(define-call-insn): Likewise.
(ja): Likewise.
("exit"): Likewise.
(define-atomic-insns): Likewise.
(sem-exchange-and-add): New macro.
* bpf.cpu ("brkpt"): New instruction.
(bpfbf): Set word-bitsize to 32 and insn-endian big.
(h-gpr): Prefer r0 to `a' and r6 to `ctx'.
(h-pc): Expand definition.
* bpf.opc (bpf_print_insn): Set endian_code to BIG.

opcodes/ChangeLog:

2020-05-28  Jose E. Marchesi  <jose.marchesi@oracle.com>
    David Faust <david.faust@oracle.com>

* bpf-desc.c: Regenerate.
* bpf-opc.h: Likewise.
* bpf-opc.c: Likewise.
* bpf-dis.c: Likewise.

4 years agogdb: add comment in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value
Simon Marchi [Thu, 28 May 2020 19:47:53 +0000 (15:47 -0400)]
gdb: add comment in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value

Add a comment to clarify why we temporarily override some of the
context's fields, and especially the per_objfile field.  A longer
explanation can be found in this previous commit

    44486dcf19b ("gdb: use caller objfile in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value")

gdb/ChangeLog:

* dwarf2/loc.c (class dwarf_evaluate_loc_desc)
<push_dwarf_reg_entry_value>: Add comment.

Change-Id: I60c6e1062799f729b30a9db78bcb6448783324b4

4 years agoFix Python3.9 related runtime problems
Kevin Buettner [Thu, 28 May 2020 03:05:40 +0000 (20:05 -0700)]
Fix Python3.9 related runtime problems

Python3.9b1 is now available on Rawhide.  GDB w/ Python 3.9 support
can be built using the configure switch -with-python=/usr/bin/python3.9.

Attempting to run gdb/Python3.9 segfaults on startup:

    #0  0x00007ffff7b0582c in PyEval_ReleaseLock () from /lib64/libpython3.9.so.1.0
    #1  0x000000000069ccbf in do_start_initialization ()
at worktree-test1/gdb/python/python.c:1789
    #2  _initialize_python ()
at worktree-test1/gdb/python/python.c:1877
    #3  0x00000000007afb0a in initialize_all_files () at init.c:237
    ...

Consulting the the documentation...

https://docs.python.org/3/c-api/init.html

...we find that PyEval_ReleaseLock() has been deprecated since version
3.2.  It recommends using PyEval_SaveThread or PyEval_ReleaseThread()
instead.  In do_start_initialization, in gdb/python/python.c, we
can replace the calls to PyThreadState_Swap() and PyEval_ReleaseLock()
with a single call to PyEval_SaveThread.   (Thanks to Keith Seitz
for working this out.)

With that in place, GDB gets a little bit further.  It still dies
on startup, but the backtrace is different:

    #0  0x00007ffff7b04306 in PyOS_InterruptOccurred ()
       from /lib64/libpython3.9.so.1.0
    #1  0x0000000000576e86 in check_quit_flag ()
at worktree-test1/gdb/extension.c:776
    #2  0x0000000000576f8a in set_active_ext_lang (now_active=now_active@entry=0x983c00 <extension_language_python>)
at worktree-test1/gdb/extension.c:705
    #3  0x000000000069d399 in gdbpy_enter::gdbpy_enter (this=0x7fffffffd2d0,
gdbarch=0x0, language=0x0)
at worktree-test1/gdb/python/python.c:211
    #4  0x0000000000686e00 in python_new_inferior (inf=0xddeb10)
at worktree-test1/gdb/python/py-inferior.c:251
    #5  0x00000000005d9fb9 in std::function<void (inferior*)>::operator()(inferior*) const (__args#0=<optimized out>, this=0xccad20)
at /usr/include/c++/10/bits/std_function.h:617
    #6  gdb::observers::observable<inferior*>::notify (args#0=0xddeb10,
this=<optimized out>)
at worktree-test1/gdb/../gdbsupport/observable.h:106
    #7  add_inferior_silent (pid=0)
at worktree-test1/gdb/inferior.c:113
    #8  0x00000000005dbcb8 in initialize_inferiors ()
at worktree-test1/gdb/inferior.c:947
    ...

We checked with some Python Developers and were told that we should
acquire the GIL prior to calling any Python C API function.  We
definitely don't have the GIL for calls of PyOS_InterruptOccurred().

I moved class_gdbpy_gil earlier in the file and use it in
gdbpy_check_quit_flag() to acquire (and automatically release) the
GIL.

With those changes in place, I was able to run to a GDB prompt.  But,
when trying to quit, it segfaulted again due to due to some other
problems with gdbpy_check_quit_flag():

    Thread 1 "gdb" received signal SIGSEGV, Segmentation fault.
    0x00007ffff7bbab0c in new_threadstate () from /lib64/libpython3.9.so.1.0
    (top-gdb) bt 8
    #0  0x00007ffff7bbab0c in new_threadstate () from /lib64/libpython3.9.so.1.0
    #1  0x00007ffff7afa5ea in PyGILState_Ensure.cold ()
       from /lib64/libpython3.9.so.1.0
    #2  0x000000000069b58c in gdbpy_gil::gdbpy_gil (this=<synthetic pointer>)
at worktree-test1/gdb/python/python.c:278
    #3  gdbpy_check_quit_flag (extlang=<optimized out>)
at worktree-test1/gdb/python/python.c:278
    #4  0x0000000000576e96 in check_quit_flag ()
at worktree-test1/gdb/extension.c:776
    #5  0x000000000057700c in restore_active_ext_lang (previous=0xe9c050)
at worktree-test1/gdb/extension.c:729
    #6  0x000000000088913a in do_my_cleanups (
pmy_chain=0xc31870 <final_cleanup_chain>,
old_chain=0xae5720 <sentinel_cleanup>)
at worktree-test1/gdbsupport/cleanups.cc:131
    #7  do_final_cleanups ()
at worktree-test1/gdbsupport/cleanups.cc:143

In this case, we're trying to call a Python C API function after
Py_Finalize() has been called from finalize_python().  I made
finalize_python set gdb_python_initialized to false and then cause
check_quit_flag() to return early when it's false.

With these changes in place, GDB seems to be working again with
Python3.9b1.  I think it likely that there are other problems lurking.
I wouldn't be surprised to find that there are other calls into Python
where we don't first make sure that we have the GIL.  Further changes
may well be needed.

I see no regressions testing on Rawhide using a GDB built with the
default Python version (3.8.3) versus one built using Python 3.9b1.

I've also tested on Fedora 28, 29, 30, 31, and 32 (all x86_64) using
the default (though updated) system installed versions of Python on
those OSes.  This means that I've tested against Python versions
2.7.15, 2.7.17, 2.7.18, 3.7.7, 3.8.2, and 3.8.3.  In each case GDB
still builds without problem and shows no regressions after applying
this patch.

gdb/ChangeLog:

2020-MM-DD  Kevin Buettner  <kevinb@redhat.com>
    Keith Seitz  <keiths@redhat.com>

* python/python.c (do_start_initialization): For Python 3.9 and
later, call PyEval_SaveThread instead of PyEval_ReleaseLock.
(class gdbpy_gil): Move to earlier in file.
(finalize_python): Set gdb_python_initialized.
(gdbpy_check_quit_flag): Acquire GIL via gdbpy_gil.  Return early
when not initialized.

4 years agoFix all unexpected failures in gas testsuite for pdp11-aout.
Stephen Casner [Thu, 28 May 2020 17:11:59 +0000 (10:11 -0700)]
Fix all unexpected failures in gas testsuite for pdp11-aout.

These failures were caused by the PDP11's mix of little-endian octets
in shorts but shorts in big endian order for long or quad so regexps
did not match.  Also tests used addresses as values in .long which
required BRD_RELOC_32 that was not implemented.

* gas/config/tc-pdp11.c (md_number_to_chars): Implement .quad
* gas/testsuite/gas/all/gas.exp: Select alternate test scripts for
pdp11, skip octa test completely.
* gas/testsuite/gas/all/eqv-dot-pdp11.s: Identical to eqv-dot.s
* gas/testsuite/gas/all/eqv-dot-pdp11.d: Match different octet order.
* gas/testsuite/gas/all/cond-pdp11.l: Match different octet order.

* bfd/pdp11.c: Implement BRD_RELOC_32 to relocate the low 16 bits of
addreses in .long (used in testsuites) and .stab values.

4 years agoFix "enumeration values not handled in switch" error in testsuite
Gary Benson [Thu, 28 May 2020 17:02:55 +0000 (18:02 +0100)]
Fix "enumeration values not handled in switch" error in testsuite

When running the testsuite with clang, gdb.base/sigaltstack.c
fails to compile with the following error:
  warning: enumeration values 'LEAF' and 'NR_LEVELS' not handled
    in switch [-Wswitch]

This prevents the gdb.base/sigaltstack.exp from executing.
This commit fixes.

gdb/testsuite/ChangeLog:

* gdb.base/sigaltstack.c (catcher): Add default case to switch
statement.

4 years agoHave the linker fail if any attempt to link in an executable is made.
Nick Clifton [Thu, 28 May 2020 16:43:21 +0000 (17:43 +0100)]
Have the linker fail if any attempt to link in an executable is made.

PR 26047
* ldelf.c (ldelf_after_open): Fail if attempting to link one
executable into another.  Ensure that the test is made for all
forms of linking.