Skip to content

Commit

Permalink
8323667: Library debug files contain non-reproducible full gcc includ…
Browse files Browse the repository at this point in the history
…e paths

Backport-of: 57fad677819ae3142782f811a8fba94b38f5a74c
  • Loading branch information
Andrew Leonard authored and savoptik committed Feb 12, 2024
1 parent 79bd47a commit 5f32918
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion make/autoconf/flags-cflags.m4
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

1 comment on commit 5f32918

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.