<div dir="ltr">Hi Doug,<div><br></div><div>Should this include a negative case that checks that the module options aren't emitted if the module is unused?</div><div><br></div><div style> - Daniel</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Mon, Jan 14, 2013 at 10:28 AM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: dgregor<br>
Date: Mon Jan 14 12:28:43 2013<br>
New Revision: 172441<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=172441&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=172441&view=rev</a><br>
Log:<br>
Switch autolinking metadata format over to actual linker options, e.g.,<br>
<br>
!0 = metadata !{metadata !"-lautolink"}<br>
!1 = metadata !{metadata !"-framework", metadata !"autolink_framework"}<br>
<br>
referenced from llvm.module.linkoptions, e.g.,<br>
<br>
!llvm.module.linkoptions = !{!0, !1, !2, !3}<br>
<br>
This conceptually moves the logic for figuring out the syntax the<br>
linker will accept from LLVM into Clang. Moreover, it makes it easier<br>
to support MSVC's<br>
<br>
#pragma comment(linker, "some option")<br>
<br>
in the future, should anyone care to do so.<br>
<br>
<br>
Modified:<br>
cfe/trunk/lib/CodeGen/CodeGenModule.cpp<br>
cfe/trunk/lib/CodeGen/CodeGenModule.h<br>
cfe/trunk/test/Modules/autolink.m<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=172441&r1=172440&r2=172441&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=172441&r1=172440&r2=172441&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jan 14 12:28:43 2013<br>
@@ -173,8 +173,7 @@<br>
EmitCtorList(GlobalDtors, "llvm.global_dtors");<br>
EmitGlobalAnnotations();<br>
EmitLLVMUsed();<br>
- EmitLinkLibraries();<br>
-<br>
+<br>
SimplifyPersonality();<br>
<br>
if (getCodeGenOpts().EmitDeclMetadata)<br>
@@ -716,24 +715,6 @@<br>
GV->setSection("llvm.metadata");<br>
}<br>
<br>
-void CodeGenModule::EmitLinkLibraries() {<br>
- // If there are no libraries to link against, do nothing.<br>
- if (LinkLibraries.empty())<br>
- return;<br>
-<br>
- // Create metadata for each library we're linking against.<br>
- llvm::NamedMDNode *Metadata<br>
- = getModule().getOrInsertNamedMetadata("llvm.link.libraries");<br>
- for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) {<br>
- llvm::Value *Args[2] = {<br>
- llvm::MDString::get(getLLVMContext(), LinkLibraries[I].Library),<br>
- llvm::ConstantInt::get(llvm::Type::getInt1Ty(getLLVMContext()),<br>
- LinkLibraries[I].IsFramework)<br>
- };<br>
- Metadata->addOperand(llvm::MDNode::get(getLLVMContext(), Args));<br>
- }<br>
-}<br>
-<br>
void CodeGenModule::EmitDeferred() {<br>
// Emit code for any potentially referenced deferred decls. Since a<br>
// previously unused static decl may become used during the generation of code<br>
@@ -2802,16 +2783,44 @@<br>
Stack.push_back(Mod);<br>
}<br>
<br>
+ if (Stack.empty())<br>
+ break;<br>
+<br>
+ // Get/create metadata for the link options.<br>
+ llvm::NamedMDNode *Metadata<br>
+ = getModule().getOrInsertNamedMetadata("llvm.module.linkoptions");<br>
+<br>
// Find all of the non-explicit submodules of the modules we've imported and<br>
// import them.<br>
while (!Stack.empty()) {<br>
clang::Module *Mod = Stack.back();<br>
Stack.pop_back();<br>
<br>
- // Add the link libraries for this module.<br>
- LinkLibraries.insert(LinkLibraries.end(),<br>
- Mod->LinkLibraries.begin(),<br>
- Mod->LinkLibraries.end());<br>
+ // Add linker options to link against the libraries/frameworks<br>
+ // described by this module.<br>
+ for (unsigned I = 0, N = Mod->LinkLibraries.size(); I != N; ++I) {<br>
+ // FIXME: -lfoo is Unix-centric and -framework Foo is Darwin-centric.<br>
+ // We need to know more about the linker to know how to encode these<br>
+ // options propertly.<br>
+<br>
+ // Link against a framework.<br>
+ if (Mod->LinkLibraries[I].IsFramework) {<br>
+ llvm::Value *Args[2] = {<br>
+ llvm::MDString::get(getLLVMContext(), "-framework"),<br>
+ llvm::MDString::get(getLLVMContext(),<br>
+ Mod->LinkLibraries[I].Library)<br>
+ };<br>
+<br>
+ Metadata->addOperand(llvm::MDNode::get(getLLVMContext(), Args));<br>
+ continue;<br>
+ }<br>
+<br>
+ // Link against a library.<br>
+ llvm::Value *OptString<br>
+ = llvm::MDString::get(getLLVMContext(),<br>
+ "-l" + Mod->LinkLibraries[I].Library);<br>
+ Metadata->addOperand(llvm::MDNode::get(getLLVMContext(), OptString));<br>
+ }<br>
<br>
// We've imported this module; now import any of its children that haven't<br>
// already been imported.<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=172441&r1=172440&r2=172441&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=172441&r1=172440&r2=172441&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Jan 14 12:28:43 2013<br>
@@ -319,9 +319,6 @@<br>
/// \brief The complete set of modules that has been imported.<br>
llvm::SetVector<clang::Module *> ImportedModules;<br>
<br>
- /// \brief The set of libraries to link against.<br>
- std::vector<clang::Module::LinkLibrary> LinkLibraries;<br>
-<br>
/// @name Cache for Objective-C runtime types<br>
/// @{<br>
<br>
@@ -998,9 +995,6 @@<br>
/// references to global which may otherwise be optimized out.<br>
void EmitLLVMUsed();<br>
<br>
- /// \brief Emit the set of libraries to link against.<br>
- void EmitLinkLibraries();<br>
-<br>
void EmitDeclMetadata();<br>
<br>
/// EmitCoverageFile - Emit the llvm.gcov metadata used to tell LLVM where<br>
<br>
Modified: cfe/trunk/test/Modules/autolink.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/autolink.m?rev=172441&r1=172440&r2=172441&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/autolink.m?rev=172441&r1=172440&r2=172441&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/autolink.m (original)<br>
+++ cfe/trunk/test/Modules/autolink.m Mon Jan 14 12:28:43 2013<br>
@@ -23,8 +23,8 @@<br>
return no_umbrella_A;<br>
}<br>
<br>
-// CHECK: !llvm.link.libraries = !{![[AUTOLINK:[0-9]+]], ![[AUTOLINK_FRAMEWORK:[0-9]+]], ![[MODULE:[0-9]+]], ![[NOUMBRELLA:[0-9]+]]}<br>
-// CHECK: ![[AUTOLINK]] = metadata !{metadata !"autolink", i1 false}<br>
-// CHECK: ![[AUTOLINK_FRAMEWORK]] = metadata !{metadata !"autolink_framework", i1 true}<br>
-// CHECK: ![[MODULE]] = metadata !{metadata !"Module", i1 true}<br>
-// CHECK: ![[NOUMBRELLA]] = metadata !{metadata !"NoUmbrella", i1 true}<br>
+// CHECK: !llvm.module.linkoptions = !{![[AUTOLINK:[0-9]+]], ![[AUTOLINK_FRAMEWORK:[0-9]+]], ![[MODULE:[0-9]+]], ![[NOUMBRELLA:[0-9]+]]}<br>
+// CHECK: ![[AUTOLINK]] = metadata !{metadata !"-lautolink"}<br>
+// CHECK: ![[AUTOLINK_FRAMEWORK]] = metadata !{metadata !"-framework", metadata !"autolink_framework"}<br>
+// CHECK: ![[MODULE]] = metadata !{metadata !"-framework", metadata !"Module"}<br>
+// CHECK: ![[NOUMBRELLA]] = metadata !{metadata !"-framework", metadata !"NoUmbrella"}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>