Skip to content

Commit 5f32918

Browse files
Andrew Leonardsavoptik
authored andcommitted
8323667: Library debug files contain non-reproducible full gcc include paths
Backport-of: 57fad677819ae3142782f811a8fba94b38f5a74c
1 parent 79bd47a commit 5f32918

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

make/autoconf/flags-cflags.m4

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2024, 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
@@ -117,6 +117,11 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
117117
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${DEBUG_PREFIX_CFLAGS}],
118118
IF_FALSE: [
119119
DEBUG_PREFIX_CFLAGS=
120+
],
121+
IF_TRUE: [
122+
# Add debug prefix map gcc system include paths, as they cause
123+
# non-deterministic debug paths depending on gcc path location.
124+
DEBUG_PREFIX_MAP_GCC_INCLUDE_PATHS
120125
]
121126
)
122127
fi
@@ -158,6 +163,55 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
158163
AC_SUBST(ASFLAGS_DEBUG_SYMBOLS)
159164
])
160165

166+
# gcc will embed the full system include paths in the debug info
167+
# resulting in non-deterministic debug symbol files and thus
168+
# non-reproducible native libraries if gcc includes are located
169+
# in different paths.
170+
# Add -fdebug-prefix-map'ings for root and gcc include paths,
171+
# pointing to a common set of folders so that the binaries are deterministic:
172+
# root include : /usr/include
173+
# gcc include : /usr/local/gcc_include
174+
# g++ include : /usr/local/gxx_include
175+
AC_DEFUN([DEBUG_PREFIX_MAP_GCC_INCLUDE_PATHS],
176+
[
177+
# Determine gcc system include paths.
178+
# Assume default roots to start with:
179+
GCC_ROOT_INCLUDE="/usr/include"
180+
181+
# Determine is sysroot or devkit specified?
182+
if test "x$SYSROOT" != "x"; then
183+
GCC_ROOT_INCLUDE="${SYSROOT%/}/usr/include"
184+
fi
185+
186+
# Add root include mapping => /usr/include
187+
GCC_INCLUDE_DEBUG_MAP_FLAGS="-fdebug-prefix-map=${GCC_ROOT_INCLUDE}/=/usr/include/"
188+
189+
# Add gcc system include mapping => /usr/local/gcc_include
190+
# Find location of stddef.h using build C compiler
191+
GCC_SYSTEM_INCLUDE=`$ECHO "#include <stddef.h>" | \
192+
$CC $CFLAGS -v -E - 2>&1 | \
193+
$GREP stddef | $TAIL -1 | $TR -s " " | $CUT -d'"' -f2`
194+
if test "x$GCC_SYSTEM_INCLUDE" != "x"; then
195+
GCC_SYSTEM_INCLUDE=`$DIRNAME $GCC_SYSTEM_INCLUDE`
196+
GCC_INCLUDE_DEBUG_MAP_FLAGS="$GCC_INCLUDE_DEBUG_MAP_FLAGS \
197+
-fdebug-prefix-map=${GCC_SYSTEM_INCLUDE}/=/usr/local/gcc_include/"
198+
fi
199+
200+
# Add g++ system include mapping => /usr/local/gxx_include
201+
# Find location of cstddef using build C++ compiler
202+
GXX_SYSTEM_INCLUDE=`$ECHO "#include <cstddef>" | \
203+
$CXX $CXXFLAGS -v -E -x c++ - 2>&1 | \
204+
$GREP cstddef | $TAIL -1 | $TR -s " " | $CUT -d'"' -f2`
205+
if test "x$GXX_SYSTEM_INCLUDE" != "x"; then
206+
GXX_SYSTEM_INCLUDE=`$DIRNAME $GXX_SYSTEM_INCLUDE`
207+
GCC_INCLUDE_DEBUG_MAP_FLAGS="$GCC_INCLUDE_DEBUG_MAP_FLAGS \
208+
-fdebug-prefix-map=${GXX_SYSTEM_INCLUDE}/=/usr/local/gxx_include/"
209+
fi
210+
211+
# Add to debug prefix cflags
212+
DEBUG_PREFIX_CFLAGS="$DEBUG_PREFIX_CFLAGS $GCC_INCLUDE_DEBUG_MAP_FLAGS"
213+
])
214+
161215
AC_DEFUN([FLAGS_SETUP_WARNINGS],
162216
[
163217
# Set default value.

0 commit comments

Comments
 (0)