diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2016-04-11 09:21:27 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2016-04-11 09:21:27 -0700 |
commit | b9e99a0be4ba956203e5f2e172d936e1e5f23d88 (patch) | |
tree | b9f340267ab1e3c40f84df0b01d291d666f915d6 | |
parent | 994aad6437e82ba41192b2235aed5adad61331fd (diff) | |
download | binutils-gdb-users/hjl/pr19939.tar.gz |
Properly handle dynamic reloc against normal symbolusers/hjl/pr19939
We shouldn't issue an error for read-only segment with dynamic IFUNC
relocations when dynamic relocations are against normal symbols.
bfd/
PR ld/19939
* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Set
readonly_dynrelocs_against_ifunc to TRUE if dynamic reloc applies
to read-only section.
* elf32-i386.c (elf_i386_size_dynamic_sections): Issue an error
for read-only segment with dynamic IFUNC relocations only if
readonly_dynrelocs_against_ifunc is TRUE.
* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Likewise.
include/
PR ld/19939
* bfdlink.h (bfd_link_info): Add readonly_dynrelocs_against_ifunc.
ld/
PR ld/19939
* testsuite/ld-i386/i386.exp: Run PR ld/19939 tests.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-i386/pr19939.s: New file.
* testsuite/ld-i386/pr19939a.d: Likewise.
* testsuite/ld-i386/pr19939b.d: Likewise.
* testsuite/ld-x86-64/pr19939.s: Likewise.
* testsuite/ld-x86-64/pr19939a.d: Likewise.
* testsuite/ld-x86-64/pr19939b.d: Likewise.
-rw-r--r-- | bfd/elf-ifunc.c | 3 | ||||
-rw-r--r-- | bfd/elf32-i386.c | 3 | ||||
-rw-r--r-- | bfd/elf64-x86-64.c | 3 | ||||
-rw-r--r-- | include/bfdlink.h | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/i386.exp | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/pr19939.s | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/pr19939a.d | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/pr19939b.d | 8 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/pr19939.s | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/pr19939a.d | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/pr19939b.d | 8 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/x86-64.exp | 2 |
12 files changed, 55 insertions, 4 deletions
diff --git a/bfd/elf-ifunc.c b/bfd/elf-ifunc.c index 1368a8e124b..23ae3c4201d 100644 --- a/bfd/elf-ifunc.c +++ b/bfd/elf-ifunc.c @@ -231,6 +231,9 @@ keep: bfd_size_type count = 0; do { + asection *s = p->sec->output_section; + if (s != NULL && (s->flags & SEC_READONLY) != 0) + info->readonly_dynrelocs_against_ifunc = TRUE; count += p->count; p = p->next; } diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 1ebb61524d5..c00f4d96e7e 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -3553,8 +3553,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) if ((info->flags & DF_TEXTREL) != 0) { - if ((elf_tdata (output_bfd)->has_gnu_symbols - & elf_gnu_symbol_ifunc) == elf_gnu_symbol_ifunc) + if (info->readonly_dynrelocs_against_ifunc) { info->callbacks->einfo (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n")); diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index dc7738a3564..b083265360d 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -3899,8 +3899,7 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd, if ((info->flags & DF_TEXTREL) != 0) { - if ((elf_tdata (output_bfd)->has_gnu_symbols - & elf_gnu_symbol_ifunc) == elf_gnu_symbol_ifunc) + if (info->readonly_dynrelocs_against_ifunc) { info->callbacks->einfo (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n")); diff --git a/include/bfdlink.h b/include/bfdlink.h index a285f6dc5e2..5cd3bbedceb 100644 --- a/include/bfdlink.h +++ b/include/bfdlink.h @@ -452,6 +452,10 @@ struct bfd_link_info /* TRUE if generate a 1-byte NOP as suffix for x86 call instruction. */ unsigned int call_nop_as_suffix : 1; + /* TRUE if there are dynamic relocs against IFUNC symbols that apply + to read-only sections. */ + unsigned int readonly_dynrelocs_against_ifunc: 1; + /* The 1-byte NOP for x86 call instruction. */ char call_nop_byte; diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 2b7a09efb97..c6708caea40 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -390,6 +390,8 @@ run_dump_test "pr17935-1" run_dump_test "pr17935-2" run_dump_test "pr18801" run_dump_test "pr18815" +run_dump_test "pr19939a" +run_dump_test "pr19939b" proc undefined_weak {cflags ldflags} { set testname "Undefined weak symbol" diff --git a/ld/testsuite/ld-i386/pr19939.s b/ld/testsuite/ld-i386/pr19939.s new file mode 100644 index 00000000000..fdd1c044cb2 --- /dev/null +++ b/ld/testsuite/ld-i386/pr19939.s @@ -0,0 +1,9 @@ + .text +selector: + movl foo@GOT(%eax), %eax + mov $bar, %ebx + ret + .type selector, %gnu_indirect_function + .globl bar +bar: + jmp selector@PLT diff --git a/ld/testsuite/ld-i386/pr19939a.d b/ld/testsuite/ld-i386/pr19939a.d new file mode 100644 index 00000000000..5883caefe7f --- /dev/null +++ b/ld/testsuite/ld-i386/pr19939a.d @@ -0,0 +1,4 @@ +#source: pr19939.s +#as: --32 +#ld: -melf_i386 -shared -z defs +#error: undefined reference to `foo' diff --git a/ld/testsuite/ld-i386/pr19939b.d b/ld/testsuite/ld-i386/pr19939b.d new file mode 100644 index 00000000000..5124ae10dcb --- /dev/null +++ b/ld/testsuite/ld-i386/pr19939b.d @@ -0,0 +1,8 @@ +#source: pr19939.s +#as: --32 +#ld: -melf_i386 -shared +#readelf: -d --wide + +#... +.*\(TEXTREL\).* +#pass diff --git a/ld/testsuite/ld-x86-64/pr19939.s b/ld/testsuite/ld-x86-64/pr19939.s new file mode 100644 index 00000000000..7eadaaa18ab --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr19939.s @@ -0,0 +1,9 @@ + .text +selector: + movq foo@GOTPCREL(%rip), %rax + movabs $bar, %rbx + ret + .type selector, %gnu_indirect_function + .globl bar +bar: + jmp selector@PLT diff --git a/ld/testsuite/ld-x86-64/pr19939a.d b/ld/testsuite/ld-x86-64/pr19939a.d new file mode 100644 index 00000000000..af5b976d89c --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr19939a.d @@ -0,0 +1,4 @@ +#source: pr19939.s +#as: --64 +#ld: -melf_x86_64 -shared -z defs +#error: undefined reference to `foo' diff --git a/ld/testsuite/ld-x86-64/pr19939b.d b/ld/testsuite/ld-x86-64/pr19939b.d new file mode 100644 index 00000000000..26161515508 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr19939b.d @@ -0,0 +1,8 @@ +#source: pr19939.s +#as: --64 +#ld: -melf_x86_64 -shared +#readelf: -d --wide + +#... +.*\(TEXTREL\).* +#pass diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 603ef37b14a..8abccd4b8d6 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -438,6 +438,8 @@ run_dump_test "pr19609-7a" run_dump_test "pr19609-7b" run_dump_test "pr19609-7c" run_dump_test "pr19609-7d" +run_dump_test "pr19939a" +run_dump_test "pr19939b" proc undefined_weak {cflags ldflags} { set testname "Undefined weak symbol" |