From 7b5b197e80f04c9b95fe7fafbd9907fc61a1e43d Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 12 Sep 2011 18:17:36 +0000 Subject: [PATCH] Use .got.plt for IFUNC symbols if there are no GOT relocations. bfd/ 2011-09-12 H.J. Lu PR ld/13178 * elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Use .got.plt if there are no GOT relocations. ld/testsuite/ 2011-09-12 H.J. Lu PR ld/13178 * ld-ifunc/ifunc-13-i386.d: Updated. * ld-ifunc/ifunc-13-x86-64.d: Likewise. * ld-ifunc/ifunc-3a-x86.d: Likewise. * ld-x86-64/pr13082-5a.d: Likewise. * ld-ifunc/ifunc-15-i386.d: New. * ld-ifunc/ifunc-15-i386.s: Likewise. * ld-ifunc/ifunc-15-x86-64.d: Likewise. * ld-ifunc/ifunc-15-x86-64.s: Likewise. --- bfd/ChangeLog | 6 ++++++ bfd/elf-ifunc.c | 7 ++++--- ld/testsuite/ChangeLog | 13 +++++++++++++ ld/testsuite/ld-ifunc/ifunc-13-i386.d | 13 ++++++------- ld/testsuite/ld-ifunc/ifunc-13-x86-64.d | 10 +++------- ld/testsuite/ld-ifunc/ifunc-15-i386.d | 13 +++++++++++++ ld/testsuite/ld-ifunc/ifunc-15-i386.s | 10 ++++++++++ ld/testsuite/ld-ifunc/ifunc-15-x86-64.d | 13 +++++++++++++ ld/testsuite/ld-ifunc/ifunc-15-x86-64.s | 10 ++++++++++ ld/testsuite/ld-ifunc/ifunc-3a-x86.d | 2 +- ld/testsuite/ld-x86-64/pr13082-5a.d | 3 +-- 11 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 ld/testsuite/ld-ifunc/ifunc-15-i386.d create mode 100644 ld/testsuite/ld-ifunc/ifunc-15-i386.s create mode 100644 ld/testsuite/ld-ifunc/ifunc-15-x86-64.d create mode 100644 ld/testsuite/ld-ifunc/ifunc-15-x86-64.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 5339ad0..9d63ff6 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2011-09-12 H.J. Lu + + PR ld/13178 + * elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Use .got.plt + if there are no GOT relocations. + 2011-09-09 Kai Tietz * peicode.h (pe_ILF_build_a_bfd): Don't remove leading underscore diff --git a/bfd/elf-ifunc.c b/bfd/elf-ifunc.c index 81429b8..3ba96c7 100644 --- a/bfd/elf-ifunc.c +++ b/bfd/elf-ifunc.c @@ -299,9 +299,10 @@ keep: 5. Otherwise use .got so that it can be shared among different objects at run-time. We only need to relocate .got entry in shared object. */ - if ((info->shared - && (h->dynindx == -1 - || h->forced_local)) + if (h->got.refcount <= 0 + || (info->shared + && (h->dynindx == -1 + || h->forced_local)) || (!info->shared && !h->pointer_equality_needed) || (info->executable && info->shared) diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 2de5268..3c00fe4 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2011-09-12 H.J. Lu + + PR ld/13178 + * ld-ifunc/ifunc-13-i386.d: Updated. + * ld-ifunc/ifunc-13-x86-64.d: Likewise. + * ld-ifunc/ifunc-3a-x86.d: Likewise. + * ld-x86-64/pr13082-5a.d: Likewise. + + * ld-ifunc/ifunc-15-i386.d: New. + * ld-ifunc/ifunc-15-i386.s: Likewise. + * ld-ifunc/ifunc-15-x86-64.d: Likewise. + * ld-ifunc/ifunc-15-x86-64.s: Likewise. + 2011-09-01 Christophe Lyon * ld-arm/arm-elf.exp: Add new rodata-merge-map test. diff --git a/ld/testsuite/ld-ifunc/ifunc-13-i386.d b/ld/testsuite/ld-ifunc/ifunc-13-i386.d index 162c3e4..55cca22 100644 --- a/ld/testsuite/ld-ifunc/ifunc-13-i386.d +++ b/ld/testsuite/ld-ifunc/ifunc-13-i386.d @@ -5,15 +5,14 @@ #readelf: -r --wide #target: x86_64-*-* i?86-*-* -Relocation section '.rel.got' at .* +Relocation section '.rel.got' at offset 0x[0-9a-f]+ contains 1 entries: [ ]+Offset[ ]+Info[ ]+Type[ ]+.* -#... -[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_GLOB_DAT[ ]+ifunc\(\)[ ]+ifunc -#... -Relocation section '.rel.ifunc' at .* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_RELATIVE[ ]+ + +Relocation section '.rel.ifunc' at offset 0x[0-9a-f]+ contains 1 entries: [ ]+Offset[ ]+Info[ ]+Type[ ]+.* [0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_32[ ]+ifunc\(\)[ ]+ifunc -#... -Relocation section '.rel.plt' at .* + +Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entries: [ ]+Offset[ ]+Info[ ]+Type[ ]+.* [0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_JUMP_SLOT[ ]+ifunc\(\)[ ]+ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-13-x86-64.d b/ld/testsuite/ld-ifunc/ifunc-13-x86-64.d index d0c0647..b01c735 100644 --- a/ld/testsuite/ld-ifunc/ifunc-13-x86-64.d +++ b/ld/testsuite/ld-ifunc/ifunc-13-x86-64.d @@ -5,14 +5,10 @@ #readelf: -r --wide #target: x86_64-*-* -Relocation section '.rela.got' at .* -[ ]+Offset[ ]+Info[ ]+Type[ ]+.* -[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_GLOB_DAT[ ]+ifunc\(\)[ ]+ifunc \+ 0 -#... -Relocation section '.rela.ifunc' at .* +Relocation section '.rela.ifunc' at offset 0x[0-9a-f]+ contains 1 entries: [ ]+Offset[ ]+Info[ ]+Type[ ]+.* [0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_64[ ]+ifunc\(\)[ ]+ifunc \+ 0 -#... -Relocation section '.rela.plt' at .* + +Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries: [ ]+Offset[ ]+Info[ ]+Type[ ]+.* [0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_JUMP_SLOT[ ]+ifunc\(\)[ ]+ifunc \+ 0 diff --git a/ld/testsuite/ld-ifunc/ifunc-15-i386.d b/ld/testsuite/ld-ifunc/ifunc-15-i386.d new file mode 100644 index 0000000..c37dd51 --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-15-i386.d @@ -0,0 +1,13 @@ +#source: ifunc-15-i386.s +#ld: -shared -m elf_i386 -z nocombreloc +#as: --32 +#readelf: -r --wide +#target: x86_64-*-* i?86-*-* + +Relocation section '.rel.got' at offset 0x[0-9a-f]+ contains 1 entries: +[ ]+Offset[ ]+Info[ ]+Type[ ]+.* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_GLOB_DAT[ ]+ifunc\(\)[ ]+ifunc + +Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entries: +[ ]+Offset[ ]+Info[ ]+Type[ ]+.* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_JUMP_SLOT[ ]+ifunc\(\)[ ]+ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-15-i386.s b/ld/testsuite/ld-ifunc/ifunc-15-i386.s new file mode 100644 index 0000000..5ee4fab --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-15-i386.s @@ -0,0 +1,10 @@ + .text + .type foo, @function + .global +foo: + movl ifunc@GOT(%ebx), %eax + ret + .type ifunc, @gnu_indirect_function + .globl ifunc +ifunc: + ret diff --git a/ld/testsuite/ld-ifunc/ifunc-15-x86-64.d b/ld/testsuite/ld-ifunc/ifunc-15-x86-64.d new file mode 100644 index 0000000..a4a5cb1 --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-15-x86-64.d @@ -0,0 +1,13 @@ +#source: ifunc-15-x86-64.s +#ld: -shared -m elf_x86_64 -z nocombreloc +#as: --64 +#readelf: -r --wide +#target: x86_64-*-* + +Relocation section '.rela.got' at offset 0x[0-9a-f]+ contains 1 entries: +[ ]+Offset[ ]+Info[ ]+Type[ ]+.* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_GLOB_DAT[ ]+ifunc\(\)[ ]+ifunc \+ 0 + +Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries: +[ ]+Offset[ ]+Info[ ]+Type[ ]+.* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_JUMP_SLOT[ ]+ifunc\(\)[ ]+ifunc \+ 0 diff --git a/ld/testsuite/ld-ifunc/ifunc-15-x86-64.s b/ld/testsuite/ld-ifunc/ifunc-15-x86-64.s new file mode 100644 index 0000000..ee336de --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-15-x86-64.s @@ -0,0 +1,10 @@ + .text + .type foo, @function + .global +foo: + movl ifunc@GOTPCREL(%rip), %eax + ret + .type ifunc, @gnu_indirect_function + .globl ifunc +ifunc: + ret diff --git a/ld/testsuite/ld-ifunc/ifunc-3a-x86.d b/ld/testsuite/ld-ifunc/ifunc-3a-x86.d index 174999d..24be639 100644 --- a/ld/testsuite/ld-ifunc/ifunc-3a-x86.d +++ b/ld/testsuite/ld-ifunc/ifunc-3a-x86.d @@ -4,5 +4,5 @@ #target: x86_64-*-* i?86-*-* #... -[ \t0-9a-f]+:[ \t0-9a-f]+call[ \t0-9a-fq]+<\*ABS\*(\+0x1b0|\+0x260|)@plt> +[ \t0-9a-f]+:[ \t0-9a-f]+call[ \t0-9a-fq]+<\*ABS\*(\+0x1b0|\+0x240|)@plt> #pass diff --git a/ld/testsuite/ld-x86-64/pr13082-5a.d b/ld/testsuite/ld-x86-64/pr13082-5a.d index e5b0c11..191c29e 100644 --- a/ld/testsuite/ld-x86-64/pr13082-5a.d +++ b/ld/testsuite/ld-x86-64/pr13082-5a.d @@ -4,10 +4,9 @@ #ld: -shared -melf32_x86_64 #readelf: -r --wide -Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries: +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: Offset Info Type Sym. Value Symbol's Name \+ Addend [0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +ifunc\(\)+ +ifunc \+ 0 -[0-9a-f]+ +[0-9a-f]+ +R_X86_64_GLOB_DAT +ifunc\(\)+ +ifunc \+ 0 Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries: Offset Info Type Sym. Value Symbol's Name \+ Addend -- 2.7.4