Age | Commit message (Collapse) | Author | Files | Lines |
|
PR ld/32572
There are two problems addressed in this PR. Firstly, the choice of
whether or not a PLT stub needs a BTI on entry was too strict,
resulting in non-pie executables not having a BTI on their stub. But
secondly, the logic to handle each stub types did not agree across the
various places where this information is used.
The first issue is fixed by using bfd_link_executable rather than
bfd_link_pde. The second is addressed by recording a delta for PLT
stub alongside the stub itself. This is then used without needing
additional logic later on since it has been pre-calculated.
A more comprehensive fix would involve creating a data structure to
describe each fixup, including a call-back function to apply any
relocations. But that's a fairly large change and not appropriate for
backporting.
|
|
Even if the assembler avoids using relaxable relocations for
inapplicable insns, such relocations can still appear for other reasons.
Be more thorough in the opcode checking we do, to avoid bogusly altering
other insns.
Furthermore correct an opcode mask (even if with the added condition
that's now fully benign).
|
|
If legacy-encoded arithmetic insns are eligible for @gotpcrel
relaxation, EVEX-encoded ones ought to be, too.
Further anything that MOV-from-memory can be used for (and transformed
from) should then also extend to MOVRS.
While extending the apx-load* testcases add -mrelax-relocations=yes to
the two ones which were missing this: Without this option the intended
testing would not occur on configurations defaulting the option to off.
|
|
|
|
[In the sequel TS means $(top_srcdir) and TB means $(top_builddir)]
The Texinfo file TS/bfd/doc/bfd.texi @includes many other .texi files
such as:
bfdt.texi
bfdio.texi
section.texi
...
These .texi files are generated from the bfd/*.c source files, by a
program called `chew' that is distributed along with BFD, via some
default rules and macro magic in TS/bfd/doc/local.mk. Important
point: the .texi files are generated in TB/bfd/doc/, not TS/bfd/doc.
Now, AM_MAKEINFOFLAGS in local.mk is defined as:
AM_MAKEINFOFLAGS = --no-split -I "$(srcdir)/%D%" -I %D%
Where %D% is 'doc/' in this case. Now, it looks like the directory
containing the .texi file is automatically inserted in the @include
search path, so the -I %D% above places TB/bfd/doc _after_ TS/bfd/doc.
Since currently TS/bfd/doc/bfdt.texi is outdated and is missing some
nodes, the error above happens.
This patch changes bfd/doc/local.mk to use -P to prepend the current
build directory to the @include search path, rather than -I, which
appends it.
bfd/ChangeLog:
2025-01-23 Jose E. Marchesi <jose.marchesi@oracle.com>
* doc/local.mk (AM_MAKEINFOFLAGS): Prepend the build directory to
the @include search path.
* Makefile.in: Regenerate.
|
|
When pure-code option is activated. The linker creates for M-profile architecures
a 2-bytes branch instruction. This causes the section alignment to be set to 2-byte
alignment instead of 4-byte alignment. This is a problem for long branch stub
without pure-code section as it contains a 32-bit address as data, which is expected
to be 4-byte aligned. Hence creating a long branch stub for PureCode section followed
by a long branch stub will result in a misalignment for the 32-bit address.
An easy fix is to add a nop instruction after the branch to keep the section alignment
to 4 bytes.
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Co-authored-by: Guillaume VACHERIAS <guillaume.vacherias@st.com>
|
|
bfd_make_readable leaks memory that could be freed by
_free_cached_info except that does too much in releasing all bfd
memory. (The fact that we had to hack around keeping the bfd filename
also indicates that releasing all bfd memory was too much.) So this
patch moves code releasing bfd_alloc'd memory to the COFF
_free_cached_info, where the syms and suchlike are released. This is
the memory that archive handling wants to release in the call there to
bfd_free_cached_info.
* coffgen.c (_bfd_coff_free_cached_info): Release syms.
* opncls.c (_bfd_new_bfd): Correct error return path.
(_bfd_free_cached_info): Don't kill all abfd->memory.
(_bfd_delete_bfd): Adjust fallback for bfd_free_cached_info.
(bfd_make_readable): Call target bfd_free_cached_info and
_bfd_free_cached_info plus reinstate section_htab.
|
|
u.compact.extries wasn't being freed anywhere. Free it when
destroying the linker hash table. Also free u.dwarf.aray there in
case errors result in the linker not getting to the slightly earlier
free in write_dwarf_eh_frame_hdr.
* elf-eh-frame.c (write_dwarf_eh_frame_hdr): Don't exit without
freeing u.dwarf.array.
* elflink.c (_bfd_elf_link_hash_table_free): Free u.compact.entries
and u.dwarf.array.
|
|
This one happens with --gc-sections and a linker script that either
discards some or all .eh_frame sections (eg. ld-elf/pr14265 test) or
maps an input .eh_frame to some other named output section. In that
case the discarded/renamed .eh_frame won't have local_cies freed.
* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Correct comment.
* elf.c (_bfd_elf_free_cached_info): Free eh_frame cies.
|
|
|
|
After commit:
commit bd32be01c997f686ab0b53f0640eaa0aeb61fbd3
Date: Fri Dec 3 00:23:20 2021 -0500
bfd: merge doc subdir up a level
And the follow-up commit:
commit 98b1464bdf6306a8ab4614b5e9f76cdb2dd00b33
Date: Wed Oct 2 22:58:08 2024 +0300
bfd: fix unnecessary bfd.info regen
There is still a problem building the bfd docs from a release tar
file.
As the release tar file contains the pre-generated .texi files we
expect the bfd/doc build stage to symlink to the pre-existing .texi
files in the source tree.
However, this is still not working as expected if $(srcdir) is
relative. The problem is this line in REGEN_TEXI:
test -e $$texi || test ! -f $(srcdir)/$$texi || $(LN_S) $(srcdir)/$$texi $$texi; \
This is executed from the build/bfd/ directory, so if $(srcdir) is
relative, then this will get you from the bfd/ directory in the build
tree to the corresponding bfd/ directory in the src tree. However,
the symlink is created in the bfd/doc/ build directory. The relative
path will then fail to take you to the bfd/ directory in the src
tree.
Fix this by using $(abs_srcdir) when creating the symlink.
Approved-By: Nick Clifton <nickc@redhat.com>
|
|
|
|
|
|
|
|
* elflink.c (elf_link_add_object_symbols): Free old_strtab
in another code path. Revert one unnecessary change in last
patch.
|
|
This fixes an error path in _bfd_elf_get_dynamic_symbols, fixes the
minimum size required when reading DT_HASH header, and tidies
formatting in a few places. Nit-fixes all.
Very likely we shouldn't be trying to mmap DT_DYNAMIC as it won't be
large enough for the mmap size threshold.
* elf.c (_bfd_elf_get_dynamic_symbols): Use _bfd_munmap_temporary
in error return path rather than free. Corrent size passed to
offset_from_vma when reading DT_HASH header. Formatting.
|
|
|
|
This arranges to free section relocs cached in elf_section_data. To
do that, some relocs stored there need to use bfd_malloc buffers
rather than bfd_alloc ones.
* elf.c (_bfd_elf_free_cached_info): Free relocs.
* elf32-ppc.c (ppc_elf_relax_section): Realloc relocs rather
than malloc, copy, free old.
* elf64-ppc.c (get_relocs): bfd_malloc relocs.
* elflink.c (_bfd_elf_link_info_read_relocs): Always
bfd_malloc relocs.
|
|
This modifies _bfd_elf_free_cached_info to unmap/free section
contents. To do that we need to *not* free sections where contents
are bfd_alloc'd or point to constant strings or somesuch. I've chosen
to implement this be adding another flag to struct bfd_section,
"alloced" to say the section contents can't be freed. Most of the
patch is about setting that flag in many places.
|
|
Do unmap/free cached contents to avoid some memory leaks we'd
otherwise see.
* elf.c (_bfd_elf_munmap_section_contents): Clear pointers to
contents that we unmap/free rather than not unmapping/freeing.
|
|
|
|
|
|
|
|
The "of course to free outsymbols" turned out to be wrong. outsymbols
belongs to objcopy which frees them, so commit 6ca01b0bdd59 introduced
a double free.
* srec.c (srec_write_symbols): Don't free outsymbols.
* tekhex.c (tekhex_write_object_contents): Likewise.
|
|
|
|
The type transition of TLSDESC is only done when -mrelax is enabled.
So when -mno-relax is enabled, keep GOT_TLS_GDESC to allocate the
GOT entry instead of just keeping GOT_TLS_IE.
|
|
Even though the relocation isn't IRELATIVE, it still should be come last if
refering to ifunc symbol. In order to get the ifunc relocs properly sorted
the correct class needs to be returned. The code mimics what has been done
for x86, sparc, aarch64 and arm32.
bfd/
PR 18841
PR 32499
* elfnn-riscv.c (riscv_reloc_type_class): Handle ifunc relocation
ordering, even though it's not IRELATIVE, it still should be come
last if refering ifunc symbol.
|
|
score_elf_create_dynamic_relocation sets up three output dynamic
relocs from rel[0], rel[1] and rel[2]. When rel[0] is the last reloc
in a section this of course results in a buffer overflow. It's a
weird thing to do given that only one relocation is output.
* elf32-score.c (score_elf_create_dynamic_relocation): Do not
set up three dynamic relocations when only one is output.
* elf32-score7.c: Likewise.
|
|
* elf64-mmix.c (mmix_elf_relocate_section): Correct size of
relocs shuffled by memmove.
|
|
|
|
https://github.com/riscv/riscv-cfi/releases/tag/v1.0
This patch only support the CFI instructions and CSR in assembler.
|
|
https://github.com/riscv/riscv-control-transfer-records/releases/tag/v1.0
The privileged spec v1.10 already removed the sfence.vm instruction, and the
encoding of sfence.vm instruction is overlapped with the sctrclr instruction
of ssctr/smctr. But since the privileged spec v1.10 already removed the
sfence.vm, and we no longer support the privileged spec v1.9.1 for now, we
had to remove the sfence.vm.
bfd/
* elfxx-riscv.c (riscv_implicit_subsets): Imply zicsr for ssctr/smctr.
(riscv_supported_std_s_ext): Added ssctr/smctr with version 1.0.
(riscv_multi_subset_supports): Handle INSN_CLASS for ssctr/smctr.
(riscv_multi_subset_supports_ext): Likewise.
gas/
* config/tc-riscv.c (enum riscv_csr_class, riscv_csr_address):
Added and handle CSR_CLASS_SSCTR and CSR_CLASS_SMCTR.
(riscv_is_priv_insn): Removed SFENCE_VM check.
* testsuite/gas/riscv/attribute-14e.d: Removed since sfence.vm is no
longer supported since privileged spec v1.10.
* testsuite/gas/riscv/attribute-14.s: Likewise.
* testsuite/gas/riscv/csr-version-1p10.d: Updated for ssctr/smctr CSRs.
* 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.
* testsuite/gas/riscv/csr.s: Likewise.
* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
* testsuite/gas/riscv/csr-dw-regnums.s: Likewise.
* testsuite/gas/riscv/march-help.l: Updated for ssctr/smctr.
* testsuite/gas/riscv/smctr-ssctr.d: New testcase for sctr instruction.
* testsuite/gas/riscv/smctr-ssctr.s: Likewise.
include/
* opcode/riscv-opc.h: Added encoding macro for sctrclr, but removed
encoding macro for sfence.vm since encoding conflict. Added CSR
numbers for ssctr/smctr CSRs.
* opcode/riscv.h (enum riscv_insn_class): Added
INSN_CLASS_SMCTR_OR_SSCTR for sctrclr.
opcodes/
* riscv-opc.c (riscv_opcodes): Added sctrclr, but removed sfence.vm
since encoding conflict.
|
|
|
|
* elf32-ppc.c (add_stub_sym): Alloc the sym name.
|
|
I've freed htab->relr in two places, first when we're done with it
in ppc64_elf_build_stubs, and also when freeing the hasn table to
catch cases where the linker exits early due to errors.
* elf64-ppc.c (ppc64_elf_link_hash_table_free): Free htab->relr.
(ppc64_elf_build_stubs): Also free it here.
(ppc_add_stub): Copy stub_name when creating..
(ppc64_elf_size_stubs): ..and always free stub_name.
(opd_entry_value): Free sym.
(ppc_build_one_stub): bfd_alloc stub sym name.
(build_global_entry_stubs_and_plt): Likewise.
(ppc64_elf_setup_section_lists): bfd_zalloc htab->sec_info.
|
|
This fixes leaks of outsymbols for various targets that use the
generic linker. The key fix here is to not generate output symbols
for targets that won't ever write symbols, and of course to free
outsymbols after they've been written in targets that do. Target
vector object_flags and section_flags are updated to better reflect
target capabilities, in particular not setting HAS_SYMS or SEC_RELOC
when the target does not support symbols or relocs.
* binary.c (binary_vec): Update section_flags.
* linker.c (generic_add_output_symbol): Don't add to
outsymbols if !HAS_SYMS.
* srec.c (srec_write_symbols): Free outsymbols on return.
(srec_vec): Update object_flags and section_flags.
(symbolsrec_vec): Likewise.
* tekhex.c (tekhex_write_object_contents): Free outsymbols on
return.
(tekhex_vec): Update object_flags and section_flags.
* verilog.c (verilog_vec): Likewise.
|
|
* binary.c (binary_sizeof_headers): Delete function. Define
instead.
* ihex.c (ihex_sizeof_headers): Likewise.
(ihex_vec): Use _bfd_nosymbols for BFD_JUMP_TABLE_SYMBOLS. Delete
now unused defines.
* verilog.c: Delete unused defines.
|
|
Some of the declarations in genlink.h are not used in current sources
apart from needing them in linker.c, so delete and/or move them there.
The patch also fixes a FIXME. It's actually quite easy to return
a failure from a hash traversal function.
* genlink.h (_bfd_generic_link_hash_newfunc): Delete.
(_bfd_generic_link_output_symbols),
(generic_write_global_symbol_info),
(_bfd_generic_link_write_global_symbol): Move to..
* linker.c: ..here, making functions static.
(generic_write_global_symbol_info): Add "failed".
(_bfd_generic_final_link): Handle wginfo.failed.
(_bfd_generic_link_write_global_symbol): Set wginfo->failed
on memory failures and return false rather than aborting.
|
|
|
|
This fixes some x86 memory leaks. I think it would be possible to
free the relr data in _bfd_elf_x86_finish_relative_relocs if we
wanted to reclaim some memory earlier, but for tidying after errors we
likely would need to free in the hash_table_free function anyway.
_bfd_x86_elf_link_relax_section is called via bfd_relax_section,
ie. whenever relaxation is enabled. This is a waste of time if
dt_relr relocs are not enabled since the function is there only to
handle relr.
* elfxx-x86.c (elf_x86_link_hash_table_free): Free relr data.
(_bfd_x86_elf_link_relax_section): Return early
if !info->enable_dt_relr. Do set "again" false before early
returns.
|
|
It is simpler to clear the buffer pointer in the caller than pass
a param that controls clearing.
* elf.c (elf_mmap_section_contents): Remove final_link param.
(_bfd_elf_mmap_section_contents): Instead set *buf to NULL here.
(_bfd_elf_link_mmap_section_contents): Adjust.
|
|
Fix some memory leaks.
* elf64-x86-64.c (elf_x86_64_scan_relocs): Ensure error return
paths that should free relocs go via error_return.
|
|
This is a very strange and obsolete kind of import type; it is
used for imported data just like IMPORT_DATA - but with an extra
odd caveat.
The behaviour is explained at [1]; generating such import libraries
with current MSVC tools produces "warning LNK4087: CONSTANT keyword is
obsolete; use DATA".
While obsolete, some import libraries within the Microsoft WDK (Windows
Driver Kit) do contain such symbols, which currently are ignored by
binutils and produce warnings about "file format not recognized".
For IMPORT_CONST for a DLL exported symbol "foo", we should provide
the import library symbols "__imp_foo" and "foo". For IMPORT_DATA, we
only provide "__imp_foo", and for IMPORT_CODE, "foo" points at a thunk.
The odd/surprising thing for IMPORT_CONST is that the "foo" symbol also
points at the same thing as "__imp_foo", i.e. directly at the IAT
entry.
[1] https://learn.microsoft.com/en-us/cpp/build/importing-using-def-files
Signed-off-by: Martin Storsjö <martin@martin.st>
|
|
The Guarded Control Stack (GCS) feature requires that two things:
- at static link time, all the input objects of a link unit have to
be compatible with GCS.
- at runtime, the executable and the shared libraries which it
depends on have to be compatible with GCS.
Both of those criteria are checked with the GCS feature stored in
the GNU property note.
The previous patch, adding support for the GCS feature check in GNU
note properties for input objects, ignored the input dynamic objects.
Although this support was better than no check, it was still
delaying the detection of compatibility issues up to the runtime
linker.
In order to help the developer in detecting such an incompatibility
issue as early as possible, this patch adds a check for input dynamic
objects lacking the GCS marking. This check can be controlled via the
linker option '-z gcs-report-dynamic[=none|warning|error]'. By default,
if the option is omitted, it inherits the value from '-z gcs-report'.
However, the inherited value is capped to 'warning' as a user might
want to only report errors in the currently built module, and not the
shared dependencies. If a user also wants to error on GCS issues in
the shared libraries, '-z gcs-report-dynamic=error' will have to be
specified explicitly.
|
|
The name returned by this function is used in asection->name, so
needs to persist until a bfd is closed.
* section.c (bfd_get_unique_section_name): Return an alloc'd
string.
|
|
symtab_hdr.contents looks to be malloc'd memory, except in one case.
Change that one case to also be malloc'd and free when we are done.
* elf.c (swap_out_syms): bfd_malloc outbound_syms.
(_bfd_elf_free_cached_info): Free symtab_hdr.contents.
* elflink.c (init_reloc_cookie): Correct cache_size. locsyms
is an array of Elf_Internal_Sym.
|
|
Many targets leaked parts of the elf_link_hash_table. Fix that by
making _bfd_elf_link_hash_table_init set up hash_table_free correctly,
so that targets that extend elf_link_hash_table without adding
anything that needs freeing, will use _bfd_elf_link_hash_table_free.
* elflink.c (elf_link_add_object_symbols): Always free
nondeflt_vers. Don't return false without freeing.
(_bfd_elf_link_hash_table_init): Set hash_table_free here..
(_bfd_elf_link_hash_table_create): ..rather than here.
(elf_link_swap_symbols_out): Don't free strtab here..
(elf_link_add_object_symbols): ..do so here instead. Don't
omit freeing on some error return paths.
|
|
This is another case where an array isn't freed anywhere and needs to
persist a while, so allocate it with bfd_alloc.
* elf-sframe.c (sframe_decoder_init_func_bfdinfo): Add abfd
param. bfd_zalloc std_func_bfdinfo.
(_bfd_elf_parse_sframe): Adjust to suit.
|
|
The set_loc array attached to eh-frame sec_info isn't freed, and is
used in _bfd_elf_eh_frame_section_offset. Rather than finding a
suitable late stage of linking past any b_e_e_f_s_o use, I decided
this might as well persist until the bfd is closed.
Some memory is freed in _bfd_elf_discard_section_eh_frame_hdr, but
the function isn't always called, so fix that too.
* elf-eh-frame.c (_bfd_elf_parse_eh_frame): bfd_alloc the
set_loc array.
(find_merged_cie): Use bfd_malloc rather than malloc.
(_bfd_elf_discard_section_eh_frame_hdr): Move condition under
which this function does anything except free memory from..
* elflink.c (bfd_elf_discard_info): ..here.
|
|
|