aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2020-11-21RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous.Nelson Chu7-14/+79
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.
2020-11-21Automatic date update in version.inGDB Administrator1-1/+1
2020-11-20gdb: fix unittests/gmp-utils-selftests.c build on solarisSimon Marchi2-6/+12
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
2020-11-20gdb: fix dwarf2/read.c build on solarisSimon Marchi2-2/+7
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
2020-11-20Ignore system_error in thread startupTom Tromey2-2/+19
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.
2020-11-20Add missing test fileNick Clifton1-0/+18
2020-11-20libctf: do not crash when CTF symbol or variable linking failsNick Alcock2-6/+15
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.
2020-11-20libctf: error-handling fixesNick Alcock3-4/+25
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.
2020-11-20libctf, include: add ctf_getsymsect and ctf_getstrsectNick Alcock5-0/+28
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.
2020-11-20libctf, include: CTF-archive-wide symbol lookupNick Alcock7-18/+275
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.
2020-11-20libctf, ld: properly deduplicate function typesNick Alcock4-6/+33
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.
2020-11-20ld, ctf: new and adjusted CTF tests due to func info / object data sectionsNick Alcock26-45/+1191
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.
2020-11-20libctf: adjust dumper for symtypetab changesNick Alcock2-131/+88
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.
2020-11-20libctf: symbol type linking supportNick Alcock14-272/+1898
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.
2020-11-20bfd, include, ld, binutils, libctf: CTF should use the dynstr/symNick Alcock36-133/+363
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.
2020-11-20objdump, readelf: Report errors from CTF archive iterationNick Alcock3-3/+17
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.
2020-11-20libctf, include, binutils, gdb: rename CTF-opening functionsNick Alcock11-43/+100
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.
2020-11-20libctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_tNick Alcock34-804/+919
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.
2020-11-20language_lookup_primitive_type, std::function -> gdb::function_viewPedro Alves4-20/+55
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.
2020-11-20Add option to nm to change the characters displayed for ifunc symbols. Add ↵Nick Clifton8-16/+172
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.
2020-11-20Add a warning to dllwrap that it is deprecated.Linda Zhang2-0/+8
PR 20979 * dllwrap.c (main): Deprecate and warn the use of dllwrap.
2020-11-20Fix SHF_GNU_RETAIN testsuite falloutJozef Lawrynowicz9-20/+48
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.
2020-11-20Automatic date update in version.inGDB Administrator1-1/+1
2020-11-19gas/testsuite: Fix SHF_GNU_RETAIN tests for FreeBSD OSABIsJozef Lawrynowicz4-3/+10
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.
2020-11-19gdb/s390: Correct recording of "store on condition" insnsAndreas Arnez2-3/+20
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.
2020-11-19Fix a bug in the s390x linker when discarding all inpuit files.Nick Clifton2-2/+10
PR 26918 * elf64-s390.c (elf_s390_finish_dynamic_sections): Check for the existance of an sgot output section before setting the sh_entsize.
2020-11-19gdb: fix format string warnings in f-lang.cSimon Marchi2-29/+40
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
2020-11-19gdb: remove `other` parameter in read_core_file_mappings parameterSimon Marchi8-13/+23
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
2020-11-19gdb/fortran: Add support for Fortran array slices at the GDB promptAndrew Burgess18-255/+1998
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'.
2020-11-19gdb: update command completion for watch, awatch, and rwatchAndrew Burgess4-31/+123
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.
2020-11-19gdb: convert some function arguments from int to boolAndrew Burgess7-21/+39
A little int to bool conversion around the 'watch' type commands. There should be no user visible changes after this commit. gdb/ChangeLog: * breakpoint.c (update_watchpoint): Pass 'false' not '0'. (watch_command_1): Update parameter types. Convert locals to bool. (watch_command_wrapper): Change parameter type. (watch_maybe_just_location): Change locals to bool. (rwatch_command_wrapper): Update parameter type. (awatch_command_wrapper): Update parameter type. * breakpoint.h (watch_command_wrapper): Change parameter type. (rwatch_command_wrapper): Update parameter type. (awatch_command_wrapper): Update parameter type. * eval.c (fetch_subexp_value): Change parameter type. * ppc-linux-nat.c (ppc_linux_nat_target::check_condition): Pass 'false' not '0'. * value.h (fetch_subexp_value): Change parameter type in declaration.
2020-11-19gdb: make use of skip_to_space and skip_spacesAndrew Burgess2-4/+7
Some late feedback on this commit: commit 037d7135de575c9e0c20e9158c105979bfee339c Date: Mon Nov 16 11:36:56 2020 +0000 gdb: improve command completion for 'print', 'x', and 'display' Suggested making use of the skip_to_space and skip_spaces helper functions. There should be no user visible changes after this commit. gdb/ChangeLog: * printcmd.c (skip_over_slash_fmt): Make use of skip_to_space and skip_spaces.
2020-11-19Automatic date update in version.inGDB Administrator1-1/+1
2020-11-18Squash coverity warning for REVERSE_INULL in dump_note_entry_pKeith Seitz2-1/+6
Coverity detected a "defect" in dump_note_entry_p in linux-tdep.c: static int dump_note_entry_p (filter_flags filterflags, const struct smaps_vmflags *v, int maybe_private_p, int mapping_anon_p, int mapping_file_p, const char *filename, ULONGEST addr, ULONGEST offset) { /* vDSO and vsyscall mappings will end up in the core file. Don't put them in the NT_FILE note. */ if (strcmp ("[vdso]", filename) == 0 || strcmp ("[vsyscall]", filename) == 0) return 0; /* Otherwise, any other file-based mapping should be placed in the note. */ return filename != nullptr; } Those strcmp's will derefernce `filename' so there is little point to checking whether it is non-NULL or not; we would have already segfaulted. It also cannot be nullptr because its value is read directly from /proc/PID/maps. The "worst" it can be is an empty string. gdb/ChangeLog 2020-11-18 Keith Seitz <keiths@redhat.com> * linux-tdep.c (dump_note_entry_p): Return true instead of checking `filename'.
2020-11-18[gdb] Improve early exits for env var in debuginfod-support.cTom de Vries2-2/+10
There's an early exit in libdebuginfod's debuginfod_query_server, which checks both for: - getenv (DEBUGINFOD_URLS_ENV_VAR) == NULL, and - (getenv (DEBUGINFOD_URLS_ENV_VAR))[0] == '\0'. In debuginfod_source_query and debuginfod_debuginfo_query (which both end up calling debuginfod_query_server) there are also early exits checking the same env var, but those just check for NULL. Make the early exit tests in debuginfod-support.c match those in libdebuginfod. gdb/ChangeLog: 2020-11-18 Tom de Vries <tdevries@suse.de> * debuginfod-support.c (debuginfod_source_query) (debuginfod_debuginfo_query): Also do early exit if "(getenv (DEBUGINFOD_URLS_ENV_VAR))[0] == '\0'".
2020-11-18gdb/testsuite: gdb.mi/mi-nonstop-exit.exp: enable non-stop using GDBFLAGSSimon Marchi7-12/+33
When running make check TESTS="gdb.mi/mi-nonstop-exit.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver" We get: 220^error,msg="Unexpected vCont reply in non-stop mode: T05swbreak:;06:60d5ffffff7f0000;07:d0d2ffffff7f0000;10:5b57fdf7ff7f0000;thread:p2a4eed.2a4eed;core :4;"^M (gdb) ^M UNRESOLVED: gdb.mi/mi-nonstop-exit.exp: first run: unable to start target This is because non-stop is enabled using "-gdb-set non-stop 1". This doesn't work with the native-extended-gdbserver board, because with that board GDB connects to GDBserver as soon as it's started. Non-stop needs to be enabled before connecting. The usual pattern to follow is to set non-stop on the command line, like gdb.mi/mi-nonstop.exp does. Change the non-stop MI tests to use that pattern. The results diff when running gdb.mi/*.exp is: -# of expected passes 2877 +# of expected passes 2938 # of unexpected failures 34 # of expected failures 8 # of known failures 13 # of unresolved testcases 4 # of unsupported tests 1 -# of duplicate test names 34 +# of duplicate test names 35 gdb/testsuite/ChangeLog: * gdb.mi/mi-nonstop-exit.exp: Enable non-stop through GDBFLAGS. * gdb.mi/mi-ns-stale-regcache.exp: Likewise. * gdb.mi/mi-nsintrall.exp: Likewise. * gdb.mi/mi-nsmoribund.exp: Likewise. * gdb.mi/mi-nsthrexec.exp: Likewise. * gdb.mi/mi-watch-nonstop.exp: Likewise. Change-Id: Ic2736bedea8d448eee8c2b534d26b2427f6b4d27
2020-11-18gdb/testsuite: use unresolved in mi_run_cmd_fullSimon Marchi2-3/+8
Running: make check TESTS="gdb.mi/mi-nonstop-exit.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver" We get: Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.mi/mi-nonstop-exit.exp ... ERROR: Unable to start target === gdb Summary === # of expected passes 2 The root cause of the problem is the typical "we try to enable non-stop after having connected to gdbserver". This is because with the native-extended-gdbserver board, GDB connects to GDBserver as soon as it's started. It's too late then to do "set non-stop 1" or "-gdb-set non-stop 1". This is fixed by the following patch. More worrying is that the error is not reported (except for the printout). From the testsuite point of view, everything went fine. runtest exits with status 0. This is because mi_run_cmd_full uses perror. perror just prints that ERROR and makes it so the next test becomes UNRESOLVED. However, there's no next test, because we just return early, seeing that we couldn't run. Change mi_run_cmd_full to call unresolved directly instead. This ensures that the failure is recorded. This is the results diff when running the gdb.mi/*.exp tests: # of unexpected failures 34 # of expected failures 8 # of known failures 13 -# of unresolved testcases 4 +# of unresolved testcases 10 # of unsupported tests 1 # of duplicate test names 34 gdb/testsuite/ChangeLog: * lib/mi-support.exp (mi_run_cmd_full): Use unresovled instead of perror. Change-Id: Ib0f214c0127fbe73f2033c6c29d678e025690220
2020-11-18Fix Windows-target testing in mi_gdb_file_cmdJoseph Myers2-0/+10
Similar to my recent fix for gdb_file_cmd, mi_gdb_file_cmd also runs into problems when GCC has created foo.exe given "-o foo". Apply exactly the same fix there as in gdb_file_cmd. This allows many more tests to succeed for Windows target that previously fell over. 2020-11-18 Joseph Myers <joseph@codesourcery.com> * lib/mi-support.exp (mi_gdb_file_cmd): Check for case where $arg.exe exists but $arg does not.
2020-11-18[gdb/build] Fix -Werror=bool-compare warning in update_static_array_sizeTom de Vries2-1/+6
With current trunk I run into: ... src/gdb/gdbtypes.c: In function 'bool update_static_array_size(type*)': src/gdb/gdbtypes.c:1250:64: error: comparison of constant '0' with boolean \ expression is always true [-Werror=bool-compare] && get_array_bounds (element_type, &low_bound, &high_bound) >= 0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ ... Fix this by dropping the compare. gdb/ChangeLog: 2020-11-18 Tom de Vries <tdevries@suse.de> * gdbtypes.c (update_static_array_size): Fix -Werror=bool-compare warning.
2020-11-18PowerPC paranioa testing of symbol merging involving comdat groupsAlan Modra10-0/+85
Ensures we don't mistreat st_other localentry bits. * testsuite/ld-powerpc/group1.d, * testsuite/ld-powerpc/group1.s, * testsuite/ld-powerpc/group1.sym, * testsuite/ld-powerpc/group2.d, * testsuite/ld-powerpc/group2.s, * testsuite/ld-powerpc/group2.sym, * testsuite/ld-powerpc/group3.s, * testsuite/ld-powerpc/group3.sym: New test files. * testsuite/ld-powerpc/powerpc.exp: Run new tests.
2020-11-18Re: Stop Gas from generating line info or address rangesAlan Modra9-32/+122
* doc/as.texi (.nop): Document optional size arg. * dwarf2dbg.c (dwarf2_gen_line_info_1): Only check SEC_ALLOC when ELF. Warn whenever dwarf line number information is ignored. * frags.c (frag_offset_ignore_align_p): New function. * frags.h (frag_offset_ignore_align_p): Declare. * read.c (s_nop): Extend to support optional size arg. * testsuite/gas/elf/dwarf2-20.d: Expect warnings, and exact range. * testsuite/gas/elf/dwarf2-20.s: Emit 16 bytes worth of nops. * testsuite/gas/m68hc11/indexed12.d: Expect warnings.
2020-11-18Support SHF_GNU_RETAIN ELF section flagJozef Lawrynowicz55-41/+943
The SHF_GNU_RETAIN section flag is an extension to the GNU ELF OSABI. It is defined as follows: ========================================================= Section Attribute Flags +-------------------------------------+ | Name | Value | +-------------------------------------+ | SHF_GNU_RETAIN | 0x200000 (1 << 21) | +-------------------------------------+ SHF_GNU_RETAIN The link editor should not garbage collect the section. ========================================================= The .section directive accepts the "R" flag, which indicates SHF_GNU_RETAIN should be applied to the section. There is not a direct mapping of SHF_GNU_RETAIN to the BFD section flag SEC_KEEP. Keeping these flags distinct allows SHF_GNU_RETAIN sections to be explicitly removed by placing them in /DISCARD/. bfd/ChangeLog: * elf-bfd.h (enum elf_gnu_osabi): Add elf_gnu_osabi_retain. (struct elf_obj_tdata): Increase has_gnu_osabi to 4 bits. * elf.c (_bfd_elf_make_section_from_shdr): Set elf_gnu_osabi_retain for SHF_GNU_RETAIN. (_bfd_elf_final_write_processing): Report if SHF_GNU_RETAIN is not supported by the OSABI. Adjust error messages. * elflink.c (elf_link_input_bfd): Copy enabled has_gnu_osabi bits from input BFD to output BFD. (bfd_elf_gc_sections): gc_mark the section if SHF_GNU_RETAIN is set. binutils/ChangeLog: * NEWS: Announce SHF_GNU_RETAIN support. * readelf.c (get_elf_section_flags): Handle SHF_GNU_RETAIN. Recognize SHF_GNU_RETAIN and SHF_GNU_MBIND only for supported OSABIs. * testsuite/binutils-all/readelf.exp: Run new tests. Don't run run_dump_test when there isn't an assembler available. * testsuite/lib/binutils-common.exp (supports_gnu_osabi): Adjust comment. * testsuite/binutils-all/readelf-maskos-1a.d: New test. * testsuite/binutils-all/readelf-maskos-1b.d: New test. * testsuite/binutils-all/readelf-maskos.s: New test. * testsuite/binutils-all/retain1.s: New test. * testsuite/binutils-all/retain1a.d: New test. * testsuite/binutils-all/retain1b.d: New test. gas/ChangeLog: * NEWS: Announce SHF_GNU_RETAIN support. * config/obj-elf.c (obj_elf_change_section): Merge SHF_GNU_RETAIN bit between section declarations. (obj_elf_parse_section_letters): Handle 'R' flag. Handle numeric flag values within the SHF_MASKOS range. (obj_elf_section): Validate SHF_GNU_RETAIN usage. * doc/as.texi: Document 'R' flag to .section directive. * testsuite/gas/elf/elf.exp: Run new tests. * testsuite/gas/elf/section10.d: Unset SHF_GNU_RETAIN bit. * testsuite/gas/elf/section10.s: Likewise. * testsuite/gas/elf/section22.d: New test. * testsuite/gas/elf/section22.s: New test. * testsuite/gas/elf/section23.s: New test. * testsuite/gas/elf/section23a.d: New test. * testsuite/gas/elf/section23b.d: New test. * testsuite/gas/elf/section23b.err: New test. * testsuite/gas/elf/section24.l: New test. * testsuite/gas/elf/section24.s: New test. * testsuite/gas/elf/section24a.d: New test. * testsuite/gas/elf/section24b.d: New test. include/ChangeLog: * elf/common.h (SHF_GNU_RETAIN): Define. ld/ChangeLog: * NEWS: Announce support for SHF_GNU_RETAIN. * ld.texi (garbage collection): Document SHF_GNU_RETAIN. (Output Section Discarding): Likewise. * testsuite/ld-elf/elf.exp: Run new tests. * testsuite/ld-elf/retain1.s: New test. * testsuite/ld-elf/retain1a.d: New test. * testsuite/ld-elf/retain1b.d: New test. * testsuite/ld-elf/retain2.d: New test. * testsuite/ld-elf/retain2.ld: New test. * testsuite/ld-elf/retain2.map: New test. * testsuite/ld-elf/retain3.d: New test. * testsuite/ld-elf/retain3.s: New test. * testsuite/ld-elf/retain4.d: New test. * testsuite/ld-elf/retain4.s: New test. * testsuite/ld-elf/retain5.d: New test. * testsuite/ld-elf/retain5.map: New test. * testsuite/ld-elf/retain5lib.s: New test. * testsuite/ld-elf/retain5main.s: New test. * testsuite/ld-elf/retain6a.d: New test. * testsuite/ld-elf/retain6b.d: New test. * testsuite/ld-elf/retain6lib.s: New test. * testsuite/ld-elf/retain6main.s: New test.
2020-11-18gdb/ChangeLog: fix typo in an entry from 2020-11-15 (gmp-utils.c)Joel Brobecker1-1/+1
2020-11-18Automatic date update in version.inGDB Administrator1-1/+1
2020-11-17gdb: make get_array_bounds return boolSimon Marchi5-14/+22
Obvious change from int to bool. I took the opportunity to move the doc to the header file. gdb/ChangeLog: * gdbtypes.h (get_array_bounds): Return bool, adjust some callers. Move doc here. * gdbtypes.c (get_array_bounds): Return bool Change-Id: I8ed20298cb0927963c1f09b345966533d5ed06e2
2020-11-17When reading string arguments for the assembler's string directives treat ↵Nick Clifton5-1/+21
space separated strings as a single entity. * read.c (stringer): Treat space separated, quote enclosed strings as a single string. * doc/as.texi (asciz): Mention this behaviour in the description of the asciz directive. * testsuite/gas/all/asciz.s: New test. * testsuite/gas/all/asciz.d: New test driver. * testsuite/gas/all/gas.exp: Run the new test.
2020-11-17Fix gdb.trace testcase build failures with ClangGary Benson2-1/+6
25 gdb.trace tests failed to build on x86 with Clang because the x86_trace_dummy function is optimized out, causing the builds to fail with variations on the following error: gdb compile failed, /usr/bin/ld: /gdbtest/build/gdb/testsuite/outputs/gdb.trace/backtrace/backtrace0.o: in function `main': /gdbtest/src/gdb/testsuite/gdb.trace/actions.c:146: undefined reference to `x86_trace_dummy' clang-12: error: linker command failed with exit code 1 This commit adds __attribute__ ((used)) to x86_trace_dummy to prevent this. gdb/testsuite/ChangeLog: * gdb.trace/trace-common.h (x86_trace_dummy): Add __attribute__ ((used)).
2020-11-17Place the libdeps record in the second archive slot.Howard Chu2-8/+16
* ar.c (main): Place the libdeps record in the second archive slot.
2020-11-17[GOLD] powerpc incremental-dump assertion failureAlan Modra2-10/+18
incremental-dump wants to instantiate Target_powerpc without options being set up. This patch fixes internal error in options, at gold/parameters.h:92 * powerpc.cc (Target_powerpc::no_tprel_opt_): Rename from tprel_opt_. Init to false. (Target_powerpc::tprel_opt): Test parameters->options().tls_optimize(). (Target_powerpc::set_tprel_opt): Delete. (Target_powerpc::set_no_tprel_opt): New function. Update all uses of set_tprel_opt.
2020-11-17[GOLD] fix jump to long branch on powerpcMichael Hudson-Doyle2-2/+7
PR 26902 * powerpc.cc (Relocate::relocate): Do not include local entry offset of target function when computing the address of a stub.