]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[AArch64][Backport] Generate DT_TEXTREL for relocation against RO section
authorJiong Wang <jiong.wang@arm.com>
Tue, 23 Jun 2015 11:19:24 +0000 (12:19 +0100)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 24 Aug 2017 12:47:09 +0000 (09:47 -0300)
2015-06-23  Jiong Wang  <jiong.wang@arm.com>

  Apply from master:
  2015-06-23  Jiong. Wang  <jiong.wang@arm.com>

  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
bfd/elfnn-aarch64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/dt_textrel.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/dt_textrel.s [new file with mode: 0644]

index d39fdddd477f4b04ce692e1b9029652084d4ded0..d994eac448897ac88ccbd9d210b64001ef1b15f3 100644 (file)
@@ -1,3 +1,12 @@
+2015-06-23  Jiong Wang  <jiong.wang@arm.com>
+
+       Apply from master:
+       2015-06-23  Jiong. Wang  <jiong.wang@arm.com>
+
+       * 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-19  Nick Clifton  <nickc@redhat.com>
 
        PR 18481
index 1df9b4ca23d3eb45298821cc607ddc165fa71e4b..8a66279709e35ed04953a41079cf0d4d53616d46 100644 (file)
@@ -7328,6 +7328,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
@@ -7615,6 +7641,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))
index 7291a52128dc86154b8fa43474d2d1783b6539a8..8be561441a7683f4ae4740d72c93d58a0fd5471d 100644 (file)
@@ -1,3 +1,12 @@
+2015-06-23  Jiong Wang  <jiong.wang@arm.com>
+
+       Apply from master:
+       2015-06-23  Jiong. Wang  <jiong.wang@arm.com>
+
+       * 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  Renlin Li  <renlin.li@arm.com>
 
        Applied from master.
index 08788c1887cfb8c1d9530be4efededcb75e9ca42..e110c85ad2ea4eb4b18a6f4c400d6948e6da2c77 100644 (file)
@@ -182,6 +182,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 (file)
index 0000000..2dbbd2f
--- /dev/null
@@ -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 (file)
index 0000000..f37f456
--- /dev/null
@@ -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