From 1952c5cd7d3d24b9647b396731bc4808a2d63d9c Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 7 Feb 2015 05:28:06 -0800 Subject: [PATCH] Issue relocation in RO section warning for -z text This patch changes linker to issue a warning for relocation in readonly section for -z text. bfd/ PR ld/17935 * elf32-i386.c (elf_i386_readonly_dynrelocs): Also issue a warning for relocation in readonly section for -z text. (elf_i386_size_dynamic_sections): Likewise. * elf64-x86-64.c (elf_x86_64_readonly_dynrelocs): Likewise. (elf_x86_64_size_dynamic_sections): Likewise. ld/testsuite/ PR ld/17935 * ld-i386/i386.exp: Run pr17935-1 and pr17935-2. * ld-x86-64/x86-64.exp: Likewise. * ld-i386/pr17935-1.d: New file. * ld-i386/pr17935-1.s: Likewise. * ld-i386/pr17935-2.d: Likewise. * ld-i386/pr17935-2.s: Likewise. * ld-x86-64/pr17935-1.d: Likewise. * ld-x86-64/pr17935-1.s: Likewise. * ld-x86-64/pr17935-2.d: Likewise. * ld-x86-64/pr17935-2.s: Likewise. --- bfd/ChangeLog | 9 +++++++++ bfd/elf32-i386.c | 10 ++++++---- bfd/elf64-x86-64.c | 10 ++++++---- ld/testsuite/ChangeLog | 15 +++++++++++++++ ld/testsuite/ld-i386/i386.exp | 2 ++ ld/testsuite/ld-i386/pr17935-1.d | 3 +++ ld/testsuite/ld-i386/pr17935-1.s | 7 +++++++ ld/testsuite/ld-i386/pr17935-2.d | 3 +++ ld/testsuite/ld-i386/pr17935-2.s | 6 ++++++ ld/testsuite/ld-x86-64/pr17935-1.d | 3 +++ ld/testsuite/ld-x86-64/pr17935-1.s | 7 +++++++ ld/testsuite/ld-x86-64/pr17935-2.d | 3 +++ ld/testsuite/ld-x86-64/pr17935-2.s | 6 ++++++ ld/testsuite/ld-x86-64/x86-64.exp | 2 ++ 14 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 ld/testsuite/ld-i386/pr17935-1.d create mode 100644 ld/testsuite/ld-i386/pr17935-1.s create mode 100644 ld/testsuite/ld-i386/pr17935-2.d create mode 100644 ld/testsuite/ld-i386/pr17935-2.s create mode 100644 ld/testsuite/ld-x86-64/pr17935-1.d create mode 100644 ld/testsuite/ld-x86-64/pr17935-1.s create mode 100644 ld/testsuite/ld-x86-64/pr17935-2.d create mode 100644 ld/testsuite/ld-x86-64/pr17935-2.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 1220455..9732bea 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2015-02-07 H.J. Lu + + PR ld/17935 + * elf32-i386.c (elf_i386_readonly_dynrelocs): Also issue a + warning for relocation in readonly section for -z text. + (elf_i386_size_dynamic_sections): Likewise. + * elf64-x86-64.c (elf_x86_64_readonly_dynrelocs): Likewise. + (elf_x86_64_size_dynamic_sections): Likewise. + 2015-02-06 H.J. Lu PR ld/12365 diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 439538e..dd4dbdc 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -2600,8 +2600,9 @@ elf_i386_readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) info->flags |= DF_TEXTREL; - if (info->warn_shared_textrel && info->shared) - info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"), + if ((info->warn_shared_textrel && info->shared) + || info->error_textrel) + info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"), p->sec->owner, h->root.root.string, p->sec); @@ -2842,8 +2843,9 @@ elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) && (info->flags & DF_TEXTREL) == 0) { info->flags |= DF_TEXTREL; - if (info->warn_shared_textrel && info->shared) - info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"), + if ((info->warn_shared_textrel && info->shared) + || info->error_textrel) + info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"), p->sec->owner, p->sec); } } diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 80136bf..5fd727b 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -2850,8 +2850,9 @@ elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h, info->flags |= DF_TEXTREL; - if (info->warn_shared_textrel && info->shared) - info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"), + if ((info->warn_shared_textrel && info->shared) + || info->error_textrel) + info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"), p->sec->owner, h->root.root.string, p->sec); @@ -3090,8 +3091,9 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd, && (info->flags & DF_TEXTREL) == 0) { info->flags |= DF_TEXTREL; - if (info->warn_shared_textrel && info->shared) - info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"), + if ((info->warn_shared_textrel && info->shared) + || info->error_textrel) + info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"), p->sec->owner, p->sec); } } diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 075016b..3f085c2 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,18 @@ +2015-02-07 H.J. Lu + + PR ld/17935 + * ld-i386/i386.exp: Run pr17935-1 and pr17935-2. + * ld-x86-64/x86-64.exp: Likewise. + + * ld-i386/pr17935-1.d: New file. + * ld-i386/pr17935-1.s: Likewise. + * ld-i386/pr17935-2.d: Likewise. + * ld-i386/pr17935-2.s: Likewise. + * ld-x86-64/pr17935-1.d: Likewise. + * ld-x86-64/pr17935-1.s: Likewise. + * ld-x86-64/pr17935-2.d: Likewise. + * ld-x86-64/pr17935-2.s: Likewise. + 2015-02-06 H.J. Lu PR ld/12365 diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 6f98b4f..f5922b4 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -263,6 +263,8 @@ run_dump_test "pr12627" run_dump_test "pr13302" run_dump_test "pr14215" run_dump_test "pr17057" +run_dump_test "pr17935-1" +run_dump_test "pr17935-2" # Must be Linux native with the C compiler if { [isnative] diff --git a/ld/testsuite/ld-i386/pr17935-1.d b/ld/testsuite/ld-i386/pr17935-1.d new file mode 100644 index 0000000..5303ea2 --- /dev/null +++ b/ld/testsuite/ld-i386/pr17935-1.d @@ -0,0 +1,3 @@ +# as: --32 +# ld: -m elf_i386 -shared -z text +# error: warning: relocation against `foo' in readonly section `.text' diff --git a/ld/testsuite/ld-i386/pr17935-1.s b/ld/testsuite/ld-i386/pr17935-1.s new file mode 100644 index 0000000..38eef2e --- /dev/null +++ b/ld/testsuite/ld-i386/pr17935-1.s @@ -0,0 +1,7 @@ + .text + .globl foo +foo: + .byte 0 + .globl bar +bar: + .dc.a foo diff --git a/ld/testsuite/ld-i386/pr17935-2.d b/ld/testsuite/ld-i386/pr17935-2.d new file mode 100644 index 0000000..c1080f4 --- /dev/null +++ b/ld/testsuite/ld-i386/pr17935-2.d @@ -0,0 +1,3 @@ +# as: --32 +# ld: -m elf_i386 -shared -z text +# error: warning: relocation in readonly section `.text' diff --git a/ld/testsuite/ld-i386/pr17935-2.s b/ld/testsuite/ld-i386/pr17935-2.s new file mode 100644 index 0000000..3ae5369 --- /dev/null +++ b/ld/testsuite/ld-i386/pr17935-2.s @@ -0,0 +1,6 @@ + .text +foo: + .byte 0 + .globl bar +bar: + .dc.a foo diff --git a/ld/testsuite/ld-x86-64/pr17935-1.d b/ld/testsuite/ld-x86-64/pr17935-1.d new file mode 100644 index 0000000..5734eab --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr17935-1.d @@ -0,0 +1,3 @@ +# as: --64 +# ld: -m elf_x86_64 -shared -z text +# error: warning: relocation against `foo' in readonly section `.text' diff --git a/ld/testsuite/ld-x86-64/pr17935-1.s b/ld/testsuite/ld-x86-64/pr17935-1.s new file mode 100644 index 0000000..38eef2e --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr17935-1.s @@ -0,0 +1,7 @@ + .text + .globl foo +foo: + .byte 0 + .globl bar +bar: + .dc.a foo diff --git a/ld/testsuite/ld-x86-64/pr17935-2.d b/ld/testsuite/ld-x86-64/pr17935-2.d new file mode 100644 index 0000000..81df652 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr17935-2.d @@ -0,0 +1,3 @@ +# as: --64 +# ld: -m elf_x86_64 -shared -z text +# error: warning: relocation in readonly section `.text' diff --git a/ld/testsuite/ld-x86-64/pr17935-2.s b/ld/testsuite/ld-x86-64/pr17935-2.s new file mode 100644 index 0000000..3ae5369 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr17935-2.s @@ -0,0 +1,6 @@ + .text +foo: + .byte 0 + .globl bar +bar: + .dc.a foo diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index bfa89c3..9bb08bd 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -311,6 +311,8 @@ run_dump_test "mov1a" run_dump_test "mov1b" run_dump_test "mov1c" run_dump_test "mov1d" +run_dump_test "pr17935-1" +run_dump_test "pr17935-2" # Must be native with the C compiler if { [isnative] && [which $CC] != 0 } { -- 2.7.4