llvm / llvm/llvm-project

lld-link produces binary that behaves differntly from MSVC

Open
#193,627 2 comments 0 reactions 0 assignees View on GitHub
lld:COFF
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

fa.c

```c
#include
__declspec(dllexport) void print()
{
printf("A\n");
}
```

fb.c

```c
#include
__declspec(dllexport) void print()
{
printf("B\n");
}
```

a.c

```c
__declspec(dllimport) void print(); // print from fb.dll
void call_a()
{
print();
}
```

b.c

```c
void print(); // print from fb.dll
void call_b()
{
call_a();
print();
}
```

main.c
```c
void call_b();
int main()
{
call_b();
}
```

Build:
```
cl /LD fa.c /link /DLL
cl /LD fb.c /link /DLL
cl /c a.c b.c main.c
lib fa.lib a.obj /out:a.lib
lib fb.lib b.obj /out:b.lib

rem if you link this part with lld-link it prints out 'A' but MSVC prints 'B'
link main.obj a.lib b.lib
```

LLD 22.1.4 (built on https://github.com/llvm/llvm-project/commit/35990504507d79e0b9deb809c8ee5e1b34ceef20)

Contributor guide

Open the contributing guide

Research direction

Reproduce the case using fa.c, fb.c, a.c, b.c, and main.c with the shown lib and link commands. Compare lld-link's output with MSVC's expected output, then trace the linker behavior involved in resolving the imported and archive symbols. Done means the lld-link-linked program matches MSVC and prints B.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.