Text file src/cmd/go/testdata/script/build_buildmode_default_reproducible.txt

     1  # Issue 63559: building with -buildmode=default should produce
     2  # a binary identical to one built with the buildmode that default
     3  # resolves to, and the build info stamped into the binary should
     4  # record the resolved buildmode.
     5  
     6  [short] skip 'links binaries'
     7  # gccgo does not set -fPIE for the default->pie case (unlike explicit
     8  # -buildmode=pie), so the two binaries would not be identical there.
     9  [compiler:gccgo] skip
    10  
    11  # Build with -buildmode=default and, separately, with the buildmode that
    12  # default resolves to. Use distinct build caches so that the second build
    13  # cannot be served from the first build's link cache: the binaries must be
    14  # byte-identical because they are truly reproducible, not because one was
    15  # copied from the other.
    16  env GOCACHE=$WORK/cache-default
    17  go build -buildmode=default -o default$GOEXE .
    18  
    19  env GOCACHE=$WORK/cache-explicit
    20  [!default-pie] go build -buildmode=exe -o explicit$GOEXE .
    21  [default-pie] go build -buildmode=pie -o explicit$GOEXE .
    22  
    23  cmp -q default$GOEXE explicit$GOEXE
    24  
    25  # The build info must record the resolved buildmode, not the literal "default".
    26  go version -m default$GOEXE
    27  [!default-pie] stdout -buildmode=exe
    28  [default-pie] stdout -buildmode=pie
    29  
    30  -- go.mod --
    31  module m
    32  
    33  go 1.26
    34  -- main.go --
    35  package main
    36  
    37  func main() {}
    38  

View as plain text