Skip to content
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: LLVM's LLD does not create working Windows executables #44250

Closed
zx2c4 opened this issue Feb 13, 2021 · 7 comments
Closed

cmd/link: LLVM's LLD does not create working Windows executables #44250

zx2c4 opened this issue Feb 13, 2021 · 7 comments

Comments

@zx2c4
Copy link
Contributor

@zx2c4 zx2c4 commented Feb 13, 2021

I'm still uncertain whether we're missing a config option for LLD to get the behavior we want, or if this is a bug in LLD. I've filed this with LLVM: https://bugs.llvm.org/show_bug.cgi?id=49172

It looks like all of the go object is being merged into one readable/executable section, which then crashes on writes to data. I haven't figured out why yet.

Fixing this is an important step in getting cgo rolling with arm and arm64 on Windows, since there's no working binutils there.

Affects #38755, #36439, #43800.

CC @rsc @alexbrainman @cherrymui @mstorsjo

@thanm
Copy link
Member

@thanm thanm commented Feb 13, 2021

Related: #39326. For that bug, the musl.cc clang compilers are being used.

@zx2c4
Copy link
Contributor Author

@zx2c4 zx2c4 commented Feb 13, 2021

Musl.cc uses gcc/binutils, not clang, and doesn't support arm or arm64 consequently.

@thanm
Copy link
Member

@thanm thanm commented Feb 13, 2021

Whoops, yes, you are right. Same symptom however (use of lld results in non-working executable).

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 13, 2021

Change https://golang.org/cl/291630 mentions this issue: cmd/link: set SizeOfRawData filed in COFF files for .bss section

@zx2c4
Copy link
Contributor Author

@zx2c4 zx2c4 commented Feb 14, 2021

I've got a working fix now -- https://golang.org/cl/291630 . This should clear the way for doing cgo on windows/arm{64}.

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 14, 2021

Change https://golang.org/cl/291632 mentions this issue: cmd/link: do not pass -Bsymbolic for PE DLLs

@dmitshur dmitshur added this to the Backlog milestone Feb 14, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 14, 2021

Change https://golang.org/cl/291633 mentions this issue: cmd/link: set .ctors COFF section to writable and aligned to 8 bytes

@gopherbot gopherbot closed this in a51daac Feb 23, 2021
gopherbot pushed a commit that referenced this issue Feb 23, 2021
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 <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
gopherbot pushed a commit that referenced this issue Feb 23, 2021
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 <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants