-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/link: using lld linker fails on Windows #39326
Comments
I took a look at the most resource source code for LLD; The "-T" or "--script" option is supported only for ELF targets. With that said, the reason that we introduced the use of the linker script in the first place was to work around a bug in ld.bfd (https://sourceware.org/bugzilla/show_bug.cgi?id=21459), so one would expect that we would not need the same workaround for lld. The main issue then becomes figuring out which linker is being used when doing external linking on windows, which should be doable. I will see about sending a CL. |
Interesting. Now looking at the script we're using:
Note the final line -- this refers to the ".debug_types" section, which as far as I know is not even generated by most compilers (clang doesn't emit it as far as I know, and gcc emits it only if you specifically as for it with a command line option). Maybe we don't need the linker script after all? |
It will insert the fragment after where That said, I do in fact see this in the default COFF/PE linker script:
The |
Thanks @ianlancetaylor , that makes sense. A lot of our gomotes still seem to be running older versions of binutils, so I can definitely still see the problem if remove the workaround. |
Change https://golang.org/cl/278932 mentions this issue: |
I've sent a CL that should take care of the primary issue. @Keithcat1 if you are able to build Go from source, perhaps you can try it out once the CL goes in. It would also be helpful to know exactly which version of lld you are testing against. Verifying the CL turned out to be a bit more work than I had thought; the C compilers on our gomotes are pretty old (do not support -fuse-ld=lld). I tested using a toolchain from https://musl.cc/x86_64-w64-mingw32-native.zip, in combination with a copy of LLD extracted from https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/LLVM-11.0.0-win64.exe. |
At the time when I posted this issue, I was using LLD 10.0 and GCC 9 or GCC 10 as well. I was using MSYS64 to get GCC and LLD. |
Thanks @Keithcat1 . Do you want me to hold the bug open, or can it be closed once the change is in? |
I haven't been able to verify yet that this works. Thanks for helping with this though. |
When doing external linking on Windows, auto-detect the linker flavor (bfd vs gold vs lld) and when linking with "lld", avoid the use of "-T" (linker script), since this option is not supported by lld. [Note: the Go linker currently employs -T to ensure proper placement of the .debug_gdb_scripts section, to work around issues in older versions of binutils; LLD recognizes this section and does place it properly]. Updates #39326. Change-Id: I3ea79cdceef2316bf86eccdb60188ac3655264ed Reviewed-on: https://go-review.googlesource.com/c/go/+/278932 Trust: Than McIntosh <[email protected]> Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jeremy Faller <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
I can't get it to work. |
Hmm. That is puzzling. Perhaps the auto-detection scheme that I put in is not working? On the system where you are seeing the failure, what output do you see when you run the command
Thanks. |
The -T argument is properly removed when I do: |
I see something similar on my windows machine. I diff'd the section header dumps for the two binaries (ld.lld and ld.bfd) and there are a lot of differences-- hard to know exactly what the problem might be. asm64.s:123 doesn't sound like it is in the Go runtime (at least I can't find a file named asm64.s anywhere in the sources, except as testdata). |
@thanm Is there something here that needs to be done for Go 1.16 release, or should this issue be moved to a different milestone? |
I'll move it to the next milestone -- there is still work to do here, but it won't happen for 1.16. |
Change https://golang.org/cl/291630 mentions this issue: |
Change https://golang.org/cl/291630 mentions this issue: |
Change https://golang.org/cl/291632 mentions this issue: |
Change https://golang.org/cl/291633 mentions this issue: |
Change https://golang.org/cl/291633 mentions this issue: |
This is only a valid option on ELF. Binutils accepts it, but LLVM rejects it, so for Windows, it's best to just omit it. Updates #44250. Updates #39326. Updates #38755. Updates #36439. Updates #43800. Change-Id: Iffd2345d757f23dd737e63bd464cd412527077c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/291632 Trust: Jason A. Donenfeld <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
Without setting these flags, LLVM's LLD ignores the .ctors section when merging objects. Updates #44250. Updates #39326. Updates #38755. Updates #36439. Updates #43800. Change-Id: I8766104508f7acd832088a590ee7d68afa0d6065 Reviewed-on: https://go-review.googlesource.com/c/go/+/291633 Trust: Jason A. Donenfeld <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
Debug info seems to be broken when trying to debug executables created by LLVM Mingw. |
after the following commands:
set CGO_LDFLAGS=-fuse-ld=lld
go build
I get this error:
command-line-arguments
C:\go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
lld: error: unknown argument: -T
collect2.exe: error: ld returned 1 exit status
The argument which is causing this is :
-Wl,-T,C:\Users\Keith\AppData\Local\Temp\go-link-100899651\fix_debug_gdb_scripts.ld
I found a way to remove this one argument, but the resulting executable crashes when I start it.
The text was updated successfully, but these errors were encountered: