mirror of
https://github.com/golang/go
synced 2024-11-18 17:54:57 -07:00
cmd/go: support -trimpath with gccgo
Fixes #32162 Change-Id: I164665108fa8ae299229054bded82cb3b027bccb Reviewed-on: https://go-review.googlesource.com/c/go/+/196023 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
d3595f7171
commit
eb6ce1cff4
@ -91,6 +91,10 @@ func (tools gccgoToolchain) gc(b *Builder, a *Action, archive string, importcfg
|
|||||||
args = append(args, "-I", root)
|
args = append(args, "-I", root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if cfg.BuildTrimpath && b.gccSupportsFlag(args[:1], "-ffile-prefix-map=a=b") {
|
||||||
|
args = append(args, "-ffile-prefix-map="+base.Cwd+"=.")
|
||||||
|
args = append(args, "-ffile-prefix-map="+b.WorkDir+"=/tmp/go-build")
|
||||||
|
}
|
||||||
args = append(args, a.Package.Internal.Gccgoflags...)
|
args = append(args, a.Package.Internal.Gccgoflags...)
|
||||||
for _, f := range gofiles {
|
for _, f := range gofiles {
|
||||||
args = append(args, mkAbs(p.Dir, f))
|
args = append(args, mkAbs(p.Dir, f))
|
||||||
@ -535,7 +539,10 @@ func (tools gccgoToolchain) cc(b *Builder, a *Action, ofile, cfile string) error
|
|||||||
defs = append(defs, "-fsplit-stack")
|
defs = append(defs, "-fsplit-stack")
|
||||||
}
|
}
|
||||||
defs = tools.maybePIC(defs)
|
defs = tools.maybePIC(defs)
|
||||||
if b.gccSupportsFlag(compiler, "-fdebug-prefix-map=a=b") {
|
if b.gccSupportsFlag(compiler, "-ffile-prefix-map=a=b") {
|
||||||
|
defs = append(defs, "-ffile-prefix-map="+base.Cwd+"=.")
|
||||||
|
defs = append(defs, "-ffile-prefix-map="+b.WorkDir+"=/tmp/go-build")
|
||||||
|
} else if b.gccSupportsFlag(compiler, "-fdebug-prefix-map=a=b") {
|
||||||
defs = append(defs, "-fdebug-prefix-map="+b.WorkDir+"=/tmp/go-build")
|
defs = append(defs, "-fdebug-prefix-map="+b.WorkDir+"=/tmp/go-build")
|
||||||
}
|
}
|
||||||
if b.gccSupportsFlag(compiler, "-gno-record-gcc-switches") {
|
if b.gccSupportsFlag(compiler, "-gno-record-gcc-switches") {
|
||||||
|
43
src/cmd/go/testdata/script/build_trimpath.txt
vendored
43
src/cmd/go/testdata/script/build_trimpath.txt
vendored
@ -16,10 +16,10 @@ grep -q $GOROOT_REGEXP hello.exe
|
|||||||
go build -trimpath -o hello.exe hello.go
|
go build -trimpath -o hello.exe hello.go
|
||||||
! grep -q $GOROOT_REGEXP hello.exe
|
! grep -q $GOROOT_REGEXP hello.exe
|
||||||
! grep -q $WORK_REGEXP hello.exe
|
! grep -q $WORK_REGEXP hello.exe
|
||||||
cd ..
|
|
||||||
|
|
||||||
# A binary from an external module built with -trimpath should not contain
|
# A binary from an external module built with -trimpath should not contain
|
||||||
# the current workspace or GOROOT.
|
# the current workspace or GOROOT.
|
||||||
|
cd $WORK
|
||||||
env GO111MODULE=on
|
env GO111MODULE=on
|
||||||
go build -trimpath -o fortune.exe rsc.io/fortune
|
go build -trimpath -o fortune.exe rsc.io/fortune
|
||||||
! grep -q $GOROOT_REGEXP fortune.exe
|
! grep -q $GOROOT_REGEXP fortune.exe
|
||||||
@ -27,18 +27,35 @@ go build -trimpath -o fortune.exe rsc.io/fortune
|
|||||||
|
|
||||||
# Two binaries built from identical packages in different directories
|
# Two binaries built from identical packages in different directories
|
||||||
# should be identical.
|
# should be identical.
|
||||||
mkdir b
|
cd $GOPATH/src/a
|
||||||
cp a/go.mod a/hello.go b
|
go build -trimpath -o $WORK/a-GOPATH.exe .
|
||||||
cd a
|
cd $WORK/_alt/src/a
|
||||||
go build -trimpath -o ../a.exe .
|
go build -trimpath -o $WORK/a-alt.exe .
|
||||||
cd ../b
|
cmp -q $WORK/a-GOPATH.exe $WORK/a-alt.exe
|
||||||
go build -trimpath -o ../b.exe .
|
|
||||||
cd ..
|
|
||||||
cmp -q a.exe b.exe
|
|
||||||
|
|
||||||
-- a/hello.go --
|
[!exec:gccgo] stop
|
||||||
|
|
||||||
|
# Binaries built using gccgo should also be identical to each other.
|
||||||
|
env GO111MODULE=off # The current released gccgo does not support builds in module mode.
|
||||||
|
cd $GOPATH/src/a
|
||||||
|
go build -compiler=gccgo -trimpath -o $WORK/gccgo-GOPATH.exe .
|
||||||
|
|
||||||
|
env old_gopath=$GOPATH
|
||||||
|
env GOPATH=$WORK/_alt
|
||||||
|
cd $WORK/_alt/src/a
|
||||||
|
go build -compiler=gccgo -trimpath -o $WORK/gccgo-alt.exe .
|
||||||
|
cd $WORK
|
||||||
|
! grep -q $GOROOT_REGEXP gccgo-GOPATH.exe
|
||||||
|
! grep -q $WORK_REGEXP gccgo-GOPATH.exe
|
||||||
|
cmp -q gccgo-GOPATH.exe gccgo-alt.exe
|
||||||
|
|
||||||
|
-- $GOPATH/src/a/hello.go --
|
||||||
package main
|
package main
|
||||||
func main() { println("hello") }
|
func main() { println("hello") }
|
||||||
|
-- $GOPATH/src/a/go.mod --
|
||||||
-- a/go.mod --
|
module example.com/a
|
||||||
module m
|
-- $WORK/_alt/src/a/hello.go --
|
||||||
|
package main
|
||||||
|
func main() { println("hello") }
|
||||||
|
-- $WORK/_alt/src/a/go.mod --
|
||||||
|
module example.com/a
|
||||||
|
Loading…
Reference in New Issue
Block a user