diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-01-14 18:28:43 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-01-14 18:28:43 +0000 |
commit | 5d75ea72d6eee3df0c6acdb282145dc4cc3a9a1b (patch) | |
tree | 240ca7fd2df2161f0fa7a1aafbead9e108a6e331 | |
parent | 8767dc29ec23f96e71658f760333bdf5d87283d5 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172441 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 57 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.h | 6 | ||||
-rw-r--r-- | test/Modules/autolink.m | 10 |
3 files changed, 38 insertions, 35 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index da37e4982d..c43528866b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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. diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 0d644a748e..4088caca50 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -319,9 +319,6 @@ class CodeGenModule : public CodeGenTypeCache { /// \brief The complete set of modules that has been imported. llvm::SetVector<clang::Module *> ImportedModules; - /// \brief The set of libraries to link against. - std::vector<clang::Module::LinkLibrary> LinkLibraries; - /// @name Cache for Objective-C runtime types /// @{ @@ -998,9 +995,6 @@ private: /// references to global which may otherwise be optimized out. void EmitLLVMUsed(); - /// \brief Emit the set of libraries to link against. - void EmitLinkLibraries(); - void EmitDeclMetadata(); /// EmitCoverageFile - Emit the llvm.gcov metadata used to tell LLVM where diff --git a/test/Modules/autolink.m b/test/Modules/autolink.m index 3c6998f7bf..836d910914 100644 --- a/test/Modules/autolink.m +++ b/test/Modules/autolink.m @@ -23,8 +23,8 @@ int use_no_umbrella() { return no_umbrella_A; } -// CHECK: !llvm.link.libraries = !{![[AUTOLINK:[0-9]+]], ![[AUTOLINK_FRAMEWORK:[0-9]+]], ![[MODULE:[0-9]+]], ![[NOUMBRELLA:[0-9]+]]} -// CHECK: ![[AUTOLINK]] = metadata !{metadata !"autolink", i1 false} -// CHECK: ![[AUTOLINK_FRAMEWORK]] = metadata !{metadata !"autolink_framework", i1 true} -// CHECK: ![[MODULE]] = metadata !{metadata !"Module", i1 true} -// CHECK: ![[NOUMBRELLA]] = metadata !{metadata !"NoUmbrella", i1 true} +// CHECK: !llvm.module.linkoptions = !{![[AUTOLINK:[0-9]+]], ![[AUTOLINK_FRAMEWORK:[0-9]+]], ![[MODULE:[0-9]+]], ![[NOUMBRELLA:[0-9]+]]} +// CHECK: ![[AUTOLINK]] = metadata !{metadata !"-lautolink"} +// CHECK: ![[AUTOLINK_FRAMEWORK]] = metadata !{metadata !"-framework", metadata !"autolink_framework"} +// CHECK: ![[MODULE]] = metadata !{metadata !"-framework", metadata !"Module"} +// CHECK: ![[NOUMBRELLA]] = metadata !{metadata !"-framework", metadata !"NoUmbrella"} |