This patch fixes a case where a user had a C-representable named
section in both the executable and shared libraries, and of course
wanted the size of the local section in the executable, not the
dynamic section. It does mean that __start and __stop symbols don't
behave exactly like PROVIDEd symbols, but I think that's a reasonable
difference particularly since this is the way they used to behave.
* elflink.c (bfd_elf_define_start_stop): Override symbols when
they are defined dynamically.
https://bugzilla.redhat.com/show_bug.cgi?id=1523457
I haven't analyzed this myself, I'm relying on Nick's excellent
analysis. What I believe is happening is that after some number of
stub sizing iterations, a long-branch stub needs to be converted to a
plt-branch, but either due to stub alignment or other stubs shrinking
in size, the stub group section size doesn't change.
That means we exit from ppc64_elf_size_stubs after sizing with an
incorrect layout, in fact the additional .branch_lt entry overlays
.got! Since .TOC. is normally set to .got + 0x8000 the stub sizing
code decides that entry is within +/-32k of the TOC pointer and so a
three insn stub is sufficient. When we come to build the stubs using
a correct non-overlaying layout, a four insn plt-branch stub is
generated and the stub group size doesn't match that calculated
earlier.
* elf64-ppc.c (ppc64_elf_size_stubs): Iterate sizing when
.branch_lt changes size.
There are actually 2 different bugs:
1. TLS transition is broken in PIE mode.
2. TLS is broken in PIC/PIE mode when the __tls_get_addr symbol
is versioned (as is the case on Linux and Solaris at least).
The 1st bug is fixed by reverting the problematic change for now
(note that the associated test doesn't pass on SPARC because of another
issue so there is no formal regression in the testsuite). The 2nd bug
is fixed by changing the call to _bfd_generic_link_add_one_symbol
on __tls_get_addr into a mere lookup in _bfd_sparc_elf_check_relocs.
bfd/
* elfxx-sparc.c (_bfd_sparc_elf_check_relocs) <R_SPARC_TLS_GD_CALL>:
Do a mere lookup of the __tls_get_addr symbol instead of adding it.
Revert
2017-10-19 H.J. Lu <hongjiu.lu@intel.com>
PR ld/22263
* elfxx-sparc.c (sparc_elf_tls_transition): Replace
bfd_link_pic with !bfd_link_executable, !bfd_link_pic with
bfd_link_executable for TLS check.
(_bfd_sparc_elf_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
(_bfd_sparc_elf_relocate_section): Likewise.
ld/
* testsuite/ld-sparc/sparc.exp (32-bit: Helper shared library):
Link with a version script.
(32-bit: TLS -fpie): New test.
(64-bit: Helper shared library): Link with a version script.
(64-bit: TLS -fpie): New test.
(64-bit: GOTDATA relocations): Pass -Av9 to the assembler.
* testsuite/ld-sparc/tlslib.ver: New file.
* testsuite/ld-sparc/tlspie32.dd: Likewise.
* testsuite/ld-sparc/tlspie32.s: Likewise.
* testsuite/ld-sparc/tlspie64.dd: Likewise.
* testsuite/ld-sparc/tlspie64.s: Likewise.
* testsuite/ld-sparc/tlssunbin32.dd: Adjust for versioned symbol.
* testsuite/ld-sparc/tlssunbin32.rd: Likewise.
* testsuite/ld-sparc/tlssunbin32.sd: Likewise.
* testsuite/ld-sparc/tlssunbin64.dd: Likewise.
* testsuite/ld-sparc/tlssunbin64.rd: Likewise.
* testsuite/ld-sparc/tlssunbin64.sd: Likewise.
Update a stale reference to `mips_elf32_section_processing', following a
merge of the function into `_bfd_mips_elf_section_processing' made with
commit 103186c62b ("PATCH for MIPS 64-bit ABI suport"),
<https://sourceware.org/ml/binutils/1999-q3/msg00072.html>.
bfd/
* elfxx-mips.c (_bfd_mips_elf_final_link): Update a stale
`mips_elf32_section_processing' comment reference.
We need to check the versioned __tls_get_addr symbol when looking up
"__tls_get_addr".
bfd/
PR ld/22721
* elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Check the
versioned __tls_get_addr symbol.
ld/
PR ld/22721
* testsuite/ld-plugin/lto.exp: Run PR ld/22721 tests.
* testsuite/ld-plugin/pr22721.t: New file.
* testsuite/ld-plugin/pr22721a.s: Likewise.
* testsuite/ld-plugin/pr22721b.c: Likewise.
Asking for ppc32 plt call stubs to be aligned at 32 byte boundaries
didn't quite work. For ld.bfd they were spaced 32 bytes apart, but
only started on a 16 byte boundary. ld.gold also didn't get it right.
Finding that bug made me check over the ppc64 plt stub alignment,
where I found that negative values for alignment (meaning align to
minimize boundary crossing) were not accepted. Since no one has
complained about that, I guess I could have removed the feature from
ld.bfd documentation, but I've opted instead to correct the code.
I've also added an optional alignment paramenter for ppc32
--plt-align, for some consistency with gold and ppc64 ld.bfd.
bfd/
* elf32-ppc.c (ppc_elf_create_glink): Correct alignment of .glink.
* elf64-ppc.c (ppc64_elf_size_stubs): Handle negative plt_stub_align.
(ppc64_elf_build_stubs): Likewise.
gold/
* powerpc.cc (param_plt_align): New function supplying default
--plt-align values. Use it..
(Stub_table::plt_call_align): ..here, and..
(Output_data_glink::global_entry_align): ..here.
(Stub_table::stub_align): Correct 32-bit minimum alignment.
ld/
* emultempl/ppc32elf.em: Support optional --plt-align arg.
* emultempl/ppc64elf.em: Support negative --plt-align arg.
This is in preparation for the next patch adding Spectre variant 2
mitigation for PowerPC and PowerPC64. Besides tidying code involved
in stub output (to reduce the number of places where bctr is output),
the patch adds some user visible features:
1) PowerPC64 ELFv2 global entry stubs now are aligned under the
control of --plt-align, with a default alignment of 32 bytes.
2) PowerPC64 __glink_PLTresolve is no longer padded out with nops.
3) PowerPC32 PLT stubs are aligned under the control of --plt-align,
with the default alignment being 16 bytes as before.
4) The PowerPC32 branch/nop table emitted before __glink_PLTresolve
is now smaller in many cases. It was sized incorrectly when the
__tls_get_addr_opt stub was used, and unnecessarily included space
for local ifuncs.
bfd/
* elf32-ppc.c (GLINK_ENTRY_SIZE): Add parameters, handle
__tls_get_addr_opt, and alignment sizing.
(TLS_GET_ADDR_GLINK_SIZE): Delete.
(is_nonpic_glink_stub): Don't use GLINK_ENTRY_SIZE.
(ppc_elf_get_synthetic_symtab): Recognize stubs spaced at 4, 6,
or 8 insns.
(ppc_elf_link_hash_table_create): Init new ppc_elf_params field.
(allocate_dynrelocs): Use new GLINK_ENTRY_SIZE.
(ppc_elf_size_dynamic_sections): Likewise. Size branch table
by PLT reloc count.
(write_glink_stub): Handle __tls_get_addr_opt stub.
Pad out to size given by GLINK_ENTRY_SIZE.
(ppc_elf_relocate_section): Adjust write_glink_stub call.
(ppc_elf_finish_dynamic_symbol): Likewise.
(ppc_elf_finish_dynamic_sections): Write PLTresolve without using
insn array since so many need rewriting.
* elf32-ppc.h (struct ppc_elf_params): Add plt_stub_align.
* elf64-ppc.c (GLINK_PLTRESOLVE_SIZE): Rename from
GLINK_CALL_STUB_SIZE. Add htab param and evaluate to size without
nops. Adjust all uses.
(ppc64_elf_get_synthetic_symtab): Don't use GLINK_CALL_STUB_SIZE
in glink_vma calculation.
(struct ppc_link_hash_table): Add global_entry section pointer.
(create_linkage_sections): Create separate section for global
entry stubs.
(PPC_LO, PPC_HI, PPC_HA): Move earlier.
(size_global_entry_stubs): Handle sizing for aligned stubs.
(ppc64_elf_size_dynamic_sections): Handle global_entry alloc,
and don't stash end of glink branch table in rawsize.
(ppc_build_one_stub): Rewrite stub size calculations.
(build_global_entry_stubs): Use new section.
(ppc64_elf_build_stubs): Don't pad __glink_PLTresolve with nops.
Build lazy link stubs out to end of section. Build global entry
stubs in new section.
gold/
* options.h (plt_align): Support for PowerPC32 too.
* powerpc.cc (Stub_table::stub_align): Heed --plt-align for 32-bit.
(Stub_table::plt_call_size, branch_stub_size): Tidy.
(Stub_table::plt_call_align): Implement using stub_align.
(Output_data_glink::global_entry_align): New function.
(Output_data_glink::global_entry_off): New function.
(Output_data_glink::global_entry_address): Use global_entry_off.
(Output_data_glink::pltresolve_size): New function, replacing
pltresolve_size_ constant. Update all uses.
(Output_data_glink::add_global_entry): Align offset.
(Output_data_glink::set_final_data_size): Use global_entry_align.
(Stub_table::do_write): Don't pad __glink_PLTrelsolve with nops.
Tidy stub output. Use global_entry_off.
ld/
* emultempl/ppc32elf.em (params): Init new field.
(enum ppc32_opt): New enum to define OPTION_* values. Add
OPTION_PLT_ALIGN and OPTION_NO_PLT_ALIGN.
(PARSE_AND_LIST_LONGOPTS): Handle new options.
(PARSE_AND_LIST_ARGS_CASES): Likewise.
(PARSE_AND_LIST_OPTIONS): Likewise. Break up help output.
* emultempl/ppc64elf.em (ppc_add_stub_section): Init alignment
correctly for negative --plt-stub-align.
* testsuite/ld-powerpc/elfv2exe.d,
* testsuite/ld-powerpc/elfv2so.d,
* testsuite/ld-powerpc/relbrlt.d,
* testsuite/ld-powerpc/relbrlt.s,
* testsuite/ld-powerpc/tlsexe.d,
* testsuite/ld-powerpc/tlsexe.r,
* testsuite/ld-powerpc/tlsexe32.d,
* testsuite/ld-powerpc/tlsexe32.g,
* testsuite/ld-powerpc/tlsexe32.r,
* testsuite/ld-powerpc/tlsexetoc.d,
* testsuite/ld-powerpc/tlsexetoc.r,
* testsuite/ld-powerpc/tlsopt5_32.d,
* testsuite/ld-powerpc/tlsso.d,
* testsuite/ld-powerpc/tlstocso.d: Update for changed stub order.
When processing a section that is a member of a group, the group
that contains it is looked up using a linear search. The resulting
O(n^2) complexity causes significant performance issues when
dealing with object files with very many groups.
By remembering the index of the last found group and restarting
the next search from that index, the search instead becomes O(n)
in common cases.
* elf.c (setup_group): Optimize search for group by remembering
last found group and restarting search at that index.
* elf-bfd.h (struct elf_obj_tdata): Add group_search_offset field.
The default should be bfd_link_common_skip_none, as in the original
patch at https://sourceware.org/ml/binutils/2002-07/msg00717.html
* aoutx.h (aout_link_check_ar_symbols): Remove default and handle
bfd_link_common_skip_none in switch.
PowerPC64 has its own mark_dynamic_ref, which needs the same change as
made by d664fd41e1 to the generic ELF version. Some other targets
discard more than just .data, so allow for that too in expected ld
messages.
bfd/
PR ld/22649
* elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref): Ignore dynamic
references on forced local symbols.
ld/
PR ld/22649
* testsuite/ld-elf/pr22649.msg: Allow other messages.
* testsuite/ld-elf/shared.exp: Check that --gc-sections is
supported before running ld/22649 tests.
One of assertions in _bfd_mips_elf_final_link could be triggered by
a combination of input files and a linker script. This happens when
either the input doesn't contain .reginfo section or when this section
is oversized. This patch replaces the assertion with a more useful
error message.
* elfxx-mips.c (_bfd_mips_elf_final_link): Notify user when
.reginfo section has wrong size.
When generating separate code LOAD segment, create a new LOAD segment
if the previous section contains text and the current section doesn't
or vice versa:
Elf file type is DYN (Shared object file)
Entry point 0x200020
There are 7 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000000 0x00000000 0x00000000 0x00200 0x00200 R 0x200000
LOAD 0x200000 0x00200000 0x00200000 0x00036 0x00036 R E 0x200000
LOAD 0x400000 0x00400000 0x00400000 0x00064 0x00064 R 0x200000
LOAD 0x400f80 0x00600f80 0x00600f80 0x000a0 0x000a0 RW 0x200000
DYNAMIC 0x400f80 0x00600f80 0x00600f80 0x00080 0x00080 RW 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10
GNU_RELRO 0x400f80 0x00600f80 0x00600f80 0x00080 0x00080 R 0x1
Section to Segment mapping:
Segment Sections...
00 .hash .gnu.hash .dynsym .dynstr .rela.plt
01 .plt .text
02 .rodata .eh_frame
03 .dynamic .got.plt
04 .dynamic
05
06 .dynamic
to prevent fetching or executing data in code pages as instructions.
Also don't put a writable section in a read-only segment if there is a
RELRO segment.
Since code segment is aligned and padded to the maximum page size on
disk, the minimum file size is bigger than the maximum page size which
is 2MB (0x200000):
-rwxr-xr-x 1 hjl hjl 4201932 Jan 10 10:41 libfoo.so
"-z max-page-size=0x1000" can be used to reduce the maximum page size to
4KB (0x1000):
-rwxr-xr-x 1 hjl hjl 15820 Jan 10 10:44 libfoo.so
PR ld/22393
* elf.c (_bfd_elf_map_sections_to_segments): When generating
separate code and read-only data LOAD segments, create a new
LOAD segment if the previous section contains text and the
current section doesn't or vice versa. Don't put a writable
section in a read-only segment if there is a RELRO segment.
We should ignore dynamic references on forced local symbols during
garbage collection since they can never be referenced dynamically.
bfd/
PR ld/22649
* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Ignore dynamic
references on forced local symbols.
ld/
PR ld/22649
* testsuite/ld-elf/pr22649-1.s: New file.
* testsuite/ld-elf/pr22649-2a.s: Likewise.
* testsuite/ld-elf/pr22649-2b.s: Likewise.
* testsuite/ld-elf/pr22649.msg: Likewise.
* testsuite/ld-elf/shared.exp: Run ld/22649 tests.
We must keep all PREINIT_ARRAY, INIT_ARRAY as well as FINI_ARRAY sections
for ld -r --gc-sections.
bfd/
PR ld/22677
* elflink.c (bfd_elf_gc_sections): Keep all PREINIT_ARRAY,
INIT_ARRAY as well as FINI_ARRAY sections for ld -r --gc-sections.
ld/
PR ld/22677
* scripttempl/elf.sc (PREINIT_ARRAY): New.
Don't add .preinit_array for ld -r.
* testsuite/ld-elf/pr22677.d: New file.
* testsuite/ld-elf/pr22677.s: Likewise.
_bfd_elf_link_renumber_dynsyms is called twice by the linker. The
first call in bfd_elf_size_dynamic_sections is just to answer the
question as to whether there are there any dynamic symbols. The
second call in bfd_elf_size_dynsym_hash_dynstr sets the st_shndx value
that dynamic symbols will have. strip_excluded_output_sections is
called between these two calls. So sections seen on the first
_bfd_elf_link_renumber_dynsyms pass might differ from those seen on
the second pass. Unfortunately, that can result in a stripped
section's dynamic symbol being assigned a dynindx on the first pass
but not corrected to the final value (of zero, ie. not dynamic) on the
second pass. PowerPC, x86, mips, and most other targets that emit
dynamic section symbols, just test that section symbol dynindx is
non-zero before using a given section symbol in dynamic relocations.
This patch prevents _bfd_elf_link_renumber_dynsyms from setting any
section symbol dynindx on the first pass.
PR 22626
* elflink.c (_bfd_elf_link_renumber_dynsyms): Don't set section
dynindx when section_sym_count is NULL.
(bfd_elf_size_dynamic_sections): Pass NULL section_sym_count to
preliminary _bfd_elf_link_renumber_dynsyms call.
PR 22571
* archive.c (bfd_openr_next_archived_file): Extend the
documentation to note that it is necessary to call
bfd_check_format on the rrturned bfd before using it.
R_AARCH64_ABS64, R_AARCH64_ABS32 and R_AARCH64_ABS16 are data relocations
supported in AArch64 elf ABI.
R_AARCH64_ABS64 under LP64 is allowed in shared object and a dynamic relocation entry
will be generated. This allows the dynamic linker to do further symbol resolution.
R_AARCH64_ABS32 likewise is allowed in shared object, however under ILP32 abi.
The original behavior for R_AARCH64_ABS32 under LP64 is that, it's allowed
in shared object and silently resolved at static linking time.
No dynamic relocation entry is generate for it.
R_AARCH64_ABS16 is allowed in shared object under both L64 and ILP32.
It's resolved at static linking time as well.
Under LP64, the address should be 64-bit. R_AARCH64_ABS32 relocation indicates
an address that is only sized 32 bits which is meaningless in LP64 shared object.
It's useful to error out.
I have checked glibc dynamic linker code, R_AARCH64_ABS16 is not supported at all. So
R_AARCH64_ABS16 should be reject in shared object completely.
In this patch, R_AARCH64_ABS32 is rejected under LP64 in constant section of shared object.
R_AARCH64_ABS16 is rejected in constant section of shared object in both ABI.
This will sometimes provide useful information for buggy code.
This fixes these failures on 64 bit which currently occur when running
the Binutils testsuite with a default PIE compiler.
< FAIL: Build rdynamic-1
< FAIL: Build dynamic-1
< FAIL: Build pr22269-1
bfd/ChangeLog:
2017-12-13 Andreas Krebbel <krebbel@linux.vnet.ibm.com>
* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Use
UNDEFWEAK_NO_DYNAMIC_RELOC.
(allocate_dynrelocs): Likewise.
(elf_s390_relocate_section): Check resolved_to_zero.
(elf_s390_finish_dynamic_symbol): Don't generate runtime reloc if
UNDEFWEAK_NO_DYNAMIC_RELOC.
A recent Fedora bug (1520805) exposed a problem with objcopy's reloc
copying code, when a binary also contains mergeable notes. The note
merging code would delete some relocs, but then the reloc copying code
would try to put them back again, which did not work.
So I am checking in the patch below to fix the problem. The patch
also tweaks one of the binutils note merging tests so that it is
skipped for the Sparc64 target, since this has funky relocs.
binutils * objcopy.c (copy_relocations_in_section): Use the orelocations
field of the input section, if it has been initialised.
* testsuite/binutils-all/note-2-64.d: Skip test on Sparc64.
bfd * elfcode.h (elf_write_relocs): Check for an empty howto field.
Many targets define their own dyn_relocs struct when they could use
struct elf_dyn_relocs. This patch tidies that, and uses
readonly_dynrelocs in a few more places.
The SH adjust_dynamic_symbol had some really weird code dating back to
2002 that looked over dynamic relocations for any in SEC_HAS_CONTENTS
or SEC_READONLY sections, rather than just the usual SEC_READONLY
sections. So basically any dynamic relocation. What's more, the SH
relocate_section has no support for emitting dynamic relocations in
non-PIC. In other words, SH has no support for avoiding copy relocs
in non-PIC. I've made that more obvious by using "if (0 && ..)" in
asjust_dynamic_symbol.
Unfortunately, LM32, M32R, NDS32, and OR1K copied the bogus SH
adjust_dynamic_symbol code. So none of those targets would have
avoided copy relocs. LM32, M32R, NDS32 get the "if (0)" treatment
too. (LM32 is even more broken in that non_got_ref is never set.)
OR1K relocate_section looks like it might support dynamic relocs in
non-PIC, so I've enabled the copy reloc avoidance code for that
target.
* elf32-hppa.c (struct elf32_hppa_dyn_reloc_entry): Delete. Use
struct elf_dyn_relocs throughout file instead.
(elf32_hppa_adjust_dynamic_symbol): Comment tidy.
* elf32-lm32.c (struct elf_lm32_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(lm32_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
Disable -z no-copyreloc too.
* elf32-m32r.c (struct elf_m32r_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(m32r_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
Disable -z no-copyreloc too.
* elf32-metag.c (struct elf_metag_dyn_reloc_entry): Delete. Use
struct elf_dyn_relocs throughout file instead.
(elf_metag_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elf32-microblaze.c (struct elf32_mb_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(readonly_dynrelocs): New function.
(microblaze_elf_adjust_dynamic_symbol): Use it.
* elf32-nds32.c (struct elf_nds32_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(nds32_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
Disable -z no-copyreloc too.
* elf32-nios2.c (struct elf32_nios2_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
* elf32-or1k.c (struct elf_or1k_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(or1k_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elf32-sh.c (struct elf_sh_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(sh_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
Disable -z no-copyreloc too.
* elf32-tilepro.c (struct tilepro_elf_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(tilepro_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elfnn-riscv.c (struct riscv_elf_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(riscv_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elfxx-sparc.c (struct _bfd_sparc_elf_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(_bfd_sparc_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elfxx-tilegx.c (struct tilegx_elf_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(tilegx_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elf32-s390.c (elf_s390_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Use readonly_dynrelocs.
Past tense is wrong for a comment before some action.
* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Comment tidy.
* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol): Likewise.