diff options
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 19 | ||||
-rw-r--r-- | ld/NEWS | 4 | ||||
-rw-r--r-- | ld/emultempl/aarch64elf.em | 17 | ||||
-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 |
15 files changed, 291 insertions, 1 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index 32b5387..151877d 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,4 +1,23 @@ 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.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. + +2019-03-13 Sudakshina Das <sudi.das@arm.com> * NEWS: Document GNU_PROPERTY_AARCH64_FEATURE_1_BTI and GNU_PROPERTY_AARCH64_FEATURE_1_PAC. @@ -10,6 +10,10 @@ Changes in 2.33: * Add support for GNU_PROPERTY_AARCH64_FEATURE_1_PAC in ELF GNU program properties in the AArch64 ELF linker. +* Add --force-bti for AArch64 to enable GNU_PROPERTY_AARCH64_FEATURE_1_BTI + on output while warning about missing GNU_PROPERTY_AARCH64_FEATURE_1_BTI + on inputs and use PLTs protected with BTI. + Changes in 2.32: * Report property change in linker map file when merging GNU properties. diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em index 45e40b5..02243d9 100644 --- a/ld/emultempl/aarch64elf.em +++ b/ld/emultempl/aarch64elf.em @@ -33,6 +33,8 @@ static int pic_veneer = 0; static int fix_erratum_835769 = 0; static int fix_erratum_843419 = 0; static int no_apply_dynamic_relocs = 0; +static aarch64_plt_type plt_type = PLT_NORMAL; +static aarch64_enable_bti_type bti_type = BTI_NONE; static void gld${EMULATION_NAME}_before_parse (void) @@ -308,12 +310,17 @@ aarch64_elf_create_output_section_statements (void) return; } + aarch64_bti_pac_info bp_info; + bp_info.plt_type = plt_type; + bp_info.bti_type = bti_type; + bfd_elf${ELFSIZE}_aarch64_set_options (link_info.output_bfd, &link_info, no_enum_size_warning, no_wchar_size_warning, pic_veneer, fix_erratum_835769, fix_erratum_843419, - no_apply_dynamic_relocs); + no_apply_dynamic_relocs, + bp_info); stub_file = lang_add_input_file ("linker stubs", lang_input_file_is_fake_enum, @@ -365,6 +372,7 @@ PARSE_AND_LIST_PROLOGUE=' #define OPTION_FIX_ERRATUM_835769 313 #define OPTION_FIX_ERRATUM_843419 314 #define OPTION_NO_APPLY_DYNAMIC_RELOCS 315 +#define OPTION_FORCE_BTI 316 ' PARSE_AND_LIST_SHORTOPTS=p @@ -378,6 +386,7 @@ PARSE_AND_LIST_LONGOPTS=' { "fix-cortex-a53-835769", no_argument, NULL, OPTION_FIX_ERRATUM_835769}, { "fix-cortex-a53-843419", no_argument, NULL, OPTION_FIX_ERRATUM_843419}, { "no-apply-dynamic-relocs", no_argument, NULL, OPTION_NO_APPLY_DYNAMIC_RELOCS}, + { "force-bti", no_argument, NULL, OPTION_FORCE_BTI}, ' PARSE_AND_LIST_OPTIONS=' @@ -398,6 +407,7 @@ PARSE_AND_LIST_OPTIONS=' fprintf (file, _(" --fix-cortex-a53-835769 Fix erratum 835769\n")); fprintf (file, _(" --fix-cortex-a53-843419 Fix erratum 843419\n")); fprintf (file, _(" --no-apply-dynamic-relocs Do not apply link-time values for dynamic relocations\n")); + fprintf (file, _(" --force-bti Turn on Branch Target Identification mechanism and generate PLTs with BTI. Generate warnings for missing BTI on inputs\n")); ' PARSE_AND_LIST_ARGS_CASES=' @@ -429,6 +439,11 @@ PARSE_AND_LIST_ARGS_CASES=' no_apply_dynamic_relocs = 1; break; + case OPTION_FORCE_BTI: + plt_type |= PLT_BTI; + bti_type = BTI_WARN; + break; + case OPTION_STUBGROUP_SIZE: { const char *end; 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) } +} |