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: "read-only file system" with -linkshared even when files are present #47186

Closed
diamondburned opened this issue Jul 14, 2021 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@diamondburned
Copy link

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

―❤―▶ go version
go version go1.17rc1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
―❤―▶ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/diamond/.go/bin"
GOCACHE="/home/diamond/.cache/go-build"
GOENV="/home/diamond/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/diamond/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/diamond/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/nix/store/psicgpf5q9glanl10fcrgd04dfmrpmd5-go-1.17beta1/share/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/nix/store/psicgpf5q9glanl10fcrgd04dfmrpmd5-go-1.17beta1/share/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17rc1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/shared-test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build36914121=/tmp/go-build -gno-record-gcc-switches"

What did you do?

First, Go was built using the regular steps that NixOS has, except after the build process, the command go install -buildmode=shared -linkshared std waws ran. This created a bunch of files:

―❤―▶ cat /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/archive/zip.shlibname
libstd.so
―❤―▶ cat /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/bytes.shlibname 
libstd.so
...
Output for tail /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/*.shlibname
―❤―▶ tail /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/*.shlibname 
==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/bufio.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/bytes.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/context.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/crypto.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/embed.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/encoding.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/errors.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/expvar.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/flag.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/fmt.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/hash.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/html.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/image.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/io.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/log.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/math.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/mime.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/net.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/os.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/path.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/plugin.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/reflect.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/regexp.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/runtime.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/sort.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/strconv.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/strings.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/sync.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/syscall.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/testing.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/time.shlibname <==
libstd.so

==> /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/unicode.shlibname <==
libstd.so

Then, a Hello World package was built using that Go:

―❤―▶ cat main.go 
package main

import "fmt"

func main() {
	fmt.Println("bruh")
}

The command to build was go install -linkshared ..

What did you expect to see?

The build should've succeeded, and upon running, should've printed bruh. When ldd is used on the binary, there should've been an entry for libstd.so.

What did you see instead?

Lots of errors about a read-only file system, even though the files are already present:

open /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/archive/zip.shlibname: read-only file system
open /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/bytes.shlibname: read-only file system
open /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/compress/bzip2.shlibname: read-only file system
open /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/compress/flate.shlibname: read-only file system
open /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/compress/gzip.shlibname: read-only file system
open /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/compress/lzw.shlibname: read-only file system
open /nix/store/7mjiq33kdk70mgfffb699gdg4hp1bna8-go-1.17beta1/share/go/pkg/linux_amd64_dynlink/bufio.shlibname: read-only file system
...

The problem here is that, even when these files are already created, Go still tries to open them. probably with a read-write or write flag, and since NixOS stores GOROOT in a read-only file system, this causes Go to fail.

@jayconrod jayconrod added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 14, 2021
@jayconrod jayconrod added this to the Unplanned milestone Jul 14, 2021
@bcmills
Copy link
Contributor

bcmills commented Jul 15, 2021

Unfortunately, -buildmode=shared -linkshared is indeed badly broken: it assumes that GOROOT/pkg is always writable, when for many users it is not. I think -linkshared and -buildmode=shared need a fairly fundamental redesign in light of the existence of the build cache today.

(We do make an attempt to test with a read-only GOROOT (#30316), but unfortunately we don't have good builder coverage for non-root users (#10719), so making GOROOT read-only doesn't actually help much today.)

@bcmills
Copy link
Contributor

bcmills commented Jul 15, 2021

Duplicate of #28553

@bcmills bcmills marked this as a duplicate of #28553 Jul 15, 2021
@bcmills bcmills closed this as completed Jul 15, 2021
@golang golang locked and limited conversation to collaborators Jul 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants