Skip to content

Commit 9f8cce1

Browse files
marc-hblgirdwood
authored andcommitted
Disable __TIME__ and the non-reproducible build counter by default
Makes even CONFIG_DEBUG builds (locally) deterministic by default: (re)building twice produces the same binaries. Also a partial fix for incremental builds: running "make" twice in a row now recompiles fewer files because version.h does not keep changing. Also makes sure non-debug builds can't use uninitialized strings in some future security accident. Fixes: ./scripts/checkpatch.pl -g 'aa85e2c0e956c' ERROR: Use of the '__DATE__' macro makes the build non-deterministic + .date = __DATE__, ERROR: Use of the '__TIME__' macro makes the build non-deterministic + .time = __TIME__, The previous behavior can be restored using any standard CMake configuration method, example: ./scripts/xtensa-build-all.sh apl cmake -B build_apl_gcc/ -DBUILD_COUNTERS=1 make -C build_apl_gcc https://reproducible-builds.org/ Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent fcaede7 commit 9f8cce1

File tree

9 files changed

+54
-19
lines changed

9 files changed

+54
-19
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ option(BUILD_UNIT_TESTS "Build unit tests" OFF)
3232
option(BUILD_UNIT_TESTS_HOST "Build unit tests for host" OFF)
3333
option(BUILD_UNIT_TESTS_XTENSA_GCC "Build xtensa unit test using GCC" OFF)
3434
option(BUILD_CLANG_SCAN "Build for clang's scan-build" OFF)
35+
option(BUILD_COUNTERS "Enable build counter(s), timestamps and any other
36+
non-deterministic build features" OFF)
3537

3638
if(CONFIG_LIBRARY OR BUILD_UNIT_TESTS_HOST)
3739
set(ARCH host)
@@ -78,6 +80,12 @@ add_library(sof_options INTERFACE)
7880

7981
target_link_libraries(sof_options INTERFACE sof_public_headers)
8082

83+
if(BUILD_COUNTERS)
84+
target_compile_definitions(sof_options INTERFACE BLD_COUNTERS=1)
85+
else()
86+
target_compile_definitions(sof_options INTERFACE BLD_COUNTERS=0)
87+
endif()
88+
8189
# interface library that is used only as container for sof statically
8290
# linked libraries
8391
add_library(sof_static_libraries INTERFACE)
@@ -183,7 +191,9 @@ target_link_libraries(sof PRIVATE sof_ld_scripts)
183191
target_link_libraries(sof PRIVATE sof_ld_flags)
184192
target_link_libraries(sof PRIVATE sof_static_libraries)
185193

194+
if (BUILD_COUNTERS)
186195
sof_add_build_counter_rule()
196+
endif()
187197

188198
add_subdirectory(src)
189199

installer/GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ BUILD_SOF_RIS := \
147147
${UNSIGNED_list:%=${BUILDS_ROOT}/build_%_${TOOLCHAIN}/sof.ri} \
148148
${SIGNED_list:%=${BUILDS_ROOT}/build_%_${TOOLCHAIN}/sof.ri}
149149

150-
# The build is not deterministic; use this to reduce noise when testing
150+
# When the build is not deterministic use this to reduce noise when testing
151151
# this Makefile.
152152
# Also very useful with XCC, see next comment.
153153
ifneq (true,${BUILD_ONLY_ONCE})

installer/sample-config.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
# USER_DESTDIR := ${_remote}:bin/
1717

1818
# Define this empty for a plain sof/ directory and no sof -> sof-v1.2.3
19-
# symbolic links.
19+
# symbolic links. This is _only_ to override the top-level directory
20+
# name; for version.h see version.cmake and try sof/.tarball-version
2021
# SOF_VERSION :=
2122
#
2223
# SOF_VERSION := $(shell git describe --tags )

src/init/ext_manifest.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ const struct ext_man_fw_version ext_man_fw_ver
2424
.micro = SOF_MICRO,
2525
.minor = SOF_MINOR,
2626
.major = SOF_MAJOR,
27-
#if CONFIG_DEBUG
28-
/* only added in debug for reproducibility in releases */
27+
/* opt-in; reproducible build by default */
28+
#if BLD_COUNTERS
2929
.build = SOF_BUILD,
3030
.date = __DATE__,
3131
.time = __TIME__,
32+
#else
33+
.build = -1,
34+
.date = "dtermin.\0",
35+
.time = "extman\0",
3236
#endif
3337
.tag = SOF_TAG,
3438
.abi_version = SOF_ABI_VERSION,

src/platform/baytrail/platform.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ static const struct sof_ipc_fw_ready ready
6464
.micro = SOF_MICRO,
6565
.minor = SOF_MINOR,
6666
.major = SOF_MAJOR,
67-
#if CONFIG_DEBUG
68-
/* only added in debug for reproducability in releases */
69-
.build = SOF_BUILD,
67+
/* opt-in; reproducible build by default */
68+
#if BLD_COUNTERS
69+
.build = SOF_BUILD, /* See version-build-counter.cmake */
7070
.date = __DATE__,
7171
.time = __TIME__,
72+
#else
73+
.build = -1,
74+
.date = "dtermin.\0",
75+
.time = "fwready.\0",
7276
#endif
7377
.tag = SOF_TAG,
7478
.abi_version = SOF_ABI_VERSION,

src/platform/haswell/platform.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ static const struct sof_ipc_fw_ready ready
5050
.micro = SOF_MICRO,
5151
.minor = SOF_MINOR,
5252
.major = SOF_MAJOR,
53-
#if CONFIG_DEBUG
54-
/* only added in debug for reproducability in releases */
55-
.build = SOF_BUILD,
53+
/* opt-in; reproducible build by default */
54+
#if BLD_COUNTERS
55+
.build = SOF_BUILD, /* See version-build-counter.cmake */
5656
.date = __DATE__,
5757
.time = __TIME__,
58+
#else
59+
.build = -1,
60+
.date = "dtermin.\0",
61+
.time = "fwready.\0",
5862
#endif
5963
.tag = SOF_TAG,
6064
.abi_version = SOF_ABI_VERSION,

src/platform/imx8/platform.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ static const struct sof_ipc_fw_ready ready
4949
.micro = SOF_MICRO,
5050
.minor = SOF_MINOR,
5151
.major = SOF_MAJOR,
52-
#ifdef DEBUG_BUILD
53-
/* only added in debug for reproducability in releases */
54-
.build = SOF_BUILD,
52+
/* opt-in; reproducible build by default */
53+
#if BLD_COUNTERS
54+
.build = SOF_BUILD, /* See version-build-counter.cmake */
5555
.date = __DATE__,
5656
.time = __TIME__,
57+
#else
58+
.build = -1,
59+
.date = "dtermin.\0",
60+
.time = "fwready.\0",
5761
#endif
5862
.tag = SOF_TAG,
5963
.abi_version = SOF_ABI_VERSION,

src/platform/imx8m/platform.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ static const struct sof_ipc_fw_ready ready
4848
.micro = SOF_MICRO,
4949
.minor = SOF_MINOR,
5050
.major = SOF_MAJOR,
51-
#ifdef DEBUG_BUILD
52-
/* only added in debug for reproducability in releases */
53-
.build = SOF_BUILD,
51+
/* opt-in; reproducible build by default */
52+
#if BLD_COUNTERS
53+
.build = SOF_BUILD, /* See version-build-counter.cmake */
5454
.date = __DATE__,
5555
.time = __TIME__,
56+
#else
57+
.build = -1,
58+
.date = "dtermin.\0",
59+
.time = "fwready.\0",
5660
#endif
5761
.tag = SOF_TAG,
5862
.abi_version = SOF_ABI_VERSION,

src/platform/intel/cavs/platform.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ static const struct sof_ipc_fw_ready ready
6060
.micro = SOF_MICRO,
6161
.minor = SOF_MINOR,
6262
.major = SOF_MAJOR,
63-
#if CONFIG_DEBUG
64-
/* only added in debug for reproducability in releases */
65-
.build = SOF_BUILD,
63+
/* opt-in; reproducible build by default */
64+
#if BLD_COUNTERS
65+
.build = SOF_BUILD, /* See version-build-counter.cmake */
6666
.date = __DATE__,
6767
.time = __TIME__,
68+
#else
69+
.build = -1,
70+
.date = "dtermin.\0",
71+
.time = "fwready.\0",
6872
#endif
6973
.tag = SOF_TAG,
7074
.abi_version = SOF_ABI_VERSION,

0 commit comments

Comments
 (0)