From c217058957a45a93481da35e1531ed120750d739 Mon Sep 17 00:00:00 2001 From: Jiong Wang Date: Tue, 23 Jun 2015 12:12:06 +0100 Subject: [PATCH] [AArch64] Generate DT_TEXTREL for relocation against read-only section 2015-06-23 Jiong Wang bfd/ * elfnn-aarch64.c (aarch64_readonly_dynrelocs): New function. (elfNN_aarch64_size_dynamic_sections): Traverse hash table to check relocations against read-only sections. ld/testsuite/ * ld-aarch64/dt_textrel.s: New testcase. * ld-aarch64/dt_textrel.d: New expectation file. * ld-aarch64/aarch64-elf.exp: Run new testcase. --- bfd/ChangeLog | 6 +++++ bfd/elfnn-aarch64.c | 30 +++++++++++++++++++++++++ ld/testsuite/ChangeLog | 6 +++++ ld/testsuite/ld-aarch64/aarch64-elf.exp | 2 ++ ld/testsuite/ld-aarch64/dt_textrel.d | 7 ++++++ ld/testsuite/ld-aarch64/dt_textrel.s | 9 ++++++++ 6 files changed, 60 insertions(+) create mode 100644 ld/testsuite/ld-aarch64/dt_textrel.d create mode 100644 ld/testsuite/ld-aarch64/dt_textrel.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 626d49af8b1..157e7f702f4 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2015-06-23 Jiong Wang + + * elfnn-aarch64.c (aarch64_readonly_dynrelocs): New function. + (elfNN_aarch64_size_dynamic_sections): Traverse hash table to check + relocations against read-only sections. + 2015-06-18 Nick Clifton PR 18481 diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 1c550582405..b13f5db610e 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -7545,6 +7545,32 @@ elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf) return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf); } +/* Find any dynamic relocs that apply to read-only sections. */ + +static bfd_boolean +aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf) +{ + struct elf_aarch64_link_hash_entry * eh; + struct elf_dyn_relocs * p; + + eh = (struct elf_aarch64_link_hash_entry *) h; + for (p = eh->dyn_relocs; p != NULL; p = p->next) + { + asection *s = p->sec; + + if (s != NULL && (s->flags & SEC_READONLY) != 0) + { + struct bfd_link_info *info = (struct bfd_link_info *) inf; + + info->flags |= DF_TEXTREL; + + /* Not an error, just cut short the traversal. */ + return FALSE; + } + } + return TRUE; +} + /* This is the most important function of all . Innocuosly named though ! */ static bfd_boolean @@ -7832,6 +7858,10 @@ elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, /* If any dynamic relocs apply to a read-only section, then we need a DT_TEXTREL entry. */ + if ((info->flags & DF_TEXTREL) == 0) + elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs, + info); + if ((info->flags & DF_TEXTREL) != 0) { if (!add_dynamic_entry (DT_TEXTREL, 0)) diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index e81e616aec6..812549c7e97 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-06-23 Jiong Wang + + * ld-aarch64/dt_textrel.s: New testcase. + * ld-aarch64/dt_textrel.d: New expectation file. + * ld-aarch64/aarch64-elf.exp: Run new testcase. + 2015-06-17 Jiong Wang * ld-aarch64/aarch64-elf.exp (aarch64_choose_ilp32_emul): New function. diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index 531ec0eab47..ac21d14956c 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -203,6 +203,8 @@ run_dump_test "ifunc-22" run_dump_test "relasz" run_dump_test "relocs-257-symbolic-func" +run_dump_test "dt_textrel" + set aarch64elflinktests { {"ld-aarch64/so with global symbol" "-shared" "" "" {copy-reloc-so.s} {} "copy-reloc-so.so"} diff --git a/ld/testsuite/ld-aarch64/dt_textrel.d b/ld/testsuite/ld-aarch64/dt_textrel.d new file mode 100644 index 00000000000..2dbbd2fdb68 --- /dev/null +++ b/ld/testsuite/ld-aarch64/dt_textrel.d @@ -0,0 +1,7 @@ +#source: dt_textrel.s +#ld: -shared +#readelf: -d +#... +.*TEXTREL.* +.* + diff --git a/ld/testsuite/ld-aarch64/dt_textrel.s b/ld/testsuite/ld-aarch64/dt_textrel.s new file mode 100644 index 00000000000..f37f45672ea --- /dev/null +++ b/ld/testsuite/ld-aarch64/dt_textrel.s @@ -0,0 +1,9 @@ + .cpu generic+fp+simd + .global p + .comm x,4,4 + .section .rodata + .align 3 + .type p, %object + .size p, 8 +p: + .xword x -- 2.30.2