-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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: Arbitrary linking failures with go1.15 #43820
Comments
Does the filesystem at your /dev/shm support fallocate syscall correctly? Does it fail if you try a different place for the temporary output file?
The linker deletes temporary files at exit (success or not). You can use |
/dev/shm is a tmpfs filesystem and the kernel version is 3.17. It seems like most fallocate features were introduced before then. |
An ELF object file. You should be able to open it with tools like objdump, readelf, or nm. |
Linkmode was set to auto (I assume it defaulted to internal since there was no output), so I changed linkmode to external and .o files were written to tmpdir. The output of objdump -d go.o was the same for a failing and a successful build. However the error message from ld still refers to a directory in /dev/shm. This got me wondering why ld is being invoked in the first place if linkmode is internal? Doesn't the go linker handle all linking? |
The linkmode defaults to auto, which means internal linking for pure-Go programs, external linking for cgo programs. You can use
Is there any difference whether the tmpdir is in /dev/shm? |
The error message looks the same no matter if I specify a tmpdir or not or which linkmode I use. The file path that the error message refers to is always a temp directory in /dev/shm. When I set a tmpdir, the only difference between when I specify linkmode as external it generates some .o files in the tmpdir, but not for auto or internal. |
I'm very confused with this. |
I am struggling to generate output suitable to post here. The failure only triggers with two or more pkg/... paths and -x makes the output quite verbose as quite a few packages are involved. Interestingly the failure did not happen for more than a thousand runs when the paths ./subpackage/... ./pkg2/cmd/program were passed, but did happen for ./subpackage/... ./pkg2/cmd/program/... the second time it ran. |
It is okay to post a large output, maybe as an attachment, if you like. If you prefer not to do that, only |
After adding -v to the ldflags some panics show up in the output: unexpected fault address 0x7f17ef7b5d32 goroutine 82 [running]: goroutine 1 [semacquire]: goroutine 81 [runnable]: |
I'm really confused here. The panic comes after the invocation of ld? Invoking ld is the last step so that shouldn't be possible. Can you paste the full exact output of linker's -v output? That should include how ld (through gcc) is invoked. |
Apologies, we would prefer that the information we post is as generic as possible. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
This happens with go1.15.7, but not on go1.14 or tip.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Ran go install folder/... folder2/... from a Makefile in a newly cleaned environment. This is a large private repo. Importantly this does not happen on the subsequent build if the cache is not cleared.
What did you expect to see?
Successfull build
What did you see instead?
/home/username/devel/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/dev/shm/go-link-811975522/go.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
More details
The file (and its containing directory for that matter) that the error message refers to does not exist in the filesystem after the build fails.
This only seems to happen in a newly cleaned build environment, i.e. a clean go cache. It doesn't happen every time make is run and the failing package differs each time.
Git bisect points to a possible cause:
commit d40b0a1
Author: Steven Hartland steven.hartland@multiplay.co.uk
Date: Fri May 8 12:09:00 2020 +0000
It stopps happening at:
commit 987ce93
Author: Cherry Zhang cherryyz@google.com
Date: Fri Jun 26 16:35:49 2020 -0400
The text was updated successfully, but these errors were encountered: