diff options
author | Alvin Wong <alvin@alvinhc.com> | 2022-09-09 09:17:33 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2022-09-09 09:55:40 +0300 |
commit | bf7c5f1fae582ff4cc875713695b2dadb1cf5e59 (patch) | |
tree | 00f6f3e7ac00a08f195f676138d6c38c7242aadf /lld/MinGW | |
parent | 06413618eae968e457350358e23c4dce932c370a (diff) | |
download | llvm-bf7c5f1fae582ff4cc875713695b2dadb1cf5e59.tar.gz |
[LLD][MinGW] Add --[no-]guard-cf and --[no-]guard-longjmp
These will be LLD-specific options to support Control Flow Guard for the
MinGW target. They are disabled by default, but enabling `--guard-cf`
will also enable `--guard-longjmp` unless `--no-guard-longjmp` is also
specified. These options maps to `-guard:cf,[no]longjmp`.
Note that these features require the `_load_config_used` symbol to
contain the load config directory and be filled with the required
symbols. While current versions of mingw-w64 do not supply this symbol,
the user can provide their own version of it.
Reviewed By: MaskRay, rnk
Differential Revision: https://reviews.llvm.org/D132808
Diffstat (limited to 'lld/MinGW')
-rw-r--r-- | lld/MinGW/Driver.cpp | 11 | ||||
-rw-r--r-- | lld/MinGW/Options.td | 5 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp index 37d2439c3925..90d210e2f880 100644 --- a/lld/MinGW/Driver.cpp +++ b/lld/MinGW/Driver.cpp @@ -379,6 +379,17 @@ bool mingw::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS, error("unknown parameter: -m" + s); } + if (args.hasFlag(OPT_guard_cf, OPT_no_guard_cf, false)) { + if (args.hasFlag(OPT_guard_longjmp, OPT_no_guard_longjmp, true)) + add("-guard:cf,longjmp"); + else + add("-guard:cf,nolongjmp"); + } else if (args.hasFlag(OPT_guard_longjmp, OPT_no_guard_longjmp, false)) { + auto *a = args.getLastArg(OPT_guard_longjmp); + warn("parameter " + a->getSpelling() + + " only takes effect when used with --guard-cf"); + } + for (auto *a : args.filtered(OPT_mllvm)) add("-mllvm:" + StringRef(a->getValue())); diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td index cc94b93e388a..923b9cce3d18 100644 --- a/lld/MinGW/Options.td +++ b/lld/MinGW/Options.td @@ -141,6 +141,11 @@ defm pdb: Eq<"pdb", "Output PDB debug info file, chosen implicitly if the argume defm thinlto_cache_dir: EqLong<"thinlto-cache-dir", "Path to ThinLTO cached object file directory">; defm Xlink : Eq<"Xlink", "Pass <arg> to the COFF linker">, MetaVarName<"<arg>">; +defm guard_cf : B<"guard-cf", "Enable Control Flow Guard" , + "Do not enable Control Flow Guard (default)">; +defm guard_longjmp : B<"guard-longjmp", + "Enable Control Flow Guard long jump hardening (default for --guard-cf)" , + "Do not enable Control Flow Guard long jump hardening">; // Alias def alias_Bdynamic_call_shared: Flag<["-"], "call_shared">, Alias<Bdynamic>; |