From 946593d19f203b02efd45b5102dd2787d9418e24 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 25 May 2011 17:41:32 +0000 Subject: Handle STT_GNU_IFUNC symols when building shared library. bfd/ 2012-05-25 H.J. Lu Backport from mainline 2012-01-06 H.J. Lu PR ld/12366 PR ld/12371 * elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Properly handle symbols marked with regular reference, but not non-GOT reference when building shared library. * elf32-i386.c (elf_i386_gc_sweep_hook): Properly handle local and global STT_GNU_IFUNC symols when building shared library. * elf64-x86-64.c (elf_x86_64_gc_sweep_hook): Likewise. ld/testsuite/ 2012-05-25 H.J. Lu Backport from mainline 2012-01-06 H.J. Lu PR ld/12366 PR ld/12371 * ld-ifunc/ifunc-10-i386.s: Add more tests. * ld-ifunc/ifunc-10-x86-64.s: Likewise. * ld-ifunc/ifunc-11-i386.s: Likewise. * ld-ifunc/ifunc-11-x86-64.s: Likewise. * ld-ifunc/ifunc-12-i386.d: New. * ld-ifunc/ifunc-12-i386.s: Likewise. * ld-ifunc/ifunc-12-x86-64.d: Likewise. * ld-ifunc/ifunc-12-x86-64.s: Likewise. * ld-ifunc/ifunc-13-i386.d: Likewise. * ld-ifunc/ifunc-13-x86-64.d: Likewise. * ld-ifunc/ifunc-13a-i386.s: Likewise. * ld-ifunc/ifunc-13a-x86-64.s: Likewise. * ld-ifunc/ifunc-13b-i386.s: Likewise. * ld-ifunc/ifunc-13b-x86-64.s: Likewise. --- ld/testsuite/ld-ifunc/ifunc-10-i386.s | 6 ++++++ ld/testsuite/ld-ifunc/ifunc-10-x86-64.s | 5 +++++ ld/testsuite/ld-ifunc/ifunc-11-i386.s | 10 ++++++++-- ld/testsuite/ld-ifunc/ifunc-11-x86-64.s | 5 +++++ ld/testsuite/ld-ifunc/ifunc-12-i386.d | 6 ++++++ ld/testsuite/ld-ifunc/ifunc-12-i386.s | 25 +++++++++++++++++++++++++ ld/testsuite/ld-ifunc/ifunc-12-x86-64.d | 6 ++++++ ld/testsuite/ld-ifunc/ifunc-12-x86-64.s | 24 ++++++++++++++++++++++++ ld/testsuite/ld-ifunc/ifunc-13-i386.d | 19 +++++++++++++++++++ ld/testsuite/ld-ifunc/ifunc-13-x86-64.d | 18 ++++++++++++++++++ ld/testsuite/ld-ifunc/ifunc-13a-i386.s | 10 ++++++++++ ld/testsuite/ld-ifunc/ifunc-13a-x86-64.s | 10 ++++++++++ ld/testsuite/ld-ifunc/ifunc-13b-i386.s | 5 +++++ ld/testsuite/ld-ifunc/ifunc-13b-x86-64.s | 5 +++++ 14 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-ifunc/ifunc-12-i386.d create mode 100644 ld/testsuite/ld-ifunc/ifunc-12-i386.s create mode 100644 ld/testsuite/ld-ifunc/ifunc-12-x86-64.d create mode 100644 ld/testsuite/ld-ifunc/ifunc-12-x86-64.s create mode 100644 ld/testsuite/ld-ifunc/ifunc-13-i386.d create mode 100644 ld/testsuite/ld-ifunc/ifunc-13-x86-64.d create mode 100644 ld/testsuite/ld-ifunc/ifunc-13a-i386.s create mode 100644 ld/testsuite/ld-ifunc/ifunc-13a-x86-64.s create mode 100644 ld/testsuite/ld-ifunc/ifunc-13b-i386.s create mode 100644 ld/testsuite/ld-ifunc/ifunc-13b-x86-64.s (limited to 'ld/testsuite/ld-ifunc') diff --git a/ld/testsuite/ld-ifunc/ifunc-10-i386.s b/ld/testsuite/ld-ifunc/ifunc-10-i386.s index 8411e815eb..76c5bef9bd 100644 --- a/ld/testsuite/ld-ifunc/ifunc-10-i386.s +++ b/ld/testsuite/ld-ifunc/ifunc-10-i386.s @@ -6,6 +6,8 @@ foo: movl ifunc@GOTOFF(%ecx), %eax call ifunc@PLT call ifunc + movl xxx@GOT(%ecx), %eax + movl xxx, %eax ret .section .text.bar,"ax",@progbits @@ -18,3 +20,7 @@ bar: .type ifunc, @gnu_indirect_function ifunc: ret + + .section .data.foo,"aw",@progbits +xxx: + .long ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-10-x86-64.s b/ld/testsuite/ld-ifunc/ifunc-10-x86-64.s index ea6f8c2d16..11e29b52b4 100644 --- a/ld/testsuite/ld-ifunc/ifunc-10-x86-64.s +++ b/ld/testsuite/ld-ifunc/ifunc-10-x86-64.s @@ -6,6 +6,7 @@ foo: movl ifunc(%rip), %eax call ifunc@PLT call ifunc + movl xxx(%rip), %eax ret .section .text.bar,"ax",@progbits @@ -18,3 +19,7 @@ bar: .type ifunc, @gnu_indirect_function ifunc: ret + + .section .data.foo,"aw",@progbits +xxx: + .quad ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-11-i386.s b/ld/testsuite/ld-ifunc/ifunc-11-i386.s index 06f592400e..e0e4740795 100644 --- a/ld/testsuite/ld-ifunc/ifunc-11-i386.s +++ b/ld/testsuite/ld-ifunc/ifunc-11-i386.s @@ -3,9 +3,11 @@ foo: .global foo movl ifunc@GOT(%ecx), %eax - movl ifunc@GOTOFF(%ecx), %eax + movl ifunc@GOTOFF(%ecx), %eax call ifunc@PLT call ifunc + movl xxx@GOT(%ecx), %eax + movl xxx, %eax ret .section .text.bar,"ax",@progbits @@ -16,6 +18,10 @@ bar: .section .text.ifunc,"ax",@progbits .type ifunc, @gnu_indirect_function - .global ifunc + .global ifunc ifunc: ret + + .section .data.foo,"aw",@progbits +xxx: + .long ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-11-x86-64.s b/ld/testsuite/ld-ifunc/ifunc-11-x86-64.s index 70d4fbfdb1..8525419b52 100644 --- a/ld/testsuite/ld-ifunc/ifunc-11-x86-64.s +++ b/ld/testsuite/ld-ifunc/ifunc-11-x86-64.s @@ -6,6 +6,7 @@ foo: movl ifunc(%rip), %eax call ifunc@PLT call ifunc + movl xxx(%rip), %eax ret .section .text.bar,"ax",@progbits @@ -19,3 +20,7 @@ bar: .global ifunc ifunc: ret + + .section .data.foo,"aw",@progbits +xxx: + .quad ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-12-i386.d b/ld/testsuite/ld-ifunc/ifunc-12-i386.d new file mode 100644 index 0000000000..de1418154e --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-12-i386.d @@ -0,0 +1,6 @@ +#ld: -shared -m elf_i386 -e bar --gc-sections +#as: --32 +#readelf: -r --wide +#target: x86_64-*-* i?86-*-* + +There are no relocations in this file. diff --git a/ld/testsuite/ld-ifunc/ifunc-12-i386.s b/ld/testsuite/ld-ifunc/ifunc-12-i386.s new file mode 100644 index 0000000000..840302f3ef --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-12-i386.s @@ -0,0 +1,25 @@ + .section .text.foo,"ax",@progbits + .type foo, @function +foo: + movl ifunc@GOT(%ecx), %eax + movl ifunc@GOTOFF(%ecx), %eax + call ifunc@PLT + call ifunc + movl xxx@GOT(%ecx), %eax + movl xxx, %eax + ret + + .section .text.bar,"ax",@progbits + .type bar, @function +bar: + .global bar + ret + + .section .text.ifunc,"ax",@progbits + .type ifunc, @gnu_indirect_function +ifunc: + ret + + .section .data.foo,"aw",@progbits +xxx: + .long ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-12-x86-64.d b/ld/testsuite/ld-ifunc/ifunc-12-x86-64.d new file mode 100644 index 0000000000..40f07c38bb --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-12-x86-64.d @@ -0,0 +1,6 @@ +#ld: -shared -m elf_x86_64 -e bar --gc-sections +#as: --64 +#readelf: -r --wide +#target: x86_64-*-* + +There are no relocations in this file. diff --git a/ld/testsuite/ld-ifunc/ifunc-12-x86-64.s b/ld/testsuite/ld-ifunc/ifunc-12-x86-64.s new file mode 100644 index 0000000000..491684bdc2 --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-12-x86-64.s @@ -0,0 +1,24 @@ + .section .text.foo,"ax",@progbits + .type foo, @function +foo: + movl ifunc@GOTPCREL(%rip), %eax + movl ifunc(%rip), %eax + call ifunc@PLT + call ifunc + movl xxx(%rip), %eax + ret + + .section .text.bar,"ax",@progbits + .type bar, @function +bar: + .global bar + ret + + .section .text.ifunc,"ax",@progbits + .type ifunc, @gnu_indirect_function +ifunc: + ret + + .section .data.foo,"aw",@progbits +xxx: + .quad ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-13-i386.d b/ld/testsuite/ld-ifunc/ifunc-13-i386.d new file mode 100644 index 0000000000..162c3e40f9 --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-13-i386.d @@ -0,0 +1,19 @@ +#source: ifunc-13a-i386.s +#source: ifunc-13b-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[ ]+Info[ ]+Type[ ]+.* +#... +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_GLOB_DAT[ ]+ifunc\(\)[ ]+ifunc +#... +Relocation section '.rel.ifunc' at .* +[ ]+Offset[ ]+Info[ ]+Type[ ]+.* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_32[ ]+ifunc\(\)[ ]+ifunc +#... +Relocation section '.rel.plt' at .* +[ ]+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 new file mode 100644 index 0000000000..d0c064773a --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-13-x86-64.d @@ -0,0 +1,18 @@ +#source: ifunc-13a-x86-64.s +#source: ifunc-13b-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[ ]+Info[ ]+Type[ ]+.* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_GLOB_DAT[ ]+ifunc\(\)[ ]+ifunc \+ 0 +#... +Relocation section '.rela.ifunc' at .* +[ ]+Offset[ ]+Info[ ]+Type[ ]+.* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_64[ ]+ifunc\(\)[ ]+ifunc \+ 0 +#... +Relocation section '.rela.plt' at .* +[ ]+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-13a-i386.s b/ld/testsuite/ld-ifunc/ifunc-13a-i386.s new file mode 100644 index 0000000000..eb893af3d3 --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-13a-i386.s @@ -0,0 +1,10 @@ + .text + .type foo, @function + .global +foo: + movl xxx@GOT(%ebx), %eax + ret + + .data +xxx: + .long ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-13a-x86-64.s b/ld/testsuite/ld-ifunc/ifunc-13a-x86-64.s new file mode 100644 index 0000000000..5bfc9e03b0 --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-13a-x86-64.s @@ -0,0 +1,10 @@ + .text + .type foo, @function + .global +foo: + movl xxx(%rip), %eax + ret + + .data +xxx: + .quad ifunc diff --git a/ld/testsuite/ld-ifunc/ifunc-13b-i386.s b/ld/testsuite/ld-ifunc/ifunc-13b-i386.s new file mode 100644 index 0000000000..3560394298 --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-13b-i386.s @@ -0,0 +1,5 @@ + .text + .type ifunc, @gnu_indirect_function + .globl ifunc +ifunc: + ret diff --git a/ld/testsuite/ld-ifunc/ifunc-13b-x86-64.s b/ld/testsuite/ld-ifunc/ifunc-13b-x86-64.s new file mode 100644 index 0000000000..3560394298 --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-13b-x86-64.s @@ -0,0 +1,5 @@ + .text + .type ifunc, @gnu_indirect_function + .globl ifunc +ifunc: + ret -- cgit v1.2.1