[Driver][GNULD] Lookup .so files and default to dynamic output.

llvm-svn: 175572
This commit is contained in:
Michael J. Spencer
2013-02-19 23:05:36 +00:00
parent 3e1729484f
commit 2139795dfa
2 changed files with 21 additions and 0 deletions

View File

@@ -115,6 +115,8 @@ public:
std::unique_ptr<llvm::opt::DerivedArgList> newArgs(
new llvm::opt::DerivedArgList(*_inputArgs));
bool isOutputDynamic = false;
if (llvm::opt::Arg *A = _inputArgs->getLastArg(ld::OPT_target)) {
newArgs->AddSeparateArg( A, _core.getOption(core::OPT_target)
, A->getValue());
@@ -134,6 +136,15 @@ public:
newArgs->AddJoinedArg(nullptr, _core.getOption(core::OPT_output),
"a.out");
if (llvm::opt::Arg *A = _inputArgs->getLastArg(ld::OPT_static))
newArgs->AddJoinedArg(A, _core.getOption(core::OPT_output_type),
newArgs->MakeArgString("static"));
else {
newArgs->AddJoinedArg(nullptr, _core.getOption(core::OPT_output_type),
newArgs->MakeArgString("dynamic"));
isOutputDynamic = true;
}
if (llvm::opt::Arg *A = _inputArgs->getLastArg(ld::OPT_relocatable))
newArgs->AddFlagArg(A, _core.getOption(core::OPT_relocatable));
@@ -170,6 +181,14 @@ public:
StringRef libName = (*it)->getValue();
SmallString<128> p;
for (const auto &path : _inputSearchPaths) {
if (isOutputDynamic) {
p = path;
llvm::sys::path::append(p, Twine("lib") + libName + ".so");
if (llvm::sys::fs::exists(p.str())) {
inputPath = newArgs->MakeArgString(p);
break;
}
}
p = path;
llvm::sys::path::append(p, Twine("lib") + libName + ".a");
if (llvm::sys::fs::exists(p.str())) {

View File

@@ -14,6 +14,8 @@ def output_e : Separate<["-"], "o">, Alias<output>;
def relocatable : Flag<["--"], "relocatable">;
def relocatable_r : Flag<["-"], "r">, Alias<relocatable>;
def dynamic_linker : Separate<["-"], "dynamic-linker">;
def OCTOTHORPE_OCTOTHORPE_OCTOTHORPE : Flag<["-"], "###">;
def emit_yaml : Flag<["-"], "emit-yaml">;