Switch autolinking metadata format over to actual linker options, e.g.,
!0 = metadata !{metadata !"-lautolink"} !1 = metadata !{metadata !"-framework", metadata !"autolink_framework"} referenced from llvm.module.linkoptions, e.g., !llvm.module.linkoptions = !{!0, !1, !2, !3} This conceptually moves the logic for figuring out the syntax the linker will accept from LLVM into Clang. Moreover, it makes it easier to support MSVC's #pragma comment(linker, "some option") in the future, should anyone care to do so. llvm-svn: 172441
This commit is contained in:
@@ -173,8 +173,7 @@ void CodeGenModule::Release() {
|
||||
EmitCtorList(GlobalDtors, "llvm.global_dtors");
|
||||
EmitGlobalAnnotations();
|
||||
EmitLLVMUsed();
|
||||
EmitLinkLibraries();
|
||||
|
||||
|
||||
SimplifyPersonality();
|
||||
|
||||
if (getCodeGenOpts().EmitDeclMetadata)
|
||||
@@ -716,24 +715,6 @@ void CodeGenModule::EmitLLVMUsed() {
|
||||
GV->setSection("llvm.metadata");
|
||||
}
|
||||
|
||||
void CodeGenModule::EmitLinkLibraries() {
|
||||
// If there are no libraries to link against, do nothing.
|
||||
if (LinkLibraries.empty())
|
||||
return;
|
||||
|
||||
// Create metadata for each library we're linking against.
|
||||
llvm::NamedMDNode *Metadata
|
||||
= getModule().getOrInsertNamedMetadata("llvm.link.libraries");
|
||||
for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) {
|
||||
llvm::Value *Args[2] = {
|
||||
llvm::MDString::get(getLLVMContext(), LinkLibraries[I].Library),
|
||||
llvm::ConstantInt::get(llvm::Type::getInt1Ty(getLLVMContext()),
|
||||
LinkLibraries[I].IsFramework)
|
||||
};
|
||||
Metadata->addOperand(llvm::MDNode::get(getLLVMContext(), Args));
|
||||
}
|
||||
}
|
||||
|
||||
void CodeGenModule::EmitDeferred() {
|
||||
// Emit code for any potentially referenced deferred decls. Since a
|
||||
// previously unused static decl may become used during the generation of code
|
||||
@@ -2802,16 +2783,44 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
|
||||
Stack.push_back(Mod);
|
||||
}
|
||||
|
||||
if (Stack.empty())
|
||||
break;
|
||||
|
||||
// Get/create metadata for the link options.
|
||||
llvm::NamedMDNode *Metadata
|
||||
= getModule().getOrInsertNamedMetadata("llvm.module.linkoptions");
|
||||
|
||||
// Find all of the non-explicit submodules of the modules we've imported and
|
||||
// import them.
|
||||
while (!Stack.empty()) {
|
||||
clang::Module *Mod = Stack.back();
|
||||
Stack.pop_back();
|
||||
|
||||
// Add the link libraries for this module.
|
||||
LinkLibraries.insert(LinkLibraries.end(),
|
||||
Mod->LinkLibraries.begin(),
|
||||
Mod->LinkLibraries.end());
|
||||
// Add linker options to link against the libraries/frameworks
|
||||
// described by this module.
|
||||
for (unsigned I = 0, N = Mod->LinkLibraries.size(); I != N; ++I) {
|
||||
// FIXME: -lfoo is Unix-centric and -framework Foo is Darwin-centric.
|
||||
// We need to know more about the linker to know how to encode these
|
||||
// options propertly.
|
||||
|
||||
// Link against a framework.
|
||||
if (Mod->LinkLibraries[I].IsFramework) {
|
||||
llvm::Value *Args[2] = {
|
||||
llvm::MDString::get(getLLVMContext(), "-framework"),
|
||||
llvm::MDString::get(getLLVMContext(),
|
||||
Mod->LinkLibraries[I].Library)
|
||||
};
|
||||
|
||||
Metadata->addOperand(llvm::MDNode::get(getLLVMContext(), Args));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Link against a library.
|
||||
llvm::Value *OptString
|
||||
= llvm::MDString::get(getLLVMContext(),
|
||||
"-l" + Mod->LinkLibraries[I].Library);
|
||||
Metadata->addOperand(llvm::MDNode::get(getLLVMContext(), OptString));
|
||||
}
|
||||
|
||||
// We've imported this module; now import any of its children that haven't
|
||||
// already been imported.
|
||||
|
||||
Reference in New Issue
Block a user