From 45965137bee4946dca3cd99285f2a7afe6b99aeb Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 5 Mar 2014 19:57:39 +1030 Subject: Support R_PPC64_ADDR64_LOCAL This adds support for "func@localentry", an expression that returns the ELFv2 local entry point address of function "func". I've excluded dynamic relocation support because that obviously would require glibc changes. include/elf/ * ppc64.h (R_PPC64_REL24_NOTOC, R_PPC64_ADDR64_LOCAL): Define. bfd/ * elf64-ppc.c (ppc64_elf_howto_raw): Add R_PPC64_ADDR64_LOCAL entry. (ppc64_elf_reloc_type_lookup): Support R_PPC64_ADDR64_LOCAL. (ppc64_elf_check_relocs): Likewise. (ppc64_elf_relocate_section): Likewise. * Add BFD_RELOC_PPC64_ADDR64_LOCAL. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. gas/ * config/tc-ppc.c (ppc_elf_suffix): Support @localentry. (md_apply_fix): Support R_PPC64_ADDR64_LOCAL. ld/testsuite/ * ld-powerpc/elfv2-2a.s, ld-powerpc/elfv2-2b.s: New files. * ld-powerpc/elfv2-2exe.d, ld-powerpc/elfv2-2so.d: New files. * ld-powerpc/powerpc.exp: Run new test. elfcpp/ * powerpc.h (R_PPC64_REL24_NOTOC, R_PPC64_ADDR64_LOCAL): Define. gold/ * powerpc.cc (Target_powerpc::Scan::local, global): Support R_PPC64_ADDR64_LOCAL. (Target_powerpc::Relocate::relocate): Likewise. --- bfd/ChangeLog | 10 +++++++++ bfd/bfd-in2.h | 1 + bfd/elf64-ppc.c | 38 +++++++++++++++++++++++++++++++++ bfd/libbfd.h | 1 + bfd/reloc.c | 2 ++ elfcpp/ChangeLog | 4 ++++ elfcpp/powerpc.h | 2 ++ gas/ChangeLog | 5 +++++ gas/config/tc-ppc.c | 2 ++ gold/ChangeLog | 6 ++++++ gold/powerpc.cc | 10 +++++++++ include/elf/ChangeLog | 4 ++++ include/elf/ppc64.h | 4 ++++ ld/testsuite/ChangeLog | 6 ++++++ ld/testsuite/ld-powerpc/elfv2-2a.s | 27 ++++++++++++++++++++++++ ld/testsuite/ld-powerpc/elfv2-2b.s | 17 +++++++++++++++ ld/testsuite/ld-powerpc/elfv2-2exe.d | 41 ++++++++++++++++++++++++++++++++++++ ld/testsuite/ld-powerpc/elfv2-2so.d | 5 +++++ ld/testsuite/ld-powerpc/powerpc.exp | 2 ++ 19 files changed, 187 insertions(+) create mode 100644 ld/testsuite/ld-powerpc/elfv2-2a.s create mode 100644 ld/testsuite/ld-powerpc/elfv2-2b.s create mode 100644 ld/testsuite/ld-powerpc/elfv2-2exe.d create mode 100644 ld/testsuite/ld-powerpc/elfv2-2so.d diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 857e84e..5e93508 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,13 @@ +2014-03-05 Alan Modra + + * elf64-ppc.c (ppc64_elf_howto_raw): Add R_PPC64_ADDR64_LOCAL entry. + (ppc64_elf_reloc_type_lookup): Support R_PPC64_ADDR64_LOCAL. + (ppc64_elf_check_relocs): Likewise. + (ppc64_elf_relocate_section): Likewise. + * Add BFD_RELOC_PPC64_ADDR64_LOCAL. + * bfd-in2.h: Regenerate. + * libbfd.h: Regenerate. + 2014-03-04 Heiher * elfxx-mips.c (mips_set_isa_flags): Use E_MIPS_ARCH_64R2 for diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index ebc7496..9832639 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -3259,6 +3259,7 @@ instruction. */ BFD_RELOC_PPC64_PLTGOT16_LO_DS, BFD_RELOC_PPC64_ADDR16_HIGH, BFD_RELOC_PPC64_ADDR16_HIGHA, + BFD_RELOC_PPC64_ADDR64_LOCAL, /* PowerPC and PowerPC64 thread-local storage relocations. */ BFD_RELOC_PPC_TLS, diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 633d8db..7a93eda 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -2095,6 +2095,21 @@ static reloc_howto_type ppc64_elf_howto_raw[] = { 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ + /* Like ADDR64, but use local entry point of function. */ + HOWTO (R_PPC64_ADDR64_LOCAL, /* type */ + 0, /* rightshift */ + 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ + 64, /* bitsize */ + FALSE, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_PPC64_ADDR64_LOCAL", /* name */ + FALSE, /* partial_inplace */ + 0, /* src_mask */ + ONES (64), /* dst_mask */ + FALSE), /* pcrel_offset */ + /* GNU extension to record C++ vtable hierarchy. */ HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ 0, /* rightshift */ @@ -2383,6 +2398,8 @@ ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, break; case BFD_RELOC_HI16_S_PCREL: r = R_PPC64_REL16_HA; break; + case BFD_RELOC_PPC64_ADDR64_LOCAL: r = R_PPC64_ADDR64_LOCAL; + break; case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT; break; case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY; @@ -5400,6 +5417,21 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, case R_PPC64_REL16_HA: break; + /* Not supported as a dynamic relocation. */ + case R_PPC64_ADDR64_LOCAL: + if (info->shared) + { + if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) + ppc_howto_init (); + info->callbacks->einfo (_("%P: %H: %s reloc unsupported " + "in shared libraries and PIEs.\n"), + abfd, sec, rel->r_offset, + ppc64_elf_howto_table[r_type]->name); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + break; + case R_PPC64_TOC16: case R_PPC64_TOC16_DS: htab->do_multi_toc = 1; @@ -14134,6 +14166,12 @@ ppc64_elf_relocate_section (bfd *output_bfd, addend -= htab->elf.tls_sec->vma + DTP_OFFSET; break; + case R_PPC64_ADDR64_LOCAL: + addend += PPC64_LOCAL_ENTRY_OFFSET (h != NULL + ? h->elf.other + : sym->st_other); + break; + case R_PPC64_DTPMOD64: relocation = 1; addend = 0; diff --git a/bfd/libbfd.h b/bfd/libbfd.h index bbca43f..69cabab 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -1401,6 +1401,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_PPC64_PLTGOT16_LO_DS", "BFD_RELOC_PPC64_ADDR16_HIGH", "BFD_RELOC_PPC64_ADDR16_HIGHA", + "BFD_RELOC_PPC64_ADDR64_LOCAL", "BFD_RELOC_PPC_TLS", "BFD_RELOC_PPC_TLSGD", "BFD_RELOC_PPC_TLSLD", diff --git a/bfd/reloc.c b/bfd/reloc.c index 5cc6e0c..792214f 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -2899,6 +2899,8 @@ ENUMX BFD_RELOC_PPC64_ADDR16_HIGH ENUMX BFD_RELOC_PPC64_ADDR16_HIGHA +ENUMX + BFD_RELOC_PPC64_ADDR64_LOCAL ENUMDOC Power(rs6000) and PowerPC relocations. diff --git a/elfcpp/ChangeLog b/elfcpp/ChangeLog index e6ec60d..fc30035 100644 --- a/elfcpp/ChangeLog +++ b/elfcpp/ChangeLog @@ -1,3 +1,7 @@ +2014-03-05 Alan Modra + + * powerpc.h (R_PPC64_REL24_NOTOC, R_PPC64_ADDR64_LOCAL): Define. + 2014-02-06 Andrew Pinski * mips.h (E_MIPS_MACH_OCTEON3): New enum constant. diff --git a/elfcpp/powerpc.h b/elfcpp/powerpc.h index 98354a2..0d156b1 100644 --- a/elfcpp/powerpc.h +++ b/elfcpp/powerpc.h @@ -176,6 +176,8 @@ enum R_PPC_EMB_BIT_FLD = 115, R_PPC64_DTPREL16_HIGHA = 115, R_PPC_EMB_RELSDA = 116, + R_PPC64_REL24_NOTOC = 116, + R_PPC64_ADDR64_LOCAL = 117, R_PPC_VLE_REL8 = 216, R_PPC_VLE_REL15 = 217, diff --git a/gas/ChangeLog b/gas/ChangeLog index dae0368..0549f39 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,5 +1,10 @@ 2014-03-05 Alan Modra + * config/tc-ppc.c (ppc_elf_suffix): Support @localentry. + (md_apply_fix): Support R_PPC64_ADDR64_LOCAL. + +2014-03-05 Alan Modra + * config/tc-ppc.c (md_assemble): Move code adjusting reloc types later. Merge absolute and relative branch reloc selection. Generate 16-bit relocs for most 16-bit insn fields given a diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c index 6ffbe13..838f522 100644 --- a/gas/config/tc-ppc.c +++ b/gas/config/tc-ppc.c @@ -1952,6 +1952,7 @@ ppc_elf_suffix (char **str_p, expressionS *exp_p) MAP64 ("dtprel@highera", BFD_RELOC_PPC64_DTPREL16_HIGHERA), MAP64 ("dtprel@highest", BFD_RELOC_PPC64_DTPREL16_HIGHEST), MAP64 ("dtprel@highesta", BFD_RELOC_PPC64_DTPREL16_HIGHESTA), + MAP64 ("localentry", BFD_RELOC_PPC64_ADDR64_LOCAL), MAP64 ("tprel@high", BFD_RELOC_PPC64_TPREL16_HIGH), MAP64 ("tprel@higha", BFD_RELOC_PPC64_TPREL16_HIGHA), MAP64 ("tprel@higher", BFD_RELOC_PPC64_TPREL16_HIGHER), @@ -6844,6 +6845,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) case BFD_RELOC_PPC64_HIGHEST_S: case BFD_RELOC_PPC64_ADDR16_HIGH: case BFD_RELOC_PPC64_ADDR16_HIGHA: + case BFD_RELOC_PPC64_ADDR64_LOCAL: break; case BFD_RELOC_PPC_DTPMOD: diff --git a/gold/ChangeLog b/gold/ChangeLog index f600b84..8ccb431 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,9 @@ +2014-03-05 Alan Modra + + * powerpc.cc (Target_powerpc::Scan::local, global): Support + R_PPC64_ADDR64_LOCAL. + (Target_powerpc::Relocate::relocate): Likewise. + 2014-03-03 Alan Modra * dwp.cc (print_version): Update copyright year to current. diff --git a/gold/powerpc.cc b/gold/powerpc.cc index 1aa4791..8130149 100644 --- a/gold/powerpc.cc +++ b/gold/powerpc.cc @@ -5482,6 +5482,7 @@ Target_powerpc::Scan::local( case elfcpp::R_PPC64_DTPREL16_HIGHESTA: case elfcpp::R_PPC64_TLSGD: case elfcpp::R_PPC64_TLSLD: + case elfcpp::R_PPC64_ADDR64_LOCAL: break; case elfcpp::R_POWERPC_GOT16: @@ -5928,6 +5929,7 @@ Target_powerpc::Scan::global( case elfcpp::R_PPC64_DTPREL16_HIGHESTA: case elfcpp::R_PPC64_TLSGD: case elfcpp::R_PPC64_TLSLD: + case elfcpp::R_PPC64_ADDR64_LOCAL: break; case elfcpp::R_POWERPC_GOT16: @@ -7137,6 +7139,13 @@ Target_powerpc::Relocate::relocate( value -= dtp_offset; break; + case elfcpp::R_PPC64_ADDR64_LOCAL: + if (gsym != NULL) + value += object->ppc64_local_entry_offset(gsym); + else + value += object->ppc64_local_entry_offset(r_sym); + break; + default: break; } @@ -7339,6 +7348,7 @@ Target_powerpc::Relocate::relocate( case elfcpp::R_PPC64_ADDR64: case elfcpp::R_PPC64_REL64: case elfcpp::R_PPC64_TOC: + case elfcpp::R_PPC64_ADDR64_LOCAL: Reloc::addr64(view, value); break; diff --git a/include/elf/ChangeLog b/include/elf/ChangeLog index bd18469..bf7a370 100644 --- a/include/elf/ChangeLog +++ b/include/elf/ChangeLog @@ -1,3 +1,7 @@ +2014-03-05 Alan Modra + + * ppc64.h (R_PPC64_REL24_NOTOC, R_PPC64_ADDR64_LOCAL): Define. + 2014-02-06 Andrew Pinski * mips.h (E_MIPS_MACH_OCTEON3): New machine flag. diff --git a/include/elf/ppc64.h b/include/elf/ppc64.h index 78d947b..30ed8bc 100644 --- a/include/elf/ppc64.h +++ b/include/elf/ppc64.h @@ -149,6 +149,10 @@ START_RELOC_NUMBERS (elf_ppc64_reloc_type) RELOC_NUMBER (R_PPC64_DTPREL16_HIGH, 114) RELOC_NUMBER (R_PPC64_DTPREL16_HIGHA, 115) +/* Added for ELFv2. */ + RELOC_NUMBER (R_PPC64_REL24_NOTOC, 116) + RELOC_NUMBER (R_PPC64_ADDR64_LOCAL, 117) + #ifndef RELOC_MACROS_GEN_FUNC /* Fake relocation only used internally by ld. */ RELOC_NUMBER (R_PPC64_LO_DS_OPT, 128) diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 701b088..b083aec 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-03-05 Alan Modra + + * ld-powerpc/elfv2-2a.s, ld-powerpc/elfv2-2b.s: New files. + * ld-powerpc/elfv2-2exe.d, ld-powerpc/elfv2-2so.d: New files. + * ld-powerpc/powerpc.exp: Run new test. + 2014-03-03 Alan Modra * ld-scripts/phdrs2.exp: Correct copyright punctuation. diff --git a/ld/testsuite/ld-powerpc/elfv2-2a.s b/ld/testsuite/ld-powerpc/elfv2-2a.s new file mode 100644 index 0000000..303087a --- /dev/null +++ b/ld/testsuite/ld-powerpc/elfv2-2a.s @@ -0,0 +1,27 @@ + .globl f1 + .type f1,@function + .text +f1: + addis 2,12,.TOC.-f1@ha + addi 2,2,.TOC.-f1@l + .localentry f1,.-f1 + blr + .size f1,.-f1 + + .globl f2 + .type f2,@function + .text +f2: + addi 2,12,.TOC.-f2 + .localentry f2,.-f2 + blr + .size f2,.-f2 + + .quad f1 + .quad f1@localentry + .quad f2 + .quad f2@localentry + .quad f3 + .quad f3@localentry + .quad f4 + .quad f4@localentry diff --git a/ld/testsuite/ld-powerpc/elfv2-2b.s b/ld/testsuite/ld-powerpc/elfv2-2b.s new file mode 100644 index 0000000..9c9d75e --- /dev/null +++ b/ld/testsuite/ld-powerpc/elfv2-2b.s @@ -0,0 +1,17 @@ + .globl f3 + .type f3,@function + .text +f3: + addis 2,12,.TOC.-f3@ha + addi 2,2,.TOC.-f3@l + .localentry f3,.-f3 + blr + .size f3,.-f3 + + .globl f4 + .type f4,@function + .text +f4: + .localentry f4,0 + blr + .size f4,.-f4 diff --git a/ld/testsuite/ld-powerpc/elfv2-2exe.d b/ld/testsuite/ld-powerpc/elfv2-2exe.d new file mode 100644 index 0000000..c8deda1 --- /dev/null +++ b/ld/testsuite/ld-powerpc/elfv2-2exe.d @@ -0,0 +1,41 @@ +#source: elfv2-2a.s +#source: elfv2-2b.s +#as: -a64 +#ld: -melf64ppc -e f1 +#objdump: -dr + +.* + +Disassembly of section \.text: + +0+10000078 : +.*: (3c 40 10 01|01 10 40 3c) lis r2,4097 +.*: (38 42 80 78|78 80 42 38) addi r2,r2,-32648 +.*: (4e 80 00 20|20 00 80 4e) blr +0+10000084 : +.*: (38 4c 7f f4|f4 7f 4c 38) addi r2,r12,32756 +.*: (4e 80 00 20|20 00 80 4e) blr +.*: (00 00 00 00|78 00 00 10) .* +.*: (10 00 00 78|00 00 00 00) .* +.*: (00 00 00 00|80 00 00 10) .* +.*: (10 00 00 80|00 00 00 00) .* +.*: (00 00 00 00|84 00 00 10) .* +.*: (10 00 00 84|00 00 00 00) .* +.*: (00 00 00 00|88 00 00 10) .* +.*: (10 00 00 88|00 00 00 00) .* +.*: (00 00 00 00|cc 00 00 10) .* +.*: (10 00 00 cc|00 00 00 00) .* +.*: (00 00 00 00|d4 00 00 10) .* +.*: (10 00 00 d4|00 00 00 00) .* +.*: (00 00 00 00|d8 00 00 10) .* +.*: (10 00 00 d8|00 00 00 00) .* +.*: (00 00 00 00|d8 00 00 10) .* +.*: (10 00 00 d8|00 00 00 00) .* + +0+100000cc : +.*: (3c 40 10 01|01 10 40 3c) lis r2,4097 +.*: (38 42 80 78|78 80 42 38) addi r2,r2,-32648 +.*: (4e 80 00 20|20 00 80 4e) blr + +0+100000d8 : +.*: (4e 80 00 20|20 00 80 4e) blr diff --git a/ld/testsuite/ld-powerpc/elfv2-2so.d b/ld/testsuite/ld-powerpc/elfv2-2so.d new file mode 100644 index 0000000..56b1434 --- /dev/null +++ b/ld/testsuite/ld-powerpc/elfv2-2so.d @@ -0,0 +1,5 @@ +#source: elfv2-2a.s +#source: elfv2-2b.s +#as: -a64 +#ld: -melf64ppc -shared -e f1 +#error: .* R_PPC64_ADDR64_LOCAL reloc unsupported in shared libraries and PIEs.* diff --git a/ld/testsuite/ld-powerpc/powerpc.exp b/ld/testsuite/ld-powerpc/powerpc.exp index 87e4ea8..2e8c126 100644 --- a/ld/testsuite/ld-powerpc/powerpc.exp +++ b/ld/testsuite/ld-powerpc/powerpc.exp @@ -271,6 +271,8 @@ if [ supports_ppc64 ] then { run_dump_test "relbrlt" run_dump_test "elfv2so" run_dump_test "elfv2exe" + run_dump_test "elfv2-2so" + run_dump_test "elfv2-2exe" } if { [istarget "powerpc*-eabi*"] } { -- cgit v1.1