<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - lld-link writes import .lib files with the wrong byte order in the second header"
href="https://llvm.org/bugs/show_bug.cgi?id=27437">27437</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>lld-link writes import .lib files with the wrong byte order in the second header
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>nicolasweber@gmx.de
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>To learn more about the .lib format, I wrote a simple dumper
(<a href="https://github.com/nico/hack/blob/master/libdump.c">https://github.com/nico/hack/blob/master/libdump.c</a>). While doing this, I
noticed that the .lib files written by lld-link always write big-ending
numbers.
The PE spec section 7 explicitly says that the entries in the first linker
member should be big-endian. It is silent about endianness for the second
linker member, but the .lib files written by link.exe have little-endian fields
there.
Now, link.exe can use the .lib files produces by lld-link:
C:\src\llvm-build-new>type test.cc
__declspec(dllexport) void f() {}
C:\src\llvm-build-new>type main.cc
__declspec(dllimport) void f();
int main() { f(); };
C:\src\llvm-build-new>cl /c test.cc
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
test.cc
C:\src\llvm-build-new>cl /c main.cc
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
main.cc
C:\src\llvm-build-new>bin\lld-link /dll test.obj
Creating library test.lib and object test.exp
C:\src\llvm-build-new>link main.obj test.lib
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation. All rights reserved.
I guess this works because link.exe falls back to the first linker member if it
can't decode the second linker member? One way to test this theory would be to
create a large import lib and see if using the dll is faster when the import
library for it is created by link or lld-link (since using the second linker
member should make linking a bit faster, since it has a sorted symbol list --
but maybe the difference is too small to measure).</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>