Age | Commit message (Collapse) | Author | Files | Lines |
|
Check for output buffer overruns.
* elf32-ppc.c (swap_reloc_out, count_and_swap_reloc_out): New
functions. Use throughout file.
* elf64-ppc.c (swap_reloc_out, count_and_swap_reloc_out): Likewise.
|
|
A number of backends want to return bfd_reloc_dangerous messaqes from
relocation special_function, and construct the message using asprintf.
Such messages are not freed anywhere, leading to small memory leaks
inside libbfd. To limit the leaks, I'd implemented a static buffer in
the ppc backends that was freed before use in asprintf output. This
patch extends that scheme to other backends using a shared static
buffer and goes further in freeing the buffer on any bfd_close.
The patch also fixes a few other cases where asprintf output was not
freed after use.
bfd/
* bfd.c (_input_error_msg): Make global and rename to..
(_bfd_error_buf): ..this.
(bfd_asprintf): New function.
(bfd_errmsg): Use bfd_asprintf.
* opncls.c (bfd_close_all_done): Free _buf_error_buf.
* elf32-arm.c (find_thumb_glue, find_arm_glue): Use bfd_asprintf.
* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
* elf32-ppc.c (ppc_elf_unhandled_reloc): Likewise.
* elf64-ppc.c (ppc64_elf_unhandled_reloc): Likewise.
* elfnn-riscv.c (riscv_resolve_pcrel_lo_relocs): Likewise.
(riscv_elf_relocate_section): Likewise.
* libbfd.h: Regenerate.
gas/
* read.c (read_end): Free current_name and current_label.
(do_s_func): Likewise on error path. strdup label.
ld/
* pe-dll.c (make_head, make_tail, make_one),
(make_singleton_name_thunk, make_import_fixup_entry),
(make_runtime_pseudo_reloc),
(pe_create_runtime_relocator_reference: Free oname after use.
|
|
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.
|
|
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.
|
|
PowerPC64 ELFv1 object files should have at most one .opd section, and
OPD handling in elf64-ppc.c makes use of this fact by caching some
.opd section info in the per-object bfd.tdata. This was done to avoid
another word in the target specific section data. Of course, fuzzers
don't respect the ABI, and even non-malicious users can accidentally
create multiple .opd sections. So it is better to avoid possible
buffer overflows and other confusion when OPD handling for a second
.opd section references data for the first .opd section, by keeping
the data per-section.
The patch also fixes a memory leak, and a corner case where I think we
could hit an assertion in opd_entry_value or read out of bounds in
ppc64_elf_branch_reloc doing a final link producing non-ppc64 output.
(It's a really rare corner case because not only would you need to be
linking ppc64 objects to non-ppc64 output, you'd also need a branch
reloc symbol to be defined in a .opd section of a non-ppc64 input.)
* elf64-ppc.c (is_ppc64_elf): Move earlier in file.
(ppc64_elf_branch_reloc): Check symbol bfd before accessing
ppc64 elf specific data structures.
(struct ppc64_elf_obj_tdata): Move opd union..
(struct _ppc64_elf_section_data): ..to here.
(ppc64_elf_before_check_relocs): Allow for opd sec_type
already set to sec_opd.
(ppc64_elf_check_relocs): Only set sec_type to sec_toc when
unset. Error for unexpected toc relocs.
(opd_entry_value): Return -1 when non-ppc64 rather than
asserting. Check and set sec_type too. Adjust for changed
location of contents and relocs.
(ppc64_elf_relocate_section): Adjust for changed location of
cached .opd relocs.
(ppc64_elf_free_cached_info): New function.
(bfd_elf64_bfd_free_cached_info): Define.
|
|
As a developer it is sometimes useful to know how many times stubs
have been resized. Report the count for users too, in ld --stats.
|
|
This is a fuzzing PR, with a testcase involving a SHF_ALLOC and
SHF_COMPRESSED SHT_RELA section, ie. a compressed dynamic reloc
section. BFD doesn't handle compressed relocation sections, with most
of the code reading relocs using sh_size (often no bfd section is
created) but in the case of SHF_ALLOC dynamic relocs we had some code
using the bfd section size. This led to a mismatch, sh_size is
compressed, size is uncompressed, and from that some uninitialised
memory. Consistently using sh_size is enough to fix this PR, but I've
also added tests to exclude SHF_COMPRESSED reloc sections from
consideration.
PR 30362
* elf.c (bfd_section_from_shdr): Exclude reloc sections with
SHF_COMPRESSED flag from normal reloc processing.
(_bfd_elf_get_dynamic_reloc_upper_bound): Similarly exclude
SHF_COMPRESSED sections from consideration. Use sh_size when
sizing to match slurp_relocs.
(_bfd_elf_canonicalize_dynamic_reloc): Likewise.
(_bfd_elf_get_synthetic_symtab): Use NUM_SHDR_ENTRIES to size
plt relocs.
* elf32-arm.c (elf32_arm_get_synthetic_symtab): Likewise.
* elf32-ppc.c (ppc_elf_get_synthetic_symtab): Likewise.
* elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Likewise.
* elfxx-mips.c (_bfd_mips_elf_get_synthetic_symtab): Likewise.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
* 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.
|
|
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.
|
|
save_res stubs aren't written in ppc_build_one_stub, their offsets
(which are zero) should not be checked.
* elf64-ppc.c (ppc_build_one_stub): Don't check save_res offsets.
|
|
Let's show the current stub as well as the previous one. Of interest
is the current offset and a new field, id. Check that the build
hash table traversal is in the same order as sizing traversal too.
* elf64-ppc.c (struct ppc_stub_hash_entry): Add id.
(struct ppc_link_hash_table): Add stub_id.
(stub_hash_newfunc): Init id and symtype.
(dump_stub): New function, extracted from..
(dump_previous_stub): ..here. Deleted.
(ppc_build_one_stub): Sanity check stub id as well as offset.
Show current stub as well as previous.
(ppc_size_one_stub): Set stub id.
(ppc64_elf_size_stubs): Init stub_id before traversal.
(ppc64_elf_build_stubs): Likewise.
|
|
powerpc64le-linux-ld is failing the assertion in ppc_build_one_stub,
again apparently, which means a stub will overwrite the tail of a
previous stub. The difficulty with debugging these issues is that
it's not a problem with the stub that triggers the assertion, but the
previous stub in that section. This patch keeps track of the last
stub and adds a debug dump. Hopefully that will help.
* elf64-ppc.c (enum _ppc64_sec_type): Add sec_stub.
(struct _ppc64_elf_section_data): Add u.last_ent.
(dump_previous_stub): New function.
(ppc_build_one_stub): Keep track of previous stub, and dump it
when finding an overlapping stub.
|
|
The "HOWTO size encoding" patch put 1 as the HOWTO size arg for
numerous howtos that are unused, describe dynamic relocs, are markers,
or otherwise are special purpose reloc howtos that don't care about
the size. The idea was to ensure no howto changed by inspecting
object files. Revert those changes, making them zero size.
* coff-alpha.c: Give special purpose reloc howtos a size of zero.
* coff-mcore.c, * elf-hppa.h, * elf-m10300.c, * elf32-arm.c,
* elf32-csky.c, * elf32-m32c.c, * elf32-m68k.c, * elf32-mep.c,
* elf32-mips.c, * elf32-ppc.c, * elf32-rx.c, * elf32-s390.c,
* elf32-spu.c, * elf32-tic6x.c, * elf32-tilepro.c, *elf32-vax.c,
* elf32-xtensa.c, * elf64-alpha.c, * elf64-mips.c,
* elf64-mmix.c, * elf64-ppc.c, * elf64-s390.c, * elfn32-mips.c,
* elfxx-loongarch.c, * elfxx-riscv.c, * elfxx-sparc.c,
* elfxx-tilegx.c, * som.c, * vms-alpha.c: Likewise.
|
|
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.
|
|
Tidy the dynamic reloc handling code in check_relocs, removing
leftover comments and code from when check_relocs was called as each
object file was read in.
* elf64-ppc.c (ppc64_elf_check_relocs): Tidy dynamic reloc
handling code.
(dec_dynrel_count): Do the same here.
|
|
|
|
Section addresses can change between ppc64_elf_size_stubs and
ppc64_elf_build_stubs due to .eh_frame editing. The idea of stashing
r_offset final addresses calculated in ppc64_elf_size_stubs for use by
ppc64_elf_build_stubs was never a good idea. Instead, we need to keep
section/offset pairs.
* elf64-ppc.c (struct ppc_link_hash_table): Delete relr_addr.
Add relr section/offset array.
(append_relr_off): Rewrite. Update all callers.
(sort_relr): New function.
(ppc64_elf_size_stubs): Adjust to suit new relative reloc stash.
(ppc64_elf_build_stubs): Likewise.
|
|
Now that ld properly aligns the end of the relro segment, the hack to
make relro work on powerpc can disappear.
bfd/
* bfd.c (bfd_emul_get_commonpagesize): Remove relro param.
Don't return bed->relropagesize.
* elf-bfd.h (struct elf_backend_data): Remove relropagesize.
* elfxx-target.h (ELF_RELROPAGESIZE): Remove.
* elf32-ppc.c (ELF_RELROPAGESIZE): Don't define.
* elf64-ppc.c: Likewise.
* bfd-in2.h: Regenerate.
ld/
* ldemul.c (after_parse_default): Adjust
bfd_emul_get_commonpagesize call.
|
|
elf64-ppc.c: In function 'ppc64_elf_size_dynamic_sections':
elf64-ppc.c:10309:45: error: value computed is not used [-Werror=unused-value]
++lgot_ents, ++lgot_masks, isym != NULL && isym++)
It is of course a silly warning, fixed in later versions of gcc. I
wrote "isym != NULL && isym++" rather than the simpler "isym++" to
stop sanitisers complaining about incrementing a NULL pointer. isym
is of course unused in any code path where it might start off as
NULL. Sometimes you can't win. So don't try to be clever in reading
local symbols only when needed. 99 times out of 100 they will be
cached anyway.
* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Avoid annoying
warnings by always reading local syms.
(ppc64_elf_layout_multitoc): Likewise.
|
|
Supporting -static-pie on PowerPC64 requires the linker to properly
treat SHN_ABS symbols for cases like glibc's _nl_current_LC_CTYPE_used
absolute symbol. I've been slow to fix the linker on powerpc because
there is some chance that this will break some shared libraries or
PIEs.
bfd/
* elf64-ppc.c (ppc64_elf_check_relocs): Consolidate local sym
handling code. Don't count dyn relocs against non-dynamic
absolute symbols.
(dec_dynrel_count): Adjust to suit.
(ppc64_elf_edit_toc): Don't remove entries for absolute symbols
when pic.
(allocate_got): Don't allocate space for got relocs against
non-dynamic absolute syms.
(ppc64_elf_layout_multitoc): Likewise.
(got_and_plt_relr): Likewise.
(ppc64_elf_size_dynamic_sections): Likewise for local got.
(got_and_plt_relr_for_local_syms): Likewise.
(ppc64_elf_size_stubs): Don't allocate space for relr either.
(ppc64_elf_relocate_section): Don't write relocs against non-dynamic
absolute symbols. Don't optimise got and toc code sequences
loading absolute symbol entries.
ld/
* testsuite/ld-powerpc/abs-reloc.s,
* testsuite/ld-powerpc/abs-static.d,
* testsuite/ld-powerpc/abs-static.r,
* testsuite/ld-powerpc/abs-pie.d,
* testsuite/ld-powerpc/abs-pie.r,
* testsuite/ld-powerpc/abs-shared.d,
* testsuite/ld-powerpc/abs-shared.r,
* testsuite/ld-powerpc/abs-pie-relr.d,
* testsuite/ld-powerpc/abs-pie-relr.r,
* testsuite/ld-powerpc/abs-shared-relr.d,
* testsuite/ld-powerpc/abs-shared-relr.r: New tests.
* testsuite/ld-powerpc/powerpc.exp: Run them.
|
|
In trying to find a testcase for PR28827, I managed to hit a linker
error in bfd_set_section_contents with a .branch_lt input section
being too large for the output .branch_lt.
bfd/
PR 28827
* elf64-ppc.c (ppc64_elf_size_stubs): Set section size to
maxsize past STUB_SHRINK_ITER before laying out. Remove now
unnecessary conditional setting of maxsize at start of loop.
ld/
* testsuite/ld-powerpc/pr28827-2.d,
* testsuite/ld-powerpc/pr28827-2.lnk,
* testsuite/ld-powerpc/pr28827-2.s: New test.
* testsuite/ld-powerpc/powerpc.exp: Run it.
|
|
The previous patch wasn't quite correct. The size and padding depends
on offset used in the current iteration, and if we're fudging the
offset past STUB_SHRINK_ITER then we'd better use that offset. We
can't have plt_stub_pad using stub_sec->size as the offset.
PR 28827
* elf64-ppc.c (plt_stub_pad): Add stub_off param.
(ppc_size_one_stub): Set up stub_offset to value used in this
iteration before sizing the stub. Adjust plt_stub_pad calls.
|
|
* elf64-ppc.c (ppc64_elf_relocate_section): Warn if the symbol
on R_PPC64_TOC isn't local.
|
|
The assertion is this one in ppc_build_one_stub
BFD_ASSERT (stub_entry->stub_offset >= stub_entry->group->stub_sec->size);
It is checking that a stub doesn't overwrite the tail of a previous
stub, so not something trivial.
Normally, stub sizing iterates until no stubs are added, detected by
no change in stub section size. Iteration also continues if no stubs
are added but one or more stubs increases in size, which also can be
detected by a change in stub section size. But there is a
pathological case where stub section sizing decreases one iteration
then increases the next. To handle that situation, stub sizing also
stops at more than STUB_SHRINK_ITER (20) iterations when calculated
stub section size is smaller. The previous larger size is kept for
the actual layout (so that building the stubs, which behaves like
another iteration of stub sizing, will see the stub section sizes
shrink). The problem with that stopping condition is that it assumes
that stub sizing is only affected by addresses external to the stub
sections, which isn't always true.
This patch fixes that by also keeping larger individual stub_offset
addresses past STUB_SHRINK_ITER. It also catches a further
pathological case where one stub shrinks and another expands in such a
way that no stub section size change is seen.
PR 28827
* elf64-ppc.c (struct ppc_link_hash_table): Add stub_changed.
(STUB_SHRINK_ITER): Move earlier in file.
(ppc_size_one_stub): Detect any change in stub_offset. Keep
larger one if past STUB_SHRINK_ITER.
(ppc64_elf_size_stubs): Iterate on stub_changed too.
|
|
More fun with R_PPC64_NONE found in .opd. Fixed by the
allocate_dynrelocs and ppc64_elf_size_dynamic_sections changes, and
since we are doing ifunc, opd and SYMBOL_REFERENCES_LOCAL tests later,
don't duplicate that work in check_relocs.
* elf64-ppc.c (ppc64_elf_check_relocs): Remove opd and ifunc
conditions for rel_count.
(dec_dynrel_count): Likewise.
(allocate_dynrelocs): Test for opd and ifunc when allocating
relative relocs.
(ppc64_elf_size_dynamic_sections): Likewise.
|
|
Similarly to the local GOT case.
* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Don't allocate
space for PLT relocs against local syms when enable_dt_relr.
|
|
Fixes another case where we end up with superfluous R_PPC64_NONE.
* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Don't allocate
space for GOT relocs against non-TLS local syms when enable_dt_relr.
(ppc64_elf_layout_multitoc): Likewise.
|
|
HJ: "There are 238 R_PPC64_NONEs in libc.so.6 alone."
Indeed, let's make them go away. I had the SYMBOL_REFERENCES_LOCAL
test in the wrong place. check_relocs is too early to know whether a
symbol is dynamic in a shared library. Lots of glibc symbols are made
local by version script, but that doesn't happen until
size_dynamic_sections.
* elf64-ppc.c (ppc64_elf_check_relocs): Don't count relative relocs
here depending on SYMBOL_REFERENCES_LOCAL.
(dec_dynrel_count): Likewise.
(allocate_dynrelocs): Do so here instead.
|
|
ppc64_elf_check_init_fini
I see this error with clang-14:
CC elf64-ppc.lo
/home/smarchi/src/binutils-gdb/bfd/elf64-ppc.c:13131:11: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
return (check_pasted_section (info, ".init")
~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fix by replacing & with &&. But given that the check_pasted_section
function has side-effects and we want to make sure both calls are made,
assign to temporary variables before evaluating the `&&`.
Change-Id: I849e1b2401bea5f4d8ef3ab9af99ba9e3ef42490
|
|
PowerPC64 takes a more traditional approach to DT_RELR than x86. Count
relative relocs in check_relocs, allocate space for them and output in
the usual places but not doing so when enable_dt_relr. DT_RELR is
sized in the existing ppc stub relaxation machinery, run via the
linker's ldemul_after_allocation hook. DT_RELR is output in the same
function that writes ppc stubs, run via ldemul_finish.
This support should be considered experimental.
bfd/
* elf64-ppc.c (struct ppc_local_dyn_relocs): Renamed from
ppc_dyn_relocs. Add rel_count field. Update uses.
(struct ppc_dyn_relocs): New. Replace all uses of elf_dyn_relocs.
(struct ppc_link_hash_table): Add relr_alloc, relr_count and
relr_addr.
(ppc64_elf_copy_indirect_symbol): Merge rel_count.
(ppc64_elf_check_relocs): Init rel_count for global and local syms.
(dec_dynrel_count): Change r_info param to reloc pointer. Update
all callers. Handle decrementing rel_count.
(allocate_got): Don't allocate space for relative relocs when
enable_dt_relr.
(allocate_dynrelocs): Likewise.
(ppc64_elf_size_dynamic_sections): Likewise. Handle srelrdyn.
(ppc_build_one_stub): Don't emit relative relocs on .branch_lt.
(compare_relr_address, append_relr_off): New functions.
(got_and_plt_relr_for_local_syms, got_and_plt_relr): Likewise.
(ppc64_elf_size_stubs): Size .relr.syn.
(ppc64_elf_build_stubs): Emit .relr.dyn.
(build_global_entry_stubs_and_plt): Don't output relative relocs
when enable_dt_relr.
(write_plt_relocs_for_local_syms): Likewise.
(ppc64_elf_relocate_section): Likewise.
binutils/
* testsuite/lib/binutils-common.exp (supports_dt_relr): Add
powerpc64.
ld/
* emulparams/elf64ppc.sh: Source dt-relr.sh.
* testsuite/ld-elf/dt-relr-2b.d: Adjust for powerpc.
* testsuite/ld-elf/dt-relr-2c.d: Likewise.
* testsuite/ld-elf/dt-relr-2d.d: Likewise.
* testsuite/ld-elf/dt-relr-2e.d: Likewise.
|
|
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.
|
|
R_PPC64_REL24_P9NOTOC is a variant of R_PPC64_REL24_NOTOC for use on
@notoc cals from non-power10 code in the rare case that using such a
construct is useful. R_PPC64_REL24_P9NOTOC will be emitted by gas
rather than R_PPC64_REL24_NOTOC when @notoc is used in a branch
instruction if power10 instructions are not enabled at that point.
The new relocation tells the linker to not use power10 instructions on
any stub emitted for that branch, unless overridden by
--power10-stubs=yes.
The current linker heuristic of only generating power10 instructions
for stubs if power10-only relocations are detected, continues to be
used.
include/
* elf/ppc64.h (R_PPC64_REL24_P9NOTOC): Define.
bfd/
* reloc.c (BFD_RELOC_PPC64_REL24_P9NOTOC): Define.
* elf64-ppc.c (ppc64_elf_howto_raw): Add entry for new reloc.
(ppc64_elf_reloc_type_lookup): Handle it.
(enum ppc_stub_type): Delete.
(enum ppc_stub_main_type, ppc_stub_sub_type): New.
(struct ppc_stub_type): New.
(struct ppc_stub_hash_entry): Use the above new type.
(struct ppc_link_hash_table): Update stub_count.
(is_branch_reloc, ppc64_elf_check_relocs),
(toc_adjusting_stub_needed): Handle new reloc.
(stub_hash_newfunc, select_alt_stub, ppc_merge_stub),
(ppc_type_of_stub, plt_stub_size, build_plt_stub),
(build_tls_get_addr_head, build_tls_get_addr_tail),
(ppc_build_one_stub, ppc_size_one_stub, ppc64_elf_size_stubs),
(ppc64_elf_build_stubs, ppc64_elf_relocate_section): Handle new
reloc. Modify stub handling to suit new scheme.
* bfd-in2.h: Regenerate.
* libbfd.h: Regenerate.
gas/
* config/tc-ppc.c (ppc_elf_suffix): When power10 is not enabled
return BFD_RELOC_PPC64_REL24_P9NOTOC for @notoc.
(fixup_size, ppc_force_relocation, ppc_fix_adjustable): Handle
BFD_RELOC_PPC64_REL24_P9NOTOC.
ld/
* testsuite/ld-powerpc/callstub-2.s: Add .machine power10.
|
|
This patch removes any fake (linker created) function descriptor
symbol if its code entry symbol isn't dynamic, to ensure bogus dynamic
symbols are not created. The change to func_desc_adjust requires that
it be run only once, which means ppc64_elf_tls_setup can't call it for
just a few selected symbols.
PR 28523
* elf64-ppc.c (func_desc_adjust): If a function entry sym is
not dynamic and has no plt entry, hide any associated fake
function descriptor symbol.
(ppc64_elf_edit): Move func_desc_adjust iteration over syms to..
(ppc64_elf_tls_setup): ..here.
|
|
This hardens the powerpc64 linker code transformations.
* elf64-ppc.c (is_8byte_reloc, offset_in_range): New functions.
(ppc64_elf_relocate_section): Sanity check r_offset before
accessing section contents for various code transformations.
|
|
_bfd_elf_ppc_at_tprel_transform doesn't handle prefix instructions,
and I'm not inclined to implement code editing for them.
* elf64-ppc.c (ppc64_elf_relocate_section): Don't attempt tprel
transform for R_PPC64_TPREL34.
|
|
Adds missing bfd_reloc_offset_in_range checks to various relocation
special_functions.
PR 28307
* elf32-ppc.c (ppc_elf_addr16_ha_reloc): Range check reloc offset.
* elf64-ppc.c (ppc64_elf_ha_reloc, ppc64_elf_brtaken_reloc): Likewise.
(ppc64_elf_toc64_reloc, ppc64_elf_prefix_reloc): Likewise.
|
|
Blindly following x86 broke linux kernel builds.
bfd/
* elf32-ppc.c (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): Define as true.
* elf64-ppc.c (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): Likewise.
gas/
* testsuite/gas/ppc/power4.d: Adjust for section sym change.
* testsuite/gas/ppc/test1elf32.d: Likewise.
* testsuite/gas/ppc/test1elf64.d: Likewise.
ld/
* testsuite/ld-powerpc/tlsexe.r: Adjust for section sym change.
* testsuite/ld-powerpc/tlsexe32.r: Likewise.
* testsuite/ld-powerpc/tlsexe32no.r: Likewise.
* testsuite/ld-powerpc/tlsexeno.r: Likewise.
* testsuite/ld-powerpc/tlsexenors.r: Likewise.
* testsuite/ld-powerpc/tlsexers.r: Likewise.
* testsuite/ld-powerpc/tlsexetoc.r: Likewise.
* testsuite/ld-powerpc/tlsexetocrs.r: Likewise.
* testsuite/ld-powerpc/tlsget.d: Likewise.
* testsuite/ld-powerpc/tlsget.wf: Likewise.
* testsuite/ld-powerpc/tlsget2.d: Likewise.
* testsuite/ld-powerpc/tlsget2.wf: Likewise.
* testsuite/ld-powerpc/tlsso.r: Likewise.
* testsuite/ld-powerpc/tlsso32.r: Likewise.
* testsuite/ld-powerpc/tlstocso.r: Likewise.
|
|
This makes the default for ppc to keep dynamic relocs on undefweak
symbols when the code won't cause DT_TEXTREL (for instance when -fPIE
or -fPIC). If ld is given -z dynamic-undefined-weak then dynamic
relocations will be created for non-PIC at the expense of possibly
causing DT_TEXTREL to be set on ppc32. Note that DT_TEXTREL and GNU
indirect functions are incompatible.
* elf32-ppc.c (allocate_dynrelocs): Keep dyn_relocs for undefweak
symbols when -z dynamic-undefined-weak or when there are no
dynamic relocs in read-only sections and -z nodynamic-undefined-weak
is not given.
* elf64-ppc.c (allocate_dynrelocs): Likewise.
|
|
It's slightly weird to have a call to a weak function not protected by
a test of that function being non-NULL, but the non-NULL test might be
covered by a test of another function. For example:
if (func1)
{
func1 ();
func2 ();
}
where func2 is known to exist if func1 exists.
* elf32-ppc.c (allocate_dynrelocs): Call ensure_undef_dynamic for
weak undefined symols that only appear on PLT relocs.
* elf64-ppc.c (allocate_dynrelocs): Likewise.
|
|
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.
|
|
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.
|
|
elf_backend_archive_symbol_lookup might be called when the linker hash
table has entries of type generic_link_hash_entry. This happens for
instance when running the mmix target linker testsuite where the
output is mmo but input is elf64-mmix.
* elf-bfd.h (struct elf_backend_data): Return bfd_link_hash_entry*
from elf_backend_archive_symbol_lookup.
(_bfd_elf_archive_symbol_lookup): Return bfd_link_hash_entry*.
* elf64-ppc.c (ppc64_elf_archive_symbol_lookup): Likewise. Check
we have a ppc_hash_table before accessing ppc_link_hash_entry
fields.
* elflink.c (_bfd_elf_archive_symbol_lookup): Return
bfd_link_hash_entry*.
(elf_link_add_archive_symbols): Adjust to suit.
|