diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -354,9 +354,9 @@ if (config->emachine != EM_AARCH64) { if (config->pacPlt) - error("--pac-plt only supported on AArch64"); + error("-z pac-plt only supported on AArch64"); if (config->forceBTI) - error("--force-bti only supported on AArch64"); + error("-z force-bti only supported on AArch64"); } } @@ -412,17 +412,18 @@ static bool isKnownZFlag(StringRef s) { return s == "combreloc" || s == "copyreloc" || s == "defs" || - s == "execstack" || s == "global" || s == "hazardplt" || - s == "ifunc-noplt" || s == "initfirst" || s == "interpose" || - s == "keep-text-section-prefix" || s == "lazy" || s == "muldefs" || - s == "separate-code" || s == "separate-loadable-segments" || - s == "nocombreloc" || s == "nocopyreloc" || s == "nodefaultlib" || - s == "nodelete" || s == "nodlopen" || s == "noexecstack" || - s == "nognustack" || + s == "execstack" || s == "force-bti" || s == "global" || + s == "hazardplt" || s == "ifunc-noplt" || s == "initfirst" || + s == "interpose" || s == "keep-text-section-prefix" || s == "lazy" || + s == "muldefs" || s == "separate-code" || + s == "separate-loadable-segments" || s == "nocombreloc" || + s == "nocopyreloc" || s == "nodefaultlib" || s == "nodelete" || + s == "nodlopen" || s == "noexecstack" || s == "nognustack" || s == "nokeep-text-section-prefix" || s == "norelro" || s == "noseparate-code" || s == "notext" || s == "now" || - s == "origin" || s == "relro" || s == "retpolineplt" || - s == "rodynamic" || s == "text" || s == "undefs" || s == "wxneeded" || + s == "origin" || s == "pac-plt" || s == "relro" || + s == "retpolineplt" || s == "rodynamic" || s == "text" || + s == "undefs" || s == "wxneeded" || s.startswith("common-page-size=") || s.startswith("max-page-size=") || s.startswith("stack-size="); } @@ -878,7 +879,7 @@ config->fini = args.getLastArgValue(OPT_fini, "_fini"); config->fixCortexA53Errata843419 = args.hasArg(OPT_fix_cortex_a53_843419); config->fixCortexA8 = args.hasArg(OPT_fix_cortex_a8); - config->forceBTI = args.hasArg(OPT_force_bti); + config->forceBTI = hasZOption(args, "force-bti"); config->requireCET = args.hasArg(OPT_require_cet); config->gcSections = args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false); config->gnuUnique = args.hasFlag(OPT_gnu_unique, OPT_no_gnu_unique, true); @@ -917,7 +918,7 @@ config->optimize = args::getInteger(args, OPT_O, 1); config->orphanHandling = getOrphanHandling(args); config->outputFile = args.getLastArgValue(OPT_o); - config->pacPlt = args.hasArg(OPT_pac_plt); + config->pacPlt = hasZOption(args, "pac-plt"); config->pie = args.hasFlag(OPT_pie, OPT_no_pie, false); config->printIcfSections = args.hasFlag(OPT_print_icf_sections, OPT_no_print_icf_sections, false); @@ -1704,7 +1705,7 @@ for (InputFile *f : objectFiles) { uint32_t features = cast>(f)->andFeatures; if (config->forceBTI && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) { - warn(toString(f) + ": --force-bti: file does not have BTI property"); + warn(toString(f) + ": -z force-bti: file does not have BTI property"); features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI; } else if (!features && config->requireCET) error(toString(f) + ": --require-cet: file is not compatible with CET"); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -180,9 +180,6 @@ // is not complete. def require_cet: F<"require-cet">; -def force_bti: F<"force-bti">, - HelpText<"Force enable AArch64 BTI in PLT, warn if Input ELF file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property">; - defm format: Eq<"format", "Change the input format of the inputs following this option">, MetaVarName<"[default,elf,binary]">; @@ -281,9 +278,6 @@ Eq<"pack-dyn-relocs", "Pack dynamic relocations in the given format">, MetaVarName<"[none,android,relr,android+relr]">; -def pac_plt: F<"pac-plt">, - HelpText<"AArch64 only, use pointer authentication in PLT">; - defm use_android_relr_tags: B<"use-android-relr-tags", "Use SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_RELR / DT_RELR*", "Use SHT_RELR / DT_RELR* tags (default)">; diff --git a/lld/docs/ld.lld.1 b/lld/docs/ld.lld.1 --- a/lld/docs/ld.lld.1 +++ b/lld/docs/ld.lld.1 @@ -191,8 +191,6 @@ field to the specified value. .It Fl -fini Ns = Ns Ar symbol Specify a finalizer function. -.It Fl -force-bti -Force enable AArch64 BTI instruction in PLT, warn if Input ELF file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property. .It Fl -format Ns = Ns Ar input-format , Fl b Ar input-format Specify the format of the inputs following this option. .Ar input-format @@ -401,8 +399,6 @@ .Fl -use-android-relr-tags is specified, use SHT_ANDROID_RELR instead of SHT_RELR. .Pp -.It Fl -pac-plt -AArch64 only, use pointer authentication in PLT. .It Fl -pic-veneer Always generate position independent thunks. .It Fl -pie , Fl -pic-executable @@ -599,6 +595,9 @@ .Dv PT_GNU_STACK segment. .Pp +.It Cm force-bti +Force enable AArch64 BTI instruction in PLT, warn if Input ELF file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property. +.Pp .It Cm global Sets the .Dv DF_1_GLOBAL flag in the @@ -688,6 +687,9 @@ $ORIGIN processing. .Pp +.It Cm pac-plt +AArch64 only, use pointer authentication in PLT. +.Pp .It Cm retpolineplt Emit retpoline format PLT entries as a mitigation for CVE-2017-5715. .Pp diff --git a/lld/test/ELF/aarch64-bti-pac-cli-error.s b/lld/test/ELF/aarch64-bti-pac-cli-error.s --- a/lld/test/ELF/aarch64-bti-pac-cli-error.s +++ b/lld/test/ELF/aarch64-bti-pac-cli-error.s @@ -1,12 +1,12 @@ # REQUIRES: x86 # RUN: llvm-mc --triple=x86_64-pc-linux --filetype=obj -o %t.o %s -# RUN: not ld.lld --pac-plt --force-bti %t.o -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld -z pac-plt -z force-bti %t.o -o %t 2>&1 | FileCheck %s # -## Check that we error if --pac-plt and --force-bti are used when target is not +## Check that we error if -z pac-plt and -z force-bti are used when target is not ## aarch64 -# CHECK: error: --pac-plt only supported on AArch64 -# CHECK-NEXT: error: --force-bti only supported on AArch64 +# CHECK: error: -z pac-plt only supported on AArch64 +# CHECK-NEXT: error: -z force-bti only supported on AArch64 .globl start start: ret diff --git a/lld/test/ELF/aarch64-feature-bti.s b/lld/test/ELF/aarch64-feature-bti.s --- a/lld/test/ELF/aarch64-feature-bti.s +++ b/lld/test/ELF/aarch64-feature-bti.s @@ -169,12 +169,12 @@ # NOEX-NEXT: add x16, x16, #1032 # NOEX-NEXT: br x17 -## Force BTI entries with the --force-bti command line option. Expect a warning +## Force BTI entries with the -z force-bti command line option. Expect a warning ## from the file without the .note.gnu.property. -# RUN: ld.lld %t.o %t2.o --force-bti %t.so -o %tforcebti.exe 2>&1 | FileCheck --check-prefix=FORCE-WARN %s +# RUN: ld.lld %t.o %t2.o -z force-bti %t.so -o %tforcebti.exe 2>&1 | FileCheck --check-prefix=FORCE-WARN %s -# FORCE-WARN: aarch64-feature-bti.s.tmp2.o: --force-bti: file does not have BTI property +# FORCE-WARN: aarch64-feature-bti.s.tmp2.o: -z force-bti: file does not have BTI property # RUN: llvm-readelf -n %tforcebti.exe | FileCheck --check-prefix=BTIPROP %s diff --git a/lld/test/ELF/aarch64-feature-btipac.s b/lld/test/ELF/aarch64-feature-btipac.s --- a/lld/test/ELF/aarch64-feature-btipac.s +++ b/lld/test/ELF/aarch64-feature-btipac.s @@ -109,13 +109,13 @@ # NODYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT) # NODYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT) -## Check that combination of --pac-plt and --force-bti warns for the file that +## Check that combination of -z pac-plt and -z force-bti warns for the file that ## doesn't contain the BTI property, but generates PAC and BTI PLT sequences. -## The --pac-plt doesn't warn as it is not required for correctness. +## The -z pac-plt doesn't warn as it is not required for correctness. -# RUN: ld.lld %t.o %t3.o %t.so --pac-plt --force-bti -o %t.exe 2>&1 | FileCheck --check-prefix=FORCE-WARN %s +# RUN: ld.lld %t.o %t3.o %t.so -z pac-plt -z force-bti -o %t.exe 2>&1 | FileCheck --check-prefix=FORCE-WARN %s -# FORCE-WARN: aarch64-feature-btipac.s.tmp3.o: --force-bti: file does not have BTI property +# FORCE-WARN: aarch64-feature-btipac.s.tmp3.o: -z force-bti: file does not have BTI property # RUN: llvm-readelf -n %t.exe | FileCheck --check-prefix=BTIPACPROP %s # RUN: llvm-objdump -d -mattr=+v8.5a --no-show-raw-insn %t.exe | FileCheck --check-prefix BTIPACEX %s diff --git a/lld/test/ELF/aarch64-feature-pac.s b/lld/test/ELF/aarch64-feature-pac.s --- a/lld/test/ELF/aarch64-feature-pac.s +++ b/lld/test/ELF/aarch64-feature-pac.s @@ -80,12 +80,12 @@ # PACDYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT) # PACDYN: 0x0000000070000003 (AARCH64_PAC_PLT) -## Turn on PAC entries with the --pac-plt command line option. There are no +## Turn on PAC entries with the -z pac-plt command line option. There are no ## warnings in this case as the choice to use PAC in PLT entries is orthogonal ## to the choice of using PAC in relocatable objects. The presence of the PAC ## .note.gnu.property is an indication of preference by the relocatable object. -# RUN: ld.lld %t.o %t2.o --pac-plt %t.so -o %tpacplt.exe +# RUN: ld.lld %t.o %t2.o -z pac-plt %t.so -o %tpacplt.exe # RUN: llvm-readelf -n %tpacplt.exe | FileCheck --check-prefix=PACPROP %s # RUN: llvm-readelf --dynamic-table %tpacplt.exe | FileCheck --check-prefix PACDYN %s # RUN: llvm-objdump -d -mattr=+v8.3a --no-show-raw-insn %tpacplt.exe | FileCheck --check-prefix PACPLT %s