[cfe-commits] r172441 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/Modules/autolink.m
Douglas Gregor
dgregor at apple.com
Wed Jan 16 17:59:03 PST 2013
On Jan 16, 2013, at 5:10 PM, Daniel Dunbar <daniel at zuster.org> wrote:
> Hi Doug,
>
> Should this include a negative case that checks that the module options aren't emitted if the module is unused?
There already is one (autolink_sub); I've added a comment in r172695.
- Doug
> - Daniel
>
>
> On Mon, Jan 14, 2013 at 10:28 AM, Douglas Gregor <dgregor at apple.com> wrote:
> Author: dgregor
> Date: Mon Jan 14 12:28:43 2013
> New Revision: 172441
>
> URL: http://llvm.org/viewvc/llvm-project?rev=172441&view=rev
> Log:
> 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.
>
>
> Modified:
> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> cfe/trunk/lib/CodeGen/CodeGenModule.h
> cfe/trunk/test/Modules/autolink.m
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=172441&r1=172440&r2=172441&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jan 14 12:28:43 2013
> @@ -173,8 +173,7 @@
> EmitCtorList(GlobalDtors, "llvm.global_dtors");
> EmitGlobalAnnotations();
> EmitLLVMUsed();
> - EmitLinkLibraries();
> -
> +
> SimplifyPersonality();
>
> if (getCodeGenOpts().EmitDeclMetadata)
> @@ -716,24 +715,6 @@
> 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 @@
> 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.
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=172441&r1=172440&r2=172441&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Jan 14 12:28:43 2013
> @@ -319,9 +319,6 @@
> /// \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 @@
> /// 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
>
> Modified: cfe/trunk/test/Modules/autolink.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/autolink.m?rev=172441&r1=172440&r2=172441&view=diff
> ==============================================================================
> --- cfe/trunk/test/Modules/autolink.m (original)
> +++ cfe/trunk/test/Modules/autolink.m Mon Jan 14 12:28:43 2013
> @@ -23,8 +23,8 @@
> 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"}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130116/7d36e49c/attachment.html>
More information about the cfe-commits
mailing list