deliverable/binutils-gdb.git
3 years agoRISC-V: Minor cleanup and testcases improvement for arch string parser.
Nelson Chu [Fri, 20 Nov 2020 06:45:32 +0000 (14:45 +0800)] 
RISC-V: Minor cleanup and testcases improvement for arch string parser.

Re-indent the related codes, unify and improve the related error messages
and comments.  Besies, also re-write the testcases to cover more cases.

bfd/
* elfxx-riscv.c: Re-indent codes, unify and improve the error
messages and comments.
(riscv_parse_prefixed_ext): Stop parsing the prefixed class
extensions if the class is RV_ISA_CLASS_UNKNOWN, I get internal
errors before adding this check for march-fail-porder* testcases.
(riscv_parse_subset): Move the rv32 with q checking in front.
* elfxx-riscv.h: Likewise.

gas/
(These are new testcases that cover more cases)
* testsuite/gas/riscv/march-fail-base-01.d: The first extension must
be e, i or g.
* testsuite/gas/riscv/march-fail-base-01.l: Likewise.
* testsuite/gas/riscv/march-fail-base-02.d: rv64e is an invalid base ISA.
* testsuite/gas/riscv/march-fail-base-02.l: Likewise.
* testsuite/gas/riscv/march-fail-order-std.d: Check orders of standard
extensions.
* testsuite/gas/riscv/march-fail-order-std.l: Likewise.
* testsuite/gas/riscv/march-fail-order-x.d: Check orders of prefixed
x extensions.
* testsuite/gas/riscv/march-fail-order-x.l: Likewise.
* testsuite/gas/riscv/march-fail-porder-x-std.d: Check orders when
standard and prefixed extensions are set at the same time.
* testsuite/gas/riscv/march-fail-porder-x-z.d: Likewise.
* testsuite/gas/riscv/march-fail-porder-z-std.d: Likewise.
* testsuite/gas/riscv/march-fail-porder.l: Likewise.
* testsuite/gas/riscv/march-fail-single-char-s.d: Only standard
extensions can use single char.
* testsuite/gas/riscv/march-fail-single-char-x.d: Likewise.
* testsuite/gas/riscv/march-fail-single-char-z.d: Likewise.
* testsuite/gas/riscv/march-fail-single-char.l: Likewise.
* testsuite/gas/riscv/march-fail-unknown-s.d: All extensions
should be known, except the non-standard x extensions.
* testsuite/gas/riscv/march-fail-unknown-std.d: Likewise.
* testsuite/gas/riscv/march-fail-unknown-std.l: Likewise.
* testsuite/gas/riscv/march-fail-unknown-z.d: Likewise.
* testsuite/gas/riscv/march-fail-unknown.l: Likewise.
* testsuite/gas/riscv/march-fail-uppercase-base.d: Do not
allow any uppercase in the arch string.
* testsuite/gas/riscv/march-fail-uppercase-std.d: Likewise.
* testsuite/gas/riscv/march-fail-uppercase-z.d: Likewise.
* testsuite/gas/riscv/march-fail-uppercase.l: Likewise.
* testsuite/gas/riscv/march-fail-version-x.d: Failed to set versions.
* testsuite/gas/riscv/march-fail-version-z.d: Likewise.
* testsuite/gas/riscv/march-fail-version.l: Likewise.
* testsuite/gas/riscv/march-fail-rv32ef.l: Updated.
* testsuite/gas/riscv/march-fail-rv32id.d: Need f-ext.
* testsuite/gas/riscv/march-fail-rv32iq.d: Should be rv64.
* testsuite/gas/riscv/march-fail-rv32iq.l: Likewise.
* testsuite/gas/riscv/march-fail-rv64iq.d: Need d-ext and f-ext.
* testsuite/gas/riscv/march-fail-rv64iq.l: Likewise.

(The following testcases are removed and covered by new testcases)
* testsuite/gas/riscv/march-fail-rv32i.d: march-fail-uppercase-base.
* testsuite/gas/riscv/march-fail-rv32i.l: Likewise.
* testsuite/gas/riscv/march-fail-rv32iam.d: march-fail-order-std.
* testsuite/gas/riscv/march-fail-rv32iam.l: Likewise.
* testsuite/gas/riscv/march-fail-rv32ic.d: march-fail-uppercase-std.
* testsuite/gas/riscv/march-fail-rv32ic.l: Likewise.
* testsuite/gas/riscv/march-fail-rv32icx2p.d: march-fail-version-x.
* testsuite/gas/riscv/march-fail-rv32icx2p.l: Likewise.
* testsuite/gas/riscv/march-fail-rv32imc.d: march-fail-order-std.
* testsuite/gas/riscv/march-fail-rv32imc.l: Likewise.
* testsuite/gas/riscv/march-fail-rv64I.d: march-fail-uppercase-std.
* testsuite/gas/riscv/march-fail-rv64I.l: Likewise.
* testsuite/gas/riscv/march-fail-rv64e.d: march-fail-base-02.
* testsuite/gas/riscv/march-fail-rv64e.l: Likewise.
* testsuite/gas/riscv/march-fail-s-with-version.d: march-fail-unknown-s.
* testsuite/gas/riscv/march-fail-s-with-version.l: Likewise.
* testsuite/gas/riscv/march-fail-s.d: march-fail-unknown-s.
* testsuite/gas/riscv/march-fail-s.l: Likewise.
* testsuite/gas/riscv/march-fail-sx.d: march-fail-unknown-s.
* testsuite/gas/riscv/march-fail-sx.l: Likewise.

3 years agotic6x elf testsuite fix
Alan Modra [Mon, 30 Nov 2020 23:57:44 +0000 (10:27 +1030)] 
tic6x elf testsuite fix

* testsuite/ld-elf/elf.exp: Set ASFLAGS for tic6x.
* testsuite/ld-elf/reloc-discard.d: Remove tic6x xfail.

3 years agoPR26979, Visibility of undefined foo@v1 should constrain foo@@v1
Alan Modra [Mon, 30 Nov 2020 08:49:00 +0000 (19:19 +1030)] 
PR26979, Visibility of undefined foo@v1 should constrain foo@@v1

Also, undefined foo should constrain the visibility of foo@@v1 just as
it does for a later plain foo definition.

bfd/
PR 26979
* elf-bfd.h (elf_backend_merge_symbol_attribute): Update prototype.
* elf32-m68hc1x.h (elf32_m68hc11_merge_symbol_attribute): Likewise.
* elfxx-mips.h (_bfd_mips_elf_merge_symbol_attribute): Likewise.
* elfxx-x86.h (_bfd_x86_elf_merge_symbol_attribute): Likewise.
* elf32-m68hc1x.c (elf32_m68hc11_merge_symbol_attribute): Replace
isym parameter with st_other.  Adjust code.
* elf64-alpha.c (elf64_alpha_merge_symbol_attribute): Likewise.
* elf64-ppc.c (ppc64_elf_merge_symbol_attribute): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_merge_symbol_attribute): Likewise.
* elfxx-mips.c (_bfd_mips_elf_merge_symbol_attribute): Likewise.
* elfxx-x86.c (_bfd_x86_elf_merge_symbol_attribute): Likewise.
* elflink.c (elf_merge_st_other): Likewise.
(_bfd_elf_merge_symbol, elf_link_add_object_symbols): Adjust to suit.
(_bfd_elf_copy_link_hash_symbol_type): Likewise.
(_bfd_elf_add_default_symbol): Merge st_other from undecorated
symbol and @VER symbol to @@VER symbol.
ld/
* testsuite/ld-elf/pr26979a.s,
* testsuite/ld-elf/pr26979b.s,
* testsuite/ld-elf/pr26979c.s,
* testsuite/ld-elf/pr26979.ver,
* testsuite/ld-elf/pr26979a.d,
* testsuite/ld-elf/pr26979b.d: New tests.

3 years agoAutomatic date update in version.in
GDB Administrator [Tue, 1 Dec 2020 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agold: Xfail PR ld/26936 test if not supported
H.J. Lu [Mon, 30 Nov 2020 13:21:51 +0000 (05:21 -0800)] 
ld: Xfail PR ld/26936 test if not supported

Linkonce sections and comdat groups can be mixed only if comdat groups
have only a single member with matching symbol table entries.  Xfail
ld/26936 test:

1. If comdat groups always have more than one member.
2. If symbol table entries in linkonce and comdat group don't match.
3. If the assembly source file is renamed.

PR ld/26936
* testsuite/ld-elf/pr26936.d: Xfail targets which don't support
mixing linkonce and comdat sections.

3 years agoRevert accidental empty commits
Tom de Vries [Mon, 30 Nov 2020 12:59:57 +0000 (13:59 +0100)] 
Revert accidental empty commits

Revert empty commits:
- "[gdb] Don't return non-existing path in debuginfod_source_query"
  commit 59404f827cb1134b68dbf228d380ff86d15c9f01
- "[gdb/testsuite] Fix minimal encodings KPASSes"
  commit 61049d1ee59905589b2ad3f8140a2582e01add7a

3 years ago[gdb/symtab] Fix gdb.base/vla-optimized-out.exp with clang
Tom de Vries [Mon, 30 Nov 2020 12:50:26 +0000 (13:50 +0100)] 
[gdb/symtab] Fix gdb.base/vla-optimized-out.exp with clang

Consider test-case gdb.base/vla-optimized-out.exp, compiled using clang-10.

GDB fails to get the size of the vla a:
...
(gdb) p sizeof (a)^M
Cannot access memory at address 0x6^M
(gdb) FAIL: gdb.base/vla-optimized-out.exp: o1: printed size of \
  optimized out vla
...

The relevant DWARF looks like this: the variable a:
...
 <2><12b>: Abbrev Number: 5 (DW_TAG_variable)
    <12c>   DW_AT_name        : a
    <132>   DW_AT_type        : <0x189>
...
has type:
...
 <1><189>: Abbrev Number: 10 (DW_TAG_array_type)
    <18a>   DW_AT_type        : <0x198>
 <2><18e>: Abbrev Number: 11 (DW_TAG_subrange_type)
    <18f>   DW_AT_type        : <0x19f>
    <193>   DW_AT_count       : <0x117>
...
with the count attribute equated to the value of this artificial variable:
...
 <2><117>: Abbrev Number: 4 (DW_TAG_variable)
    <118>   DW_AT_location    : 10 byte block: 75 1 10 ff ff ff ff f 1a 9f \
              (DW_OP_breg5 (rdi): 1;
       DW_OP_constu: 4294967295;
       DW_OP_and;
       DW_OP_stack_value)
    <123>   DW_AT_name        : __vla_expr0
    <127>   DW_AT_type        : <0x182>
    <12b>   DW_AT_artificial  : 1
...

The location description of the variable is terminated with DW_OP_stack_value,
which according to the DWARF spec means that "the DWARF expression represents
the actual value of the object, rather than its location".

However, in attr_to_dynamic_prop, we set is_reference to true:
...
               baton->locexpr.is_reference = true;
...
and use it in dwarf2_evaluate_property to dereference the value of the DWARF
expression, which causes the access to memory at address 0x6.

Fix this by ignoring the baton->locexpr.is_reference == true setting if
the expression evaluation has ctx.location == DWARF_VALUE_STACK, such that we
get:
...
(gdb) p sizeof (a)^M
$2 = 6^M
(gdb) PASS: gdb.base/vla-optimized-out.exp: o1: printed size of \
  optimized out vla
...

Tested on x86_64-linux, with gcc.

Tested the following test-cases (the ones mentioned in PR26905) on
x86_64-linux with clang-10:
- gdb.base/vla-optimized-out.exp
- gdb.base/vla-ptr.exp
- gdb.mi/mi-vla-c99

gdb/ChangeLog:

2020-11-30  Tom de Vries  <tdevries@suse.de>

PR symtab/26905
* dwarf2/loc.c (dwarf2_locexpr_baton_eval): Add and handle
is_reference parameter.
(dwarf2_evaluate_property): Update dwarf2_locexpr_baton_eval call.

gdb/testsuite/ChangeLog:

2020-11-30  Tom de Vries  <tdevries@suse.de>

PR symtab/26905
* gdb.dwarf2/count.exp: Remove kfails.

3 years ago[gdb/testsuite] Fix minimal encodings KPASSes
Tom de Vries [Mon, 16 Nov 2020 12:02:04 +0000 (13:02 +0100)] 
[gdb/testsuite] Fix minimal encodings KPASSes

With current master I see a couple of KPASSes:
...
KPASS: gdb.ada/enum_idx_packed.exp: scenario=minimal: ptype small \
  (PRMS minimal encodings)
  ...
KPASS: gdb.ada/mod_from_name.exp: scenario=minimal: print xp \
  (PRMS minimal encodings)
KPASS: gdb.ada/pckd_arr_ren.exp: scenario=minimal: print var \
  (PRMS minimal encodings)
...

The corresponding setup_kfail is called for everything before gnat 11.

However, the test-cases also PASS for me with gnat-4.8, gnat-7.5.0 and
gnat-8.4.0.

Fix the KPASSes by limiting the setup_kfail to gnat 9 and 10.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-11-16  Tom de Vries  <tdevries@suse.de>

* gdb.ada/enum_idx_packed.exp: Limit setup_kfail to gnat 9 and 10.
* gdb.ada/mod_from_name.exp: Same.
* gdb.ada/pckd_arr_ren.exp: Same.

3 years ago[gdb] Don't return non-existing path in debuginfod_source_query
Tom de Vries [Mon, 16 Nov 2020 09:29:36 +0000 (10:29 +0100)] 
[gdb] Don't return non-existing path in debuginfod_source_query

When setting env var DEBUGINFOD_URLS to " " and running the testsuite, we run
into these regressions:
...
FAIL: gdb.base/list-missing-source.exp: info source
FAIL: gdb.base/source-dir.exp: info source before setting directory search list
...

Setting var DEBUGINFOD_URLS to " " allows the debuginfod query function
debuginfod_source_query to get past its early exit.

The function debuginfod_source_query is documented as: "If the file is
successfully retrieved, its path on the local machine is stored in DESTNAME".

However, in case we get back -ENOENT from libdebuginfod, we still set
DESTNAME:
....
  if (fd.get () < 0 && fd.get () != -ENOENT)
    printf_filtered (_("Download failed: %s.  Continuing without source file %ps.\n"),
                     safe_strerror (-fd.get ()),
                     styled_string (file_name_style.style (),  srcpath));
  else
    *destname = make_unique_xstrdup (srcpath);

  return fd;
...

Fix this by making debuginfod_source_query fit it's documentation and only
setting DESTNAME when successfully retrieving a file.  Likewise in
debuginfod_debuginfo_query.

gdb/ChangeLog:

2020-11-16  Tom de Vries  <tdevries@suse.de>

* debuginfod-support.c (debuginfod_source_query)
(debuginfod_debuginfo_query): Only set DESTNAME if successful.

3 years agoRemove per-language op_name functions
Tom Tromey [Mon, 30 Nov 2020 08:37:10 +0000 (01:37 -0700)] 
Remove per-language op_name functions

enum exp_opcode is created from all the .def files, but then each
language is required to implement its own op_name function to turn an
enum value to a string.  This seemed over-complicated to me, and this
patch removes the per-language functions in favor of simply using the
.def names for all languages.  Note that op_name is only used for
dumping expressions, which is a maintainer/debug feature.
Furthermore, I don't think there was any case where the .def name and
the string name differed.

gdb/ChangeLog
2020-11-30  Tom Tromey  <tom@tromey.com>

* rust-lang.c (rust_op_name): Remove.
(exp_descriptor_rust): Update.
* parser-defs.h (op_name_standard): Don't declare.
(struct exp_descriptor) <op_name>: Remove.
* parse.c (exp_descriptor_standard): Update.
* opencl-lang.c (exp_descriptor_opencl): Update.
* m2-lang.c (m2_language::exp_descriptor_modula2): Update.
* f-lang.c (op_name_f): Remove.
(f_language::exp_descriptor_tab): Update.
* expression.h (op_name): Update.
* expprint.c (op_name): Rewrite.
(op_name_standard): Remove.
(dump_raw_expression, dump_subexp): Update.
* c-lang.c (exp_descriptor_c): Update.
* ax-gdb.c (gen_expr): Update.
* ada-lang.c (ada_op_name): Remove.
(ada_exp_descriptor): Update.

3 years agoRemove some dead code from evaluate_subexp_standard
Tom Tromey [Mon, 30 Nov 2020 08:24:57 +0000 (01:24 -0700)] 
Remove some dead code from evaluate_subexp_standard

I noticed that in the OP_ARRAY case in evaluate_subexp_standard,
"index_pc" is read but never set.  This dead code then guards the only
call to init_array_element, so this can be removed as well.

gdb/ChangeLog
2020-11-30  Tom Tromey  <tom@tromey.com>

* eval.c (init_array_element): Remove.
(evaluate_subexp_standard) <OP_ARRAY>: Remove "index_pc".

3 years agoAutomatic date update in version.in
GDB Administrator [Mon, 30 Nov 2020 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogold: Add endbr64 to IBT TLSDESC PLT entry
H.J. Lu [Sun, 29 Nov 2020 19:36:13 +0000 (11:36 -0800)] 
gold: Add endbr64 to IBT TLSDESC PLT entry

Gold generates:

 c10:   ff 35 da 23 00 00       push   0x23da(%rip)        # 2ff0 <_GLOBAL_OFFSET_TABLE_+0x8>
 c16:   f2 ff 25 c3 23 00 00    bnd jmp *0x23c3(%rip)        # 2fe0 <_DYNAMIC+0x260>
 c1d:   0f 1f 00                nopl   (%rax)

for IBT TLSDESC PLT entry which misses endbr64.  Add endbr64 to generate:

 c10:   f3 0f 1e fa             endbr64
 c14:   ff 35 d6 23 00 00       push   0x23d6(%rip)        # 2ff0 <_GLOBAL_OFFSET_TABLE_+0x8>
 c1a:   ff 25 c0 23 00 00       jmp    *0x23c0(%rip)        # 2fe0 <_DYNAMIC+0x260>

PR ld/26972
* x86_64.cc (Output_data_plt_x86_64_ibt::tlsdesc_plt_entry): Add
endbr64.
(Output_data_plt_x86_64_ibt::do_fill_tlsdesc_entry): Adjusted.

3 years agoFix Value.format_string docu for static members argument
Hannes Domani [Tue, 24 Nov 2020 18:43:19 +0000 (19:43 +0100)] 
Fix Value.format_string docu for static members argument

The argument is called static_members, not static_fields.

gdb/doc/ChangeLog:

2020-11-29  Hannes Domani  <ssbssa@yahoo.de>

PR python/26974
* python.texi: Fix docu for static members argument.

3 years agoDon't delete the locator win info
Hannes Domani [Thu, 19 Nov 2020 15:49:53 +0000 (16:49 +0100)] 
Don't delete the locator win info

The locator win info is special because it is static, all the others are
created dynamically.

gdb/ChangeLog:

2020-11-29  Hannes Domani  <ssbssa@yahoo.de>

PR tui/26973
* tui/tui-layout.c (tui_apply_current_layout): Don't delete the
static locator win info.

3 years agox86: Do not dump DS/CS segment overrides for branch hints
Borislav Petkov [Sat, 28 Nov 2020 13:20:06 +0000 (14:20 +0100)] 
x86: Do not dump DS/CS segment overrides for branch hints

The previous change

  "x86: Ignore CS/DS/ES/SS segment-override prefixes in 64-bit mode"

to ignore segment override prefixes in 64-bit mode lead to dumping
branch hints as excessive prefixes:

  ffffffff8109d5a0 <vmx_get_rflags>:
  ...
  ffffffff8109d601:       3e 77 0a                ds ja,pt ffffffff8109d60e <vmx_get_rflags+0x6e>
   ^^^^^

In this particular case, those prefixes are not excessive but are used
to provide branch hints - taken/not-taken - to the CPU.

Assign active_seg_prefix in that particular case to consume them.

gas/

2002-11-29  Borislav Petkov  <bp@suse.de>

        * testsuite/gas/i386/branch.d: Add new branch insns test.
        * testsuite/gas/i386/branch.s: Likewise.
        * testsuite/gas/i386/i386.exp: Insert the new branch test.
        * testsuite/gas/i386/x86-64-branch.d: Test for branch hints insns.
        * testsuite/gas/i386/x86-64-branch.s: Likewise.
        * testsuite/gas/i386/ilp32/x86-64-branch.d: Likewise.

opcodes/

2020-11-28 Borislav Petkov  <bp@suse.de>

        * i386-dis.c (print_insn): Set active_seg_prefix for branch hint insns
        to not dump branch hint prefixes 0x2E and 0x3E as unused prefixes.

3 years agogold: Convert x86-64 GOTPCRELX only if addend == -4
H.J. Lu [Sun, 29 Nov 2020 14:00:37 +0000 (06:00 -0800)] 
gold: Convert x86-64 GOTPCRELX only if addend == -4

Convert x86-64 GOTPCRELX relocations only if addend == -4.

PR gold/26939
* x86_64.cc (Target_x86_64<size>::Scan::local): Check
get_r_addend() == -4 for GOTPCRELX conversion.
(Target_x86_64<size>::Scan::global): Likewise.
(Target_x86_64<size>::Relocate::relocate): Likewise.
* testsuite/Makefile.am (check_DATA): Add
x86_64_mov_to_lea15.stdout and x86_64_mov_to_lea16.stdout.
(MOSTLYCLEANFILES): Add x86_64_mov_to_lea15 and
x86_64_mov_to_lea16.
(x86_64_mov_to_lea9.o): New target.
(x86_64_mov_to_lea10.o): Likewise.
(x86_64_mov_to_lea15): Likewise.
(x86_64_mov_to_lea16): Likewise.
(x86_64_mov_to_lea15.stdout): Likewise.
(x86_64_mov_to_lea16.stdout): Likewise.
* testsuite/Makefile.in: Regenerated.
* testsuite/x86_64_mov_to_lea.sh: Updated.
* testsuite/x86_64_mov_to_lea5.s: New file.

3 years agogold: Get linkonce/comdate sections for debugging sections
H.J. Lu [Sun, 29 Nov 2020 13:55:23 +0000 (05:55 -0800)] 
gold: Get linkonce/comdate sections for debugging sections

When relocating debug sections, get the section index for the linkonce
section.  Since symbols referenced in debugging sections can be defined
a single comdat section with a different section name, also check the
single comdat section.

PR gold/26937
* object.cc (Sized_relobj_file::map_to_kept_section): Get the
section index for linkonce section.  Also check the single
comdat section.
* testsuite/Makefile.am (check_SCRIPTS): Add pr26936.sh.
(check_DATA): Add pr26936a.stdout and pr26936b.stdout.
(MOSTLYCLEANFILES): Add pr26936a and pr26936b.
(pr26936a.stdout): New target.
(pr26936a): Likewise.
(pr26936b.stdout): Likewise.
(pr26936b): Likewise.
(pr26936a.o): Likewise.
(pr26936b.o): Likewise.
(pr26936c.o): Likewise.
(pr26936d.o): Likewise.
* testsuite/Makefile.in: Regenerated.
* testsuite/pr26936.sh: New file.
* testsuite/pr26936a.s: Likewise.
* testsuite/pr26936b.s: Likewise.
* testsuite/pr26936c.s: Likewise.
* testsuite/pr26936d.s: Likewise.

3 years agoAutomatic date update in version.in
GDB Administrator [Sun, 29 Nov 2020 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoGDB: Fix detection of ELF support when configuring with -Werror=implicit-function...
Alex Richardson [Sat, 28 Nov 2020 16:45:06 +0000 (11:45 -0500)] 
GDB: Fix detection of ELF support when configuring with -Werror=implicit-function-declaration

I am getting

    I'm sorry, Dave, I can't do that.  Symbol format `elf64-littleriscv' unknown.

errors after updating from GDB 8.3 to 10.  Bisecting showed that since
commit 1ff6de031241 ("bfd, ld: add CTF section linking"), bfd.h depends
on strncmp() being present, so configuring with
-Werror=implicit-function-declaration results in the check for ELF
support in BFD failing:

    .../gdb/gdb/../bfd/elf-bfd.h: In function 'bfd_section_is_ctf':
    .../gdb/gdb/../bfd/elf-bfd.h:3086:10: error: implicit declaration of function 'strncmp' [-Werror=implicit-function-declaration]
       return strncmp (name, ".ctf", 4) == 0 && (name[4] == 0 || name[4] == '.');

gdb/ChangeLog:

* acincludde.m4 (GDB_AC_CHECK_BFD): Include string.h in the test
program.

Change-Id: Iec5e21d454c2a544c44d65e23cfde552c424c18e

3 years agoPR26907, segment contains empty SHT_NOBITS section
Alan Modra [Fri, 27 Nov 2020 22:15:02 +0000 (08:45 +1030)] 
PR26907, segment contains empty SHT_NOBITS section

Section ordering is important for _bfd_elf_map_sections_to_segments
and assign_file_positions_for_load_sections, which are only prepared
to handle sections in increasing LMA order.  When zero size sections
are involved it is possible to have multiple sections at the same LMA.
In that case the zero size sections must sort before any non-zero size
sections regardless of their types.

bfd/
PR 26907
* elf.c (elf_sort_sections): Don't sort zero size !load sections
after load sections.
ld/
* testsuite/ld-elf/pr26907.ld,
* testsuite/ld-elf/pr26907.s,
* testsuite/ld-elf/pr26907.d: New test.

3 years agoAutomatic date update in version.in
GDB Administrator [Sat, 28 Nov 2020 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb: fix potentially uninitialised variable
Andrew Burgess [Fri, 27 Nov 2020 10:46:07 +0000 (10:46 +0000)] 
gdb: fix potentially uninitialised variable

In commit:

  commit 037d7135de575c9e0c20e9158c105979bfee339c
  Date:   Mon Nov 16 11:36:56 2020 +0000

      gdb: improve command completion for 'print', 'x', and 'display'

A potential use of an uninitialised variable was introduced.  This is
fixed in this commit.

Previously when analysing /FMT strings for tab completion we
considered two possibilities, either the user has typed '/', or the
user has typed '/' followed by an alpha-numeric character, as these
are the only valid FMT string characters.

This meant that if the user type, for example '/@' and then tried to
tab complete gdb would use an uninitialised variable.

Currently only the first character after the '/' is checked to see if
it is alpha-numeric, so if a user typed '/x@@' then gdb would be happy
to treat this as a FMT string.

Given the goal of this change was primarily to allow tab completion of
symbols later in the command when a /FMT was used then I decided to
just make the /FMT skipping less smart.  Now any characters after the
'/' up to the first white space, will be treated as a FMT string.

gdb/ChangeLog:

* printcmd.c (skip_over_slash_fmt): Reorder code to ensure in_fmt
is always initialized.

3 years agoAdd Rogerio Alves to gdb/MAINTAINERS.
Rogerio Alves [Fri, 27 Nov 2020 14:41:43 +0000 (11:41 -0300)] 
Add Rogerio Alves to gdb/MAINTAINERS.

gdb/Changelog
2020-11-26  Rogerio Alves <rcardoso@linux.ibm.com>
* MAINTAINERS (Write After Approval): Add myself.

3 years agoAllow spaces in the name of the external preprocessor used by windres.
Nick Clifton [Fri, 27 Nov 2020 14:18:20 +0000 (14:18 +0000)] 
Allow spaces in the name of the external preprocessor used by windres.

PR 26865
* windres.c (main): If the preprocessor name includes spaces,
ensure that it is quoted.

3 years agoELF: Support .noinit and .persistent sections
Jozef Lawrynowicz [Fri, 27 Nov 2020 10:45:35 +0000 (10:45 +0000)] 
ELF: Support .noinit and .persistent sections

The ".persistent" section is for data that should be initialized during
load, but not during application reset.

The ".noinit" section is for data that should not be initialized during
load or application reset.

Targets utilizing the elf.sc linker script template can define
HAVE_{NOINIT,PERSISTENT}=yes to include the .noinit or .persistent
output sections in the generated linker script.

Targets with existing support for .noinit did not handle unique
.noinit.* and .gnu.linkonce.n.* sections the .noinit output section,
this patch also fixes that.

bfd/ChangeLog:

* elf.c (special_sections_g): Add .gnu.linkonce.n and .gnu.linkonce.p.
(special_sections_n): Add .noinit.
(special_sections_p): Add .persistent.

binutils/ChangeLog:

* testsuite/lib/binutils-common.exp (supports_noinit_section): New.
(supports_persistent_section): New.

gas/ChangeLog:

* testsuite/gas/elf/elf.exp: Run new tests.
* testsuite/gas/elf/section25.d: New test.
* testsuite/gas/elf/section25.s: New test.
* testsuite/gas/elf/section26.d: New test.
* testsuite/gas/elf/section26.s: New test.

ld/ChangeLog:

* emulparams/armelf.sh (OTHER_SECTIONS): Remove .noinit section
definition.
Define HAVE_{NOINIT,PERSISTENT}=yes.
* scripttempl/avr.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.*
input section wildcard patterns.
* scripttempl/elf.sc: Define .noinit and .persistent sections when
HAVE_NOINIT or HAVE_PERSISTENT are defined to "yes".
* scripttempl/elf32msp430.sc (.noinit): Add .noinit.* and
.gnu.linkonce.n.*. input section wildcard patterns.
(.persistent): Add .persistent.* and
.gnu.linkonce.p.*. input section wildcard patterns.
* scripttempl/elfarcv2.sc (.noinit): Add .noinit.* and
.gnu.linkonce.n.*. input section wildcard patterns.
* scripttempl/pru.sc: Likewise.
* testsuite/ld-elf/noinit-sections-1.d: New test.
* testsuite/ld-elf/noinit-sections-2.d: New test.
* testsuite/ld-elf/noinit-sections-2.l: New test.
* testsuite/ld-elf/noinit-sections.s: New test.
* testsuite/ld-elf/persistent-sections-1.d: New test.
* testsuite/ld-elf/persistent-sections-2.d: New test.
* testsuite/ld-elf/persistent-sections-2.l: New test.
* testsuite/ld-elf/persistent-sections.s: New test.

3 years agoAutomatic date update in version.in
GDB Administrator [Fri, 27 Nov 2020 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoPrevent a memory allocation failure when parsing corrupt DWARF debug sections.
Nick Clifton [Thu, 26 Nov 2020 17:08:33 +0000 (17:08 +0000)] 
Prevent a memory allocation failure when parsing corrupt DWARF debug sections.

PR 26946
* dwarf2.c (read_section): Check for debug sections with excessive
sizes.

3 years agogdb/aarch64: Add named flags for FPCR and FPSR registers
Przemyslaw Wirkus [Thu, 26 Nov 2020 12:09:01 +0000 (12:09 +0000)] 
gdb/aarch64: Add named flags for FPCR and FPSR registers

This patch updates FPCR (Floating-point Control Register) and FPSR
(Floating-point Status Register) named fields in AArch64. For detailed
description of named register FPCR and FPSR bit fields see [1] and [2].

Please not that bit fields FIZ, AH and NEP (bits 0, 1 and 2 respectively) in
FPCR are defined starting from Armv8.7 architecture.

[1]: https://developer.arm.com/docs/ddi0595/i/aarch64-system-registers/fpcr
[2]: https://developer.arm.com/docs/ddi0595/i/aarch64-system-registers/fpsr

Example:
>>> info all-registers fpsr
fpsr           0x10                [ IXC ]
>>> info all-registers fpcr
fpcr           0x0                 [ RMode=0 ]

3 years agoPR26936 testsuite fixes
Alan Modra [Thu, 26 Nov 2020 07:15:26 +0000 (17:45 +1030)] 
PR26936 testsuite fixes

Many targets fail this test due to -z noseparate-code not being
supported, or _start not being the proper entry symbol, or "as -g"
something other than "generate debug".

PR 26936
* testsuite/ld-elf/pr26936.d: Pass --gen-debug to gas rather than -g.
Only run when -shared -z options are supported.
* testsuite/ld-elf/pr26936b.s: Define more entry symbols.

3 years agoelf: Get the real kept section
H.J. Lu [Thu, 26 Nov 2020 00:14:13 +0000 (16:14 -0800)] 
elf: Get the real kept section

When mixing linkonce and comdat sections, we need to keep searching to
get the real kept section.

bfd/

PR ld/26936
* elflink.c (_bfd_elf_check_kept_section): Get the real kept
section.

ld/

PR ld/26936
* testsuite/ld-elf/pr26936.d: New file.
* testsuite/ld-elf/pr26936a.s: Likewise.
* testsuite/ld-elf/pr26936b.s: Likewise.
* testsuite/ld-elf/pr26936c.s: Likewise.

3 years agoAutomatic date update in version.in
GDB Administrator [Thu, 26 Nov 2020 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agolibctf: Pass format argument to asprintf
H.J. Lu [Tue, 24 Nov 2020 14:08:43 +0000 (14:08 +0000)] 
libctf: Pass format argument to asprintf

libctf/ChangeLog
2020-09-23  H.J. Lu  <hongjiu.lu@intel.com>

PR libctf/26934
* ctf-dump.c (ctf_dump_objts): Pass format argument to asprintf.

3 years agobinutils: readelf: support CTF dicts with non-native-endian symtabs
Nick Alcock [Mon, 23 Nov 2020 21:30:24 +0000 (21:30 +0000)] 
binutils: readelf: support CTF dicts with non-native-endian symtabs

Now we have a way to tell libctf what the endianness of the symtab is,
get readelf to use it.  (objdump doesn't need to do so, nor does ld,
because they both use BFD-aware mechanisms to open CTF dicts, so libctf
can automatically figure the symtab endianness out.)

binutils/ChangeLog
2020-11-23  Nick Alcock  <nick.alcock@oracle.com>

* readelf.c (dump_section_as_ctf): Call ctf_arc_symsect_endianness.

3 years agolibctf, include: support foreign-endianness symtabs with CTF
Nick Alcock [Mon, 23 Nov 2020 21:17:44 +0000 (21:17 +0000)] 
libctf, include: support foreign-endianness symtabs with CTF

The CTF symbol lookup machinery added recently has one deficit: it
assumes the symtab is in the machine's native endianness.  This is
always true when the linker is writing out symtabs (because cross
linkers byteswap symbols only after libctf has been called on them), but
may be untrue in the cross case when the linker or another tool
(objdump, etc) is reading them.

Unfortunately the easy way to model this to the caller, as an endianness
field in the ctf_sect_t, is precluded because doing so would change the
size of the ctf_sect_t, which would be an ABI break.  So, instead, allow
the endianness of the symtab to be set after open time, by calling one
of the two new API functions ctf_symsect_endianness (for ctf_dict_t's)
or ctf_arc_symsect_endianness (for entire ctf_archive_t's).  libctf
calls these functions automatically for objects opened via any of the
BFD-aware mechanisms (ctf_bfdopen, ctf_bfdopen_ctfsect, ctf_fdopen,
ctf_open, or ctf_arc_open), but the various mechanisms that just take
raw ctf_sect_t's will assume the symtab is in native endianness and need
a later call to ctf_*symsect_endianness to adjust it if needed.  (This
call is basically free if the endianness is actually native: it only
costs anything if the symtab endianness was previously guessed wrong,
and there is a symtab, and we are using it directly rather than using
symtab indexing.)

Obviously, calling ctf_lookup_by_symbol or ctf_symbol_next before the
symtab endianness is correctly set will probably give wrong answers --
but you can set it at any time as long as it is before then.

include/ChangeLog
2020-11-23  Nick Alcock  <nick.alcock@oracle.com>

* ctf-api.h: Style nit: remove () on function names in comments.
(ctf_sect_t): Mention endianness concerns.
(ctf_symsect_endianness): New declaration.
(ctf_arc_symsect_endianness): Likewise.

libctf/ChangeLog
2020-11-23  Nick Alcock  <nick.alcock@oracle.com>

* ctf-impl.h (ctf_dict_t) <ctf_symtab_little_endian>: New.
(struct ctf_archive_internal) <ctfi_symsect_little_endian>: Likewise.
* ctf-create.c (ctf_serialize): Adjust for new field.
* ctf-open.c (init_symtab): Note the semantics of repeated calls.
(ctf_symsect_endianness): New.
(ctf_bufopen_internal): Set ctf_symtab_little_endian suitably for
the native endianness.
(_Static_assert): Moved...
(swap_thing): ... with this...
* swap.h: ... to here.
* ctf-util.c (ctf_elf32_to_link_sym): Use it, byteswapping the
Elf32_Sym if the ctf_symtab_little_endian demands it.
(ctf_elf64_to_link_sym): Likewise swap the Elf64_Sym if needed.
* ctf-archive.c (ctf_arc_symsect_endianness): New, set the
endianness of the symtab used by the dicts in an archive.
(ctf_archive_iter_internal): Initialize to unknown (assumed native,
do not call ctf_symsect_endianness).
(ctf_dict_open_by_offset): Call ctf_symsect_endianness if need be.
(ctf_dict_open_internal): Propagate the endianness down.
(ctf_dict_open_sections): Likewise.
* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Get the endianness from the
struct bfd and pass it down to the archive.
* libctf.ver: Add ctf_symsect_endianness and
ctf_arc_symsect_endianness.

3 years agoRemove two unnecessary variables from evaluate_subexp_standard
Tom Tromey [Wed, 25 Nov 2020 17:19:40 +0000 (10:19 -0700)] 
Remove two unnecessary variables from evaluate_subexp_standard

I noticed a couple of spots in evaluate_subexp_standard that looked
like:

    value *result;
    result = something;
    return result;

This patch simplifies these spots to a simple "return".

gdb/ChangeLog
2020-11-25  Tom Tromey  <tom@tromey.com>

* eval.c (evaluate_subexp_standard): Remove unnecessary
variables.

3 years agoDo not include parser-defs.h from c-lang.h
Tom Tromey [Tue, 24 Nov 2020 18:50:54 +0000 (11:50 -0700)] 
Do not include parser-defs.h from c-lang.h

While working on another series, I noticed that c-lang.h does not need
to include parser-defs.h.  This patch makes this change, and fixes up
the two .c files that needed this include.  Tested by rebuilding.

gdb/ChangeLog
2020-11-25  Tom Tromey  <tom@tromey.com>

* d-lang.c: Include parser-defs.h.
* rust-lang.c: Include parser-defs.h.
* c-lang.h: Do not include parser-defs.h.

3 years agoDuplicate output sections in scripts
Alan Modra [Tue, 24 Nov 2020 13:11:31 +0000 (23:41 +1030)] 
Duplicate output sections in scripts

Previously, ld merged duplicate output sections if such existed in
scripts, except for those with a constraint of SPECIAL.  This makes
scripts with duplicate output section statements create duplicate
output sections in the linker output file.

* ldlang.c (lang_output_section_statement_lookup): Change "create"
parameter to a tristate, if 2 then always create a new output
section statement.  Update all callers, with
lang_enter_output_section_statement using "2".
(map_input_to_output_sections): Don't ignore SPECIAL constraint
here.
* ldlang.h (lang_output_section_statement_type): Update prototype.
(lang_output_section_find): Update.

3 years agonm ifunc test tweaks
Alan Modra [Tue, 24 Nov 2020 13:10:53 +0000 (23:40 +1030)] 
nm ifunc test tweaks

* testsuite/binutils-all/nm.exp (ifunc): xfail more targets.

3 years agogas output_file_close error message
Alan Modra [Mon, 23 Nov 2020 22:15:33 +0000 (08:45 +1030)] 
gas output_file_close error message

Seen on arm-elf, where ELFOSABI_ARM is set too late to get a warning
when processing ifunc related directives on their source line.
../gas/as-new ifunc.s -o tmpdir/ifunc.o
../gas/as-new: symbol type STT_GNU_IFUNC is supported only by GNU and FreeBSD targets
ifunc.s: Assembler messages:
ifunc.s: Fatal error: can't close tmpdir/ifunc.o: sorry, cannot handle this file

This patch doesn't fix the real underlying problem, just the late
error message where "can't close" is a misdirection in this case.

* output-file.c (output_file_close): Remove "can't close" from
error message.
* testsuite/gas/mips/reginfo-2.l: Update expected output.

3 years agoAutomatic date update in version.in
GDB Administrator [Wed, 25 Nov 2020 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agold/x86-64: Add PR gold/26939 tests
H.J. Lu [Tue, 24 Nov 2020 19:32:14 +0000 (11:32 -0800)] 
ld/x86-64: Add PR gold/26939 tests

GOTPCRELX relocations can be transformed only when addend == -4.  Add
tests for GOTPCRELX relocations with addend != -4.

PR gold/26939
* testsuite/ld-x86-64/pr26939-x32.d: New file.
* testsuite/ld-x86-64/pr26939.d: Likewise.
* testsuite/ld-x86-64/pr26939.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR gold/26939 tests.

3 years agogdb: remove struct cached_reg typedef
Simon Marchi [Tue, 24 Nov 2020 14:57:21 +0000 (09:57 -0500)] 
gdb: remove struct cached_reg typedef

Since we are in C++, this typedef is no longer necessary, we can just
refer to the struct name directly.

gdb/ChangeLog:

* regcache.h (struct cached_reg): Remove typedef.

Change-Id: I0168b5a9cf88e9b962521760c7e2d0e6f0b52cdf

3 years agogdb/testsuite: do not hard-code location indices in condbreak-multi-context.exp
Tankut Baris Aktemur [Tue, 24 Nov 2020 08:56:38 +0000 (09:56 +0100)] 
gdb/testsuite: do not hard-code location indices in condbreak-multi-context.exp

Breakpoint locations are sorted according to their addresses.  The
addresses are determined by how the compiler emits the code.
Therefore, we may have a different order of locations depending on the
compiler we use.  To make the gdb.base/condbreak-multi-context.exp
test flexible enough for different compilers' output, do not hard-code
location indices.

Tested with GCC and Clang.

gdb/testsuite/ChangeLog:
2020-11-24  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.base/condbreak-multi-context.exp: Do not hard-code location
indices.

3 years agogdb/README: Fix the URL of the MPFR website (now https).
Joel Brobecker [Tue, 24 Nov 2020 03:10:06 +0000 (07:10 +0400)] 
gdb/README: Fix the URL of the MPFR website (now https).

gdb/ChangeLog:

        * README: Fix the URL of the MPFR library.

3 years agogdb/README: Document the --with-libgmp-prefix configure option
Joel Brobecker [Tue, 24 Nov 2020 03:09:23 +0000 (07:09 +0400)] 
gdb/README: Document the --with-libgmp-prefix configure option

gdb/ChangeLog:

        * README: Document the --with-libgmp-prefix configure option.

3 years agogdb/NEWS: Document that GDB now supports DWARF-based fixed point types
Joel Brobecker [Tue, 24 Nov 2020 03:08:42 +0000 (07:08 +0400)] 
gdb/NEWS: Document that GDB now supports DWARF-based fixed point types

gdb/ChangeLog:

        * NEWS: Add entry documenting support for DWARF-based fixed
        point types.

3 years agogdb/NEWS: Document that building GDB now requires GMP
Joel Brobecker [Tue, 24 Nov 2020 03:08:05 +0000 (07:08 +0400)] 
gdb/NEWS: Document that building GDB now requires GMP

gdb/ChangeLog:

        * NEWS: Document that building GDB now requires GMP.

3 years agoAdd TYPE_CODE_FIXED_POINT handling in print_type_scalar
Joel Brobecker [Tue, 24 Nov 2020 03:03:36 +0000 (22:03 -0500)] 
Add TYPE_CODE_FIXED_POINT handling in print_type_scalar

This commit enhances print_type_scalar to include support for
TYPE_CODE_FIXED_POINT. This way, any language falling back to
this function for printing the description of some types
also gets basic ptype support for fixed point types as well.

This fixes a couple of XFAILs in gdb.dwarf2/dw2-fixed-point.exp.

gdb/ChangeLog:

        * typeprint.c (print_type_scalar): Add handling of
        TYPE_CODE_FIXED_POINT.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/dw2-fixed-point.exp: Fix the expected output of
        the "ptype pck__fp1_range_var" test for the module-2 and pascal
        languages.  Remove the associated setup_xfail.

3 years agovalarith.c: Replace INIT_VAL_WITH_FIXED_POINT_VAL macro by lambda
Joel Brobecker [Tue, 24 Nov 2020 02:50:29 +0000 (21:50 -0500)] 
valarith.c: Replace INIT_VAL_WITH_FIXED_POINT_VAL macro by lambda

gdb/ChangeLog (Simon Marchi  <simark@simark.ca>):

        * valarith.c (fixed_point_binop): Replace the
        INIT_VAL_WITH_FIXED_POINT_VAL macro by a lambda.  Update all
        users accordingly.

3 years agoMake function fixed_point_scaling_factor a method of struct type
Joel Brobecker [Tue, 24 Nov 2020 02:49:13 +0000 (21:49 -0500)] 
Make function fixed_point_scaling_factor a method of struct type

This logically connects this function to the object it inspects.

gdb/ChangeLog:

        * gdbtypes.h (struct type) <fixed_point_scaling_factor>: New method,
        replacing fixed_point_scaling_factor.  All callers updated
        throughout this project.
        (fixed_point_scaling_factor): Delete declaration.
        * gdbtypes.c (type::fixed_point_scaling_factor): Replaces
        fixed_point_scaling_factor.  Adjust implementation accordingly.

3 years agoMake fixed_point_type_base_type a method of struct type
Joel Brobecker [Tue, 24 Nov 2020 02:48:23 +0000 (21:48 -0500)] 
Make fixed_point_type_base_type a method of struct type

As suggested by Simon, to logically connect this function to
the object it inspects.

Note that, logically, this method should be "const". Unfortunately,
the implementation iterates on struct type objects starting with "this",
and thus trying to declare the method "const" triggers a compilation
error.

gdb/ChangeLog:

        * gdbtypes.h (struct type) <fixed_point_type_base_type> New method,
        replacing the fixed_point_type_base_type function. All callers
        updated throughout this project.
        (fixed_point_type_base_type): Remove declaration.
        * gdbtypes.c (type::fixed_point_type_base_type): Replaces
        fixed_point_type_base_type.  Adjust implementation accordingly.

3 years agogdbtypes.h: Get rid of the TYPE_FIXED_POINT_INFO macro
Joel Brobecker [Tue, 24 Nov 2020 02:47:40 +0000 (21:47 -0500)] 
gdbtypes.h: Get rid of the TYPE_FIXED_POINT_INFO macro

This is one step further towards the removal of all these macros.

gdb/ChangeLog:

        * gdbtypes.h (struct type) <fixed_point_info, set_fixed_point_info>:
        New methods.
        (INIT_FIXED_POINT_SPECIFIC): Adjust.
        (TYPE_FIXED_POINT_INFO): Delete macro.
        (allocate_fixed_point_type_info): Change return type to void.
        * gdbtypes.c (copy_type_recursive): Replace the use of
        TYPE_FIXED_POINT_INFO by a call to the fixed_point_info method.
        (fixed_point_scaling_factor): Likewise.
        (allocate_fixed_point_type_info): Change return type to void.
        Adjust implementation accordingly.
        * dwarf2/read.c (finish_fixed_point_type): Replace the use of
        TYPE_FIXED_POINT_INFO by a call to the fixed_point_info method.

3 years agogmp-utils: Convert the read/write methods to using gdb::array_view
Joel Brobecker [Tue, 24 Nov 2020 02:46:38 +0000 (21:46 -0500)] 
gmp-utils: Convert the read/write methods to using gdb::array_view

This commit changes the interfaces of some of the methods declared
in gmp-utils to take a gdb::array_view of gdb_byte instead of a
(gdb_byte *, size) couple.

This makes these methods' API probably more C++-idiomatic.

        * gmp-utils.h (gdb_mpz::read): Change buf and len parameters
        into one single gdb::array_view parameter.
        (gdb_mpz::write): Likewise.
        (gdb_mpq::read_fixed_point, gdb_mpq::write_fixed_point): Likewise.
        * gmp-utils.c (gdb_mpz::read): Change buf and len parameters
        into one single gdb::array_view parameter.
        Adjust implementation accordingly.
        (gdb_mpz::write): Likewise.
        (gdb_mpq::read_fixed_point, gdb_mpq::write_fixed_point): Likewise.
        * unittests/gmp-utils-selftests.c: Adapt following changes above.
        * valarith.c, valops.c, valprint.c, value.c: Likewise.

3 years agochange and rename gmp_string_asprintf to return an std::string
Joel Brobecker [Tue, 24 Nov 2020 02:45:35 +0000 (21:45 -0500)] 
change and rename gmp_string_asprintf to return an std::string

This was suggested by Simon during a code review of this package upstream.
The upside is that this makes the function's API more natural and C++.
The downside is an extra malloc, which might be the reason why we went
for using a unique_xmalloc_ptr in the first place. Since this function
is not expected to be called frequently, the API improvement might be
worth the performance impact.

gdb/ChangeLog:

        * gmp-utils.h (gmp_string_printf): Rename from gmp_string_asprintf.
        Change return type to std::string. Update all callers.
        * gmp-utils.c (gmp_string_printf): Likewise.

3 years agoFix stack smashing error during gdb_mpq_write_fixed_point selftest
Joel Brobecker [Tue, 24 Nov 2020 02:34:57 +0000 (06:34 +0400)] 
Fix stack smashing error during gdb_mpq_write_fixed_point selftest

When building GDB using Ubuntu 20.04's system libgmp and compiler,
running the "maintenance selftest" command triggers the following error:

    | Running selftest gdb_mpq_write_fixed_point.
    | *** stack smashing detected ***: terminated
    | [1]    1092790 abort (core dumped)  ./gdb gdb

This happens while trying to construct an mpq_t object (a rational)
from two integers representing the numerator and denominator.
In our test, the numerator is -8, and the denominator is 1.
The problem was that the rational was constructed using the wrong
function. This is what we were doing prior to this patch:

    mpq_set_ui (v.val, numerator, denominator);

The 'u' in "ui" stands for *unsigned*, which is wrong because
numerator and denominator's type is "int".

As a result of the above, instead of getting a rational value of -8,
we get a rational with a very large positive value (gmp_printf
says "18446744073709551608").

From there, the test performs an operation which is expected to
write this value into a buffer which was not dimensioned to fit
such a number, thus leading GMP into a buffer overflow.
This was verified by applying the formula that GMP's documentation
gives for the required memory buffer size needed during export:

    | When an application is allocating space itself the required size can
    | be determined with a calculation like the following. Since
    | mpz_sizeinbase always returns at least 1, count here will be at
    | least one, which avoids any portability problems with malloc(0),
    | though if z is zero no space at all is actually needed (or written).
    |
    |     numb = 8*size - nail;
    |     count = (mpz_sizeinbase (z, 2) + numb-1) / numb;
    |     p = malloc (count * size);

With the very large number, mpz_sizeinbase returns 66 and thus
the malloc size becomes 16 bytes instead of the 8 we allocated.

This patch fixes the issue by using the correct "set" function.

gdb/ChangeLog:

        * unittests/gmp-utils-selftests.c (write_fp_test): Use mpq_set_si
        instead of mpq_set_ui to initialize our GMP rational.

3 years agoAutomatic date update in version.in
GDB Administrator [Tue, 24 Nov 2020 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb/testsuite: show evaluation errors in gdb_assert
Simon Marchi [Mon, 23 Nov 2020 22:26:00 +0000 (17:26 -0500)] 
gdb/testsuite: show evaluation errors in gdb_assert

Let's say you put this gdb_assert in a test:

    gdb_assert "some invalid tcl code"

You just get:

    FAIL: gdb.base/template.exp: some invalid tcl code

That's not very easy to debug, since you don't know what's invalid in
your code.

Change gdb_assert to print the error message when catch's return code is
1 (TCL_ERROR).  The "warning" is shown both on stdout and in the log
file.  Mark the test as unresolved, because the evaluation error means
we couldn't reach a valid pass/fail conclusion.

gdb/testsuite/ChangeLog:

* lib/gdb.exp (gdb_assert): Show error message on error.

Change-Id: Ie6477859554e909ed8d07fb2769c6f2f55e7cce6

3 years ago[gdb/testsuite] Fix minimal encodings KPASSes
Tom de Vries [Mon, 23 Nov 2020 19:09:50 +0000 (20:09 +0100)] 
[gdb/testsuite] Fix minimal encodings KPASSes

With current master I see a couple of KPASSes:
...
KPASS: gdb.ada/enum_idx_packed.exp: scenario=minimal: ptype small \
  (PRMS minimal encodings)
  ...
KPASS: gdb.ada/mod_from_name.exp: scenario=minimal: print xp \
  (PRMS minimal encodings)
KPASS: gdb.ada/pckd_arr_ren.exp: scenario=minimal: print var \
  (PRMS minimal encodings)
...

The corresponding setup_kfail is called for everything before gnat 11.

However, the test-cases also PASS for me with gnat-4.8, gnat-7.5.0 and
gnat-8.4.0.

Fix the KPASSes by limiting the setup_kfail to gnat 9 and 10.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-11-23  Tom de Vries  <tdevries@suse.de>

* gdb.ada/enum_idx_packed.exp: Limit setup_kfail to gnat 9 and 10.
* gdb.ada/mod_from_name.exp: Same.
* gdb.ada/pckd_arr_ren.exp: Same.

3 years ago[gdb] Don't return non-existing path in debuginfod_source_query
Tom de Vries [Mon, 23 Nov 2020 19:09:50 +0000 (20:09 +0100)] 
[gdb] Don't return non-existing path in debuginfod_source_query

When setting env var DEBUGINFOD_URLS to " " and running the testsuite, we run
into these regressions:
...
FAIL: gdb.base/list-missing-source.exp: info source
FAIL: gdb.base/source-dir.exp: info source before setting directory search list
...

Setting var DEBUGINFOD_URLS to " " allows the debuginfod query function
debuginfod_source_query to get past its early exit.

The function debuginfod_source_query is documented as: "If the file is
successfully retrieved, its path on the local machine is stored in DESTNAME".

However, in case we get back -ENOENT from libdebuginfod, we still set
DESTNAME:
....
  if (fd.get () < 0 && fd.get () != -ENOENT)
    printf_filtered (_("Download failed: %s.  Continuing without source file %ps.\n"),
                     safe_strerror (-fd.get ()),
                     styled_string (file_name_style.style (),  srcpath));
  else
    *destname = make_unique_xstrdup (srcpath);

  return fd;
...

Fix this by making debuginfod_source_query fit it's documentation and only
setting DESTNAME when successfully retrieving a file.  Likewise in
debuginfod_debuginfo_query.

gdb/ChangeLog:

2020-11-23  Tom de Vries  <tdevries@suse.de>

* debuginfod-support.c (debuginfod_source_query)
(debuginfod_debuginfo_query): Only set DESTNAME if successful.

3 years agoFix an illegal memory access when accessing corrupt dynamic secondary relocations.
Nick Clifton [Mon, 23 Nov 2020 14:07:02 +0000 (14:07 +0000)] 
Fix an illegal memory access when accessing corrupt dynamic secondary relocations.

PR 26931
* elf-bfd.h (struct elf_backend_data): Add bfd_boolean field to
slurp_secondary_relocs field.
(_bfd_elf_slurp_secondary_reloc_section): Update prototype.
* elf.c (_bfd_elf_slurp_secondary_reloc_section): Add new
parameter.  Compute number of symbols based upon the new
parameter.
* elfcode.h (elf_slurp_reloc_table): Pass dynamic as new
parameter.

3 years agos390x: Set .got sh_entsize only if .got size > 0
H.J. Lu [Mon, 23 Nov 2020 13:06:51 +0000 (05:06 -0800)] 
s390x: Set .got sh_entsize only if .got size > 0

bfd/

PR ld/26918
* elf64-s390.c (elf_s390_finish_dynamic_sections): Set .got
sh_entsize only if .got size > 0.

ld:

PR ld/26918
* testsuite/ld-s390/pr26918-1.d: New file.
* testsuite/ld-s390/pr26918-1.s: Likewise.
* testsuite/ld-s390/s390.exp: Run all *.d tests.

3 years agold: Make ARC's tls_ie-01 test more flexible
Shahab Vahedi [Mon, 23 Nov 2020 10:24:29 +0000 (12:24 +0200)] 
ld: Make ARC's tls_ie-01 test more flexible

This is to address the regressions addressed by Nic [1].

The regular expression pattern for the tls_ie-01 test was
too strict and raising false alarms.  The new pattern only
looks for matches that should be there AND ignores the boiler
plates from the object dump.

[1] New failures for ARC targets in linker testsuite
https://sourceware.org/pipermail/binutils/2020-November/114177.html

ld/

* testsuite/ld-arc/tls_ie-01.d: Use a more general pattern.

3 years agoaarch64: Add support for Cortex-A78C
Przemyslaw Wirkus [Mon, 23 Nov 2020 10:03:36 +0000 (10:03 +0000)] 
aarch64: Add support for Cortex-A78C

This patch adds support for -mcpu=cortex-a78c command line option.
For more information about this processor, see [0]:

[0] https://developer.arm.com/ip-products/processors/cortex-a/cortex-a78c

3 years agogdb/testsuite: add template for test cases
Simon Marchi [Mon, 23 Nov 2020 03:04:27 +0000 (22:04 -0500)] 
gdb/testsuite: add template for test cases

The wiki contains a template for new test cases:

    https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Building_the_Example_Program

... which is helpful, because even after many years I can't write all
the boilerplate for writing a test case without doing some mistakes.

However, I think it would be nice to have it in the tree.  It's much
faster to cp the files than going to the wiki and copy/pasting the
contents.

As a bonus, the copyright years will get updated in these files, unlike
those in the wiki.  So they will always be good when we start a new
test.

If this patch is merged, I plan to change the wiki to just point to
these files.

gdb/testsuite/ChangeLog:

* gdb.base/template.exp: New.
* gdb.base/template.c: New.

Change-Id: I7dbf068a043b48f83cc325087d70e868eee998c6

3 years agoAutomatic date update in version.in
GDB Administrator [Mon, 23 Nov 2020 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years ago[gdb/testsuite] Add testcase for DW_AT_count referencing a variable
Gary Benson [Sun, 22 Nov 2020 09:54:58 +0000 (10:54 +0100)] 
[gdb/testsuite] Add testcase for DW_AT_count referencing a variable

Clang describes the upper bounds of variable length arrays using
a DW_AT_count attribute which references the DIE of a synthetic
variable whose value is specified using a DW_AT_location.  GDB handles
these incorrectly if the corresponding DWARF expression finishes with a
DW_OP_stack_value (PR26905).  This commit adds a new kfailed test to
gdb.dwarf2/count.exp with the same DWARF as that generated by Clang for
gdb.base/vla-optimized-out.exp, one of the failing tests.

Checked on Fedora 32 x86_64, with GCC and Clang.

gdb/testsuite/ChangeLog:

2020-11-22  Gary Benson <gbenson@redhat.com>

PR gdb/26905
* gdb.dwarf2/count.exp: Add test for an array whose upper bound
is defined using a DW_AT_count which references another DIE.

3 years agoAutomatic date update in version.in
GDB Administrator [Sun, 22 Nov 2020 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years ago[gdb/testsuite] Add clang xfail in gdb.base/vla-ptr.exp
Tom de Vries [Sat, 21 Nov 2020 17:11:36 +0000 (18:11 +0100)] 
[gdb/testsuite] Add clang xfail in gdb.base/vla-ptr.exp

When running gdb.base/vla-ptr.exp with clang-10, we run into this FAIL:
...
(gdb) print td_vla^M
$6 = 0x7fffffffd2b0^M
(gdb) FAIL: gdb.base/vla-ptr.exp: print td_vla
...

Clang 10.0.1 generates the following DWARF for td_vla.  A variable DIE:
...
 <2><19f>: Abbrev Number: 6 (DW_TAG_variable)
    <1a0>   DW_AT_location    : 0x39 (location list)
    <1a4>   DW_AT_name        : td_vla
    <1aa>   DW_AT_type        : <0x1ae>
....
with typedef type:
...
 <2><1ae>: Abbrev Number: 7 (DW_TAG_typedef)
    <1af>   DW_AT_type        : <0x1fc>
    <1b3>   DW_AT_name        : typedef_vla
...
pointing to:
...
 <1><1fc>: Abbrev Number: 11 (DW_TAG_array_type)
    <1fd>   DW_AT_type        : <0x1d3>
 <2><201>: Abbrev Number: 14 (DW_TAG_subrange_type)
    <202>   DW_AT_type        : <0x1f5>
...

The subrange type is missing the count attribute.  This was filed as
llvm PR48247 - "vla var with typedef'd type has incomplete debug info".

Mark this as xfail.

gdb/testsuite/ChangeLog:

2020-11-21  Tom de Vries  <tdevries@suse.de>

* gdb.base/vla-ptr.exp: Add XFAIL.

3 years agoChange watchpoint_exp_is_const to return bool
Tom Tromey [Sat, 21 Nov 2020 16:16:41 +0000 (09:16 -0700)] 
Change watchpoint_exp_is_const to return bool

I noticed that watchpoint_exp_is_const should return bool; this patch
implements this change.

gdb/ChangeLog
2020-11-21  Tom Tromey  <tom@tromey.com>

* breakpoint.c (watchpoint_exp_is_const): Return bool.

3 years agoRISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous.
Nelson Chu [Wed, 18 Nov 2020 03:39:52 +0000 (19:39 -0800)] 
RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous.

I get the feedback recently that enable linker relaxations may fail to
build some program.  Consider the following case,

.text
foo:
addi a0, a0, %pcrel_lo(.L2)
call foo
.L1: auipc a1, %pcrel_hi(data_g)
addi a1, a1, %pcrel_lo(.L1)
lui a2, %hi(data_g)
addi a2, a2, %lo(data_g)
lui a3, %tprel_hi(data_t)
add a3, a3, tp, %tprel_add(data_t)
addi a3, a3, %tprel_lo(data_t)
.L2: auipc a0, %pcrel_hi(data_g)

.data
.word 0x0
.global data_g
data_g: .word 0x1

.section .tbss
data_t: .word 0x0

The current ld reports `dangerous relocation error` when doing the
pcgp relaxation,
test.o: in function `foo':
(.text+0x0): dangerous relocation: %pcrel_lo missing matching %pcrel_hi

The .L2 auipc should not be removed since it is behind the corresponding
addi, so we record the information in the pcgp_relocs table to avoid
removing the auipc later.  But current ld still remove it since we do not
update the pcgp_relocs table while doing other relaxations.  I have two
solutions to fix the problem,

1. Update the pcgp_relocs table once we actually delete the code.
2. Add new relax pass to do the pcgp relaxations

At first I tried to do the first solution, and we need to update at
least three information - hi_sec_off of riscv_pcgp_lo_reloc, hi_sec_off
and hi_addr (symbol value) of riscv_pcgp_hi_reloc.  Update the hi_sec_off
is simple, but it is more complicate to update the symbol value, since we
almost have to do parts the same works of _bfd_riscv_relax_call again in
the riscv_relax_delete_bytes to get the correct symbol value.

Compared with the first solution, the second one is more intuitive and
simple.  We add a new relax pass to do the pcgp relaxations later, so
we will get all the information correctly in the _bfd_riscv_relax_call,
including the symbol value, without changing so much code.  I do not see
any penalty by adding a new relax pass for now, so it should be fine
to delay the pcgp relaxations.

Besides, I have pass all riscv-gnu-toolchain regressions for this patch.

bfd/
* elfnn-riscv.c (_bfd_riscv_relax_section):  Add a new relax pass
to do the pcgp relaxation later, after the lui and call relaxations,
but before the delete and alignment relaxations.

ld/
* emultempl/riscvelf.em (riscv_elf_before_allocation): Change
link_info.relax_pass from 3 to 4.
* testsuite/ld-riscv-elf/pcgp-relax.d: New testcase.
* testsuite/ld-riscv-elf/pcgp-relax.s: Likewise.
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.

3 years agoAutomatic date update in version.in
GDB Administrator [Sat, 21 Nov 2020 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb: fix unittests/gmp-utils-selftests.c build on solaris
Simon Marchi [Fri, 20 Nov 2020 16:17:33 +0000 (11:17 -0500)] 
gdb: fix unittests/gmp-utils-selftests.c build on solaris

When building on solaris (gcc farm machine gcc211), I get:

      CXX    unittests/gmp-utils-selftests.o
    /export/home/simark/src/binutils-gdb/gdb/unittests/gmp-utils-selftests.c: In function 'void selftests::gdb_mpz_read_all_from_small()'  :
    /export/home/simark/src/binutils-gdb/gdb/unittests/gmp-utils-selftests.c:128:43: error: call of overloaded 'pow(int, int)'   is ambiguous
       LONGEST l_min = -pow (2, buf_len * 8 - 1);
                                               ^
    In file included from /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/math.h:22:0,
                     from ../gnulib/import/math.h:27,
                     from /export/home/simark/src/binutils-gdb/gdb/unittests/gmp-utils-selftests.c:23:
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/math_iso.h:210:21: note: candidate: long double std::pow(long double, long double)
      inline long double pow(long double __X, long double __Y) { return
                         ^
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/math_iso.h:170:15: note: candidate: float std::pow(float, float)
      inline float pow(float __X, float __Y) { return __powf(__X, __Y); }
                   ^
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/math_iso.h:71:15: note: candidate: double std::pow(double, double)
     extern double pow __P((double, double));
                   ^

The "pow" function overloads only exist for float-like types, and the
compiler doesn't know which one we want.  Change "2" for "2.0", which
makes the compiler choose one alternative (the double one, I believe).

gdb/ChangeLog:

* unittests/gmp-utils-selftests.c (gdb_mpz_read_all_from_small):
Pass 2.0 to pow.
(gdb_mpz_write_all_from_small): Likewise.

Change-Id: Ied2ae0f01494430244a7c94f8a38b07d819f4213

3 years agogdb: fix dwarf2/read.c build on solaris
Simon Marchi [Fri, 20 Nov 2020 16:17:32 +0000 (11:17 -0500)] 
gdb: fix dwarf2/read.c build on solaris

When building on solaris (gcc farm machine gcc211), I get:

      CXX    dwarf2/read.o
    /export/home/simark/src/binutils-gdb/gdb/dwarf2/read.c: In function 'void finish_fixed_point_type(type*, die_info*, dwarf2_cu*)':
    /export/home/simark/src/binutils-gdb/gdb/dwarf2/read.c:18204:42: error: call of overloaded 'abs(LONGEST&)' is ambiguous
           *num_or_denom = 1 << abs (scale_exp);
                                              ^
    In file included from /usr/include/stdlib.h:11:0,
                     from ../gnulib/import/stdlib.h:36,
                     from /opt/csw/include/c++/5.5.0/cstdlib:72,
                     from /export/home/simark/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:90,
                     from /export/home/simark/src/binutils-gdb/gdb/defs.h:28,
                     from /export/home/simark/src/binutils-gdb/gdb/dwarf2/read.c:31:
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/stdlib_iso.h:163:16: note: candidate: long int std::abs(long int)
      inline long   abs(long _l) { return labs(_l); }
                    ^
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/stdlib_iso.h:117:12: note: candidate: int std::abs(int)
     extern int abs(int);
                ^

I don't know why, but using std::abs instead of just abs fixes it.

gdb/ChangeLog:

* dwarf2/read.c (finish_fixed_point_type): Use std::abs instead
of abs.

Change-Id: I57b9098351f2a8b2d2f61e848b97f7b2dfe55908

3 years agoIgnore system_error in thread startup
Tom Tromey [Fri, 20 Nov 2020 15:22:46 +0000 (08:22 -0700)] 
Ignore system_error in thread startup

libstdc++ might change so that it always implements std::thread, but
then have thread startup simply fail.  This is being discussed here:

https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558736.html

This patch pre-emptively changes gdb to handle this scenario.  It
seemed fine to me to ignore all system errors at thread startup, so
that is what this does.

gdbsupport/ChangeLog
2020-11-20  Tom Tromey  <tromey@adacore.com>

* thread-pool.cc (thread_pool::set_thread_count): Ignore system
errors.

3 years agoAdd missing test file
Nick Clifton [Fri, 20 Nov 2020 14:06:14 +0000 (14:06 +0000)] 
Add missing test file

3 years agolibctf: do not crash when CTF symbol or variable linking fails
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf: do not crash when CTF symbol or variable linking fails

When linking fails, we delete all the generated outputs, but we fail to
remove them from the ctf_link_outputs hash we stuck them in before doing
symbol and variable section linking (which we had to do because that's
where ctf_create_per_cu, used by both, looks for them).  This leaves
stale pointers to freed memory behind, and crashes soon follow.

Fix obvious.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-link.c (ctf_link_deduplicating): Clean up the ctf_link_outputs
hash on error.

3 years agolibctf: error-handling fixes
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf: error-handling fixes

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-create.c (ctf_dtd_insert): Set ENOMEM on the dict if out of memory.
(ctf_dvd_insert): Likewise.
(ctf_add_function): Report ECTF_RDONLY if this dict is not writable.
* ctf-subr.c (ctf_err_warn): Only debug-dump passed-in warnings if
the passed-in error code is nonzero: the error on the dict for
warnings may relate to a previous error.

3 years agolibctf, include: add ctf_getsymsect and ctf_getstrsect
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf, include: add ctf_getsymsect and ctf_getstrsect

libctf has long provided ctf_getdatasect, which hands back a pointer to
the CTF section a (read-only) dict came from.  But it has no such
functions to return pointers to the ELF symbol table or string table
it's working from, which is unfortunate because several libctf functions
(ctf_open, ctf_fdopen, and ctf_bfdopen) figure out which string and
symbol table to use themselves, and don't tell the user what they
decided, so the caller can't agree on which symtab to use with libctf
even if it wanted to.

Add a pair of functions to return the symtab and strtab in use.  Like
ctf_getdatasect, these return ctf_sect_t structures by value, filled
with all-NULL/0 content if a symtab or strtab is not being used.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-api.h (ctf_getsymsect): New.
(ctf_getstrsect): Likewise.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-open.c (ctf_getsymsect): New.
(ctf_getstrsect): Likewise.
* libctf.ver: Add them.

3 years agolibctf, include: CTF-archive-wide symbol lookup
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf, include: CTF-archive-wide symbol lookup

CTF archives may contain multiple dicts, each of which contain many
types and possibly a bunch of symtypetab entries relating to those
types: each symtypetab entry is going to appear in exactly one dict,
with the corresponding entries in the other dicts empty (either pads, or
indexed symtypetabs that do not mention that symbol).  But users of
libctf usually want to get back the type associated with a symbol
without having to dig around to find out which dict that type might be
in.

This adds machinery to do that -- and since you probably want to do it
repeatedly, it adds internal caching to the ctf-archive machinery so
that iteration over archives via ctf_archive_next and repeated symbol
lookups do not have to repeatedly reopen the archive.  (Iteration using
ctf_archive_iter will gain caching soon.)

Two new API functions:

ctf_dict_t *
ctf_arc_lookup_symbol (ctf_archive_t *arc, unsigned long symidx,
       ctf_id_t *typep, int *errp);

This looks up the symbol with index SYMIDX in the archive ARC, returning
the dictionary in which it resides and optionally the type index as
well.  Errors are returned in ERRP.  The dict should be
ctf_dict_close()d when done, but is also cached inside the ctf_archive
so that the open cost is only paid once.  The result of the symbol
lookup is also cached internally, so repeated lookups of the same symbol
are nearly free.

void ctf_arc_flush_caches (ctf_archive_t *arc);

Flush all the caches. Done at close time, but also available as an API
function if users want to do it by hand.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-api.h (ctf_arc_lookup_symbol): New.
(ctf_arc_flush_caches): Likewise.
* ctf.h: Document new auto-ctf_import behaviour.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-impl.h (struct ctf_archive_internal) <ctfi_dicts>: New, dicts
the archive machinery has opened and cached.
<ctfi_symdicts>: New, cache of dicts containing symbols looked up.
<ctfi_syms>: New, cache of types of symbols looked up.
* ctf-archive.c (ctf_arc_close): Free them on close.
(enosym): New, flag entry for 'symbol not present'.
(ctf_arc_import_parent): New, automatically import the parent from
".ctf" if this is a child in an archive and ".ctf" is present.
(ctf_dict_open_sections): Use it.
(ctf_archive_iter_internal): Likewise.
(ctf_cached_dict_close): New, thunk around ctf_dict_close.
(ctf_dict_open_cached): New, open and cache a dict.
(ctf_arc_flush_caches): New, flush the caches.
(ctf_arc_lookup_symbol): New, look up a symbol in (all members of)
an archive, and cache the lookup.
(ctf_archive_iter): Note the new caching behaviour.
(ctf_archive_next): Use ctf_dict_open_cached.
* libctf.ver: Add ctf_arc_lookup_symbol and ctf_arc_flush_caches.

3 years agolibctf, ld: properly deduplicate function types
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf, ld: properly deduplicate function types

Some type kinds in CTF (functions, arrays, pointers, slices, and
cvr-quals) are intrinsically nameless: the ctt_name field in the CTF
is always zero, and the libctf API provides no way to set a name.
But the compiler can and does sometimes set names for some of these
kinds: in particular, the name it sets on CTF_K_FUNCTION types is the
means it uses to force the name of the function into the string table
so that it can point at it from the function info section.

So null out the name at hashing time so that the deduplicator can
correctly detect that e.g. function types identical but for name should
be considered truly identical, since they will not have a name when the
deduplicator re-emits them into the output.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* testsuite/ld-ctf/data-func-conflicted.d: Shrink the expected
size of the type section now that function types are being
deduplicated properly.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-dedup.c (ctf_dedup_rhash_type): Null out the names of nameless
type kinds, just in case the input has named them.

3 years agold, ctf: new and adjusted CTF tests due to func info / object data sections
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
ld, ctf: new and adjusted CTF tests due to func info / object data sections

The flags word is nonzero now (so all the tests have been adjusted to
not depend on its content): some of them have data objects and functions
in the data object and function info sections now, rather than in the
variable section or recorded nowhere.  There is a new test for
parent/child relationships and index section emission.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* testsuite/ld-ctf/array.d: Adjust for nonzero flags word and
public symbols in the data section rather than variables: use
sysv hash style to keep test results the same on non-GNU targets.
* testsuite/ld-ctf/diag-cttname-null.d: Likewise.
* testsuite/ld-ctf/diag-cuname.d: Likewise.
* testsuite/ld-ctf/diag-parlabel.d: Likewise.
* testsuite/ld-ctf/slice.d: Likewise.
* testsuite/ld-ctf/function.d: Likewise, but in the function section.
* testsuite/ld-ctf/conflicting-cycle-1.B-1.d:  Adjust for nonzero
flags word.
* testsuite/ld-ctf/conflicting-cycle-1.B-2.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-2.A-1.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-2.A-2.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-2.parent.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-3.C-1.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-3.C-2.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-3.parent.d: Likewise.
* testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise.
* testsuite/ld-ctf/cycle-1.d: Likewise.
* testsuite/ld-ctf/cycle-2.A.d: Likewise.
* testsuite/ld-ctf/cycle-2.B.d: Likewise.
* testsuite/ld-ctf/cycle-2.C.d: Likewise.
* testsuite/ld-ctf/diag-wrong-magic-number-mixed.d:  Likewise.
* testsuite/ld-ctf/super-sub-cycles.d:  Likewise.
* testsuite/ld-ctf/data-func-1.c: New test.
* testsuite/ld-ctf/data-func-2.c: Likewise.
* testsuite/ld-ctf/data-func-conflicted.d: Likewise.

3 years agolibctf: adjust dumper for symtypetab changes
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf: adjust dumper for symtypetab changes

Now that we have a new format for the function info section, it's much
easier to dump it: we can use the same code we use for the object type
section, and that's got simpler too because we can use ctf_symbol_next.

Also dump the new stuff in the header: the new flags bits and the index
section lengths.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-dump.c (ctf_dump_header): Dump the new flags bits and the index
section lengths.
(ctf_dump_objts): Report indexed sections.  Also dump functions.  Use
ctf_symbol_next, not manual looping.
(ctf_dump_funcs): Delete.
(ctf_dump): Use ctf_dump_objts, not ctf_dump_funcs.

3 years agolibctf: symbol type linking support
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf: symbol type linking support

This adds facilities to write out the function info and data object
sections, which efficiently map from entries in the symbol table to
types.  The write-side code is entirely new: the read-side code was
merely significantly changed and support for indexed tables added
(pointed to by the no-longer-unused cth_objtidxoff and cth_funcidxoff
header fields).

With this in place, you can use ctf_lookup_by_symbol to look up the
types of symbols of function and object type (and, as before, you can
use ctf_lookup_variable to look up types of file-scope variables not
present in the symbol table, as long as you know their name: but
variables that are also data objects are now found in the data object
section instead.)

(Compatible) file format change:

The CTF spec has always said that the function info section looks much
like the CTF_K_FUNCTIONs in the type section: an info word (including an
argument count) followed by a return type and N argument types. This
format is suboptimal: it means function symbols cannot be deduplicated
and it causes a lot of ugly code duplication in libctf.  But
conveniently the compiler has never emitted this!  Because it has always
emitted a rather different format that libctf has never accepted, we can
be sure that there are no instances of this function info section in the
wild, and can freely change its format without compatibility concerns or
a file format version bump.  (And since it has never been emitted in any
code that generated any older file format version, either, we need keep
no code to read the format as specified at all!)

So the function info section is now specified as an array of uint32_t,
exactly like the object data section: each entry is a type ID in the
type section which must be of kind CTF_K_FUNCTION, the prototype of
this function.

This allows function types to be deduplicated and also correctly encodes
the fact that all functions declared in C really are types available to
the program: so they should be stored in the type section like all other
types.  (In format v4, we will be able to represent the types of static
functions as well, but that really does require a file format change.)

We introduce a new header flag, CTF_F_NEWFUNCINFO, which is set if the
new function info format is in use.  A sufficiently new compiler will
always set this flag.  New libctf will always set this flag: old libctf
will refuse to open any CTF dicts that have this flag set.  If the flag
is not set on a dict being read in, new libctf will disregard the
function info section.  Format v4 will remove this flag (or, rather, the
flag has no meaning there and the bit position may be recycled for some
other purpose).

New API:

Symbol addition:
  ctf_add_func_sym: Add a symbol with a given name and type.  The
                    type must be of kind CTF_K_FUNCTION (a function
                    pointer).  Internally this adds a name -> type
                    mapping to the ctf_funchash in the ctf_dict.
  ctf_add_objt_sym: Add a symbol with a given name and type.  The type
                    kind can be anything, including function pointers.
    This adds to ctf_objthash.

These both treat symbols as name -> type mappings: the linker associates
symbol names with symbol indexes via the ctf_link_shuffle_syms callback,
which sets up the ctf_dynsyms/ctf_dynsymidx/ctf_dynsymmax fields in the
ctf_dict.  Repeated relinks can add more symbols.

Variables that are also exposed as symbols are removed from the variable
section at serialization time.

CTF symbol type sections which have enough pads, defined by
CTF_INDEX_PAD_THRESHOLD (whether because they are in dicts with symbols
where most types are unknown, or in archive where most types are defined
in some child or parent dict, not in this specific dict) are sorted by
name rather than symidx and accompanied by an index which associates
each symbol type entry with a name: the existing ctf_lookup_by_symbol
will map symbol indexes to symbol names and look the names up in the
index automatically.  (This is currently ELF-symbol-table-dependent, but
there is almost nothing specific to ELF in here and we can add support
for other symbol table formats easily).

The compiler also uses index sections to communicate the contents of
object file symbol tables without relying on any specific ordering of
symbols: it doesn't need to sort them, and libctf will detect an
unsorted index section via the absence of the new CTF_F_IDXSORTED header
flag, and sort it if needed.

Iteration:
  ctf_symbol_next: Iterator which returns the types and names of symbols
                   one by one, either for function or data symbols.

This does not require any sorting: the ctf_link machinery uses it to
pull in all the compiler-provided symbols cheaply, but it is not
restricted to that use.

(Compatible) changes in API:
  ctf_lookup_by_symbol: can now be called for object and function
                        symbols: never returns ECTF_NOTDATA (which is
now not thrown by anything, but is kept for
                        compatibility and because it is a plausible
                        error that we might start throwing again at some
                        later date).

Internally we also have changes to the ctf-string functionality so that
"external" strings (those where we track a string -> offset mapping, but
only write out an offset) can be consulted via the usual means
(ctf_strptr) before the strtab is written out.  This is important
because ctf_link_add_linker_symbol can now be handed symbols named via
strtab offsets, and ctf_link_shuffle_syms must figure out their actual
names by looking in the external symtab we have just been fed by the
ctf_link_add_strtab callback, long before that strtab is written out.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-api.h (ctf_symbol_next): New.
(ctf_add_objt_sym): Likewise.
(ctf_add_func_sym): Likewise.
* ctf.h: Document new function info section format.
(CTF_F_NEWFUNCINFO): New.
(CTF_F_IDXSORTED): New.
(CTF_F_MAX): Adjust accordingly.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-impl.h (CTF_INDEX_PAD_THRESHOLD): New.
(_libctf_nonnull_): Likewise.
(ctf_in_flight_dynsym_t): New.
(ctf_dict_t) <ctf_funcidx_names>: Likewise.
<ctf_objtidx_names>: Likewise.
<ctf_nfuncidx>: Likewise.
<ctf_nobjtidx>: Likewise.
<ctf_funcidx_sxlate>: Likewise.
<ctf_objtidx_sxlate>: Likewise.
<ctf_objthash>: Likewise.
<ctf_funchash>: Likewise.
<ctf_dynsyms>: Likewise.
<ctf_dynsymidx>: Likewise.
<ctf_dynsymmax>: Likewise.
<ctf_in_flight_dynsym>: Likewise.
(struct ctf_next) <u.ctn_next>: Likewise.
(ctf_symtab_skippable): New prototype.
(ctf_add_funcobjt_sym): Likewise.
(ctf_dynhash_sort_by_name): Likewise.
(ctf_sym_to_elf64): Rename to...
(ctf_elf32_to_link_sym): ... this, and...
(ctf_elf64_to_link_sym): ... this.
* ctf-open.c (init_symtab): Check for lack of CTF_F_NEWFUNCINFO
flag, and presence of index sections.  Refactor out
ctf_symtab_skippable and ctf_elf*_to_link_sym, and use them.  Use
ctf_link_sym_t, not Elf64_Sym.  Skip initializing objt or func
sxlate sections if corresponding index section is present.  Adjust
for new func info section format.
(ctf_bufopen_internal): Add ctf_err_warn to corrupt-file error
handling.  Report incorrect-length index sections.  Always do an
init_symtab, even if there is no symtab section (there may be index
sections still).
(flip_objts): Adjust comment: func and objt sections are actually
identical in structure now, no need to caveat.
(ctf_dict_close):  Free newly-added data structures.
* ctf-create.c (ctf_create): Initialize them.
(ctf_symtab_skippable): New, refactored out of
init_symtab, with st_nameidx_set check added.
(ctf_add_funcobjt_sym): New, add a function or object symbol to the
ctf_objthash or ctf_funchash, by name.
(ctf_add_objt_sym): Call it.
(ctf_add_func_sym): Likewise.
(symtypetab_delete_nonstatic_vars): New, delete vars also present as
data objects.
(CTF_SYMTYPETAB_EMIT_FUNCTION): New flag to symtypetab emitters:
this is a function emission, not a data object emission.
(CTF_SYMTYPETAB_EMIT_PAD): New flag to symtypetab emitters: emit
pads for symbols with no type (only set for unindexed sections).
(CTF_SYMTYPETAB_FORCE_INDEXED): New flag to symtypetab emitters:
always emit indexed.
(symtypetab_density): New, figure out section sizes.
(emit_symtypetab): New, emit a symtypetab.
(emit_symtypetab_index): New, emit a symtypetab index.
(ctf_serialize): Call them, emitting suitably sorted symtypetab
sections and indexes.  Set suitable header flags.  Copy over new
fields.
* ctf-hash.c (ctf_dynhash_sort_by_name): New, used to impose an
order on symtypetab index sections.
* ctf-link.c (ctf_add_type_mapping): Delete erroneous comment
relating to code that was never committed.
(ctf_link_one_variable): Improve variable name.
(check_sym): New, symtypetab analogue of check_variable.
(ctf_link_deduplicating_one_symtypetab): New.
(ctf_link_deduplicating_syms): Likewise.
(ctf_link_deduplicating): Call them.
(ctf_link_deduplicating_per_cu): Note that we don't call them in
this case (yet).
(ctf_link_add_strtab): Set the error on the fp correctly.
(ctf_link_add_linker_symbol): New (no longer a do-nothing stub), add
a linker symbol to the in-flight list.
(ctf_link_shuffle_syms): New (no longer a do-nothing stub), turn the
in-flight list into a mapping we can use, now its names are
resolvable in the external strtab.
* ctf-string.c (ctf_str_rollback_atom): Don't roll back atoms with
external strtab offsets.
(ctf_str_rollback): Adjust comment.
(ctf_str_write_strtab): Migrate ctf_syn_ext_strtab population from
writeout time...
(ctf_str_add_external): ... to string addition time.
* ctf-lookup.c (ctf_lookup_var_key_t): Rename to...
(ctf_lookup_idx_key_t): ... this, now we use it for syms too.
<clik_names>: New member, a name table.
(ctf_lookup_var): Adjust accordingly.
(ctf_lookup_variable): Likewise.
(ctf_lookup_by_id): Shuffle further up in the file.
(ctf_symidx_sort_arg_cb): New, callback for...
(sort_symidx_by_name): ... this new function to sort a symidx
found to be unsorted (likely originating from the compiler).
(ctf_symidx_sort): New, sort a symidx.
(ctf_lookup_symbol_name): Support dynamic symbols with indexes
provided by the linker.  Use ctf_link_sym_t, not Elf64_Sym.
Check the parent if a child lookup fails.
(ctf_lookup_by_symbol): Likewise.  Work for function symbols too.
(ctf_symbol_next): New, iterate over symbols with types (without
sorting).
(ctf_lookup_idx_name): New, bsearch for symbol names in indexes.
(ctf_try_lookup_indexed): New, attempt an indexed lookup.
(ctf_func_info): Reimplement in terms of ctf_lookup_by_symbol.
(ctf_func_args): Likewise.
(ctf_get_dict): Move...
* ctf-types.c (ctf_get_dict): ... here.
* ctf-util.c (ctf_sym_to_elf64): Re-express as...
(ctf_elf64_to_link_sym): ... this.  Add new st_symidx field, and
st_nameidx_set (always 0, so st_nameidx can be ignored).  Look in
the ELF strtab for names.
(ctf_elf32_to_link_sym): Likewise, for Elf32_Sym.
(ctf_next_destroy): Destroy ctf_next_t.u.ctn_next if need be.
* libctf.ver: Add ctf_symbol_next, ctf_add_objt_sym and
ctf_add_func_sym.

3 years agobfd, include, ld, binutils, libctf: CTF should use the dynstr/sym
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
bfd, include, ld, binutils, libctf: CTF should use the dynstr/sym

This is embarrassing.

The whole point of CTF is that it remains intact even after a binary is
stripped, providing a compact mapping from symbols to types for
everything in the externally-visible interface of an ELF object: it has
connections to the symbol table for that purpose, and to the string
table to avoid duplicating symbol names.  So it's a shame that the hooks
I implemented last year served to hook it up to the .symtab and .strtab,
which obviously disappear on strip, leaving any accompanying the CTF
dict containing references to strings (and, soon, symbols) which don't
exist any more because their containing strtab has been vaporized.  The
original Solaris design used .dynsym and .dynstr (well, actually,
.ldynsym, which has more symbols) which do not disappear. So should we.

Thankfully the work we did before serves as guide rails, and adjusting
things to use the .dynstr and .dynsym was fast and easy.  The only
annoyance is that the dynsym is assembled inside elflink.c in a fairly
piecemeal fashion, so that the easiest way to get the symbols out was to
hook in before every call to swap_symbol_out (we also leave in a hook in
front of symbol additions to the .symtab because it seems plausible that
we might want to hook them in future too: for now that hook is unused).
We adjust things so that rather than being offered a whole hash table of
symbols at once, libctf is now given symbols one at a time, with st_name
indexes already resolved and pointing at their final .dynstr offsets:
it's now up to libctf to resolve these to names as needed using the
strtab info we pass it separately.

Some bits might be contentious.  The ctf_new_dynstr callback takes an
elf_internal_sym, and this remains an elf_internal_sym right down
through the generic emulation layers into ldelfgen.  This is no worse
than the elf_sym_strtab we used to pass down, but in the future when we
gain non-ELF CTF symtab support we might want to lower the
elf_internal_sym to some other representation (perhaps a
ctf_link_symbol) in bfd or in ldlang_ctf_new_dynsym.  We rename the
'apply_strsym' hooks to 'acquire_strings' instead, becuse they no longer
have anything to do with symbols.

There are some API changes to pieces of API which are technically public
but actually totally unused by anything and/or unused by anything but ld
so they can change freely: the ctf_link_symbol gains new fields to allow
symbol names to be given as strtab offsets as well as strings, and a
symidx so that the symbol index can be passed in.  ctf_link_shuffle_syms
loses its callback parameter: the idea now is that linkers call the new
ctf_link_add_linker_symbol for every symbol in .dynsym, feed in all the
strtab entries with ctf_link_add_strtab, and then a call to
ctf_link_shuffle_syms will apply both and arrange to use them to reorder
the CTF symtab at CTF serialization time (which is coming in the next
commit).

Inside libctf we have a new preamble flag CTF_F_DYNSTR which is always
set in v3-format CTF dicts from this commit forwards: CTF dicts without
this flag are associated with .strtab like they used to be, so that old
dicts' external strings don't turn to garbage when loaded by new libctf.
Dicts with this flag are associated with .dynstr and .dynsym instead.
(The flag is not the next in sequence because this commit was written
quite late: the missing flags will be filled in by the next commit.)

Tests forthcoming in a later commit in this series.

bfd/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* elflink.c (elf_finalize_dynstr): Call examine_strtab after
dynstr finalization.
(elf_link_swap_symbols_out): Don't call it here.  Call
ctf_new_symbol before swap_symbol_out.
(elf_link_output_extsym): Call ctf_new_dynsym before
swap_symbol_out.
(bfd_elf_final_link): Likewise.
* elf.c (swap_out_syms): Pass in bfd_link_info.  Call
ctf_new_symbol before swap_symbol_out.
(_bfd_elf_compute_section_file_positions): Adjust.

binutils/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* readelf.c (dump_section_as_ctf): Use .dynsym and .dynstr, not
.symtab and .strtab.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* bfdlink.h (struct elf_sym_strtab): Replace with...
(struct elf_internal_sym): ... this.
(struct bfd_link_callbacks) <examine_strtab>: Take only a
symstrtab argument.
<ctf_new_symbol>: New.
<ctf_new_dynsym>: Likewise.
* ctf-api.h (struct ctf_link_sym) <st_symidx>: New.
<st_nameidx>: Likewise.
<st_nameidx_set>: Likewise.
(ctf_link_iter_symbol_f): Removed.
(ctf_link_shuffle_syms): Remove most parameters, just takes a
ctf_dict_t now.
(ctf_link_add_linker_symbol): New, split from
ctf_link_shuffle_syms.
* ctf.h (CTF_F_DYNSTR): New.
(CTF_F_MAX): Adjust.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ldelfgen.c (struct ctf_strsym_iter_cb_arg): Rename to...
(struct ctf_strtab_iter_cb_arg): ... this, changing fields:
<syms>: Remove.
<symcount>: Remove.
<symstrtab>: Rename to...
<strtab>: ... this.
(ldelf_ctf_strtab_iter_cb): Adjust.
(ldelf_ctf_symbols_iter_cb): Remove.
(ldelf_new_dynsym_for_ctf): New, tell libctf about a single
symbol.
(ldelf_examine_strtab_for_ctf): Rename to...
(ldelf_acquire_strings_for_ctf): ... this, only doing the strtab
portion and not symbols.
* ldelfgen.h: Adjust declarations accordingly.
* ldemul.c (ldemul_examine_strtab_for_ctf): Rename to...
(ldemul_acquire_strings_for_ctf): ... this.
(ldemul_new_dynsym_for_ctf): New.
* ldemul.h: Adjust declarations accordingly.
* ldlang.c (ldlang_ctf_apply_strsym): Rename to...
(ldlang_ctf_acquire_strings): ... this.
(ldlang_ctf_new_dynsym): New.
(lang_write_ctf): Call ldemul_new_dynsym_for_ctf with NULL to do
the actual symbol shuffle.
* ldlang.h (struct elf_strtab_hash): Adjust accordingly.
* ldmain.c (bfd_link_callbacks): Wire up new/renamed callbacks.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-link.c (ctf_link_shuffle_syms): Adjust.
(ctf_link_add_linker_symbol): New, unimplemented stub.
* libctf.ver: Add it.
* ctf-create.c (ctf_serialize): Set CTF_F_DYNSTR on newly-serialized
dicts.
* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Check for the flag: open the
symtab/strtab if not present, dynsym/dynstr otherwise.
* ctf-archive.c (ctf_arc_bufpreamble): New, get the preamble from
some arbitrary member of a CTF archive.
* ctf-impl.h (ctf_arc_bufpreamble): Declare it.

3 years agoobjdump, readelf: Report errors from CTF archive iteration
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
objdump, readelf: Report errors from CTF archive iteration

We were failing to report errors from ctf_archive_iter, which results in
silent early termination if (for example) one CTF archive member in a
.ctf section is corrupted and cannot be opened.  Report the error in the
usual fashion instead.

binutils/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* objdump.c (dump_ctf): Report errors from ctf_archive_iter.
* readelf.c (dump_section_as_ctf): Likewise.

3 years agolibctf, include, binutils, gdb: rename CTF-opening functions
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf, include, binutils, gdb: rename CTF-opening functions

The functions that return ctf_dict_t's given a ctf_archive_t and a name
are very clumsily named.  It sounds like they return *archives*, not
dictionaries, and the names are very long and clunky.  Why do we
have a ctf_arc_open_by_name when it opens a dictionary, not an archive,
and when there is no way to open a dictionary in any other way?  The
answer is purely internal: the function is located in ctf-archive.c,
and everything in there was called ctf_arc_*, and there is another
way to open a dict (by offset in the archive), that is internal to
ctf-archive.c and that nothing else can call.

This is clearly bad naming. The internal organization of the source tree
should not dictate public API names!

So rename things (keeping the old, bad names for compatibility), and
adjust all users.  You now open a dict using ctf_dict_open, and
open it giving ELF sections via ctf_dict_open_sections.

binutils/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* objdump.c (dump_ctf): Use ctf_dict_open, not
ctf_arc_open_by_name.
* readelf.c (dump_section_as_ctf): Likewise.

gdb/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctfread.c (elfctf_build_psymtabs): Use ctf_dict_open, not
ctf_arc_open_by_name.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-api.h (ctf_arc_open_by_name): Rename to...
(ctf_dict_open): ... this, keeping compatibility function.
(ctf_arc_open_by_name_sections): Rename to...
(ctf_dict_open_sections): ... this, keeping compatibility function.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-archive.c (ctf_arc_open_by_offset): Rename to...
(ctf_dict_open_by_offset): ... this.  Adjust callers.
(ctf_arc_open_by_name_internal): Rename to...
(ctf_dict_open_internal): ... this.  Adjust callers.
(ctf_arc_open_by_name_sections): Rename to...
(ctf_dict_open_sections): ... this, keeping compatibility function.
(ctf_arc_open_by_name): Rename to...
(ctf_dict_open): ... this, keeping compatibility function.
* libctf.ver: New functions added.
* ctf-link.c (ctf_link_one_input_archive): Adjusted accordingly.
(ctf_link_deduplicating_open_inputs): Likewise.

3 years agolibctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t

The naming of the ctf_file_t type in libctf is a historical curiosity.
Back in the Solaris days, CTF dictionaries were originally generated as
a separate file and then (sometimes) merged into objects: hence the
datatype was named ctf_file_t, and known as a "CTF file".  Nowadays, raw
CTF is essentially never written to a file on its own, and the datatype
changed name to a "CTF dictionary" years ago.  So the term "CTF file"
refers to something that is never a file!  This is at best confusing.

The type has also historically been known as a 'CTF container", which is
even more confusing now that we have CTF archives which are *also* a
sort of container (they contain CTF dictionaries), but which are never
referred to as containers in the source code.

So fix this by completing the renaming, renaming ctf_file_t to
ctf_dict_t throughout, and renaming those few functions that refer to
CTF files by name (keeping compatibility aliases) to refer to dicts
instead.  Old users who still refer to ctf_file_t will see (harmless)
pointer-compatibility warnings at compile time, but the ABI is unchanged
(since C doesn't mangle names, and ctf_file_t was always an opaque type)
and things will still compile fine as long as -Werror is not specified.
All references to CTF containers and CTF files in the source code are
fixed to refer to CTF dicts instead.

Further (smaller) renamings of annoyingly-named functions to come, as
part of the process of souping up queries across whole archives at once
(needed for the function info and data object sections).

binutils/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* objdump.c (dump_ctf_errs): Rename ctf_file_t to ctf_dict_t.
(dump_ctf_archive_member): Likewise.
(dump_ctf): Likewise. Use ctf_dict_close, not ctf_file_close.
* readelf.c (dump_ctf_errs): Rename ctf_file_t to ctf_dict_t.
(dump_ctf_archive_member): Likewise.
(dump_section_as_ctf): Likewise.  Use ctf_dict_close, not
ctf_file_close.

gdb/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctfread.c: Change uses of ctf_file_t to ctf_dict_t.
(ctf_fp_info::~ctf_fp_info): Call ctf_dict_close, not ctf_file_close.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-api.h (ctf_file_t): Rename to...
(ctf_dict_t): ... this.  Keep ctf_file_t around for compatibility.
(struct ctf_file): Likewise rename to...
(struct ctf_dict): ... this.
(ctf_file_close): Rename to...
(ctf_dict_close): ... this, keeping compatibility function.
(ctf_parent_file): Rename to...
(ctf_parent_dict): ... this, keeping compatibility function.
All callers adjusted.
* ctf.h: Rename references to ctf_file_t to ctf_dict_t.
(struct ctf_archive) <ctfa_nfiles>: Rename to...
<ctfa_ndicts>: ... this.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ldlang.c (ctf_output): This is a ctf_dict_t now.
(lang_ctf_errs_warnings): Rename ctf_file_t to ctf_dict_t.
(ldlang_open_ctf): Adjust comment.
(lang_merge_ctf): Use ctf_dict_close, not ctf_file_close.
* ldelfgen.h (ldelf_examine_strtab_for_ctf): Rename ctf_file_t to
ctf_dict_t.  Change opaque declaration accordingly.
* ldelfgen.c (ldelf_examine_strtab_for_ctf): Adjust.
* ldemul.h (examine_strtab_for_ctf): Likewise.
(ldemul_examine_strtab_for_ctf): Likewise.
* ldeuml.c (ldemul_examine_strtab_for_ctf): Likewise.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-impl.h: Rename ctf_file_t to ctf_dict_t: all declarations
adjusted.
(ctf_fileops): Rename to...
(ctf_dictops): ... this.
(ctf_dedup_t) <cd_id_to_file_t>: Rename to...
<cd_id_to_dict_t>: ... this.
(ctf_file_t): Fix outdated comment.
<ctf_fileops>: Rename to...
<ctf_dictops>: ... this.
(struct ctf_archive_internal) <ctfi_file>: Rename to...
<ctfi_dict>: ... this.
* ctf-archive.c: Rename ctf_file_t to ctf_dict_t.
Rename ctf_archive.ctfa_nfiles to ctfa_ndicts.
Rename ctf_file_close to ctf_dict_close.  All users adjusted.
* ctf-create.c: Likewise.  Refer to CTF dicts, not CTF containers.
(ctf_bundle_t) <ctb_file>: Rename to...
<ctb_dict): ... this.
* ctf-decl.c: Rename ctf_file_t to ctf_dict_t.
* ctf-dedup.c: Likewise.  Rename ctf_file_close to
ctf_dict_close. Refer to CTF dicts, not CTF containers.
* ctf-dump.c: Likewise.
* ctf-error.c: Likewise.
* ctf-hash.c: Likewise.
* ctf-inlines.h: Likewise.
* ctf-labels.c: Likewise.
* ctf-link.c: Likewise.
* ctf-lookup.c: Likewise.
* ctf-open-bfd.c: Likewise.
* ctf-string.c: Likewise.
* ctf-subr.c: Likewise.
* ctf-types.c: Likewise.
* ctf-util.c: Likewise.
* ctf-open.c: Likewise.
(ctf_file_close): Rename to...
(ctf_dict_close): ...this.
(ctf_file_close): New trivial wrapper around ctf_dict_close, for
compatibility.
(ctf_parent_file): Rename to...
(ctf_parent_dict): ... this.
(ctf_parent_file): New trivial wrapper around ctf_parent_dict, for
compatibility.
* libctf.ver: Add ctf_dict_close and ctf_parent_dict.

3 years agolanguage_lookup_primitive_type, std::function -> gdb::function_view
Pedro Alves [Mon, 16 Nov 2020 19:15:00 +0000 (19:15 +0000)] 
language_lookup_primitive_type, std::function -> gdb::function_view

gdb/ChangeLog:

* language.c (language_arch_info::lookup_primitive_type): Use
gdb::function_view instead of gdb::function.
(template language_lookup_primitive_type): Rename to ...
(language_lookup_primitive_type_1): ... this, and make static.
(language_lookup_primitive_type(const struct language_defn *,
struct gdbarch *, const char *): Make non-template.
(language_lookup_primitive_type(const struct language_defn *,
struct gdbarch *, std::function<bool (struct type *)>): Make
non-template and use gdb::function_view.
* language.h (language_arch_info::lookup_primitive_type): Use
gdb::function_view instead of std::function.
(language_lookup_primitive_type): No longer template.
* opencl-lang.c (lookup_opencl_vector_type): 'filter' is now a
lambda instead of a std::function.

3 years agoAdd option to nm to change the characters displayed for ifunc symbols. Add a configu...
Nick Clifton [Fri, 20 Nov 2020 13:04:56 +0000 (13:04 +0000)] 
Add option to nm to change the characters displayed for ifunc symbols.  Add a configure time option to change the default characters.

PR 22967
* nm.c (ifunc_type_chars): New variable.
(long_options): Add --ifunc-chars.
(print_symbol): Use ifunc_type_chars for ifunc symbols.
(main): Handle the new option.
* doc/binutils.texi: Document the new option.
* configure.ac: Add --enable-f-for-ifunc-symbols option which
changes the default symbol displayed by nm.
* NEWS: Mention the new feature.
* testsuite/binutils-all/nm.exp: Test the new feature.
* config.in: Regenerate.
* configure: Regenerate.

3 years agoAdd a warning to dllwrap that it is deprecated.
Linda Zhang [Fri, 20 Nov 2020 11:07:26 +0000 (11:07 +0000)] 
Add a warning to dllwrap that it is deprecated.

PR 20979
* dllwrap.c (main): Deprecate and warn the use of dllwrap.

3 years agoFix SHF_GNU_RETAIN testsuite fallout
Jozef Lawrynowicz [Fri, 20 Nov 2020 10:31:07 +0000 (10:31 +0000)] 
Fix SHF_GNU_RETAIN testsuite fallout

binutils/ChangeLog:

* testsuite/binutils-all/readelf-maskos-1a.d: Fix test for unrecognized
bit set in SHF_MASKOS range.
* testsuite/binutils-all/readelf-maskos-1b.d: Likewise.
* testsuite/binutils-all/readelf-maskos-unknown.s: New test.

ld/ChangeLog:

* testsuite/ld-elf/retain3.s: Move symbolic reference into writeable
.data section from read-only .text section.
* testsuite/ld-elf/retain5.d: Don't pass --print-gc-sections for test
that doesn't require it.
* testsuite/ld-elf/retain6a.d: Adjust test.
* testsuite/ld-elf/retain6main.s: Move symbolic reference into writeable
.data section from read-only .text section.

3 years agoAutomatic date update in version.in
GDB Administrator [Fri, 20 Nov 2020 00:00:20 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogas/testsuite: Fix SHF_GNU_RETAIN tests for FreeBSD OSABIs
Jozef Lawrynowicz [Thu, 19 Nov 2020 18:56:15 +0000 (18:56 +0000)] 
gas/testsuite: Fix SHF_GNU_RETAIN tests for FreeBSD OSABIs

gas/ChangeLog:

* testsuite/gas/elf/section22.d: Allow FreeBSD OSABI in readelf
output.
* testsuite/gas/elf/section23a.d: Likewise.
* testsuite/gas/elf/section24a.d: Likewise.

3 years agogdb/s390: Correct recording of "store on condition" insns
Andreas Arnez [Thu, 19 Nov 2020 18:10:58 +0000 (19:10 +0100)] 
gdb/s390: Correct recording of "store on condition" insns

The "store on condition" instructions STOC, STOCG, and STOCFH are recorded
as if their instruction formats resembled that of STG.  This is wrong,
usually resulting in "failed to record execution log" errors when trying
to record code with any of these instructions.

This patch fixes the recording of these instructions.

gdb/ChangeLog:

PR tdep/26916
* s390-tdep.c (s390_process_record): Fix recording of STOC, STOCG,
and STOCFH.

3 years agoFix a bug in the s390x linker when discarding all inpuit files.
Nick Clifton [Thu, 19 Nov 2020 17:36:24 +0000 (17:36 +0000)] 
Fix a bug in the s390x linker when discarding all inpuit files.

PR 26918
* elf64-s390.c (elf_s390_finish_dynamic_sections): Check for the
existance of an sgot output section before setting the
sh_entsize.

3 years agogdb: fix format string warnings in f-lang.c
Simon Marchi [Thu, 19 Nov 2020 16:31:34 +0000 (11:31 -0500)] 
gdb: fix format string warnings in f-lang.c

I get a bunch of these warnings when compiling for i386 (32-bit):

      CXX    f-lang.o
    /home/simark/src/binutils-gdb/gdb/f-lang.c: In function 'value* fortran_value_subarray(value*, expression*, int*, int, noside)':
    /home/simark/src/binutils-gdb/gdb/f-lang.c:453:48: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'LONGEST' {aka 'long long int'} [-Werror=format=]
      453 |        debug_printf ("|   |   |-> Low bound: %ld\n", lb);
          |                                              ~~^     ~~
          |                                                |     |
          |                                                |     LONGEST {aka long long int}
          |                                                long int
          |                                              %lld

Fix them by using plongest/pulongest.

gdb/ChangeLog:

* f-lang.c (fortran_value_subarray): Use plongest/pulongest.

Change-Id: I666ead5593653d5a1a3dab2ffdc72942c928c7d2

3 years agogdb: remove `other` parameter in read_core_file_mappings parameter
Simon Marchi [Thu, 19 Nov 2020 15:34:57 +0000 (10:34 -0500)] 
gdb: remove `other` parameter in read_core_file_mappings parameter

The `void *other` parameter in read_core_file_mappings' loop_cb
parameter is never used, remove it.

gdb/ChangeLog:

* gdbarch.sh (read_core_file_mappings): Remove `other` parameter
in `loop_cb` parameter.
* gdbarch.c: Re-generate.
* gdbarch.h: Re-generate.
* arch-utils.c (default_read_core_file_mappings): Remove `other`
parameter.
* arch-utils.h (default_read_core_file_mappings): Likewise.
* corelow.c (core_target::build_file_mappings): Likewise.
* linux-tdep.c (linux_read_core_file_mappings): Likewise.
(linux_core_info_proc_mappings): Likewise.

Change-Id: I6f408b4962b61b8a603642a844772b3026625523

3 years agogdb/fortran: Add support for Fortran array slices at the GDB prompt
Andrew Burgess [Thu, 8 Oct 2020 15:45:59 +0000 (16:45 +0100)] 
gdb/fortran: Add support for Fortran array slices at the GDB prompt

This commit brings array slice support to GDB.

WARNING: This patch contains a rather big hack which is limited to
Fortran arrays, this can be seen in gdbtypes.c and f-lang.c.  More
details on this below.

This patch rewrites two areas of GDB's Fortran support, the code to
extract an array slice, and the code to print an array.

After this commit a user can, from the GDB prompt, ask for a slice of
a Fortran array and should get the correct result back.  Slices can
(optionally) have the lower bound, upper bound, and a stride
specified.  Slices can also have a negative stride.

Fortran has the concept of repacking array slices.  Within a compiled
Fortran program if a user passes a non-contiguous array slice to a
function then the compiler may have to repack the slice, this involves
copying the elements of the slice to a new area of memory before the
call, and copying the elements back to the original array after the
call.  Whether repacking occurs will depend on which version of
Fortran is being used, and what type of function is being called.

This commit adds support for both packed, and unpacked array slicing,
with the default being unpacked.

With an unpacked array slice, when the user asks for a slice of an
array GDB creates a new type that accurately describes where the
elements of the slice can be found within the original array, a
value of this type is then returned to the user.  The address of an
element within the slice will be equal to the address of an element
within the original array.

A user can choose to select packed array slices instead using:

  (gdb) set fortran repack-array-slices on|off
  (gdb) show fortran repack-array-slices

With packed array slices GDB creates a new type that reflects how the
elements of the slice would look if they were laid out in contiguous
memory, allocates a value of this type, and then fetches the elements
from the original array and places then into the contents buffer of
the new value.

One benefit of using packed slices over unpacked slices is the memory
usage, taking a small slice of N elements from a large array will
require (in GDB) N * ELEMENT_SIZE bytes of memory, while an unpacked
array will also include all of the "padding" between the
non-contiguous elements.  There are new tests added that highlight
this difference.

There is also a new debugging flag added with this commit that
introduces these commands:

  (gdb) set debug fortran-array-slicing on|off
  (gdb) show debug fortran-array-slicing

This prints information about how the array slices are being built.

As both the repacking, and the array printing requires GDB to walk
through a multi-dimensional Fortran array visiting each element, this
commit adds the file f-array-walk.h, which introduces some
infrastructure to support this process.  This means the array printing
code in f-valprint.c is significantly reduced.

The only slight issue with this commit is the "rather big hack" that I
mentioned above.  This hack allows us to handle one specific case,
array slices with negative strides.  This is something that I don't
believe the current GDB value contents model will allow us to
correctly handle, and rather than rewrite the value contents code
right now, I'm hoping to slip this hack in as a work around.

The problem is that, as I see it, the current value contents model
assumes that an object base address will be the lowest address within
that object, and that the contents of the object start at this base
address and occupy the TYPE_LENGTH bytes after that.

( We do have the embedded_offset, which is used for C++ sub-classes,
such that an object can start at some offset from the content buffer,
however, the assumption that the object then occupies the next
TYPE_LENGTH bytes is still true within GDB. )

The problem is that Fortran arrays with a negative stride don't follow
this pattern.  In this case the base address of the object points to
the element with the highest address, the contents of the array then
start at some offset _before_ the base address, and proceed for one
element _past_ the base address.

As the stride for such an array would be negative then, in theory the
TYPE_LENGTH for this type would also be negative.  However, in many
places a value in GDB will degrade to a pointer + length, and the
length almost always comes from the TYPE_LENGTH.

It is my belief that in order to correctly model this case the value
content handling of GDB will need to be reworked to split apart the
value's content buffer (which is a block of memory with a length), and
the object's in memory base address and length, which could be
negative.

Things are further complicated because arrays with negative strides
like this are always dynamic types.  When a value has a dynamic type
and its base address needs resolving we actually store the address of
the object within the resolved dynamic type, not within the value
object itself.

In short I don't currently see an easy path to cleanly support this
situation within GDB.  And so I believe that leaves two options,
either add a work around, or catch cases where the user tries to make
use of a negative stride, or access an array with a negative stride,
and throw an error.

This patch currently goes with adding a work around, which is that
when we resolve a dynamic Fortran array type, if the stride is
negative, then we adjust the base address to point to the lowest
address required by the array.  The printing and slicing code is aware
of this adjustment and will correctly slice and print Fortran arrays.

Where this hack will show through to the user is if they ask for the
address of an array in their program with a negative array stride, the
address they get from GDB will not match the address that would be
computed within the Fortran program.

gdb/ChangeLog:

* Makefile.in (HFILES_NO_SRCDIR): Add f-array-walker.h.
* NEWS: Mention new options.
* f-array-walker.h: New file.
* f-lang.c: Include 'gdbcmd.h' and 'f-array-walker.h'.
(repack_array_slices): New static global.
(show_repack_array_slices): New function.
(fortran_array_slicing_debug): New static global.
(show_fortran_array_slicing_debug): New function.
(value_f90_subarray): Delete.
(skip_undetermined_arglist): Delete.
(class fortran_array_repacker_base_impl): New class.
(class fortran_lazy_array_repacker_impl): New class.
(class fortran_array_repacker_impl): New class.
(fortran_value_subarray): Complete rewrite.
(set_fortran_list): New static global.
(show_fortran_list): Likewise.
(_initialize_f_language): Register new commands.
(fortran_adjust_dynamic_array_base_address_hack): New function.
* f-lang.h (fortran_adjust_dynamic_array_base_address_hack):
Declare.
* f-valprint.c: Include 'f-array-walker.h'.
(class fortran_array_printer_impl): New class.
(f77_print_array_1): Delete.
(f77_print_array): Delete.
(fortran_print_array): New.
(f_value_print_inner): Update to call fortran_print_array.
* gdbtypes.c: Include 'f-lang.h'.
(resolve_dynamic_type_internal): Call
fortran_adjust_dynamic_array_base_address_hack.

gdb/testsuite/ChangeLog:

        * gdb.fortran/array-slices-bad.exp: New file.
        * gdb.fortran/array-slices-bad.f90: New file.
        * gdb.fortran/array-slices-sub-slices.exp: New file.
        * gdb.fortran/array-slices-sub-slices.f90: New file.
        * gdb.fortran/array-slices.exp: Rewrite tests.
        * gdb.fortran/array-slices.f90: Rewrite tests.
        * gdb.fortran/vla-sizeof.exp: Correct expected results.

gdb/doc/ChangeLog:

        * gdb.texinfo (Debugging Output): Document 'set/show debug
        fortran-array-slicing'.
        (Special Fortran Commands): Document 'set/show fortran
        repack-array-slices'.

3 years agogdb: update command completion for watch, awatch, and rwatch
Andrew Burgess [Mon, 16 Nov 2020 16:50:03 +0000 (16:50 +0000)] 
gdb: update command completion for watch, awatch, and rwatch

Switch over to using new option processing mechanism for watch,
awatch, and rwatch commands.  Add command completion function.

This means that expression completion now works correctly when the
-location flag is used.  So previously:

  (gdb) watch var.<TAB><TAB>
  .... list fields of var ....

But,

  (gdb) watch -location var.<TAB><TAB>
  .... list all symbols ....

After this commit only the fields of 'var' are listed even when
'-location' is passed.

Another benefit of this change is that '-location' will now complete.

One thing to note is that previous these commands accepted both
'-location' or '-l' (these being synonyms).  The new option scheme
doesn't really allow for official short form flags, however, it does
allow for non-ambiguous sub-strings to be used.  What this means is
that currently (as these commands only have the '-location' flag) the
user can still use '-l', so there's no change there.

The interactive help text for these commands now emphasises
'-location' as the real option, but does mention that '-l' can also be
used.

gdb/ChangeLog:

* breakpoint.c (struct watch_options): New struct.
(watch_option_defs): New static global.
(make_watch_options_def_group): New function.
(watch_maybe_just_location): Convert option parsing.
(watch_command_completer): New function.
(_initialize_breakpoint): Build help text using options mechanism.

gdb/testsuite/ChangeLog:

* gdb.base/completion.exp: Add new completion tests.

This page took 0.060169 seconds and 4 git commands to generate.