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 -ldflags="-s -w" invalid #25046

Closed
gooid opened this issue Apr 24, 2018 · 12 comments
Closed

cmd/go: build -ldflags="-s -w" invalid #25046

gooid opened this issue Apr 24, 2018 · 12 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@gooid
Copy link

gooid commented Apr 24, 2018

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

go version go1.10.1 windows/amd64

Does this issue reproduce with the latest release?

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=d:\GoLang\go.ext
set GORACE=
set GOROOT=d:\GoLang\go1.10.1
set GOTMPDIR=
set GOTOOLDIR=d:\GoLang\go1.10.1\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=B:\TEMP\go-build911831290=/tmp/go-build -gno-record-gcc-switches

What did you do?

go source path: D:\GoLang\go.ext\src\github.com\gooid\demo\main.go

package main

import (
	"fmt"
)

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

cmd:

d:\GoLang\go.ext\src\github.com\gooid\demo>set GOPATH=d:\GoLang\go.ext

d:\GoLang\go.ext\src\github.com\gooid\demo>go build -ldflags="-s -w"

d:\GoLang\go.ext\src\github.com\gooid\demo>dir demo.exe
...
2018/04/24  10:05         1,259,520 demo.exe
...

d:\GoLang\go.ext\src\github.com\gooid\demo>set GOPATH=D:\GoLang\go.ext

d:\GoLang\go.ext\src\github.com\gooid\demo>go build -ldflags="-s -w"

d:\GoLang\go.ext\src\github.com\gooid\demo>dir demo.exe
...
2018/04/24  10:05         2,051,584 demo.exe
...

d:\GoLang\go.ext\src\github.com\gooid\demo>set GOPATH=d:\golang\go.ext

d:\GoLang\go.ext\src\github.com\gooid\demo>go build -ldflags="-s -w"

d:\GoLang\go.ext\src\github.com\gooid\demo>dir demo.exe
...
2018/04/24  10:06         2,051,584 demo.exe
...

What did you expect to see?

The size of all demo.exe is 1,259,520

What did you see instead?

Different GOPATH (but effective in Window), The size of all demo.exe is different, -ldflags="-s -w" invalid。

@davecheney
Copy link
Contributor

davecheney commented Apr 24, 2018 via email

@gooid
Copy link
Author

gooid commented Apr 24, 2018

d:\GoLang\go.ext\src\github.com\gooid\demo>set GOPATH=d:\GoLang\go.ext
d:\GoLang\go.ext\src\github.com\gooid\demo>go build -x -ldflags="-s -w"
WORK=B:\TEMP\go-build785960802
mkdir -p $WORK\b001\
cat >$WORK\b001\importcfg.link << 'EOF' # internal
packagefile github.com/gooid/demo=C:\Users\liukaizan\AppData\Local\go-build\47\4733598739e08c94536bddb42f3ea21d2560aaa915e6956fc187d7984cc30c98-d
packagefile fmt=d:\GoLang\go1.10.1\pkg\windows_amd64\fmt.a
packagefile runtime=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime.a
packagefile errors=d:\GoLang\go1.10.1\pkg\windows_amd64\errors.a
packagefile io=d:\GoLang\go1.10.1\pkg\windows_amd64\io.a
packagefile math=d:\GoLang\go1.10.1\pkg\windows_amd64\math.a
packagefile os=d:\GoLang\go1.10.1\pkg\windows_amd64\os.a
packagefile reflect=d:\GoLang\go1.10.1\pkg\windows_amd64\reflect.a
packagefile strconv=d:\GoLang\go1.10.1\pkg\windows_amd64\strconv.a
packagefile sync=d:\GoLang\go1.10.1\pkg\windows_amd64\sync.a
packagefile unicode/utf8=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf8.a
packagefile runtime/internal/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\atomic.a
packagefile runtime/internal/sys=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\sys.a
packagefile sync/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\sync\atomic.a
packagefile internal/cpu=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\cpu.a
packagefile internal/poll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\poll.a
packagefile internal/syscall/windows=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows.a
packagefile internal/testlog=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\testlog.a
packagefile syscall=d:\GoLang\go1.10.1\pkg\windows_amd64\syscall.a
packagefile time=d:\GoLang\go1.10.1\pkg\windows_amd64\time.a
packagefile unicode/utf16=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf16.a
packagefile unicode=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode.a
packagefile internal/race=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\race.a
packagefile internal/syscall/windows/sysdll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\sysdll.a
packagefile internal/syscall/windows/registry=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\registry.a
EOF
mkdir -p $WORK\b001\exe\
cd .
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\link.exe" -o "B:\\TEMP\\go-build785960802\\b001\\exe\\a.out.exe" -importcfg "B:\\TEMP\\go-build785960802\\b001\\importcfg.link" -buildmode=exe -buildid=L1EghNmYHPcFlIdgYz6G/yPzdyeFwEV_BsjwB48UU/H1bKbtQyW5GIYnlynryD/L1EghNmYHPcFlIdgYz6G -s -w -extld=gcc "C:\\Users\\liukaizan\\AppData\\Local\\go-build\\47\\4733598739e08c94536bddb42f3ea21d2560aaa915e6956fc187d7984cc30c98-d"
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\buildid.exe" -w "B:\\TEMP\\go-build785960802\\b001\\exe\\a.out.exe" # internal
cp $WORK\b001\exe\a.out.exe demo.exe
rm -r $WORK\b001\ 

d:\GoLang\go.ext\src\github.com\gooid\demo>del demo.exe
d:\GoLang\go.ext\src\github.com\gooid\demo>set GOPATH=d:\golang\go.ext
d:\GoLang\go.ext\src\github.com\gooid\demo>go build -x -ldflags="-s -w"
WORK=B:\TEMP\go-build109047758
mkdir -p $WORK\b001\
cat >$WORK\b001\importcfg << 'EOF' # internal
# import config
packagefile fmt=d:\GoLang\go1.10.1\pkg\windows_amd64\fmt.a
packagefile runtime=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime.a
EOF
cd d:\golang\go.ext\src\github.com\gooid\demo
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\compile.exe" -o "B:\\TEMP\\go-build109047758\\b001\\_pkg_.a" -trimpath "B:\\TEMP\\go-build109047758\\b001" -p main -complete -buildid qg_0bj3bXd7YdjORSd5z/qg_0bj3bXd7YdjORSd5z -goversion go1.10.1 -D "" -importcfg "B:\\TEMP\\go-build109047758\\b001\\importcfg" -pack -c=4 "d:\\golang\\go.ext\\src\\github.com\\gooid\\demo\\main.go"
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\buildid.exe" -w "B:\\TEMP\\go-build109047758\\b001\\_pkg_.a" # internal
cp "B:\\TEMP\\go-build109047758\\b001\\_pkg_.a" "C:\\Users\\liukaizan\\AppData\\Local\\go-build\\1a\\1ad9f3359e4cdb3920b3af8f43bc60045a6085159aa06563b27ca154fe5938cf-d" # internal
cat >$WORK\b001\importcfg.link << 'EOF' # internal
packagefile github.com/gooid/demo=$WORK\b001\_pkg_.a
packagefile fmt=d:\GoLang\go1.10.1\pkg\windows_amd64\fmt.a
packagefile runtime=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime.a
packagefile errors=d:\GoLang\go1.10.1\pkg\windows_amd64\errors.a
packagefile io=d:\GoLang\go1.10.1\pkg\windows_amd64\io.a
packagefile math=d:\GoLang\go1.10.1\pkg\windows_amd64\math.a
packagefile os=d:\GoLang\go1.10.1\pkg\windows_amd64\os.a
packagefile reflect=d:\GoLang\go1.10.1\pkg\windows_amd64\reflect.a
packagefile strconv=d:\GoLang\go1.10.1\pkg\windows_amd64\strconv.a
packagefile sync=d:\GoLang\go1.10.1\pkg\windows_amd64\sync.a
packagefile unicode/utf8=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf8.a
packagefile runtime/internal/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\atomic.a
packagefile runtime/internal/sys=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\sys.a
packagefile sync/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\sync\atomic.a
packagefile internal/cpu=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\cpu.a
packagefile internal/poll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\poll.a
packagefile internal/syscall/windows=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows.a
packagefile internal/testlog=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\testlog.a
packagefile syscall=d:\GoLang\go1.10.1\pkg\windows_amd64\syscall.a
packagefile time=d:\GoLang\go1.10.1\pkg\windows_amd64\time.a
packagefile unicode/utf16=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf16.a
packagefile unicode=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode.a
packagefile internal/race=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\race.a
packagefile internal/syscall/windows/sysdll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\sysdll.a
packagefile internal/syscall/windows/registry=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\registry.a
EOF
mkdir -p $WORK\b001\exe\
cd .
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\link.exe" -o "B:\\TEMP\\go-build109047758\\b001\\exe\\a.out.exe" -importcfg "B:\\TEMP\\go-build109047758\\b001\\importcfg.link" -buildmode=exe -buildid=vFlAC6JQmS8x59lELmg8/qg_0bj3bXd7YdjORSd5z/m1v7ZVfaEClTlxcNo9dI/vFlAC6JQmS8x59lELmg8 -extld=gcc "B:\\TEMP\\go-build109047758\\b001\\_pkg_.a"
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\buildid.exe" -w "B:\\TEMP\\go-build109047758\\b001\\exe\\a.out.exe" # internal
cp $WORK\b001\exe\a.out.exe demo.exe
rm -r $WORK\b001\ 

@davecheney
Copy link
Contributor

Can you also do the dir check to confirm that the size is different between the first and second invocation.

@gooid
Copy link
Author

gooid commented Apr 24, 2018


d:\GoLang\go.ext\src\github.com\gooid\demo>set GOPATH=d:\GoLang\go.ext

d:\GoLang\go.ext\src\github.com\gooid\demo>go build -x -ldflags="-s -w"
WORK=B:\TEMP\go-build416612238
mkdir -p $WORK\b001\
cat >$WORK\b001\importcfg.link << 'EOF' # internal
packagefile github.com/gooid/demo=C:\Users\liukaizan\AppData\Local\go-build\47\4733598739e08c94536bddb42f3ea21d2560aaa91
5e6956fc187d7984cc30c98-d
packagefile fmt=d:\GoLang\go1.10.1\pkg\windows_amd64\fmt.a
packagefile runtime=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime.a
packagefile errors=d:\GoLang\go1.10.1\pkg\windows_amd64\errors.a
packagefile io=d:\GoLang\go1.10.1\pkg\windows_amd64\io.a
packagefile math=d:\GoLang\go1.10.1\pkg\windows_amd64\math.a
packagefile os=d:\GoLang\go1.10.1\pkg\windows_amd64\os.a
packagefile reflect=d:\GoLang\go1.10.1\pkg\windows_amd64\reflect.a
packagefile strconv=d:\GoLang\go1.10.1\pkg\windows_amd64\strconv.a
packagefile sync=d:\GoLang\go1.10.1\pkg\windows_amd64\sync.a
packagefile unicode/utf8=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf8.a
packagefile runtime/internal/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\atomic.a
packagefile runtime/internal/sys=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\sys.a
packagefile sync/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\sync\atomic.a
packagefile internal/cpu=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\cpu.a
packagefile internal/poll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\poll.a
packagefile internal/syscall/windows=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows.a
packagefile internal/testlog=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\testlog.a
packagefile syscall=d:\GoLang\go1.10.1\pkg\windows_amd64\syscall.a
packagefile time=d:\GoLang\go1.10.1\pkg\windows_amd64\time.a
packagefile unicode/utf16=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf16.a
packagefile unicode=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode.a
packagefile internal/race=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\race.a
packagefile internal/syscall/windows/sysdll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\sysdll.a
packagefile internal/syscall/windows/registry=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\registry.a
EOF
mkdir -p $WORK\b001\exe\
cd .
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\link.exe" -o "B:\\TEMP\\go-build416612238\\b001\\exe\\a.out.exe" -impor
tcfg "B:\\TEMP\\go-build416612238\\b001\\importcfg.link" -buildmode=exe -buildid=L1EghNmYHPcFlIdgYz6G/yPzdyeFwEV_BsjwB48
UU/H1bKbtQyW5GIYnlynryD/L1EghNmYHPcFlIdgYz6G -s -w -extld=gcc "C:\\Users\\liukaizan\\AppData\\Local\\go-build\\47\\47335
98739e08c94536bddb42f3ea21d2560aaa915e6956fc187d7984cc30c98-d"
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\buildid.exe" -w "B:\\TEMP\\go-build416612238\\b001\\exe\\a.out.exe" # i
nternal
cp $WORK\b001\exe\a.out.exe demo.exe
rm -r $WORK\b001\

d:\GoLang\go.ext\src\github.com\gooid\demo>dir demo.exe
 驱动器 D 中的卷是 work
 卷的序列号是 0001-FC75

 d:\GoLang\go.ext\src\github.com\gooid\demo 的目录

2018/04/24  11:04         1,259,520 demo.exe
               1 个文件      1,259,520 字节
               0 个目录  6,755,278,848 可用字节

d:\GoLang\go.ext\src\github.com\gooid\demo>del demo.exe

d:\GoLang\go.ext\src\github.com\gooid\demo>set GOPATH=d:\golang\go.ext

d:\GoLang\go.ext\src\github.com\gooid\demo>go build -x -ldflags="-s -w"
WORK=B:\TEMP\go-build032957018
mkdir -p $WORK\b001\
cat >$WORK\b001\importcfg.link << 'EOF' # internal
packagefile github.com/gooid/demo=C:\Users\liukaizan\AppData\Local\go-build\1a\1ad9f3359e4cdb3920b3af8f43bc60045a6085159
aa06563b27ca154fe5938cf-d
packagefile fmt=d:\GoLang\go1.10.1\pkg\windows_amd64\fmt.a
packagefile runtime=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime.a
packagefile errors=d:\GoLang\go1.10.1\pkg\windows_amd64\errors.a
packagefile io=d:\GoLang\go1.10.1\pkg\windows_amd64\io.a
packagefile math=d:\GoLang\go1.10.1\pkg\windows_amd64\math.a
packagefile os=d:\GoLang\go1.10.1\pkg\windows_amd64\os.a
packagefile reflect=d:\GoLang\go1.10.1\pkg\windows_amd64\reflect.a
packagefile strconv=d:\GoLang\go1.10.1\pkg\windows_amd64\strconv.a
packagefile sync=d:\GoLang\go1.10.1\pkg\windows_amd64\sync.a
packagefile unicode/utf8=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf8.a
packagefile runtime/internal/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\atomic.a
packagefile runtime/internal/sys=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\sys.a
packagefile sync/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\sync\atomic.a
packagefile internal/cpu=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\cpu.a
packagefile internal/poll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\poll.a
packagefile internal/syscall/windows=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows.a
packagefile internal/testlog=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\testlog.a
packagefile syscall=d:\GoLang\go1.10.1\pkg\windows_amd64\syscall.a
packagefile time=d:\GoLang\go1.10.1\pkg\windows_amd64\time.a
packagefile unicode/utf16=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf16.a
packagefile unicode=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode.a
packagefile internal/race=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\race.a
packagefile internal/syscall/windows/sysdll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\sysdll.a
packagefile internal/syscall/windows/registry=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\registry.a
EOF
mkdir -p $WORK\b001\exe\
cd .
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\link.exe" -o "B:\\TEMP\\go-build032957018\\b001\\exe\\a.out.exe" -impor
tcfg "B:\\TEMP\\go-build032957018\\b001\\importcfg.link" -buildmode=exe -buildid=vFlAC6JQmS8x59lELmg8/qg_0bj3bXd7YdjORSd
5z/m1v7ZVfaEClTlxcNo9dI/vFlAC6JQmS8x59lELmg8 -extld=gcc "C:\\Users\\liukaizan\\AppData\\Local\\go-build\\1a\\1ad9f3359e4
cdb3920b3af8f43bc60045a6085159aa06563b27ca154fe5938cf-d"
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\buildid.exe" -w "B:\\TEMP\\go-build032957018\\b001\\exe\\a.out.exe" # i
nternal
cp $WORK\b001\exe\a.out.exe demo.exe
rm -r $WORK\b001\

d:\GoLang\go.ext\src\github.com\gooid\demo>dir demo.exe
 驱动器 D 中的卷是 work
 卷的序列号是 0001-FC75

 d:\GoLang\go.ext\src\github.com\gooid\demo 的目录

2018/04/24  11:05         2,051,584 demo.exe
               1 个文件      2,051,584 字节
               0 个目录  6,754,488,320 可用字节

@davecheney
Copy link
Contributor

I the first invocation -s -w is being passed to link.exe

"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\link.exe" -o "B:\\TEMP\\go-build416612238\\b001\\exe\\a.out.exe" -importcfg "B:\\TEMP\\go-build416612238\\b001\\importcfg.link" -buildmode=exe -buildid=L1EghNmYHPcFlIdgYz6G/yPzdyeFwEV_BsjwB48UU/H1bKbtQyW5GIYnlynryD/L1EghNmYHPcFlIdgYz6G -s -w -extld=gcc "C:\\Users\\liukaizan\\AppData\\Local\\go-build\\47\\4733598739e08c94536bddb42f3ea21d2560aaa915e6956fc187d7984cc30c98-d"

In the second it is missing

"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\link.exe" -o "B:\\TEMP\\go-build032957018\\b001\\exe\\a.out.exe" -importcfg "B:\\TEMP\\go-build032957018\\b001\\importcfg.link" -buildmode=exe -buildid=vFlAC6JQmS8x59lELmg8/qg_0bj3bXd7YdjORSd5z/m1v7ZVfaEClTlxcNo9dI/vFlAC6JQmS8x59lELmg8 -extld=gcc "C:\\Users\\liukaizan\\AppData\\Local\\go-build\\1a\\1ad9f3359e4cdb3920b3af8f43bc60045a6085159aa06563b27ca154fe5938cf-d"

/cc @rsc

@davecheney davecheney added this to the Go1.11 milestone Apr 24, 2018
@ianlancetaylor
Copy link
Contributor

Does it work if you run go build -ldflags=all="-s -w"?

@gooid
Copy link
Author

gooid commented Apr 24, 2018

Does it work if you run go build -ldflags=all="-s -w"?
d:\GoLang\go.ext\src\github.com\gooid\demo>go build -x -ldflags=all="-s -w"
WORK=B:\TEMP\go-build374060654
mkdir -p $WORK\b001\
cat >$WORK\b001\importcfg.link << 'EOF' # internal
packagefile github.com/gooid/demo=C:\Users\liukaizan\AppData\Local\go-build\1a\1ad9f3359e4cdb3920b3af8f43bc60045a6085159
aa06563b27ca154fe5938cf-d
packagefile fmt=d:\GoLang\go1.10.1\pkg\windows_amd64\fmt.a
packagefile runtime=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime.a
packagefile errors=d:\GoLang\go1.10.1\pkg\windows_amd64\errors.a
packagefile io=d:\GoLang\go1.10.1\pkg\windows_amd64\io.a
packagefile math=d:\GoLang\go1.10.1\pkg\windows_amd64\math.a
packagefile os=d:\GoLang\go1.10.1\pkg\windows_amd64\os.a
packagefile reflect=d:\GoLang\go1.10.1\pkg\windows_amd64\reflect.a
packagefile strconv=d:\GoLang\go1.10.1\pkg\windows_amd64\strconv.a
packagefile sync=d:\GoLang\go1.10.1\pkg\windows_amd64\sync.a
packagefile unicode/utf8=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf8.a
packagefile runtime/internal/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\atomic.a
packagefile runtime/internal/sys=d:\GoLang\go1.10.1\pkg\windows_amd64\runtime\internal\sys.a
packagefile sync/atomic=d:\GoLang\go1.10.1\pkg\windows_amd64\sync\atomic.a
packagefile internal/cpu=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\cpu.a
packagefile internal/poll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\poll.a
packagefile internal/syscall/windows=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows.a
packagefile internal/testlog=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\testlog.a
packagefile syscall=d:\GoLang\go1.10.1\pkg\windows_amd64\syscall.a
packagefile time=d:\GoLang\go1.10.1\pkg\windows_amd64\time.a
packagefile unicode/utf16=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode\utf16.a
packagefile unicode=d:\GoLang\go1.10.1\pkg\windows_amd64\unicode.a
packagefile internal/race=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\race.a
packagefile internal/syscall/windows/sysdll=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\sysdll.a
packagefile internal/syscall/windows/registry=d:\GoLang\go1.10.1\pkg\windows_amd64\internal\syscall\windows\registry.a
EOF
mkdir -p $WORK\b001\exe\
cd .
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\link.exe" -o "B:\\TEMP\\go-build374060654\\b001\\exe\\a.out.exe" -impor
tcfg "B:\\TEMP\\go-build374060654\\b001\\importcfg.link" -buildmode=exe -buildid=tVFezFwIGIsU1SmKsjHV/qg_0bj3bXd7YdjORSd
5z/m1v7ZVfaEClTlxcNo9dI/tVFezFwIGIsU1SmKsjHV -s -w -extld=gcc "C:\\Users\\liukaizan\\AppData\\Local\\go-build\\1a\\1ad9f
3359e4cdb3920b3af8f43bc60045a6085159aa06563b27ca154fe5938cf-d"
"d:\\GoLang\\go1.10.1\\pkg\\tool\\windows_amd64\\buildid.exe" -w "B:\\TEMP\\go-build374060654\\b001\\exe\\a.out.exe" # i
nternal
cp $WORK\b001\exe\a.out.exe demo.exe
rm -r $WORK\b001\

d:\GoLang\go.ext\src\github.com\gooid\demo>dir demo.exe
 驱动器 D 中的卷是 work
 卷的序列号是 0001-FC75

 d:\GoLang\go.ext\src\github.com\gooid\demo 的目录

2018/04/24  12:33         1,259,520 demo.exe
               1 个文件      1,259,520 字节
               0 个目录  6,755,270,656 可用字节

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 24, 2018
@alexbrainman
Copy link
Member

I suspect cmd/go breaks on windows when os.Getwd returns path that differs from what %GOPATH% contains just in case of its characters. For example, c:\go and C:\GO - both paths are correct paths on Windows. And they refer to the same directory on Windows. But cmd/go treats them as different directories:
https://github.com/golang/go/blob/dev.boringcrypto.go1.10/src/cmd/go/internal/load/search.go#L285

I see no way to fix this but to convert these paths to upper case (or lower case) before comparing on windows. Please let me know, if there is a better way.

I think this is a dup of #19491 and #24232

Alex

@gooid
Copy link
Author

gooid commented Apr 24, 2018

https://github.com/golang/go/blob/dev.boringcrypto.go1.10/src/cmd/go/internal/load/search.go#L285

maybe :

	return func(p *Package) bool {
		if rel, err := filepath.Rel(p.Dir, dir); err != nil || rel != "." {
			return false
		}
		return true
	}

@alexbrainman

@alexbrainman
Copy link
Member

I think this is a dup of #19491 and #24232

My mistake, that was meant to say that this current issue is a dup of #19491 and #24750

maybe :

return func(p *Package) bool {
if rel, err := filepath.Rel(p.Dir, dir); err != nil || rel != "." {
return false
}
return true
}
@alexbrainman

I would not know.

Alex

@gopherbot
Copy link

Change https://golang.org/cl/109235 mentions this issue: cmd/go/internal/load: use strings.ToLower when comparing package directory names

@gopherbot
Copy link

Change https://golang.org/cl/129059 mentions this issue: cmd/go: fix -gcflags, -ldflags not applying to current directory

gopherbot pushed a commit that referenced this issue Aug 17, 2018
A flag setting like -gcflags=-e applies only to the packages
named on the command line, not to their dependencies.
The way we used to implement this was to remember the
command line arguments, reinterpret them as pattern matches
instead of package argument generators (globs), and apply them
during package load. The reason for this complexity was to
address a command-line like:

	go build -gcflags=-e fmt runtime

The load of fmt will load dependencies, including runtime,
and the load of runtime will reuse the result of the earlier load.
Because we were computing the effective -gcflags for each
package during the load, we had to have a way to tell, when
encountering runtime during the load of fmt, that runtime had
been named on the command line, even though we hadn't
gotten that far. That would be easy if the only possible
arguments were import paths, but we also need to handle

	go build -gcflags=-e fmt runt...
	go build -gcflags=-e fmt $GOROOT/src/runtime
	go build -gcflags=-e fmt $GOROOT/src/runt...
	and so on.

The match predicates usually did their job well, but not
always. In particular, thanks to symlinks and case-insensitive
file systems and unusual ways to spell file paths, it's always
been possible in various corner cases to give an argument
that evalutes to the runtime package during loading but
failed to match it when reused to determine "was this package
named on the command line?"

CL 109235 fixed one instance of this problem by making
a directory pattern match case-insensitive on Windows, but that
is incorrect in some other cases and doesn't address the root problem,
namely that there will probably always be odd corner cases
where pattern matching and pattern globbing are not exactly aligned.

This CL eliminates the assumption that pattern matching
and pattern globbing are always completely in agreement,
by simply marking the packages named on the command line
after the package load returns them. This means delaying
the computation of tool flags until after the load too,
for a few different ways packages are loaded.
The different load entry points add some complexity,
which is why the original approach seemed more attractive,
but the original approach had complexity that we simply
didn't recognize at the time.

This CL then rolls back the CL 109235 pattern-matching change,
but it keeps the test introduced in that CL. That test still passes.

In addition to fixing ambiguity due to case-sensitive file systems,
this new approach also very likely fixes various ambiguities that
might arise from abuse of symbolic links.

Fixes #24232.
Fixes #24456.
Fixes #24750.
Fixes #25046.
Fixes #25878.

Change-Id: I0b09825785dfb5112fb11494cff8527ebf57966f
Reviewed-on: https://go-review.googlesource.com/129059
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
@golang golang locked and limited conversation to collaborators Aug 10, 2019
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

6 participants