aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf64-ppc.c
AgeCommit message (Collapse)AuthorFilesLines
2019-09-05PowerPC64 GOT_PCREL relocsAlan Modra1-53/+23
PC-relative relocs typically use the addend in adjusting what they are relative to. For example: bcl 20,31,1f 1: mflr 12 addi 12,12,xxx-1b generates "R_PPC64_REL16 xxx+0x4" for the addi (when little-endian). The addend reflects the fact that you want the offset relative to the previous insn not the current one in this case. So the question is, will we ever want to do something like that for an instruction using R_PPC64_GOT_PCREL34? I thought so at the time I first implemented support in ld but at the time I think the hardware was possibly going to support pcrel+offset+reg addressing. In which case you might want something like: load_big_offset_into_r2 pld 3,sym-big_offset@got@pcrel(2) which would be a way of supporting more than 8G offsets from code to the GOT. We could do the same with load_big_offset_into_r2 pla 9,sym-big_offset@got@pcrel ldx 3,9,2 However, this is really a poor version of TOC-pointer relative code. So let's go with an addend on R_PPC64_GOT_PCREL34 meaning that sym+addend should be put in a GOT entry, and the relocation calculate the pc-relative offset to that GOT entry. Note that this is an extension to the ABI, which says (by the expression given for GOT relocs) that non-zero addends on GOT and PLT relocs are ignored. This is true for all GOT/PLT relocs, not just the pcrel ones. * elf64-ppc.c (ppc64_elf_check_relocs): Interpret an addend in GOT_PCREL and PLT_PCREL relocs as affecting the value stored in the GOT/PLT entry rather than affecting the offset to that GOI/PLT entry. (ppc64_elf_edit_toc, ppc64_elf_relocate_section): Likewise.
2019-09-05R_PPC64_PCREL_OPTAlan Modra1-12/+39
The loads and stores handled in the second instruction of a sequence marked by R_PPC64_PCREL_OPT may be a prefix instruction. For example: pld ra,symbol@got@pcrel 0: pld rt,off(ra) .reloc 0b-8,R_PPC64_PCREL_OPT,(.-8)-(0b-8) can be optimised to pld rt,symbol+off@pcrel pnop * elf64-ppc.c (xlate_pcrel_opt): Handle prefix loads and stores in second instruction. (ppc64_elf_relocate_section): Likewise.
2019-08-29PowerPC64 xlate_pcrel_optAlan Modra1-19/+22
We can easily support an offset on the second instruction of a sequence marked with R_PPC64_PCREL_OPT. For example, pla ra,symbol@pcrel ld rt,off(ra) can be optimised to pld rt,symbol+off@pcrel nop * elf64-ppc.c (xlate_pcrel_opt): Add poff parameter. Allow offset on second insn, return it in poff. (ppc64_elf_relocate_section): Add offset to paddi addend for PCREL_OPT.
2019-08-24PowerPC64 segfault in ppc64_elf_edit_tocAlan Modra1-0/+5
Found on a GOT reference to __ehdr_start, which is tweaked to be undefined weak at some stages of linking. SYMBOL_REFERENCES_LOCAL isn't a sufficient test. * elf64-ppc.c (ppc64_elf_edit_toc): Exclude undefined weak symbols from GOT optimisation.
2019-08-19PowerPC64 ha/lo insn checksAlan Modra1-72/+100
These are done in ppc64_elf_edit_toc, which now also garbage collects unused GOT entries. The checks for legitimate instructions weren't being done for the GOT relocs, unless the file also happened to have a toc section. * elf64-ppc.c (struct ppc64_elf_obj_tdata): Rename has_gotrel to has_optrel. (struct _ppc64_elf_section_data): Likewise. (ppc64_elf_check_relocs): Set has_optrel for more relocs. (ppc64_elf_edit_toc): Do ha/lo insn checks in GOT loop rather than TOC loop. Check PLT16 insns too.
2019-07-19[PowerPC64] pc-relative TLS relocationsAlan Modra1-28/+209
This patch supports using pcrel instructions in TLS code sequences. A number of new relocations are needed, gas operand modifiers to generate those relocations, and new TLS optimisation. For optimisation it turns out that the new pcrel GD and LD sequences can be distinguished from the non-pcrel GD and LD sequences by there being different relocations on the new sequence. The final "add ra,rb,13" on IE sequences similarly needs a new relocation, or as I chose, a modification of R_PPC64_TLS. On pcrel IE code, the R_PPC64_TLS points one byte into the "add" instruction rather than being on the instruction boundary. GD: pla 3,z@got@tlsgd@pcrel # R_PPC64_GOT_TLSGD34 bl __tls_get_addr@notoc(z@tlsgd) # R_PPC64_TLSGD and R_PPC64_REL24_NOTOC edited to IE pld 3,z@got@tprel@pcrel add 3,3,13 edited to LE paddi 3,13,z@tprel nop LD: pla 3,z@got@tlsld@pcrel # R_PPC64_GOT_TLSLD34 bl __tls_get_addr@notoc(z@tlsld) # R_PPC64_TLSLD and R_PPC64_REL24_NOTOC .. paddi 9,3,z2@dtprel pld 10,z3@got@dtprel@pcrel add 10,10,3 edited to LE paddi 3,13,0x1000 nop IE: pld 9,z@got@tprel@pcrel # R_PPC64_GOT_TPREL34 add 3,9,z@tls@pcrel # R_PPC64_TLS at insn+1 ldx 4,9,z@tls@pcrel lwax 5,9,z@tls@pcrel stdx 5,9,z@tls@pcrel edited to LE paddi 9,13,z@tprel nop ld 4,0(9) lwa 5,0(9) std 5,0(9) LE: paddi 10,13,z@tprel include/ * elf/ppc64.h (R_PPC64_TPREL34, R_PPC64_DTPREL34), (R_PPC64_GOT_TLSGD34, R_PPC64_GOT_TLSLD34), (R_PPC64_GOT_TPREL34, R_PPC64_GOT_DTPREL34): Define. (IS_PPC64_TLS_RELOC): Include new tls relocs. bfd/ * reloc.c (BFD_RELOC_PPC64_TPREL34, BFD_RELOC_PPC64_DTPREL34), (BFD_RELOC_PPC64_GOT_TLSGD34, BFD_RELOC_PPC64_GOT_TLSLD34), (BFD_RELOC_PPC64_GOT_TPREL34, BFD_RELOC_PPC64_GOT_DTPREL34), (BFD_RELOC_PPC64_TLS_PCREL): New pcrel tls relocs. * elf64-ppc.c (ppc64_elf_howto_raw): Add howtos for pcrel tls relocs. (ppc64_elf_reloc_type_lookup): Translate pcrel tls relocs. (must_be_dyn_reloc, dec_dynrel_count): Add R_PPC64_TPREL64. (ppc64_elf_check_relocs): Support pcrel tls relocs. (ppc64_elf_tls_optimize, ppc64_elf_relocate_section): Likewise. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. gas/ * config/tc-ppc.c (ppc_elf_suffix): Map "tls@pcrel", "got@tlsgd@pcrel", "got@tlsld@pcrel", "got@tprel@pcrel", and "got@dtprel@pcrel". (fixup_size, md_assemble): Handle pcrel tls relocs. (ppc_force_relocation, ppc_fix_adjustable): Likewise. (md_apply_fix, tc_gen_reloc): Likewise. ld/ * testsuite/ld-powerpc/tlsgd.d, * testsuite/ld-powerpc/tlsgd.s, * testsuite/ld-powerpc/tlsie.d, * testsuite/ld-powerpc/tlsie.s, * testsuite/ld-powerpc/tlsld.d, * testsuite/ld-powerpc/tlsld.s: New tests. * testsuite/ld-powerpc/powerpc.exp: Run them.
2019-07-18[PowerPC64] Use STN_UNDEF internally for edited relocsAlan Modra1-33/+6
It's not correct to use non-STT_TLS symbols with TLS relocation, not that it matters much when editing relocs, but this edited reloc can be output by --emit-relocs. So don't use a symbol on the reloc. * elf64-ppc.c (ppc64_elf_relocate_section): Don't bother selecting a TLS section symbol for edited relocs. Tighten TLS symbol/reloc match test.
2019-07-18[PowerPC64] Don't store TLS_EXPLICIT in tls_maskAlan Modra1-8/+9
This saves a bit in tls_mask, and fixes a bug that could be triggered in the unlikely case that both @got (usual ELF style) and @toc (PowerOpen style) code was used to set up args for __tls_get_addr. * elf64-ppc.c (TLS_EXPLICIT): Define as 256. (ppc64_elf_check_relocs): Don't store TLS_EXPLICIT even if char is more than 8 bits. (ppc64_elf_tls_optimize): Likewise. Make tls_set, tls_clear, and tls_type vars unsigned int. (ppc64_elf_relocate_section): Use r_type rather than TLS_EXPLICIT to select r_type edit.
2019-07-18[PowerPC] Rename TLS_TPRELGD to TLS_GDIEAlan Modra1-13/+11
Choose a better name, that reflects why the flag is set (GD to IE optimisation) rather than what the flag produces (TPREL64 reloc on a single GOT entry replacing a tls_index pair). * elf32-ppc.c (TLS_GDIE): Rename from TLS_TPRELGD throughout file. Correct comment. * elf64-ppc.c (TLS_GDIE): Likewise.
2019-07-18[PowerPC64] correct tprel offset limitAlan Modra1-3/+2
I don't expect anyone will have hit this bug. You'd need a TLS segment of 2G before you'd notice. * elf64-ppc.c (ppc64_elf_tls_optimize): Correct test for allowed range of tp-relative offsets.
2019-07-13Dynamic TLS section symbolsAlan Modra1-11/+28
It is possible to create shared libraries on PowerPC using -ftls-model=inital-exec or -ftls-model=local-exec. The first is half reasonable, getting you a shared library that can't be dlopen'd but otherwise is reasonable. The second is quite bad. Not only do you lose being able to dlopen, the library also has dynamic text relocations. Worse, the TPREL16_LO, TPREL16_HA and other TPREL16 dynamic relocs emitted were wrong, resulting in wrong values being applied by ld.so. Using the first TLS section symbol in dynamic relocations for local TLS symbols doesn't work. It's wrong because TLS symbols used by TLS relocs have values relative to the TLS segment, whereas the TLS section symbols are addresses. This patch instead uses a symbol index of zero which is used elsewhere by PowerPC on dynamic TLS relocs. It's not strictly ABI compliant to use a non-TLS symbol with TLS relocs but symbol index zero can be interpreted as "no symbol". Not using the first TLS section symbol means it doesn't need to be dynamic. The patch also fixes a further problem with PowerPC32 dynamic TPREL16* relocs, which shouldn't have the symbol value in the addend as we do for non-TLS symbols. bfd/ * elflink.c (_bfd_elf_omit_section_dynsym_default): Don't keep tls_sec. (_bfd_elf_init_1_index_section): Prefer not using TLS sections. (_bfd_elf_init_2_index_sections): Likewise. * elf64-ppc.c (ppc64_elf_relocate_section): When emitting dynamic relocations for local TLS symbols, use STN_UNDEF as the relocation symbol. * elf32-ppc.c (ppc_elf_relocate_section): Likewise, and don't leave TLS symbol value in the addend. ld/ * testsuite/ld-powerpc/tlsso.r: Update. * testsuite/ld-powerpc/tlsso32.g: Update. * testsuite/ld-powerpc/tlsso32.r: Update. * testsuite/ld-powerpc/tlstocso.r: Update. * testsuite/ld-cris/tls-dso-dtpoffd2.d: Update. * testsuite/ld-cris/tls-dso-dtpoffd4.d: Update. * testsuite/ld-cris/tls-dso-tpoffgotcomm1.d: Update. * testsuite/ld-cris/tls-gd-1.d: Update. * testsuite/ld-cris/tls-gd-1h.d: Update. * testsuite/ld-cris/tls-gd-2.d: Update. * testsuite/ld-cris/tls-gd-2h.d: Update. * testsuite/ld-cris/tls-ie-10.d: Update. * testsuite/ld-cris/tls-ie-11.d: Update. * testsuite/ld-cris/tls-ie-8.d: Update. * testsuite/ld-cris/tls-ie-9.d: Update. * testsuite/ld-cris/tls-js1.d: Update. * testsuite/ld-cris/tls-ld-4.d: Update. * testsuite/ld-cris/tls-ld-5.d: Update. * testsuite/ld-cris/tls-ld-6.d: Update. * testsuite/ld-cris/tls-ld-7.d: Update. * testsuite/ld-cris/tls-ldgd-14.d: Update. * testsuite/ld-cris/tls-ldgd-15.d: Update. * testsuite/ld-cris/tls-ldgdx-14.d: Update. * testsuite/ld-cris/tls-ldgdx-15.d: Update. * testsuite/ld-cris/tls-local-54.d: Update. * testsuite/ld-cris/tls-local-60.d: Update. * testsuite/ld-cris/tls-local-61.d: Update. * testsuite/ld-cris/tls-local-63.d: Update. * testsuite/ld-cris/tls-local-64.d: Update. * testsuite/ld-cris/tls-ok-30.d: Update. * testsuite/ld-cris/tls-ok-32.d: Update. * testsuite/ld-cris/tls-ok-34.d: Update. * testsuite/ld-mips-elf/tls-multi-got-1.got: Update. * testsuite/ld-mips-elf/tls-multi-got-1.r: Update. * testsuite/ld-mips-elf/tlsdyn-pie-o32.d: Update. * testsuite/ld-mips-elf/tlsdyn-pie-o32.got: Update. * testsuite/ld-mips-elf/tlslib-o32-hidden.got: Update. * testsuite/ld-mips-elf/tlslib-o32-ver.got: Update. * testsuite/ld-mips-elf/tlslib-o32.got: Update. * testsuite/ld-s390/tlspic.rd: Update. * testsuite/ld-s390/tlspic_64.rd: Update. * testsuite/ld-sparc/tlssunnopic32.rd: Update. * testsuite/ld-sparc/tlssunnopic64.rd: Update. * testsuite/ld-sparc/tlssunpic32.rd: Update. * testsuite/ld-sparc/tlssunpic64.rd: Update.
2019-06-23PR24704, Internal error building skiboot for powerpc64-linux-gnuAlan Modra1-16/+18
While the skiboot linker script bears some culpability in this PR, it's also true that the GOT indirect to GOT relative optimisation for 16-bit offsets isn't safe. At least, it isn't safe to remove the GOT entry based on distance between the GOT pointer and symbol calculated from the preliminary layout. So this patch removes that optimisation, and reduces the range allowed for 32-bit and 34-bit offsets. PR 24704 bfd/ * elf64-ppc.c (R_PPC64_GOT16_DS): Don't set has_gotrel. (ppc64_elf_edit_toc): Don't remove R_PPC64_GOT16_DS got entries. Reduce range of offsets allowed for other GOT relocs. ld/ * testsuite/ld-powerpc/elfv2exe.d: Update. * testsuite/ld-powerpc/elfv2so.d: Update.
2019-06-19PowerPC64 notoc callsAlan Modra1-3/+3
Calls from functions that don't have a valid toc pointer in r2 (these calls are marked with _NOTOC relocs) to functions that require r2 valid must go via the callee global entry point. This patch corrects the condition the linker was using to detect functions that require r2 to be valid. Values of both zero and one in st_other local entry bits mean a function doesn't care about r2. * elf64-ppc.c (ppc64_elf_inline_plt): Correct st_other test for functions that require r2 valid to use local entry. (ppc64_elf_size_stubs, ppc64_elf_relocate_section): Likewise.
2019-06-14PowerPC comment fixesAlan Modra1-5/+5
"paddi rt,sym@pcrel" as an abbreviation for "paddi rt,0,sym@pcrel,1" is invalid, so replace with "pla rt,sym@pcrel" which is a valid form of "pla rt,sym@pcrel(0),1". * elf64-ppc.c: Fix comments involving paddi.
2019-05-24PowerPC notoc linkage stubsAlan Modra1-43/+281
Use pcrel addressing instructions in linkage stubs. bfd/ * elf64-ppc.c: Comment on powerxx _notoc stub variants. (LI_R11_0, LIS_R11, ORI_R11_R11_0, SLDI_R11_R11_34): Define. (PADDI_R12_PC, PLD_R12_PC, D34, HA34): Define. (struct ppc_link_hash_table): Add powerxx_stubs. (ppc64_elf_check_relocs): Set powerxx_stubs. (build_powerxx_offset, size_powerxx_offset), (num_relocs_for_powerxx_offset), (emit_relocs_for_powerxx_offset): New functions. (plt_stub_size): Size powerxx stubs. (ppc_build_one_stub): Emit powerxx stubs. (ppc_size_one_stub): Size powerxx stubs. Omit .eh_frame for powerxx stubs. ld/ * testsuite/ld-powerpc/notoc2.d, * testsuite/ld-powerpc/notoc2.s: New test. * testsuite/ld-powerpc/powerpc.exp: Run it.
2019-05-24PowerPC GOT_PCREL34 optimisationAlan Modra1-13/+210
bfd/ * elf64-ppc.c (ppc64_elf_check_relocs): Set has_gotrel for R_PPC64_GOT_PCREL34. (xlate_pcrel_opt): New function. (ppc64_elf_edit_toc): Handle R_PPC64_GOT_PCREL34. (ppc64_elf_relocate_section): Edit GOT indirect to GOT relative for R_PPC64_GOT_PCREL34. Implement R_PPC64_PCREL_OPT optimisation. ld/ * testsuite/ld-powerpc/pcrelopt.s, * testsuite/ld-powerpc/pcrelopt.d, * testsuite/ld-powerpc/pcrelopt.sec: New test. * testsuite/ld-powerpc/powerpc.exp: Run it.
2019-05-24PowerPC relocations for prefix insnsAlan Modra1-41/+368
include/ * elf/ppc64.h (R_PPC64_PLTSEQ_NOTOC, R_PPC64_PLTCALL_NOTOC), (R_PPC64_PCREL_OPT, R_PPC64_D34, R_PPC64_D34_LO, R_PPC64_D34_HI30), (R_PPC64_D34_HA30, R_PPC64_PCREL34, R_PPC64_GOT_PCREL34), (R_PPC64_PLT_PCREL34, R_PPC64_PLT_PCREL34_NOTOC), (R_PPC64_ADDR16_HIGHER34, R_PPC64_ADDR16_HIGHERA34), (R_PPC64_ADDR16_HIGHEST34, R_PPC64_ADDR16_HIGHESTA34), (R_PPC64_REL16_HIGHER34, R_PPC64_REL16_HIGHERA34), (R_PPC64_REL16_HIGHEST34, R_PPC64_REL16_HIGHESTA34), (R_PPC64_D28, R_PPC64_PCREL28): Define. bfd/ * reloc.c (BFD_RELOC_PPC64_D34, BFD_RELOC_PPC64_D34_LO), (BFD_RELOC_PPC64_D34_HI30, BFD_RELOC_PPC64_D34_HA30), (BFD_RELOC_PPC64_PCREL34, BFD_RELOC_PPC64_GOT_PCREL34), (BFD_RELOC_PPC64_PLT_PCREL34), (BFD_RELOC_PPC64_ADDR16_HIGHER34, BFD_RELOC_PPC64_ADDR16_HIGHERA34), (BFD_RELOC_PPC64_ADDR16_HIGHEST34, BFD_RELOC_PPC64_ADDR16_HIGHESTA34), (BFD_RELOC_PPC64_REL16_HIGHER34, BFD_RELOC_PPC64_REL16_HIGHERA34), (BFD_RELOC_PPC64_REL16_HIGHEST34, BFD_RELOC_PPC64_REL16_HIGHESTA34), (BFD_RELOC_PPC64_D28, BFD_RELOC_PPC64_PCREL28): New reloc enums. * elf64-ppc.c (PNOP): Define. (ppc64_elf_howto_raw): Add reloc howtos for new relocations. (ppc64_elf_reloc_type_lookup): Translate new bfd reloc numbers. (ppc64_elf_ha_reloc): Adjust addend for highera34 and highesta34 relocs. (ppc64_elf_prefix_reloc): New function. (struct ppc_link_hash_table): Add notoc_plt. (is_branch_reloc): Add R_PPC64_PLTCALL_NOTOC. (is_plt_seq_reloc): Add R_PPC64_PLT_PCREL34, R_PPC64_PLT_PCREL34_NOTOC, and R_PPC64_PLTSEQ_NOTOC. (ppc64_elf_check_relocs): Handle pcrel got and plt relocs. Set has_pltcall for section on seeing R_PPC64_PLTCALL_NOTOC. Handle possible need for dynamic relocs on non-pcrel powerxx relocs. (dec_dynrel_count): Handle non-pcrel powerxx relocs. (ppc64_elf_inline_plt): Handle R_PPC64_PLTCALL_NOTOC. (toc_adjusting_stub_needed): Likewise. (ppc64_elf_tls_optimize): Handle R_PPC64_PLTSEQ_NOTOC. (ppc64_elf_relocate_section): Handle new powerxx relocs. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. gas/ * config/tc-ppc.c (ppc_elf_suffix): Support @pcrel, @got@pcrel, @plt@pcrel, @higher34, @highera34, @highest34, and @highesta34. (fixup_size): Handle new powerxx relocs. (md_assemble): Warn for @pcrel on non-prefix insns. Accept @l, @h and @ha on prefix insns, and infer reloc without any @ suffix. Translate powerxx relocs to suit DQ and DS field instructions. Include operand tests as well as opcode test to translate BFD_RELOC_HI16_S to BFD_RELOC_PPC_16DX_HA. (ppc_fix_adjustable): Return false for pcrel GOT and PLT relocs. (md_apply_fix): Handle new powerxx relocs. * config/tc-ppc.h (TC_FORCE_RELOCATION_SUB_LOCAL): Accept BFD_RELOC_PPC64_ADDR16_HIGHER34, BFD_RELOC_PPC64_ADDR16_HIGHERA34, BFD_RELOC_PPC64_ADDR16_HIGHEST34, BFD_RELOC_PPC64_ADDR16_HIGHESTA34, BFD_RELOC_PPC64_D34, and BFD_RELOC_PPC64_D28. * testsuite/gas/ppc/prefix-reloc.d, * testsuite/gas/ppc/prefix-reloc.s: New test. * testsuite/gas/ppc/ppc.exp: Run it.
2019-04-30PowerPC64 GOT indirect to GOT relative optimisationAlan Modra1-3/+207
This implements an optimisation that converts sequences like addis r9,r2,sym@got@ha ld r3,sym@got@l(r9) to addis r9,r2,sym@toc@ha addi r3,r9,sym@toc@l when "sym" is locally defined and can't be overridden. bfd/ * elf64-ppc.c (struct ppc64_elf_obj_tdata): Add has_gotrel. (struct _ppc64_elf_section_data): Likewise. (ppc64_elf_check_relocs): Set above fields. (ppc64_elf_edit_toc): Add a pass over GOT relocs. (ppc64_elf_relocate_section): Edit GOT indirect to GOT relative when possible. ld/ * testsuite/ld-powerpc/elfv2exe.d: Update. * testsuite/ld-powerpc/elfv2so.d: Update. * testsuite/ld-powerpc/tocopt.d: Update. * testsuite/ld-powerpc/tocopt.s: Update. * testsuite/ld-powerpc/tocopt5.d: Update. * testsuite/ld-powerpc/tocopt5.s: Update. * testsuite/ld-powerpc/tocopt7.d: Update. * testsuite/ld-powerpc/tocopt7.s: Update. * testsuite/ld-powerpc/tocopt8.d: Update. * testsuite/ld-powerpc/tocopt8.s: Update.
2019-04-11Check corrupt VTENTRY entry in bfd_elf_gc_record_vtentryH.J. Lu1-3/+1
Instead of BFD_ASSERT (h != NULL) with ld: BFD ... assertion fail .../bfd/elf64-x86-64.c:2562 ld: bad.o: invalid string offset 50331648 >= 371 for section `nterp' check corrupt VTENTRY entry in bfd_elf_gc_record_vtentry with ld: bad.o: section 'g': corrupt VTENTRY entry * elf-m10300.c (mn10300_elf_check_relocs): Remove BFD_ASSERT of "h != NULL". Don't check "h != NULL" before calling. bfd_elf_gc_record_vtentry. * elf32-arm.c (elf32_arm_check_relocs): Likewise. * elf32-bfin.c (bfin_check_relocs): Likewise. * elf32-cris.c (cris_elf_check_relocs): Likewise. * elf32-csky.c (csky_elf_check_relocs): Likewise. * elf32-d10v.c (elf32_d10v_check_relocs): Likewise. * elf32-dlx.c (elf32_dlx_check_relocs): Likewise. * elf32-fr30.c (fr30_elf_check_relocs): Likewise. * elf32-frv.c (elf32_frv_check_relocs): Likewise. * elf32-hppa.c (elf32_hppa_check_relocs): Likewise. * elf32-i386.c (elf_i386_check_relocs): Likewise. * elf32-iq2000.c (iq2000_elf_check_relocs): Likewise. * elf32-m32r.c (m32r_elf_check_relocs): Likewise. * elf32-m68hc1x.c (elf32_m68hc11_check_relocs): Likewise. * elf32-m68k.c (elf_m68k_check_relocs): Likewise. * elf32-mcore.c (mcore_elf_check_relocs): Likewise. * elf32-metag.c (elf_metag_check_relocs): Likewise. * elf32-or1k.c (or1k_elf_check_relocs): Likewise. * elf32-ppc.c (ppc_elf_check_relocs): Likewise. * elf32-s390.c (elf_s390_check_relocs): Likewise. * elf32-sh.c (sh_elf_check_relocs): Likewise. * elf32-v850.c (v850_elf_check_relocs): Likewise. * elf32-vax.c (elf_vax_check_relocs): Likewise. * elf32-xstormy16.c (xstormy16_elf_check_relocs): Likewise. * elf32-xtensa.c (elf_xtensa_check_relocs): Likewise. * elf64-mmix.c (mmix_elf_check_relocs): Likewise. * elf64-ppc.c (ppc64_elf_check_relocs): Likewise. * elf64-s390.c (elf_s390_check_relocs): Likewise. * elf64-x86-64.c (elf_s390_check_relocs): Likewise. * elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise. * elflink.c (bfd_elf_gc_record_vtinherit): Check for corrupt VTENTRY entry.
2019-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2018-12-31[PowerPC64] Nop out ld 2,24(1) after old-style __tls_get_addrAlan Modra1-1/+9
When optimising inline plt calls to __tls_get_addr without tls marker relocs, ld should zap any toc restore insn after the bctrl, to stop a load-hit-store stall. * elf64-ppc.c (ppc64_elf_relocate_section <tls_ldgd_opt>): When editing an old-style __tls_get_addr call, replace a toc restore insn with a nop.
2018-12-18PR23980, assertion failAlan Modra1-1/+5
All of the backend relocate_section functions that interpret reloc numbers assuming the input file is of the expected type (ie. same as output or very similar) really ought to be checking input file type. Not many do, and those that do currently just assert. This patch replaces the assertion with a more graceful exit. PR 23980 * elf32-i386.c (elf_i386_relocate_section): Exit with wrong format error rather than asserting input file is as expected. * elf32-s390.c (elf_s390_relocate_section): Likewise. * elf32-sh.c (sh_elf_relocate_section): Likewise. * elf32-xtensa.c (elf_xtensa_relocate_section): Likewise. * elf64-ppc.c (ppc64_elf_relocate_section): Likewise. * elf64-s390.c (elf_s390_relocate_section): Likewise. * elf64-x86-64.c (elf_x86_64_relocate_section): Likewise. * elf32-ppc.c (ppc_elf_relocate_section): Exit with wrong format error if input file is not ppc32 ELF.
2018-12-18PR23980, powerpc64 ld segfaultAlan Modra1-0/+3
PR 23980 * elf64-ppc.c (ppc64_elf_hide_symbol): Check hash table type before referencing ppc64-only fields of hash entries.
2018-11-30PR23937, powerpc64le local ifunc IRELATIVE relocs are wrongAlan Modra1-1/+2
IFUNC resolvers must always be called via their global entry point. They will be called from ld.so rather than from the local executable. PR 23937 bfd/ * elf64-ppc.c (write_plt_relocs_for_local_syms): Don't add local entry offset for ifuncs. ld/ * testsuite/ld-powerpc/pr23937.d, * testsuite/ld-powerpc/pr23937.s: New test. * testsuite/ld-powerpc/powerpc.exp: Run it.
2018-10-13_bfd_clear_contents bounds checkingAlan Modra1-1/+1
This PR shows a fuzzed binary triggering a segfault via a bad relocation in .debug_line. It turns out that unlike normal relocations applied to a section, the linker applies those with symbols from discarded sections via _bfd_clear_contents without checking that the relocation is within the section bounds. The same thing now happens when reading debug sections since commit a4cd947aca23, the PR23425 fix. PR 23770 PR 23425 * reloc.c (_bfd_clear_contents): Replace "location" param with "buf" and "off". Bounds check "off". Return status. * cofflink.c (_bfd_coff_generic_relocate_section): Update _bfd_clear_contents call. * elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): Likewise. * elf32-arc.c (elf_arc_relocate_section): Likewise. * elf32-i386.c (elf_i386_relocate_section): Likewise. * elf32-metag.c (metag_final_link_relocate): Likewise. * elf32-nds32.c (nds32_elf_get_relocated_section_contents): Likewise. * elf32-ppc.c (ppc_elf_relocate_section): Likewise. * elf32-visium.c (visium_elf_relocate_section): Likewise. * elf64-ppc.c (ppc64_elf_relocate_section): Likewise. * elf64-x86-64.c *(elf_x86_64_relocate_section): Likewise. * libbfd-in.h (_bfd_clear_contents): Update prototype. * libbfd.h: Regenerate.
2018-08-31PowerPC64 --emit-relocs support for notoc stubsAlan Modra1-37/+189
This patch uses the newly defined high-part REL16 relocs to emit relocations on the notoc stubs as we already do for other stubs. * elf64-ppc.c (num_relocs_for_offset): New function. (emit_relocs_for_offset): New function. (use_global_in_relocs): New function, split out from.. (ppc_build_one_stub): ..here. Output relocations for notoc stubs. (ppc_size_one_stub): Calculate reloc count for notoc stubs. (ppc64_elf_size_stubs): Don't count undefined syms in stub_globals.
2018-08-31PowerPC64 higher REL16 relocationsAlan Modra1-0/+45
There are occasions where someone might want to build a 64-bit pc-relative offset from 16-bit pieces. This adds the necessary REL16 relocs corresponding to existing ADDR16 relocs that can be used to build 64-bit absolute values. include/ * elf/ppc64.h (R_PPC64_REL16_HIGH, R_PPC64_REL16_HIGHA), (R_PPC64_REL16_HIGHER, R_PPC64_REL16_HIGHERA), (R_PPC64_REL16_HIGHEST, R_PPC64_REL16_HIGHESTA): Define. (R_PPC64_LO_DS_OPT, R_PPC64_16DX_HA): Bump value. bfd/ * reloc.c (BFD_RELOC_PPC64_REL16_HIGH, BFD_RELOC_PPC64_REL16_HIGHA), (BFD_RELOC_PPC64_REL16_HIGHER, BFD_RELOC_PPC64_REL16_HIGHERA), (BFD_RELOC_PPC64_REL16_HIGHEST, BFD_RELOC_PPC64_REL16_HIGHESTA): Define. * elf64-ppc.c (ppc64_elf_howto_raw): Add new REL16 howtos. (ppc64_elf_reloc_type_lookup): Translate new REL16 relocs. (ppc64_elf_check_relocs, ppc64_elf_relocate_section): Handle them. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. gas/ * config/tc-ppc.h (TC_FORCE_RELOCATION_SUB_LOCAL): Allow ADDR16 HIGH, HIGHA, HIGHER, HIGHERA, HIGHEST, and HIGHESTA relocs. Group 16-bit relocs. * config/tc-ppc.c (md_apply_fix): Translate those ADDR16 relocs to REL16 when pcrel. Sort relocs.
2018-08-31Rearrange ppc_size_one_stub and correct _notoc stub examplesAlan Modra1-230/+274
This patch rearranges ppc_size_one_stub to make it a little easier to compare against ppc_build_one_stub, and makes a few other random changes that might help for future maintenance. There should be no functional changes here. The patch also fixes code examples in comments. A couple of "ori" instructions lacked the source register operand, and "@high" is the correct reloc modifier to use in a sequence building a 64-bit value. (@hi reports overflow of a 32-bit signed value.) * elf64-ppc.c: Correct _notoc stub comments. (ppc_build_one_stub): Simplify output of branch for notoc long branch stub. Don't include label offset of 8 bytes in "off" calculation for notoc plt stub. Don't emit insns to get pc. (build_offset): Emit insns to get pc here instead. (size_offset): Add 4 extra insns. (plt_stub_size): Adjust for "off" and size_offset changes. (ppc_size_one_stub): Rearrange code into a switch, duplicating some to better match ppc_build_one_stub.
2018-08-24PowerPC64 "call lacks nop"Alan Modra1-2/+2
The "-fPIC" and "-mcmodel=small" parts of these messages isn't always true, so lets dispense with that and just report the type of stub causing trouble. * elf64-ppc.c (ppc64_elf_relocate_section): Revise "call lacks nop" error message.
2018-08-23Fix "unresolved reloc" error for NOTOC relocsAlan Modra1-3/+2
* elf64-ppc.c (ppc64_elf_relocate_section): Don't miss clearing unresolved_reloc on ppc_stub_plt_call_notoc.
2018-08-21PowerPC HOWTOsAlan Modra1-1676/+274
These take up far too many lines in the files. This patch introduces a replacement for the HOWTO macro that simplifies the relow howto initialization. Apart from the two relocs mentioned in the ChangeLog, no relocation howto is changed. * elf64-ppc.c (HOW): Define. (ONES): Delete. (ppc64_elf_howto_raw): Use HOW to initialize entries. * elf32-ppc.c (HOW): Define. (ppc_elf_howto_raw): Use HOW to initialize entries, updating R_PPC_VLE_REL15 and R_PPC_VLE_REL24 to use bitpos=0.
2018-08-16Correct elf64-ppc.c linkage stub comment and formatting fixesAlan Modra1-77/+89
ppc_stub_long_branch_notoc will never need more than a 32-bit offset for the r12 offset since the stub target must be in range of a branch instruction. * elf64-ppc.c: Correct ppc_stub_long_branch_notoc example. Formatting.
2018-08-07PowerPC64 EH info for _notoc linkage stubsAlan Modra1-140/+248
This patch generates EH info for the new _notoc linkage stubs, to support unwinding from asynchronous signal handlers. Unwinding through the __tls_get_addr_opt stub was already supported, but that was just a single stub. With multiple stubs the EH opcodes need to be emitted and sized when iterating over stubs, so this is done when emitting and sizing the stub code. Emitting the CIEs and FDEs is done when sizing the stubs, as we did before in order to have the linker generated FDEs indexed in .eh_frame_hdr. I moved the final tweaks to FDEs from ppc64_elf_finish_dynamic_sections to ppc64_elf_build_stubs simply because it's tidier to be done with them at that point. bfd/ * elf64-ppc.c (struct map_stub): Delete tls_get_addr_opt_bctrl. Add lr_restore, eh_size and eh_base. (eh_advance, eh_advance_size): New functions. (build_tls_get_addr_stub): Emit EH info for stub. (ppc_build_one_stub): Likewise for _notoc stubs. (ppc_size_one_stub): Size EH info for stub. (group_sections): Init new map_stub fields. (stub_eh_frame_size): Delete. (ppc64_elf_size_stubs): Size EH info for stubs. Set up dummy EH program for stubs. (ppc64_elf_build_stubs): Reinit new map_stub fields. Set FDE offset to stub section here.. (ppc64_elf_finish_dynamic_sections): ..rather than here. ld/ * testsuite/ld-powerpc/notoc.s: Generate some cfi. * testsuite/ld-powerpc/notoc.d: Adjust. * testsuite/ld-powerpc/notoc.wf: New file. * testsuite/ld-powerpc/powerpc.exp: Run "ext" and "notoc" tests as run_ld_link_tests rather than run_dump_test.
2018-08-07__tls_get_addr_opt stubs and tocsave optimizationAlan Modra1-6/+7
This patch fixes a bug in the handling of the __tls_get_addr_opt stub. Calls via this stub don't have a toc restoring instruction following the "bl", and the stub itself doesn't have an initial toc save instruction. Thus it is incorrect to skip over the first instruction when a __tls_get_addr call is marked with a tocsave reloc. * elf64-ppc.c (ppc64_elf_relocate_section): Don't skip first instruction of __tls_get_addr_opt stub. (plt_stub_size): Omit ALWAYS_EMIT_R2SAVE condition when dealing with __tls_get_addr_opt stub. (build_tls_get_addr_stub, ppc_size_one_stub): Likewise.
2018-08-05R_PPC64_REL24_NOTOC supportAlan Modra1-117/+573
R_PPC64_REL24_NOTOC is used on calls like "bl foo@notoc" to tell the linker that linkage stubs for PLT calls or long branches can't use r2 for pic addressing. Instead, new stubs that generate pc-relative addresses are used. One complication is that pc-relative offsets to the PLT may need to be 64-bit in large programs, in contrast to the toc-relative addressing used by older PLT linkage stubs where a 32-bit offset is sufficient until the PLT itself exceeds 2G in size. .eh_frame info to cover the _notoc stubs is yet to be implemented. bfd/ * elf64-ppc.c (ADDI_R12_R11, ADDI_R12_R12, LIS_R12), (ADDIS_R12_R11, ORIS_R12_R12_0, ORI_R12_R12_0), (SLDI_R12_R12_32, LDX_R12_R11_R12, ADD_R12_R11_R12): Define. (ppc64_elf_howto_raw): Add R_PPC64_REL24_NOTOC entry. (ppc64_elf_reloc_type_lookup): Support R_PPC64_REL24_NOTOC. (ppc_stub_type): Add ppc_stub_long_branch_notoc, ppc_stub_long_branch_both, ppc_stub_plt_branch_notoc, ppc_stub_plt_branch_both, ppc_stub_plt_call_notoc, and ppc_stub_plt_call_both. (is_branch_reloc): Add R_PPC64_REL24_NOTOC. (build_offset, size_offset): New functions. (plt_stub_size): Support plt_call_notoc and plt_call_both. (ppc_build_one_stub, ppc_size_one_stub): Support new stubs. (toc_adjusting_stub_needed): Handle R_PPC64_REL24_NOTOC. (ppc64_elf_size_stubs): Likewise, and new stubs. (ppc64_elf_build_stubs, ppc64_elf_relocate_section): Likewise. * reloc.c: Add BFD_RELOC_PPC64_REL24_NOTOC. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. gas/ * config/tc-ppc.c (ppc_elf_suffix): Support @notoc. (ppc_force_relocation, ppc_fix_adjustable): Handle REL24_NOTOC. ld/ * testsuite/ld-powerpc/ext.d, * testsuite/ld-powerpc/ext.s, * testsuite/ld-powerpc/ext.lnk, * testsuite/ld-powerpc/notoc.d, * testsuite/ld-powerpc/notoc.s: New tests. * testsuite/ld-powerpc/powerpc.exp: Run them.
2018-08-05Lose _r2off in powerpc64 stub namesAlan Modra1-2/+2
Not a lot is conveyed by putting _r2off in a stub symbol that can't be seen by inspecting the stub code or the toc restoring instruction immediately after a call via such a stub. Also, we don't distinguish plt_call stub symbols from plt_call_r2save stub symbols, so this patch makes long branch and plt branch stub symbols consistent with that decision. bfd/ * elf64-ppc.c (ppc_build_one_stub): Lose "_r2off" in stub symbols. ld/ * testsuite/ld-powerpc/elfv2exe.d: Adjust for stub symbol change. * testsuite/ld-powerpc/tocopt6.d: Likewise.
2018-08-01PowerPC64 __tls_get_addr_opt stub .eh_frame fixAlan Modra1-61/+64
This patch sets stub_offset in ppc_size_one_stub rather than in ppc_build_one_stub. That allows the plt stub alignment to be done in just ppc_size_one_stub rather than both functions. The patch also corrects the place where the alignment was done, fixing a possible error in .eh_frame data, and tidies some offset calculations. bfd/ * elf64-ppc.c (plt_stub_pad): Delay plt_stub_size call until needed. (ppc_build_one_stub): Don't set stub_offset, instead assert that it is sane. Don't adjust stub_offset for alignment. Adjust size calculation. Use "targ" temp when calculating offsets. (ppc_size_one_stub): Set stub_offset here. Use "targ" temp when calculating offsets. Adjust for alignment before setting tls_get_addr_opt_bctrl. ld/ * testsuite/ld-powerpc/powerpc.exp: Run tlsopt5 with plt alignment. * testsuite/ld-powerpc/tlsopt5.s: Add extra call. * testsuite/ld-powerpc/tlsopt5.wf: Adjust expected output. * testsuite/ld-powerpc/tlsopt5.d: Likewise.
2018-07-26Implement PowerPC64 .localentry for value 1Alan Modra1-6/+9
This adds support for ".localentry 1", a new st_other STO_PPC64_LOCAL_MASK encoding that signifies a function with a single entry point like ".localentry 0", but unlike a ".localentry 0" function does not preserve r2. include/ * elf/ppc64.h: Specify byte offset to local entry for values of two to six in STO_PPC64_LOCAL_MASK. Clarify r2 return value for such functions when entering via global entry point. Specify meaning of a value of one in STO_PPC64_LOCAL_MASK. bfd/ * elf64-ppc.c (ppc64_elf_size_stubs): Use a ppc_stub_long_branch_r2off for calls to symbols with STO_PPC64_LOCAL_MASK bits set to 1. gas/ * config/tc-ppc.c (ppc_elf_localentry): Allow .localentry values of 1 and 7 to directly set value into STO_PPC64_LOCAL_MASK bits. ld/testsuite/ * ld-powerpc/elfv2.s: Add .localentry f5,1 testcase. * ld-powerpc/elfv2exe.d: Update. * ld-powerpc/elfv2so.d: Update.
2018-07-25Suppress string diagnostics for pre-release GCCAlan Modra1-3/+3
Extends commit 898ade12ee8 to cover other targets. * elf32-arm.c (elf32_arm_nabi_write_core_note): Disable -Wstringop-truncation warning for gcc-8.0 too. * elf32-ppc.c (ppc_elf_write_core_note): Likewise. * elf64-ppc.c (ppc64_elf_write_core_note): Likewise. * elfxx-aarch64.c (_bfd_aarch64_elf_write_core_note): Likewise. * elf32-s390.c (elf_s390_write_core_note): Comment fix. * elf64-s390.c (elf_s390_write_core_note): Likewise.
2018-07-06Fix diagnostic errorsAlan Modra1-1/+3
Fixes a number of build errors like the following .../elf32-arm.c: In function 'elf32_arm_nabi_write_core_note': .../elf32-arm.c:2177: error: #pragma GCC diagnostic not allowed inside functions .../elf32-arm.c:2186: error: #pragma GCC diagnostic not allowed inside functions See the comment in diagnostics.h. include/ * diagnostics.h: Comment on macro usage. bfd/ * elf32-arm.c (elf32_arm_nabi_write_core_note): Don't use DIAGNOTIC_PUSH and DIAGNOSTIC_POP unconditionally. * elf32-ppc.c (ppc_elf_write_core_note): Likewise. * elf32-s390.c (elf_s390_write_core_note): Likewise. * elf64-ppc.c (ppc64_elf_write_core_note): Likewise. * elf64-s390.c (elf_s390_write_core_note): Likewise. * elfxx-aarch64.c (_bfd_aarch64_elf_write_core_note): Likewise.
2018-07-05Error for mismatched powerpc ABI tagsAlan Modra1-1/+2
And report the two input files that are incompatible rather than reporting that an input file is incompatible with the output. bfd/ * elf-bfd.h (_bfd_elf_ppc_merge_fp_attributes): Update prototype. * elf32-ppc.c (_bfd_elf_ppc_merge_fp_attributes): Return error on mismatch. Remove "warning: " from messages. Track last bfd used to set tags. (ppc_elf_merge_obj_attributes): Likewise. Handle status from _bfd_elf_ppc_merge_fp_attributes. * elf64-ppc.c (ppc64_elf_merge_private_bfd_data): Handle status from _bfd_elf_ppc_merge_fp_attributes. ld/ * testsuite/ld-powerpc/attr-gnu-4-12.d: Update expected output. * testsuite/ld-powerpc/attr-gnu-4-13.d: Likewise. * testsuite/ld-powerpc/attr-gnu-4-21.d: Likewise. * testsuite/ld-powerpc/attr-gnu-4-23.d: Likewise. * testsuite/ld-powerpc/attr-gnu-4-31.d: Likewise. * testsuite/ld-powerpc/attr-gnu-4-32.d: Likewise. * testsuite/ld-powerpc/attr-gnu-8-23.d: Likewise. * testsuite/ld-powerpc/attr-gnu-12-21.d: Likewise.
2018-07-03GNU attribute output on errorsAlan Modra1-3/+1
.gnu.attributes entries from linker input files are merged to the output file, the output having the union of compatible input attributes. Incompatible attributes generally cause a linker error and no output. However in some cases only a warning is emitted, and one of the incompatible input attributes is passed on to the output. PowerPC tends to emit warnings rather than errors, and the output takes the first input attribute. For example, if we have two input files with Tag_GNU_Power_ABI_FP, the first with a value signifying "double-precision hard float, IBM long double", the second with a value signifying "double-precision hard float, IEEE long double", we'll get a warning about incompatible long double types and the output will say "double-precision hard float, IBM long double". The output attribute of course isn't correct. It would be correct to specify "IBM and IEEE long double", but we don't have a way to represent that currently. While it would be possible to extend the encoding, there isn't much gain in doing so. A shared library providing support for both long double types should link against objects using either long double type without warning or error. That is what you'd get if such a shared library had no Tag_GNU_Power_ABI_FP attribute. So this patch provides a way for the backend to omit .gnu.attributes tags from the output. * elf-bfd.h (ATTR_TYPE_FLAG_ERROR, ATTR_TYPE_HAS_ERROR): Define. * elf-attrs.c (is_default_attr): Handle ATTR_TYPE_HAS_ERROR. * elf32-ppc.c (_bfd_elf_ppc_merge_fp_attributes): Use ATTR_TYPE_FLAG_INT_VAL. Set ATTR_TYPE_HAS_ERROR on finding incompatible attribute. (ppc_elf_merge_obj_attributes): Likewise. Return _bfd_elf_merge_object_attributes result. * elf64-ppc.c (ppc64_elf_merge_private_bfd_data): Return _bfd_elf_merge_object_attributes result.
2018-06-04Use DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION to silence GCC 8.1H.J. Lu1-0/+9
GCC 8.1 warns about destination size with -Wstringop-truncation: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643 Use DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION to silence it. bfd/ PR binutils/23146 * bfd-in.h: Include "diagnostics.h". * bfd-in2.h: Regenerated. * elf32-arm.c (elf32_arm_nabi_write_core_note): Use DIAGNOSTIC_PUSH, DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION and DIAGNOSTIC_POP to silence GCC 8.1 warnings with -Wstringop-truncation. * elf32-ppc.c (ppc_elf_write_core_note): Likewse. * elf32-s390.c (elf_s390_write_core_note): Likewse. * elf64-ppc.c (ppc64_elf_write_core_note): Likewse. * elf64-s390.c (elf_s390_write_core_note): Likewse. * elfxx-aarch64.c (_bfd_aarch64_elf_write_core_note): Likewse. include/ * diagnostics.h (DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION): Always define for GCC.
2018-05-28ld: Unify STT_GNU_IFUNC handlingH.J. Lu1-5/+0
Take STT_GNU_IFUNC handling scattered across targets and gather it in the generic ELF linker. bfd/ PR ld/23238 * elf-s390-common.c (elf_s390_add_symbol_hook): Removed. * elf32-arc.c (elf_arc_add_symbol_hook): Likewise. (elf_backend_add_symbol_hook): Likewise. * elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise. (elf_backend_add_symbol_hook): Likewise. * elf32-s390.c (elf_backend_add_symbol_hook): Likewise. * elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise. (elf_backend_add_symbol_hook): Likewise. * elf64-s390.c (elf_backend_add_symbol_hook): Likewise. * elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise. * elfxx-aarch64.h (_bfd_aarch64_elf_add_symbol_hook): Likewise. (elf_backend_add_symbol_hook): Likewise. * elf32-arm.c (elf32_arm_add_symbol_hook): Remove STT_GNU_IFUNC handling. * elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise. * elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise. * elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise. * elflink.c (elf_link_add_object_symbols): Set elf_gnu_symbol_ifunc for STT_GNU_IFUNC symbols. ld/ PR ld/23238 * testsuite/ld-ifunc/ifunc-26.d: New file. * testsuite/ld-ifunc/ifunc-26.s: Likewise. * testsuite/ld-ifunc/ifunc.exp: Run *.d tests without a working compiler.
2018-05-23Add ATTRIBUTE_NONSTRING to ppc64_elf_write_core_noteH.J. Lu1-1/+1
This patch silences gcc8 -Wstringop-truncation warnings. * elf64-ppc.c (ppc64_elf_write_core_note): Add ATTRIBUTE_NONSTRING to data.
2018-05-16PR22458, failure to choose a matching ELF targetAlan Modra1-1/+1
https://sourceware.org/ml/binutils/2013-05/msg00271.html was supposed to banish "file format is ambiguous" errors for ELF. It didn't, because the code supposedly detecting formats that implement match_priority didn't work. That was due to not placing all matching targets into the vector of matching targets. ELF objects should all match the generic ELF target (priority 2), plus one or more machine specific targets (priority 1), and perhaps a single machine specific target with OS/ABI set (priority 0, best match). So the armel object in the testcase actually matches elf32-littlearm, elf32-littlearm-symbian, and elf32-littlearm-vxworks (all priority 1), and elf32-little (priority 2). As the PR reported, elf32-little wasn't seen as matching. Fixing that part of the problem wasn't too difficult but matching the generic ELF target as well as the ARM ELF targets resulted in ARM testsuite failures. These proved to be the annoying reordering of stubs that occurs from time to time due to the stub names containing the section id. Matching another target causes more sections to be created in elf_object_p. If section ids change, stub names change, which results in different hashing and can therefore result in different hash table traversal and stub creation order. That particular problem is fixed by resetting section_id to the initial state before attempting each target match, and taking a snapshot of its value after a successful match. PR 22458 * format.c (struct bfd_preserve): Add section_id. (bfd_preserve_save, bfd_preserve_restore): Save and restore _bfd_section_id. (bfd_reinit): Set _bfd_section_id. (bfd_check_format_matches): Put all matches of any priority into matching_vector. Save initial section id and start each attempted match at that section id. * libbfd-in.h (_bfd_section_id): Declare. * section.c (_bfd_section_id): Rename from section_id and make global. Adjust uses. (bfd_get_next_section_id): Delete. * elf64-ppc.c (ppc64_elf_setup_section_lists): Replace use of bfd_get_section_id with _bfd_section_id. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate.
2018-04-27PR23123, PowerPC32 ifunc regressionAlan Modra1-4/+4
Two of the gcc ifunc tests fail for ppc32, due to my pr22374 fix being a little too enthusiastic in trimming PLT entries. ppc64 doesn't have the same failures because ppc64_elf_check_relocs happens to set needs_plt for any ifunc reloc. PR 23123 PR 22374 * elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Don't drop plt relocs for ifuncs. * elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Comment fixes.
2018-04-26PPC64: always make synthetic .text symbols for GNU ifunc symbolsPedro Alves1-6/+16
If you create an ifunc using GCC's __attribute__ ifunc, like: extern int gnu_ifunc (int arg); static int gnu_ifunc_target (int arg) { return 0; } __typeof (gnu_ifunc) *gnu_ifunc_resolver (unsigned long hwcap) { return gnu_ifunc_target; } __typeof (gnu_ifunc) gnu_ifunc __attribute__ ((ifunc ("gnu_ifunc_resolver"))); then you end up with two (function descriptor) symbols, one for the ifunc itself, and another for the resolver: (...) 12: 0000000000020060 104 FUNC GLOBAL DEFAULT 18 gnu_ifunc_resolver (...) 16: 0000000000020060 104 GNU_IFUNC GLOBAL DEFAULT 18 gnu_ifunc (...) Both ifunc and resolver symbols have the same address/value, so ppc64_elf_get_synthetic_symtab only creates a synthetic text symbol for one of them. In the case above, it ends up being created for the resolver, only: (gdb) maint print msymbols (...) [ 7] t 0x980 .frame_dummy section .text [ 8] T 0x9e4 .gnu_ifunc_resolver section .text [ 9] T 0xa58 __glink_PLTresolve section .text (...) GDB needs to know when a program stepped into an ifunc resolver, so that it can know whether to step past the resolver into the target function without the user noticing. The way GDB does it is my checking whether the current PC points to an ifunc symbol (since resolver and ifunc have the same address by design). The problem is then that ppc64_elf_get_synthetic_symtab never creates the synchetic symbol for the ifunc, so GDB stops stepping at the resolver (in a test added by the following patch): (gdb) step gnu_ifunc_resolver (hwcap=21) at gdb/testsuite/gdb.base/gnu-ifunc-lib.c:33 33 { (gdb) FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=1: final_debug=0: step After this commit, we get: [ 8] i 0x9e4 .gnu_ifunc section .text [ 9] T 0x9e4 .gnu_ifunc_resolver section .text And stepping an ifunc call takes to the final function: (gdb) step 0x00000000100009e8 in .final () (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=1: final_debug=0: step An alternative to touching bfd I considered was for GDB to check whether there's an ifunc data symbol / function descriptor that points to the current PC, whenever the program stops, but discarded it because we'd have to do a linear scan over .opd over an over to find a matching function descriptor for the current PC. At that point I considered caching that info, but quickly dismissed it as then that has no advantage (memory or performance) over just creating the synthetic ifunc text symbol in the first place. I ran the binutils and ld testsuites on PPC64 ELFv1 (machine gcc110 on the GCC compile farm), and saw no regressions. This commit is part of a GDB patch series that includes GDB tests that fail without this fix. bfd/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Don't consider ifunc and non-ifunc symbols duplicates.
2018-04-14powerpc common-page-sizeAlan Modra1-1/+2
max-page-size only matters for demand paged executables or shared libraries, and the ideal size is the largest value used by your operating system. Values larger than necessary just waste file space and memory. common-page-size also affects file and memory size, trading a possible small increase in file size for a decrease in memory size when the operating system is using a common-page-size page. With a powerpc max-page-size of 64k and common-page-size of 4k many executables will use no more memory pages when the system page size is 4k than an executable linked with -z max-page-size=0x1000, yet will still run on a system using 64k pages. However, when running on a system using 64k pages relro protection will not be completely effective. Due to the relro problem, powerpc binutils has been using a default common-page-size of 64k since 2014-12-18 (git commit 04c6a44c7), leading to complaints about increased file and memory sizes. People not using relro do have a valid reason to complain.. So this patch introduces an extra back-end value to use as the default for common-page-size when generating relro executables, and enables the support for powerpc. Non relro executables will now be generated with a default common-page-size of 4k. bfd/ * elf-bfd.h (struct elf_backend_data): Add relropagesize. * elfxx-target.h (ELF_RELROPAGESIZE): Provide default and sanity test. (elfNN_bed): Init relropagesize. * bfd.c (bfd_emul_get_commonpagesize): Add boolean param to select relropagesize. * elf32-ppc.c (ELF_COMMONPAGESIZE): Define as 0x1000. (ELF_RELROPAGESIZE): Define as ELF_MAXPAGESIZE. (ELF_MINPAGESIZE): Don't define. * elf64-ppc.c (ELF_COMMONPAGESIZE): Define as 0x1000. (ELF_RELROPAGESIZE): Define as ELF_MAXPAGESIZE. * bfd-in2.h: Regenerate. ld/ * ldmain.c (main): Move config.maxpagesize and config.commonpagesize initialization to.. * ldemul.c (after_parse_default): ..here. * testsuite/ld-powerpc/ppc476-shared.d: Pass -z common-page-size. * testsuite/ld-powerpc/ppc476-shared2.d: Likewise.
2018-04-09Inline PLT call optimizationAlan Modra1-4/+164
This patch adds the analysis part of PLT call optimization, enabling the code added with the previous patch that actually performs the optimization. Gold support is not available yet. bfd/ * elf64-ppc.c (struct _ppc64_elf_section_data): Add has_pltcall field. (struct ppc_link_hash_table): Add can_convert_all_inline_plt. (ppc64_elf_check_relocs): Set has_pltcall. (ppc64_elf_adjust_dynamic_symbol): Discard some PLT entries. (ppc64_elf_inline_plt): New function. (ppc64_elf_size_dynamic_sections): Discard some PLT entries for locals. * elf64-ppc.h (ppc64_elf_inline_plt): Declare. * elf32-ppc.c (has_pltcall): Define. (struct ppc_elf_link_hash_table): Add can_convert_all_inline_plt. (ppc_elf_check_relocs): Set has_pltcall. (ppc_elf_inline_plt): New function. (ppc_elf_adjust_dynamic_symbol): Discard some PLT entries. (ppc_elf_size_dynamic_sections): Likewise. * elf32-ppc.h (ppc_elf_inline_plt): Declare. ld/ * emultempl/ppc64elf.em (no_inline_plt): New var. (ppc_before_allocation): Call ppc64_elf_inline_plt. (enum ppc64_opt): Add OPTION_NO_INLINE_OPT. (PARSE_AND_LIST_LONGOPTS, PARSE_AND_LIST_OPTIONS, PARSE_AND_LIST_ARGS_CASES): Handle --no-inline-optimize. * emultemps/ppc32elf.em (no_inline_opt): New var. (prelim_size_sections): New function, extracted from.. (ppc_before_allocation): ..here. Call ppc_elf_inline_plt. (enum ppc32_opt): Add OPTION_NO_INLINE_OPT. (PARSE_AND_LIST_LONGOPTS, PARSE_AND_LIST_OPTIONS, PARSE_AND_LIST_ARGS_CASES): Handle --no-inline-optimize.