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

Reviewed-by: erikj, ihse
  • Loading branch information
Andrew Leonard committed Jan 18, 2024
1 parent ff8cc26 commit 57fad67
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

3 comments on commit 57fad67

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@andrew-m-leonard
Copy link

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 57fad67 Feb 8, 2024

Choose a reason for hiding this comment

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

@andrew-m-leonard the backport was successfully created on the branch backport-andrew-m-leonard-57fad677 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 57fad677 from the openjdk/jdk repository.

The commit being backported was authored by Andrew Leonard on 18 Jan 2024 and was reviewed by Erik Joelsson and Magnus Ihse Bursie.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-andrew-m-leonard-57fad677:backport-andrew-m-leonard-57fad677
$ git checkout backport-andrew-m-leonard-57fad677
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-andrew-m-leonard-57fad677

⚠️ @andrew-m-leonard You are not yet a collaborator in my fork openjdk-bots/jdk21u-dev. An invite will be sent out and you need to accept it before you can proceed.

Please sign in to comment.