diff options
author | Matthew Malcomson <matthew.malcomson@arm.com> | 2022-01-18 10:54:13 +0000 |
---|---|---|
committer | Matthew Malcomson <matthew.malcomson@arm.com> | 2022-01-18 10:54:13 +0000 |
commit | d6cf562af412479f6b86666450c8ef1109f4e4a0 (patch) | |
tree | 65e51dd4e8c15a8fe180220a9e30ea2c1b1bfd66 | |
parent | f3ecc5c84e9806a10435f4fc8b43b66b6e2bb877 (diff) | |
download | binutils-gdb-d6cf562af412479f6b86666450c8ef1109f4e4a0.tar.gz |
Switch __cap_dynrelocs* to __rela_dyn* symbols
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.
-rw-r--r-- | bfd/elfnn-aarch64.c | 36 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/aarch64-elf.exp | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.d | 19 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.s | 28 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.d | 25 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.s | 38 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.d | 25 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.s | 20 |
8 files changed, 175 insertions, 19 deletions
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 08d1141d4dd..9888ab5a489 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -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) diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index 893c869f1a3..426f48617e3 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -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 index 00000000000..b8474f996fe --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.d @@ -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 index 00000000000..b445fe1a2f6 --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-1.s @@ -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 index 00000000000..c2fcd5001fb --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.d @@ -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 index 00000000000..3bdee480836 --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-2.s @@ -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 index 00000000000..8ebf8420ca3 --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.d @@ -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 index 00000000000..b6cd8015432 --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-morello-reloc-markers-3.s @@ -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 |