<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Feb 13, 2017 at 12:33 PM, Martell Malone <span dir="ltr"><<a href="mailto:martellmalone@gmail.com" target="_blank">martellmalone@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hey Rui, </div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">I wonder how llvm-dlltool would fit in the entire picture of mingw support. I don't think dlltool is the last missing piece. What do you need to do other than that to fully support mingw using LLVM toolchain?</span></blockquote></span><div>Other then changing `lib/MC/WinCOFFStreamer.cpp` to not use -aligncomm within the EmitCommonSymbol function and a single patch for mingw-w64 itself to pre-populate it's .ctors and .dtors list, so llvm-dlltool is infact the only missing part really.<br></div></div></blockquote><div><br></div><div>Also you need to make a change to LLD/COFF to accept GNU command arguments, right? (Looks like you already have that patch locally.)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>This gives us a fully working clang based mingw-w64 C compiler.<br><br>C++ and exception handling is a different story.<br><br>libc++ is somewhat working with the following test results<br><br><div>Expected Passes    : 2188</div><div>Expected Failures  : 44</div><div>Unsupported Tests  : 588</div><div>Unexpected Failures: 2816</div><br>I was able to build it with exceptions disabled and I actually managed to bootstrap llvm and clang itself.<br>It didn't run very well though as you can imagine based on the above tests.<span class=""><br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">It's not a performance issue but a code maintenance issue. The initial patches to support mingw was trying to add a new linker driver and a different linkin semantics to the COFF linker which seemed too complicated to me. IIRC, I suggested adding a shim which translates GNU command line arguments to MSVC linker arguments. Didn't it work?</span></blockquote></span>There were just so many differences between link and ld I never followed down that path. I pushed forward with the short import library support based on your later suggestions. My patch to hack lld into accepting some very basic gnu front end arguments was enough to get all the above working which was enough to develop further.<br><br>Best,<br>Martell </div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 13, 2017 at 8:08 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Hi Martell,</div><div class="gmail_quote"><br></div><div class="gmail_quote">I wonder how llvm-dlltool would fit in the entire picture of mingw support. I don't think dlltool is the last missing piece. What do you need to do other than that to fully support mingw using LLVM toolchain?</div><div class="gmail_quote"><br></div><div class="gmail_quote"><span>On Mon, Feb 13, 2017 at 8:56 AM, Martell Malone via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey llvm'ers,<br><br>I have been working on a dlltool replacement for llvm.<br>Here is my initial differential <a href="https://reviews.llvm.org/D29892" target="_blank">https://reviews.llvm.org/D2989<wbr>2</a><br>It is based on some functionality that already exists in lld.<br>I added functionality to support, <span style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px">PE COFF Weak Externals </span>and of course a front end to actually use it.<br>I believe the work here can also be used for llvm-lib and lessen the load on lld.<br>I would like some comments about how this could be be structured to live in llvm with a shared code base across lib ar and dlltool.<br>I also have a section below called "Difference from lib" which is somewhat of a rationale for the tool.<br><br>Many Thanks,<br>Martell<br><br><br>Context<br><span style="font-family:sans-serif">==========<br></span><br>Awhile back I talked to various llvm'ers about getting mingw-w64 support for lld.<br>There were a few issues raised but the main issue was that mingw-w64 should try best to comply with the PECOFF spec, adding support for custom sections and various binutils/mingw hacks would impact the performance of the COFF linker and in general is not something that lld should support.<br></div></blockquote><div><br></div></span><div>It's not a performance issue but a code maintenance issue. The initial patches to support mingw was trying to add a new linker driver and a different linkin semantics to the COFF linker which seemed too complicated to me. IIRC, I suggested adding a shim which translates GNU command line arguments to MSVC linker arguments. Didn't it work?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_2856333141893705091h5"><div dir="ltr"><br>Motivation<br><span style="font-family:sans-serif">==========<br></span><br>The main motivation was because dlltool and ld did not comply with PECOFF Spec.<br>It has some custom formatting and uses the assembler for some reason to generate import libraries, it did not use the short import library format at all.<br><br>There has been many work arounds for the problem this creates such as the creation of the `reimp` tool. Which imports MSVC built libs creates a def and uses dlltool so that the binutils linker can use it.<br><br>We should just be using the short import format and the linker should support that.<br>Thus llvm-dlltool was born.<br><br><br>Difference from lib<br>===================<br><br>Using <span style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px">PE COFF spec (section 8, Import Library Format) should be self explanatory.<br>lib.exe is able to accept def files and create libraries using this format.<br><br>example<br> <br>  `LIBRARY "user32.dll"<br>   EXPORTS<br>   MessageBoxA`<br></span><br>LIB.exe can create a user32.lib with the function MessageBoxA from the above definition.<br><br>Mingw-w64 is different MSVC in that we need to compile the runtime.<br>MS provide us with their crt prebuilt so lib.exe doesn't have support for external function aliasing.<span style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px"><br>We often use aliases for posix naming reasons as well as avoid using the MS version of a function.<br><br>example<br><br></span><span style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px">  `LIBRARY "user32.dll"</span><br style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px">   EXPORTS</span><br style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px">   MessageBoxA<br></span><span style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px">   MessageBoxW==MessageBoxA`<br></span><br>LIB.exe doesn't not have support for this but dlltool does.<br>The best fit for this within the spec is <span style="color:rgb(0,0,0);font-family:"segoe ui","segoe ui web regular","segoe ui symbol",lato,"helvetica neue",helvetica,arial,sans-serif;font-size:13px">PE COFF spec (Aux Format 3: Weak Externals)<br></span><br>Mingw-w64 also uses lib prefix and .a file extensions for the library name so the driver should be different. The above example would be libuser32.a, for when shared and static versions of the same library exist there is the .dll.a variant.<br><br><br>Issues<br>=======<br><br>Like more of the gnu suite dlltool was not designed in one build multi target manner.<br>We would have to introduce custom arguments to specify the target, "i686", "x86_64", "thumb2pe" etc.<br>This will most likely break some level of backwards compatibility with the binutils version.<br><br></div>
<br></div></div>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>