[llvm-bugs] [Bug 27436] New: lld-link writes import .lib files with the wrong byte order in the second header

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 20 08:51:08 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27436

            Bug ID: 27436
           Summary: lld-link writes import .lib files with the wrong byte
                    order in the second header
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: nicolasweber at gmx.de
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

To learn more about the .lib format, I wrote a simple dumper
(https://github.com/nico/hack/blob/master/libdump.c). 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 files
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).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160420/d02d9989/attachment.html>


More information about the llvm-bugs mailing list