Commit Graph

18009 Commits

Author SHA1 Message Date
Christoph Müllner
8254c3d2c9 RISC-V: Add T-Head Bitmanip vendor extension
T-Head has a range of vendor-specific instructions.
Therefore it makes sense to group them into smaller chunks
in form of vendor extensions.

This patch adds the XThead{Ba,Bb,Bs} extensions, a collection of
T-Head-specific bitmanipulation instructions.
The 'th' prefix and the "XThead{Ba,Bb,Bs}" extension are documented
in a PR for the RISC-V toolchain conventions ([1]).

[1] https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/19

Co-developed-by: Lifang Xia <lifang_xia@linux.alibaba.com>
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2022-09-22 18:06:09 +02:00
Christoph Müllner
547c18d9bb RISC-V: Add T-Head SYNC vendor extension
T-Head has a range of vendor-specific instructions.
Therefore it makes sense to group them into smaller chunks
in form of vendor extensions.

This patch adds the XTheadSync extension, a collection of
T-Head-specific multi-processor synchronization instructions.
The 'th' prefix and the "XTheadSync" extension are documented in a PR
for the RISC-V toolchain conventions ([1]).

[1] https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/19

Co-developed-by: Lifang Xia <lifang_xia@linux.alibaba.com>
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2022-09-22 18:06:09 +02:00
Christoph Müllner
a9ba8bc2d3 RISC-V: Add T-Head CMO vendor extension
T-Head has a range of vendor-specific instructions.
Therefore it makes sense to group them into smaller chunks
in form of vendor extensions.

This patch adds the XTheadCmo extension, a collection of T-Head specific
cache management operations.
The 'th' prefix and the "XTheadCmo" extension are documented in a PR
for the RISC-V toolchain conventions ([1]).

In total XTheadCmo introduces the following 21 instructions:

* DCACHE.{C,CI,I}ALL
* DCACHE.{C,CI,I}{PA,VA,SW} rs1
* DCACHE.C{PAL1,VAL1} rs1
* ICACHE.I{ALL,ALLS}
* ICACHE.I{PA,VA} rs1
* L2CACHE.{C,CI,I}ALL

Contrary to Zicbom, the XTheadCmo instructions don't have a constant
displacement, therefore we have a different syntax for the arguments.
To clarify this is intended behaviour, there is a set of negative test
for Zicbom-style arguments in x-thead-cmo-fail.s.

[1] https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/19

v2:
- Add missing DECLARE_INSN() list
- Fix ordering

Co-developed-by: Lifang Xia <lifang_xia@linux.alibaba.com>
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2022-09-22 18:06:09 +02:00
Christoph Müllner
fb1737381d RISC-V: Add generic support for vendor extensions
This patch introduces changes that allow the integration of vendor ISA
extensions:
* Define a list of vendor extensions (riscv_supported_vendor_x_ext)
  where vendor extensions can be added
* Introduce a section with a table in the documentation where vendor
  extensions can be added

To add a vendor extension that consists of instructions only,
the following things need to be done:
* Add the extension to the riscv_supported_vendor_x_ext list
* Add lookup entry in riscv_multi_subset_supports
* Documenting the extension in c-riscv.texti
* Add test cases for all instructions
* Add MATCH*/MASK* constants and DECLARE_INSN() for all instructions
* Add new instruction class to enum riscv_insn_class
* Define the instructions in riscv_opcodes
* Additional changes if necessary (depending on the instructions)

Co-developed-by: Lifang Xia <lifang_xia@linux.alibaba.com>
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2022-09-22 18:06:09 +02:00
GDB Administrator
8cdbd5231e Automatic date update in version.in 2022-09-22 00:00:10 +00:00
Alan Modra
d13102c03e bfd BLD-POTFILES.in dependencies
A file that consists of a list of files doesn't depend on those files
being built.  This patch came from trying to avoid a maintainer-mode
make -j bug, where the recipe for targmatch.h was being run twice in
parallel.  Typical output shown below.

make[2]: Entering directory '/build/gas/all/bfd'
  GEN      bfdver.h
  GEN      elf32-target.h
  GEN      elf64-target.h
  GEN      targmatch.h
Making info in po
make[3]: Entering directory '/build/gas/all/bfd/po'
cd .. && make po/SRC-POTFILES.in
cd .. && make po/BLD-POTFILES.in
make[4]: Entering directory '/build/gas/all/bfd'
  GEN      elf32-aarch64.c
  GEN      elf64-aarch64.c
  GEN      elf32-ia64.c
  GEN      elf64-ia64.c
  GEN      elf32-loongarch.c
  GEN      elf64-loongarch.c
  GEN      elf32-riscv.c
  GEN      elf64-riscv.c
  GEN      peigen.c
  GEN      pepigen.c
  GEN      pex64igen.c
  GEN      pe-aarch64igen.c
  GEN      targmatch.h
make[4]: Entering directory '/build/gas/all/bfd'
  CCLD     doc/chew.stamp
mv: cannot stat 'targmatch.new': No such file or directory
make[4]: *** [Makefile:2325: targmatch.h] Error 1

	* Makefile.am (po/BLD-POTFILES.in): Don't depend on $(BLD_POTFILES).
	(po/SRC-POTFILES.in): Don't depend on $(SRC_POTFILES).
2022-09-22 08:14:55 +09:30
Alan Modra
f9a59eea78 PR29566, objdump -p considers an empty .gnu.version_r invalid
Allow and ignore an empty section.

	PR 29566
	* elf.c (bfd_section_from_shdr): Don't set elf_dynverdef or
	elf_dynverref for empty sections.
	(_bfd_elf_slurp_version_tables): Remove now redundant tests.
2022-09-21 22:10:14 +09:30
Alan Modra
3094c89e9c PR29573, addr2line doesn't display file/line for local symbols
The DWARF standard is clear that DW_AT_linkage_name is optional.
Compilers may not provide the attribute on functions and variables,
even though the language mangles names.  g++ does not for local
variables and functions.  Without DW_AT_linkage_name, mangled object
file symbols can't be directly matched against the source-level
DW_AT_name in DWARF info.  One possibility is demangling the object
file symbols, but that comes with its own set of problems:
1) A demangler might not be available for the compiler/language.
2) Demangling doesn't give the source function name as stored in
   DW_AT_name.  Class and template parameters must be stripped at
   least.

So this patch takes a simpler approach.  A symbol matches DWARF info
if the DWARF address matches the symbol address, and if the symbol
name contains the DWARF name as a sub-string.  Very likely the name
matching is entirely superfluous.

	PR 29573
	* dwarf.c (lookup_symbol_in_function_table): Match a symbol
	containing the DWARF source name as a substring.
	(lookup_symbol_in_variable_table): Likewise.
	(_bfd_dwarf2_find_nearest_line_with_alt): If stash_find_line_fast
	returns false, fall back to comp_unit_find_line.
2022-09-21 16:08:38 +09:30
Alan Modra
6c5e237146 dwarf2.c: simplify best_fit_len tests
* dwarf2.c (lookup_address_in_function_table): Simplify
	best_fit_len test.
	(info_hash_lookup_funcinfo): Likewise.
	(lookup_symbol_in_function_table): Likewise, also reorder tests
	and check "file" is set.
	(lookup_symbol_in_variable_table): Reorder tests.
2022-09-21 15:55:10 +09:30
Alan Modra
4609af80c2 dwarf2.c: mangle_style
non_mangled incorrectly returned "true" for Ada.  Correct that, and
add a few more non-mangled entries.  Return a value suitable for
passing to cplus_demangle to control demangling.

	* dwarf2.c: Include demangle.h.
	(mangle_style): Rename from non_mangled.  Return DMGL_* value
	to suit lang.  Adjust all callers.
2022-09-21 15:55:10 +09:30
Alan Modra
6c0cf2ca0d dwarf2.c remove varinfo and funcinfo sec field
The "sec" field in these structures is only set and used in lookup
functions.  It always starts off as NULL.  So the only possible effect
of the field is to modify the return of the lookup, which was its
purpose back in 2005 when HJ fixed PR990.  Since then we solved the
problem of relocatable object files with the fix for PR2338, so this
field is now redundant.

	* dwarf.c (struct funcinfo, struct varinfo): Remove "sec" field.
	(lookup_symbol_in_function_table): Don't set or test "sec".
	(lookup_symbol_in_variable_table): Likewise.
	(info_hash_lookup_funcinfo, info_hash_lookup_varinfo): Likewise.
2022-09-21 15:55:10 +09:30
Shihua
96462b0129 RISC-V: Implement Ztso extension
This patch support ZTSO extension. It will turn on the tso flag for elf_flags
once we have enabled Ztso extension.  This is intended to implement v0.1 of
the proposed specification which can be found in Chapter 25 of,
https://github.com/riscv/riscv-isa-manual/releases/download/draft-20220723-10eea63/riscv-spec.pdf.

bfd\ChangeLog:

        * elfnn-riscv.c (_bfd_riscv_elf_merge_private_bfd_data): Set TSO flag.
        * elfxx-riscv.c: Add Ztso's arch.

binutils\ChangeLog:

        * readelf.c (get_machine_flags): Set TSO flag.

gas\ChangeLog:

        * config/tc-riscv.c (riscv_set_tso): Ditto.
        (riscv_set_arch): Ditto.
        * testsuite/gas/riscv/ztso.d: New test.

include\ChangeLog:

        * elf/riscv.h (EF_RISCV_TSO): Ditto.
2022-09-21 11:43:35 +08:00
GDB Administrator
e348122963 Automatic date update in version.in 2022-09-21 00:00:13 +00:00
Alan Modra
8c8fa33c20 looping in alpha_vms_slurp_relocs
The direct cause for the looping was failing to test for error return
from _bfd_vms_get_object_record inside a while(1) loop.  Fix that.
Also record status of first alpha_vms_slurp_relocs call and return
that for all subsequent calls.  (The object format has one set of
relocation records for all sections.)  If the first call fails, all
others should too.

	* vms-alpha.c (struct vms_private_data_struct): Make reloc_done
	a tri-state int.
	(alpha_vms_slurp_relocs): Set reloc_done to 1 on success, -1 on
	failure.  Return that status on subsequent calls.  Check
	_bfd_vms_get_object_record return status.
	(alpha_vms_get_reloc_upper_bound): Return status from
	alpha_vms_slurp_relocs.
	(alpha_vms_write_exec): Exclude sections with contents NULL due
	to previous errors from layout, and don't try to write them.
2022-09-21 09:06:21 +09:30
Nick Clifton
7e19db932c New Serbian translations for various binutils sub-directories. 2022-09-20 11:33:16 +01:00
Xi Ruoyao
ae2e4d4035 LoongArch: Fix R_LARCH_IRELATIVE insertion after elf_link_sort_relocs
loongarch_elf_finish_dynamic_symbol is called after elf_link_sort_relocs
if -z combreloc.  elf_link_sort_relocs redistributes the contents of
.rela.* sections those would be merged into .rela.dyn, so the slot for
R_LARCH_IRELATIVE may be out of relplt->contents now.

To make things worse, the boundary check

    dyn < dyn + relplt->size / sizeof (*dyn)

is obviously wrong ("x + 10 < x"? :), causing the issue undetected
during the linking process and the resulted executable suddenly crashes
at runtime.

The issue was found during an attempt to add static-pie support to the
toolchain.

Fix it by iterating through the inputs of .rela.dyn to find the slot.
2022-09-20 17:16:06 +08:00
Xi Ruoyao
6224a6c2ea LoongArch: Don't write into GOT for local ifunc
Local ifuncs are always resolved at runtime via R_LARCH_IRELATIVE, so
there is no need to write anything into GOT.  And when we write the GOT
we actually trigger a heap-buffer-overflow: If a and b are different
sections, we cannot access something in b with "a->contents + (offset
from a)" because "a->contents" and "b->contents" are heap buffers
allocated separately, not slices of a large buffer.

So stop writing into GOT for local ifunc now.
2022-09-20 17:16:05 +08:00
GDB Administrator
6519cd1a15 Automatic date update in version.in 2022-09-20 00:00:17 +00:00
GDB Administrator
c99b2113a4 Automatic date update in version.in 2022-09-19 00:00:12 +00:00
GDB Administrator
4e38ed582c Automatic date update in version.in 2022-09-18 00:00:11 +00:00
GDB Administrator
5e3cecb21a Automatic date update in version.in 2022-09-17 00:00:14 +00:00
Alan Modra
839a4671a9 pdb sanity check block_size
* pdb.c (pdb_get_elt_at_index): Only allow block_size to be
	512, 1024, 2048, or 4096.
2022-09-16 13:05:41 +09:30
Nelson Chu
8838766ad6 RISC-V: Make g imply zmmul extension.
bfd/
	* elfxx-riscv.c (riscv_implicit_subset): Moved entry of m after g,
	so that g can imply zmmul.
gas/
	* testsuite/gas/riscv/attribute-01.d: Updated.
	* testsuite/gas/riscv/attribute-02.d: Likewise.
	* testsuite/gas/riscv/attribute-03.d: Likewise.
	* testsuite/gas/riscv/attribute-04.d: Likewise.
	* testsuite/gas/riscv/attribute-05.d: Likewise.
	* testsuite/gas/riscv/attribute-10.d: Likewise.
	* testsuite/gas/riscv/march-imply-g.d: Likewise.
	* testsuite/gas/riscv/march-imply-unsupported.d: Likewise.
2022-09-16 09:30:57 +08:00
GDB Administrator
ca4f92520e Automatic date update in version.in 2022-09-16 00:00:10 +00:00
Tsukasa OI
d0975d8002 bfd, binutils, gas: Remove/mark unused variables
Clang generates a warning on unused (technically, written but not read
thereafter) variables.  By the default configuration (with "-Werror"), it
causes a build failure (unless "--disable-werror" is specified).

This commit adds ATTRIBUTE_UNUSED attribute to some of them, which means
they are *possibly* unused (can be used but no warnings occur when
unused) and removes others.

bfd/ChangeLog:

	* elf32-lm32.c (lm32_elf_size_dynamic_sections): Mark unused
	rgot_count variable.
	* elf32-nds32.c (elf32_nds32_unify_relax_group): Remove unused
	count variable.
	* mmo.c (mmo_scan): Mark unused lineno variable.

binutils/ChangeLog:

	* windmc.c (write_rc): Remove unused i variable.

gas/ChangeLog:

	* config/tc-riscv.c (riscv_ip): Remove unused argnum variable.

ld/ChangeLog:

	* pe-dll.c (generate_reloc): Remove unused bi and page_count
	variables.
2022-09-15 10:46:02 +00:00
GDB Administrator
8422cbe455 Automatic date update in version.in 2022-09-15 00:00:13 +00:00
Alan Modra
8d783d5e1d looping in bfd_mach_o_fat_openr_next_archived_file
mach-o.c doesn't sanity check mach-o-fat archives, making it easy for
fuzzers to create an archive with mach_o_fat_archentry headers that
point to the same offset.  bfd_mach_o_fat_openr_next_archived_file
uses the previous element offset to find its header, and thus the next
element.  If two offsets are the same, any tool reading the archive
will get stuck.  This patch rejects such archives, and any with
overlapping elements.

	* mach-o.c (overlap_previous): New function.
	(bfd_mach_o_fat_archive_p): Sanity check that elements do not
	overlap each other or the file and archive headers.
2022-09-14 17:14:06 +09:30
Alan Modra
faf351b59d regen pofiles 2022-09-14 15:45:19 +09:30
Tsukasa OI
491cf3178f bfd: Stop using -Wstack-usage=262144 when built with Clang
Some components of GNU Binutils will pass "-Wstack-usage=262144" when
"GCC >= 5.0" is detected.  However, Clang does not support "-Wstack-usage",
despite that related configuration part in bfd/warning.m4 handles the latest
Clang (15.0.0 as of this writing) as "GCC >= 5.0".

The option "-Wstack-usage" was ignored when the first version of Clang is
released but even this "ignoring" behavior is removed before Clang 4.0.0.
So, if we give Clang "-Wstack-usage=262144", it generates a warning, making
the build failure.

This commit checks "__clang__" macro to prevent adding the option if the
compiler is identified as Clang.

bfd/ChangeLog:

	* warning.m4: Stop appending "-Wstack-usage=262144" option when
	compiled with Clang.
	* configure: Regenerate.

binutils/ChangeLog:

	* configure: Regenerate.

gas/ChangeLog:

	* configure: Regenerate.

gold/ChangeLog:

	* configure: Regenerate.

gprof/ChangeLog:

	* configure: Regenerate.

ld/ChangeLog:

	* configure: Regenerate.

opcodes/ChangeLog:

	* configure: Regenerate.
2022-09-14 05:42:17 +00:00
Alan Modra
acfd5524fa asan: som_set_reloc_info heap buffer overflow
Also a bugfix.  The first time the section was read, the contents
didn't supply an addend.

	* som.c (som_set_reloc_info): Sanity check offset.  Do process
	contents after reading.  Tidy section->contents after freeing.
2022-09-14 10:19:57 +09:30
Alan Modra
72e366db62 ubsan: som_is_space null dereference
On objcopy of fuzzed file.

	* som.c (som_write_fixups): Exit loop if space sections all
	processed.
2022-09-14 10:19:56 +09:30
Alan Modra
3cb5e955a3 msan: vms-alpha use-of-uninitialized-value in dst_retrieve_location
* vms-alpha.c (dst_define_location): Init any unused entries.
2022-09-14 10:19:56 +09:30
Alan Modra
365bf300da PR29540, R_PPC64_NONE in .rela.dyn when linking Linux vdso
PR 29540
	* elf64-ppc.c (allocate_dynrelocs): Don't alloc space for relocs
	against discarded sections.
	(ppc64_elf_size_dynamic_sections): Use standard test for discarded
	sections.
	* elf32-ppc.c (allocate_dynrelocs): Don't alloc space for relocs
	against discarded sections.
	(ppc_elf_size_dynamic_sections): Use standard test for discarded
	sections.
2022-09-14 10:19:56 +09:30
GDB Administrator
620fe92831 Automatic date update in version.in 2022-09-14 00:00:17 +00:00
Mark Harmstone
6a69b0a180 Add pdb archive format
Resubmitted with changes in
https://sourceware.org/pipermail/binutils/2022-September/122791.html
made.
2022-09-13 10:31:05 +01:00
GDB Administrator
20e2bd5c63 Automatic date update in version.in 2022-09-13 00:00:19 +00:00
Nelson Chu
ecb915b4de RISC-V: PR28509, the default visibility symbol cannot be referenced by R_RISCV_JAL.
When generating the shared object, the default visibility symbols may bind
externally, which means they will be exported to the dynamic symbol table,
and are preemptible by default.  These symbols cannot be referenced by the
non-pic R_RISCV_JAL and R_RISCV_RVC_JUMP.  However, consider that linker
may relax the R_RISCV_CALL relocations to R_RISCV_JAL or R_RISCV_RVC_JUMP,
if these relocations are relocated to the plt entries, then we won't report
error for them.  Perhaps we also need the similar checks for the
R_RISCV_BRANCH and R_RISCV_RVC_BRANCH relocations.

After applying this patch, and revert the following glibc patch,
riscv: Fix incorrect jal with HIDDEN_JUMPTARGET
https://sourceware.org/git/?p=glibc.git;a=commit;h=68389203832ab39dd0dbaabbc4059e7fff51c29b

I get the expected errors as follows,
ld: relocation R_RISCV_RVC_JUMP against `__sigsetjmp' which may bind externally can not be used when making a shared object; recompile with -fPIC
ld: relocation R_RISCV_JAL against `exit' which may bind externally can not be used when making a shared object; recompile with -fPIC

Besides, we also have similar changes for libgcc,
RISC-V: jal cannot refer to a default visibility symbol for shared object
45116f3420

bfd/
	pr 28509
	* elfnn-riscv.c (riscv_elf_relocate_section): Report errors when
	makeing a shard object, and the referenced symbols of R_RISCV_JAL
	relocations are default visibility.  Besides, we should handle most
	of the cases here, so don't need the unresolvable check later for
	R_RISCV_JAL and R_RISCV_RVC_JUMP.
ld/
	pr 28509
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
	* testsuite/ld-riscv-elf/lib-nopic-01a.s: Removed.
	* testsuite/ld-riscv-elf/lib-nopic-01b.d: Likewise.
	* testsuite/ld-riscv-elf/lib-nopic-01b.s: Likewise.
	* testsuite/ld-riscv-elf/shared-lib-nopic-01.d: New testcase.
	* testsuite/ld-riscv-elf/shared-lib-nopic-01.s: Likewise.
	* testsuite/ld-riscv-elf/shared-lib-nopic-02.d: Likewise.
	* testsuite/ld-riscv-elf/shared-lib-nopic-02.s: Likewise.
	* testsuite/ld-riscv-elf/shared-lib-nopic-03.d: Likewise.
	* testsuite/ld-riscv-elf/shared-lib-nopic-03.s: Likewise.
	* testsuite/ld-riscv-elf/shared-lib-nopic-04.d: Likewise.
	* testsuite/ld-riscv-elf/shared-lib-nopic-04.s: Likewise.
2022-09-12 11:31:41 +08:00
GDB Administrator
0967e2e492 Automatic date update in version.in 2022-09-12 00:00:10 +00:00
GDB Administrator
20a64ae9cb Automatic date update in version.in 2022-09-11 00:00:12 +00:00
GDB Administrator
9d3b25ecc5 Automatic date update in version.in 2022-09-10 00:00:07 +00:00
Nick Clifton
efc1521e40 Support debuginfo files with empty group sections.
PR 29532
bfd	* elf.c (setup_group): Do not return false if there is no group
	information available.

bionutils* objcopy.c (setup_section): Leave group sections intact when
	creating separate debuginfo files.
2022-09-09 12:01:55 +01:00
GDB Administrator
58448ad29c Automatic date update in version.in 2022-09-09 00:00:26 +00:00
GDB Administrator
f42546b6cc Automatic date update in version.in 2022-09-08 00:00:07 +00:00
GDB Administrator
3c4e228256 Automatic date update in version.in 2022-09-07 00:00:08 +00:00
Aaron Merey
6e7a29c7de bfd: Add bfd_find_nearest_line_with_alt
bfd_find_nearest_line_with_alt functions like bfd_find_nearest_line with
the addition of a parameter for specifying the filename of a supplementary
debug file such as one referenced by .gnu_debugaltlink or .debug_sup.

This patch focuses on implementing bfd_find_nearest_line_with_alt
support for ELF/DWARF2 .gnu_debugaltlink. For other targets this
function simply sets the invalid_operation bfd_error.
2022-09-06 10:42:50 -04:00
GDB Administrator
a49fdb49c8 Automatic date update in version.in 2022-09-06 00:00:07 +00:00
GDB Administrator
06c00d5fea Automatic date update in version.in 2022-09-05 00:00:07 +00:00
GDB Administrator
d236680ae9 Automatic date update in version.in 2022-09-04 00:00:07 +00:00
GDB Administrator
148b68a56c Automatic date update in version.in 2022-09-03 00:00:08 +00:00
Max Filippov
658ba81aef xtensa: bfd: fix TLS relocations generated for PIE
When generating TLS dynamic relocations the existing xtensa BFD code
treats linking to a PIE exactly as linking to a shared object, resulting
in generation of wrong relocations for TLS entries. Fix that and add
tests.

bfd/
	* elf32-xtensa.c (elf_xtensa_check_relocs): Use bfd_link_dll
	instead of bfd_link_pic. Add elf_xtensa_dynamic_symbol_p test
	when generating GOT entries.
	(elf_xtensa_relocate_section): Use bfd_link_dll instead of
	bfd_link_pic.
ld/
	* testsuite/ld-xtensa/tlspie.dd: New file.
	* testsuite/ld-xtensa/tlspie.rd: New file.
	* testsuite/ld-xtensa/tlspie.sd: New file.
	* testsuite/ld-xtensa/tlspie.td: New file.
	* testsuite/ld-xtensa/xtensa-linux.exp (TLS PIE transitions):
	New test.
2022-09-02 09:54:49 -07:00
Frederic Cambus
d0a122d311 Add OpenBSD ARM Little Endian BFD support.
* config.bfd (arm-*-openbsd*): Restore target.
2022-09-02 11:29:54 +01:00
GDB Administrator
5edf42b635 Automatic date update in version.in 2022-09-02 00:00:13 +00:00
GDB Administrator
a651b117e1 Automatic date update in version.in 2022-09-01 00:00:07 +00:00
GDB Administrator
649cd1d8df Automatic date update in version.in 2022-08-31 00:00:07 +00:00
Nick Clifton
37833b9665 BFD library: Use entry 0 in directory and filename tables of DWARF-5 debug info.
PR 29529
	* dwarf2.c (struct line_info_table): Add new field:
	use_dir_and_file_0.
	(concat_filename): Use new field to help select the correct table
	slot.
	(read_formatted_entries): Do not skip entry 0.
	(decode_line_info): Set new field depending upon the version of
	DWARF being parsed.  Initialise filename based upon the setting of
	the new field.
2022-08-30 16:01:20 +01:00
Tsukasa OI
0938b032da RISC-V: Add 'Zmmul' extension in assembler.
Three-part patch set from Tsukasa OI to support zmmul in assembler.

The 'Zmmul' is a RISC-V extension consisting of only multiply instructions
(a subset of 'M' which has multiply and divide instructions).

bfd/
	* elfxx-riscv.c (riscv_implicit_subsets): Add 'Zmmul' implied by 'M'.
	(riscv_supported_std_z_ext): Add 'Zmmul' extension.
	(riscv_multi_subset_supports): Add handling for new instruction class.
gas/
	* testsuite/gas/riscv/attribute-09.d: Updated implicit 'Zmmul' by 'M'.
	* testsuite/gas/riscv/option-arch-02.d: Likewise.
	* testsuite/gas/riscv/m-ext.s: New test.
	* testsuite/gas/riscv/m-ext-32.d: New test (RV32).
	* testsuite/gas/riscv/m-ext-64.d: New test (RV64).
	* testsuite/gas/riscv/zmmul-32.d: New expected output.
	* testsuite/gas/riscv/zmmul-64.d: Likewise.
	* testsuite/gas/riscv/m-ext-fail-xlen-32.d: New test (failure
	by using RV64-only instructions in RV32).
	* testsuite/gas/riscv/m-ext-fail-xlen-32.l: Likewise.
	* testsuite/gas/riscv/m-ext-fail-zmmul-32.d: New failure test
	(RV32 + Zmmul but with no M).
	* testsuite/gas/riscv/m-ext-fail-zmmul-32.l: Likewise.
	* testsuite/gas/riscv/m-ext-fail-zmmul-64.d: New failure test
	(RV64 + Zmmul but with no M).
	* testsuite/gas/riscv/m-ext-fail-zmmul-64.l: Likewise.
	* testsuite/gas/riscv/m-ext-fail-noarch-64.d: New failure test
	(no Zmmul or M).
	* testsuite/gas/riscv/m-ext-fail-noarch-64.l: Likewise.
include/
	* opcode/riscv.h (enum riscv_insn_class): Added INSN_CLASS_ZMMUL.
ld/
	* testsuite/ld-riscv-elf/attr-merge-arch-01.d: We don't care zmmul in
	these testcases, so just replaced m by a.
	* testsuite/ld-riscv-elf/attr-merge-arch-01a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-01b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-02.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-02a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-03a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-user-ext-01.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-user-ext-rv32i2p1_a2p0.s: Renamed.
	* testsuite/ld-riscv-elf/attr-merge-user-ext-rv32i2p1_a2p1.s: Renamed.
opcodes/
	* riscv-opc.c (riscv_opcodes): Updated multiply instructions to zmmul.
2022-08-30 17:46:11 +08:00
GDB Administrator
fae8f4d1fd Automatic date update in version.in 2022-08-30 00:00:07 +00:00
GDB Administrator
27d582267a Automatic date update in version.in 2022-08-29 00:00:07 +00:00
GDB Administrator
d91ab9a73b Automatic date update in version.in 2022-08-28 00:00:14 +00:00
rupothar
9c17922bfe bfd: Fix minor bug in read_indexed_address function.
read_indexed_address function is using offset_size instead of
addr_size while reading addrx forms.
2022-08-27 14:25:44 +09:30
GDB Administrator
46e59b72f2 Automatic date update in version.in 2022-08-27 00:00:08 +00:00
GDB Administrator
8d00b2b74b Automatic date update in version.in 2022-08-26 00:00:06 +00:00
H.J. Lu
2c43d202ae x86: Ignore protected visibility in shared libraries on Solaris
On x86, the PLT entry in executable may be used as function address for
functions in shared libraries.  If functions are protected, the function
address used in executable can be different from the function address
used in shared library.  This will lead to incorrect run-time behavior
if function pointer equality is needed.  By default, x86 linker issues
an error in this case.

On Solaris, linker issued an error for

struct tm *tb = (kind == CPP_time_kind::FIXED ? gmtime : localtime) (&tt);

where gmtime is a protected function in libc.so.  Use gmtime's PLT entry
in executable as function address is safe since function pointer equality
isn't needed.  Ignore protected visibility in shared libraries on Solaris
to disable linker error.  If function pointer equality is needed, linker
will silently generate executable with incorrect run-time behavior on
Solaris.

	PR ld/29512
	* elf32-i386.c (elf_i386_scan_relocs): Ignore protected
	visibility in shared libraries on Solaris.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
2022-08-25 09:10:45 -07:00
Alan Modra
c2d7de232b PR11290, avr-ld "out of range error" is confusing
Don't overload bfd_reloc_outofrange with what is really a domain error
(target at odd address), or an overflow.

	PR 11290
	* reloc.c (bfd_reloc_other): Correct comment.
	* elf32-avr.c (avr_final_link_relocate): Return bfd_reloc_other
	for unaligned reloc target values.  Return bfd_reloc_overflow
	when stubs are too far away and when R_AVR_LDS_STS_16,
	R_AVR_PORT6, or R_AVR_PORT5 overflow.
	(elf32_avr_relocate_section): Report more descriptive relocation
	errors.
	* bfd-in2.h: Regenerate.
2022-08-25 17:20:01 +09:30
GDB Administrator
66a43cf1a7 Automatic date update in version.in 2022-08-25 00:00:08 +00:00
liuzhensong
42bd5254fb LoongArch: ld: Fix bug not generate plt when link a dso
Fix the bug that can not generate func@plt
  when linking a undefined function with cmodel=medium.
  Add testcase.

  bfd/
    * elfnn-loongarch.c
  ld/testsuite/ld-loongarch-elf/
    * cmodel-libjirl.dd
    * cmodel.exp
    * libjirl.s
2022-08-24 14:27:03 +08:00
GDB Administrator
044193ebf6 Automatic date update in version.in 2022-08-24 00:00:10 +00:00
Alan Modra
37c49d0d63 SHT_RELR sh_link and sh_info
I don't think it makes any sense for a SHT_RELR section to specify a
symbol table with sh_link.  SHT_RELR relocations don't use symbols.
There is no real need to specify sh_info either, SHT_RELR is not for
relocatable object files.  Anyway, fuzzers of course don't restrict
themselves to even half-sensible objects.  So they found a hole in
objcopy using a non-alloc SHT_RELR in an ET_EXEC.  In that case BFD
set up the SHT_RELR section as if it were a SHT_REL against the
sh_info target section.  When it came to reading in the target section
relocs, the count was horribly wrong which caused a buffer overflow.

	* elf.c (bfd_section_from_shdr <SHT_RELR>): Always just make a
	normal section, don't treat it as a reloc section.
2022-08-23 21:10:51 +09:30
Alan Modra
6ecc36f7b7 Re: bfd_elf_set_group_contents assertion
Further to commit 7744e3278b.

	* elf.c (bfd_elf_set_group_contents): Restrict loc in loop writing
	contents, and add another assertion.
2022-08-23 18:32:25 +09:30
GDB Administrator
f8bfbd5b75 Automatic date update in version.in 2022-08-23 00:00:12 +00:00
Frederic Cambus
ba86e75013 Add OpenBSD AArch64 Little Endian BFD support.
* config.bfd (aarch64-*-openbsd*): Add target.
2022-08-22 10:19:42 +01:00
GDB Administrator
1034d824d8 Automatic date update in version.in 2022-08-22 00:00:07 +00:00
GDB Administrator
12f26cb22e Automatic date update in version.in 2022-08-21 00:00:11 +00:00
Alan Modra
7749133722 symbols for bfd_simple_get_relocated_section_contents
If symbols are provided by the caller of this function they are
passed on to bfd_get_relocated_section_contents.  No surprises there.
It gets a little weird if they are not provided.  In that case they
are read from the bfd by _bfd_generic_link_add_symbols, and global
symbols are added to the generic linker hash table.  Global symbols
are not added to the linker hash table if symbols *are* provided.  Now
the linker hash table symbols are not used by the generic
bfd_get_relocated_section_conents, and also not by most target
versions when called from bfd_simple_get_relocated_section_contents
except for symbols like "_gp".  So it mostly doesn't matter whether
symbols are in the linker hash table, but it's odd that there is a
difference.  We could always add them, but I'm inclined to think that
is unnecessary work so this patch always leaves them out.

Also, symbols are canonicalized and written into a malloc'd buffer.
The buffer isn't freed, see commit 8e16317ca5.  I don't know whether
that matters any more, but in any case I can't see why we need another
copy of the symbols when _bfd_generic_link_read_symbols has already
cached symbols.

	* simple.c (bfd_simple_get_relocated_section_contents): If not
	provided, read symbols via bfd_generic_link_read_symbols.  Do
	not create another copy of symbols.  Tidy failure exits.
	Minor tidy of bfd_get_relocated_section_contents and
	bfd_get_full_section_contents arguments.
2022-08-21 07:54:27 +09:30
GDB Administrator
a6ac3352ac Automatic date update in version.in 2022-08-20 00:00:07 +00:00
Alan Modra
866318daa3 loongarch64_pei_vec garbage in objcopy'd relocs
Like commit a9c09a3667, but for loongarch64.

	* coff-loongarch64.c (SWAP_IN_RELOC_OFFSET): Define.
	(SWAP_OUT_RELOC_OFFSET): Define.
2022-08-19 10:30:45 +09:30
GDB Administrator
c9dc8fbd9b Automatic date update in version.in 2022-08-19 00:00:09 +00:00
GDB Administrator
2b57654c27 Automatic date update in version.in 2022-08-18 00:00:07 +00:00
Alan Modra
7744e3278b bfd_elf_set_group_contents assertion
objcopy of broken SHT_GROUP sections shouldn't write garbage.

	* elf.c (bfd_elf_set_group_contents): If number of entries is
	unexpected, fill out section with zeros.
2022-08-17 17:29:42 +09:30
Alan Modra
31e43bfffb timeout in mmo_get_symbols
Fix mmo_get_byte to return a fail-safe value, not just on the first
call with a read error but on subsequent calls too.

	* mmo.c (mmo_get_byte): Return the fail-safe value on every
	call after a read error.
2022-08-17 16:35:57 +09:30
Alan Modra
7a1bc25b9d mmo.c leak in mmo_make_section
* mmo.c (mmo_make_section): Alloc name using bfd_alloc.  Use
	bfd_error_no_memory.
	(mmo_decide_section): Check for NULL return from mmo_make_section.
2022-08-17 16:35:57 +09:30
Alan Modra
2bda15d73c asan: heap buffer overflow in mmo_scan
mmo_get_loc needs to handle arbitrary vma and size chunks.  Fuzzers
found that it wasn't working so well when the end of chunks were
getting close to address wrap-around.

	* mmo.c (mmo_get_loc): Make "size" unsigned.  Avoid arithmetic
	overflow when calculating whether range hits an existing chunk.
2022-08-17 16:32:04 +09:30
Alan Modra
11c6a7c623 elf.c tidy
Swap params of is_note, so they are section, segment like others used
in rewrite_elf_program_header.  Whitespace fixes, plus wrapping of
overlong lines.
2022-08-17 11:53:21 +09:30
GDB Administrator
cd78bd1e8c Automatic date update in version.in 2022-08-17 00:00:07 +00:00
Torbjörn SVENSSON
4ae982e83c bfd: Define ___lc_codepage_func prototype for older MinGW-w64
In commit 68e80d96a8, the usage of
___lc_codepage_func was introduced to determine the current encoding.

Prior to version 9.0 of MinGW-w64, the function prototype for
___lc_codepage_func was missing and trying to build BFD caused the
following error:

error: implicit declaration of function ‘___lc_codepage_func’

This changeset adds a conditonal definition of
___lc_codepage_func to allow a sucessful build with MinGW-w64.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2022-08-16 18:04:21 +01:00
Alan Modra
45d92439ae PR29495, rewrite_elf_program_header looping
This patch, in order of significance:
1) Replaces some macros with inline functions.
2) Those inline functions catch and avoid arithmetic overflows when
   comparing addresses.
3) When assigning sections to segments (IS_SECTION_IN_INPUT_SEGMENT)
   use bed->want_p_paddr_set_to_zero to decide whether lma vs p_paddr
   or vma vs p_vaddr should be tested.  When remapping, use the same
   test, and use is_note rather than the more restrictive
   IS_COREFILE_NOTE.

It's important that the later tests not be more restrictive.  If they
are it can lead to the situation triggered by the testcases, where a
section seemingly didn't fit and thus needed a new mapping.  It didn't
fit the new mapping either, and this repeated until memory exhausted.

	PR 29495
	* elf.c (SEGMENT_END, SECTION_SIZE, IS_CONTAINED_BY_VMA): Delete.
	(IS_CONTAINED_BY_LMA, IS_NOTE, IS_COREFILE_NOTE): Delete.
	(segment_size, segment_end, section_size): New inline function.
	(is_contained_by, is_note): Likewise.
	(rewrite_elf_program_header): Use new functions.
2022-08-16 18:19:34 +09:30
GDB Administrator
246cb4b5a1 Automatic date update in version.in 2022-08-16 00:00:08 +00:00
Alan Modra
a9c09a3667 aarch64_pei_vec
I know this target is just a skeleton, but let's not write out relocs
with uninitialised garbage.

	* coff-aarch64.c (SWAP_IN_RELOC_OFFSET): Define.
	(SWAP_OUT_RELOC_OFFSET): Define.
2022-08-15 10:19:57 +09:30
GDB Administrator
7cc124ae97 Automatic date update in version.in 2022-08-15 00:00:07 +00:00
GDB Administrator
8ad969a3fe Automatic date update in version.in 2022-08-14 00:00:07 +00:00
Alan Modra
ef186fe54a PR29482 - strip: heap-buffer-overflow
PR 29482
	* coffcode.h (coff_set_section_contents): Sanity check _LIB.
2022-08-13 15:32:47 +09:30
Alan Modra
8007515072 asan: NULL dereference in spu_elf_object_p
* elf32-spu.c (spu_elf_object_p): Don't dereference NULL
	shdr->bfd_section.
2022-08-13 14:11:27 +09:30
Alan Modra
9effb9f15f ubsan: undefined shift in sign_extend
* libhppa.h (sign_extend): Avoid undefined behaviour.
2022-08-13 14:11:27 +09:30
Alan Modra
8c68d88cc4 asan: NULL dereference in som_set_reloc_info
* som.c (som_set_reloc_info): Ignore non-existent previous
	fixup references.
2022-08-13 14:11:27 +09:30
GDB Administrator
901dd67d0d Automatic date update in version.in 2022-08-13 00:00:06 +00:00
GDB Administrator
6f419c9825 Automatic date update in version.in 2022-08-12 00:00:14 +00:00
Fangrui Song
453595283c RISC-V: Remove R_RISCV_GNU_VTINHERIT/R_RISCV_GNU_VTENTRY
They were legacy relocation types copied from other ports.  The related
-fvtable-gc was removed from GCC in 2003.

The associated assembler directives (.vtable_inherit and .vtable_entry)
have never been supported by the RISC-V port.  Remove related ld code.

Link: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/323
2022-08-10 22:01:41 -07:00
Alan Modra
5291ecf972 regen potfiles 2022-08-11 10:50:50 +09:30
GDB Administrator
7030e40b76 Automatic date update in version.in 2022-08-11 00:00:07 +00:00
Youling Tang
31f6009538 bfd: Add support for LoongArch64 EFI (efi-*-loongarch64).
This adds support for efi-loongarch64 by virtue of adding a new PEI target
pei-loongarch64.  This is not a full target and only exists to support EFI at
this time.

This means that this target does not support relocation processing and is mostly
a container format.  This format has been added to elf based loongarch64 targets
such that efi images can be made natively on Linux.

However this target is not valid for use with gas but only with objcopy.

We should't limit addresses to 32-bits for 64-bit vma, otherwise there will be
"RVA truncated" error when using objcopy on loongarch64.

With these changes the resulting file is recognized as an efi image.

Any magic number is based on the Microsoft PE specification [1].

The test results are as follows:
$ make check-binutils RUNTESTFLAGS='loongarch64.exp'
  PASS: Check if efi app format is recognized

$ objdump -h -f tmpdir/loongarch64copy.o
  tmpdir/loongarch64copy.o:     file format pei-loongarch64
  architecture: Loongarch64, flags 0x00000132:
  EXEC_P, HAS_SYMS, HAS_LOCALS, D_PAGED
  start address 0x0000000000000000

  Sections:
  Idx Name          Size      VMA               LMA               File off  Algn
    0 .text         0000003c  00000000200000b0  00000000200000b0  00000200  2**2
                    CONTENTS, ALLOC, LOAD, READONLY, CODE

[1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format

bfd:
  * .gitignore (pe-loongarch64igen.c): New.
  * Makefile.am (pei-loongarch64.lo, pe-loongarch64igen.lo, pei-loongarch64.c,
  pe-loongarch64igen.c): Add support.
  * Makefile.in: Likewise.
  * bfd.c (bfd_get_sign_extend_vma): Add pei-loongarch64.
  * coff-loongarch64.c: New file.
  * coffcode.h (coff_set_arch_mach_hook, coff_set_flags,
  coff_write_object_contents) Add loongarch64 (loongarch64_pei_vec) support.
  * config.bfd: Likewise.
  * configure: Likewise.
  * configure.ac: Likewise.
  * libpei.h (GET_OPTHDR_IMAGE_BASE, PUT_OPTHDR_IMAGE_BASE,
  GET_OPTHDR_SIZE_OF_STACK_RESERVE, PUT_OPTHDR_SIZE_OF_STACK_RESERVE,
  GET_OPTHDR_SIZE_OF_STACK_COMMIT, PUT_OPTHDR_SIZE_OF_STACK_COMMIT,
  GET_OPTHDR_SIZE_OF_HEAP_RESERVE, PUT_OPTHDR_SIZE_OF_HEAP_RESERVE,
  GET_OPTHDR_SIZE_OF_HEAP_COMMIT, PUT_OPTHDR_SIZE_OF_HEAP_COMMIT,
  GET_PDATA_ENTRY, _bfd_peLoongArch64_bfd_copy_private_bfd_data_common,
  _bfd_peLoongArch64_bfd_copy_private_section_data,
  _bfd_peLoongArch64_get_symbol_info, _bfd_peLoongArch64_only_swap_filehdr_out,
  _bfd_peLoongArch64_print_private_bfd_data_common,
  _bfd_peLoongArch64i_final_link_postscript,
  _bfd_peLoongArch64i_only_swap_filehdr_out, _bfd_peLoongArch64i_swap_aouthdr_in,
  _bfd_peLoongArch64i_swap_aouthdr_out, _bfd_peLoongArch64i_swap_aux_in,
  _bfd_peLoongArch64i_swap_aux_out, _bfd_peLoongArch64i_swap_lineno_in,
  _bfd_peLoongArch64i_swap_lineno_out, _bfd_peLoongArch64i_swap_scnhdr_out,
  _bfd_peLoongArch64i_swap_sym_in, _bfd_peLoongArch64i_swap_sym_out,
  _bfd_peLoongArch64i_swap_debugdir_in, _bfd_peLoongArch64i_swap_debugdir_out,
  _bfd_peLoongArch64i_write_codeview_record,
  _bfd_peLoongArch64i_slurp_codeview_record,
  _bfd_peLoongArch64_print_ce_compressed_pdata): New.
  * peXXigen.c (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out,
  _bfd_XXi_swap_scnhdr_out, pe_print_pdata, _bfd_XX_print_private_bfd_data_common,
  _bfd_XX_bfd_copy_private_section_data, _bfd_XXi_final_link_postscript):
  Support COFF_WITH_peLoongArch64,
  * pei-loongarch64.c: New file.
  * peicode.h (coff_swap_scnhdr_in, pe_ILF_build_a_bfd, pe_ILF_object_p):
  Support COFF_WITH_peLoongArch64.
  (jtab): Add dummy entry that traps.
  * targets.c (loongarch64_pei_vec): New.

binutils
  * testsuite/binutils-all/loongarch64/loongarch64.exp: New file.
  * testsuite/binutils-all/loongarch64/pei-loongarch64.d: New test.
  * testsuite/binutils-all/loongarch64/pei-loongarch64.s: New test.

include
  * coff/loongarch64.h: New file.
  * coff/pe.h (IMAGE_FILE_MACHINE_LOONGARCH64): New.

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
2022-08-10 09:26:25 +08:00
GDB Administrator
4c3cb23cc0 Automatic date update in version.in 2022-08-10 00:00:10 +00:00
GDB Administrator
ded48050c1 Automatic date update in version.in 2022-08-09 00:00:07 +00:00
Martin Liska
e441b55e94 add splay tree for info_ptr -> CU mapping
While using perf top for MozillaThunderbird I noticed quite some slow
dissably call with source code involved. E.g.

time ./objdump --start-address=0x0000000004e0dcd0 --stop-address=0x0000000004e0df8b -l -d --no-show-raw-insn -S -C /usr/lib64/thunderbird/libxul.so

took 2.071s and I noticed quite some time is spent in
find_abstract_instance:

    33.46%  objdump  objdump               [.] find_abstract_instance
    18.22%  objdump  objdump               [.] arange_add
    13.77%  objdump  objdump               [.] read_attribute_value
     4.82%  objdump  objdump               [.] comp_unit_maybe_decode_line_info
     3.10%  objdump  libc.so.6             [.] __memset_avx2_unaligned_erms

where linked list of CU is iterated when searing for where info_ptr
belongs to:

         : 3452   for (u = unit->prev_unit; u != NULL; u = u->prev_unit)
    0.00 :   4c61f7: mov    0x10(%rbx),%rax
    0.00 :   4c61fb: test   %rax,%rax
    0.00 :   4c61fe: je     4c6215 <find_abstract_instance+0x365>
         : 3453   if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr)
    0.00 :   4c6200: cmp    0x60(%rax),%rdx
   83.20 :   4c6204: jb     4c620c <find_abstract_instance+0x35c>
    0.00 :   4c6206: cmp    0x78(%rax),%rdx
    6.89 :   4c620a: jb     4c6270 <find_abstract_instance+0x3c0>
         : 3452   for (u = unit->prev_unit; u != NULL; u = u->prev_unit)
    0.00 :   4c620c: mov    0x10(%rax),%rax
    7.90 :   4c6210: test   %rax,%rax
    0.00 :   4c6213: jne    4c6200 <find_abstract_instance+0x350>

The following scan can be replaced with search in a splay tree and with
that I can get to 1.5s and there are other symbols where the difference
is even bigger.

bfd/ChangeLog:

	PR 29081
	* dwarf2.c (struct addr_range): New.
	(addr_range_intersects): Likewise.
	(splay_tree_compare_addr_range): Likewise.
	(splay_tree_free_addr_range): Likewise.
	(struct dwarf2_debug_file): Add comp_unit_tree.
	(find_abstract_instance): Use the splay tree when searching
	for a info_ptr.
	(stash_comp_unit): Insert to the splay tree.
	(_bfd_dwarf2_cleanup_debug_info): Clean up the splay tree.
2022-08-08 13:51:14 +02:00
Martin Liska
06ce017c7d dwarf: use find_abstract_instance for vars and DW_AT_specification
The following simple test case fails when dwz is used:

$ cat demo.C
namespace std {
  enum { _S_fixed, _S_floatfield = _S_fixed };
  struct {
    struct {};
  }
  __ioinit;
}

int main() {
  return 0;
}

$ g++ demo.C -g && cp a.out b.out && dwz -m xxx.so a.out b.out && objdump -S a.out >/dev/null
objdump: DWARF error: could not find variable specification at offset 0x3d3

As seen the reference is defined in xxx.so shared part:

$ eu-readelf -w -N a.out | grep -A3 -B3 3d3
             decl_column          (data1) 11
             sibling              (ref_udata) [   387]
 [   387]    variable             abbrev: 30
             specification        (GNU_ref_alt) [   3d3]
             location             (exprloc)
              [ 0] addr 0x404019
 [   396]    subprogram           abbrev: 32

$ eu-readelf -w -N a.out | less

...

 Compilation unit at offset 920:
 Version: 5, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 Unit type: partial (3)
...
 [   3d3]      variable             abbrev: 31
               name                 (strp) "__ioinit"
               decl_file            (data1) demo.C (10)
               decl_line            (data1) 6
               decl_column          (data1) 3
               type                 (ref_udata) [   3c4]
               declaration          (flag_present) yes

With the patch the same output is emitted as before usage of dwz.

bfd/ChangeLog:

	PR 29442
	* dwarf2.c (struct varinfo): Use const char * type.
	(scan_unit_for_symbols): Call find_abstract_instance for
	DW_AT_specification for variables that can be in a different CU
	(e.g. done by dwz)
2022-08-08 13:51:10 +02:00
GDB Administrator
dd27fd47f1 Automatic date update in version.in 2022-08-08 00:00:10 +00:00
GDB Administrator
3ba7b1551b Automatic date update in version.in 2022-08-07 00:00:08 +00:00
Alan Modra
45c8663b92 asan: heap buffer overflow in _bfd_error_handler
On coff_slurp_symbol_table printing "unrecognized storage class"
for a symbol error.  If the symbol name is the last string in its
section and not terminated, we run off the end of the buffer.

	* coffgen.c (build_debug_section): Terminate the section with
	an extra 0.
2022-08-06 19:59:02 +09:30
Alan Modra
431d48ef28 asan: segfault in coff_write_auxent_fname
More fuzzed input file nonsense.

	* coffgen.c (coff_write_symbol): Don't call coff_write_auxent_fname
	when extrap is NULL.
2022-08-06 18:43:24 +09:30
Alan Modra
f7a559d5e1 msan: bfd_mach_o_layout_commands use of uninitialised value
Catches fuzzed input with unterminated strings that later run off the
end of their buffers when calling strlen.

	* mach-o.c: Use size_t vars where approprite.
	(bfd_mach_o_alloc_and_read): Add "extra" param.  Allocate that
	much extra and clear.  Update all callers, those that set up
	strings with one extra byte.
2022-08-06 18:43:24 +09:30
Alan Modra
578a7392c3 objcopy section alignment
bfd_set_section_alignment currently always returns true.  This patch
changes it to return false on silly alignment values, avoiding yet
another way to trigger ubsan errors like coffcode.h:3192:12: runtime
error: shift exponent 299 is too large for 32-bit type 'int'.  We'll
catch that one in objcopy.c:setup_sections.  However, setup_sections
gives up on other setup operations that are necessary even after an
error of some sort.  Change that to keep going, which might change the
error message but that shouldn't matter in the least.

bfd/
	* section.c (bfd_set_section_alignment): Return false and
	don't set alignment_power for stupidly large alignments.
	* bfd-in2.h: Regenerate.
	* coffcode.h (coff_compute_section_file_positions): Don't use
	an int constant when calculating alignment.
binutils/
	* objcopy.c (setup_section): Keep on going after hitting
	non-fatal errors.
2022-08-06 18:43:24 +09:30
Alan Modra
77b38f6db9 ubsan: som.c undefined shift in som_set_reloc_info
Do the shift using unsigned variables to avoid UB on << 8.

	* som.c (som_set_reloc_info): Make v unsigned.  Localise some
	variables to their blocks.
2022-08-06 18:43:04 +09:30
GDB Administrator
9663a947c0 Automatic date update in version.in 2022-08-06 00:00:09 +00:00
Alan Modra
4900c4e60c Get rid of BFD_VMA_FMT
Remove the BFD_VMA_FMT defines in bfd.h and configure support.

	* bfd-in.h (BFD_VMA_FMT): Don't define.
	* configure.ac (BFD_INT64_FMT): Remove configure test.
	* configure.com: Likewise.
	* Makefile.in: Regenerate.
	* bfd-in2.h: Regenerate.
	* configure: Regenerate.
2022-08-06 08:08:32 +09:30
Alan Modra
37c59664ad asan: ppc64_elf_get_synthetic_symtab heap buffer overflow
Fuzzed input files with sizes of .dynamic not a multiple of dynamic
tag size can result in reading past the end of the buffer with the
current simple checks.  Fix that, and use the same check in other
files that process input object .dynamic section.  (There is no need
for buffer overflow checks in the linker's generated .dynamic
section.)

	* elf32-ppc.c (ppc_elf_get_synthetic_symtab): Sanity check
	.dynamic content buffer reads.
	* elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Likewise.
	* elf64-ia64-vms.c (elf64_vms_link_add_object_symbols): Likewise.
	* elf.c (_bfd_elf_print_private_bfd_data): Simplify .dynamic
	buffer sanity checks.
	* elflink.c (elf_link_add_object_symbols): Avoid possible UB
	subtracting sizeof_dyn from pointer.
2022-08-05 20:48:29 +09:30
GDB Administrator
62b73b6580 Automatic date update in version.in 2022-08-05 00:00:16 +00:00
Alan Modra
b82817674f Don't use BFD_VMA_FMT in binutils
BFD_VMA_FMT can't be used in format strings that need to be
translated, because the translation won't work when the type of
bfd_vma differs from the machine used to compile .pot files.  We've
known about this for a long time, but patches slip through review.

So just get rid of BFD_VMA_FMT, instead using the appropriate PRId64,
PRIu64, PRIx64 or PRIo64 and SCN variants for scanf.  The patch is
mostly mechanical, the only thing requiring any thought is casts
needed to preserve PRId64 output from bfd_vma values, or to preserve
one of the unsigned output formats from bfd_signed_vma values.
2022-08-04 12:22:39 +09:30
Alan Modra
94e27e8e69 MIPS: Use R_MIPS_REL16 for BFD_RELOC_16
R_MIPS_REL16 isn't a pc-relative reloc as the name might indicate.

	* elf64-mips.c (mips_reloc_map): Map BFD_RELOC_16 to R_MIPS_REL16.
	* elfn32-mips.c (mips_reloc_map): Likewise.
2022-08-04 11:42:33 +09:30
GDB Administrator
fcbfb25dcc Automatic date update in version.in 2022-08-04 00:00:08 +00:00
H.J. Lu
59f214544c elf: Reset alignment for each PT_LOAD segment
Reset alignment for each PT_LOAD segment to avoid using alignment from
the previous PT_LOAD segment.

bfd/

	PR ld/29435
	* elf.c (assign_file_positions_for_load_sections): Reset
	alignment for each PT_LOAD segment.

ld/

	PR ld/29435
	* testsuite/ld-elf/pr29435.d: New file.
	* testsuite/ld-elf/pr29435.s: Likewise.
2022-08-03 13:34:01 -07:00
Alan Modra
a6ad791442 Fix a conflict between the linker's need to rename some PE format input libraries and the BFD library's file caching mechanism.
PR 29389
bfd	* bfd.c (BFD_CLOSED_BY_CACHE): New bfd flag.
	* cache.c (bfd_cache_delete): Set BFD_CLOSED_BY_DELETE on the
	closed bfd.
	(bfd_cache_lookup_worker): Clear BFD_CLOSED_BY_DELETE on the newly
	reopened bfd.
	* opncls.c (bfd_set_filename): Refuse to change the name of a bfd
	that has been closed by bfd_cache_delete.  Mark changed bfds as
	uncacheable.
	* bfd-in2.h: Regenerate.

ld	* ldlang.h (lang_input_statement_struct): Add sort_key field.
	* emultempl/pe.em (after_open): If multiple import libraries refer
	to the same bfd, store their names in the sort_key field.
	* emultempl/pep.em (after_open): Likewise.
	* ldlang.c (sort_filename): New function.  Returns the filename to
	be used when sorting input files.
	(wild_sort): Use the sort_filename function.
2022-08-03 13:31:57 +01:00
Alan Modra
ecfc6ddb80 Re: PE objdump -x
All of these buffer overrun tests are better written as a comparison
against size remaining, due to ISO C 9899 standard 6.5.2 para 8
regarding adding a constant to a pointer:

"If both the pointer operand and the result point to elements of the
same array object, or one past the last element of the array object,
the evaluation shall not produce an overflow; otherwise, the behavior
is undefined."

So "ex_dta + 4" might be undefined behaviour, if you interpret "the
array object" in this case to be the malloc'd section contents!

	* pei-x86_64.c (pex64_get_unwind_info): Tidy sanity checks.
	(pex64_xdata_print_uwd_codes): Likewise.
2022-08-03 17:00:17 +09:30
GDB Administrator
8aaafe957c Automatic date update in version.in 2022-08-03 00:00:07 +00:00
Jan Beulich
2ba2f09618 ELF: emit symbol table when there are relocations
Even when there are no symbols (e.g. all relocations being against
absolute values), a symbol table (with just the first placeholder entry)
needs to be emitted. Otherwise tools like objdump won't properly process
the relocations. The respective checks in assign_section_numbers() and
_bfd_elf_compute_section_file_positions() support also this view. Oddly
enough so far HAS_RELOC was only set when reading in an object file, but
not when generating one anew; the flag would only have been cleared when
no relocations were found (anymore).

While there also amend the affected function's leading comment to also
mention gas.
2022-08-02 15:43:26 +02:00
Matthew Malcomson
976f16630b ld: aarch64: Adjust TLS relaxation condition
In aarch64_tls_transition_without_check and elfNN_aarch64_tls_relax we
choose whether to perform a relaxation to an IE access model or an LE
access model based on whether the symbol itself is marked as local (i.e.
`h == NULL`).

This is problematic in two ways.  The first is that sometimes a global
dynamic access can be relaxed to an initial exec access when creating a
shared library, and if that happens on a local symbol then we currently
relax it to a local exec access instead.  This usually does not happen
since we only relax an access if aarch64_can_relax_tls returns true and
aarch64_can_relax_tls does not have the same problem.  However, it can
happen when we have seen both an IE and GD access on the same symbol.
This case is exercised in the newly added testcase tls-relax-gd-ie-2.

The second problem is that deciding based on whether the symbol is local
misses the case when the symbol is global but is still non-interposable
and known to be located in the executable.  This happens on all global
symbols in executables.
This case is exercised in the newly added testcase tls-relax-ie-le-4.

Here we adjust the condition we base our relaxation on so that we relax
to local-exec if we are creating an executable and the relevant symbol
we're accessing is stored inside that executable.

-- Updating tests for new relaxation criteria

Many of the tests added to check our relaxation to IE were implemented
by taking advantage of the fact that we did not relax a global symbol
defined in an executable.

Since a global symbol defined in an executable is still not
interposable, we know that a TLS version of such a symbol will be in the
main TLS block.  This means that we can perform a stronger relaxation on
such symbols and relax their accesses to a local-exec access.

Hence we have to update all tests that relied on the older suboptimal
decision making.

The two cases when we still would want to relax a general dynamic access
to an initial exec one are:
1) When in a shared library and accessing a symbol which we have already
   seen accessed with an initial exec access sequence.
2) When in an executable and accessing a symbol defined in a shared
   library.

Both of these require shared library support, which means that these
tests are now only available on targets with that.

I have chosen to switch the existing testcases from a plain executable
to one dynamically linked to a shared object as that doesn't require
changing the testcases quite so much (just requires accessing a
different variable rather than requiring adding another code sequence).

The tls-relax-all testcase was an outlier to the above approach, since
it included a general dynamic access to both a local and global symbol
and inspected for the difference accordingly.
2022-08-02 12:10:01 +01:00
Alan Modra
217cbb0055 PE objdump -x
objdump -x on PE executables produces lots of "xdata section corrupt"
and "corrupt unwind data" warnings, and refuses to dump that info.  It
turns out that the sanity checks were bad, not the data.  Fix them.

	* pei-x86_64.c (pex64_get_unwind_info): Correct buffer overrun
	sanity checks.
	(pex64_xdata_print_uwd_codes): Similarly.
2022-08-02 17:01:56 +09:30
GDB Administrator
c1165f1bcf Automatic date update in version.in 2022-08-02 00:00:08 +00:00
Alan Modra
f493c2174e Get rid of fprintf_vma and sprintf_vma
These two macros print either a 16 digit hex number or an 8 digit
hex number.  Unfortunately they depend on both target and host, which
means that the output for 32-bit targets may be either 8 or 16 hex
digits.

Replace them in most cases with code that prints a bfd_vma using
PRIx64.  In some cases, deliberately lose the leading zeros.
This change some output, notably in base/offset fields of m68k
disassembly which I think looks better that way, and in error
messages.  I've kept leading zeros in symbol dumps (objdump -t)
and in PE header dumps.

bfd/
	* bfd-in.h (fprintf_vma, sprintf_vma, printf_vma): Delete.
	* bfd-in2.h: Regenerate.
	* bfd.c (bfd_sprintf_vma): Don't use sprintf_vma.
	(bfd_fprintf_vma): Don't use fprintf_vma.
	* coff-rs6000.c (xcoff_reloc_type_tls): Don't use sprintf_vma.
	Instead use PRIx64 to print bfd_vma values.
	(xcoff_ppc_relocate_section): Likewise.
	* cofflink.c (_bfd_coff_write_global_sym): Likewise.
	* mmo.c (mmo_write_symbols_and_terminator): Likewise.
	* srec.c (srec_write_symbols): Likewise.
	* elf32-xtensa.c (print_r_reloc): Similarly for fprintf_vma.
	* pei-x86_64.c (pex64_dump_xdata): Likewise.
	(pex64_bfd_print_pdata_section): Likewise.
	* som.c (som_print_symbol): Likewise.
	* ecoff.c (_bfd_ecoff_print_symbol): Use bfd_fprintf_vma.
opcodes/
	* dis-buf.c (perror_memory, generic_print_address): Don't use
	sprintf_vma.  Instead use PRIx64 to print bfd_vma values.
	* i386-dis.c (print_operand_value, print_displacement): Likewise.
	* m68k-dis.c (print_base, print_indexed): Likewise.
	* ns32k-dis.c (print_insn_arg): Likewise.
	* ia64-gen.c (_opcode_int64_low, _opcode_int64_high): Delete.
	(opcode_fprintf_vma): Delete.
	(print_main_table): Use PRIx64 to print opcode.
binutils/
	* od-macho.c: Replace all uses of printf_vma with bfd_printf_vma.
	* objcopy.c (copy_object): Don't use sprintf_vma.  Instead use
	PRIx64 to print bfd_vma values.
	(copy_main): Likewise.
	* readelf.c (CHECK_ENTSIZE_VALUES): Likewise.
	(dynamic_section_mips_val): Likewise.
	(print_vma): Don't use printf_vma.  Instead use PRIx64 to print
	bfd_vma values.
	(dump_ia64_vms_dynamic_fixups): Likewise.
	(process_version_sections): Likewise.
	* rddbg.c (stab_context): Likewise.
gas/
	* config/tc-i386.c (offset_in_range): Don't use sprintf_vma.
	Instead use PRIx64 to print bfd_vma values.
	(md_assemble): Likewise.
	* config/tc-mips.c (load_register, macro): Likewise.
	* messages.c (as_internal_value_out_of_range): Likewise.
	* read.c (emit_expr_with_reloc): Likewise.
	* config/tc-ia64.c (note_register_values): Don't use fprintf_vma.
	Instead use PRIx64 to print bfd_vma values.
	(print_dependency): Likewise.
	* listing.c (list_symbol_table): Use bfd_sprintf_vma.
	* symbols.c (print_symbol_value_1): Use %p to print pointers.
	(print_binary): Likewise.
	(print_expr_1): Use PRIx64 to print bfd_vma values.
	* write.c (print_fixup): Use %p to print pointers.  Don't use
	fprintf_vma.
	* testsuite/gas/all/overflow.l: Update expected output.
	* testsuite/gas/m68k/mcf-mov3q.d: Likewise.
	* testsuite/gas/m68k/operands.d: Likewise.
	* testsuite/gas/s12z/truncated.d: Likewise.
ld/
	* deffilep.y (def_file_print): Don't use fprintf_vma.  Instead
	use PRIx64 to print bfd_vma values.
	* emultempl/armelf.em (gld${EMULATION_NAME}_finish): Don't use
	sprintf_vma.  Instead use PRIx64 to print bfd_vma values.
	* emultempl/pe.em (gld${EMULATION_NAME}_finish): Likewise.
	* ldlang.c (lang_map): Use %V to print region origin.
	(lang_one_common): Don't use sprintf_vma.
	* ldmisc.c (vfinfo): Don't use fprintf_vma or sprintf_vma.
	* pe-dll.c (pe_dll_generate_def_file): Likewise.
gdb/
	* remote.c (remote_target::trace_set_readonly_regions): Replace
	uses of sprintf_vma with bfd_sprintf_vma.
2022-08-01 13:52:18 +09:30
liuzhensong
48ca1b26b9 LoongArch: Set defaults to exec stack 0. 2022-08-01 09:05:00 +08:00
Alan Modra
1a5178fe28 PR29348, BFD_VMA_FMT wrong
There is a problem with my commit 0e3c1eebb2, which replaced
bfd_uint64_t with uint64_t: Some hosts typedef int64_t to long long
even when long is the same size as long long.  That confuses the code
choosing one of "l", "ll", or "I64" for BFD_VMA_FMT, and results in
warnings.

Write a direct configure test for the printf int64_t style instead.
This removes the last use of BFD_HOST_64BIT_LONG, so delete that.
Note that the changes to configure.com are pure guesswork.

	PR 29348
	* bfd-in.h (BFD_HOST_64BIT_LONG): Don't define.
	(BFD_VMA_FMT): Define using BFD_INT64_FMT when 64-bit.
	(bfd_vma, bfd_signed_vma): Move comments to 64-bit typedefs.
	* configure.ac (BFD_HOST_64BIT_LONG): Delete.
	(BFD_INT64_FMT): New config test.
	* configure.com: Update similarly.
	* Makefile.in: Regenerate.
	* bfd-in2.h: Regenerate.
	* configure: Regenerate.
2022-08-01 09:30:33 +09:30
GDB Administrator
df0e73ff93 Automatic date update in version.in 2022-08-01 00:00:06 +00:00
GDB Administrator
55ea1654ab Automatic date update in version.in 2022-07-31 00:00:07 +00:00
GDB Administrator
017772c826 Automatic date update in version.in 2022-07-30 00:00:08 +00:00
Alan Modra
10948fb9fd Re: PR16005, avr linker crash on a particular instruction sequence with --relax
The last patch wasn't so clever.  The contents in fact have already
been read, just not cached where relax_delete_bytes expects them.
relax_delete_bytes also modifies relocs and syms, so they should be
cached too.

	PR 16005
	* elf32-avr.c (elf32_avr_relax_delete_bytes): Revert last change.
	(elf32_avr_relax_section): Cache contents, relocs and syms
	before calling relax_delete_bytes.
2022-07-29 23:28:04 +09:30
Nick Clifton
b44cfc5de1 Stop the linker from complaining about unrecognised DW_FORM-rnglistx and DW_FORM_loclistx format attributes.
PR 29424
	* dwarf2.c (read_attribute_value): Handle DW_FORM_rnglistx and
	DW_FORM_loclistx.
2022-07-29 12:58:10 +01:00
Alan Modra
b875e9c93d PR16005, avr linker crash on a particular instruction sequence with --relax
It's possible for relax_delete_bytes to be called with section
contents NULL, as demonstrated by the testcase in this PR.

	PR 16005
	* elf32-avr.c (elf32_avr_relax_delete_bytes): Get section contents
	if not already available.
2022-07-29 17:25:35 +09:30
GDB Administrator
d17823bfd3 Automatic date update in version.in 2022-07-29 00:00:12 +00:00
GDB Administrator
2eb132bdfb Automatic date update in version.in 2022-07-28 00:00:06 +00:00
GDB Administrator
3c0c7b4e1a Automatic date update in version.in 2022-07-27 00:00:06 +00:00
Nick Clifton
e8f4567b9c Updated translations for various sub-directories 2022-07-26 13:06:29 +01:00
Nick Clifton
27121f6740 Fix indentation in loongarch code, preventing a compile time warning. 2022-07-26 11:33:51 +01:00
GDB Administrator
8e883b5e11 Automatic date update in version.in 2022-07-26 00:00:07 +00:00
liuzhensong
9801120721 bfd: Delete R_LARCH_NONE from dyn info of LoongArch.
Some R_LARCH_64 in section .eh_frame will to generate
  R_LARCH_NONE, we change relocation to R_LARCH_32_PCREL
  from R_LARCH_64 in setction .eh_frame and not generate
  dynamic relocation for R_LARCH_32_PCREL.

  Add New relocate type R_LARCH_32_PCREL for .eh_frame.

  include/elf/
    loongarch.h

  bfd/
    bfd/bfd-in2.h
    libbfd.h
    reloc.c
    elfxx-loongarch.c
    elfnn-loongarch.c

  gas/config/
    tc-loongarch.c

  binutils/
    readelf.c

  ld/testsuite/ld-elf/
    eh5.d
2022-07-25 09:59:08 +08:00
liuzhensong
bc2a35c0b4 LoongArch: Move ifunc info to rela.dyn from rela.plt.
Delete R_LARCH_IRELATIVE from dynamic loader (glibc ld.so) when
  loading lazy function (rela.plt section).

  In dynamic programes, move ifunc dynamic relocate info to section
  srelgot from srelplt.

  bfd/
    elfnn-loongarch.c
2022-07-25 09:59:08 +08:00
liuzhensong
6d13722a97 bfd: Add supported for LoongArch new relocations.
Define new reloc types according to linker needs.

  include/elf/
    loongarch.h

  bfd/
    bfd-in2.h
    libbfd.h
    reloc.c
    elfnn-loongarch.c
    elfxx-loongarch.c
    elfxx-loongarch.h
2022-07-25 09:59:08 +08:00
GDB Administrator
5d8af25542 Automatic date update in version.in 2022-07-25 00:00:06 +00:00
GDB Administrator
561e83f7c5 Automatic date update in version.in 2022-07-24 00:00:20 +00:00
GDB Administrator
4c70437ddc Automatic date update in version.in 2022-07-23 00:00:28 +00:00
GDB Administrator
13391ff8bc Automatic date update in version.in 2022-07-22 00:00:19 +00:00
H.J. Lu
8f29211c3f i386: Don't allow GOTOFF relocation against IFUNC symbol for PIC
We can't use the PLT entry as the function address for PIC since the PIC
register may not be set up properly for indirect call.

bfd/

	PR ld/27998
	* elf32-i386.c (elf_i386_relocate_section): Don't allow GOTOFF
	relocation against IFUNC symbol for PIC.

ld/

	PR ld/27998
	* testsuite/ld-i386/pr27998a.d: Replace -shared with -e bar.
	* testsuite/ld-i386/pr27998b.d: Expect a linker error.
	* testsuite/ld-ifunc/ifunc-2-i386-now.d: Updated.
	* testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-i386.s: Replace @GOTOFF with @GOT.
	* testsuite/ld-ifunc/ifunc-2-local-i386.s: Likewise.
2022-07-21 11:40:27 -07:00
Alan Modra
590207aa6e PowerPC64: fix build error on 32-bit hosts
elf64-ppc.c:11673:33: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘bfd_vma’ {aka ‘long long unsigned int’} [-Werror=format=]
11673 |   fprintf (stderr, "offset = %#lx:", stub_entry->stub_offset);
      |                              ~~~^    ~~~~~~~~~~~~~~~~~~~~~~~
      |                                 |              |
      |                                 |              bfd_vma {aka long long unsigned int}
      |                                 long unsigned int
      |                              %#llx

	* elf64-ppc.c (dump_stub): Use BFD_VMA_FMT.
2022-07-21 13:35:51 +09:30
GDB Administrator
2637e8bb1a Automatic date update in version.in 2022-07-21 00:00:20 +00:00
GDB Administrator
73d9afb778 Automatic date update in version.in 2022-07-20 00:00:20 +00:00
H.J. Lu
f638657759 x86: Disallow invalid relocations against protected symbols
Since glibc 2.36 will issue warnings for copy relocation against
protected symbols and non-canonical reference to canonical protected
functions, change the linker to always disallow such relocations.

bfd/

	* elf32-i386.c (elf_i386_scan_relocs): Remove check for
	elf_has_indirect_extern_access.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
	(elf_x86_64_relocate_section): Remove check for
	elf_has_no_copy_on_protected.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Check for building
	executable instead of elf_has_no_copy_on_protected.
	(_bfd_x86_elf_adjust_dynamic_symbol): Disallow copy relocation
	against non-copyable protected symbol.
	* elfxx-x86.h (SYMBOL_NO_COPYRELOC): Remove check for
	elf_has_no_copy_on_protected.

ld/

	* testsuite/ld-i386/i386.exp: Expect linker error for PR ld/17709
	test.
	* testsuite/ld-i386/pr17709.rd: Removed.
	* testsuite/ld-i386/pr17709.err: New file.
	* testsuite/ld-x86-64/pr17709.rd: Removed.
	* testsuite/ld-x86-64/pr17709.err: New file.
	* testsuite/ld-x86-64/pr28875-func.err: Updated.
	* testsuite/ld-x86-64/x86-64.exp: Expect linker error for PR
	ld/17709 test.  Add tests for function pointer against protected
	function.
2022-07-19 08:41:52 -07:00
Fangrui Song
d19a265487 x86: Make protected symbols local for -shared
Call _bfd_elf_symbol_refs_local_p with local_protected==true.  This has
2 noticeable effects for -shared:

* GOT-generating relocations referencing a protected data symbol no
  longer lead to a GLOB_DAT (similar to a hidden symbol).
* Direct access relocations (e.g. R_X86_64_PC32) no longer has the
  confusing diagnostic below.

    __attribute__((visibility("protected"))) void *foo() {
      return (void *)foo;
    }

    // gcc -fpic -shared -fuse-ld=bfd
    relocation R_X86_64_PC32 against protected symbol `foo' can not be used when making a shared object

The new behavior matches arm, aarch64 (commit
83c325007c), and powerpc ports, and other
linkers: gold and ld.lld.

Note: if some code tries to use direct access relocations to take the
address of foo, the pointer equality will break, but the error should be
reported on the executable link, not on the innocent shared object link.
glibc 2.36 will give a warning at relocation resolving time.

With this change, `#define elf_backend_extern_protected_data 1` is no
longer effective.  Just remove it.

Remove the test "Run protected-func-1 without PIE" since -fno-pic
address taken operation in the executable doesn't work with protected
symbol in a shared object by default.  Similarly, remove
protected-data-1a and protected-data-1b.  protected-data-1b can be made
working by removing HAVE_LD_PIE_COPYRELOC from GCC
(https://sourceware.org/pipermail/gcc-patches/2022-June/596678.html).
2022-07-19 08:41:52 -07:00
Luis Machado
d0ff5ca959 [AArch64] Support AArch64 MTE memory tag dumps in core files
The Linux kernel can dump memory tag segments to a core file, one segment
per mapped range. The format and documentation can be found in the Linux
kernel tree [1].

The following patch adjusts bfd and binutils so they can handle this new
segment type and display it accordingly. It also adds code required so GDB
can properly read/dump core file data containing memory tags.

Upon reading, each segment that contains memory tags gets mapped to a
section named "memtag". These sections will be used by GDB to lookup the tag
data. There can be multiple such sections with the same name, and they are not
numbered to simplify GDB's handling and lookup.

There is another patch for GDB that enables both reading
and dumping of memory tag segments.

Tested on aarch64-linux Ubuntu 20.04.

[1] Documentation/arm64/memory-tagging-extension.rst (Core Dump Support)
2022-07-19 15:24:27 +01:00
H.J. Lu
bd0736124c x86: Properly check invalid relocation against protected symbol
Only check invalid relocation against protected symbol defined in shared
object.

bfd/

	PR ld/29377
	* elf32-i386.c (elf_i386_scan_relocs): Only check invalid
	relocation against protected symbol defined in shared object.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.

ld/

	PR ld/29377
	* testsuite/ld-elf/linux-x86.exp: Run PR ld/29377 tests.
	* testsuite/ld-elf/pr29377a.c: New file.
	* testsuite/ld-elf/pr29377b.c: Likewise.
2022-07-18 18:15:39 -07:00
GDB Administrator
b87062aade Automatic date update in version.in 2022-07-19 00:00:25 +00:00
GDB Administrator
38733fdc8c Automatic date update in version.in 2022-07-18 00:00:20 +00:00
GDB Administrator
f39cc214d5 Automatic date update in version.in 2022-07-17 00:00:12 +00:00
GDB Administrator
c3359b8b95 Automatic date update in version.in 2022-07-16 00:00:14 +00:00
GDB Administrator
9afca381e2 Automatic date update in version.in 2022-07-15 00:00:29 +00:00
GDB Administrator
869fa2b36c Automatic date update in version.in 2022-07-14 00:00:20 +00:00
GDB Administrator
dd4c046506 Automatic date update in version.in 2022-07-13 00:00:17 +00:00
Alan Modra
35c5dcc666 PR29355, ld segfaults with -r/-q and custom-named section .rela*
The bug testcase uses an output section named .rel or .rela which has
input .data sections mapped to it.  The input .data section has
relocations.  When counting output relocations SHT_REL and SHT_RELA
section reloc_count is ignored, with the justification that reloc
sections themselves can't have relocations and some backends use
reloc_count in reloc sections.  However, the test wrongly used the
output section type (which normally would match input section type).
Fix that.  Note that it is arguably wrong for ld to leave the output
.rel/.rela section type as SHT_REL/SHT_RELA when non-empty non-reloc
sections are written to it, but I'm not going to change that since it
might be useful to hand-craft relocs in a data section that is then
written to a SHT_REL/SHT_RELA output section.

	PR 29355
	* elflink.c (bfd_elf_final_link): Use input section type rather
	than output section type to determine whether to exclude using
	reloc_count from that section.
2022-07-12 12:05:28 +09:30
GDB Administrator
242f3484db Automatic date update in version.in 2022-07-12 00:00:22 +00:00
GDB Administrator
b265799996 Automatic date update in version.in 2022-07-11 00:00:24 +00:00
GDB Administrator
e5c0531cfe Automatic date update in version.in 2022-07-10 00:00:07 +00:00
GDB Administrator
d2acd4b0c5 Automatic date update in version.in 2022-07-09 00:00:18 +00:00
Nick Clifton
631ec08cb1 Update version to 2.39.50 and regenerate files 2022-07-08 11:19:44 +01:00
Nick Clifton
0bd0932314 Add markers for 2.39 branch 2022-07-08 10:41:07 +01:00
GDB Administrator
97a8d0ab53 Automatic date update in version.in 2022-07-08 00:00:16 +00:00
Tsukasa OI
045f385d9a RISC-V: Added Zfhmin and Zhinxmin.
This commit adds Zfhmin and Zhinxmin extensions (subsets of Zfh and
Zhinx extensions, respectively).  In the process supporting Zfhmin and
Zhinxmin extension, this commit also changes how instructions are
categorized considering Zfhmin, Zhinx and Zhinxmin extensions.

Detailed changes,

* From INSN_CLASS_ZFH to INSN_CLASS_ZFHMIN:

flh, fsh, fmv.x.h and fmv.h.x.

* From INSN_CLASS_ZFH to INSN_CLASS_ZFH_OR_ZHINX:

fmv.h.

* From INSN_CLASS_ZFH_OR_ZHINX to INSN_CLASS_ZFH_OR_ZHINX:

fneg.h, fabs.h, fsgnj.h, fsgnjn.h, fsgnjx.h,
fadd.h, fsub.h, fmul.h, fdiv.h, fsqrt.h, fmin.h, fmax.h,
fmadd.h, fnmadd.h, fmsub.h, fnmsub.h,
fcvt.w.h, fcvt.wu.h, fcvt.h.w, fcvt.h.wu,
fcvt.l.h, fcvt.lu.h, fcvt.h.l, fcvt.h.lu,
feq.h, flt.h, fle.h, fgt.h, fge.h,
fclass.h.

* From INSN_CLASS_ZFH_OR_ZHINX to INSN_CLASS_ZFHMIN_OR_ZHINXMIN:

fcvt.s.h and fcvt.h.s.

* From INSN_CLASS_D_AND_ZFH_INX to INSN_CLASS_ZFHMIN_AND_D:

fcvt.d.h and fcvt.h.d.

* From INSN_CLASS_Q_AND_ZFH_INX to INSN_CLASS_ZFHMIN_AND_Q:

fcvt.q.h and fcvt.h.q.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_implicit_subsets): Change implicit
	subsets.  Zfh->Zicsr is not needed and Zfh->F is replaced with
	Zfh->Zfhmin and Zfhmin->F.  Zhinx->Zicsr is not needed and
	Zhinx->Zfinx is replaced with Zhinx->Zhinxmin and
	Zhinxmin->Zfinx.
	(riscv_supported_std_z_ext): Added zfhmin and zhinxmin.
	(riscv_multi_subset_supports):  Rewrite handling for new
	instruction classes.
	(riscv_multi_subset_supports_ext): Updated.
	(riscv_parse_check_conflicts): Change error message to include
	zfh and zfhmin extensions.

gas/ChangeLog:

	* testsuite/gas/riscv/zfhmin-d-insn-class-fail.s: New complex
	error handling test.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-1.d: Likewise.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-1.l: Likewise.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-2.d: Likewise.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-2.l: Likewise.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-3.d: Likewise.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-3.l: Likewise.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-4.d: Likewise.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-4.l: Likewise.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-5.d: Likewise.
	* testsuite/gas/riscv/zfhmin-d-insn-class-fail-5.l: Likewise.
	* testsuite/gas/riscv/zhinx.d: Renamed from fp-zhinx-insns.d
	and refactored.
	* testsuite/gas/riscv/zhinx.s: Likewise.

include/ChangeLog:

	* opcode/riscv.h (enum riscv_insn_class): Removed INSN_CLASS_ZFH,
	INSN_CLASS_D_AND_ZFH_INX and INSN_CLASS_Q_AND_ZFH_INX.  Added
	INSN_CLASS_ZFHMIN, INSN_CLASS_ZFHMIN_OR_ZHINXMIN,
	INSN_CLASS_ZFHMIN_AND_D and INSN_CLASS_ZFHMIN_AND_Q.

opcodes/ChangeLog:

	* riscv-opc.c (riscv_opcodes): Change instruction classes for
	Zfh and Zfhmin instructions.  Fix `fcvt.h.lu' instruction
	(two operand variant) mask.
2022-07-07 16:23:54 +08:00
Tsukasa OI
37cf60c6a6 RISC-V: Fix requirement handling on Zhinx+{D,Q}
This commit fixes how instructions are masked on Zhinx+Z{d,q}inx.
fcvt.h.d and fcvt.d.h require ((D&&Zfh)||(Zdinx&&Zhinx)) and
fcvt.h.q and fcvt.q.h require ((Q&&Zfh)||(Zqinx&&Zhinx)).

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_multi_subset_supports): Fix feature gate
	on INSN_CLASS_{D,Q}_AND_ZFH_INX.
	(riscv_multi_subset_supports_ext): Fix feature gate diagnostics
	on INSN_CLASS_{D,Q}_AND_ZFH_INX.

gas/ChangeLog:

	* testsuite/gas/riscv/fp-zhinx-insns.d: Add Zqinx to -march
	for proper testing.
2022-07-07 12:05:56 +08:00
GDB Administrator
2025522ac7 Automatic date update in version.in 2022-07-07 00:00:21 +00:00
H.J. Lu
fb5a4a581d elf: Copy p_align of PT_GNU_STACK for stack alignment
commit 74e315dbfe
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Dec 13 19:46:04 2021 -0800

    elf: Set p_align to the minimum page size if possible

may ignore p_align of PT_GNU_STACK when copying ELF program header if
the maximum page size is larger than p_align of PT_LOAD segments.  Copy
p_align of PT_GNU_STACK since p_align of PT_GNU_STACK describes stack
alignment, not page size,

	PR binutils/29319
	* elf.c (copy_elf_program_header): Copy p_align of PT_GNU_STACK
	for stack alignment.
2022-07-06 12:39:06 -07:00
GDB Administrator
8df9766816 Automatic date update in version.in 2022-07-06 00:00:17 +00:00
GDB Administrator
10e52570b8 Automatic date update in version.in 2022-07-05 00:00:18 +00:00
Tsukasa OI
0f2f2e7019 RISC-V: Update Zihintpause extension version
Because ratified Zihintpause extension has a version number of 2.0
(not 1.0), we should update the number.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_supported_std_z_ext): Update version
	number of Zihintpause extension.
2022-07-04 08:45:54 +08:00
GDB Administrator
1e3a4f12e7 Automatic date update in version.in 2022-07-04 00:00:18 +00:00
GDB Administrator
dcc9b683dc Automatic date update in version.in 2022-07-03 00:00:16 +00:00
GDB Administrator
f15f0ddd10 Automatic date update in version.in 2022-07-02 00:00:15 +00:00
GDB Administrator
2899490953 Automatic date update in version.in 2022-07-01 00:00:33 +00:00
GDB Administrator
133791286f Automatic date update in version.in 2022-06-30 00:00:16 +00:00
GDB Administrator
b55819a720 Automatic date update in version.in 2022-06-29 00:00:23 +00:00
Clément Chigot
68e80d96a8 bfd: handle codepage when opening files on MinGW
Even if MS docs say that CP_UTF8 should always be used on newer
applications, forcing it might produce undefined filename if the
encoding isn't UTF-8.
MinGW seems to call ___lc_codepage_func() in order to retrieve the
current thread codepage.

bfd/ChangeLog:

        * bfdio.c (_bfd_real_fopen): Retrieve codepage with
        ___lc_codepage_func() on MinGW.
2022-06-28 16:55:24 +02:00
Alan Modra
f40bb390bb PowerPC64: align plt_branch stubs
plt_branch stubs are similar to plt_call stubs in that they branch
via bctr.  Align them too.

bfd/
	* elf64-ppc.c (ppc_size_one_stub): Align plt_branch stubs as for
	plt_call stubs.
ld/
	* testsuite/ld-powerpc/elfv2exe.d: Adjust for plt_branch changes.
	* testsuite/ld-powerpc/notoc.d: Likewise.
	* testsuite/ld-powerpc/notoc.wf: Likewise.
	* testsuite/ld-powerpc/notoc3.d: Likewise.
	* testsuite/ld-powerpc/pr23937.d: Likewise.
2022-06-28 13:02:26 +09:30
Alan Modra
0f0d9373a3 PowerPC64: plt_stub_pad
* elf64-ppc.c (plt_stub_pad): Simplify parameters and untangle
	from plt_stub_size.
	(ppc_size_one_stub): Call plt_stub_size before plt_stub_pad to
	provide size.  Recalculate size if it might change.
2022-06-28 13:02:26 +09:30
Alan Modra
04cb922ade PowerPC64: Tidy stub type changes
It made sense before I started using separate fields for main type and
sub type to add a difference in main type to the type (thus keeping
sub type unchanged).  Not so much now.

	* elf64-ppc.c (ppc_merge_stub): Simplify stub type change.
	(ppc_size_one_stub): Likewise.
2022-06-28 13:02:26 +09:30
Pekka Seppänen
7c24bdc583 PR29293, elfnn-aarch64.c: def_protected member unintialized
PR 29293
	* elfnn-aarch64.c (elfNN_aarch64_link_hash_newfunc): Init def_protected.
2022-06-28 11:14:58 +09:30
Tsukasa OI
766077c173 RISC-V: Add 'Sstc' extension and its CSRs
This commit adds "stimecmp / vstimecmp" Extension (Sstc) and its CSRs.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_supported_std_s_ext): Add 'Sstc'
	extension to valid 'S' extension list.

gas/ChangeLog:

	* config/tc-riscv.c (enum riscv_csr_class): Add CSR classes for
	'Sstc' extension. (riscv_csr_address): Add handling for new CSR
	classes.
	* testsuite/gas/riscv/csr-dw-regnums.s: Add new CSRs.
	* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
	* testsuite/gas/riscv/csr.s: Add new CSRs.
	* testsuite/gas/riscv/csr-version-1p9p1.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p9p1.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.l: Likewise.

include/ChangeLog:

	* opcode/riscv-opc.h (CSR_STIMECMP, CSR_STIMECMPH,
	CSR_VSTIMECMP, CSR_VSTIMECMPH): New CSR macros.
2022-06-28 09:08:42 +08:00
Tsukasa OI
713f370809 RISC-V: Add 'Sscofpmf' extension with its CSRs
This commit adds Count Overflow and Mode-Based Filtering Extension
(Sscofpmf) and its CSRs.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_supported_std_s_ext): Add 'Sscofpmf'
	extension to valid 'S' extension list.

gas/ChangeLog:

	* config/tc-riscv.c (enum riscv_csr_class): Add CSR classes for
	'Sscofpmf' extension. (riscv_csr_address): Add handling for new
	CSR classes.
	* testsuite/gas/riscv/csr-dw-regnums.s: Add new CSRs.
	* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
	* testsuite/gas/riscv/csr.s: Add new CSRs.
	* testsuite/gas/riscv/csr-version-1p9p1.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p9p1.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.l: Likewise.

include/ChangeLog:

	* opcode/riscv-opc.h (CSR_SCOUNTOVF, CSR_MHPMEVENT3H,
	CSR_MHPMEVENT4H, CSR_MHPMEVENT5H, CSR_MHPMEVENT6H,
	CSR_MHPMEVENT7H, CSR_MHPMEVENT8H, CSR_MHPMEVENT9H,
	CSR_MHPMEVENT10H, CSR_MHPMEVENT11H, CSR_MHPMEVENT12H,
	CSR_MHPMEVENT13H, CSR_MHPMEVENT14H, CSR_MHPMEVENT15H,
	CSR_MHPMEVENT16H, CSR_MHPMEVENT17H, CSR_MHPMEVENT18H,
	CSR_MHPMEVENT19H, CSR_MHPMEVENT20H, CSR_MHPMEVENT21H,
	CSR_MHPMEVENT22H, CSR_MHPMEVENT23H, CSR_MHPMEVENT24H,
	CSR_MHPMEVENT25H, CSR_MHPMEVENT26H, CSR_MHPMEVENT27H,
	CSR_MHPMEVENT28H, CSR_MHPMEVENT29H, CSR_MHPMEVENT30H,
	CSR_MHPMEVENT31H): New CSR macros.
2022-06-28 09:08:06 +08:00
Tsukasa OI
6af47b081e RISC-V: Add 'Smstateen' extension and its CSRs
This commit adds State Enable Extension (Smstateen) and its CSRs.

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_supported_std_s_ext): Add 'Smstateen'
	extension to valid 'S' extension list.

gas/ChangeLog:

	* config/tc-riscv.c (enum riscv_csr_class): Add CSR classes for
	'Smstateen' extension. (riscv_csr_address): Add handling for
	new CSR classes.
	* testsuite/gas/riscv/csr-dw-regnums.s: Add new CSRs.
	* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
	* testsuite/gas/riscv/csr.s: Add new CSRs.
	* testsuite/gas/riscv/csr-version-1p9p1.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p9p1.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.l: Likewise.

include/ChangeLog:

	* opcode/riscv-opc.h (CSR_MSTATEEN0, CSR_MSTATEEN1,
	CSR_MSTATEEN2, CSR_MSTATEEN3, CSR_SSTATEEN0, CSR_SSTATEEN1,
	CSR_SSTATEEN2, CSR_SSTATEEN3, CSR_HSTATEEN0, CSR_HSTATEEN1,
	CSR_HSTATEEN2, CSR_HSTATEEN3, CSR_MSTATEEN0H, CSR_MSTATEEN1H,
	CSR_MSTATEEN2H, CSR_MSTATEEN3H, CSR_HSTATEEN0H, CSR_HSTATEEN1H,
	CSR_HSTATEEN2H, CSR_HSTATEEN3H): New CSR macros.
2022-06-28 09:07:25 +08:00
GDB Administrator
f0cb8284cf Automatic date update in version.in 2022-06-28 00:00:24 +00:00
Jan Beulich
4f6c04da69 bfd: prune config.bfd's setting of targ_archs
The final "match all" case can take care of a few explicit entries:
Purge those. Also move s12z* into proper position (the table is
otherwise sorted, after all).
2022-06-27 11:12:57 +02:00
Jan Beulich
ddd7bf3e28 drop XC16x bits
Commit 04f096fb9e ("Move the xc16x target to the obsolete list") moved
the architecture from the "obsolete but still available" to the
"obsolete / support removed" list in config.bfd, making the architecture
impossible to enable (except maybe via "enable everything" options").

Note that I didn't touch */po/*.po{,t} on the assumption that these
would be updated by some (half)automatic means.
2022-06-27 11:11:46 +02:00
GDB Administrator
b4eb841afe Automatic date update in version.in 2022-06-27 00:00:25 +00:00
GDB Administrator
9544899f28 Automatic date update in version.in 2022-06-26 00:00:10 +00:00
Fangrui Song
af9bf9cb47 arm: Define elf_backend_extern_protected_data to 0 [PR 18705]
Similar to commit 4fb55bf6a9 for aarch64.

Commit b68a20d667 changed ld to produce
R_ARM_GLOB_DAT but that defeated the purpose of protected visibility
as an optimization.  Restore the previous behavior (which matches
ld.lld) by defining elf_backend_extern_protected_data to 0.
2022-06-25 10:27:49 -07:00
GDB Administrator
c3467df4ac Automatic date update in version.in 2022-06-25 00:00:12 +00:00
GDB Administrator
54603ee2ae Automatic date update in version.in 2022-06-24 00:00:17 +00:00