From 57fad677819ae3142782f811a8fba94b38f5a74c Mon Sep 17 00:00:00 2001 From: Andrew Leonard Date: Thu, 18 Jan 2024 09:56:54 +0000 Subject: [PATCH] 8323667: Library debug files contain non-reproducible full gcc include paths Reviewed-by: erikj, ihse --- make/autoconf/flags-cflags.m4 | 56 ++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/make/autoconf/flags-cflags.m4 b/make/autoconf/flags-cflags.m4 index df44f7a2d59..57c2878f6eb 100644 --- a/make/autoconf/flags-cflags.m4 +++ b/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 @@ -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 " | \ + $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 " | \ + $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.