[llvm-bugs] [Bug 38939] New: LLD for MinGW generating false undefined references and segmentation fault binaries
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Sep 13 10:40:26 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38939
Bug ID: 38939
Summary: LLD for MinGW generating false undefined references
and segmentation fault binaries
Product: lld
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: COFF
Assignee: unassignedbugs at nondot.org
Reporter: notengobattery at gmail.com
CC: llvm-bugs at lists.llvm.org
First of all, I've doing some work in order to bring a fully functional, self
hosted LLVM distro to MinGW. I've made some great advancements (for example,
getting rid of 'undefined reference to typeinfo/vtable') and I built a 1st
stage LLVM/Clang from *Trunk* (or master if using the git mirror) and a 2nd
stage LLVM/Clang that uses the libc++, libc++abi and libunwind from stage 1.
Both stages are working correctly and passing the test-suite tests, both when
using the MinGW's libstdc++ and the just-built libcxx+libcxxabi+libunwind.
AFAIK most features are working, from exceptions to sanitizers, so I'm in a
good road.
As I cannot and won't upload binaries, you have to trust my pastebins.
- In this pastebin you can see the DLL dependencies of a self-hosted LLVM
distro on MinGW using GNU BFD linker
https://pastebin.com/iUFngMfw
However, when using the just-build LLD to build a simple .exe it fails. It also
fails when building the final stage llvm-tblgen.exe
- In this pastebin you can see the Clang log for building a simple a.exe in 4
combinations: lld-libc++, lld-libstdc++, bfd-libc++ and bfd-libstdc++
https://pastebin.com/vuYRkBwG
If I use LLD and the /force option, a binary is created but it segfaults
- In this pastebin you can see the Clang log for building a simple a.exe with
/force flag that segfaults
https://pastebin.com/LBgSam9f
P.D. Sorry for using pastebin
-- Extra details
1. As long as you use libc++ instead of libstdc++ to build lld, it won't
segfault or deadlock. Using libstdc++ to build ld.lld will deadlock. I'm not
sure but this may be related https://bugs.llvm.org/show_bug.cgi?id=36785
2. I've tracked the problem to a specific function. In particular this one
https://github.com/llvm-mirror/lld/blob/72803c47f6c7d5ebbcccf44651403654fa60b903/COFF/SymbolTable.cpp#L154
This is important because as far as I understand, LLD will mark some symbols
that had an entry in the import library (i.e. dll.a) with the prefix __imp_ but
not the corresponding export without the __imp_ as "Lazy". These "Lazy" symbols
are MinGW automatic imports.
The mentioned function will convert this Symbol to a DefinedImportData which
contains a reference to the DLL (i.e. the dll, not the dll.a), so the symbol
will not be undefined if it's present in the DLL and LLD will link and
reference the relative address in the DLL (i.e. not the dll.a).
As long as I tested, this dynamic cast always fails, so LLD cannot resolve
the MinGW automatic import and generates a false positive for the undefined
symbol. And, of course, if you use /force, these symbols will point to
0x00000000, and that is the cause of the segfault.
If I examine the generated .exe (the one linked with bfd) using Dependency
Walker, the symbol is successfully imported, referenced and used. LLD produces
a bad binary even when /force is used.
https://pastebin.com/GDEESVmi
--
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/20180913/400739ac/attachment-0001.html>
More information about the llvm-bugs
mailing list