Issue 238905
Summary arm64ec: lld-link.exe v23.1.4 incorrectly resolves _setjmp from an x64 obj to arm64ec #__intrinsic_setjmp entry during mixed x64/arm64ec linking
Labels new issue
Assignees
Reporter cdwang
    With lld-link v23.1.4, the x64 caller's _setjmp reference resolves to the native ARM64EC #__intrinsic_setjmp entry.  

With Microsoft link.exe in msvc v14.51, the same _setjmp reference correctly resolves to the x64-compatible __intrinsic_setjmp import thunk. 

Using the same two object files and the same CRT/SDK library search paths, the executable linked by LLD crashes with 0xC000026F, while the executable linked by Microsoft link.exe exits successfully. In both cases, the ARM64EC main object was compiled with Clang.

Repro
The use of x64 cl.exe below is intentional. The first object must contain x64 code.
Open a command prompt with:
%comspec% /k "C:\Program Files\Microsoft Visual Studio\18\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" arm64_x64
Compile x64_setjmp_probe.c as x64 with MSVC  v14.51 compiler:

"C:\Program Files\Microsoft Visual Studio\18\Enterprise\VC\Tools\MSVC\14.51.36231\bin\HostARM64\x64\cl.exe" /nologo /c /O2 /MD /Z7 x64_setjmp_probe.c /Fox64_setjmp_probe.obj

x64_setjmp_probe.c

#include <setjmp.h>
int x64_setjmp_probe(void)
{
jmp_buf state;
return setjmp(state);
}
MSVC's x64  <setjmp.h> expands the source-level setjmp into a call that references _setjmp. This probe saves the context and returns normally. 

Compile ec_probe_main.c as ARM64EC with Clang:

c:\llvm\bin\clang-cl.exe --target=arm64ec-pc-windows-msvc -fms-compatibility-version=19.51 /nologo /c /O2 /MD /Z7 ec_probe_main.c /Foec_probe_main.obj


ec_probe_main.c

int x64_setjmp_probe(void);
int main(void)
{
return x64_setjmp_probe();
}
Next, open another command prompt with:

%comspec% /k "C:\Program Files\Microsoft Visual Studio\18\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" arm64

Link the same two objects with LLD:

c:\llvm\bin\lld-link.exe /nologo /machine:arm64ec /debug /pdb:probe-lld.pdb /map:probe-lld.map /out:probe-lld.exe ec_probe_main.obj x64_setjmp_probe.obj

Then link them with Microsoft link.exe

"C:\Program Files\Microsoft Visual Studio\18\Enterprise\VC\Tools\MSVC\14.51.36231\bin\HostARM64\arm64\link.exe" /nologo /machine:arm64ec /debug /pdb:probe-mslink.pdb /map:probe-mslink.map /out:probe-mslink.exe ec_probe_main.obj x64_setjmp_probe.obj 
Compare _setjmp resolution in the linker maps

The critical difference is:
Linker LLD 23.1.4:
_setjmp == #__intrinsic_setjmp, the native ARM64EC entry
Microsoft link.exe:
_setjmp == __intrinsic_setjmp, the x64-compatible entry

For reference, the original map files contain:
LLD:

_setjmp 0000000140006094
#__intrinsic_setjmp 0000000140006094
#_setjmp 0000000140006094
__intrinsic_setjmp  0000000140008110
x64_setjmp_probe 0000000140008000
Here, _setjmp and #__intrinsic_setjmp resolve to the same address:

_setjmp == #__intrinsic_setjmp == 0000000140006094
Microsoft link.exe:


#__intrinsic_setjmp 0000000140006be4
#_setjmp            0000000140006be4
__intrinsic_setjmp 000000014000905c
_setjmp             000000014000905c
x64_setjmp_probe 0000000140009000

#__intrinsic_setjmp 0000000140006be4
#_setjmp 0000000140006be4
Here, _setjmp instead resolves to the x64-compatible __intrinsic_setjmp entry:

_setjmp == __intrinsic_setjmp == 000000014000905c

In short, the same x64 _setjmp reference is bound to different entry points by the two linkers. LLD binds it to the native ARM64EC entry, whereas Microsoft link.exe binds it to the x64-compatible entry. The LLD-linked executable subsequently fails with 0xC000026F; the Microsoft-linked executable runs successfully.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to