Skip to content

Commit e1bc9b9

Browse files
Andrew LeonardTheRealMDoerr
authored andcommitted
8284437: Building from different users/workspace is not always deterministic
Backport-of: 4451257b1432e4180a16757aafca6141b8063772
1 parent e58448b commit e1bc9b9

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

make/autoconf/flags-cflags.m4

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,24 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
9595
# info flags for toolchains unless we know they work.
9696
# See JDK-8207057.
9797
ASFLAGS_DEBUG_SYMBOLS=""
98+
99+
# Debug prefix mapping if supported by compiler
100+
DEBUG_PREFIX_CFLAGS=
101+
98102
# Debug symbols
99103
if test "x$TOOLCHAIN_TYPE" = xgcc; then
104+
if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
105+
# Check if compiler supports -fdebug-prefix-map. If so, use that to make
106+
# the debug symbol paths resolve to paths relative to the workspace root.
107+
workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
108+
DEBUG_PREFIX_CFLAGS="-fdebug-prefix-map=${workspace_root_trailing_slash}="
109+
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${DEBUG_PREFIX_CFLAGS}],
110+
IF_FALSE: [
111+
DEBUG_PREFIX_CFLAGS=
112+
]
113+
)
114+
fi
115+
100116
CFLAGS_DEBUG_SYMBOLS="-g"
101117
ASFLAGS_DEBUG_SYMBOLS="-g"
102118
elif test "x$TOOLCHAIN_TYPE" = xclang; then
@@ -108,6 +124,11 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
108124
CFLAGS_DEBUG_SYMBOLS="-Z7"
109125
fi
110126
127+
if test "x$DEBUG_PREFIX_CFLAGS" != x; then
128+
CFLAGS_DEBUG_SYMBOLS="$CFLAGS_DEBUG_SYMBOLS $DEBUG_PREFIX_CFLAGS"
129+
ASFLAGS_DEBUG_SYMBOLS="$ASFLAGS_DEBUG_SYMBOLS $DEBUG_PREFIX_CFLAGS"
130+
fi
131+
111132
AC_SUBST(CFLAGS_DEBUG_SYMBOLS)
112133
AC_SUBST(ASFLAGS_DEBUG_SYMBOLS)
113134
])

make/common/NativeCompilation.gmk

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -389,6 +389,12 @@ define SetupCompileNativeFileBody
389389
$1_OBJ_DEPS := $$($1_SRC_FILE) $$($$($1_BASE)_COMPILE_VARDEPS_FILE) \
390390
$$($$($1_BASE)_EXTRA_DEPS) $$($1_VARDEPS_FILE)
391391
$1_COMPILE_OPTIONS := $$($1_FLAGS) $(CC_OUT_OPTION)$$($1_OBJ) $$($1_SRC_FILE)
392+
# For reproducible builds with gcc ensure random symbol generation is seeded deterministically
393+
ifeq ($(TOOLCHAIN_TYPE), gcc)
394+
ifeq ($$(ENABLE_REPRODUCIBLE_BUILD), true)
395+
$1_COMPILE_OPTIONS += -frandom-seed="$$($1_FILENAME)"
396+
endif
397+
endif
392398

393399
$$($1_OBJ_JSON): $$($1_OBJ_DEPS)
394400
$$(call WriteCompileCommandsFragment, $$@, $$(PWD), $$($1_SRC_FILE), \
@@ -1143,6 +1149,19 @@ define SetupNativeCompilationBody
11431149
endif
11441150
endif
11451151

1152+
# Debuginfo of ASM objects always embeds the absolute object path,
1153+
# as ASM debuginfo paths do not get prefix mapped.
1154+
# So for reproducible builds use relative paths to ensure a reproducible
1155+
# debuginfo and libs, when creating debug symbols.
1156+
ifeq ($$(ENABLE_REPRODUCIBLE_BUILD), true)
1157+
ifeq ($(call isTargetOs, linux), true)
1158+
ifeq ($$($1_COMPILE_WITH_DEBUG_SYMBOLS), true)
1159+
$1_LINK_OBJS_RELATIVE := true
1160+
$1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1161+
endif
1162+
endif
1163+
endif
1164+
11461165
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
11471166
$$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)
11481167

make/hotspot/gensrc/GensrcAdlc.gmk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ ifeq ($(call check-jvm-feature, compiler2), true)
5858

5959
ADLC_CFLAGS += -I$(TOPDIR)/src/hotspot/share
6060

61+
# Add file macro mappings
62+
ADLC_CFLAGS += $(FILE_MACRO_CFLAGS)
63+
6164
$(eval $(call SetupNativeCompilation, BUILD_ADLC, \
6265
NAME := adlc, \
6366
TYPE := EXECUTABLE, \

make/jdk/src/classes/build/tools/makezipreproducible/MakeZipReproducible.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -204,6 +204,10 @@ void addEntry(ZipOutputStream zos, ZipEntry entry, InputStream entryInputStream)
204204
entry.setTimeLocal(timestamp);
205205
}
206206

207+
// Ensure "extra" field is not set from original ZipEntry info that may be not deterministic
208+
// eg.may contain specific UID/GID
209+
entry.setExtra(null);
210+
207211
zos.putNextEntry(entry);
208212
if (entry.getSize() > 0 && entryInputStream != null) {
209213
entryInputStream.transferTo(zos);

0 commit comments

Comments
 (0)