[llvm-dev] Obj doesn't link under MSVC

Reid Kleckner via llvm-dev llvm-dev at lists.llvm.org
Sun Nov 8 12:25:55 PST 2020


It sounds like LLVM isn't generating PIC code. Adding `llc
-relocation-model=static` makes it generate assembly that probably uses
this relocation:
https://godbolt.org/z/Kx5h6n

I think clang usually configures LLVM to generate PIC code for Win x64.

On Sat, Nov 7, 2020 at 8:07 PM Andrei Damian via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hello,
>
> I'm using LLVM (10.0.1) in a project I'm working on. Unfortunately, I've
> encountered a problem a few days ago I could not find a solution yet.
> I'm using LLVM in combination with the Microsoft's compiler and the
> platform I'm
> targeting is also MSVC x64.
>
> When linking a generated .obj file with code from another cpp into the
> dll, the
> linker complains as follows:
>
> ```
> s.obj : error LNK2017: 'ADDR32' relocation to '.rdata' invalid without
> /LARGEADDRESSAWARE:NO
> LINK : fatal error LNK1165: link failed because of fixup errors
> ```
> which is funny because as far as I can tell, that flag should have no
> effect on
> x64 anyway. If I add it to the linker command, it says it's ignored.
>
> I've noticed this happens when I use a global constant, eg. a string,
> but not
> always - for some inputs it triggers the error, for some it doesn't.
>
> The bat that links into exe looks like:
> ```
> @call set path=C:\Program Files (x86)\Microsoft Visual
> Studio\2019\Enterprise\VC\Auxiliary\Build;%path%
> call vcvarsall.bat x64
> cl /EHsc /DEBUG /Z7 /LD s.obj code.cpp
> ```
>
> and the IR: https://godbolt.org/z/dcrzoq
>
> Researching a bit I could find an issue on Rust's Github that seems to
> have been
> solved by time, and the statement `default rel` for an assembler to be
> inserted
> at the beginning of the ASM file, which I'm not sure how would be related.
>
> The only workaround I could find is to allocate the string on stack and set
> every element one by one, but it polutes the IR and it makes LLVM not to
> be able
> to optimize the thing into the readonly section, from what I noticed.
>
> I kindly request your help, thanks.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201108/32f49cff/attachment.html>


More information about the llvm-dev mailing list