summaryrefslogtreecommitdiffstats
path: root/lld/COFF/DriverUtils.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-09-13 13:13:52 +0000
committerNico Weber <nicolasweber@gmx.de>2019-09-13 13:13:52 +0000
commitd48ea5da94165dbaba14b1281b74994fe970a7e0 (patch)
tree0f6a7804b6c93c6a00939ef6feb34b713ab1d9e8 /lld/COFF/DriverUtils.cpp
parent67503ba556cd4008179491db6d024ec0f9d9c9cd (diff)
downloadbcm5719-llvm-d48ea5da94165dbaba14b1281b74994fe970a7e0.tar.gz
bcm5719-llvm-d48ea5da94165dbaba14b1281b74994fe970a7e0.zip
lld-link: Add a flag /lldignoreenv that makes lld-link ignore env vars.
This is useful for enforcing that builds are independent of the environment; it can be used when all system library paths are added via /libpath: already. It's similar ot cl.exe's /X flag. Since it should also affect %LINK% (the other caller of `Process::GetEnv` in lld/COFF), the early-option-parsing needs to move around a bit. The options are: - Add a manual loop over the argv ArrayRef and look for "/lldignoreenv". This repeats the name of the flag in both Options.td and in DriverUtils.cpp. - Add yet another table.ParseArgs() call just for /lldignoreenv before adding %LINK%. - Use the existing early ParseArgs() that's there for --rsp-quoting and use it for /lldignoreenv for %LINK% as well. This means --rsp-quoting and /lldignoreenv can't be passed via %LINK%. I went with the third approach. Differential Revision: https://reviews.llvm.org/D67456 llvm-svn: 371852
Diffstat (limited to 'lld/COFF/DriverUtils.cpp')
-rw-r--r--lld/COFF/DriverUtils.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index b525ffdae9c..e08b855740a 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -808,13 +808,17 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
// We need to get the quoting style for response files before parsing all
// options so we parse here before and ignore all the options but
- // --rsp-quoting.
+ // --rsp-quoting and /lldignoreenv.
+ // (This means --rsp-quoting can't be added through %LINK%.)
opt::InputArgList args = table.ParseArgs(argv, missingIndex, missingCount);
- // Expand response files (arguments in the form of @<filename>)
- // and then parse the argument again.
+
+ // Expand response files (arguments in the form of @<filename>) and insert
+ // flags from %LINK% and %_LINK_%, and then parse the argument again.
SmallVector<const char *, 256> expandedArgv(argv.data(),
argv.data() + argv.size());
+ if (!args.hasArg(OPT_lldignoreenv))
+ addLINK(expandedArgv);
cl::ExpandResponseFiles(saver, getQuotingStyle(args), expandedArgv);
args = table.ParseArgs(makeArrayRef(expandedArgv).drop_front(), missingIndex,
missingCount);
@@ -884,7 +888,7 @@ ArgParser::parseDirectives(StringRef s) {
// link.exe has an interesting feature. If LINK or _LINK_ environment
// variables exist, their contents are handled as command line strings.
// So you can pass extra arguments using them.
-opt::InputArgList ArgParser::parseLINK(std::vector<const char *> argv) {
+void ArgParser::addLINK(SmallVector<const char *, 256> &argv) {
// Concatenate LINK env and command line arguments, and then parse them.
if (Optional<std::string> s = Process::GetEnv("LINK")) {
std::vector<const char *> v = tokenize(*s);
@@ -894,7 +898,6 @@ opt::InputArgList ArgParser::parseLINK(std::vector<const char *> argv) {
std::vector<const char *> v = tokenize(*s);
argv.insert(std::next(argv.begin()), v.begin(), v.end());
}
- return parse(argv);
}
std::vector<const char *> ArgParser::tokenize(StringRef s) {
OpenPOWER on IntegriCloud