diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 73ffdad33bc8d5bf9cf2e2d84a606e8d183695f7..5c78fb54f919ddc7877b69da21f4594ade8ee98b 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -10355,6 +10355,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 @@ -10668,25 +10685,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 228cfe224c57efc1cac6c694d304d8186e8749d6..8de7bdfc6376e3ee0b750eb6429f18d6f4a92017 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 0000000000000000000000000000000000000000..b8474f996fee97befacaf2f3366e2f1ef6a6885d --- /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 0000000000000000000000000000000000000000..b445fe1a2f6212fc838f7b7ed3b03e95b1ae6bb1 --- /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 0000000000000000000000000000000000000000..c2fcd5001fb2bc99977d7407ef9ed9165f440a44 --- /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 0000000000000000000000000000000000000000..3bdee480836df4b1bd0592edcfa92c08cda554bb --- /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 0000000000000000000000000000000000000000..8ebf8420ca354daa4166883329526ce711a3793a --- /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 0000000000000000000000000000000000000000..b6cd8015432c6b7632e3b24fb1ae6e703588287e --- /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