[LLVMdev] RFC: auto-linking IR proposal

Daniel Dunbar daniel at zuster.org
Wed Jan 16 15:08:31 PST 2013


Hi Gao,

Thanks for the extra information...


On Wed, Jan 16, 2013 at 1:14 PM, Yunzhong Gao <Yunzhong.Gao at am.sony.com>wrote:

> Hi Daniel,
>
> Nice to meet you.
>
> My understanding of the Microsoft #pragma comment(lib, ...) semantics is
> that
> each specified library will be converted into a directive that starts with
> "/DEFAULTLIB" in the COFF .drectve section. To demonstrate, the following
> patch
> produces directives that work with Visual Studio 2010 using the
> now-deprecated
> dependent library feature (commits r168779 and r168694).
>

Is that feature now-deprecated? The documentation here:
  http://msdn.microsoft.com/en-us/library/7f0aews7.aspx
only talks about the "exestr" comment type being deprecated.

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.

/* beginning of patch */
>
> Index: /home/ygao/LLVM/llvm/lib/Target/X86/X86AsmPrinter.cpp
> ===================================================================
> --- /home/ygao/LLVM/llvm/lib/Target/X86/X86AsmPrinter.cpp       (revision
> 165914)
> +++ /home/ygao/LLVM/llvm/lib/Target/X86/X86AsmPrinter.cpp       (working
> copy)
> @@ -641,6 +641,19 @@
>      const TargetLoweringObjectFileCOFF &TLOFCOFF =
>        static_cast<const
> TargetLoweringObjectFileCOFF&>(getObjFileLowering());
>
> +    // Output linker support code for #pragma comment(lib, ...) on Windows
> +    if (M.lib_size() > 0 && Subtarget->isTargetWindows()) {
> +      OutStreamer.SwitchSection(TLOFCOFF.getDrectveSection());
> +      SmallString<128> name;
> +      for (Module::lib_iterator I = M.lib_begin(), E = M.lib_end();
> +           I != E; ++I) {
> +        name = " /DEFAULTLIB:\"";
> +        name += *I;
> +        name += "\"";
> +        OutStreamer.EmitBytes(name, 0);
> +      }
> +    }
> +
>      for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
>        if (I->hasDLLExportLinkage())
>          DLLExportedFns.push_back(Mang->getSymbol(I));
>
> /* end of patch */
>
> I am currently looking for advice on what is the correct approach to
> re-implement #pragma comment(lib, ...) with Clang/LLVM.
>
> A mingw linker (at least the one that I played with) just ignores this
> directive
> with no warnings or errors.
>
> One can either add another module flag for "Named Libraries" in addition to
> "Linker Options", which might be easier to implement. Or one can provide a
> target-specific hook to the frontend, which converts #pragma comment(lib,
> "blah.lib") to something like this:
>

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, ...)


>
> !0 = medata !{ i32 6, "Linker Options",
>   metadata !{
>     !metadata { metadata !"/DEFAULTLIB:blah.lib" }
>   }
> }
> !llvm.module.flags = !{ !0 }
>
> Your example is maybe more complicated where you need to convert libz to
> "-lz".
>
> Regarding the ordering information of the libraries, I think for MSVC the
> libraries are supposed to follow lexical order in the same source file. I
> am not
> sure if there is any restriction across different source files. Here is a
> link
> to the MSDN doc:
> http://msdn.microsoft.com/en-us/library/7f0aews7%28v=vs.80%29.aspx


See previous reply to Michael Spencer, but yes, we will preserve order.


> It is probably not too hard to add a directive section to ELF similar to
> COFF.
>
> At the 2012 LLVM Dev Meeting, there was a presentation on adding Modules
> to C,
> which presented a way to use ObjC-style .map files to specify libraries,
> which
> may be relevant to this auto-linking feature.
>

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).

 - Daniel


>
> I look forward to more discussions,
>
> - Gao.
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130116/0047134b/attachment.html>


More information about the llvm-dev mailing list