From 75656eebb877f643c38bc6898fd82e28c3302530 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 19 Oct 2015 19:40:43 +0000 Subject: [PATCH] COFF: /OPT should accept comma-separated multiple arguments. /OPT:foo,bar is equivalent to /OPT:foo /OPT:bar. Reported by alexchandel. https://llvm.org/bugs/show_bug.cgi?id=25228 llvm-svn: 250728 --- lld/COFF/Driver.cpp | 60 +++++++++++++++++++---------------- lld/test/COFF/icf-simple.test | 3 ++ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 4d375c3af0dc..f4ce04aa914c 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -361,35 +361,39 @@ void LinkerDriver::link(llvm::ArrayRef ArgsArr) { // Handle /opt for (auto *Arg : Args.filtered(OPT_opt)) { - std::string S = StringRef(Arg->getValue()).lower(); - if (S == "noref") { - Config->DoGC = false; - Config->DoICF = false; - continue; + std::string Str = StringRef(Arg->getValue()).lower(); + SmallVector Vec; + StringRef(Str).split(Vec, ','); + for (StringRef S : Vec) { + if (S == "noref") { + Config->DoGC = false; + Config->DoICF = false; + continue; + } + if (S == "icf" || StringRef(S).startswith("icf=")) { + Config->DoICF = true; + continue; + } + if (S == "noicf") { + Config->DoICF = false; + continue; + } + if (StringRef(S).startswith("lldlto=")) { + StringRef OptLevel = StringRef(S).substr(7); + if (OptLevel.getAsInteger(10, Config->LTOOptLevel) || + Config->LTOOptLevel > 3) + error("/opt:lldlto: invalid optimization level: " + OptLevel); + continue; + } + if (StringRef(S).startswith("lldltojobs=")) { + StringRef Jobs = StringRef(S).substr(11); + if (Jobs.getAsInteger(10, Config->LTOJobs) || Config->LTOJobs == 0) + error("/opt:lldltojobs: invalid job count: " + Jobs); + continue; + } + if (S != "ref" && S != "lbr" && S != "nolbr") + error(Twine("/opt: unknown option: ") + S); } - if (S == "icf" || StringRef(S).startswith("icf=")) { - Config->DoICF = true; - continue; - } - if (S == "noicf") { - Config->DoICF = false; - continue; - } - if (StringRef(S).startswith("lldlto=")) { - StringRef OptLevel = StringRef(S).substr(7); - if (OptLevel.getAsInteger(10, Config->LTOOptLevel) || - Config->LTOOptLevel > 3) - error("/opt:lldlto: invalid optimization level: " + OptLevel); - continue; - } - if (StringRef(S).startswith("lldltojobs=")) { - StringRef Jobs = StringRef(S).substr(11); - if (Jobs.getAsInteger(10, Config->LTOJobs) || Config->LTOJobs == 0) - error("/opt:lldltojobs: invalid job count: " + Jobs); - continue; - } - if (S != "ref" && S != "lbr" && S != "nolbr") - error(Twine("/opt: unknown option: ") + S); } // Handle /failifmismatch diff --git a/lld/test/COFF/icf-simple.test b/lld/test/COFF/icf-simple.test index 04d86d1e916b..ae72fd9d9d73 100644 --- a/lld/test/COFF/icf-simple.test +++ b/lld/test/COFF/icf-simple.test @@ -9,6 +9,9 @@ # RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \ # RUN: /verbose /opt:noicf %t.obj > %t.log 2>&1 # RUN: FileCheck -check-prefix=NOICF %s < %t.log +# RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \ +# RUN: /verbose /opt:noref,noicf %t.obj > %t.log 2>&1 +# RUN: FileCheck -check-prefix=NOICF %s < %t.log # NOICF-NOT: Removed foo # NOICF-NOT: Removed bar