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: go1.11 try to write something in GOROOT(/usr/lib/go) #27482

Closed
Sherlock-Holo opened this issue Sep 4, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@Sherlock-Holo
Copy link

commented Sep 4, 2018

Please answer these questions before submitting your issue. Thanks!

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

1.11

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sherlock/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/sherlock/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build522995885=/tmp/go-build -gno-record-gcc-switches"

What did you do?

write some codes for example:

package main

import (
	"fmt"
	"log"
	"net"
)

func main() {
	conn, err := net.Dial("tcp", "127.0.0.1:80")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(conn)
}

and then GO111MODULE=on go build -x -i -o /tmp/dns_test test.go

What did you expect to see?

final result is &{{0xc0000b4080}}

What did you see instead?

WORK=/tmp/go-build830644480
mkdir -p $WORK/b029/
mkdir -p /usr/lib/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/
cp /home/sherlock/.cache/go-build/89/89cdadc642daf0746cd75f328ee8f7236140d600069f196c3465f077b6538058-d /usr/lib/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/dnsmessage.a
rm -r $WORK/b029/
go build golang_org/x/net/dns/dnsmessage: open /usr/lib/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/dnsmessage.a: permission denied

@Sherlock-Holo

This comment has been minimized.

Copy link
Author

commented Sep 4, 2018

I set GOPATH=/tmp/go to reproduce it

write the same codes, if I run go build -x -i -o test test.go , work fine, but if run GO111MODULE=on go build -x -i -o test test.go, report same thing

WORK=/tmp/go-build324819374
mkdir -p $WORK/b029/
mkdir -p /usr/lib/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/
cp /home/sherlock/.cache/go-build/89/89cdadc642daf0746cd75f328ee8f7236140d600069f196c3465f077b6538058-d /usr/lib/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/dnsmessage.a
rm -r $WORK/b029/
go build golang_org/x/net/dns/dnsmessage: open /usr/lib/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/dnsmessage.a: permission denied

@Sherlock-Holo

This comment has been minimized.

Copy link
Author

commented Sep 4, 2018

I create go.mod in /tmp/go/src/test, codes is in /tmp/go/src/test

@LionNatsu

This comment has been minimized.

Copy link
Contributor

commented Sep 4, 2018

[lion@archlinux test]$ tree ~/test-go-mod
/home/lion/test-go-mod
└── src
    └── test
        ├── go.mod
        └── test.go

2 directories, 2 files
[lion@archlinux test]$ go env | grep GOPATH
GOPATH="/home/lion/test-go-mod"
[lion@archlinux test]$ go env | grep GOROOT
GOROOT="/usr/lib/go"
[lion@archlinux test]$ cat go.mod 
module test
[lion@archlinux test]$ cat test.go 
package test

import "net"

func init() {
        net.Dial("tcp", "127.0.0.1:80")
}
[lion@archlinux test]$ GO111MODULE=on go build -x -i test.go
WORK=/tmp/go-build620481900
mkdir -p $WORK/b028/
mkdir -p /usr/lib/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/
cp /home/lion/.cache/go-build/89/89cdadc642daf0746cd75f328ee8f7236140d600069f196c3465f077b6538058-d /usr/lib/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/dnsmessage.a
rm -r $WORK/b028/
go build golang_org/x/net/dns/dnsmessage: open /usr/lib/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/dnsmessage.a: permission denied
[lion@archlinux test]$ 
@LionNatsu

This comment has been minimized.

Copy link
Contributor

commented Sep 4, 2018

GO111MODULE=on works without -i

[lion@archlinux test]$ GO111MODULE=on go build -x test.go   
WORK=/tmp/go-build105322324
mkdir -p $WORK/b002/
cd /usr/lib/go/src/net
CGO_LDFLAGS='"-g" "-O2"' /usr/lib/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b002/ -importpath net -- -I $WORK/b002/ -g -O2 ./cgo_linux.go ./cgo_resnew.go ./cgo_socknew.go ./cgo_unix.go
cd $WORK
gcc -fno-caret-diagnostics -c -x c - || true
gcc -Qunused-arguments -c -x c - || true
gcc -fdebug-prefix-map=a=b -c -x c - || true
gcc -gno-record-gcc-switches -c -x c - || true
cd $WORK/b002
TERM='dumb' gcc -I /usr/lib/go/src/net -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b002=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x001.o -c _cgo_export.c
TERM='dumb' gcc -I /usr/lib/go/src/net -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b002=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x002.o -c cgo_linux.cgo2.c
TERM='dumb' gcc -I /usr/lib/go/src/net -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b002=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x003.o -c cgo_resnew.cgo2.c
TERM='dumb' gcc -I /usr/lib/go/src/net -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b002=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x004.o -c cgo_socknew.cgo2.c
TERM='dumb' gcc -I /usr/lib/go/src/net -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b002=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x005.o -c cgo_unix.cgo2.c
TERM='dumb' gcc -I /usr/lib/go/src/net -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b002=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_cgo_main.o -c _cgo_main.c
cd /usr/lib/go/src/net
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b002=/tmp/go-build -gno-record-gcc-switches -o $WORK/b002/_cgo_.o $WORK/b002/_cgo_main.o $WORK/b002/_x001.o $WORK/b002/_x002.o $WORK/b002/_x003.o $WORK/b002/_x004.o $WORK/b002/_x005.o -g -O2
TERM='dumb' /usr/lib/go/pkg/tool/linux_amd64/cgo -dynpackage net -dynimport $WORK/b002/_cgo_.o -dynout $WORK/b002/_cgo_import.go
cat >$WORK/b002/importcfg << 'EOF' # internal
# import config
packagefile context=/usr/lib/go/pkg/linux_amd64/context.a
packagefile errors=/usr/lib/go/pkg/linux_amd64/errors.a
packagefile golang_org/x/net/dns/dnsmessage=/home/lion/.cache/go-build/89/89cdadc642daf0746cd75f328ee8f7236140d600069f196c3465f077b6538058-d
packagefile internal/nettrace=/usr/lib/go/pkg/linux_amd64/internal/nettrace.a
packagefile internal/poll=/usr/lib/go/pkg/linux_amd64/internal/poll.a
packagefile internal/singleflight=/usr/lib/go/pkg/linux_amd64/internal/singleflight.a
packagefile io=/usr/lib/go/pkg/linux_amd64/io.a
packagefile math/rand=/usr/lib/go/pkg/linux_amd64/math/rand.a
packagefile os=/usr/lib/go/pkg/linux_amd64/os.a
packagefile runtime=/usr/lib/go/pkg/linux_amd64/runtime.a
packagefile sort=/usr/lib/go/pkg/linux_amd64/sort.a
packagefile sync=/usr/lib/go/pkg/linux_amd64/sync.a
packagefile sync/atomic=/usr/lib/go/pkg/linux_amd64/sync/atomic.a
packagefile syscall=/usr/lib/go/pkg/linux_amd64/syscall.a
packagefile time=/usr/lib/go/pkg/linux_amd64/time.a
packagefile runtime/cgo=/usr/lib/go/pkg/linux_amd64/runtime/cgo.a
EOF
/usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/b002/_pkg_.a -trimpath $WORK/b002 -p net -std -buildid Ucw9ErjS3YzK7TL2Q4qM/Ucw9ErjS3YzK7TL2Q4qM -goversion go1.11 -D "" -importcfg $WORK/b002/importcfg -pack -c=2 ./addrselect.go ./conf.go ./dial.go ./dnsclient.go ./dnsclient_unix.go ./dnsconfig_unix.go ./error_posix.go ./error_unix.go ./fd_unix.go ./file.go ./file_unix.go ./hook.go ./hook_unix.go ./hosts.go ./interface.go ./interface_linux.go ./ip.go ./iprawsock.go ./iprawsock_posix.go ./ipsock.go ./ipsock_posix.go ./lookup.go ./lookup_unix.go ./mac.go ./net.go ./nss.go ./parse.go ./pipe.go ./port.go ./port_unix.go ./rawconn.go ./sendfile_linux.go ./sock_cloexec.go ./sock_linux.go ./sock_posix.go ./sockaddr_posix.go ./sockopt_linux.go ./sockopt_posix.go ./sockoptip_linux.go ./sockoptip_posix.go ./splice_linux.go ./tcpsock.go ./tcpsock_posix.go ./tcpsockopt_posix.go ./tcpsockopt_unix.go ./udpsock.go ./udpsock_posix.go ./unixsock.go ./unixsock_posix.go ./writev_unix.go $WORK/b002/_cgo_gotypes.go $WORK/b002/cgo_linux.cgo1.go $WORK/b002/cgo_resnew.cgo1.go $WORK/b002/cgo_socknew.cgo1.go $WORK/b002/cgo_unix.cgo1.go $WORK/b002/_cgo_import.go
/usr/lib/go/pkg/tool/linux_amd64/pack r $WORK/b002/_pkg_.a $WORK/b002/_x001.o $WORK/b002/_x002.o $WORK/b002/_x003.o $WORK/b002/_x004.o $WORK/b002/_x005.o # internal
/usr/lib/go/pkg/tool/linux_amd64/buildid -w $WORK/b002/_pkg_.a # internal
cp $WORK/b002/_pkg_.a /home/lion/.cache/go-build/8c/8c392b9808c064f021086beb11cd15f0f41fee247f29a469ce351a4f05ba9263-d # internal
mkdir -p $WORK/b001/
cat >$WORK/b001/importcfg << 'EOF' # internal
# import config
packagefile net=$WORK/b002/_pkg_.a
EOF
cd /home/lion/test-go-mod/src/test
/usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/b001/_pkg_.a -trimpath $WORK/b001 -p command-line-arguments -complete -buildid Dt91mYP9DTkaBpD59l6s/Dt91mYP9DTkaBpD59l6s -goversion go1.11 -D _/home/lion/test-go-mod/src/test -importcfg $WORK/b001/importcfg -pack -c=2 ./test.go
/usr/lib/go/pkg/tool/linux_amd64/buildid -w $WORK/b001/_pkg_.a # internal
cp $WORK/b001/_pkg_.a /home/lion/.cache/go-build/5a/5a26dd5287a16175fa8aa343ebd42cd31bb2af5e8dda3910cc472b14e9db29ec-d # internal
[lion@archlinux test]$ 

@andybons andybons changed the title go1.11 try to write something in GOROOT(/usr/lib/go) cmd/go: go1.11 try to write something in GOROOT(/usr/lib/go) Sep 4, 2018

@andybons andybons added this to the Unplanned milestone Sep 4, 2018

@andybons

This comment has been minimized.

Copy link
Member

commented Sep 4, 2018

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Sep 5, 2018

Duplicate of #27285

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.