[PATCH] D48621: Report an error for an unknown -z option.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 27 00:27:04 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL335712: Report an error for an unknown -z option. (authored by ruiu, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48621?vs=153004&id=153009#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48621

Files:
  lld/trunk/ELF/Driver.cpp
  lld/trunk/test/ELF/driver.test


Index: lld/trunk/test/ELF/driver.test
===================================================================
--- lld/trunk/test/ELF/driver.test
+++ lld/trunk/test/ELF/driver.test
@@ -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
Index: lld/trunk/ELF/Driver.cpp
===================================================================
--- lld/trunk/ELF/Driver.cpp
+++ lld/trunk/ELF/Driver.cpp
@@ -325,6 +325,25 @@
   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 @@
   }
 
   readConfigs(Args);
+  checkZOptions(Args);
   initLLVM();
   createFiles(Args);
   if (errorCount())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48621.153009.patch
Type: text/x-patch
Size: 1839 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180627/3654f9c3/attachment.bin>


More information about the llvm-commits mailing list