Skip to content

Commit ea7c243

Browse files
committed
compiler-wrapper: set -frandom-seed=$* when GCC
To make builds deterministic with GCC, use `-frandom-seed` with the value set to all command line arguments. Signed-off-by: Harmen Stoppels <me@harmenstoppels.nl>
1 parent 520d89c commit ea7c243

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

repos/spack_repo/builtin/packages/compiler_wrapper/cc.sh

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,20 +365,17 @@ if [ -z "$mode" ] || [ "$mode" = ld ]; then
365365
done
366366
fi
367367

368-
# Finish setting up the mode.
368+
# Finish setting up the mode, and check whether -frandom-seed needs to be set.
369+
eval _set_frandom_seed=\${SPACK_${comp}_HAS_FRANDOM_SEED:-}
369370
if [ -z "$mode" ]; then
370371
mode=ccld
371372
for arg in "$@"; do
372-
if [ "$arg" = "-E" ]; then
373-
mode=cpp
374-
break
375-
elif [ "$arg" = "-S" ]; then
376-
mode=as
377-
break
378-
elif [ "$arg" = "-c" ]; then
379-
mode=cc
380-
break
381-
fi
373+
case $arg in
374+
-E) mode=cpp ;;
375+
-S) mode=as ;;
376+
-c) mode=cc ;;
377+
-frandom-seed=*) _set_frandom_seed= ;;
378+
esac
382379
done
383380
fi
384381

@@ -951,6 +948,15 @@ extend args_list libs_list "-l"
951948
full_command_list="$command"
952949
extend full_command_list args_list
953950

951+
if [ -n "$_set_frandom_seed" ]; then
952+
case "$mode" in
953+
cc|ccld)
954+
# Make GCC deterministic by setting the random seed to command line arguments
955+
append full_command_list "-frandom-seed=$input_command"
956+
;;
957+
esac
958+
fi
959+
954960
# prepend the ccache binary if we're using ccache
955961
if [ -n "$SPACK_CCACHE_BINARY" ]; then
956962
case "$lang_flags" in

repos/spack_repo/builtin/packages/compiler_wrapper/package.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CompilerWrapper(Package):
4040
if sys.platform != "win32":
4141
version(
4242
"1.0",
43-
sha256="c7b816479554fd32f677db15ceec6627b91c86074a5d65498688afcbe2796188",
43+
sha256="5ecaeb9bf67538daa492ea95bd18b73dccac9af5bf3e187f013aa413adff3ce4",
4444
expand=False,
4545
)
4646
else:
@@ -175,6 +175,10 @@ def setup_dependent_build_environment(
175175
compiler = getattr(compiler_pkg, attr_name)
176176
env.set(spack_var_name, compiler)
177177

178+
# -frandom-seed= is needed for deterministic builds with GCC
179+
if compiler_pkg.name == "gcc":
180+
env.set(f"SPACK_{wrapper_var_name}_HAS_FRANDOM_SEED", "1")
181+
178182
if language not in compiler_pkg.compiler_wrapper_link_paths:
179183
continue
180184

0 commit comments

Comments
 (0)