]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Switch __cap_dynrelocs* to __rela_dyn* symbols
authorMatthew Malcomson <matthew.malcomson@arm.com>
Tue, 18 Jan 2022 10:54:13 +0000 (10:54 +0000)
committerMatthew Malcomson <matthew.malcomson@arm.com>
Tue, 18 Jan 2022 10:54:13 +0000 (10:54 +0000)
The name has been changed in LLVM, so we adjust it in binutils to match.

We also move where these symbols are created.  Previously they were
created in elfNN_aarch64_always_size_sections, but we move this to
elfNN_aarch64_size_dynamic_sections.

We do the moving since these symbols are supposed to span all dynamic
capability relocations stored in the .rela.dyn section for static
executables.  In the case of a static binary we place relocations for
the GOT into this section as well as internal relocations.

These relocations for the GOT are handled in
elfNN_aarch64_size_dynamic_sections, which is called *after*
elfNN_aarch64_always_size_sections.  The size of this section is only
fully known after those GOT relocations are managed, so the position
these symbols should be placed in is only known at that point.  Hence we
only initialise the __rela_dyn* symbols at that point.

2021-10-06  Matthew Malcomson  <matthew.malcomson@arm.com>
ChangeLog:

* bfd/elfnn-aarch64.c (elfNN_aarch64_always_size_sections): Move
initialisation of __rela_dyn* symbols ...
(elfNN_aarch64_size_dynamic_sections): ... to here.
* ld/testsuite/ld-aarch64/aarch64-elf.exp: Run new tests.
* ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.d: New test.
* ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.s: New test.
* ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.d: New test.
* ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.s: New test.
* ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.d: New test.
* ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.s: New test.

bfd/elfnn-aarch64.c
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.s [new file with mode: 0644]

index 08d1141d4ddd986bff194a2dbc03c585dc282f8f..9888ab5a489be0fc79315d2ad7c07ec2acf465b2 100644 (file)
@@ -10370,6 +10370,23 @@ elfNN_aarch64_size_dynamic_sections (bfd *output_bfd,
                 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
                 info);
 
+  if (bfd_link_executable (info)
+      && !bfd_link_pic (info)
+      && htab->srelcaps
+      && htab->srelcaps->size > 0)
+    {
+      struct elf_link_hash_entry *h;
+
+      h = _bfd_elf_define_linkage_sym (output_bfd, info,
+                                      htab->srelcaps,
+                                      "__rela_dyn_start");
+      h = _bfd_elf_define_linkage_sym (output_bfd, info,
+                                      htab->srelcaps,
+                                      "__rela_dyn_end");
+
+      h->root.u.def.value = htab->srelcaps->vma + htab->srelcaps->size;
+    }
+
   /* For every jump slot reserved in the sgotplt, reloc_count is
      incremented.  However, when we reserve space for TLS descriptors,
      it's not incremented, so in order to compute the space reserved
@@ -10683,25 +10700,6 @@ elfNN_aarch64_always_size_sections (bfd *output_bfd,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
-
-  if (bfd_link_executable (info)
-      && !bfd_link_pic (info)
-      && htab->srelcaps
-      && htab->srelcaps->size > 0)
-    {
-      struct elf_link_hash_entry *h;
-
-      h = _bfd_elf_define_linkage_sym (output_bfd, info,
-                                      htab->srelcaps,
-                                      "__cap_dynrelocs_start");
-      h = _bfd_elf_define_linkage_sym (output_bfd, info,
-                                      htab->srelcaps,
-                                      "__cap_dynrelocs_end");
-
-      h->root.u.def.value = htab->srelcaps->vma + htab->srelcaps->size;
-    }
-
   tls_sec = elf_hash_table (info)->tls_sec;
 
   if (tls_sec)
index 893c869f1a313e6192d4585e46fc9c8b93d13b88..426f48617e36be957d6cd80274020bbcb169d85a 100644 (file)
@@ -246,6 +246,9 @@ run_dump_test_lp64 "emit-relocs-morello-3"
 run_dump_test_lp64 "emit-relocs-morello-3-a64c"
 run_dump_test_lp64 "emit-relocs-morello-4"
 run_dump_test_lp64 "emit-relocs-morello-5"
+run_dump_test_lp64 "emit-morello-reloc-markers-1"
+run_dump_test_lp64 "emit-morello-reloc-markers-2"
+run_dump_test_lp64 "emit-morello-reloc-markers-3"
 
 run_dump_test_lp64 "morello-capinit"
 run_dump_test_lp64 "morello-stubs"
diff --git a/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.d b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.d
new file mode 100644 (file)
index 0000000..b8474f9
--- /dev/null
@@ -0,0 +1,19 @@
+# The aim here is to test that
+#   a) We generate the __rela_dyn_{start,end} symbols.
+#   b) They span the entire .rela.dyn section.
+# This particular case (the -1 file) is in case of there being no .got symbols.
+#source: emit-morello-reloc-markers-1.s
+#as: -march=morello+c64
+#ld: -Ttext-segment 0x0 -static
+#objdump: --syms --section-headers --section=.rela.dyn --section=.got
+
+.*:     file format .*
+
+Sections:
+Idx Name          Size      VMA               LMA               File off  Algn
+  0 \.rela\.dyn     00000018  0000000000000000  0000000000000000  00010000  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+SYMBOL TABLE:
+0000000000000000 l    d  \.rela\.dyn   0000000000000000 \.rela\.dyn
+0000000000000018 l     O \.rela\.dyn   0000000000000000 __rela_dyn_end
+0000000000000000 l     O \.rela\.dyn   0000000000000000 __rela_dyn_start
diff --git a/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.s b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.s
new file mode 100644 (file)
index 0000000..b445fe1
--- /dev/null
@@ -0,0 +1,28 @@
+       .arch morello+crc+c64
+       .file   "very-basic-test.c"
+       .text
+       .data
+       .align  2
+       .type   retval, %object
+       .size   retval, 4
+retval:
+       .word   1
+       .text
+       .align  2
+       .global _start
+       .type   _start, %function
+_start:
+       adrp    c0, .LC0
+       add     c0, c0, :lo12:.LC0
+       ldr     c0, [c0]
+       ldr     w0, [c0]
+       ret
+       .size   _start, .-_start
+       .section        .data.rel.ro.local,"aw"
+       .align  4
+       .type   .LC0, %object
+       .size   .LC0, 16
+.LC0:
+       .capinit        retval
+       .xword  0
+       .xword  0
diff --git a/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.d b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.d
new file mode 100644 (file)
index 0000000..c2fcd50
--- /dev/null
@@ -0,0 +1,25 @@
+# The aim here is to test that
+#   a) We generate the __rela_dyn_{start,end} symbols.
+#   b) They span the entire .rela.dyn section.
+# This particular case (the -2 file) is in case of there both .got symbols and
+# local symbols that require relocations.
+#source: emit-morello-reloc-markers-2.s
+#as: -march=morello+c64
+#ld: -Ttext-segment 0x0 -static
+#objdump: --syms --section-headers --section=.rela.dyn --section=.got
+
+.*:     file format .*
+
+Sections:
+Idx Name          Size      VMA               LMA               File off  Algn
+  0 \.rela\.dyn     00000030  0000000000000000  0000000000000000  00010000  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  .* \.got .*
+.*
+
+SYMBOL TABLE:
+0000000000000000 l    d  \.rela\.dyn   0000000000000000 \.rela\.dyn
+.*
+0000000000000030 l     O \.rela\.dyn   0000000000000000 __rela_dyn_end
+0000000000000000 l     O \.rela\.dyn   0000000000000000 __rela_dyn_start
+#pass
diff --git a/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.s b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.s
new file mode 100644 (file)
index 0000000..3bdee48
--- /dev/null
@@ -0,0 +1,38 @@
+       .arch morello+crc+c64
+       .file   "very-basic-test.c"
+       .text
+       .data
+       .align  2
+       .type   retval, %object
+       .size   retval, 4
+retval:
+       .word   1
+       .global other
+       .align  2
+       .type   other, %object
+       .size   other, 4
+other:
+       .word   1
+       .text
+       .align  2
+       .global _start
+       .type   _start, %function
+_start:
+       adrp    c0, .LC0
+       add     c0, c0, :lo12:.LC0
+       ldr     c0, [c0]
+       ldr     w1, [c0]
+       adrp    c0, :got:other
+       ldr     c0, [c0, #:got_lo12:other]
+       ldr     w0, [c0]
+       add     w0, w1, w0
+       ret
+       .size   _start, .-_start
+       .section        .data.rel.ro.local,"aw"
+       .align  4
+       .type   .LC0, %object
+       .size   .LC0, 16
+.LC0:
+       .capinit        retval
+       .xword  0
+       .xword  0
diff --git a/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.d b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.d
new file mode 100644 (file)
index 0000000..8ebf842
--- /dev/null
@@ -0,0 +1,25 @@
+# The aim here is to test that
+#   a) We generate the __rela_dyn_{start,end} symbols.
+#   b) They span the entire .rela.dyn section.
+# This particular case (the -3 file) is in case of there being only .got
+# symbols that need dynamic relocations.
+#source: emit-morello-reloc-markers-3.s
+#as: -march=morello+c64
+#ld: -Ttext-segment 0x0 -static
+#objdump: --syms --section-headers --section=.rela.dyn --section=.got
+
+.*:     file format .*
+
+Sections:
+Idx Name          Size      VMA               LMA               File off  Algn
+  0 \.rela\.dyn     00000018  0000000000000000  0000000000000000  00010000  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  .* \.got .*
+.*
+
+SYMBOL TABLE:
+0000000000000000 l    d  \.rela\.dyn   0000000000000000 \.rela\.dyn
+.*
+0000000000000018 l     O \.rela\.dyn   0000000000000000 __rela_dyn_end
+0000000000000000 l     O \.rela\.dyn   0000000000000000 __rela_dyn_start
+#pass
diff --git a/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.s b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.s
new file mode 100644 (file)
index 0000000..b6cd801
--- /dev/null
@@ -0,0 +1,20 @@
+       .arch morello+crc+c64
+       .file   "very-basic-test.c"
+       .text
+       .global retval
+       .data
+       .align  2
+       .type   retval, %object
+       .size   retval, 4
+retval:
+       .word   1
+       .text
+       .align  2
+       .global _start
+       .type   _start, %function
+_start:
+       adrp    c0, :got:retval
+       ldr     c0, [c0, #:got_lo12:retval]
+       ldr     w0, [c0]
+       ret
+       .size   _start, .-_start