8256240: Reproducible builds should turn on the "deterministic" flag for Visual Studio

Reviewed-by: erikj
This commit is contained in:
Magnus Ihse Bursie 2020-11-23 11:33:18 +00:00
parent 0fb31dbf3a
commit b0485b9632
4 changed files with 54 additions and 20 deletions

View File

@ -203,7 +203,8 @@ FLAGS_POST_TOOLCHAIN
PLATFORM_SETUP_OPENJDK_TARGET_BITS
PLATFORM_SETUP_OPENJDK_TARGET_ENDIANNESS
# Configure flags for the tools
# Configure flags for the tools. Need to know if we should build reproducible.
JDKOPT_SETUP_REPRODUCIBLE_BUILD
FLAGS_SETUP_FLAGS
# Setup debug symbols (need objcopy from the toolchain for that)
@ -247,7 +248,6 @@ JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST
JDKOPT_EXCLUDE_TRANSLATIONS
JDKOPT_ENABLE_DISABLE_MANPAGES
JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE
JDKOPT_SETUP_REPRODUCIBLE_BUILD
###############################################################################
#

View File

@ -750,6 +750,18 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
$1_WARNING_CFLAGS_JVM="-Wno-format-zero-length -Wtype-limits -Wuninitialized"
fi
if test "x$TOOLCHAIN_TYPE" = xmicrosoft && test "x$ENABLE_REPRODUCIBLE_BUILD" = xtrue; then
# Enabling deterministic creates warnings if __DATE__ or __TIME__ are
# used, and since we are, silence that warning.
REPRODUCIBLE_CFLAGS="-experimental:deterministic -wd5048"
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${REPRODUCIBLE_CFLAGS}],
PREFIX: $3,
IF_FALSE: [
REPRODUCIBLE_CFLAGS=
]
)
fi
# Prevent the __FILE__ macro from generating absolute paths into the built
# binaries. Depending on toolchain, different mitigations are possible.
# * GCC and Clang of new enough versions have -fmacro-prefix-map.
@ -768,6 +780,30 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
FILE_MACRO_CFLAGS=
]
)
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft &&
test "x$ENABLE_REPRODUCIBLE_BUILD" = xtrue; then
# There is a known issue with the pathmap if the mapping is made to the
# empty string. Add a minimal string "s" as prefix to work around this.
workspace_root_win="${WORKSPACE_ROOT%/}"
UTIL_REWRITE_AS_WINDOWS_MIXED_PATH([workspace_root_win])
# PATHMAP_FLAGS is also added to LDFLAGS in flags-ldflags.m4.
PATHMAP_FLAGS="-pathmap:${workspace_root_win//\//\\\\}=s \
-pathmap:${workspace_root_win}=s"
FILE_MACRO_CFLAGS="$PATHMAP_FLAGS"
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${FILE_MACRO_CFLAGS}],
PREFIX: $3,
IF_FALSE: [
PATHMAP_FLAGS=
FILE_MACRO_CFLAGS=
]
)
fi
AC_MSG_CHECKING([how to prevent absolute paths in output])
if test "x$FILE_MACRO_CFLAGS" != x; then
AC_MSG_RESULT([using compiler options])
else
AC_MSG_RESULT([using relative paths])
fi
fi
AC_SUBST(FILE_MACRO_CFLAGS)
@ -776,12 +812,13 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
CFLAGS_JVM_COMMON="$ALWAYS_CFLAGS_JVM $ALWAYS_DEFINES_JVM \
$TOOLCHAIN_CFLAGS_JVM ${$1_TOOLCHAIN_CFLAGS_JVM} \
$OS_CFLAGS $OS_CFLAGS_JVM $CFLAGS_OS_DEF_JVM $DEBUG_CFLAGS_JVM \
$WARNING_CFLAGS $WARNING_CFLAGS_JVM $JVM_PICFLAG $FILE_MACRO_CFLAGS"
$WARNING_CFLAGS $WARNING_CFLAGS_JVM $JVM_PICFLAG $FILE_MACRO_CFLAGS \
$REPRODUCIBLE_CFLAGS"
CFLAGS_JDK_COMMON="$ALWAYS_CFLAGS_JDK $ALWAYS_DEFINES_JDK $TOOLCHAIN_CFLAGS_JDK \
$OS_CFLAGS $CFLAGS_OS_DEF_JDK $DEBUG_CFLAGS_JDK $DEBUG_OPTIONS_FLAGS_JDK \
$WARNING_CFLAGS $WARNING_CFLAGS_JDK $DEBUG_SYMBOLS_CFLAGS_JDK \
$FILE_MACRO_CFLAGS"
$FILE_MACRO_CFLAGS $REPRODUCIBLE_CFLAGS"
# Use ${$2EXTRA_CFLAGS} to block EXTRA_CFLAGS to be added to build flags.
# (Currently we don't have any OPENJDK_BUILD_EXTRA_CFLAGS, but that might

View File

@ -137,9 +137,17 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
fi
fi
if test "x$ENABLE_REPRODUCIBLE_BUILD" = "xtrue"; then
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
REPRODUCIBLE_LDFLAGS="-experimental:deterministic"
fi
fi
if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
BASIC_LDFLAGS="$BASIC_LDFLAGS -pdbaltpath:%_PDB%"
# PATHMAP_FLAGS is setup in flags-cflags.m4.
FILE_MACRO_LDFLAGS="${PATHMAP_FLAGS}"
fi
fi
@ -187,13 +195,15 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_CPU_DEP],
LDFLAGS_JDK_COMMON="$BASIC_LDFLAGS $BASIC_LDFLAGS_JDK_ONLY \
$OS_LDFLAGS_JDK_ONLY $DEBUGLEVEL_LDFLAGS_JDK_ONLY ${$2EXTRA_LDFLAGS}"
$2LDFLAGS_JDKLIB="$LDFLAGS_JDK_COMMON $BASIC_LDFLAGS_JDK_LIB_ONLY \
${$1_LDFLAGS_JDK_LIBPATH} $SHARED_LIBRARY_FLAGS"
${$1_LDFLAGS_JDK_LIBPATH} $SHARED_LIBRARY_FLAGS \
$REPRODUCIBLE_LDFLAGS $FILE_MACRO_LDFLAGS"
$2LDFLAGS_JDKEXE="$LDFLAGS_JDK_COMMON $EXECUTABLE_LDFLAGS \
${$1_CPU_EXECUTABLE_LDFLAGS}"
${$1_CPU_EXECUTABLE_LDFLAGS} $REPRODUCIBLE_LDFLAGS $FILE_MACRO_LDFLAGS"
$2JVM_LDFLAGS="$BASIC_LDFLAGS $BASIC_LDFLAGS_JVM_ONLY $OS_LDFLAGS_JVM_ONLY \
$DEBUGLEVEL_LDFLAGS $DEBUGLEVEL_LDFLAGS_JVM_ONLY $BASIC_LDFLAGS_ONLYCXX \
${$1_CPU_LDFLAGS} ${$1_CPU_LDFLAGS_JVM_ONLY} ${$2EXTRA_LDFLAGS}"
${$1_CPU_LDFLAGS} ${$1_CPU_LDFLAGS_JVM_ONLY} ${$2EXTRA_LDFLAGS} \
$REPRODUCIBLE_LDFLAGS $FILE_MACRO_LDFLAGS"
AC_SUBST($2LDFLAGS_JDKLIB)
AC_SUBST($2LDFLAGS_JDKEXE)

View File

@ -151,11 +151,6 @@ public class AbsPathsInImage {
return super.visitFile(file, attrs);
} else if (fileName.endsWith(".debuginfo") || fileName.endsWith(".pdb")) {
// Do nothing
} else if (fileName.endsWith(".dll")) {
// On Windows, the Microsoft toolchain does not provide a way
// to reliably remove all absolute paths from __FILE__ usage.
// Until that is fixed, we simply exclude *.dll from this
// test.
} else if (fileName.endsWith(".zip")) {
scanZipFile(file, searchPatterns);
} else {
@ -168,14 +163,6 @@ public class AbsPathsInImage {
private void scanFile(Path file, List<byte[]> searchPatterns) throws IOException {
List<String> matches = scanBytes(Files.readAllBytes(file), searchPatterns);
// For the same reason as the *.dll above, the jdk.jpackage module
// contains some unavoidable header references in the launcher which is
// stored as a java resource inside the modules file.
if (IS_WINDOWS && file.toString().endsWith("modules")) {
matches = matches.stream()
.filter(f -> !f.matches(".*jdk\\.jpackage.*\\.h.*"))
.collect(Collectors.toList());
}
if (matches.size() > 0) {
matchFound = true;
System.out.println(file + ":");