Text file src/cmd/link/testdata/script/randlayout_option.txt

     1  
     2  # Test that the -randlayout flag randomizes function order and
     3  # generates a working binary.
     4  
     5  [short] skip
     6  
     7  # Build with random layout using one seed, then run ...
     8  go build -o prog123.exe -ldflags=-randlayout=123
     9  exec ./prog123.exe
    10  
    11  # ... now build with a different seed and run.
    12  go build -x -o prog456.exe -ldflags=-randlayout=456
    13  exec ./prog456.exe
    14  
    15  # Capture symbols (sorted by address)
    16  go tool nm prog123.exe
    17  cp stdout syms123.txt
    18  
    19  # Capture symbols (sorted by address)
    20  go tool nm prog456.exe
    21  cp stdout syms456.txt
    22  
    23  # Output should be different.
    24  ! cmp syms123.txt syms456.txt
    25  
    26  -- go.mod --
    27  module main
    28  
    29  go 1.20
    30  
    31  -- mymain.go --
    32  package main
    33  
    34  func main() {
    35    println("Hi mom!")
    36  }
    37  
    38  
    39  

View as plain text