Skip to content

Commit 61f4d6e

Browse files
committed
cmd/cgo: don't generate random numbers for symbols
If 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. $ strings --all --bytes=8 $WORK/b055/_pkg_.a | grep "gnu.lto_.profile" .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 .gnu.lto_.profile.1 Signed-off-by: Morten Linderud <[email protected]>
1 parent 2e773a3 commit 61f4d6e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/cmd/go/internal/work/exec.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,12 @@ func (b *Builder) compilerCmd(compiler []string, incdir, workdir string) []strin
25512551
a = append(a, "-gno-record-gcc-switches")
25522552
}
25532553

2554+
// Tell gcc to not insert truly random numbers into the build process
2555+
// this ensures LTO won't create random symbols.
2556+
if b.gccSupportsFlag(compiler, "-frandom-seed=1") {
2557+
a = append(a, "-frandom-seed=1")
2558+
}
2559+
25542560
// On OS X, some of the compilers behave as if -fno-common
25552561
// is always set, and the Mach-O linker in 6l/8l assumes this.
25562562
// See https://golang.org/issue/3253.

0 commit comments

Comments
 (0)