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/go: build fails when setting linker to lld using ldflags #27110

Closed
pcc opened this issue Aug 21, 2018 · 6 comments
Closed

cmd/go: build fails when setting linker to lld using ldflags #27110

pcc opened this issue Aug 21, 2018 · 6 comments

Comments

@pcc
Copy link
Contributor

pcc commented Aug 21, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +0b30cf534a Mon Aug 20 23:12:45 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOOS="linux"

What did you do?

$ cat foo.c
void foo() {}
$ cat foo.h
void foo();
$ cat foo.go
package main

/*
#include "foo.h"
*/
import "C"

func main() {
	C.foo()
}
$ CC=clang CGO_LDFLAGS=-fuse-ld=lld go build 

What did you expect to see?

Build succeeds

What did you see instead?

# cgotest
[...]/link: running clang failed: exit status 1
clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
ld.lld: error: unknown --compress-debug-sections value: zlib-gnu
ld.lld: error: --compress-debug-sections: zlib is not available
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The link command tries to detect whether the -Wl,--compress-debug-sections=zlib-gnu flag is supported here:

if ctxt.compressDWARF && linkerFlagSupported(argv[0], compressDWARF) {

but does so incorrectly (it doesn't use the provided ldflags, and therefore checks whether the flag is supported by /usr/bin/ld instead of whichever linker the user selected). LLD doesn't currently support -Wl,--compress-debug-sections=zlib-gnu, so we get this error.

@gopherbot
Copy link

Change https://golang.org/cl/130316 mentions this issue: cmd/link: pass provided ldflags when testing whether an ldflag is supported

@rayvbr
Copy link

rayvbr commented Aug 27, 2018

Just ran into a (possibly) related issue when using Go 1.11 to build a --buildmode=c-shared target for android/arm:

/usr/local/go/pkg/tool/linux_amd64/link: running /home/root/android-ndk-linux/android-ndk-r14/toolchains/llvm/prebuilt/linux-x86_64/bin/clang failed: exit status 1
/home/root/android-ndk-linux/android-ndk-r14/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: fatal error: --compress-debug-sections=zlib-gnu: must take one of the following arguments: none, zlib

Is 6417e91 slated to be included in a future Go 1.11.1 release?

@ianlancetaylor
Copy link
Contributor

@gopherbot please backport to 1.11

@gopherbot
Copy link

Backport issue(s) opened: #27293 (for 1.11).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@gopherbot
Copy link

Change https://golang.org/cl/134057 mentions this issue: cmd/link: don't pass all linker args when testing flag

gopherbot pushed a commit that referenced this issue Sep 11, 2018
Some linker flags can actually be input files, which can cause
misleading errors when doing the trial link, which can cause the
linker to incorrectly decide that the flag is not supported, which can
cause the link to fail.

Fixes #27510
Updates #27110
Updates #27293

Change-Id: I70c1e913cee3c813e7b267bf779bcff26d4d194a
Reviewed-on: https://go-review.googlesource.com/134057
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Damien Neil <dneil@google.com>
@qzmfranklin
Copy link

This issue is still out with golang 1.11.2, as described by kubernetes/kubernetes#71996.

The problem is that the clang lld linker (as of 7.0.0) does not support --compress-debug-sections=zlib-gnu (see this PR).

@golang golang locked and limited conversation to collaborators Dec 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants