summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-09-17 00:45:02 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-09-17 00:45:02 +0000
commit2cc3f17a26417de82ccd8f3e381f30afff78afed (patch)
treed7f7d459fdf5044380f0b3de933e4908983d9e4b
parent80a32d62f6da7f945db221bcfda3e95f4dfb0f50 (diff)
downloadbcm5719-llvm-2cc3f17a26417de82ccd8f3e381f30afff78afed.tar.gz
bcm5719-llvm-2cc3f17a26417de82ccd8f3e381f30afff78afed.zip
Driver: Add magic handling for "reserved library names", starting with
-lstdc++. This is the best gross solution for a gross problem. This issue is that historically, GCC has add -L options to its internally library directories. This has allowed users and platforms to end up depending on the layout of GCC's internal library directories. We want to correct this mistake by eliminating that -L, but this means that existing libraries which are in the GCC lib dir won't be found. We are going to handle this by treating those -l names as "reserved", and requiring toolchains to know how to add the right full path to the reserved library. The immediately side effect of this is that users trying to use -L to find their own -lstdc++ will need to start using -nostdlib (which is a good idea anyway). Another side effect is that -stdlib=libc++ -lstdc++ will now do the "right" thing, for curious definitions of right. llvm-svn: 114144
-rw-r--r--clang/include/clang/Driver/Options.td7
-rw-r--r--clang/lib/Driver/Driver.cpp12
-rw-r--r--clang/lib/Driver/Tools.cpp19
3 files changed, 33 insertions, 5 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index de8f1769a5f..a574f41d8c5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -38,6 +38,7 @@ def u_Group : OptionGroup<"<u group>">;
def pedantic_Group : OptionGroup<"<pedantic group>">,
Group<CompileOnly_Group>;
+def reserved_lib_Group : OptionGroup<"<reserved libs group>">;
// Temporary groups for clang options which we know we don't support,
// but don't want to verbosely warn the user about.
@@ -742,4 +743,8 @@ def _write_user_dependencies : Flag<"--write-user-dependencies">, Alias<MMD>;
def _ : Joined<"--">, Flags<[Unsupported]>;
// Special internal option to handle -Xlinker --no-demangle.
-def Z_Xlinker__no_demangle : Flag<"-Z-Xlinker-no-demangle">, Flags<[Unsupported]>;
+def Z_Xlinker__no_demangle : Flag<"-Z-Xlinker-no-demangle">, Flags<[Unsupported, NoArgumentUnused]>;
+
+// Reserved library options.
+def Z_reserved_lib_stdcxx : Flag<"-Z-reserved-lib-stdc++">,
+ Flags<[LinkerInput, NoArgumentUnused, Unsupported]>, Group<reserved_lib_Group>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f5ba96549ba..3707acad249 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -115,6 +115,7 @@ InputArgList *Driver::ParseArgStrings(const char **ArgBegin,
DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
DerivedArgList *DAL = new DerivedArgList(Args);
+ bool HasNostdlib = Args.hasArg(options::OPT_nostdlib);
for (ArgList::const_iterator it = Args.begin(),
ie = Args.end(); it != ie; ++it) {
const Arg *A = *it;
@@ -157,6 +158,17 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
continue;
}
+ // Rewrite reserved library names, unless -nostdlib is present.
+ if (!HasNostdlib && A->getOption().matches(options::OPT_l)) {
+ llvm::StringRef Value = A->getValue(Args);
+
+ if (Value == "stdc++") {
+ DAL->AddFlagArg(A, Opts->getOption(
+ options::OPT_Z_reserved_lib_stdcxx));
+ continue;
+ }
+ }
+
DAL->append(*it);
}
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 7866ad67bc0..6d66af50c50 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -104,10 +104,20 @@ static void AddLinkerInputs(const ToolChain &TC,
<< TC.getTripleString();
}
- if (II.isFilename())
+ // Add filenames immediately.
+ if (II.isFilename()) {
CmdArgs.push_back(II.getFilename());
- else
- II.getInputArg().renderAsInput(Args, CmdArgs);
+ continue;
+ }
+
+ // Otherwise, this is a linker input argument.
+ const Arg &A = II.getInputArg();
+
+ // Handle reserved library options.
+ if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) {
+ TC.AddClangCXXStdlibLibArgs(Args, CmdArgs);
+ } else
+ A.renderAsInput(Args, CmdArgs);
}
}
@@ -3242,7 +3252,8 @@ void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA,
ArgStringList CmdArgs;
if (Output.isFilename()) {
- CmdArgs.push_back(Args.MakeArgString(std::string("-out:") + Output.getFilename()));
+ CmdArgs.push_back(Args.MakeArgString(std::string("-out:") +
+ Output.getFilename()));
} else {
assert(Output.isNothing() && "Invalid output.");
}
OpenPOWER on IntegriCloud