<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/132411>132411</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lld-link] LLD-LINK produces broken forward imports in source DEF
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lhmouse
</td>
</tr>
</table>
<pre>
First let's define an empty DLL that exports `CreateThread`, forwarded from Windows KERNEL32.DLL:
```c
// test.c
int
__stdcall
_DllMainCRTStartup(void* i, unsigned long r, void* p)
{ return 1; }
```
```plaintext
EXPORTS
CreateThread = kernel32.CreateThread
```
Now build two DLLs, one with Microsoft LINK (good.dll) and one with LLD (bad.dll):
```plaintext
clang test.c -Wl,-DEF:test.def -shared -Wl,-nodefaultlib -Wl,kernel32.lib -o good.dll
clang test.c -Wl,-DEF:test.def -shared -Wl,-nodefaultlib -Wl,kernel32.lib -fuse-ld=lld -o bad.dll
```
The bad DLL will cause failure when it's loaded by another application, saying **\_kernel32.dll** is not found. Now let's open the good DLL with a hex editor:

And this is the bad DLL. The import from `_kernel32.CreateThread` is exactly the issue.

This bug exists only when targeting x86-32.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VN9uqzgTfxrnZgQyNgRywUVaGuno5PT71FPp7F1l8ADeOjayTZO8_cokabvb1V7tSpYCnjDz-zMzwns1GMSaFHekaFZiDqN1tR4Pdva4aq081zvlfACNgbDSg8ReGQRhAA9TOEOz30MYRQA8TdYFD2RN7x2KgM-jQyHJmhJ2D711R-EkSuidPcAvZaQ9evj-8PT4sOcsbfZ7wreELmdNL6eLL2xH2A4C-pDGd2UCoduXFx9kJ7SOz43WP4Qy90_PP4NwYZ4Iq96skoRtQcXis1lYStDWDODi1S0-EbaJVco7cBhmZyAj_A5I2XwG8hdckxbKBDxFJA-__f9_T88_Cd0CfOYNhDfwis6g5iz9kyJfEj_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