<div dir="ltr">Hi Gao,<div><br></div><div>Thanks for the extra information...</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 16, 2013 at 1:14 PM, Yunzhong Gao <span dir="ltr"><<a href="mailto:Yunzhong.Gao@am.sony.com" target="_blank">Yunzhong.Gao@am.sony.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Daniel,<br>
<br>
Nice to meet you.<br>
<br>
My understanding of the Microsoft #pragma comment(lib, ...) semantics is that<br>
each specified library will be converted into a directive that starts with<br>
"/DEFAULTLIB" in the COFF .drectve section. To demonstrate, the following patch<br>
produces directives that work with Visual Studio 2010 using the now-deprecated<br>
dependent library feature (commits r168779 and r168694).<br></blockquote><div><br></div><div style>Is that feature now-deprecated? The documentation here:</div><div style>  <a href="http://msdn.microsoft.com/en-us/library/7f0aews7.aspx">http://msdn.microsoft.com/en-us/library/7f0aews7.aspx</a></div>
<div style>only talks about the "exestr" comment type being deprecated.</div><div style><br></div><div style>I see that the /defaultlib flag itself to the linker is deprecated, but it isn't clear to me that that means the dependent library feature is also deprecated.</div>
<div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
/* beginning of patch */<br>
<br>
Index: /home/ygao/LLVM/llvm/lib/Target/X86/X86AsmPrinter.cpp<br>
===================================================================<br>
--- /home/ygao/LLVM/llvm/lib/Target/X86/X86AsmPrinter.cpp       (revision 165914)<br>
+++ /home/ygao/LLVM/llvm/lib/Target/X86/X86AsmPrinter.cpp       (working copy)<br>
@@ -641,6 +641,19 @@<br>
     const TargetLoweringObjectFileCOFF &TLOFCOFF =<br>
       static_cast<const TargetLoweringObjectFileCOFF&>(getObjFileLowering());<br>
<br>
+    // Output linker support code for #pragma comment(lib, ...) on Windows<br>
+    if (M.lib_size() > 0 && Subtarget->isTargetWindows()) {<br>
+      OutStreamer.SwitchSection(TLOFCOFF.getDrectveSection());<br>
+      SmallString<128> name;<br>
+      for (Module::lib_iterator I = M.lib_begin(), E = M.lib_end();<br>
+           I != E; ++I) {<br>
+        name = " /DEFAULTLIB:\"";<br>
+        name += *I;<br>
+        name += "\"";<br>
+        OutStreamer.EmitBytes(name, 0);<br>
+      }<br>
+    }<br>
+<br>
     for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)<br>
       if (I->hasDLLExportLinkage())<br>
         DLLExportedFns.push_back(Mang->getSymbol(I));<br>
<br>
/* end of patch */<br>
<br>
I am currently looking for advice on what is the correct approach to<br>
re-implement #pragma comment(lib, ...) with Clang/LLVM.<br>
<br>
A mingw linker (at least the one that I played with) just ignores this directive<br>
with no warnings or errors.<br>
<br>
One can either add another module flag for "Named Libraries" in addition to<br>
"Linker Options", which might be easier to implement. Or one can provide a<br>
target-specific hook to the frontend, which converts #pragma comment(lib,<br>
"blah.lib") to something like this:<br></blockquote><div><br></div><div style>I would vote that we have a target hook that lets us emit the code into the "Linker Options" metadata, which would also be our handling of #pragma comment(linker, ...)</div>
<div style> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
!0 = medata !{ i32 6, "Linker Options",<br>
  metadata !{<br>
    !metadata { metadata !"/DEFAULTLIB:blah.lib" }<br>
  }<br>
}<br>
!llvm.module.flags = !{ !0 }<br>
<br>
Your example is maybe more complicated where you need to convert libz to "-lz".<br>
<br>
Regarding the ordering information of the libraries, I think for MSVC the<br>
libraries are supposed to follow lexical order in the same source file. I am not<br>
sure if there is any restriction across different source files. Here is a link<br>
to the MSDN doc:<br>
<a href="http://msdn.microsoft.com/en-us/library/7f0aews7%28v=vs.80%29.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/7f0aews7%28v=vs.80%29.aspx</a></blockquote><div><br></div><div style>See previous reply to Michael Spencer, but yes, we will preserve order.</div>
<div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
It is probably not too hard to add a directive section to ELF similar to COFF.<br>
<br>
At the 2012 LLVM Dev Meeting, there was a presentation on adding Modules to C,<br>
which presented a way to use ObjC-style .map files to specify libraries, which<br>
may be relevant to this auto-linking feature.<br></blockquote><div><br></div><div style>Yes, the motivation for adding the feature is to support modules (actually, current trunk sources are already emitting some kind of metadata to this effect, although it needs to be updated).</div>
<div style><br></div><div style> - Daniel</div><div style> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<br>
I look forward to more discussions,<br>
<br>
- Gao.<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div></div>