Fixed #66 — -shared do not set a SONAME

This commit is contained in:
Alexey Prokhin
2012-02-14 19:54:51 +04:00
parent fb5618e336
commit 6687a6624b
4 changed files with 25 additions and 2 deletions

View File

@@ -110,6 +110,12 @@ cl::opt<std::string> objectDir("od",
cl::Prefix,
cl::desc("Write object files to directory <objdir>"));
cl::opt<std::string> soname("soname",
cl::value_desc("soname"),
cl::Hidden,
cl::Prefix,
cl::desc("Use <soname> as output shared library soname"));
// Output format options
cl::opt<bool> output_bc("output-bc",

View File

@@ -28,6 +28,7 @@ namespace opts {
extern cl::opt<bool> dontWriteObj;
extern cl::opt<std::string> objectFile;
extern cl::opt<std::string> objectDir;
extern cl::opt<std::string> soname;
extern cl::opt<bool> output_bc;
extern cl::opt<bool> output_ll;
extern cl::opt<bool> output_s;

View File

@@ -278,8 +278,6 @@ int linkObjToBinary(bool sharedLib)
}
}
args.push_back("-o");
args.push_back(output.c_str());
@@ -315,14 +313,17 @@ int linkObjToBinary(bool sharedLib)
}
// default libs
bool addSoname = false;
switch(global.params.os) {
case OSLinux:
addSoname = true;
args.push_back("-lrt");
// fallthrough
case OSMacOSX:
args.push_back("-ldl");
// fallthrough
case OSFreeBSD:
addSoname = true;
args.push_back("-lpthread");
args.push_back("-lm");
break;
@@ -345,6 +346,16 @@ int linkObjToBinary(bool sharedLib)
// Assume 32-bit?
args.push_back("-m32");
OutBuffer buf;
if (opts::createSharedLib && addSoname) {
std::string soname = opts::soname.getNumOccurrences() == 0 ? output : opts::soname;
if (!soname.empty()) {
buf.writestring("-Wl,-soname,");
buf.writestring(soname.c_str());
args.push_back(buf.toChars());
}
}
// print link command?
if (!quiet || global.params.verbose)
{

View File

@@ -419,6 +419,11 @@ int main(int argc, char** argv)
}
}
if (soname.getNumOccurrences() > 0 && !createSharedLib) {
error("-soname can be used only when building a shared library");
fatal();
}
// create a proper target
Ir ir;