aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2017-10-10[ARM] PR ld/21402, only override the symbol dynamic decision on undefined ↵Renlin Li3-15/+12
weak symbol. Similar as aarch64 backend, arm backend only overrides the decision on undefined weak symbols. arm backend part already emits necessary relative relocation for this case. bfd/ PR ld/21402 * elf32-arm.c (allocate_dynrelocs_for_symbol): Only make undefined weak symbols into dynamic. ld/ PR ld/21402 * testsuite/ld-arm/tls-app.d: Update address. * testsuite/ld-arm/tls-app.r: Remove relocations. * testsuite/ld-arm/unresolved-1-dyn.d: Update.
2017-10-09Fix link time warning message when running the srec linker tests.Nick Clifton1-1/+1
* testsuite/ld-srec/srec.exp (run_srec_test): Set start address.
2017-10-09Fix compile time warning message when running the PR19874 linker test.Nick Clifton1-1/+1
PR ld/19874 * testsuite/ld-x86-64/pr19784c.c (bar): Change return type to void.
2017-10-09ld: Don't allow '~' as the first char in symbol nameH.J. Lu4-0/+22
Don't allow '~' as the first character in symbol name in linker script. PR ld/22267 * ldlex.l (SYMBOLNAMECHAR1) New. (DEFSYMEXP): Replace FILENAMECHAR1 with SYMBOLNAMECHAR1. (EXPRESSION): Likewise. * testsuite/ld-scripts/expr.exp: Run pr22267. * testsuite/ld-scripts/pr22267.d: New file. * testsuite/ld-scripts/pr22267.s: Likewise. * testsuite/ld-scripts/pr22267.t: Likewise.
2017-10-07ld-elf/merge.d: Don't expect to fail for sparcH.J. Lu1-1/+1
It passed with cross binutils to sparc-linux and sparc64-linux. * testsuite/ld-elf/merge.d: Don't expect to fail for sparc.
2017-10-05Change readelf so that when --wide is active a relocation's full name is ↵Nick Clifton1-1/+1
displayed. PR 22262 binutils* readelf.c (dump_relocations): Do not truncate reloc names when displaying output in wide mode. ld * testsuite/ld-powerpc/relocsort.d: Update expected output (for longer reloc names).
2017-10-05PR21167, relocation sections not included in groupsAlan Modra1-4/+5
This fixes a wart I've known about for years, but haven't done anything about because BFD treats relocation sections as an adjunct to the section they relocate. SHF_GROUP on the section thus implicitly applies to its relocation section(s), but it is an error that the reloc sections aren't part of the group. Like many patches to gas, this wasn't as straightforward as it could be due to a number of backends, i386, cr16 and others, removing relocs in tc_get_reloc rather than marking them as "done" earlier in md_apply_reloc. So it isn't possible for the group support to reliably detect the presence of relocs by looking at fixups earlier than write_relocs. However the group support needs to create signature symbols, and that must be done before the symbol table is frozen, before write_relocs. So split off the group sizing from elf_adjust_symtab and put it in elf_frob_file_after_relocs. bfd/ PR 21167 * elf.c (_bfd_elf_setup_sections): Don't trim reloc sections from groups. (_bfd_elf_init_reloc_shdr): Pass sec_hdr, use it to copy SHF_GROUP flag from section. (elf_fake_sections): Adjust calls. Exit immediately on failure. (bfd_elf_set_group_contents): Add associated reloc section indices to group contents gas/ PR 21167 * config/obj-elf.c (struct group_list): Delete elt_count. (groups): New static. (build_group_lists): Don't count elements. (elf_adjust_symtab): Use groups rather than auto list. Set up pointer from group member to SHT_GROUP section. Don't size SHT_GROUP section or clean up here.. (elf_frob_file_after_relocs): ..do so here instead. * testsuite/gas/arc/jli-1.d, * testsuite/gas/elf/groupautob.d, * testsuite/gas/mips/compact-eh-eb-2.d, * testsuite/gas/mips/compact-eh-eb-5.d, * testsuite/gas/mips/compact-eh-el-2.d, * testsuite/gas/mips/compact-eh-el-5.d: Adjust. ld/ PR 21167 * testsuite/ld-elf/group9b.d: Adjust for relocs included in group.
2017-09-30Add a test for PR binutils/21978H.J. Lu4-0/+12
PR binutils/21978 * testsuite/ld-elf/pr21978.od: New file. * testsuite/ld-elf/pr21978a.c: Likewise. * testsuite/ld-elf/pr21978b.c: Likewise. * testsuite/ld-elf/shared.exp: Run PR binutils/21978 test.
2017-09-28Skip the PR 14918 linker test for ARM targets.Nick Clifton1-3/+13
I am applying a patch that has been lying around in the Fedora binutils sources for a while. It skips the PR14918 linker test for ARM based targets. This test checks that libgcc is not included in a link of an empty executable. This works for most targets, but on the ARM the crt1.o startup code calls __libc_csu_init which is in /usr/lib/libc_nonshared.a(elf-init.oS). This in turn needs __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1, and so the test fails.
2017-09-28PR22220, BFD linker wrongly marks symbols as PREVAILING_DEF_IRONLYAlan Modra5-0/+39
non_ir_ref_dynamic wasn't being set in the case where we have a versioned dynamic symbol definition with a non-versioned matching IR symbol. bfd/ PR 22220 * elflink.c (_bfd_elf_merge_symbol): Set non_ir_ref_dynamic in a case where plugin_notice isn't called. ld/ * testsuite/ld-plugin/pr22220.h, * testsuite/ld-plugin/pr22220lib.cc, * testsuite/ld-plugin/pr22220lib.ver, * testsuite/ld-plugin/pr22220main.cc: New test. * testsuite/ld-plugin/lto.exp: Run it.
2017-09-26LD/testsuite: Fix undefined symbol tests for MIPS and S+core targetsMaciej W. Rozycki1-3/+23
Fix commit 647d4de92e06 ("Test undefined symbols in shared libraries") and remove "undefined symbols in shared lib (dyn reloc)" test failures for MIPS and S+core targets. This test assumes 3 dynamic relocation entries, however the respective psABIs define an extra single dummy *_NONE relocation at the beginning of the dynamic relocation table, which results in test output like the following for MIPS: Relocation section '.rel.dyn' at offset 0x33c contains 4 entries: Offset Info Type Sym.Value Sym. Name 00000000 00000000 R_MIPS_NONE 00010364 00000903 R_MIPS_REL32 00000000 undef_pfun 00010360 00000a03 R_MIPS_REL32 00000000 undef_data 00010368 00000b03 R_MIPS_REL32 00000000 undef_notype and S+core: Relocation section '.rel.dyn' at offset 0x274 contains 4 entries: Offset Info Type Sym.Value Sym. Name 00000000 00000000 R_SCORE_NONE 5ffe0464 00000e12 R_SCORE_REL32 00000000 undef_notype 5ffe045c 00000f12 R_SCORE_REL32 00000000 undef_data 5ffe0460 00001012 R_SCORE_REL32 00000000 undef_pfun targets respectively, and also n64 MIPS targets pad relocation triplets they use with extra *_NONE relocations, resulting in output like this: Relocation section '.rel.dyn' at offset 0x4c0 contains 4 entries: Offset Info Type Sym. Value Sym. Name 000000000000 000000000000 R_MIPS_NONE Type2: R_MIPS_NONE Type3: R_MIPS_NONE 000000010508 000900001203 R_MIPS_REL32 0000000000000000 undef_pfun Type2: R_MIPS_64 Type3: R_MIPS_NONE 000000010500 000a00001203 R_MIPS_REL32 0000000000000000 undef_data Type2: R_MIPS_64 Type3: R_MIPS_NONE 000000010510 000b00001203 R_MIPS_REL32 0000000000000000 undef_notype Type2: R_MIPS_64 Type3: R_MIPS_NONE Expect the right number of *_NONE relocations then, and adjust the total number of relocations expected accordingly. ld/ * testsuite/ld-undefined/undefined.exp: Correct the dyn reloc test for MIPS and S+core targets.
2017-09-22Add a test for PR ld/22150H.J. Lu5-0/+50
PR ld/22150 * testsuite/ld-elf/pr22150.vd: New file. * testsuite/ld-elf/pr22150.ver: Likewise. * testsuite/ld-elf/pr22150a.s: Likewise. * testsuite/ld-elf/pr22150b.s: Likewise. * testsuite/ld-elf/shared.exp: Run PR ld/22150 tests.
2017-09-21Reduce excessive .eh_frame alignment for powerpcAlan Modra1-6/+2
PowerPC64 .cfi directives use DW_EH_PE_sdata4 encoding for .eh_frame, so there is no real reason why .eh_frame should be 8 byte aligned. gas/ * config/tc-ppc.h (EH_FRAME_ALIGNMENT): Define. ld/ * testsuite/ld-powerpc/tlsopt5.wf: Update for reduced alignment.
2017-09-15PR22118, Incorrectly-capitalized regexpAlan Modra1-1/+1
PR 22118 * testsuite/ld-aarch64/erratum843419.d: Correct regexp.
2017-09-14globalaudit.rd: Allow additional bits in DT_FLAGS_1H.J. Lu1-1/+1
With -PIE on x86-64, we get 0x000000006ffffffb (FLAGS_1) Flags: GLOBAUDIT PIE We should allow additional bits in DT_FLAGS_1. PR ld/22139 * testsuite/ld-elf/globalaudit.rd: Allow additional bits in DT_FLAGS_1.
2017-09-14x86: Cache section contents and relocationsH.J. Lu6-0/+48
bfd/ PR ld/22135 * elf32-i386.c (elf_i386_convert_load_reloc): Add an argument to indicate if conversion is performed. (elf_i386_check_relocs): Cache section contents and relocations if conversion is performed. * elf64-x86-64.c (elf_x86_64_check_relocs): Cache section contents and relocations if conversion is performed. ld/ PR ld/22135 * testsuite/ld-i386/i386.exp: Run pr22135. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr22135.d: New file. * testsuite/ld-i386/pr22135.s: Likewise. * testsuite/ld-x86-64/pr22135.d: Likewise. * testsuite/ld-x86-64/pr22135.s: Likewise.
2017-09-10PowerPC64 --plt-alignAlan Modra3-14/+18
This changes the PowerPC64 --plt-align option to perform the usual alignment of code as suggested by its name, as well as the previous behaviour of padding so as to reduce boundary crossing. The old behaviour is had by using a negative parameter. The default is also changed to align plt stub code by default to 32 byte boundaries, the point being to get better bctr branch prediction on power8 and power9 hardware. bfd/ * elf64-ppp.c (plt_stub_pad): Handle positive and negative plt_stub_align. ld/ * ld.texinfo (--plt-align): Describe new behaviour of option. * emultempl/ppc64elf.em (params): Default plt_stub_align to 5. * testsuite/ld-powerpc/powerpc.exp: Pass --no-plt-align for selected tests. * testsuite/ld-powerpc/relbrlt.d: Pass --no-plt-align. * testsuite/ld-powerpc/elfv2so.d: Adjust expected output.
2017-09-09x86: Properly handle __ehdr_startH.J. Lu16-0/+140
After _bfd_i386_elf_convert_load and _bfd_x86_64_elf_convert_load are removed, elf_i386_convert_load_reloc and elf_x86_64_convert_load_reloc see __ehdr_start as an undefined symbol when they are called from check_relocs to convert GOT relocations against local symbols. But __ehdr_start will be defined as a hidden symbol by linker at the later stage if it is referenced. This patch marks __ehdr_start as a defined local symbol at the start of check_relocs if it is referenced and not defined. bfd/ PR ld/22115 * elf32-i386.c (elf_i386_convert_load_reloc): Check linker_def. Don't use UNDEFINED_WEAK_RESOLVED_TO_ZERO. * elf64-x86-64.c (elf_x86_64_convert_load_reloc): Check linker_def. Don't use UNDEFINED_WEAK_RESOLVED_TO_ZERO. * elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Set local_ref and linker_def on __ehdr_start if it is referenced and not defined. (_bfd_x86_elf_link_symbol_references_local): Also set local_ref and return TRUE when building executable, if a symbol has non-GOT/non-PLT relocations in text section or there is no dynamic linker. * elfxx-x86.h (elf_x86_link_hash_entry): Add linker_def. ld/ PR ld/22115 * ld-i386/i386.exp: Run PR ld/22115 tests, * ld/testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr22115-1.s: New file. * testsuite/ld-i386/pr22115-1a.d: Likewise. * testsuite/ld-i386/pr22115-1b.d: Likewise. * testsuite/ld-i386/pr22115-1c.d: Likewise. * testsuite/ld-i386/pr22115-1d.d: Likewise. * testsuite/ld-x86-64/pr22115-1.s: Likewise. * testsuite/ld-x86-64/pr22115-1a-x32.d: Likewise. * testsuite/ld-x86-64/pr22115-1a.d: Likewise. * testsuite/ld-x86-64/pr22115-1b-x32.d: Likewise. * testsuite/ld-x86-64/pr22115-1b.d: Likewise. * testsuite/ld-x86-64/pr22115-1c-x32.d: Likewise. * testsuite/ld-x86-64/pr22115-1c.d: Likewise. * testsuite/ld-x86-64/pr22115-1d-x32.d: Likewise. * testsuite/ld-x86-64/pr22115-1d.d: Likewise.
2017-09-06x86-64: Add R_X86_64_converted_reloc_bitH.J. Lu4-6/+4
Add R_X86_64_converted_reloc_bit to relocation type to indicate if a relocation is converted from a GOTPCREL relocation. Linker now generates failed to convert GOTPCREL relocation; relink with --no-relax for all cases, including relocations against local symbols. bfd/ * elf64-x86-64.c (R_X86_64_converted_reloc_bit): New. (elf_x86_64_info_to_howto): Get the real relocation type by masking out R_X86_64_converted_reloc_bit. (elf_x86_64_check_tls_transition): Get the real relocation type by masking out R_X86_64_converted_reloc_bit. (elf_x86_64_convert_load_reloc): Set R_X86_64_converted_reloc_bit instead of setting converted_reloc. (elf_x86_64_relocate_section): Check R_X86_64_converted_reloc_bit instead of converted_reloc. Get the real relocation type by masking out R_X86_64_converted_reloc_bit. (elf_x86_64_link_setup_gnu_properties): Verify that the value of R_X86_64_converted_reloc_bit is valid. * elfxx-x86.h (converted_reloc): Removed. ld/ * testsuite/ld-x86-64/pr19609-2a.d: Updated. * testsuite/ld-x86-64/pr19609-2b.d: Likewise. * testsuite/ld-x86-64/pr19609-4a.d: Likewise. * testsuite/ld-x86-64/pr19609-4c.d: Likewise.
2017-09-05x86-64: Properly set converted_relocH.J. Lu3-3/+3
Linker now generates failed to convert GOTPCREL relocation; relink with --no-relax for more cases. bfd/ * elf64-x86-64.c (elf_x86_64_convert_load_reloc): Properly set converted_reloc. ld/ * testsuite/ld-x86-64/pr19609-5d.d: Updated. * testsuite/ld-x86-64/pr19609-7a.d: Likewise. * testsuite/ld-x86-64/pr19609-7c.d: Likewise.
2017-09-05x86-64: Improve GOTPCREL relocation conversionH.J. Lu2-3/+3
When GOTPCREL relocation conversion leads to relocation overflow, we may get a mysterious linker message, like relocation truncated to fit: R_X86_64_32S against symbol `foo' This patch changes the linker message to failed to convert GOTPCREL relocation; relink with --no-relax bfd/ * elf64-x86-64.c (elf_x86_64_convert_load_reloc): Remove the sec argument. Don't check relocation overflow. Avoid relocation overflow if --no-relax is used. Set converted_reloc on symbol if a GOTPCREL relocation is converted. (elf_x86_64_relocate_section): Issue a fatal error and suggest --no-relax if GOTPCREL relocation conversion leads to relocation overflow. * elfxx-x86.h (elf_x86_link_hash_entry): Add converted_reloc. ld/ * testsuite/ld-x86-64/pr19609-4e.d: Updated. * testsuite/ld-x86-64/pr19609-6a.d: Likewise.
2017-09-03x86-64: Set tlsdesc_plt if GOT_TLS_GDESC_P is trueH.J. Lu3-0/+87
We need to set tlsdesc_plt for x86-64 if GOT_TLS_GDESC_P is true when allocating dynamic relocations so that _bfd_x86_elf_size_dynamic_sections will generate TLSDESC_PLT and TLSDESC_GOT in x86-64 output. bfd/ PR ld/22071 * elfxx-x86.c (elf_x86_allocate_dynrelocs): Set tlsdesc_plt for x86-64 if GOT_TLS_GDESC_P is true. ld/ PR ld/22071 * testsuite/ld-x86-64/pr22071.d: New file. * testsuite/ld-x86-64/pr22071.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run pr22071.
2017-09-01x86-64: Check ELF_COMMON_DEF_P for common symbolsH.J. Lu3-0/+70
bfd/ PR ld/22064 * elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Check ELF_COMMON_DEF_P for common symbols. ld/ PR ld/22064 * testsuite/ld-x86-64/pr22064a.S: New file. * testsuite/ld-x86-64/pr22064b.c: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run PR ld/22064 test.
2017-09-01x86: Correct unwind information for the second PLTH.J. Lu22-49/+522
For i386, generate unwind information for the second PLT. For x32, correct alignment of .eh_frame section for the second PLT. bfd/ PR ld/22061 * elf32-i386.c (elf_i386_link_setup_gnu_properties): Create .eh_frame section for the second PLT. * elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Correct alignment of .eh_frame section for the second PLT. ld/ PR ld/22061 * testsuite/ld-i386/ibt-plt-1.d: Updated. * testsuite/ld-i386/ibt-plt-2a.d: Likewise. * testsuite/ld-i386/ibt-plt-2c.d: Likewise. * testsuite/ld-i386/ibt-plt-3a.d: Likewise. * testsuite/ld-i386/ibt-plt-3c.d: Likewise. * testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise. * testsuite/ld-i386/ibt-plt-2b.d: Pass --hash-style=sysv to ld and dump unwind information. * testsuite/ld-i386/ibt-plt-2d.d: Likewise. * testsuite/ld-i386/ibt-plt-3b.d: Likewise. * testsuite/ld-i386/ibt-plt-3d.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2b-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2b.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2d-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2d.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3b-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3b.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3d-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3d.d: Likewise.
2017-08-31Add a test for PR ld/22048H.J. Lu4-0/+38
PR ld/22048 * testsuite/ld-x86-64/pr22048.d: New file. * testsuite/ld-x86-64/pr22048a.s: Likewise. * testsuite/ld-x86-64/pr22048b.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run pr22048.
2017-08-31Remove .eh_frame zero terminatorsAlan Modra2-13/+3
The machinery to do this was there, but not enabled if the terminator was the only thing in the section. bfd/ * elf-eh-frame.c (_bfd_elf_parse_eh_frame): Don't exit early for a section containing just a terminator. Allow multiple terminators at end of section. * elflink.c (bfd_elf_discard_info): Iterate over .eh_frame sections when not adding alignment. Assert on terminator in the middle of FDEs. ld/ * testsuite/ld-elf/eh3.d: Update. * testsuite/ld-elf/eh4.d: Update.
2017-08-30LD/testsuite: Also discard `.MIPS.options' in orphan testsMaciej W. Rozycki1-2/+2
Complement commit 5b5f4e6f8cd2 ("ld: Early detection of orphans we know will be discarded") and add `.MIPS.options' to the list of sections discarded with orphan tests, removing failures like: ./ld-new: error: unplaced orphan section `.MIPS.options' from `tmpdir/orphan-11.o'. FAIL: ld-elf/orphan-11 and: ./ld-new: error: unplaced orphan section `.MIPS.options' from `tmpdir/orphan-12.o'. FAIL: ld-elf/orphan-12 from n64 MIPS testing. ld/ * testsuite/ld-elf/orphan-11.ld: Also discard `.MIPS.options' sections.
2017-08-30MIPS/BFD: Correct microMIPS cross-mode BAL to JALX relaxationMaciej W. Rozycki13-0/+139
Fix a bug in commit a6ebf6169a1b ("MIPS: Convert cross-mode BAL to JALX") and in BFD linker relaxation correct the microMIPS interpretation of the branch offset, which is supposed to be shifted by 1 bit, rather than 2 as in the regular MIPS case. bfd/ * elfxx-mips.c (mips_elf_perform_relocation): Correct microMIPS branch offset interpretation. gas/ * testsuite/gas/mips/branch-addend-micromips.d: New test. * testsuite/gas/mips/branch-addend-micromips-n32.d: New test. * testsuite/gas/mips/branch-addend-micromips-n64.d: New test. * testsuite/gas/mips/branch-addend-micromips.s: New test source. * testsuite/gas/mips/mips.exp: Run the new tests. ld/ * testsuite/ld-mips-elf/bal-jalx-addend-micromips.d: New test. * testsuite/ld-mips-elf/bal-jalx-addend-micromips-n32.d: New test. * testsuite/ld-mips-elf/bal-jalx-addend-micromips-n64.d: New test. * testsuite/ld-mips-elf/bal-jalx-local-micromips.d: New test. * testsuite/ld-mips-elf/bal-jalx-local-micromips-n32.d: New test. * testsuite/ld-mips-elf/bal-jalx-local-micromips-n64.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-micromips.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-micromips-n32.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-micromips-n64.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips-n32.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips-n64.d: New test. * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2017-08-30PowerPC TPREL16_HA/LO reloc optimizationAlan Modra10-109/+178
In the TLS GD/LD to LE optimization, ld replaces a sequence like addi 3,2,x@got@tlsgd R_PPC64_GOT_TLSGD16 x bl __tls_get_addr(x@tlsgd) R_PPC64_TLSGD x R_PPC64_REL24 __tls_get_addr nop with addis 3,13,x@tprel@ha R_PPC64_TPREL16_HA x addi 3,3,x@tprel@l R_PPC64_TPREL16_LO x nop When the tprel offset is small, this can be further optimized to nop addi 3,13,x@tprel nop bfd/ * elf64-ppc.c (struct ppc_link_hash_table): Add do_tls_opt. (ppc64_elf_tls_optimize): Set it. (ppc64_elf_relocate_section): Nop addis on TPREL16_HA, and convert insn on TPREL16_LO and TPREL16_LO_DS relocs to use r13 when addis would add zero. * elf32-ppc.c (struct ppc_elf_link_hash_table): Add do_tls_opt. (ppc_elf_tls_optimize): Set it. (ppc_elf_relocate_section): Nop addis on TPREL16_HA, and convert insn on TPREL16_LO relocs to use r2 when addis would add zero. gold/ * powerpc.cc (Target_powerpc::Relocate::relocate): Nop addis on TPREL16_HA, and convert insn on TPREL16_LO and TPREL16_LO_DS relocs to use r2/r13 when addis would add zero. ld/ * testsuite/ld-powerpc/tls.s: Add calls with tls markers. * testsuite/ld-powerpc/tls32.s: Likewise. * testsuite/ld-powerpc/powerpc.exp: Run tls marker tests. * testsuite/ld-powerpc/tls.d: Adjust for TPREL16_HA/LO optimization. * testsuite/ld-powerpc/tlsexe.d: Likewise. * testsuite/ld-powerpc/tlsexetoc.d: Likewise. * testsuite/ld-powerpc/tlsld.d: Likewise. * testsuite/ld-powerpc/tlsmark.d: Likewise. * testsuite/ld-powerpc/tlsopt4.d: Likewise. * testsuite/ld-powerpc/tlstoc.d: Likewise.
2017-08-30PowerPC64 __tls_get_addr sequence optimizationAlan Modra7-30/+30
There isn't a good reason for ld.bfd to behave differently from gold in the code generated by TLS GD/LD to LE optimization. bfd/ * elf64-ppc.c (ppc64_elf_relocate_section): When optimizing __tls_get_addr call sequences to LE, don't move the addi down to the nop. Replace the bl with addi and leave the nop alone. ld/ * testsuite/ld-powerpc/tls.d: Update. * testsuite/ld-powerpc/tlsexe.d: Update. * testsuite/ld-powerpc/tlsexetoc.d: Update. * testsuite/ld-powerpc/tlsld.d: Update. * testsuite/ld-powerpc/tlsmark.d: Update. * testsuite/ld-powerpc/tlsopt4.d: Update. * testsuite/ld-powerpc/tlstoc.d: Update.
2017-08-30testsuite/ld-cris various files: Run ld with --hash-style=sysv.Hans-Peter Nilsson49-49/+49
* testsuite/ld-cris/dso-pltdis1.d: Run ld with --hash-style=sysv. * testsuite/ld-cris/dso-pltdis2.d, testsuite/ld-cris/dso12-pltdis.d, testsuite/ld-cris/expdyn1.d, testsuite/ld-cris/expdyn5.d, testsuite/ld-cris/expdyn6.d, testsuite/ld-cris/expdyn7.d, testsuite/ld-cris/gotplt1.d, testsuite/ld-cris/gotplt2.d, testsuite/ld-cris/gotplt3.d, testsuite/ld-cris/hiddef1.d, testsuite/ld-cris/libdso-11.d, testsuite/ld-cris/libdso-12.d, testsuite/ld-cris/libdso-12b.d, testsuite/ld-cris/libdso-12c.d, testsuite/ld-cris/libdso-13.d, testsuite/ld-cris/libdso-13b.d, testsuite/ld-cris/libdso-14.d, testsuite/ld-cris/libdso-15.d, testsuite/ld-cris/libdso-15b.d, testsuite/ld-cris/libdso-1b.d, testsuite/ld-cris/libdso-1c.d, testsuite/ld-cris/libdso-1d.d, testsuite/ld-cris/libdso-4.d, testsuite/ld-cris/pr16044.d, testsuite/ld-cris/pv32-1.d, testsuite/ld-cris/tls-dso-dtpoffd2.d, testsuite/ld-cris/tls-dso-dtpoffd4.d, testsuite/ld-cris/tls-dso-tpoffgotcomm1.d, testsuite/ld-cris/tls-dso-x1x2-1.d, testsuite/ld-cris/tls-gc-71.d, testsuite/ld-cris/tls-ie-78.d, testsuite/ld-cris/tls-js1.d, testsuite/ld-cris/tls-ldgdex-14.d, testsuite/ld-cris/tls-ldgdex-15.d, testsuite/ld-cris/tls-legdx-16.d, testsuite/ld-cris/tls-legdx-17.d, testsuite/ld-cris/tls-local-63.d, testsuite/ld-cris/tls-local-64.d, testsuite/ld-cris/tls-ok-30.d, testsuite/ld-cris/tls-ok-32.d, testsuite/ld-cris/tls-ok-34.d, testsuite/ld-cris/tls-und-38.d, testsuite/ld-cris/tls-und-42.d, testsuite/ld-cris/tls-und-46.d, testsuite/ld-cris/tls-und-50.d, testsuite/ld-cris/weakref2.d, testsuite/ld-cris/weakref3.d, testsuite/ld-cris/weakref4.d: Likewise.
2017-08-29Improve MSP430 section placement.Jozef Lawrynowicz17-0/+667
ld * emultempl/msp430.em (change_output_section): New function. (move_prefixed_section): New function. (add_region_prefix): New function. (msp430_elf_after_open): New function. (gld${EMULATION_NAME}_add_options): Implement. (gld${EMULATION_NAME}_list_options): Implement. (gld${EMULATION_NAME}_handle_option): Implement. * ld.texinfo: Document new options. * testsuite/ld-msp430-elf/main-bss-lower.d: New. * testsuite/ld-msp430-elf/main-bss-upper.d: New. * testsuite/ld-msp430-elf/main-const-lower.d: New. * testsuite/ld-msp430-elf/main-const-upper.d: New. * testsuite/ld-msp430-elf/main-text-lower.d: New. * testsuite/ld-msp430-elf/main-text-upper.d: New. * testsuite/ld-msp430-elf/main-var-lower.d: New. * testsuite/ld-msp430-elf/main-var-upper.d: New. * testsuite/ld-msp430-elf/main-with-data-bss-unique-sec.s: New. * testsuite/ld-msp430-elf/main-with-data-bss.s: New. * testsuite/ld-msp430-elf/main-with-text-rodata-unique-sec.s: New. * testsuite/ld-msp430-elf/main-with-text-rodata.s: New. * testsuite/ld-msp430-elf/msp430-elf.exp: New. * testsuite/ld-msp430-elf/msp430-no-lower.ld: New. * testsuite/ld-msp430-elf/msp430.ld: New. * emultempl/msp430.em (data_statement_size): New. (eval_upper_either_sections): New. (eval_lower_either_sections): New. (intermediate_relax_sections): New. (msp430_elf_after_allocation): New. * emultempl/msp430.em (gld${EMULATION_NAME}_place_orphan): Always place sections in the lower region. gas * config/tc-msp430.c (md_parse_option): Define high data and high bss symbols if -mdata-region is passed. Define -mdata-region open. * doc/c-msp430.texi: Document -mdata-region. * testsuite/gas/msp430/high-data-bss-sym.d: New test. * testsuite/gas/msp430/high-data-bss-sym.s: New. * testsuite/gas/msp430/msp430.exp: Add -mdata-region tests.
2017-08-26Disallow copy relocation against protected data symbolH.J. Lu10-0/+276
We shpouldn't generate copy relocation to resolve reference to protected data symbol defined in shared object with the NO_COPY_ON_PROTECTED property. This patch adds a bit to elf_obj_tdata as well as elf_i386_link_hash_entry and elf_x86_64_link_hash_entry to track the bfd with the NO_COPY_ON_PROTECTED property as well as protected symbol defined in shared object. extern_protected_data is set to FALSE if any input relocatable file contains the NO_COPY_ON_PROTECTED property. bfd/ PR ld/21997 * elf-bfd.h (elf_obj_tdata): Use ENUM_BITFIELD on object_id, dyn_lib_class and has_gnu_symbols. Change bad_symtab to bitfield. Add a has_no_copy_on_protected bitfield. (elf_has_no_copy_on_protected): New. * elf-properties.c (_bfd_elf_parse_gnu_properties): Set elf_has_no_copy_on_protected for GNU_PROPERTY_NO_COPY_ON_PROTECTED. (elf_merge_gnu_property_list): Likewise. (_bfd_elf_link_setup_gnu_properties): Set extern_protected_data to FALSE for elf_has_no_copy_on_protected. * elf32-i386.c (SYMBOL_NO_COPYRELOC): New. (elf_i386_link_hash_entry): Add def_protected. (elf_i386_adjust_dynamic_symbol): Also check SYMBOL_NO_COPYRELOC when checking info->nocopyreloc. (elf_i386_link_setup_gnu_properties): Don't set extern_protected_data here. (elf_i386_merge_symbol_attribute): New function. (elf_backend_merge_symbol_attribute): New. * elf64-x86-64.c (SYMBOL_NO_COPYRELOC): New. (elf_x86_64_link_hash_entry): Add def_protected. (elf_x86_64_need_pic): Report protected symbol for def_protected. (elf_x86_64_adjust_dynamic_symbol): Also check SYMBOL_NO_COPYRELOC when checking info->nocopyreloc. (elf_x86_64_relocate_section): Also check for R_X86_64_PC32 relocation run-time overflow and unresolvable R_X86_64_32S relocation against protected data symbol defined in shared object with GNU_PROPERTY_NO_COPY_ON_PROTECTED. (elf_x86_64_link_setup_gnu_properties): Don't set extern_protected_data here. (elf_x86_64_merge_symbol_attribute): New function. (elf_backend_merge_symbol_attribute): New. ld/ PR ld/21997 * testsuite/ld-i386/i386.exp: Run PR ld/21997 tests. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr21997-1a.S: New file. * testsuite/ld-i386/pr21997-1b.c: Likewise. * testsuite/ld-i386/pr21997-1c.S: Likewise. * testsuite/ld-x86-64/pr21997-1a.S: Likewise. * testsuite/ld-x86-64/pr21997-1a.err: Likewise. * testsuite/ld-x86-64/pr21997-1b.c: Likewise. * testsuite/ld-x86-64/pr21997-1b.err: Likewise. * testsuite/ld-x86-64/pr21997-1c.c: Likewise.
2017-08-24ld: Add "--" after regexpH.J. Lu4-4/+4
Add "--" after regexp to support dejagnu 1.4.4. * testsuite/ld-elf/pr21903c.d: Remove '\' before --. * testsuite/ld-elf/pr21903d.d: Likewise. * testsuite/ld-elf/pr21903e.d: Likewise. * testsuite/lib/ld-lib.exp (run_dump_test): Add "--" after regexp.
2017-08-24ld: Replace regexp with string matchH.J. Lu2-4/+4
Replace regexp with string match to workaround dejagnu 1.4.4 which complains: ERROR: bad switch "-fPIE": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or -- * testsuite/ld-i386/i386.exp (undefined_weak): Replace regexp with string match. * testsuite/ld-x86-64/x86-64.exp (undefined_weak): Likewise.
2017-08-24x86-64: Run pr22001-1b on x32H.J. Lu1-8/+25
Run pr22001-1b on x32 since R_X86_64_32S relocation can be turned into dynamic R_X86_64_32 relocation which won't overflow on x32. * testsuite/ld-x86-64/x86-64.exp: Run pr22001-1b on x32.
2017-08-24x86-64: Check relocations with -z nocopyrelocH.J. Lu10-0/+235
On x86-64, when -z nocopyreloc is used to build executable, relocations may overflow at run-time or may not be resolved without PIC. This patch checks these conditions and issues an error with suggestion for -fPIC. bfd/ PR ld/22001 * elf64-x86-64.c (elf_x86_64_relocate_section): Check for R_X86_64_PC32 relocation run-time overflow and unresolvable R_X86_64_32S relocation with -z nocopyreloc. ld/ PR ld/22001 * testsuite/ld-i386/i386.exp: Run -z nocopyreloc tests. * testsuite/ld-x86-64/x86-64.exp: Likewise. * ld/testsuite/ld-i386/pr22001-1a.c: New file. * ld/testsuite/ld-i386/pr22001-1b.c: Likewise. * ld/testsuite/ld-i386/pr22001-1c.S: Likewise. * ld/testsuite/ld-x86-64/pr22001-1a.c: Likewise. * ld/testsuite/ld-x86-64/pr22001-1a.err: Likewise. * ld/testsuite/ld-x86-64/pr22001-1b.c: Likewise. * ld/testsuite/ld-x86-64/pr22001-1b.err: Likewise. * ld/testsuite/ld-x86-64/pr22001-1c.c: Likewise.
2017-08-24ld: Early detection of orphans we know will be discardedAndrew Burgess5-0/+53
When processing an orphan section we first call lang_place_orphans, this function handles a few sections for which the behaviour is known COMMON sections, or sections marked as SEC_EXCLUDE. Any orphans that are not handled in lang_place_orphans are passed on to ldlang_place_orphan, this is where we decide where to put the orphan, and then call lang_add_section to perform the actual orphan placement. We previously had a larger set of checks at the start of the function lang_add_section to discard some sections that we _knew_ should not be added into the output file, this was where .group sections (in a final link) and .debug* sections (with --strip-debug) were dropped. The problem with dropping these sections at the lang_add_section stage is that a user might also be using --orphan-handling=error to prevent orphans. If they are then they should not be get errors about sections that we know will be discarded, and which are not mentioned in the linker script. The solution proposed in this patch is to move the "will this section be discarded" check into a separate function, and use this in lang_place_orphans to have the early discard phase discard sections that we know should not be included in the output file. ld/ChangeLog: PR 21961 * ldlang.c (lang_discard_section_p): New function. (lang_add_section): Checks moved out into new function, which is now called. (lang_place_orphans): Call lang_discard_section_p instead of duplicating some of the checks from lang_add_section. * testsuite/ld-elf/orphan-11.d: New file. * testsuite/ld-elf/orphan-11.ld: New file. * testsuite/ld-elf/orphan-11.s: New file. * testsuite/ld-elf/orphan-12.d: New file. * testsuite/ld-elf/orphan-12.s: New file.
2017-08-24Test undefined symbols in shared librariesAlan Modra2-98/+189
git commit 46434633f9 said Make undefined symbols in allocate_dynrelocs dynamic ..if they have dynamic relocs. An undefined symbol in a PIC object that finds no definition ought to become dynamic in order to support --allow-shlib-undefined, but there is nothing in the generic ELF linker code to do this if the reference isn't via the GOT or PLT. (An initialized function pointer is an example.) So it falls to backend code to ensure the symbol is made dynamic. The above isn't true. Undefined symbols are indeed made dynamic for shared libraries. Undefined symbols are not automatically made dynamic in executables, and it was the PIE case that triggered an internal consistency assertion on powerpc64. I guess I could have jumped the other way when fixing PR21988, and not created a dynamic reloc. Either way, it doesn't matter a great deal. We're going to get an error on strong undefined symbols in an executable anyway, and broken binaries if you try to use --unresolved-symbols=ignore-all to disable the error. * testsuite/ld-undefined/fundef.s: New test. * testsuite/ld-undefined/undefined.exp: Test that undefined symbols in shared libraries are made dynamic.
2017-08-23Update PR ld/21903 tests for dejagnu 1.4.4H.J. Lu3-3/+3
Add '\' before -- to workaround dejagnu 1.4.4 which complains: ERROR: bad switch "--no-define-common may not be used without -shared":... * testsuite/ld-elf/pr21903c.d: Add '\' before --. * testsuite/ld-elf/pr21903d.d: Likewise. * testsuite/ld-elf/pr21903e.d: Likewise.
2017-08-23x86-64: Properly report output type when PIC is neededH.J. Lu4-4/+4
-fPIC may be needed to compile PIE or PDE objects, not just shared object. bfd/ * elf64-x86-64.c (elf_x86_64_need_pic): Add an argument for bfd_link_info. Report shared, PIE or PDE object based on bfd_link_info. (elf_x86_64_check_relocs): Update elf_x86_64_need_pic call. (elf_x86_64_relocate_section): Likewise. ld/ * testsuite/ld-x86-64/pie2.d: Updated. * testsuite/ld-x86-64/pr19719.d: Likewise. * testsuite/ld-x86-64/pr19807-2a.d: Likewise. * testsuite/ld-x86-64/pr19969.d: Likewise.
2017-08-23x86: Clear extern_protected_data for GNU_PROPERTY_NO_COPY_ON_PROTECTEDH.J. Lu6-0/+90
When GNU_PROPERTY_NO_COPY_ON_PROTECTED is set, it indicates that there are no copy relocations against protected data symbols. When linker sees GNU_PROPERTY_NO_COPY_ON_PROTECTED on any input relocatable file, it sets extern_protected_data to FALSE. bfd/ * elf32-i386.c (elf_i386_link_setup_gnu_properties): Set extern_protected_data to FALSE if GNU_PROPERTY_NO_COPY_ON_PROTECTED is set on any input relocatable file. * elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Likewise. ld/ * testsuite/ld-i386/i386.exp: Run protected7. * testsuite/ld-i386/protected7.d: New file. * testsuite/ld-i386/protected7.s: Likewise. * testsuite/ld-x86-64/protected8.d: Likewise. * testsuite/ld-x86-64/protected8.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run protected8.
2017-08-23Remove pr19161 test hppa xfailAlan Modra1-1/+1
* testsuite/ld-gc/pr19161.d: Don't xfail hppa.
2017-08-22Update PR ld/21964 testsH.J. Lu7-52/+94
* testsuite/ld-elf/pr21964-1a.c (foo): Renamed to ... (foo1): This. * testsuite/ld-elf/pr21964-1b.c: Rewrite. * testsuite/ld-elf/pr21964-1c.c: New file. * testsuite/ld-elf/pr21964-2c.c: Likewise. * testsuite/ld-elf/pr21964-2a.c (foo): Renamed to ... (foo1): This. * testsuite/ld-elf/pr21964-2b.c: Rewrite. * testsuite/ld-elf/shared.exp: Update PR ld/21964 tests.
2017-08-21Make __start/__stop symbols protected visibilityAlan Modra25-25/+106
They can't be hidden visibility since apparently people use dlsym to look them up. bfd/ PR ld/21964 * elf-bfd.h (SYMBOLIC_BIND): Return TRUE for __start/__stop symbols. * elflink.c (bfd_elf_define_start_stop): Rewrite. ld/ PR ld/21964 * testsuite/ld-elf/pr21562a.d: Update for changed start/stop symbols. * testsuite/ld-elf/pr21562b.d: Likewise. * testsuite/ld-elf/pr21562c.d: Likewise. * testsuite/ld-elf/pr21562d.d: Likewise. * testsuite/ld-elf/pr21562e.d: Likewise. * testsuite/ld-elf/pr21562f.d: Likewise. * testsuite/ld-elf/pr21562g.d: Likewise. * testsuite/ld-elf/pr21562h.d: Likewise. * testsuite/ld-elf/pr21562i.d: Likewise. * testsuite/ld-elf/pr21562j.d: Likewise. * testsuite/ld-elf/pr21562k.d: Likewise. * testsuite/ld-elf/pr21562l.d: Likewise. * testsuite/ld-elf/pr21562m.d: Likewise. * testsuite/ld-elf/pr21562n.d: Likewise. * testsuite/ld-elf/sizeofa.d: Likewise. * testsuite/ld-elf/sizeofb.d: Likewise. * testsuite/ld-elf/startofa.d: Likewise. * testsuite/ld-elf/startofb.d: Likewise. * testsuite/ld-gc/pr20022.d: Likewise. * testsuite/ld-gc/start.d: Likewise. * testsuite/ld-elf/pr21964-1a.c: New file. * testsuite/ld-elf/pr21964-1b.c: New file. * testsuite/ld-elf/pr21964-2a.c: New file. * testsuite/ld-elf/pr21964-2b.c: New file. * testsuite/ld-elf/shared.exp: Run PR ld/21964 tests.
2017-08-21PR ld/20125, MMIX weak symbolsHans-Peter Nilsson2-0/+23
Weak undefineds with PUSHJ relocs were "lost", causing internal inconsistencies and an abort.
2017-08-20Update testsuite/ld-x86-64/plt-main-bnd.ddH.J. Lu1-1/+1
2017-08-20 A. Wilcox <awilfox@adelielinux.org> PR ld/21976 * testsuite/ld-x86-64/plt-main-bnd.dd: Accept '_' in symbol name.
2017-08-14PR21441, Unnecessary padding of .eh_frame sectionAlan Modra2-10/+2
Until all .eh_frame sections have been edited we don't know their sizes. So it isn't possible to properly decide whether a non-empty .eh_frame section follows a given section until editing is complete. bfd/ PR 21441 * elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Don't add alignment padding here. * elflink.c (bfd_elf_discard_info): Add .eh_frame padding here in a reverse pass over sections. ld/ PR 21441 * testsuite/ld-x86-64/pr21038a.d: Adjust. * testsuite/ld-x86-64/pr21038a-now.d: Adjust.
2017-08-13ld: Restore linker scripts in PR ld/21884 testsH.J. Lu10-0/+54
OUTPUT_FORMAT in linker script of PR ld/21884 tests is needed to trigger PR ld/21884. Restore linker scripts and add nacl versions of the same tests. * testsuite/ld-i386/i386.exp: Run pr21884-nacl. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr21884.d: Don't run on nacl targets. * testsuite/ld-x86-64/pr21884.d: Likewise. * testsuite/ld-i386/pr21884.t: Revert the last change. * testsuite/ld-x86-64/pr21884.t: Likewise. * testsuite/ld-i386/pr21884-nacl.d: New file. * testsuite/ld-i386/pr21884-nacl.t: Likewise. * testsuite/ld-x86-64/pr21884-nacl.d: Likewise. * testsuite/ld-x86-64/pr21884-nacl.t: Likewise.
2017-08-13Fix i686-nacl and x86_64-nacl pr21884 failuresAlan Modra2-8/+0
OUTPUT_FORMAT in the script results in "./ld-new: target elf32-i386 not found" and similarly for the x86_64 test. * testsuite/ld-i386/pr21884.t: Remove unneeded format, arch and entry. * testsuite/ld-x86-64/pr21884.t: Likewise.