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

Andrei Damian via llvm-dev llvm-dev at lists.llvm.org
Sat Nov 7 20:07:15 PST 2020


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.


More information about the llvm-dev mailing list