8323667: Library debug files contain non-reproducible full gcc include paths

Reviewed-by: erikj, ihse
This commit is contained in:
Andrew Leonard 2024-01-18 09:56:54 +00:00
parent ff8cc268fd
commit 57fad67781

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -117,6 +117,11 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${DEBUG_PREFIX_CFLAGS}],
IF_FALSE: [
DEBUG_PREFIX_CFLAGS=
],
IF_TRUE: [
# Add debug prefix map gcc system include paths, as they cause
# non-deterministic debug paths depending on gcc path location.
DEBUG_PREFIX_MAP_GCC_INCLUDE_PATHS
]
)
fi
@ -158,6 +163,55 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
AC_SUBST(ASFLAGS_DEBUG_SYMBOLS)
])
# gcc will embed the full system include paths in the debug info
# resulting in non-deterministic debug symbol files and thus
# non-reproducible native libraries if gcc includes are located
# in different paths.
# Add -fdebug-prefix-map'ings for root and gcc include paths,
# pointing to a common set of folders so that the binaries are deterministic:
# root include : /usr/include
# gcc include : /usr/local/gcc_include
# g++ include : /usr/local/gxx_include
AC_DEFUN([DEBUG_PREFIX_MAP_GCC_INCLUDE_PATHS],
[
# Determine gcc system include paths.
# Assume default roots to start with:
GCC_ROOT_INCLUDE="/usr/include"
# Determine is sysroot or devkit specified?
if test "x$SYSROOT" != "x"; then
GCC_ROOT_INCLUDE="${SYSROOT%/}/usr/include"
fi
# Add root include mapping => /usr/include
GCC_INCLUDE_DEBUG_MAP_FLAGS="-fdebug-prefix-map=${GCC_ROOT_INCLUDE}/=/usr/include/"
# Add gcc system include mapping => /usr/local/gcc_include
# Find location of stddef.h using build C compiler
GCC_SYSTEM_INCLUDE=`$ECHO "#include <stddef.h>" | \
$CC $CFLAGS -v -E - 2>&1 | \
$GREP stddef | $TAIL -1 | $TR -s " " | $CUT -d'"' -f2`
if test "x$GCC_SYSTEM_INCLUDE" != "x"; then
GCC_SYSTEM_INCLUDE=`$DIRNAME $GCC_SYSTEM_INCLUDE`
GCC_INCLUDE_DEBUG_MAP_FLAGS="$GCC_INCLUDE_DEBUG_MAP_FLAGS \
-fdebug-prefix-map=${GCC_SYSTEM_INCLUDE}/=/usr/local/gcc_include/"
fi
# Add g++ system include mapping => /usr/local/gxx_include
# Find location of cstddef using build C++ compiler
GXX_SYSTEM_INCLUDE=`$ECHO "#include <cstddef>" | \
$CXX $CXXFLAGS -v -E -x c++ - 2>&1 | \
$GREP cstddef | $TAIL -1 | $TR -s " " | $CUT -d'"' -f2`
if test "x$GXX_SYSTEM_INCLUDE" != "x"; then
GXX_SYSTEM_INCLUDE=`$DIRNAME $GXX_SYSTEM_INCLUDE`
GCC_INCLUDE_DEBUG_MAP_FLAGS="$GCC_INCLUDE_DEBUG_MAP_FLAGS \
-fdebug-prefix-map=${GXX_SYSTEM_INCLUDE}/=/usr/local/gxx_include/"
fi
# Add to debug prefix cflags
DEBUG_PREFIX_CFLAGS="$DEBUG_PREFIX_CFLAGS $GCC_INCLUDE_DEBUG_MAP_FLAGS"
])
AC_DEFUN([FLAGS_SETUP_WARNINGS],
[
# Set default value.