[lld] r335712 - Report an error for an unknown -z option.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 27 00:22:27 PDT 2018
Author: ruiu
Date: Wed Jun 27 00:22:27 2018
New Revision: 335712
URL: http://llvm.org/viewvc/llvm-project?rev=335712&view=rev
Log:
Report an error for an unknown -z option.
This is a less clever version of https://reviews.llvm.org/D48433.
This is a dumb version but I think I prefer this for its simplicity.
Differential Revision: https://reviews.llvm.org/D48621
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/test/ELF/driver.test
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=335712&r1=335711&r2=335712&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Jun 27 00:22:27 2018
@@ -325,6 +325,25 @@ static bool getZFlag(opt::InputArgList &
return Default;
}
+static bool isKnown(StringRef S) {
+ return S == "combreloc" || S == "copyreloc" || S == "defs" ||
+ S == "execstack" || S == "hazardplt" || S == "initfirst" ||
+ S == "keep-text-section-prefix" || S == "lazy" || S == "muldefs" ||
+ S == "nocombreloc" || S == "nocopyreloc" || S == "nodelete" ||
+ S == "nodlopen" || S == "noexecstack" ||
+ S == "nokeep-text-section-prefix" || S == "norelro" || S == "notext" ||
+ S == "now" || S == "origin" || S == "relro" || S == "retpolineplt" ||
+ S == "rodynamic" || S == "text" || S == "wxneeded" ||
+ S.startswith("max-page-size") || S.startswith("stack-size");
+}
+
+// Report an error for an unknown -z option.
+static void checkZOptions(opt::InputArgList &Args) {
+ for (auto *Arg : Args.filtered(OPT_z))
+ if (!isKnown(Arg->getValue()))
+ error("unknown -z value: " + StringRef(Arg->getValue()));
+}
+
void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
ELFOptTable Parser;
opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
@@ -380,6 +399,7 @@ void LinkerDriver::main(ArrayRef<const c
}
readConfigs(Args);
+ checkZOptions(Args);
initLLVM();
createFiles(Args);
if (errorCount())
Modified: lld/trunk/test/ELF/driver.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/driver.test?rev=335712&r1=335711&r2=335712&view=diff
==============================================================================
--- lld/trunk/test/ELF/driver.test (original)
+++ lld/trunk/test/ELF/driver.test Wed Jun 27 00:22:27 2018
@@ -55,6 +55,9 @@
# RUN: not ld.lld %t -output=/no/such/file 2>&1 | FileCheck -check-prefix=ERR8 %s
# ERR8: cannot open output file utput=/no/such/file
+# RUN: not ld.lld %t -z foo 2>&1 | FileCheck -check-prefix=ERR9 %s
+# ERR9: unknown -z value: foo
+
.globl _start
_start:
nop
More information about the llvm-commits
mailing list