From: Morten Linderud Date: Thu, 16 Feb 2023 14:37:50 +0000 (+0000) Subject: cmd/cgo: include seed string with -frandom-seed for lto X-Git-Tag: go1.21rc1~1539 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=37e893b1bd7bb57b169224486e1f3f5eef264340;p=gostls13.git cmd/cgo: include seed string with -frandom-seed for lto cgo is built with -flto the symbols in runtime/cgo is going to include random numbers which would make builds unreproducible. Settings -frandom-seeds ensures this is consistent across builds, and to ensure we always use a reproducible seed across builds we use the actionID as the seed string. runtime/cgo built with "-frandom-seed=OFEc9OKoUMJwh3-5yFCH" would output the following: $ strings --all --bytes=8 $WORK/b055/_pkg_.a | grep "gnu.lto_.profile" .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 .gnu.lto_.profile.8403a797 Change-Id: I3c2d261a94f23c8227a922da9a7f81660905fd71 GitHub-Last-Rev: cec5162316d33d8f652948706ce0a5f8c6794a6e GitHub-Pull-Request: golang/go#58561 Reviewed-on: https://go-review.googlesource.com/c/go/+/468835 Reviewed-by: Bryan Mills Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills --- diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index b211680e1c..9c8b14df00 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -39,6 +39,7 @@ import ( "cmd/go/internal/slices" "cmd/go/internal/str" "cmd/go/internal/trace" + "cmd/internal/buildid" "cmd/internal/quoted" "cmd/internal/sys" ) @@ -2544,6 +2545,12 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s } } + // Tell gcc to not insert truly random numbers into the build process + // this ensures LTO won't create random numbers for symbols. + if b.gccSupportsFlag(compiler, "-frandom-seed=1") { + flags = append(flags, "-frandom-seed="+buildid.HashToString(a.actionID)) + } + overlayPath := file if p, ok := a.nonGoOverlay[overlayPath]; ok { overlayPath = p