Commit Graph

304 Commits

Author SHA1 Message Date
Szabolcs Nagy
c9cf7bdfe5 aarch64: Add DT_RELR support for ILP32 ABI
Extend the 64bit DT_RELR support to work on 32bit ELF too. For this
only a few changes were needed in the sizing and creation of the
relr relocations.
2024-06-25 11:07:51 +01:00
Szabolcs Nagy
961befd693 aarch64: Fix DT_RELR support with discarded sections
In case of discarded sections, via /DISCARD/ or .gnu.linkonce,
relr relocation accounting was wrong.  This broke building linux.

The issue was that the *_relocate_section logic was copied to
record_relr_non_got_relocs to find the relative relocs that can
be packed, however *_relocate_section is not called on sections
that are discarded, while record_relr_non_got_relocs is called
for all input sections. The fix is to filter out the discarded
sections with the same logic that is used to count non-GOT
relocs in *_late_size_sections for local symbols earlier.
Use the discarded_section helper in both cases to clarify the
intent and handle all corner-cases consistently.

GOT relocations are affected too if all sections are discarded
that reference the GOT entry of a particular symbol, however
this can cause unused GOT entries independently of DT_RELR, and
the only difference with DT_RELR is that a relative reloc may be
emitted instead of a R_AARCH64_NONE for the unused GOT entry
which is acceptable. A proper fix would require redoing the GOT
refcounting after we know the discarded sections, see bug 31850.
2024-06-07 08:23:23 +01:00
Szabolcs Nagy
a71d876801 aarch64: Add DT_RELR support
The logic to decide if an input relocation for a symbol becomes a
particular kind of output relocation is one of the hard to maintain
parts of the bfd ld backend, since it is partially repeated across

 elfNN_aarch64_check_relocs (where dynamic relocations are counted per
 symbol and input section),

 elfNN_aarch64_late_size_sections (where relocation sections are sized
 and GOT offsets assigned),

 elfNN_aarch64_relocate_section (where most relocations are applied and
 output to a relocation section),

 elfNN_aarch64_finish_dynamic_symbol (where some of the GOT
 relocations are applied and output).

The DT_RELR support adds another layer to this complexity: after the
output relocation sections are sized, so all dynamic relocations are
accounted (in elfNN_aarch64_late_size_sections), we scan the symbols
and input relocations again to decide which ones become relative
relocations that can be packed. The sizes of the relocation sections
are updated accordingly. This logic must be consistent with the code
that applies the relocs later so each relative relocation is emitted
exactly once: either in .rela.* or packed in .relr.dyn.

Sizing of .relr.dyn is done via elfNN_aarch64_size_relative_relocs that
may be called repeatedly whenever the layout changes since an address
change can affect the size of the packed format. Then the final content
is emitted in elfNN_aarch64_finish_relative_relocs, that is called
after the layout is final and before relocations are applied and
emitted. These hooks are only called if DT_RELR is enabled.

We only pack relative relocs that are known to be aligned in the output
during .relr.dyn sizing, the potentially unaligned relative relocs are
emitted normally (in .rela.*, not packed), because the format requires
aligned addresses.
2024-05-31 09:47:50 +01:00
Alan Modra
af969b14ae PR 30569, always call elf_backend_size_dynamic_sections
This largely mechanical patch is preparation for a followup patch.

For quite some time I've thought that it would be useful to call
elf_backend_size_dynamic_sections even when no dynamic objects are
seen by the linker.  That's what this patch does, with some renaming.
There are no functional changes to the linker, just a move of the
dynobj test in bfd_elf_size_dynamic_sections to target backend
functions, replacing the asserts/aborts already there.  No doubt some
of the current always_size_sections functions could be moved to
size_dynamic_sections but I haven't made that change.

Because both hooks are now always called, I have renamed
always_size_sections to early_size_sections and size_dynamic_sections
to late_size_sections.  I condisdered calling late_size_sections plain
size_sections, since this is the usual target dynamic section sizing
hook, but decided that searching the sources for "size_sections" would
then hit early_size_sections and other functions.
2024-04-02 10:32:04 +10:30
Alan Modra
f618d7fda2 Remove is_relocatable_executable from backend code
With the removal of symbian support, most targets no longer or never
did set is_relocatable_executable.  Remove the backend support that is
no longer relevant.

	* elf32-arm.c (record_arm_to_thumb_glue, elf32_arm_create_thumb_stub),
	(elf32_arm_final_link_relocate, elf32_arm_check_relocs),
	(elf32_arm_adjust_dynamic_symbol, allocate_dynrelocs_for_symbol),
	(elf32_arm_output_arch_local_syms): Remove is_relocatable_executable
	code and comments.
	* elf32-csky.c (csky_elf_adjust_dynamic_symbol): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
	* elfnn-kvx.c (elfNN_kvx_final_link_relocate): Likewise.
	* elfxx-mips.c (count_section_dynsyms): Likewise.
2024-02-21 23:40:12 +10:30
Alan Modra
313f04b6ed Re: elf_backend_finish_dynamic_symbol returning false
I didn't examine ld testsuite logs properly after cf95b909e2.
Replacing one of the "return false" with BFD_ASSERT in
finish_dynamic_symbol was wrong as it causes segmentation faults on
testcases expected to fail.  Revert those changes and instead make
a bfd_final_link failure noisy.
2024-02-15 19:11:42 +10:30
Alan Modra
cf95b909e2 elf_backend_finish_dynamic_symbol returning false
Returning false from elf_backend_finish_dynamic_symbol will not result
in an error being printed unless bfd_error is set but will result in
the linker exiting with a non-zero status.  If just bfd_error is set
then a generic "final link failed" will result, which doesn't help a
user much.  So elf_backend_finish_dynamic_symbol should print its own
error message whenever returning false, or use BFD_ASSERT or abort to
print assertion failures for conditions that shouldn't occur.

This patch does that, and removes unnecessary "htab != NULL" tests in
elf_backend_finish_dynamic_symbol.  Such tests aren't needed in a
function only called via elf_backend_data.
2024-02-15 11:24:13 +10:30
Alan Modra
fd67aa1129 Update year range in copyright notice of binutils files
Adds two new external authors to etc/update-copyright.py to cover
bfd/ax_tls.m4, and adds gprofng to dirs handled automatically, then
updates copyright messages as follows:

1) Update cgen/utils.scm emitted copyrights.
2) Run "etc/update-copyright.py --this-year" with an extra external
   author I haven't committed, 'Kalray SA.', to cover gas testsuite
   files (which should have their copyright message removed).
3) Build with --enable-maintainer-mode --enable-cgen-maint=yes.
4) Check out */po/*.pot which we don't update frequently.
2024-01-04 22:58:12 +10:30
Szabolcs Nagy
fc48504c7a bfd: aarch64: Avoid BTI stub for a PLT that has BTI
We decide to emit BTI stubs based on the instruction at the target
location. But PLT code is generated later than the stubs so we always
read 0 which is not a valid BTI.

Fix the logic to special case the PLT section: this is code the linker
generates so we know when it will have BTI.

This avoids BTI stubs in large executables where the PLTs have them
already. An alternative is to never emit BTI stubs for PLTs, instead
use BTI in the PLT if a library gets too big, however that may be
more tricky given the ordering of PLT sizing and stub insertion.

Related to bug 30957.
2023-11-09 14:44:37 +00:00
Szabolcs Nagy
a74ac8c419 bfd: aarch64: Fix leaks in case of BTI stub reuse
BTI stub parameters were recomputed even if those were already set up.
This is unnecessary work and leaks the symbol name that is allocated
for the stub.
2023-11-09 14:44:37 +00:00
Szabolcs Nagy
d3a8dfdef0 bfd: aarch64: Fix broken BTI stub PR30930
Input sections are grouped together that can use the same stub area
(within reach) and these groups have a stable id.

Stubs have a name generated from the stub group id and target symbol.
When a relocation requires a stub with a name that already exists, the
stub is reused instead of adding a new one.

For an indirect branch stub another BTI stub may be inserted near the
target to provide a BTI landing pad.

The BTI stub can end up with the same stub group id and thus the same
name as the indirect stub. This happens if the target symbol is within
reach of the indirect branch stub. Then, due to the name collision,
only a single stub was emmitted which branched to itself causing an
infinite loop at runtime.

A possible solution is to just name the BTI stubs differently, but
since in the problematic case the indirect and BTI stub are in the
same stub area, a better solution is to emit a single stub with a
direct branch. The stub is still needed since the caller cannot reach
the target directly and we also want a BTI landing pad in the stub in
case other indirect stubs target the same symbol and thus need a BTI
stub.

In short we convert an indirect branch stub into a BTI stub when the
target is within reach and has no BTI. It is a hassle to change the
symbol of the stub so a BTI stub may end up with *_veneer instead of
*_bti_veneer after the conversion, but this should not matter much.
(Refactoring some of _bfd_aarch64_add_call_stub_entries would be
useful but too much for this bug fix patch.)

The same conversion to direct branch could be done even if the target
did not need a BTI. The stub groups are fixed in the current logic so
linking can fail if too many stubs are inserted and the section layout
is changed too much, but this only happens in extreme cases that can
be reasonably ignored. Because of this the target cannot go out of
reach during stub insertion so the optimization is valid, but not
implemented by this patch for the non-BTI case.

Fixes bug 30930.
2023-11-09 14:44:37 +00:00
Szabolcs Nagy
98b94ebb3f bfd: aarch64: Fix BTI stub optimization PR30957
The instruction was looked up in the wrong input file (file of branch
source instead of branch target) when optimizing away BTI stubs in

  commit 5834f36d93
  bfd: aarch64: Optimize BTI stubs PR30076

This can cause adding BTI stubs when they are not necessary or removing
them when they are (the latter is a correctness issue but it is very
unlikely in practice).

Fixes bug 30957.
2023-11-09 14:44:37 +00:00
Alan Modra
09d757a5c2 Re: _bfd_free_cached_info
ELF targets with target-specific free_cache_info functions need to
call _bfd_elf_free_cached_info, not _bfd_generic_bfd_free_cached_info.

	* elf64-ppc.c (ppc64_elf_free_cached_info): Call
	_bfd_elf_free_cached_info.
	* elfnn-aarch64.c (elfNN_aarch64_bfd_free_cached_info): Likewise.
2023-06-08 10:31:45 +09:30
Alan Modra
ba75d1c55c _bfd_free_cached_info
doc/bfdint.texi and comments in the aout and som code about this
function are just wrong, and its name is not very apt.  Better would
be _bfd_mostly_destroy, and we certainly should not be saying anything
about the possibility of later recreating anything lost by this
function.  What's more, if _bfd_free_cached_info is called when
creating an archive map to reduce memory usage by throwing away
symbols, the target _close_and_cleanup function won't have access to
tdata or section bfd_user_data to tidy memory.  This means most of the
target _close_and_cleanup function won't do anything, and therefore
sometimes will result in memory leaks.

This patch fixes the documentation problems and moves most of the
target _close_and_cleanup code to target _bfd_free_cached_info.
Another notable change is that bfd_generic_bfd_free_cached_info is now
defined as _bfd_free_cached_info rather than _bfd_bool_bfd_true,
ie. the default now frees objalloc memory.
2023-06-07 14:16:06 +09:30
Alan Modra
8261abd513 bfd_close and target free_cached_memory
bfd_free_cached_info is used in just one place in archive.c, which
means most times we reach bfd_close the function isn't called.  On the
other hand, if bfd_free_cached_info is called we can't do much on the
bfd since it loses all its obj_alloc memory.  This restricts what can
be done in a target _close_and_cleanup.  In particular you can't look
at sections, which leads to duplication of code in target
close_and_cleanup and free_cached_info, eg. elfnn-aarch64.c.

	* opncls.c (_bfd_delete_bfd): Call bfd_free_cached_info.
	* elfnn-aarch64.c (elfNN_aarch64_close_and_cleanup): Delete.
	(bfd_elfNN_close_and_cleanup): Don't define.
	* som.c (som_bfd_free_cached_info): Don't call
	_bfd_generic_close_and_cleanup here.
	(som_close_and_cleanup): Define as _bfd_generic_close_and_cleanup.
2023-06-01 09:51:59 +09:30
Michael Matz
13a3cad698 PR30437 aarch64: make RELA relocs idempotent
normally RELA relocs in BFD should not consider the contents of the
relocated place.  The aarch64 psABI is even stricter, it specifies
(section 5.7.16) that all RELA relocs _must_ be idempotent.

Since the inception of the aarch64 BFD backend all the relocs have a
non-zero src_mask, and hence break this invariant.  It's normally not
a very visible problem as one can see it only when the relocated place
already contains a non-zero value, which usually only happens sometimes
when using 'ld -r' (or as in the testcase when jumping through hoops to
generate the relocations).  Or with alternative toolchains that do encode
stuff in the relocated places with the assumption that a relocation
to that place ignores whatever is there (as they can according to
the psABI).

Golang is such a toolchain and https://github.com/golang/go/issues/39927
is ultimately caused by this problem: the testcase testGCData failing
is caused by the garbage collection data-structure to describe a type
containing pointers to be wrong.  It's wrong because a field that's
supposed to contain a file-relative offset (to some gcbits) has a
relocation applied and that relocation has an addend which also is
already part of the go-produced object file (so the addend is
implicitely applied twice).

bfd/
	PR ld/30437
	* elfnn-aarch64.c (elfNN_aarch64_howto_table): Clear src_mask
	if all relocation descriptors.

ld/
	* testsuite/ld-aarch64/rela-idempotent.s: New testcase.
	* testsuite/ld-aarch64/rela-idempotent.d: New.
	* testsuite/ld-aarch64/aarch64-elf.exp: Run it.
2023-05-23 16:43:14 +02:00
Jan Beulich
af9eb2ee1b Arm64/ELF: accept relocations against STN_UNDEF
While only a secondary issue there, the testcase of PR gas/27212 exposes
an oversight in relocation handling: Just like e.g. Arm32, which has a
similar comment and a similar check, relocations against STN_UNDEF have
to be permitted to satisfy the ELF spec.
2023-03-31 08:15:53 +02:00
Alan Modra
d75137c755 ubsan: elfnn-aarch64.c:4595:19: runtime error: load of value 190
which is not a valid value for type '_Bool'

	* elfnn-aarch64.c (stub_hash_newfunc): Clear all fields past root.
2023-03-28 12:10:28 +10:30
Szabolcs Nagy
5834f36d93 bfd: aarch64: Optimize BTI stubs PR30076
Don't insert a second stub if the target is already compatible with
an indirect branch.
2023-03-23 12:49:32 +00:00
Szabolcs Nagy
15b4f66b0a bfd: aarch64: Fix stubs that may break BTI PR30076
Insert two stubs in a BTI enabled binary when fixing long calls: The
first is near the call site and uses an indirect jump like before,
but it targets the second stub that is near the call target site and
uses a direct jump.

This is needed when a single stub breaks BTI compatibility.

The stub layout is kept fixed between sizing and building the stubs,
so the location of the second stub is known at build time, this may
introduce padding between stubs when those are relaxed.  Stub layout
with BTI disabled is unchanged.
2023-03-23 12:49:32 +00:00
Szabolcs Nagy
557a2f2822 bfd: aarch64: Refactor stub sizing code
elfNN_aarch64_size_stubs has grown big, so factor out the call stub
related code before adding new logic there.
2023-03-23 12:49:32 +00:00
Alan Modra
81ff113f78 Test SEC_HAS_CONTENTS before reading section contents
bfd_malloc_and_get_section does size sanity checking before allocating
memory and reading contents.  These size checks are not done for bss
style sections, because they typically don't occupy file space and
thus can't be compared against file size.  However, if you are
expecting to look at something other than a whole lot of zeros, don't
allow fuzzers to avoid the size checking.

	* cofflink.c (process_embedded_commands): Don't look at
	sections without SEC_HAS_CONTENTS set.
	* cpu-arm.c (bfd_arm_update_notes): Likewise.
	(bfd_arm_get_mach_from_notes): Likewise.
	* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Likewise.
	* elf-hppa.h (elf_hppa_sort_unwind): Likewise.
	* elf-m10300.c (mn10300_elf_relax_section): Likewise.
	* elf-sframe.c (_bfd_elf_parse_sframe): Likewise.
	* elf.c (_bfd_elf_print_private_bfd_data): Likewise.
	* elf32-arm.c (bfd_elf32_arm_process_before_allocation): Likewise.
	* elf32-avr.c (avr_elf32_load_property_records): Likewise.
	* elf32-ppc.c (_bfd_elf_ppc_set_arch): Likewise.
	(ppc_elf_get_synthetic_symtab, ppc_elf_relax_section): Likewise.
	* elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Likewise.
	(opd_entry_value, ppc64_elf_edit_opd, ppc64_elf_edit_toc): Likewise.
	* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.
	* elflink.c (elf_link_add_object_symbols): Likewise.
	(bfd_elf_get_bfd_needed_list): Likewise.
	* elfnn-aarch64.c (get_plt_type): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_get_synthetic_symtab): Likewise.
	* linker.c (_bfd_handle_already_linked): Likewise.
	* opncls.c (bfd_get_debug_link_info_1): Likewise.
	(bfd_get_alt_debug_link_info, get_build_id): Likewise.
	* peXXigen.c (pe_print_idata, pe_print_pdata): Likewise.
	(_bfd_XX_print_ce_compressed_pdata, pe_print_reloc): Likewise.
	* pei-x86_64.c (pex64_bfd_print_pdata_section): Likewise.
	* stabs.c (_bfd_link_section_stabs): Likewise.
	(_bfd_discard_section_stabs): Likewise.
	* xcofflink.c (_bfd_xcoff_get_dynamic_symtab_upper_bound): Likewise.
	(_bfd_xcoff_canonicalize_dynamic_symtab): Likewise.
	(_bfd_xcoff_get_dynamic_reloc_upper_bound): Likewise.
	(_bfd_xcoff_canonicalize_dynamic_reloc): Likewise.
	(xcoff_link_add_dynamic_symbols): Likewise.
	(xcoff_link_check_dynamic_ar_symbols): Likewise.
	(bfd_xcoff_build_dynamic_sections): Likewise.
2023-02-23 12:58:53 +10:30
Alan Modra
4981a31d52 Use __func__ rather than __FUNCTION__
We already use C99's __func__ in places, use it more generally.  This
patch doesn't change uses in the testsuite.  I've also left one in
gold.h that is protected by GCC_VERSION < 4003.  If any of the
remaining uses bothers anyone I invite patches.

bfd/
	* bfd-in.h: Replace __FUNCTION__ with __func__.
	* elf32-bfin.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-cris.c: Replace __FUNCTION__ with __func__.
	* config/tc-m68hc11.c: Likewise.
	* config/tc-msp430.c: Likewise.
gold/
	* dwp.h: Replace __FUNCTION__ with __func__.
	* gold.h: Likewise, except for use inside GCC_VERSION < 4003.
ld/
	* emultempl/pe.em: Replace __FUNCTION__ with __func__.
	* emultempl/pep.em: Likewise.
	* pe-dll.c: Likewise.
2023-01-12 17:20:21 +10:30
Alan Modra
d87bef3a7b Update year range in copyright notice of binutils files
The newer update-copyright.py fixes file encoding too, removing cr/lf
on binutils/bfdtest2.c and ld/testsuite/ld-cygwin/exe-export.exp, and
embedded cr in binutils/testsuite/binutils-all/ar.exp string match.
2023-01-01 21:50:11 +10:30
Alan Modra
c63d486281 enable-non-contiguous-regions warnings
The warning about discarded sections in elf_link_input_bfd doesn't
belong there since the code is dealing with symbols.  Multiple symbols
in a discarded section will result in multiple identical warnings
about the section.  Move the warning to a new function in ldlang.c.

The patch also tidies the warning quoting of section and file names,
consistently using `%pA' and `%pB'.  I'm no stickler for one style of
section and file name quoting, but they ought to be consistent within
a warning, eg. see the first one fixed in ldlang.c, and when a warning
is emitted for multiple targets they all ought to use exactly the same
format string to reduce translation work.  elf64-ppc.c loses the
build_one_stub errors since we won't get there before hitting the
fatal errors in size_one_stub.

bfd/
	* elflink.c (elf_link_input_bfd): Don't warn here about
	discarded sections.
	* elf32-arm.c (arm_build_one_stub): Use consistent style in
	--enable-non-contiguous-regions error.
	* elf32-csky.c (csky_build_one_stub): Likewise.
	* elf32-hppa.c (hppa_build_one_stub): Likewise.
	* elf32-m68hc11.c (m68hc11_elf_build_one_stub): Likewise.
	* elf32-m68hc12.c (m68hc12_elf_build_one_stub): Likewise.
	* elf32-metag.c (metag_build_one_stub): Likewise.
	* elf32-nios2.c (nios2_build_one_stub): Likewise.
	* elfnn-aarch64.c (aarch64_build_one_stub): Likewise.
	* xcofflink.c (xcoff_build_one_stub): Likewise.
	* elf64-ppc.c (ppc_size_one_stub): Likewise.
	(ppc_build_one_stub): Delete dead code.
ld/
	* ldlang.c (lang_add_section): Use consistent style in
	--enable-non-contiguous-regions warnings.
	(size_input_section): Likewise.
	(warn_non_contiguous_discards): New function.
	(lang_process): Call it.
	* testsuite/ld-arm/non-contiguous-arm.d: Update.
	* testsuite/ld-arm/non-contiguous-arm4.d: Update.
	* testsuite/ld-arm/non-contiguous-arm7.d: Add
	--enable-non-contiguous-regions-warnings.
	* testsuite/ld-arm/non-contiguous-arm7.err: New.
	* testsuite/ld-powerpc/non-contiguous-powerpc.d: Update.
	* testsuite/ld-powerpc/non-contiguous-powerpc64.d: Update.
2022-12-21 17:56:27 +10:30
H.J. Lu
25d17459e3 ld: Always call elf_backend_output_arch_local_syms
Always call elf_backend_output_arch_local_syms since only the backend
knows if elf_backend_output_arch_local_syms is needed when all symbols
are striped.  elf_backend_output_arch_local_syms is defined only for
x86, ARM and AARCH64.  On x86, elf_backend_output_arch_local_syms must
be called to handle local IFUNC symbols even if all symbols are striped.
Update ARM and AARCH64 to skip elf_backend_output_arch_local_syms when
symbols aren't needed.

bfd/

	PR ld/29797
	* elf32-arm.c (elf32_arm_output_arch_local_syms): Skip if symbols
	aren't needed.
	* elfnn-aarch64.c (elfNN_aarch64_output_arch_local_syms):
	Likewise.
	* elflink.c (bfd_elf_final_link): Always call
	elf_backend_output_arch_local_syms if available.

ld/

	PR ld/29797
	* testsuite/ld-elf/linux-x86.exp: Run PR ld/29797 test.
	* testsuite/ld-elf/pr29797.c: New file.
2022-11-17 08:13:37 -08: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
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
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
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
Fangrui Song
83c325007c aarch64: Allow PC-relative relocations against protected STT_FUNC for -shared
__attribute__((visibility("protected"))) void *foo() {
      return (void *)foo;
    }

gcc -fpic -shared -fuse-ld=bfd fails with the confusing diagnostic:

    relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `foo' which may bind externally can not be used when making a shared object; recompile with -fPIC

Call _bfd_elf_symbol_refs_local_p with local_protected==true to suppress
the error.  The new behavior matches gold and ld.lld.

Note: if some code tries to use direct access relocations to take the
address of foo (likely due to -fno-pic), 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.
2022-06-23 01:10:44 -07:00
Fangrui Song
4fb55bf6a9 aarch64: Define elf_backend_extern_protected_data to 0 [PR 18705]
Follow-up to commit 90b7a5df15
("aarch64: Disallow copy relocations on protected data").

Commit 32f573bcb3 changed ld to produce
R_AARCH64_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-23 01:04:39 -07:00
Fangrui Song
90b7a5df15 aarch64: Disallow copy relocations on protected data
If an executable has copy relocations for extern protected data, that
can only work if the shared object containing the definition is built
with assumptions (a) the compiler emits GOT-generating relocations (b)
the linker produces R_*_GLOB_DAT instead of R_*_RELATIVE.  Otherwise the
shared object uses its own definition directly and the executable
accesses a stale copy.  Note: the GOT relocations defeat the purpose of
protected visibility as an optimization, and it turns out this never
worked perfectly.

glibc 2.36 will warn on copy relocations on protected data.  Let's
produce a warning at link time, matching ld.lld which has been used on
many aarch64 OSes.

Note: x86 requires GNU_PROPERTY_NO_COPY_ON_PROTECTED to have the error.
This is to largely due to GCC 5's "x86-64: Optimize access to globals in
PIE with copy reloc" which started to use direct access relocations for
external data symbols in -fpie mode.

GCC's aarch64 port does not have the change.  Nowadays with most builds
switching to -fpie/-fpic, aarch64 mostly doesn't need to worry about
copy relocations.  So for aarch64 we simply don't check
GNU_PROPERTY_NO_COPY_ON_PROTECTED.
2022-06-22 10:55:12 -07:00
Alan Modra
c94cb02662 HOWTO size encoding
This changes the HOWTO macro to encode the howto.size field from a
value given in bytes.  This of course requires editing all target
uses of HOWTO, a major pain, but makes it a little nicer to specify
new target HOWTOs.  Object files before/after this patch are
unchanged in .data and .rodata.

bfd/
	* reloc.c (HOWTO_RSIZE): Encode size in bytes.
	(EMPTY_HOWTO): Adjust to keep it all zero.
	* aout-ns32k.c, * aoutx.h, * coff-alpha.c, * coff-arm.c,
	* coff-i386.c, * coff-mcore.c, * coff-mips.c, * coff-rs6000.c,
	* coff-sh.c, * coff-tic30.c, * coff-tic4x.c, * coff-tic54x.c,
	* coff-x86_64.c, * coff-z80.c, * coff-z8k.c, * coff64-rs6000.c,
	* elf-hppa.h, * elf-m10200.c, * elf-m10300.c, * elf32-arc.c,
	* elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c,
	* elf32-cris.c, * elf32-crx.c, * elf32-csky.c, * elf32-d10v.c,
	* elf32-d30v.c, * elf32-dlx.c, * elf32-epiphany.c,
	* elf32-fr30.c, * elf32-frv.c, * elf32-ft32.c, * elf32-gen.c,
	* elf32-h8300.c, * elf32-i386.c, * elf32-ip2k.c, * elf32-iq2000.c,
	* elf32-lm32.c, * elf32-m32c.c, * elf32-m32r.c, * elf32-m68hc11.c,
	* elf32-m68hc12.c, * elf32-m68k.c, * elf32-mcore.c, * elf32-mep.c,
	* elf32-metag.c, * elf32-microblaze.c, * elf32-mips.c,
	* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
	* elf32-nios2.c, * elf32-or1k.c, * elf32-pj.c, * elf32-ppc.c,
	* elf32-pru.c, * elf32-rl78.c, * elf32-rx.c, * elf32-s12z.c,
	* elf32-s390.c, * elf32-score.c, * elf32-score7.c,
	* elf32-sh-relocs.h, * elf32-spu.c, * elf32-tic6x.c,
	* elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c,
	* elf32-visium.c, * elf32-wasm32.c, * elf32-xc16x.c,
	* elf32-xgate.c, * elf32-xstormy16.c, * elf32-xtensa.c,
	* elf32-z80.c, * elf64-alpha.c, * elf64-bpf.c, * elf64-gen.c,
	* elf64-mips.c, * elf64-mmix.c, * elf64-nfp.c, * elf64-ppc.c,
	* elf64-s390.c, * elf64-x86-64.c, * elfn32-mips.c,
	* elfnn-aarch64.c, * elfxx-ia64.c, * elfxx-loongarch.c,
	* elfxx-mips.c, * elfxx-riscv.c, * elfxx-sparc.c,
	* elfxx-tilegx.c, * mach-o-aarch64.c, * mach-o-arm.c,
	* mach-o-i386.c, * mach-o-x86-64.c, * pdp11.c, * reloc.c,
	* som.c, * vms-alpha.c: Adjust all uses of HOWTO.
	* bfd-in2.h: Regenerate.
include/
	* elf/arc-reloc.def: Adjust all uses of HOWTO.
2022-06-08 21:33:00 +09:30
Alan Modra
a2c5833233 Update year range in copyright notice of binutils files
The result of running etc/update-copyright.py --this-year, fixing all
the files whose mode is changed by the script, plus a build with
--enable-maintainer-mode --enable-cgen-maint=yes, then checking
out */po/*.pot which we don't update frequently.

The copy of cgen was with commit d1dd5fcc38ead reverted as that commit
breaks building of bfp opcodes files.
2022-01-02 12:04:28 +10:30
Alan Modra
bb67763979 Remove unnecessary ELF_MINPAGESIZE defines
The idea of this patch is to make it easy to see which targets (just
sparc) have ELF_MINPAGESIZE != ELF_COMMONPAGESIZE.

	* elf32-arm.c (ELF_MINPAGESIZE): Don't define.
	* elf32-metag.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elf64-x86-64.c: Likewise.  Also don't redefine a bunch of other
	macros for l1om elf64-target.h use that are unchanged from default.
2022-01-01 14:22:09 +10:30
Alan Modra
8ef22662dc asan: buffer overflow in elfnn-aarch64.c get_plt_type
We can't assume .dynamic is a multiple of ElfNN_External_Dyn, at least
not when presented with fuzzed object files.

	* elfnn-aarch64.c (get_plt_type): Don't access past end of
	improperly sized .dynamic.
2021-12-17 16:01:13 +10:30
Nick Clifton
ffa5352c0c Fix problems translating messages when a percentage sign appears at the end of a string.
PR 28051
gas	* config/tc-i386.c (offset_in_range): Reformat error messages in
	order to fix problems when translating.
	(md_assemble): Likewise.
	* messages.c (as_internal_value_out_of_range): Likewise.
	* read.c (emit_expr_with_reloc): Likewise.
	* testsuite/gas/all/overflow.l Change expected output format.
	* po/gas.pot: Regenerate.

bfd	* coff-rs6000.c (xcoff_reloc_type_tls): Reformat error messages in
	order to fix problems when translating.
	* cofflink.c (_bfd_coff_write_global_sym): Likewise.
	* elfnn-aarch64.c (_bfd_aarch64_erratum_843419_branch_to_stub):
	Likewise.
	* po/bfd.pot: Regenerate.
2021-07-07 10:25:41 +01:00
Nick Clifton
24aebc79b1 Stop the BFD library from treating annobin symbols as potential function symbols.
bfd	* elf.c (_bfd_elf_maybe_function_sym): Do not accept annobin
	symbols as potential function symbols.
	* elfnn-aarch64.c (elfNN_aarch64_maybe_function_sym): Likewise.
	* elf64-ppc.c (ppc64_elf_maybe_function_sym): Likewise.
	* elf32-arm.c (elf32_arm_maybe_function_sym): Likewise.

ld	* testsuite/ld-elf/anno-sym.s: New test source file.
	* testsuite/ld-elf/anno-sym.d: New test driver.
	* testsuite/ld-elf/anno-sym.l: New test error output.
2021-04-28 11:49:09 +01:00
Alan Modra
2cc15b10e5 convert elf_link_hash macros to inline functions
Involves a bit of editing as we now need to be more precise in pointer
types.

bfd/
	* elf-bfd.h (is_elf_hash_table): Convert macro to inline function.
	(elf_link_hash_lookup, elf_link_hash_traverse): Likewise.
	(elf_hash_table, elf_hash_table_id): Likewise.
	* elf32-arm.c (elf32_arm_setup_section_lists): Delete redundant
	is_elf_hash_table check.
	* elf32-csky.c (elf32_csky_setup_section_lists): Likewise.
	* elf32-hppa.c (clobber_millicode_symbols): Correct param types.
	* elf64-alpha.c (elf64_alpha_output_extsym): Likewise.
	* elfnn-ia64.c (elfNN_ia64_global_dyn_info_free: Likewise.
	(elfNN_ia64_global_dyn_sym_thunk: Likewise.
	* elf64-ia64-vms.c (elf64_ia64_global_dyn_info_free): Likewise.
	(elf64_ia64_global_dyn_sym_thunk): Likewise.
	(elf64_vms_link_add_object_symbols): Pass base type of hash table
	to is_elf_hash_table.
	* elflink.c (_bfd_elf_dynamic_symbol_p): Likewise.
	(_bfd_elf_symbol_refs_local_p, _bfd_elf_add_dynamic_entry): Likewise.
	(_bfd_elf_strip_zero_sized_dynamic_sections): Likewise.
	(_bfd_elf_link_check_relocs, elf_link_add_object_symbols): Likewise.
	(bfd_elf_final_link): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_setup_section_lists): Likewise.
	* elf64-ppc.c (ppc64_elf_set_toc): Likewise.  Use bfd_link_hash_lookup.
ld/
	* emultempl/mipself.em (mips_create_output_section_statements):
	Pass base type of hash table to is_elf_hash_table.
	* ldelf.c (ldelf_after_open): Likewise.
2021-04-12 21:19:02 +09:30
Alan Modra
0a1b45a20e Use bool in bfd
* sysdep.h: POISON_BFD_BOOLEAN: Define.
	* aix5ppc-core.c, * aout-cris.c, * aout-ns32k.c, * aout-target.h,
	* aoutx.h, * arc-got.h, * archive.c, * archive64.c, * archures.c,
	* bfd-in.h, * bfd.c, * bfdwin.c, * binary.c, * cache.c,
	* coff-alpha.c, * coff-arm.c, * coff-arm.h, * coff-bfd.c,
	* coff-bfd.h, * coff-go32.c, * coff-i386.c, * coff-ia64.c,
	* coff-mcore.c, * coff-mips.c, * coff-rs6000.c, * coff-sh.c,
	* coff-stgo32.c, * coff-tic30.c, * coff-tic4x.c, * coff-tic54x.c,
	* coff-x86_64.c, * coff-z80.c, * coff-z8k.c, * coff64-rs6000.c,
	* coffcode.h, * coffgen.c, * cofflink.c, * compress.c,
	* corefile.c, * cpu-aarch64.c, * cpu-aarch64.h, * cpu-alpha.c,
	* cpu-arc.c, * cpu-arm.c, * cpu-arm.h, * cpu-avr.c, * cpu-bfin.c,
	* cpu-bpf.c, * cpu-cr16.c, * cpu-cris.c, * cpu-crx.c,
	* cpu-csky.c, * cpu-d10v.c, * cpu-d30v.c, * cpu-dlx.c,
	* cpu-epiphany.c, * cpu-fr30.c, * cpu-frv.c, * cpu-ft32.c,
	* cpu-h8300.c, * cpu-hppa.c, * cpu-i386.c, * cpu-ia64.c,
	* cpu-iamcu.c, * cpu-ip2k.c, * cpu-iq2000.c, * cpu-k1om.c,
	* cpu-l1om.c, * cpu-lm32.c, * cpu-m10200.c, * cpu-m10300.c,
	* cpu-m32c.c, * cpu-m32r.c, * cpu-m68hc11.c, * cpu-m68hc12.c,
	* cpu-m68k.c, * cpu-m9s12x.c, * cpu-m9s12xg.c, * cpu-mcore.c,
	* cpu-mep.c, * cpu-metag.c, * cpu-microblaze.c, * cpu-mips.c,
	* cpu-mmix.c, * cpu-moxie.c, * cpu-msp430.c, * cpu-mt.c,
	* cpu-nds32.c, * cpu-nfp.c, * cpu-nios2.c, * cpu-ns32k.c,
	* cpu-or1k.c, * cpu-pdp11.c, * cpu-pj.c, * cpu-powerpc.c,
	* cpu-pru.c, * cpu-riscv.c, * cpu-rl78.c, * cpu-rs6000.c,
	* cpu-rx.c, * cpu-s12z.c, * cpu-s390.c, * cpu-score.c,
	* cpu-sh.c, * cpu-sparc.c, * cpu-spu.c, * cpu-tic30.c,
	* cpu-tic4x.c, * cpu-tic54x.c, * cpu-tic6x.c, * cpu-tilegx.c,
	* cpu-tilepro.c, * cpu-v850.c, * cpu-v850_rh850.c, * cpu-vax.c,
	* cpu-visium.c, * cpu-wasm32.c, * cpu-xc16x.c, * cpu-xgate.c,
	* cpu-xstormy16.c, * cpu-xtensa.c, * cpu-z80.c, * cpu-z8k.c,
	* dwarf1.c, * dwarf2.c, * ecoff-bfd.h, * ecoff.c, * ecofflink.c,
	* elf-attrs.c, * elf-bfd.h, * elf-eh-frame.c, * elf-hppa.h,
	* elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-nacl.c,
	* elf-nacl.h, * elf-properties.c, * elf-s390-common.c,
	* elf-s390.h, * elf-strtab.c, * elf-vxworks.c, * elf-vxworks.h,
	* elf.c, * elf32-am33lin.c, * elf32-arc.c, * elf32-arm.c,
	* elf32-arm.h, * elf32-avr.c, * elf32-avr.h, * elf32-bfin.c,
	* elf32-bfin.h, * elf32-cr16.c, * elf32-cr16.h, * elf32-cris.c,
	* elf32-crx.c, * elf32-csky.c, * elf32-csky.h, * elf32-d10v.c,
	* elf32-d30v.c, * elf32-dlx.c, * elf32-epiphany.c,
	* elf32-fr30.c, * elf32-frv.c, * elf32-ft32.c, * elf32-gen.c,
	* elf32-h8300.c, * elf32-hppa.c, * elf32-hppa.h, * elf32-i386.c,
	* elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c,
	* elf32-m32r.c, * elf32-m68hc11.c, * elf32-m68hc12.c,
	* elf32-m68hc1x.c, * elf32-m68hc1x.h, * elf32-m68k.c,
	* elf32-m68k.h, * elf32-mcore.c, * elf32-mep.c, * elf32-metag.c,
	* elf32-metag.h, * elf32-microblaze.c, * elf32-mips.c,
	* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
	* elf32-nios2.c, * elf32-nios2.h, * elf32-or1k.c, * elf32-pj.c,
	* elf32-ppc.c, * elf32-ppc.h, * elf32-pru.c, * elf32-rl78.c,
	* elf32-rx.c, * elf32-s12z.c, * elf32-s390.c, * elf32-score.c,
	* elf32-score.h, * elf32-score7.c, * elf32-sh-relocs.h,
	* elf32-sh.c, * elf32-sparc.c, * elf32-spu.c, * elf32-spu.h,
	* elf32-tic6x.c, * elf32-tic6x.h, * elf32-tilegx.c,
	* elf32-tilepro.c, * elf32-v850.c, * elf32-v850.h,
	* elf32-vax.c, * elf32-visium.c, * elf32-wasm32.c,
	* elf32-xc16x.c, * elf32-xgate.c, * elf32-xstormy16.c,
	* elf32-xtensa.c, * elf32-z80.c, * elf64-alpha.c, * elf64-bpf.c,
	* elf64-gen.c, * elf64-hppa.c, * elf64-ia64-vms.c,
	* elf64-mips.c, * elf64-mmix.c, * elf64-nfp.c, * elf64-ppc.c,
	* elf64-ppc.h, * elf64-s390.c, * elf64-sparc.c,
	* elf64-tilegx.c, * elf64-x86-64.c, * elfcode.h,
	* elfcore.h, * elflink.c, * elfn32-mips.c, * elfnn-aarch64.c,
	* elfnn-ia64.c, * elfnn-riscv.c, * elfxx-aarch64.c,
	* elfxx-aarch64.h, * elfxx-ia64.c, * elfxx-ia64.h,
	* elfxx-mips.c, * elfxx-mips.h, * elfxx-riscv.c, * elfxx-riscv.h,
	* elfxx-sparc.c, * elfxx-sparc.h, * elfxx-target.h,
	* elfxx-tilegx.c, * elfxx-tilegx.h, * elfxx-x86.c, * elfxx-x86.h,
	* format.c, * genlink.h, * hash.c, * i386aout.c, * i386lynx.c,
	* i386msdos.c, * ihex.c, * libaout.h, * libbfd-in.h,
	* libbfd.c, * libcoff-in.h, * libecoff.h, * libpei.h,
	* libxcoff.h, * linker.c, * mach-o-aarch64.c, * mach-o-arm.c,
	* mach-o-i386.c, * mach-o-x86-64.c, * mach-o.c, * mach-o.h,
	* merge.c, * mmo.c, * netbsd.h, * opncls.c, * pc532-mach.c,
	* pdp11.c, * pe-arm.c, * pe-i386.c, * pe-mcore.c, * pe-sh.c,
	* pe-x86_64.c, * peXXigen.c, * pef.c, * pei-arm.c, * pei-i386.c,
	* pei-ia64.c, * pei-mcore.c, * pei-sh.c, * pei-x86_64.c,
	* peicode.h, * plugin.c, * plugin.h, * ppcboot.c, * reloc.c,
	* reloc16.c, * rs6000-core.c, * section.c, * simple.c, * som.c,
	* som.h, * srec.c, * stabs.c, * syms.c, * targets.c, * tekhex.c,
	* verilog.c, * vms-alpha.c, * vms-lib.c, * vms-misc.c, * vms.h,
	* wasm-module.c, * xcofflink.c, * xcofflink.h, * xsym.c,
	* xsym.h: Replace bfd_boolean with bool, FALSE with false, and
	TRUE with true throughout.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* libcoff.h: Regenerate.
2021-03-31 10:49:23 +10:30
Alan Modra
63b4cc53dc TRUE/FALSE simplification
There is really no need to write code like "foo != 0 ? TRUE : FALSE"
unless we had stupidly defined FALSE as something other than 0 or TRUE
as something other than 1.  The simpler "foo != 0" does just as well.
Similarly "(condition == TRUE)" or "(condition == FALSE) can be
simplified to "(condition)" and "(!condition)" respectively.

I'll note that there is reason to use "integer_expression != 0" when
assigning a bfd_boolean rather than the simpler "integer_expression",
if you expect the variable to have 0 or 1 value.  It's probably even a
good idea to not rely on implicit conversion if bfd_boolean were _Bool.

bfd/
	* aoutx.h (aout_link_write_symbols): Don't cast boolean expression
	to bfd_boolean.
	* elf32-or1k.c (or1k_set_got_and_rela_sizes): Dont compare booleans
	against FALSE.
	* elf32-arc.c (name_for_global_symbol): Don't compare boolean to TRUE.
	(is_reloc_PC_relative): Don't use "boolean_condition ? TRUE : FALSE".
	(is_reloc_SDA_relative, is_reloc_for_GOT): Likewise.
	(is_reloc_for_PLT, is_reloc_for_TLS): Likewise.
	* elf32-arm.c (stm32l4xx_need_create_replacing_stub): Likewise.
	* elf32-nds32.c (insert_nds32_elf_blank): Likewise.
	* elf32-rx.c (rx_set_section_contents): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_ignore_undef_symbol): Likewise.
	* mach-o.c (bfd_mach_o_read_command): Likewise.
	* targets.c (bfd_get_target_info): Likewise.
binutils/
	* dlltool.c (main): Don't use "boolean_condition ? TRUE : FALSE".
	* dwarf.c (read_and_display_attr_value): Likewise.
	(display_debug_str_offsets): Likewise.
	* objdump.c (dump_bfd): Likewise.
	* readelf.c (dump_section_as_strings): Likewise.
	(dump_section_as_bytes): Likewise.
gas/
	* atof-generic.c (FALSE, TRUE): Don't define.
	* config/obj-elf.h (FALSE, TRUE): Don't define.
	* config/obj-som.h (FALSE, TRUE): Don't define.
	* config/tc-hppa.h (FALSE, TRUE): Don't define.
	* config/tc-pdp11.c (FALSE, TRUE): Don't define.
	* config/tc-iq2000.h (obj_fix_adjustable): Delete.
	* config/tc-m32r.h (TC_FIX_ADJUSTABLE): Delete.
	* config/tc-mt.h (obj_fix_adjustable): Delete.
	* config/tc-nds32.h (TC_FIX_ADJUSTABLE): Delete.
	* config/tc-arc.c (parse_opcode_flags): Simplify boolean expression.
	(relaxable_flag, relaxable_operand, assemble_insn): Likewise.
	(tokenize_extregister): Likewise.
	* config/tc-csky.c (parse_opcode, get_operand_value): Likewise.
	(parse_operands_op, parse_operands, md_assemble): Likewise.
	* config/tc-d10v.c (build_insn): Likewise.
	* config/tc-score.c (s3_gen_insn_frag): Likewise.
	* config/tc-score7.c (s7_gen_insn_frag, s7_relax_frag): Likewise.
	* config/tc-tic6x.c (tic6x_update_features, md_assemble): Likewise.
	* config/tc-z80.c (emit_byte): Likewise.
include/
	* opcode/aarch64.h (alias_opcode_p): Simplify boolean expression.
	(opcode_has_alias, pseudo_opcode_p, optional_operand_p): Likewise.
	(opcode_has_special_coder): Likewise.
ld/
	* emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Simplify
	boolean expression.
	* lexsup.c (parse_args): Likewise.
	* pe-dll.c (pe_dll_id_target): Likewise.
opcodes/
	* aarch64-opc.c (vector_qualifier_p): Simplify boolean expression.
	(fp_qualifier_p, get_data_pattern): Likewise.
	(aarch64_get_operand_modifier_from_value): Likewise.
	(aarch64_extend_operator_p, aarch64_shift_operator_p): Likewise.
	(operand_variant_qualifier_p): Likewise.
	(qualifier_value_in_range_constraint_p): Likewise.
	(aarch64_get_qualifier_esize): Likewise.
	(aarch64_get_qualifier_nelem): Likewise.
	(aarch64_get_qualifier_standard_value): Likewise.
	(get_lower_bound, get_upper_bound): Likewise.
	(aarch64_find_best_match, match_operands_qualifier): Likewise.
	(aarch64_print_operand): Likewise.
	* aarch64-opc.h (operand_has_inserter, operand_has_extractor): Likewise.
	(operand_need_sign_extension, operand_need_shift_by_two): Likewise.
	(operand_need_shift_by_four, operand_maybe_stack_pointer): Likewise.
	* arm-dis.c (print_insn_mve, print_insn_thumb32): Likewise.
	* tic6x-dis.c (tic6x_check_fetch_packet_header): Likewise.
	(print_insn_tic6x): Likewise.
2021-03-29 11:22:22 +10:30
Alan Modra
1201fda61b hash table iterator callback functions int vs. bfd_boolean
Correct return type of callbacks invoked by htab_traverse and other
hashtab.h functions to int, and one case of a callback invoked by
elf_link_hash_traverse to bfd_boolean.

	* elf32-i386.c (elf_i386_finish_local_dynamic_symbol): Return int.
	* elf64-ia64-vms.c (elf64_ia64_local_dyn_info_free): Likewise.
	(elf64_ia64_local_dyn_sym_thunk): Likewise.
	* elf64-x86-64.c (elf_x86_64_finish_local_dynamic_symbol): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_allocate_local_ifunc_dynrelocs),
	(elfNN_aarch64_finish_local_dynamic_symbol): Likewise.
	* elfnn-ia64.c (elfNN_ia64_local_dyn_info_free): Likewise.
	(elfNN_ia64_local_dyn_sym_thunk): Likewise.
	* elfnn-riscv.c (allocate_local_ifunc_dynrelocs): Likewise.
	(riscv_pcrel_reloc_eq): Likewise.
	(riscv_elf_finish_local_dynamic_symbol): Likewise.
	* elfxx-sparc.c (allocate_local_dynrelocs): Likewise.
	(finish_local_dynamic_symbol): Likewise.
	* elfxx-x86.c (elf_x86_allocate_local_dynreloc): Likewise.
	* elfxx-mips.c (mips_elf_resolve_got_page_ref): Likewise.
	(mips_elf_count_got_symbols): Change return type to bfd_boolean.
2021-03-29 11:22:21 +10:30
Alan Modra
0f68420117 elf_backend_relocate_section int vs. bfd_boolean
This functions was changed to return an int in commit ece5ef6079 but
since bfd_boolean was an int typedef I lazily left all the ELF
relocate_section functions as returning bfd_boolean, except the SPU
one.  In order to use _Bool or bool in place of bfd_boolean we need to
be fussy about the return types.

	* elf-m10200.c (mn10200_elf_relocate_section): Return int.
	* elf-m10300.c (mn10300_elf_relocate_section): Likewise.
	* elf32-arc.c (elf_arc_relocate_section): Likewise.
	* elf32-arm.c (elf32_arm_relocate_section): Likewise.
	* elf32-avr.c (elf32_avr_relocate_section): Likewise.
	* elf32-bfin.c (bfin_relocate_section): Likewise.
	(bfinfdpic_relocate_section): Likewise.
	* elf32-cr16.c (elf32_cr16_relocate_section): Likewise.
	* elf32-cris.c (cris_elf_relocate_section): Likewise.
	* elf32-crx.c (elf32_crx_relocate_section): Likewise.
	* elf32-csky.c (csky_elf_relocate_section): Likewise.
	* elf32-d10v.c (elf32_d10v_relocate_section): Likewise.
	* elf32-epiphany.c (epiphany_elf_relocate_section): Likewise.
	* elf32-fr30.c (fr30_elf_relocate_section): Likewise.
	* elf32-frv.c (elf32_frv_relocate_section): Likewise.
	* elf32-ft32.c (ft32_elf_relocate_section): Likewise.
	* elf32-h8300.c (elf32_h8_relocate_section): Likewise.
	* elf32-hppa.c (elf32_hppa_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-ip2k.c (ip2k_elf_relocate_section): Likewise.
	* elf32-iq2000.c (iq2000_elf_relocate_section): Likewise.
	* elf32-lm32.c (lm32_elf_relocate_section): Likewise.
	* elf32-m32c.c (m32c_elf_relocate_section): Likewise.
	* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Likewise.
	* elf32-m68hc1x.h (elf32_m68hc11_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-mcore.c (mcore_elf_relocate_section): Likewise.
	* elf32-mep.c (mep_elf_relocate_section): Likewise.
	* elf32-metag.c (elf_metag_relocate_section): Likewise.
	* elf32-microblaze.c (microblaze_elf_relocate_section): Likewise.
	* elf32-moxie.c (moxie_elf_relocate_section): Likewise.
	* elf32-msp430.c (elf32_msp430_relocate_section): Likewise.
	* elf32-mt.c (mt_elf_relocate_section): Likewise.
	* elf32-nds32.c (nds32_elf_relocate_section): Likewise.
	* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
	* elf32-or1k.c (or1k_elf_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-pru.c (pru_elf32_relocate_section): Likewise.
	* elf32-rl78.c (rl78_elf_relocate_section): Likewise.
	* elf32-rx.c (rx_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-score.c (s3_bfd_score_elf_relocate_section): Likewise.
	(_bfd_score_elf_relocate_section): Likewise.
	* elf32-score.h (s7_bfd_score_elf_relocate_section): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise.
	* elf32-sh.c (sh_elf_relocate_section): Likewise.
	* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf32-v850.c (v850_elf_relocate_section): Likewise.
	* elf32-vax.c (elf_vax_relocate_section): Likewise.
	* elf32-visium.c (visium_elf_relocate_section): Likewise.
	* elf32-xc16x.c (elf32_xc16x_relocate_section): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf32-z80.c (z80_elf_relocate_section): Likewise.
	* elf64-alpha.c (elf64_alpha_relocate_section_r): Likewise.
	(elf64_alpha_relocate_section): Likewise.
	* elf64-bpf.c (bpf_elf_relocate_section): Likewise.
	* elf64-hppa.c (elf64_hppa_relocate_section): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_relocate_section): Likewise.
	* elf64-mmix.c (mmix_elf_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_relocate_section): Likewise.
	* elfnn-ia64.c (elfNN_ia64_relocate_section): Likewise.
	* elfnn-riscv.c (riscv_elf_relocate_section): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_relocate_section): Likewise.
	* elfxx-mips.h (_bfd_mips_elf_relocate_section): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-sparc.h (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
	* elfxx-tilegx.h (tilegx_elf_relocate_section): Likewise.
2021-03-29 11:22:21 +10:30
Martin Liska
08dedd6631 Add startswith function and use it instead of CONST_STRNEQ.
bfd/ChangeLog:

	* bfd-in.h (startswith): Add startswith function.
	(CONST_STRNEQ): Remove.
	* bfd-in2.h (startswith): Regenerate with make headers.
	* archive.c (bfd_slurp_armap): Replace usage of CONST_STRNEQ with startswith.
	(_bfd_slurp_extended_name_table): Likewise.
	* archive64.c (_bfd_archive_64_bit_slurp_armap): Likewise.
	* bfd.c (bfd_get_sign_extend_vma): Likewise.
	(bfd_convert_section_size): Likewise.
	(bfd_convert_section_contents): Likewise.
	* coff-stgo32.c (go32exe_create_stub): Likewise.
	(go32exe_check_format): Likewise.
	* coffcode.h (styp_to_sec_flags): Likewise.
	(GNU_DEBUGALTLINK): Likewise.
	* coffgen.c (_bfd_coff_section_already_linked): Likewise.
	(coff_gc_sweep): Likewise.
	(bfd_coff_gc_sections): Likewise.
	* cofflink.c (coff_link_add_symbols): Likewise.
	(process_embedded_commands): Likewise.
	* compress.c (bfd_is_section_compressed_with_header): Likewise.
	(bfd_init_section_decompress_status): Likewise.
	* dwarf2.c (find_debug_info): Likewise.
	(place_sections): Likewise.
	* ecoff.c (_bfd_ecoff_slurp_armap): Likewise.
	* elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Likewise.
	* elf.c (_bfd_elf_make_section_from_shdr): Likewise.
	(assign_section_numbers): Likewise.
	(elfcore_grok_win32pstatus): Likewise.
	* elf32-arm.c (cmse_scan): Likewise.
	(elf32_arm_gc_mark_extra_sections): Likewise.
	(elf32_arm_size_dynamic_sections): Likewise.
	(is_arm_elf_unwind_section_name): Likewise.
	* elf32-bfin.c (bfin_size_dynamic_sections): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise.
	* elf32-cris.c (elf_cris_size_dynamic_sections): Likewise.
	* elf32-csky.c (csky_elf_size_dynamic_sections): Likewise.
	* elf32-hppa.c (elf32_hppa_size_dynamic_sections): Likewise.
	* elf32-iq2000.c (iq2000_elf_check_relocs): Likewise.
	* elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise.
	* elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise.
	* elf32-metag.c (elf_metag_size_dynamic_sections): Likewise.
	* elf32-msp430.c (msp430_elf_relax_delete_bytes): Likewise.
	* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise.
	* elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise.
	* elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
	* elf32-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elf32-score.c (s3_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-sh.c (sh_elf_size_dynamic_sections): Likewise.
	* elf32-tic6x.c (is_tic6x_elf_unwind_section_name): Likewise.
	(elf32_tic6x_size_dynamic_sections): Likewise.
	* elf32-vax.c (elf_vax_size_dynamic_sections): Likewise.
	* elf32-xtensa.c (elf_xtensa_size_dynamic_sections): Likewise.
	(xtensa_is_insntable_section): Likewise.
	(xtensa_is_littable_section): Likewise.
	(xtensa_is_proptable_section): Likewise.
	(xtensa_property_section_name): Likewise.
	(xtensa_callback_required_dependence): Likewise.
	* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise.
	* elf64-hppa.c (elf64_hppa_size_dynamic_sections): Likewise.
	* elf64-ia64-vms.c (is_unwind_section_name): Likewise.
	(get_reloc_section): Likewise.
	(elf64_ia64_size_dynamic_sections): Likewise.
	(elf64_ia64_object_p): Likewise.
	* elf64-mmix.c (mmix_elf_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Likewise.
	* elf64-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elflink.c (elf_link_add_object_symbols): Likewise.
	(_bfd_elf_gc_mark_extra_sections): Likewise.
	(bfd_elf_parse_eh_frame_entries): Likewise.
	(_bfd_elf_section_already_linked): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections): Likewise.
	* elfnn-ia64.c (is_unwind_section_name): Likewise.
	(elfNN_ia64_size_dynamic_sections): Likewise.
	(elfNN_ia64_object_p): Likewise.
	* elfxx-mips.c (FN_STUB_P): Likewise.
	(CALL_STUB_P): Likewise.
	(CALL_FP_STUB_P): Likewise.
	(_bfd_mips_elf_section_from_shdr): Likewise.
	(_bfd_mips_elf_fake_sections): Likewise.
	(_bfd_mips_elf_size_dynamic_sections): Likewise.
	(_bfd_mips_final_write_processing): Likewise.
	(_bfd_mips_elf_final_link): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections): Likewise.
	* elfxx-x86.c (elf_i386_is_reloc_section): Likewise.
	(elf_x86_64_is_reloc_section): Likewise.
	* hpux-core.c (thread_section_p): Likewise.
	* libcoff.h (bfd_pei_p): Likewise.
	* linker.c (REAL): Likewise.
	(unwrap_hash_lookup): Likewise.
	(_bfd_generic_link_add_one_symbol): Likewise.
	* mmo.c (mmo_internal_write_section): Likewise.
	* osf-core.c (osf_core_core_file_p): Likewise.
	* pef.c (bfd_pef_print_symbol): Likewise.
	* pei-x86_64.c (pex64_print_all_pdata_sections): Likewise.
	* som.c (som_slurp_symbol_table): Likewise.
	(som_slurp_armap): Likewise.
	* wasm-module.c (wasm_compute_custom_section_file_position): Likewise.

binutils/ChangeLog:

	* dlltool.c (scan_drectve_symbols): Replace usage of CONST_STRNEQ with startswith.
	* emul_aix.c (ar_emul_aix_parse_arg): Likewise.
	* objcopy.c (is_mergeable_note_section): Likewise.
	* objdump.c (dump_dwarf_section): Likewise.
	* prdbg.c (pr_method_type): Likewise.
	(pr_class_baseclass): Likewise.
	(tg_class_baseclass): Likewise.
	* readelf.c (process_lto_symbol_tables): Likewise.
	* stabs.c (ULLHIGH): Likewise.
	(parse_stab_argtypes): Likewise.
	(stab_demangle_function_name): Likewise.

gas/ChangeLog:

	* config/tc-i386.c (md_parse_option): Replace usage of CONST_STRNEQ with startswith.
	(x86_64_section_word): Likewise.
	* config/tc-sparc.c (md_parse_option): Likewise.

gdb/ChangeLog:

	* arm-tdep.c (show_disassembly_style_sfunc): Replace usage of CONST_STRNEQ with startswith.
	(_initialize_arm_tdep): Likewise.

ld/ChangeLog:

	* emultempl/aix.em: Replace usage of CONST_STRNEQ with startswith.
	* emultempl/beos.em: Likewise.
	* emultempl/elf.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
	* ldctor.c (ctor_prio): Likewise.
	* ldelf.c (ldelf_try_needed): Likewise.
	(ldelf_parse_ld_so_conf): Likewise.
	(ldelf_after_open): Likewise.
	(output_rel_find): Likewise.
	(ldelf_place_orphan): Likewise.
	* ldfile.c (ldfile_add_library_path): Likewise.
	* ldlang.c (lang_add_input_file): Likewise.
	* ldmain.c (get_sysroot): Likewise.
	(get_emulation): Likewise.
	(add_archive_element): Likewise.
	* ldwrite.c (unsplittable_name): Likewise.
	(clone_section): Likewise.
	* lexsup.c (parse_args): Likewise.
	* pe-dll.c (is_import): Likewise.
	(pe_implied_import_dll): Likewise.

opcodes/ChangeLog:

	* aarch64-dis.c (parse_aarch64_dis_option): Replace usage of CONST_STRNEQ with startswith.
	* arc-dis.c (parse_option): Likewise.
	* arm-dis.c (parse_arm_disassembler_options): Likewise.
	* cris-dis.c (print_with_operands): Likewise.
	* h8300-dis.c (bfd_h8_disassemble): Likewise.
	* i386-dis.c (print_insn): Likewise.
	* ia64-gen.c (fetch_insn_class): Likewise.
	(parse_resource_users): Likewise.
	(in_iclass): Likewise.
	(lookup_specifier): Likewise.
	(insert_opcode_dependencies): Likewise.
	* mips-dis.c (parse_mips_ase_option): Likewise.
	(parse_mips_dis_option): Likewise.
	* s390-dis.c (disassemble_init_s390): Likewise.
	* wasm32-dis.c (parse_wasm32_disassembler_options): Likewise.
2021-03-22 11:01:43 +01:00
Alexander Fedotov
dbb078f66e When displaying ARM private file flag bits, use a 0x prefix.
* elf32-arm.c (elf32_arm_print_private_bfd_data): Prefix hex value
	of private flags with 0x.
	* elfnn-aarch64.c (elfNN_aarch64_print_private_bfd_data): Likewise.
2021-01-04 15:13:57 +00:00
Alan Modra
250d07de5c Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
Alan Modra
5160d0f323 PR26979, Visibility of undefined foo@v1 should constrain foo@@v1
Also, undefined foo should constrain the visibility of foo@@v1 just as
it does for a later plain foo definition.

bfd/
	PR 26979
	* elf-bfd.h (elf_backend_merge_symbol_attribute): Update prototype.
	* elf32-m68hc1x.h (elf32_m68hc11_merge_symbol_attribute): Likewise.
	* elfxx-mips.h (_bfd_mips_elf_merge_symbol_attribute): Likewise.
	* elfxx-x86.h (_bfd_x86_elf_merge_symbol_attribute): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_merge_symbol_attribute): Replace
	isym parameter with st_other.  Adjust code.
	* elf64-alpha.c (elf64_alpha_merge_symbol_attribute): Likewise.
	* elf64-ppc.c (ppc64_elf_merge_symbol_attribute): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_merge_symbol_attribute): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_merge_symbol_attribute): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_merge_symbol_attribute): Likewise.
	* elflink.c (elf_merge_st_other): Likewise.
	(_bfd_elf_merge_symbol, elf_link_add_object_symbols): Adjust to suit.
	(_bfd_elf_copy_link_hash_symbol_type): Likewise.
	(_bfd_elf_add_default_symbol): Merge st_other from undecorated
	symbol and @VER symbol to @@VER symbol.
ld/
	* testsuite/ld-elf/pr26979a.s,
	* testsuite/ld-elf/pr26979b.s,
	* testsuite/ld-elf/pr26979c.s,
	* testsuite/ld-elf/pr26979.ver,
	* testsuite/ld-elf/pr26979a.d,
	* testsuite/ld-elf/pr26979b.d: New tests.
2020-12-01 11:26:35 +10:30
Siddhesh Poyarekar
c7cd291722 aarch64: Return an error on conditional branch to an undefined symbol
The fix in 7e05773767 introduced a PLT
for conditional jumps when the target symbol is undefined.  This is
incorrect because conditional branch relocations are not allowed to
clobber IP0/IP1 and hence, should not result in a dynamic relocation.

Revert that change and in its place, issue an error when the target
symbol is undefined.

bfd/

	2020-09-10  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Revert
	changes in 7e05773767.  Set
	error for undefined symbol in BFD_RELOC_AARCH64_BRANCH19 and
	BFD_RELOC_AARCH64_TSTBR14 relocations.

ld/

	2020-09-10  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

	* testsuite/ld-aarch64/emit-relocs-560.d: Expect error instead
	of valid output.
2020-09-10 21:42:37 +05:30
Alan Modra
26009aa763 ubsan elfnn-aarch64.c:7142 shift exponent 32 is too large
* elfnn-aarch64.c (elfNN_aarch64_relocate_section): Correct type
	of constant shifted left.
2020-09-02 16:30:42 +09:30