Commit Graph

17601 Commits

Author SHA1 Message Date
Alan Modra
30596893ab sparc64 segfault in finish_dynamic_symbol
SYMBOL_REFERENCES_LOCAL can return true for undefined symbols.  This
can result in a segfault when running sparc64 ld/testsuite/ld-vsb
tests that expect a failure.

	* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Don't
	access u.def.section on non-default visibility undefined symbol.
2022-05-31 21:14:00 +09:30
Alan Modra
74a04e5b2a v850_elf_set_note prototype
v850_elf_set_note is declared using an unsigned int note param in
elf32-v850.h but defined with enum c850_notes note in elf32-v850.c.
Current mainline gcc is warning about this.  Huh.

	* elf32-v850.c (v850_elf_set_note): Make "note" param an
	unsigned int.
2022-05-31 21:14:00 +09:30
GDB Administrator
8b294b1fc7 Automatic date update in version.in 2022-05-31 00:00:08 +00:00
Alan Modra
eab286a7c8 Use a union to avoid casts in bfd/doc/chew.c
This fixes -Wpedantic warnings in chew.c.  Conversion between function
and object pointers is not guaranteed.  They can even be different
sizes, not that we're likely to encounter build machines like that
nowadays.

	PR 29194
	* doc/chew.c (pcu): New union typedef.
	(dict_type, pc): Use it here.  Adjust uses of pc.
	(add_to_definition): Make "word" param a pcu.  Adjust all uses
	of function.
	(stinst_type): Delete.
2022-05-30 19:00:04 +09:30
Alan Modra
7273d78f3f use libiberty xmalloc in bfd/doc/chew.c
Catch out of memory.

	* doc/chew.c: Include libibery.h.
	(init_string_with_size, nextword): Replace malloc with xmalloc.
	(newentry, add_to_definition): Likewise.
	(catchar, catbuf): Replace realloc with xrealloc.
	(add_intrinsic): Replace strdup with xstrdup.
	* doc/local.mk (LIBIBERTY): Define.
	(chew): Link against libiberty.
	* Makefile.in: Regenerate.
2022-05-30 17:04:39 +09:30
Alan Modra
f43ffe07b1 Update K&R functions in bfd/doc/chew.c
* doc/chew.c: Update function definitions to ISO C, remove
	now unnecessary prototypes.
2022-05-30 17:03:52 +09:30
Alan Modra
b9b0b2b5e3 Reorganise bfd/doc/chew.c a little
This also removes some unused variables, and deletes support for the
"var" keyword which isn't used and was broken.  (No means to set
variables, and add_var used push_number inconsistent with its use
elsewhere.)

	* doc/chew.c: Move typedefs before variables, variables before
	functions.
	(die): Move earlier.
	(word_type, sstack, ssp): Delete.
	(dict_type): Delete var field.
	(add_var): Delete.
	(compile): Remove "var" support.
2022-05-30 17:02:01 +09:30
jiawei
292c7bf86d RISC-V: Add zhinx extension supports.
The zhinx extension is a sub-extension in zfinx, corresponding to
zfh extension but use GPRs instead of FPRs.

This patch expanded the zfh insn class define, since zfh and zhinx
use the same opcodes, thanks for Nelson's works.

changelog in V2: Add missing classes of 'zfh' and 'zhinx' in
"riscv_multi_subset_supports_ext".

bfd/ChangeLog:

        * elfxx-riscv.c (riscv_multi_subset_supports): New extensions.
        (riscv_multi_subset_supports_ext): New extensions.

gas/ChangeLog:

        * testsuite/gas/riscv/fp-zhinx-insns.d: New test.
        * testsuite/gas/riscv/fp-zhinx-insns.s: New test.

include/ChangeLog:

        * opcode/riscv.h (enum riscv_insn_class): New INSN classes.

opcodes/ChangeLog:

        * riscv-opc.c: Modify INSN_CLASS.
2022-05-30 11:42:08 +08:00
GDB Administrator
9606310bbb Automatic date update in version.in 2022-05-30 00:00:07 +00:00
GDB Administrator
7caebc2a2a Automatic date update in version.in 2022-05-29 00:00:08 +00:00
GDB Administrator
4fb8f32e40 Automatic date update in version.in 2022-05-28 00:00:10 +00:00
Alan Modra
6015985895 Replace bfd_hostptr_t with uintptr_t
bfd_hostptr_t is defined as a type large enough to hold either a long
or a pointer.  It mostly appears in the coff backend code in casts.
include/coff/internal.h struct internal_syment and union
internal_auxent have the only uses in data structures, where
comparison with include/coff/external.h and other code reveals that
the type only needs to be large enough for a 32-bit integer or a
pointer.  That should mean replacing with uintptr_t is OK.
2022-05-27 22:08:59 +09:30
Alan Modra
65d13793d9 Remove much of BFD_HOST configury
This patch removes the definition of bfd_uint64_t and bfd_int64_t as
well as most BFD_HOST_* which are now unused.
2022-05-27 22:08:59 +09:30
Alan Modra
0e3c1eebb2 Remove use of bfd_uint64_t and similar
Requiring C99 means that uses of bfd_uint64_t can be replaced with
uint64_t, and similarly for bfd_int64_t, BFD_HOST_U_64_BIT, and
BFD_HOST_64_BIT.  This patch does that, removes #ifdef BFD_HOST_*
and tidies a few places that print 64-bit values.
2022-05-27 22:08:59 +09:30
GDB Administrator
62b5b11b1b Automatic date update in version.in 2022-05-27 00:00:06 +00:00
Hans-Peter Nilsson
81cd0a49c9 cris: bfd: Correct default to no execstack
In the now-historical CRIS glibc port, the default stack permission
was no-exec as in "#define DEFAULT_STACK_PERMS (PF_R|PF_W)", and the
gcc port only emits the executable-stack marker when needed; when
emitting code needing it.  In other words, the binutils setting
mismatches.  It doesn't matter much, except being confusing and
defaulting to "off" is more sane.

ld:

	* testsuite/ld-elf/elf.exp (target_defaults_to_execstack): Switch to 0
	for cris*-*-*.

bfd:
	* elf32-cris.c (elf_backend_default_execstack): Define to 0.

Change-Id: I52f37598f119b19111c7a6546c00a627fca0f396
2022-05-27 01:02:46 +02:00
Potharla, Rupesh
f67741e172 bfd: Add Support for DW_FORM_strx* and DW_FORM_addrx* 2022-05-26 16:39:52 +09:30
Luca Boccassi
9e2bb0cb5e ld: add --package-metadata
Generate a .note.package FDO package metadata ELF note, following
the spec: https://systemd.io/ELF_PACKAGE_METADATA/

If the jansson library is available at build time (and it is explicitly
enabled), link ld to it, and use it to validate that the input is
correct JSON, to avoid writing garbage to the file. The
configure option --enable-jansson has to be used to explicitly enable
it (error out when not found). This allows bootstrappers (or others who
are not interested) to seamlessly skip it without issues.
2022-05-26 12:56:12 +09:30
GDB Administrator
d1a24139ad Automatic date update in version.in 2022-05-26 00:00:10 +00:00
Tsukasa OI
51498ab9ab RISC-V: Fix RV32Q conflict
This commit makes RV32 + 'Q' extension (version 2.2 or later) not
conflicting since this combination is no longer prohibited by the
specification.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_parse_check_conflicts): Remove conflict
	detection that prohibits RV32Q on 'Q' version 2.2 or later.

gas/ChangeLog:

	* testsuite/gas/riscv/march-fail-rv32iq.d: Removed.
	* testsuite/gas/riscv/march-fail-rv32iq.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv32iq2p0.d: New test
	showing RV32IQ fails on 'Q' extension version 2.0.
	* testsuite/gas/riscv/march-fail-rv32iq2p0.l: Likewise.
	* testsuite/gas/riscv/march-fail-rv32iq2.d: Likewise.
	* testsuite/gas/riscv/march-fail-rv32iq-isa-2p2.d: New test
	showing RV32IQ fails on ISA specification version 2.2.
	* testsuite/gas/riscv/march-ok-rv32iq2p2.d: New test
	showing RV32IQ succesds on 'Q' extension version 2.2.
	* testsuite/gas/riscv/march-ok-rv32iq-isa-20190608.d: New test
	showing RV32IQ succesds on ISA specification 20190608.
2022-05-25 11:19:59 +08:00
GDB Administrator
f59e7b1289 Automatic date update in version.in 2022-05-25 00:00:06 +00:00
GDB Administrator
9e0f632935 Automatic date update in version.in 2022-05-24 00:00:08 +00:00
GDB Administrator
8d4b0049b5 Automatic date update in version.in 2022-05-23 00:00:07 +00:00
GDB Administrator
cb3a7614fe Automatic date update in version.in 2022-05-22 00:00:06 +00:00
GDB Administrator
d195321cec Automatic date update in version.in 2022-05-21 00:00:39 +00:00
Jia-Wei Chen
9ecdcd1be1 RISC-V: Update zfinx implement with zicsr.
Update zfinx implement with zicsr, fix missing fcsr use by zfinx.
add zicsr imply by zfinx.

bfd/ChangeLog:

        * elfxx-riscv.c: New imply.

gas/ChangeLog:

        * testsuite/gas/riscv/csr-insns-pseudo-zfinx.d: New test.

opcodes/ChangeLog:

        * riscv-opc.c: Update insn class.
2022-05-20 22:21:34 +08:00
Steinar H. Gunderson
b43771b045 add a trie to map quickly from address range to compilation unit
When using perf to profile large binaries, _bfd_dwarf2_find_nearest_line()
becomes a hotspot, as perf wants to get line number information
(for inline-detection purposes) for each and every sample. In Chromium
in particular (the content_shell binary), this entails going through
475k address ranges, which takes a long time when done repeatedly.

Add a radix-256 trie over the address space to quickly map address to
compilation unit spaces; for content_shell, which is 1.6 GB when some
(but not full) debug information turned is on, we go from 6 ms to
0.006 ms (6 µs) for each lookup from address to compilation unit, a 1000x
speedup.

There is a modest RAM increase of 180 MB in this binary (the existing
linked list over ranges uses about 10 MB, and the entire perf job uses
between 2–3 GB for a medium-size profile); for smaller binaries with few
ranges, there should be hardly any extra RAM usage at all.
2022-05-20 16:10:34 +02:00
Alan Modra
bd7d326deb Tidy warn-execstack handling
Make ld and bfd values consistent by swapping values 0 and 2 in
link_info.warn_execstack.  This has the benefit of making the value an
"extended" boolean, with 0 meaning no warning, 1 meaning warn, other
values a conditional warning.

Yes, this patch introduces fails on arm/aarch64.  Not a problem with
this patch but an arm/aarch64 before_parse problem.

bfd/
	* elflink.c (bfd_elf_size_dynamic_sections): Adjust
	warn_execstack test.
include/
	* bfdlink.h (warn_execstack): Swap 0 and 2 meaning.
ld/
	* configure.ac (DEFAULT_LD_WARN_EXECSTACK): Use values of 0,
	1, 2 consistent with link_info.warn_execstack.
	* ld.texi: Typo fixes.
	* lexsup.c (parse_args): Adjust setting of link_info.warn_execstack.
	(elf_static_list_options): Adjust help message conditions.
	* configure: Regenerate.
2022-05-20 16:11:25 +09:30
GDB Administrator
ef5d515048 Automatic date update in version.in 2022-05-20 00:00:45 +00:00
Jan Beulich
20bed3bb35 COFF: use hash for string table also when copying / stripping
Otherwise the string table may grow and hence e.g. change a final binary
(observed with PE/COFF ones) even if really there's no change. Doing so
in fact reduces the overall amount of code, and in particular the number
of places which need to remain in sync.

Afaics there's no real equivalent to the "traditional_format" field used
when linking, so hashing is always enabled when copying / stripping.
2022-05-19 12:45:55 +02:00
Jan Beulich
f0a53c9c89 COFF/PE: keep linker version during objcopy / strip
Neither of the tools is really a linker, so whatever was originally
recorded should be retained rather than being overwritten by these
tools' versions.
2022-05-19 12:44:56 +02:00
Jan Beulich
ce462d0435 COFF: make objcopy / strip honor --keep-file-symbols
So far this option had no effect when used together with e.g.
--strip-debug. Set BSF_FILE on these symbols to change that.

While altering this also join two adjacent blocks of case labeled
statements with identical code.
2022-05-19 12:44:08 +02:00
Jan Beulich
bc5baa9f13 don't over-align file positions of PE executable sections
When a sufficiently small alignment was specified via --file-alignment,
individual section alignment shouldn't affect placement within the file.
This involves first of all clearing D_PAGED for images when section and
file alignment together don't permit paging of the image. The involved
comparison against COFF_PAGE_SIZE in turn helped point out (through a
compiler warning) that 'page_size' should be of unsigned type (as in
particular FileAlignment is). This yet in turn pointed out a dubious
error condition (which is being deleted).

For the D_PAGED case I think the enforced file alignment may still be
too high, but I'm wary of changing that logic without knowing of
possible corner cases.

Furthermore file positions in PE should be independent of the alignment
recorded in section headers anyway. Otherwise there are e.g. anomalies
following commit 6f8f6017a0 ("PR27567, Linking PE files adds alignment
section flags to executables") in that linking would use information a
subsequent processing step (e.g. stripping) wouldn't have available
anymore, and hence a binary could change in that 2nd step for no actual
reason. (Similarly stripping a binary linked with a linker pre-dating
that commit would change the binary again when stripping it a 2nd time.)
2022-05-19 12:43:10 +02:00
Yvan Roux
5f3fc928df _bfd_real_fopen should not use ccs parameter on Windows
PR 25713
	* bfdio.c (_bfd_real_fopen): Delete ccs string.
2022-05-19 10:58:13 +01:00
Tsukasa OI
c4dd8eb523 RISC-V: Fix canonical extension order (K and J)
This commit fixes canonical extension order to follow the RISC-V ISA
Manual draft-20210402-1271737 or later.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_recognized_prefixed_ext): Fix "K" extension
	prefix to be placed before "J".
2022-05-19 11:31:31 +08:00
GDB Administrator
4f02f4d802 Automatic date update in version.in 2022-05-19 00:00:25 +00:00
GDB Administrator
ed11f0543e Automatic date update in version.in 2022-05-18 00:00:31 +00:00
Nelson Chu
035784e345 RISC-V: Added half-precision floating-point v1.0 instructions.
bfd/
	* elfxx-riscv.c (riscv_implicit_subsets): Added implicit f
	and zicsr for zfh.
	(riscv_supported_std_z_ext): Added default v1.0 version for zfh.
	(riscv_multi_subset_supports): Handle INSN_CLASS_ZFH,
	INSN_CLASS_D_AND_ZFH and INSN_CLASS_Q_AND_ZFH.
gas/
	* config/tc-riscv.c (FLT_CHARS): Added "hH".
	(macro): Expand Pseudo M_FLH and M_FSH.
	(riscv_pseudo_table): Added .float16 directive.
	* testsuite/gas/riscv/float16-be.d: New testcase for .float16.
	* testsuite/gas/riscv/float16-le.d: Likewise.
	* testsuite/gas/riscv/float16.s: Likewise.
	* testsuite/gas/riscv/fp-zfh-insns.d: New testcase for zfh.
	* testsuite/gas/riscv/fp-zfh-insns.s: Likewise.
include/
	* opcode/riscv-opc.h: Added MASK and MATCH encodings for zfh.
	* opcode/riscv.h: Added INSN_CLASS and pseudo macros for zfh.
opcodes/
	* riscv-opc.c (riscv_opcodes): Added zfh instructions.
2022-05-17 13:31:38 +08:00
GDB Administrator
626d0e40e5 Automatic date update in version.in 2022-05-17 00:00:35 +00:00
GDB Administrator
b7ff32f191 Automatic date update in version.in 2022-05-16 00:00:37 +00:00
GDB Administrator
6d8b70895c Automatic date update in version.in 2022-05-15 00:00:21 +00:00
GDB Administrator
0b99131d48 Automatic date update in version.in 2022-05-14 00:00:19 +00:00
Pedro Alves
169692ce6c Fix "gdb --write" with core files
If you load a core file into GDB with the --write option, or "set
write on" (equivalent), and then poke memory expecting it to patch the
core binary, you'll notice something odd -- the write seems to
succeed, but in reality, it doesn't.  The value you wrote doesn't
persist.  Like so:

 $ gdb -q --write -c testsuite/outputs/gdb.base/patch/gcore.test
 [New LWP 615986]
 Core was generated by `/home/pedro/gdb/build/gdb/testsuite/outputs/gdb.base/patch/patch'.
 Program terminated with signal SIGTRAP, Trace/breakpoint trap.
 #0  0x0000555555555131 in ?? ()
 (gdb) p *(unsigned char *)0x0000555555555131 = 1
 $1 = 1 '\001'
 (gdb) p *(unsigned char *)0x0000555555555131
 $2 = 185 '\271'
 (gdb)

Diffing hexdumps of before/after patching, reveals that a "0x1" was
actually written somewhere in the file.  The problem is that the "0x1"
was written at the wrong offset in the file...

That happens because _bfd_elf_set_section_contents does this to seek
to the section's offset:

  pos = hdr->sh_offset + offset;
  if (bfd_seek (abfd, pos, SEEK_SET) != 0
      || bfd_bwrite (location, count, abfd) != count)
    return false;

... and 'hdr->sh_offset' is zero, so we seek to just OFFSET, which is
incorrect.  The reason 'hdr->sh_offset' is zero is that
kernel-generated core files normally don't even have a section header
table (gdb-generated ones do, but that's more an accident than a
feature), and indeed elf_core_file_p doesn't even try to read sections
at all:

  /*  Core files are simply standard ELF formatted files that partition
      the file using the execution view of the file (program header table)
      rather than the linking view.  In fact, there is no section header
      table in a core file.

      The process status information (including the contents of the general
      register set) and the floating point register set are stored in a
      segment of type PT_NOTE.  We handcraft a couple of extra bfd sections
      that allow standard bfd access to the general registers (.reg) and the
      floating point registers (.reg2).  */

  bfd_cleanup
  elf_core_file_p (bfd *abfd)

Changing _bfd_elf_set_section_contents from:

  pos = hdr->sh_offset + offset;

to:

  pos = section->filepos + offset;

fixes it.  If we do that however, the tail end of
_bfd_elf_set_section_contents ends up as a copy of
_bfd_generic_set_section_contents, so just call the latter, thus
eliminating some duplicate code.

New GDB testcase included, which exercises both patching an executable
and patching a core file.  Patching an executable already works
without this fix, because in that case BFD reads in the sections
table.  Still, we had no testcase for that yet.  In fact, we have no
"set write on" testcases at all, this is the first one.

Tested on x86-64 GNU/Linux, gdb, ld, binutils, and gas.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18227
Change-Id: I0f49f58b48aabab2e269f2959b8fd8a7fe36fdce
2022-05-13 10:56:05 +01:00
GDB Administrator
d112ec9673 Automatic date update in version.in 2022-05-13 00:00:33 +00:00
GDB Administrator
6c8c5823e3 Automatic date update in version.in 2022-05-12 00:00:24 +00:00
GDB Administrator
455f32e3c3 Automatic date update in version.in 2022-05-11 00:00:18 +00:00
Alan Modra
f3b9cfd195 bfd: remove use of PTR
* coffcode.h (coff_write_object_contents): Don't cast to PTR.
	* elf32-csky.c (csky_elf_link_hash_traverse): Remove use of PTR
	and PARAMS.
	(csky_allocate_dynrelocs): Don't use PTR cast.
	* elf32-nios2.c (adjust_dynrelocs, allocate_dynrelocs): Replace
	PTR with void *.
	* elf32-visium.c (visium_elf_howto_parity_reloc): Likewise.
	* elfxx-ia64.c (ia64_elf_reloc): Likewise.
	* plugin.c (bfd_plugin_bfd_print_private_bfd_data): Likewise.
2022-05-10 11:21:37 +09:30
GDB Administrator
9abf92d229 Automatic date update in version.in 2022-05-10 00:00:17 +00:00
GDB Administrator
2dc60c7710 Automatic date update in version.in 2022-05-09 00:00:15 +00:00
GDB Administrator
07d9774171 Automatic date update in version.in 2022-05-08 00:00:21 +00:00