Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -346,16 +346,20 @@ } static bool isKnownZFlag(StringRef S) { - return S == "combreloc" || S == "copyreloc" || S == "defs" || - S == "execstack" || S == "global" || S == "hazardplt" || - S == "initfirst" || S == "interpose" || - 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="); + static llvm::SmallDenseSet KnownFlags { + "combreloc", "copyreloc", "defs", + "execstack", "global", "hazardplt", + "initfirst", "interpose", "keep-text-section-prefix", + "lazy", "muldefs", "nocombreloc", + "nocopyreloc", "nodelete", "nodlopen", + "noexecstack", "nokeep-text-section-prefix", "norelro", + "notext", "now", "origin", + "relro", "retpolineplt", "rodynamic", + "text", "wxneeded" + }; + + return KnownFlags.count(S) || S.startswith("max-page-size=") || + S.startswith("stack-size="); } // Report an error for an unknown -z option. Index: test/ELF/invalid/zunknown-flag.test =================================================================== --- test/ELF/invalid/zunknown-flag.test +++ test/ELF/invalid/zunknown-flag.test @@ -0,0 +1,3 @@ +# RUN: not ld.lld -z obviouslyunknownflag 2>&1 | FileCheck --check-prefix=ERR %s +# ERR: error: unknown -z value: obviouslyunknownflag +