diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 66fe86bbac45f2de1bce43c68036ff18ffb989a8..832de531131c82912275f2f40b475e3571cd53d5 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -9852,6 +9852,25 @@ elfNN_aarch64_merge_gnu_properties (struct bfd_link_info *info, { uint32_t prop = elf_aarch64_tdata (info->output_bfd)->gnu_and_prop; + + /* If output has been marked with BTI using command line argument, give out + warning if necessary. */ + if ((prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) + && (!elf_aarch64_tdata (info->output_bfd)->no_enable_bti_warn)) + { + if ((aprop && !(aprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) + || (bprop && !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) + /* If either property is NULL, it means its bfd did not have any + property. */ + || !aprop || !bprop) + { + _bfd_error_handler (_("warning: BTI turned on by --bti when " + "all inputs do not have BTI in NOTE " + "section. If this was intentional use " + "--bti-nowarn to turn off the warning.")); + } + } + return _bfd_aarch64_elf_merge_gnu_properties (info, abfd, aprop, bprop, prop); } diff --git a/ld/NEWS b/ld/NEWS index 31731219ad546483ae92a7e32862986627bfc4d4..e19870f741ad072d89e4f72a1c96d2903ad9d3fd 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -13,6 +13,10 @@ Changes in 2.33: * Add --bti-nowarn for AArch64 to enable GNU_PROPERTY_AARCH64_FEATURE_1_BTI on output without any warnings and use PLTs protected with BTI. +* Add --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 146bfad31fd299ef5c170b269e86afd0f3e1f5b9..c2db3e9e531930f0659197219369da1ddb04275c 100644 --- a/ld/emultempl/aarch64elf.em +++ b/ld/emultempl/aarch64elf.em @@ -373,6 +373,7 @@ PARSE_AND_LIST_PROLOGUE=' #define OPTION_FIX_ERRATUM_843419 314 #define OPTION_NO_APPLY_DYNAMIC_RELOCS 315 #define OPTION_BTI_NOWARN 316 +#define OPTION_BTI_WARN 317 ' PARSE_AND_LIST_SHORTOPTS=p @@ -387,6 +388,7 @@ PARSE_AND_LIST_LONGOPTS=' { "fix-cortex-a53-843419", no_argument, NULL, OPTION_FIX_ERRATUM_843419}, { "no-apply-dynamic-relocs", no_argument, NULL, OPTION_NO_APPLY_DYNAMIC_RELOCS}, { "bti-nowarn", no_argument, NULL, OPTION_BTI_NOWARN}, + { "bti", no_argument, NULL, OPTION_BTI_WARN}, ' PARSE_AND_LIST_OPTIONS=' @@ -408,6 +410,7 @@ PARSE_AND_LIST_OPTIONS=' 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, _(" --bti-nowarn Turn on Branch Target Identification mechanism and generate PLTs with BTI. Generate no warnings for missing BTI on inputs\n")); + fprintf (file, _(" --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=' @@ -444,6 +447,11 @@ PARSE_AND_LIST_ARGS_CASES=' bti_type = BTI_NOWARN; break; + case OPTION_BTI_WARN: + 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 ed0bca5b081c5c016b3f8e96619b76820aa1525d..906534b230c8905fb97a6739e1c1411683455fe3 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -400,3 +400,5 @@ 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-6.d b/ld/testsuite/ld-aarch64/bti-plt-6.d new file mode 100644 index 0000000000000000000000000000000000000000..0f94e89ba227abbcf2d01b0b0fd0c5be12db2f5c --- /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 --bti +#warning: .*: warning: BTI turned on by --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 0000000000000000000000000000000000000000..e4fbac4d87d746d514d109b80ccc0d0105ef444d --- /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: bti-plt-1.s +#source: bti-plt-2.s +#as: -mabi=lp64 +#ld: -shared --bti +#warning: .*: warning: BTI turned on by --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