-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go/internal/modload: ensure that __debug_modinfo__ is not discard…
…ed during linking Fixes #28753 Updates #29628 Change-Id: I4a561be7d491a0d088e656b00151ae1bdbd16a84 Reviewed-on: https://go-review.googlesource.com/c/158357 Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Russ Cox <[email protected]>
- Loading branch information
Bryan C. Mills
committed
Jan 23, 2019
1 parent
193c16a
commit 9d23975
Showing
2 changed files
with
77 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,34 +7,83 @@ cd x | |
go mod edit -require=rsc.io/[email protected] | ||
go mod edit -replace=rsc.io/[email protected]=rsc.io/[email protected] | ||
|
||
go run main.go | ||
|
||
stderr 'Hello, world.' | ||
# Build a binary and ensure that it can output its own debug info. | ||
# The debug info should be accessible before main starts (golang.org/issue/29628). | ||
go build | ||
exec ./x$GOEXE | ||
stderr 'mod\s+x\s+\(devel\)' | ||
stderr 'dep\s+rsc.io/quote\s+v1.5.2\s+' | ||
stderr '=>\s+rsc.io/quote\s+v1.0.0\s+h1:' | ||
stderr 'Hello, world.' | ||
|
||
[short] skip | ||
|
||
# Build a binary that accesses its debug info by reading the binary directly | ||
# (rather than through debug.ReadBuildInfo). | ||
# The debug info should still be present (golang.org/issue/28753). | ||
cd unused | ||
go build | ||
exec ./unused$GOEXE | ||
|
||
-- x/go.mod -- | ||
module x | ||
|
||
-- x/lib/lib.go -- | ||
// Package lib accesses runtime/debug.modinfo before package main's init | ||
// functions have run. | ||
package lib | ||
|
||
import "runtime/debug" | ||
|
||
func init() { | ||
m, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
panic("failed debug.ReadBuildInfo") | ||
} | ||
println("mod", m.Main.Path, m.Main.Version) | ||
for _, d := range m.Deps { | ||
println("dep", d.Path, d.Version, d.Sum) | ||
if r := d.Replace; r != nil { | ||
println("=>", r.Path, r.Version, r.Sum) | ||
} | ||
} | ||
} | ||
|
||
-- x/main.go -- | ||
package main | ||
|
||
import "runtime/debug" | ||
import "rsc.io/quote" | ||
import ( | ||
"rsc.io/quote" | ||
_ "x/lib" | ||
) | ||
|
||
func main() { | ||
println(quote.Hello()) | ||
|
||
m, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
panic("failed debug.ReadBuildInfo") | ||
} | ||
println("mod", m.Main.Path, m.Main.Version) | ||
for _, d := range m.Deps { | ||
println("dep", d.Path, d.Version, d.Sum) | ||
if r := d.Replace; r != nil { | ||
println("=>", r.Path, r.Version, r.Sum) | ||
} | ||
} | ||
println(quote.Hello()) | ||
} | ||
|
||
-- x/unused/main.go -- | ||
// The unused binary does not access runtime/debug.modinfo. | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
_ "rsc.io/quote" | ||
) | ||
|
||
func main() { | ||
b, err := ioutil.ReadFile(os.Args[0]) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
infoStart, _ := hex.DecodeString("3077af0c9274080241e1c107e6d618e6") | ||
if !bytes.Contains(b, infoStart) { | ||
log.Fatal("infoStart not found in binary") | ||
} | ||
log.Println("ok") | ||
} |