Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/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 ArgsArr) { ELFOptTable Parser; opt::InputArgList Args = Parser.parse(ArgsArr.slice(1)); @@ -380,6 +399,7 @@ } readConfigs(Args); + checkZOptions(Args); initLLVM(); createFiles(Args); if (errorCount()) Index: lld/test/ELF/driver.test =================================================================== --- lld/test/ELF/driver.test +++ lld/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