diff options
author | Sudakshina Das <sudi.das@arm.com> | 2019-03-13 10:54:30 +0000 |
---|---|---|
committer | Sudakshina Das <sudi.das@arm.com> | 2019-03-13 11:47:07 +0000 |
commit | 37c18eedffe3926a330149ca93e7407917e2be38 (patch) | |
tree | bc49f9058988c84c84029fe8b302e102fa4387c6 /ld/testsuite/ld-aarch64 | |
parent | cd702818c6cf25277253b3b5c23f17d2cf7a94df (diff) | |
download | gdb-37c18eedffe3926a330149ca93e7407917e2be38.zip gdb-37c18eedffe3926a330149ca93e7407917e2be38.tar.gz gdb-37c18eedffe3926a330149ca93e7407917e2be38.tar.bz2 |
[BFD, LD, AArch64, 2/3] Add --force-bti to enable BTI and to select BTI enabled PLTs
This is part of the patch series to add support for BTI and
PAC in AArch64 linker.
1) This patch adds a new ld command line option: --force-bti.
In the presence of this option, the linker enables BTI with the
GNU_PROPERTY_AARCH64_FEATURE_1_BTI feature. This gives out warning
in case of missing gnu notes for BTI in inputs.
2) It also defines a new set of BTI enabled PLTs. These are used either
when all the inputs are marked with GNU_PROPERTY_AARCH64_FEATURE_1_BTI
or when the new --force-bti option is used. This required adding new
fields in elf_aarch64_link_hash_table so that we could make the PLT
related information more generic.
3) It also defines a dynamic tag DT_AARCH64_BTI_PLT. The linker uses
this whenever it picks BTI enabled PLTs.
All these are made according to the new AArch64 ELF ABI
https://developer.arm.com/docs/ihi0056/latest/elf-for-the-arm-64-bit-architecture-aarch64-abi-2018q4
*** bfd/ChangeLog ***
2019-03-13 Sudakshina Das <sudi.das@arm.com>
Szabolcs Nagy <szabolcs.nagy@arm.com>
* bfd-in.h (aarch64_plt_type, aarch64_enable_bti_type): New.
(aarch64_bti_pac_info): New.
(bfd_elf64_aarch64_set_options): Add aarch64_bti_pac_info argument.
(bfd_elf32_aarch64_set_options): Likewise.
* bfd-in2.h: Regenerate
* elfnn-aarch64.c (PLT_BTI_ENTRY_SIZE): New.
(PLT_BTI_SMALL_ENTRY_SIZE, PLT_BTI_TLSDESC_ENTRY_SIZE): New.
(elfNN_aarch64_small_plt0_bti_entry): New.
(elfNN_aarch64_small_plt_bti_entry): New.
(elfNN_aarch64_tlsdesc_small_plt_bti_entry): New.
(elf_aarch64_obj_tdata): Add no_bti_warn and plt_type fields.
(elf_aarch64_link_hash_table): Add plt0_entry, plt_entry and
tlsdesc_plt_entry_size fields.
(elfNN_aarch64_link_hash_table_create): Initialise the new fields.
(setup_plt_values): New helper function.
(bfd_elfNN_aarch64_set_options): Use new bp_info to set plt sizes and
bti enable type.
(elfNN_aarch64_allocate_dynrelocs): Use new size members instead of
fixed macros.
(elfNN_aarch64_size_dynamic_sections): Likewise and add checks.
(elfNN_aarch64_create_small_pltn_entry): Use new generic pointers
to plt stubs instead of fixed ones and update filling them according
to the need for bti.
(elfNN_aarch64_init_small_plt0_entry): Likewise.
(elfNN_aarch64_finish_dynamic_sections): Likewise.
(get_plt_type, elfNN_aarch64_get_synthetic_symtab): New.
(elfNN_aarch64_plt_sym_val): Update size accordingly.
(elfNN_aarch64_link_setup_gnu_properties): Set up plts if BTI GNU NOTE
is set.
(bfd_elfNN_get_synthetic_symtab): Define.
(elfNN_aarch64_merge_gnu_properties): Give out warning with --force-bti
and mising BTI NOTE SECTION.
*** binutils/ChangeLog ***
2019-03-13 Sudakshina Das <sudi.das@arm.com>
Szabolcs Nagy <szabolcs.nagy@arm.com>
* readelf.c (get_aarch64_dynamic_type): New.
(get_dynamic_type): Use above for EM_AARCH64.
(dynamic_section_aarch64_val): New.
(process_dynamic_section): Use above for EM_AARCH64.
*** include/ChangeLog ***
2019-03-13 Sudakshina Das <sudi.das@arm.com>
Szabolcs Nagy <szabolcs.nagy@arm.com>
* elf/aarch64.h (DT_AARCH64_BTI_PLT): New.
*** ld/ChangeLog ***
2019-03-13 Sudakshina Das <sudi.das@arm.com>
Szabolcs Nagy <szabolcs.nagy@arm.com>
* NEWS: Document --force-bti.
* emultempl/aarch64elf.em (plt_type, bti_type, OPTION_FORCE_BTI): New.
(PARSE_AND_LIST_SHORTOPTS, PARSE_AND_LIST_OPTIONS): Add force-bti.
(PARSE_AND_LIST_ARGS_CASES): Handle OPTION_FORCE_BTI.
* testsuite/ld-aarch64/aarch64-elf.exp: Add all the tests below.
* testsuite/ld-aarch64/bti-plt-1.d: New test.
* testsuite/ld-aarch64/bti-plt-1.s: New test.
* testsuite/ld-aarch64/bti-plt-2.s: New test.
* testsuite/ld-aarch64/bti-plt-2.d: New test.
* testsuite/ld-aarch64/bti-plt-3.d: New test.
* testsuite/ld-aarch64/bti-plt-4.d: New test.
* testsuite/ld-aarch64/bti-plt-5.d: New test.
* testsuite/ld-aarch64/bti-plt-6.d: New test.
* testsuite/ld-aarch64/bti-plt-7.d: New test.
* testsuite/ld-aarch64/bti-plt-so.s: New test.
* testsuite/ld-aarch64/bti-plt.ld: New test.
Diffstat (limited to 'ld/testsuite/ld-aarch64')
-rw-r--r-- | ld/testsuite/ld-aarch64/aarch64-elf.exp | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-1.d | 32 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-1.s | 21 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-2.d | 11 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-2.s | 21 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-3.d | 34 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-4.d | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-5.d | 28 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-6.d | 15 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-7.d | 15 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt-so.s | 41 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/bti-plt.ld | 14 |
12 files changed, 252 insertions, 0 deletions
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index c6fefbb..906534b 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -374,6 +374,8 @@ run_dump_test_lp64 "pie-bind-locally" run_dump_test "property-bti-pac1" run_dump_test "property-bti-pac2" run_dump_test "property-bti-pac3" +run_dump_test "bti-plt-1" +run_dump_test "bti-plt-2" set aarch64elflinktests { {"ld-aarch64/so with global symbol" "-shared" "" "" {copy-reloc-so.s} @@ -389,6 +391,14 @@ set aarch64elflinktests { {"ld-aarch64/func sym hash opt for exe" "-e0 --hash-style=gnu tmpdir/func-in-so.so" "" "" {func-sym-hash-opt.s} {{readelf --dyn-sym func-sym-hash-opt.d}} "hash-opt"} + {"Build bti-plt-so for PLT tests" "-shared" "" "" {bti-plt-so.s} + {} "libbti-plt-so.so"} } run_ld_link_tests $aarch64elflinktests + +run_dump_test "bti-plt-3" +run_dump_test "bti-plt-4" +run_dump_test "bti-plt-5" +run_dump_test "bti-plt-6" +run_dump_test "bti-plt-7" diff --git a/ld/testsuite/ld-aarch64/bti-plt-1.d b/ld/testsuite/ld-aarch64/bti-plt-1.d new file mode 100644 index 0000000..b7b58a8 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-1.d @@ -0,0 +1,32 @@ +#name: Check --force-bti emits BTI PLT (shared) +#source: bti-plt-1.s +#as: -mabi=lp64 +#ld: -shared --force-bti -T bti-plt.ld +#objdump: -dr -j .plt + +[^:]*: *file format elf64-.*aarch64 + +Disassembly of section \.plt: + +[0-9]+ <.*>: +.*: d503245f bti c +.*: a9bf7bf0 stp x16, x30, \[sp, #-16\]! +.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_> +.*: f9400e11 ldr x17, \[x16, #24\] +.*: 91006210 add x16, x16, #0x18 +.*: d61f0220 br x17 +.*: d503201f nop +.*: d503201f nop +.*: d503201f nop + +[0-9]+ <.*>: +.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_> +.*: f9401211 ldr x17, \[x16, #32\] +.*: 91008210 add x16, x16, #0x20 +.*: d61f0220 br x17 + +[0-9]+ <.*>: +.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_> +.*: f9401611 ldr x17, \[x16, #40\] +.*: 9100a210 add x16, x16, #0x28 +.*: d61f0220 br x17 diff --git a/ld/testsuite/ld-aarch64/bti-plt-1.s b/ld/testsuite/ld-aarch64/bti-plt-1.s new file mode 100644 index 0000000..78e1aaa --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-1.s @@ -0,0 +1,21 @@ + .text + .globl _start + .type _start,@function +_start: + bl foo + bl bar + .section ".note.gnu.property", "a" + .p2align 3 + .long 1f - 0f /* name length */ + .long 5f - 2f /* data length */ + .long 5 /* note type */ +0: .asciz "GNU" /* vendor name */ +1: + .p2align 3 +2: .long 0xc0000000 /* pr_type. */ + .long 4f - 3f /* pr_datasz. */ +3: + .long 0x1 /* BTI. */ +4: + .p2align 3 +5: diff --git a/ld/testsuite/ld-aarch64/bti-plt-2.d b/ld/testsuite/ld-aarch64/bti-plt-2.d new file mode 100644 index 0000000..c26e47a --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-2.d @@ -0,0 +1,11 @@ +#name: Check --force-bti emits BTI feature (shared) +#source: bti-plt-1.s +#source: bti-plt-2.s +#as: -mabi=lp64 +#ld: -shared --force-bti -T bti-plt.ld +#readelf: -n + +Displaying notes found in: .note.gnu.property + Owner Data size Description + GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 + Properties: AArch64 feature: BTI diff --git a/ld/testsuite/ld-aarch64/bti-plt-2.s b/ld/testsuite/ld-aarch64/bti-plt-2.s new file mode 100644 index 0000000..fff945c --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-2.s @@ -0,0 +1,21 @@ + .text + .globl _start + .type _start,@function +func2: + bl foo2 + bl bar2 + .section ".note.gnu.property", "a" + .p2align 3 + .long 1f - 0f /* name length */ + .long 5f - 2f /* data length */ + .long 5 /* note type */ +0: .asciz "GNU" /* vendor name */ +1: + .p2align 3 +2: .long 0xc0000000 /* pr_type. */ + .long 4f - 3f /* pr_datasz. */ +3: + .long 0x1 /* BTI. */ +4: + .p2align 3 +5: diff --git a/ld/testsuite/ld-aarch64/bti-plt-3.d b/ld/testsuite/ld-aarch64/bti-plt-3.d new file mode 100644 index 0000000..0d4c467 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-3.d @@ -0,0 +1,34 @@ +#name: Check --force-bti emits BTI PLT (exec) +#source: bti-plt-1.s +#as: -mabi=lp64 +#ld: --force-bti -e _start -T bti-plt.ld -L./tmpdir -lbti-plt-so +#objdump: -dr -j .plt + +[^:]*: *file format elf64-.*aarch64 + +Disassembly of section \.plt: + +[0-9]+ <.*>: +.*: d503245f bti c +.*: a9bf7bf0 stp x16, x30, \[sp, #-16\]! +.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_> +.*: f9400e11 ldr x17, \[x16, #24\] +.*: 91006210 add x16, x16, #0x18 +.*: d61f0220 br x17 +.*: d503201f nop +.*: d503201f nop +.*: d503201f nop + +[0-9]+ <.*>: +.*: d503245f bti c +.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_> +.*: f9401211 ldr x17, \[x16, #32\] +.*: 91008210 add x16, x16, #0x20 +.*: d61f0220 br x17 + +[0-9]+ <.*>: +.*: d503245f bti c +.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_> +.*: f9401611 ldr x17, \[x16, #40\] +.*: 9100a210 add x16, x16, #0x28 +.*: d61f0220 br x17 diff --git a/ld/testsuite/ld-aarch64/bti-plt-4.d b/ld/testsuite/ld-aarch64/bti-plt-4.d new file mode 100644 index 0000000..90aeed2 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-4.d @@ -0,0 +1,10 @@ +#name: Check --force-bti emits BTI feature (exec) +#source: bti-plt-1.s +#as: -mabi=lp64 +#ld: --force-bti -e _start -T bti-plt.ld -L./tmpdir -lbti-plt-so +#readelf: -n + +Displaying notes found in: .note.gnu.property + Owner Data size Description + GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 + Properties: AArch64 feature: BTI diff --git a/ld/testsuite/ld-aarch64/bti-plt-5.d b/ld/testsuite/ld-aarch64/bti-plt-5.d new file mode 100644 index 0000000..01231b6 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-5.d @@ -0,0 +1,28 @@ +#name: BTI PLT with only GNU PROP +#source: property-bti-pac1.s +#as: -mabi=lp64 -defsym __property_bti__=1 +#ld: -e _start -L./tmpdir -lbti-plt-so +#objdump: -dr -j .plt +#target: *linux* + +[^:]*: *file format elf64-.*aarch64 + +Disassembly of section \.plt: + +[0-9a-f]+ <.*>: +.*: d503245f bti c +.*: a9bf7bf0 stp x16, x30, \[sp, #-16\]! +.*: 90000090 adrp x16, 410000 <_start\+0xfd28> +.*: f9421611 ldr x17, \[x16, #1064\] +.*: 9110a210 add x16, x16, #0x428 +.*: d61f0220 br x17 +.*: d503201f nop +.*: d503201f nop +.*: d503201f nop + +[0-9a-f]+ <.*>: +.*: d503245f bti c +.*: 90000090 adrp x16, 410000 <_start\+0xfd28> +.*: f9421a11 ldr x17, \[x16, #1072\] +.*: 9110c210 add x16, x16, #0x430 +.*: d61f0220 br x17 diff --git a/ld/testsuite/ld-aarch64/bti-plt-6.d b/ld/testsuite/ld-aarch64/bti-plt-6.d new file mode 100644 index 0000000..c7d5169 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-6.d @@ -0,0 +1,15 @@ +#name: Warn with one missing GNU NOTE BTI input +#source: property-bti-pac1.s +#source: property-bti-pac2.s +#as: -mabi=lp64 -defsym __property_pac__=1 +#ld: -shared --force-bti +#warning: .*: warning: BTI turned on by --force-bti.*$ +#readelf: -n + +# Should warn about the missing input BTI NOTE but should +# still mark output as BTI + +Displaying notes found in: .note.gnu.property + Owner Data size Description + GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 + Properties: AArch64 feature: BTI, PAC diff --git a/ld/testsuite/ld-aarch64/bti-plt-7.d b/ld/testsuite/ld-aarch64/bti-plt-7.d new file mode 100644 index 0000000..625f284 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-7.d @@ -0,0 +1,15 @@ +#name: Warn when neither inputs has GNU NOTE BTI +#source: property-bti-pac1.s +#source: plt_mapping_symbol.s +#as: -mabi=lp64 +#ld: -shared --force-bti +#warning: .*: warning: BTI turned on by --force-bti.*$ +#readelf: -n + +# Should warn about the missing input BTI NOTE but should +# still mark output as BTI + +Displaying notes found in: .note.gnu.property + Owner Data size Description + GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 + Properties: AArch64 feature: BTI diff --git a/ld/testsuite/ld-aarch64/bti-plt-so.s b/ld/testsuite/ld-aarch64/bti-plt-so.s new file mode 100644 index 0000000..2c11356 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt-so.s @@ -0,0 +1,41 @@ + .global foo + .type foo, %function +foo: + sub sp, sp, #16 + mov w0, 9 + str w0, [sp, 12] + ldr w0, [sp, 12] + add w0, w0, 4 + str w0, [sp, 12] + nop + add sp, sp, 16 + ret + .size foo, .-foo + .global bar + .type bar, %function +bar: + sub sp, sp, #16 + mov w0, 9 + str w0, [sp, 12] + ldr w0, [sp, 12] + add w0, w0, 4 + str w0, [sp, 12] + nop + add sp, sp, 16 + ret + .size bar, .-bar + .section ".note.gnu.property", "a" + .p2align 3 + .long 1f - 0f /* name length */ + .long 5f - 2f /* data length */ + .long 5 /* note type */ +0: .asciz "GNU" /* vendor name */ +1: + .p2align 3 +2: .long 0xc0000000 /* pr_type. */ + .long 4f - 3f /* pr_datasz. */ +3: + .long 0x1 /* BTI. */ +4: + .p2align 3 +5: diff --git a/ld/testsuite/ld-aarch64/bti-plt.ld b/ld/testsuite/ld-aarch64/bti-plt.ld new file mode 100644 index 0000000..8682623 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-plt.ld @@ -0,0 +1,14 @@ +OUTPUT_ARCH(aarch64) +ENTRY(_start) +SECTIONS +{ + . = 0x10000; + .rela.plt : { *(.rela.plt) *(.rela.iplt) } + . = 0x18000; + .plt : { *(.plt) *(.iplt) } + . = 0x20000; + .text : { *(.text) } + . = 0x28000; + .got : { *(.got) *(.got.plt) } + .ARM.attributes 0 : { *(.ARM.atttributes) } +} |