1 #
   2 # Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 ################################################################################
  27 #
  28 # Setup flags for C/C++ compiler
  29 #
  30 
  31 ###############################################################################
  32 #
  33 # How to compile shared libraries.
  34 #
  35 AC_DEFUN([FLAGS_SETUP_SHARED_LIBS],
  36 [
  37   if test "x$TOOLCHAIN_TYPE" = xgcc; then
  38     # Default works for linux, might work on other platforms as well.
  39     SHARED_LIBRARY_FLAGS='-shared'
  40     SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$ORIGIN[$]1'
  41     SET_SHARED_LIBRARY_ORIGIN="-Wl,-z,origin $SET_EXECUTABLE_ORIGIN"
  42     SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
  43     SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
  44 
  45   elif test "x$TOOLCHAIN_TYPE" = xclang; then
  46     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
  47       # Linking is different on MacOSX
  48       SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0"
  49       SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path$(or [$]1,/.)'
  50       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
  51       SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
  52       SET_SHARED_LIBRARY_MAPFILE='-Wl,-exported_symbols_list,[$]1'
  53 
  54     elif test "x$OPENJDK_TARGET_OS" = xaix; then
  55       # Linking is different on aix
  56       SHARED_LIBRARY_FLAGS="-shared -Wl,-bM:SRE -Wl,-bnoentry"
  57       SET_EXECUTABLE_ORIGIN=""
  58       SET_SHARED_LIBRARY_ORIGIN=''
  59       SET_SHARED_LIBRARY_NAME=''
  60       SET_SHARED_LIBRARY_MAPFILE=''
  61 
  62     else
  63       # Default works for linux, might work on other platforms as well.
  64       SHARED_LIBRARY_FLAGS='-shared'
  65       SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$ORIGIN[$]1'
  66       SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
  67       SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
  68 
  69       # arm specific settings
  70       if test "x$OPENJDK_TARGET_CPU" = "xarm"; then
  71         # '-Wl,-z,origin' isn't used on arm.
  72         SET_SHARED_LIBRARY_ORIGIN='-Wl,-rpath,\$$$$ORIGIN[$]1'
  73       else
  74         SET_SHARED_LIBRARY_ORIGIN="-Wl,-z,origin $SET_EXECUTABLE_ORIGIN"
  75       fi
  76     fi
  77 
  78   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
  79     SHARED_LIBRARY_FLAGS="-qmkshrobj -bM:SRE -bnoentry"
  80     SET_EXECUTABLE_ORIGIN=""
  81     SET_SHARED_LIBRARY_ORIGIN=''
  82     SET_SHARED_LIBRARY_NAME=''
  83     SET_SHARED_LIBRARY_MAPFILE=''
  84 
  85   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
  86     SHARED_LIBRARY_FLAGS="-dll"
  87     SET_EXECUTABLE_ORIGIN=''
  88     SET_SHARED_LIBRARY_ORIGIN=''
  89     SET_SHARED_LIBRARY_NAME=''
  90     SET_SHARED_LIBRARY_MAPFILE='-def:[$]1'
  91   fi
  92 
  93   AC_SUBST(SET_EXECUTABLE_ORIGIN)
  94   AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
  95   AC_SUBST(SET_SHARED_LIBRARY_NAME)
  96   AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
  97   AC_SUBST(SHARED_LIBRARY_FLAGS)
  98 ])
  99 
 100 AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
 101 [
 102   # By default don't set any specific assembler debug
 103   # info flags for toolchains unless we know they work.
 104   # See JDK-8207057.
 105   ASFLAGS_DEBUG_SYMBOLS=""
 106 
 107   # Debug prefix mapping if supported by compiler
 108   DEBUG_PREFIX_CFLAGS=
 109 
 110   # Debug symbols
 111   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 112     if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
 113       # Check if compiler supports -fdebug-prefix-map. If so, use that to make
 114       # the debug symbol paths resolve to paths relative to the workspace root.
 115       workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
 116       DEBUG_PREFIX_CFLAGS="-fdebug-prefix-map=${workspace_root_trailing_slash}="
 117       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${DEBUG_PREFIX_CFLAGS}],
 118         IF_FALSE: [
 119             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
 125         ]
 126       )
 127     fi
 128 
 129     CFLAGS_DEBUG_SYMBOLS="-g -gdwarf-4"
 130     ASFLAGS_DEBUG_SYMBOLS="-g"
 131   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 132     if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
 133       # Check if compiler supports -fdebug-prefix-map. If so, use that to make
 134       # the debug symbol paths resolve to paths relative to the workspace root.
 135       workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
 136       DEBUG_PREFIX_CFLAGS="-fdebug-prefix-map=${workspace_root_trailing_slash}="
 137       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${DEBUG_PREFIX_CFLAGS}],
 138         IF_FALSE: [
 139             DEBUG_PREFIX_CFLAGS=
 140         ]
 141       )
 142     fi
 143 
 144     # -gdwarf-4 and -gdwarf-aranges were introduced in clang 5.0
 145     GDWARF_FLAGS="-gdwarf-4 -gdwarf-aranges"
 146     FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${GDWARF_FLAGS}],
 147         IF_FALSE: [GDWARF_FLAGS=""])
 148 
 149     CFLAGS_DEBUG_SYMBOLS="-g ${GDWARF_FLAGS}"
 150     ASFLAGS_DEBUG_SYMBOLS="-g"
 151   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 152     CFLAGS_DEBUG_SYMBOLS="-g1"
 153   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 154     CFLAGS_DEBUG_SYMBOLS="-Z7"
 155   fi
 156 
 157   if test "x$DEBUG_PREFIX_CFLAGS" != x; then
 158     CFLAGS_DEBUG_SYMBOLS="$CFLAGS_DEBUG_SYMBOLS $DEBUG_PREFIX_CFLAGS"
 159     ASFLAGS_DEBUG_SYMBOLS="$ASFLAGS_DEBUG_SYMBOLS $DEBUG_PREFIX_CFLAGS"
 160   fi
 161 
 162   AC_SUBST(CFLAGS_DEBUG_SYMBOLS)
 163   AC_SUBST(ASFLAGS_DEBUG_SYMBOLS)
 164 ])
 165 
 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 
 215 AC_DEFUN([FLAGS_SETUP_WARNINGS],
 216 [
 217   # Set default value.
 218   if test "x$TOOLCHAIN_TYPE" != xxlc; then
 219     WARNINGS_AS_ERRORS_DEFAULT=true
 220   else
 221     WARNINGS_AS_ERRORS_DEFAULT=false
 222   fi
 223 
 224   UTIL_ARG_ENABLE(NAME: warnings-as-errors, DEFAULT: $WARNINGS_AS_ERRORS_DEFAULT,
 225       RESULT: WARNINGS_AS_ERRORS,
 226       DEFAULT_DESC: [auto],
 227       DESC: [consider native warnings to be an error])
 228   AC_SUBST(WARNINGS_AS_ERRORS)
 229 
 230   case "${TOOLCHAIN_TYPE}" in
 231     microsoft)
 232       DISABLE_WARNING_PREFIX="-wd"
 233       BUILD_CC_DISABLE_WARNING_PREFIX="-wd"
 234       CFLAGS_WARNINGS_ARE_ERRORS="-WX"
 235 
 236       WARNINGS_ENABLE_ALL="-W3"
 237       DISABLED_WARNINGS="4800 5105"
 238       ;;
 239 
 240     gcc)
 241       DISABLE_WARNING_PREFIX="-Wno-"
 242       BUILD_CC_DISABLE_WARNING_PREFIX="-Wno-"
 243       CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
 244 
 245       # Additional warnings that are not activated by -Wall and -Wextra
 246       WARNINGS_ENABLE_ADDITIONAL="-Wpointer-arith -Wsign-compare \
 247           -Wunused-function -Wundef -Wunused-value -Wreturn-type \
 248           -Wtrampolines"
 249       WARNINGS_ENABLE_ADDITIONAL_CXX="-Woverloaded-virtual -Wreorder"
 250       WARNINGS_ENABLE_ALL_CFLAGS="-Wall -Wextra -Wformat=2 $WARNINGS_ENABLE_ADDITIONAL"
 251       WARNINGS_ENABLE_ALL_CXXFLAGS="$WARNINGS_ENABLE_ALL_CFLAGS $WARNINGS_ENABLE_ADDITIONAL_CXX"
 252 
 253       DISABLED_WARNINGS="unused-parameter unused"
 254       # gcc10/11 on ppc generate lots of abi warnings about layout of aggregates containing vectors
 255       if test "x$OPENJDK_TARGET_CPU_ARCH" = "xppc"; then
 256         DISABLED_WARNINGS="$DISABLED_WARNINGS psabi"
 257       fi
 258       ;;
 259 
 260     clang)
 261       DISABLE_WARNING_PREFIX="-Wno-"
 262       BUILD_CC_DISABLE_WARNING_PREFIX="-Wno-"
 263       CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
 264 
 265       # Additional warnings that are not activated by -Wall and -Wextra
 266       WARNINGS_ENABLE_ADDITIONAL="-Wpointer-arith -Wsign-compare -Wreorder \
 267           -Wunused-function -Wundef -Wunused-value -Woverloaded-virtual"
 268       WARNINGS_ENABLE_ALL="-Wall -Wextra -Wformat=2 $WARNINGS_ENABLE_ADDITIONAL"
 269 
 270       DISABLED_WARNINGS="unknown-warning-option unused-parameter unused"
 271       ;;
 272 
 273     xlc)
 274       DISABLE_WARNING_PREFIX="-Wno-"
 275       CFLAGS_WARNINGS_ARE_ERRORS="-qhalt=w"
 276 
 277       # Possibly a better subset than "all" is "lan:trx:ret:zea:cmp:ret"
 278       WARNINGS_ENABLE_ALL="-qinfo=all -qformat=all"
 279       DISABLED_WARNINGS=""
 280       ;;
 281   esac
 282   AC_SUBST(DISABLE_WARNING_PREFIX)
 283   AC_SUBST(BUILD_CC_DISABLE_WARNING_PREFIX)
 284   AC_SUBST(CFLAGS_WARNINGS_ARE_ERRORS)
 285   AC_SUBST(DISABLED_WARNINGS)
 286   AC_SUBST(DISABLED_WARNINGS_C)
 287   AC_SUBST(DISABLED_WARNINGS_CXX)
 288 ])
 289 
 290 AC_DEFUN([FLAGS_SETUP_QUALITY_CHECKS],
 291 [
 292   # bounds, memory and behavior checking options
 293   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 294     case $DEBUG_LEVEL in
 295     release )
 296       # no adjustment
 297       ;;
 298     fastdebug )
 299       # no adjustment
 300       ;;
 301     slowdebug )
 302       # FIXME: By adding this to C(XX)FLAGS_DEBUG_OPTIONS/JVM_CFLAGS_SYMBOLS it
 303       # gets added conditionally on whether we produce debug symbols or not.
 304       # This is most likely not really correct.
 305 
 306       # Add runtime stack smashing and undefined behavior checks.
 307       CFLAGS_DEBUG_OPTIONS="-fstack-protector-all --param ssp-buffer-size=1"
 308       CXXFLAGS_DEBUG_OPTIONS="-fstack-protector-all --param ssp-buffer-size=1"
 309 
 310       JVM_CFLAGS_SYMBOLS="$JVM_CFLAGS_SYMBOLS -fstack-protector-all --param ssp-buffer-size=1"
 311       ;;
 312     esac
 313   fi
 314 ])
 315 
 316 AC_DEFUN([FLAGS_SETUP_OPTIMIZATION],
 317 [
 318   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 319     C_O_FLAG_HIGHEST_JVM="-O3"
 320     C_O_FLAG_HIGHEST="-O3"
 321     C_O_FLAG_HI="-O3"
 322     C_O_FLAG_NORM="-O2"
 323     C_O_FLAG_SIZE="-Os"
 324     C_O_FLAG_DEBUG="-O0"
 325     C_O_FLAG_DEBUG_JVM="-O0"
 326     C_O_FLAG_NONE="-O0"
 327     # -D_FORTIFY_SOURCE=2 hardening option needs optimization (at least -O1) enabled
 328     # set for lower O-levels -U_FORTIFY_SOURCE to overwrite previous settings
 329     if test "x$OPENJDK_TARGET_OS" = xlinux -a "x$DEBUG_LEVEL" = "xfastdebug"; then
 330       DISABLE_FORTIFY_CFLAGS="-U_FORTIFY_SOURCE"
 331       # ASan doesn't work well with _FORTIFY_SOURCE
 332       # See https://github.com/google/sanitizers/wiki/AddressSanitizer#faq
 333       if test "x$ASAN_ENABLED" = xyes; then
 334         ENABLE_FORTIFY_CFLAGS="${DISABLE_FORTIFY_CFLAGS}"
 335       else
 336         ENABLE_FORTIFY_CFLAGS="-D_FORTIFY_SOURCE=2"
 337       fi
 338       C_O_FLAG_HIGHEST_JVM="${C_O_FLAG_HIGHEST_JVM} ${ENABLE_FORTIFY_CFLAGS}"
 339       C_O_FLAG_HIGHEST="${C_O_FLAG_HIGHEST} ${ENABLE_FORTIFY_CFLAGS}"
 340       C_O_FLAG_HI="${C_O_FLAG_HI} ${ENABLE_FORTIFY_CFLAGS}"
 341       C_O_FLAG_NORM="${C_O_FLAG_NORM} ${ENABLE_FORTIFY_CFLAGS}"
 342       C_O_FLAG_SIZE="${C_O_FLAG_SIZE} ${DISABLE_FORTIFY_CFLAGS}"
 343       C_O_FLAG_DEBUG="${C_O_FLAG_DEBUG} ${DISABLE_FORTIFY_CFLAGS}"
 344       C_O_FLAG_DEBUG_JVM="${C_O_FLAG_DEBUG_JVM} ${DISABLE_FORTIFY_CFLAGS}"
 345       C_O_FLAG_NONE="${C_O_FLAG_NONE} ${DISABLE_FORTIFY_CFLAGS}"
 346     fi
 347   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 348     if test "x$OPENJDK_TARGET_OS" = xaix; then
 349       C_O_FLAG_HIGHEST_JVM="-O3 -finline-functions"
 350       C_O_FLAG_HIGHEST="-O3 -finline-functions"
 351       C_O_FLAG_HI="-O3 -finline-functions"
 352     else
 353       C_O_FLAG_HIGHEST_JVM="-O3"
 354       C_O_FLAG_HIGHEST="-O3"
 355       C_O_FLAG_HI="-O3"
 356     fi
 357     C_O_FLAG_NORM="-O2"
 358     C_O_FLAG_DEBUG_JVM="-O0"
 359     C_O_FLAG_SIZE="-Os"
 360     C_O_FLAG_DEBUG="-O0"
 361     C_O_FLAG_NONE="-O0"
 362   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 363     C_O_FLAG_HIGHEST_JVM="-O3 -qhot=level=1 -qinline -qinlglue"
 364     C_O_FLAG_HIGHEST="-O3 -qhot=level=1 -qinline -qinlglue"
 365     C_O_FLAG_HI="-O3 -qinline -qinlglue"
 366     C_O_FLAG_NORM="-O2"
 367     C_O_FLAG_DEBUG="-qnoopt"
 368     # FIXME: Value below not verified.
 369     C_O_FLAG_DEBUG_JVM=""
 370     C_O_FLAG_NONE="-qnoopt"
 371   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 372     C_O_FLAG_HIGHEST_JVM="-O2 -Oy-"
 373     C_O_FLAG_HIGHEST="-O2"
 374     C_O_FLAG_HI="-O1"
 375     C_O_FLAG_NORM="-O1"
 376     C_O_FLAG_DEBUG="-Od"
 377     C_O_FLAG_DEBUG_JVM=""
 378     C_O_FLAG_NONE="-Od"
 379     C_O_FLAG_SIZE="-Os"
 380   fi
 381 
 382   # Now copy to C++ flags
 383   CXX_O_FLAG_HIGHEST_JVM="$C_O_FLAG_HIGHEST_JVM"
 384   CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
 385   CXX_O_FLAG_HI="$C_O_FLAG_HI"
 386   CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
 387   CXX_O_FLAG_DEBUG="$C_O_FLAG_DEBUG"
 388   CXX_O_FLAG_DEBUG_JVM="$C_O_FLAG_DEBUG_JVM"
 389   CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
 390   CXX_O_FLAG_SIZE="$C_O_FLAG_SIZE"
 391 
 392   # Adjust optimization flags according to debug level.
 393   case $DEBUG_LEVEL in
 394     release )
 395       # no adjustment
 396       ;;
 397     fastdebug )
 398       # Not quite so much optimization
 399       C_O_FLAG_HI="$C_O_FLAG_NORM"
 400       CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
 401       ;;
 402     slowdebug )
 403       # Disable optimization
 404       C_O_FLAG_HIGHEST_JVM="$C_O_FLAG_DEBUG_JVM"
 405       C_O_FLAG_HIGHEST="$C_O_FLAG_DEBUG"
 406       C_O_FLAG_HI="$C_O_FLAG_DEBUG"
 407       C_O_FLAG_NORM="$C_O_FLAG_DEBUG"
 408       C_O_FLAG_SIZE="$C_O_FLAG_DEBUG"
 409       CXX_O_FLAG_HIGHEST_JVM="$CXX_O_FLAG_DEBUG_JVM"
 410       CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_DEBUG"
 411       CXX_O_FLAG_HI="$CXX_O_FLAG_DEBUG"
 412       CXX_O_FLAG_NORM="$CXX_O_FLAG_DEBUG"
 413       CXX_O_FLAG_SIZE="$CXX_O_FLAG_DEBUG"
 414       ;;
 415   esac
 416 
 417   AC_SUBST(C_O_FLAG_HIGHEST_JVM)
 418   AC_SUBST(C_O_FLAG_HIGHEST)
 419   AC_SUBST(C_O_FLAG_HI)
 420   AC_SUBST(C_O_FLAG_NORM)
 421   AC_SUBST(C_O_FLAG_NONE)
 422   AC_SUBST(C_O_FLAG_SIZE)
 423   AC_SUBST(CXX_O_FLAG_HIGHEST_JVM)
 424   AC_SUBST(CXX_O_FLAG_HIGHEST)
 425   AC_SUBST(CXX_O_FLAG_HI)
 426   AC_SUBST(CXX_O_FLAG_NORM)
 427   AC_SUBST(CXX_O_FLAG_NONE)
 428   AC_SUBST(CXX_O_FLAG_SIZE)
 429 ])
 430 
 431 AC_DEFUN([FLAGS_SETUP_CFLAGS],
 432 [
 433   ### CFLAGS
 434 
 435   FLAGS_SETUP_CFLAGS_HELPER
 436 
 437   FLAGS_OS=$OPENJDK_TARGET_OS
 438   FLAGS_OS_TYPE=$OPENJDK_TARGET_OS_TYPE
 439   FLAGS_CPU=$OPENJDK_TARGET_CPU
 440   FLAGS_CPU_ARCH=$OPENJDK_TARGET_CPU_ARCH
 441   FLAGS_CPU_BITS=$OPENJDK_TARGET_CPU_BITS
 442   FLAGS_CPU_ENDIAN=$OPENJDK_TARGET_CPU_ENDIAN
 443   FLAGS_CPU_LEGACY=$OPENJDK_TARGET_CPU_LEGACY
 444   FLAGS_CPU_LEGACY_LIB=$OPENJDK_TARGET_CPU_LEGACY_LIB
 445 
 446   FLAGS_SETUP_CFLAGS_CPU_DEP([TARGET])
 447 
 448   # Repeat the check for the BUILD_CC and BUILD_CXX. Need to also reset CFLAGS
 449   # since any target specific flags will likely not work with the build compiler.
 450   CC_OLD="$CC"
 451   CXX_OLD="$CXX"
 452   CFLAGS_OLD="$CFLAGS"
 453   CXXFLAGS_OLD="$CXXFLAGS"
 454   CC="$BUILD_CC"
 455   CXX="$BUILD_CXX"
 456   CFLAGS=""
 457   CXXFLAGS=""
 458 
 459   FLAGS_OS=$OPENJDK_BUILD_OS
 460   FLAGS_OS_TYPE=$OPENJDK_BUILD_OS_TYPE
 461   FLAGS_CPU=$OPENJDK_BUILD_CPU
 462   FLAGS_CPU_ARCH=$OPENJDK_BUILD_CPU_ARCH
 463   FLAGS_CPU_BITS=$OPENJDK_BUILD_CPU_BITS
 464   FLAGS_CPU_ENDIAN=$OPENJDK_BUILD_CPU_ENDIAN
 465   FLAGS_CPU_LEGACY=$OPENJDK_BUILD_CPU_LEGACY
 466   FLAGS_CPU_LEGACY_LIB=$OPENJDK_BUILD_CPU_LEGACY_LIB
 467 
 468   FLAGS_SETUP_CFLAGS_CPU_DEP([BUILD], [OPENJDK_BUILD_], [BUILD_])
 469 
 470   CC="$CC_OLD"
 471   CXX="$CXX_OLD"
 472   CFLAGS="$CFLAGS_OLD"
 473   CXXFLAGS="$CXXFLAGS_OLD"
 474 ])
 475 
 476 ################################################################################
 477 # platform independent
 478 AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
 479 [
 480   #### OS DEFINES, these should be independent on toolchain
 481   if test "x$OPENJDK_TARGET_OS" = xlinux; then
 482     CFLAGS_OS_DEF_JVM="-DLINUX -D_FILE_OFFSET_BITS=64"
 483     CFLAGS_OS_DEF_JDK="-D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
 484   elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
 485     CFLAGS_OS_DEF_JVM="-D_ALLBSD_SOURCE -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE"
 486     CFLAGS_OS_DEF_JDK="-D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
 487   elif test "x$OPENJDK_TARGET_OS" = xaix; then
 488     CFLAGS_OS_DEF_JVM="-DAIX"
 489   elif test "x$OPENJDK_TARGET_OS" = xbsd; then
 490     CFLAGS_OS_DEF_JDK="-D_ALLBSD_SOURCE"
 491   elif test "x$OPENJDK_TARGET_OS" = xwindows; then
 492     CFLAGS_OS_DEF_JVM="-D_WINDOWS -DWIN32 -D_JNI_IMPLEMENTATION_"
 493   fi
 494 
 495   CFLAGS_OS_DEF_JDK="$CFLAGS_OS_DEF_JDK -D$OPENJDK_TARGET_OS_UPPERCASE"
 496 
 497   #### GLOBAL DEFINES
 498   # Set some common defines. These works for all compilers, but assume
 499   # -D is universally accepted.
 500 
 501   # Always enable optional macros for VM.
 502   ALWAYS_CFLAGS_JVM="-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
 503 
 504   # Setup some hard coded includes
 505   ALWAYS_CFLAGS_JDK=" \
 506       -I\$(SUPPORT_OUTPUTDIR)/modules_include/java.base \
 507       -I\$(SUPPORT_OUTPUTDIR)/modules_include/java.base/\$(OPENJDK_TARGET_OS_INCLUDE_SUBDIR) \
 508       -I${TOPDIR}/src/java.base/share/native/libjava \
 509       -I${TOPDIR}/src/java.base/$OPENJDK_TARGET_OS_TYPE/native/libjava \
 510       -I${TOPDIR}/src/hotspot/share/include \
 511       -I${TOPDIR}/src/hotspot/os/${HOTSPOT_TARGET_OS_TYPE}/include"
 512 
 513   ###############################################################################
 514 
 515   # Adjust flags according to debug level.
 516   # Setup debug/release defines
 517   if test "x$DEBUG_LEVEL" = xrelease; then
 518     DEBUG_CFLAGS_JDK="-DNDEBUG"
 519   else
 520     DEBUG_CFLAGS_JDK="-DDEBUG"
 521 
 522     if test "x$TOOLCHAIN_TYPE" = xxlc; then
 523       # We need '-qminimaltoc' or '-qpic=large -bbigtoc' if the TOC overflows.
 524       # Hotspot now overflows its 64K TOC (currently only for debug),
 525       # so for debug we build with '-qpic=large -bbigtoc'.
 526       DEBUG_CFLAGS_JVM="-qpic=large"
 527     fi
 528     if test "x$TOOLCHAIN_TYPE" = xclang && test "x$OPENJDK_TARGET_OS" = xaix; then
 529       DEBUG_CFLAGS_JVM="-fpic -mcmodel=large"
 530     fi
 531   fi
 532 
 533   if test "x$DEBUG_LEVEL" != xrelease; then
 534     DEBUG_OPTIONS_FLAGS_JDK="$CFLAGS_DEBUG_OPTIONS"
 535     DEBUG_SYMBOLS_CFLAGS_JDK="$CFLAGS_DEBUG_SYMBOLS"
 536   fi
 537 
 538   #### TOOLCHAIN DEFINES
 539 
 540   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 541     ALWAYS_DEFINES_JVM="-D_GNU_SOURCE -D_REENTRANT"
 542   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 543     ALWAYS_DEFINES_JVM="-D_GNU_SOURCE"
 544   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 545     ALWAYS_DEFINES_JVM="-D_REENTRANT"
 546     ALWAYS_DEFINES_JDK="-D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
 547   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 548     # Access APIs for Windows 8 and above
 549     # see https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170
 550     ALWAYS_DEFINES_JDK="-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0602 \
 551         -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -DWIN32 -DIAL"
 552     ALWAYS_DEFINES_JVM="-DNOMINMAX -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0602 \
 553         -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE"
 554   fi
 555 
 556   ###############################################################################
 557   #
 558   #
 559   # CFLAGS BASIC
 560   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 561     # COMMON to gcc and clang
 562     TOOLCHAIN_CFLAGS_JVM="-pipe -fno-rtti -fno-exceptions \
 563         -fvisibility=hidden -fno-strict-aliasing -fno-omit-frame-pointer"
 564   fi
 565 
 566   if test "x$TOOLCHAIN_TYPE" = xclang && test "x$OPENJDK_TARGET_OS" = xaix; then
 567     # clang compiler on aix needs -ffunction-sections
 568     TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -ffunction-sections -ftls-model -fno-math-errno -fstack-protector"
 569     TOOLCHAIN_CFLAGS_JDK="-ffunction-sections -fsigned-char -fstack-protector"
 570   fi
 571 
 572   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 573     TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -fstack-protector"
 574     TOOLCHAIN_CFLAGS_JDK="-pipe -fstack-protector"
 575     # reduce lib size on linux in link step, this needs also special compile flags
 576     # do this on s390x also for libjvm (where serviceability agent is not supported)
 577     if test "x$ENABLE_LINKTIME_GC" = xtrue; then
 578       TOOLCHAIN_CFLAGS_JDK="$TOOLCHAIN_CFLAGS_JDK -ffunction-sections -fdata-sections"
 579       if test "x$OPENJDK_TARGET_CPU" = xs390x; then
 580         TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -ffunction-sections -fdata-sections"
 581       fi
 582     fi
 583     # technically NOT for CXX (but since this gives *worse* performance, use
 584     # no-strict-aliasing everywhere!)
 585     TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing"
 586 
 587   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 588     # Restrict the debug information created by Clang to avoid
 589     # too big object files and speed the build up a little bit
 590     # (see http://llvm.org/bugs/show_bug.cgi?id=7554)
 591     TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -flimit-debug-info"
 592 
 593     # In principle the stack alignment below is cpu- and ABI-dependent and
 594     # should agree with values of StackAlignmentInBytes in various
 595     # src/hotspot/cpu/*/globalDefinitions_*.hpp files, but this value currently
 596     # works for all platforms.
 597     TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -mno-omit-leaf-frame-pointer -mstack-alignment=16"
 598 
 599     if test "x$OPENJDK_TARGET_OS" = xlinux; then
 600       if test "x$DEBUG_LEVEL" = xrelease; then
 601         # Clang does not inline as much as GCC does for functions with "inline" keyword by default.
 602         # This causes noticeable slowdown in pause time for G1, and possibly in other areas.
 603         # Increasing the inline hint threshold avoids the slowdown for Clang-built JVM.
 604         TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -mllvm -inlinehint-threshold=100000"
 605       fi
 606       TOOLCHAIN_CFLAGS_JDK="-pipe"
 607       TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing" # technically NOT for CXX
 608     fi
 609 
 610   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 611     # Suggested additions: -qsrcmsg to get improved error reporting
 612     # set -qtbtable=full for a better traceback table/better stacks in hs_err when xlc16 is used
 613     TOOLCHAIN_CFLAGS_JDK="-qtbtable=full -qchars=signed -qfullpath -qsaveopt -qstackprotect"  # add on both CFLAGS
 614     TOOLCHAIN_CFLAGS_JVM="-qtbtable=full -qtune=balanced -fno-exceptions \
 615         -qalias=noansi -qstrict -qtls=default -qnortti -qnoeh -qignerrno -qstackprotect"
 616   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 617     TOOLCHAIN_CFLAGS_JVM="-nologo -MD -Zc:preprocessor -Zc:strictStrings -MP"
 618     TOOLCHAIN_CFLAGS_JDK="-nologo -MD -Zc:preprocessor -Zc:strictStrings -Zc:wchar_t-"
 619   fi
 620 
 621   # CFLAGS C language level for JDK sources (hotspot only uses C++)
 622   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang || test "x$TOOLCHAIN_TYPE" = xxlc; then
 623     LANGSTD_CFLAGS="-std=c11"
 624   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 625     LANGSTD_CFLAGS="-std:c11"
 626   fi
 627   TOOLCHAIN_CFLAGS_JDK_CONLY="$LANGSTD_CFLAGS $TOOLCHAIN_CFLAGS_JDK_CONLY"
 628 
 629   # CXXFLAGS C++ language level for all of JDK, including Hotspot.
 630   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang || test "x$TOOLCHAIN_TYPE" = xxlc; then
 631     LANGSTD_CXXFLAGS="-std=c++14"
 632   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 633     LANGSTD_CXXFLAGS="-std:c++14"
 634   else
 635     AC_MSG_ERROR([Don't know how to enable C++14 for this toolchain])
 636   fi
 637   TOOLCHAIN_CFLAGS_JDK_CXXONLY="$TOOLCHAIN_CFLAGS_JDK_CXXONLY $LANGSTD_CXXFLAGS"
 638   TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM $LANGSTD_CXXFLAGS"
 639   ADLC_LANGSTD_CXXFLAGS="$LANGSTD_CXXFLAGS"
 640 
 641   # CFLAGS WARNINGS STUFF
 642   # Set JVM_CFLAGS warning handling
 643   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 644     WARNING_CFLAGS_JDK_CONLY="$WARNINGS_ENABLE_ALL_CFLAGS"
 645     WARNING_CFLAGS_JDK_CXXONLY="$WARNINGS_ENABLE_ALL_CXXFLAGS"
 646     WARNING_CFLAGS_JVM="$WARNINGS_ENABLE_ALL_CXXFLAGS"
 647 
 648   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 649     WARNING_CFLAGS="$WARNINGS_ENABLE_ALL"
 650 
 651   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 652     WARNING_CFLAGS="$WARNINGS_ENABLE_ALL"
 653 
 654   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 655     WARNING_CFLAGS=""  # currently left empty
 656   fi
 657 
 658   # Set some additional per-OS defines.
 659 
 660   # Additional macosx handling
 661   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 662     OS_CFLAGS="-DMAC_OS_X_VERSION_MIN_REQUIRED=$MACOSX_VERSION_MIN_NODOTS \
 663         -mmacosx-version-min=$MACOSX_VERSION_MIN"
 664 
 665     if test -n "$MACOSX_VERSION_MAX"; then
 666         OS_CFLAGS="$OS_CFLAGS \
 667             -DMAC_OS_X_VERSION_MAX_ALLOWED=$MACOSX_VERSION_MAX_NODOTS"
 668     fi
 669   fi
 670 
 671   OS_CFLAGS="$OS_CFLAGS -DLIBC=$OPENJDK_TARGET_LIBC"
 672   if test "x$OPENJDK_TARGET_LIBC" = xmusl; then
 673     OS_CFLAGS="$OS_CFLAGS -DMUSL_LIBC"
 674   fi
 675 
 676   # Where does this really belong??
 677   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 678     PICFLAG="-fPIC"
 679     PIEFLAG="-fPIE"
 680   elif test "x$TOOLCHAIN_TYPE" = xclang && test "x$OPENJDK_TARGET_OS" = xaix; then
 681     JVM_PICFLAG="-fpic -mcmodel=large -Wl,-bbigtoc
 682     JDK_PICFLAG="-fpic
 683   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 684     # '-qpic' defaults to 'qpic=small'. This means that the compiler generates only
 685     # one instruction for accessing the TOC. If the TOC grows larger than 64K, the linker
 686     # will have to patch this single instruction with a call to some out-of-order code which
 687     # does the load from the TOC. This is of course slower, and we also would have
 688     # to use '-bbigtoc' for linking anyway so we could also change the PICFLAG to 'qpic=large'.
 689     # With 'qpic=large' the compiler will by default generate a two-instruction sequence which
 690     # can be patched directly by the linker and does not require a jump to out-of-order code.
 691     #
 692     # Since large TOC causes perf. overhead, only pay it where we must. Currently this is
 693     # for all libjvm variants (both gtest and normal) but no other binaries. So, build
 694     # libjvm with -qpic=large and link with -bbigtoc.
 695     JVM_PICFLAG="-qpic=large"
 696     JDK_PICFLAG="-qpic"
 697   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 698     PICFLAG=""
 699   fi
 700 
 701   if test "x$TOOLCHAIN_TYPE" != xxlc; then
 702     JVM_PICFLAG="$PICFLAG"
 703     JDK_PICFLAG="$PICFLAG"
 704   fi
 705 
 706   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 707     # Linking is different on MacOSX
 708     JDK_PICFLAG=''
 709     if test "x$STATIC_BUILD" = xtrue; then
 710       JVM_PICFLAG=""
 711     fi
 712   fi
 713 
 714   # Extra flags needed when building optional static versions of certain
 715   # JDK libraries.
 716   STATIC_LIBS_CFLAGS="-DSTATIC_BUILD=1"
 717   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 718     STATIC_LIBS_CFLAGS="$STATIC_LIBS_CFLAGS -ffunction-sections -fdata-sections \
 719       -DJNIEXPORT='__attribute__((visibility(\"default\")))'"
 720   else
 721     STATIC_LIBS_CFLAGS="$STATIC_LIBS_CFLAGS -DJNIEXPORT="
 722   fi
 723   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 724     # Disable relax-relocation to enable compatibility with older linkers
 725     RELAX_RELOCATIONS_FLAG="-Xassembler -mrelax-relocations=no"
 726     FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${RELAX_RELOCATIONS_FLAG}],
 727         IF_TRUE: [STATIC_LIBS_CFLAGS="$STATIC_LIBS_CFLAGS ${RELAX_RELOCATIONS_FLAG}"])
 728   fi
 729   AC_SUBST(STATIC_LIBS_CFLAGS)
 730 ])
 731 
 732 ################################################################################
 733 # $1 - Either BUILD or TARGET to pick the correct OS/CPU variables to check
 734 #      conditionals against.
 735 # $2 - Optional prefix for each variable defined.
 736 # $3 - Optional prefix for compiler variables (either BUILD_ or nothing).
 737 AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
 738 [
 739   #### CPU DEFINES, these should (in theory) be independent on toolchain
 740 
 741   # Setup target CPU
 742   # Setup endianness
 743   if test "x$FLAGS_CPU_ENDIAN" = xlittle; then
 744     $1_DEFINES_CPU_JVM="-DVM_LITTLE_ENDIAN"
 745     $1_DEFINES_CPU_JDK="-D_LITTLE_ENDIAN"
 746   else
 747     $1_DEFINES_CPU_JDK="-D_BIG_ENDIAN"
 748   fi
 749 
 750   # setup CPU bit size
 751   $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -DARCH='\"$FLAGS_CPU_LEGACY\"' \
 752       -D$FLAGS_CPU_LEGACY"
 753 
 754   if test "x$FLAGS_CPU_BITS" = x64 && test "x$FLAGS_OS" != xaix; then
 755     # xlc on AIX defines _LP64=1 by default and issues a warning if we redefine it.
 756     $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -D_LP64=1"
 757     $1_DEFINES_CPU_JVM="${$1_DEFINES_CPU_JVM} -D_LP64=1"
 758   fi
 759 
 760   # toolchain dependent, per-cpu
 761   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 762     if test "x$FLAGS_CPU" = xaarch64; then
 763       $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -D_ARM64_ -Darm64"
 764     elif test "x$FLAGS_CPU" = xx86_64; then
 765       $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -D_AMD64_ -Damd64"
 766     else
 767       $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -D_X86_ -Dx86"
 768     fi
 769   fi
 770 
 771   # CFLAGS PER CPU
 772   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 773     # COMMON to gcc and clang
 774     AC_MSG_CHECKING([if $1 is x86])
 775     if test "x$FLAGS_CPU" = xx86; then
 776       AC_MSG_RESULT([yes])
 777       AC_MSG_CHECKING([if control flow protection is enabled by additional compiler flags])
 778       if echo "${EXTRA_CFLAGS}${EXTRA_CXXFLAGS}${EXTRA_ASFLAGS}" | ${GREP} -q 'fcf-protection' ; then
 779         # cf-protection requires CMOV and thus i686
 780         $1_CFLAGS_CPU="-march=i686"
 781         AC_MSG_RESULT([yes, forcing ${$1_CFLAGS_CPU}])
 782       else
 783         # Force compatibility with i586 on 32 bit intel platforms.
 784         $1_CFLAGS_CPU="-march=i586"
 785         AC_MSG_RESULT([no, forcing ${$1_CFLAGS_CPU}])
 786       fi
 787     else
 788       AC_MSG_RESULT([no])
 789     fi
 790   fi
 791 
 792   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 793     if test "x$FLAGS_CPU" = xaarch64; then
 794       # -Wno-psabi to get rid of annoying "note: parameter passing for argument of type '<type> changed in GCC 9.1"
 795       $1_CFLAGS_CPU="-Wno-psabi"
 796     elif test "x$FLAGS_CPU" = xarm; then
 797       # -Wno-psabi to get rid of annoying "note: the mangling of 'va_list' has changed in GCC 4.4"
 798       $1_CFLAGS_CPU="-fsigned-char -Wno-psabi $ARM_ARCH_TYPE_FLAGS $ARM_FLOAT_TYPE_FLAGS -DJDK_ARCH_ABI_PROP_NAME='\"\$(JDK_ARCH_ABI_PROP_NAME)\"'"
 799       $1_CFLAGS_CPU_JVM="-DARM"
 800     elif test "x$FLAGS_CPU_ARCH" = xppc; then
 801       $1_CFLAGS_CPU_JVM="-minsert-sched-nops=regroup_exact -mno-multiple -mno-string"
 802       if test "x$FLAGS_CPU" = xppc64; then
 803         # -mminimal-toc fixes `relocation truncated to fit' error for gcc 4.1.
 804         # Use ppc64 instructions, but schedule for power5
 805         $1_CFLAGS_CPU_JVM="${$1_CFLAGS_CPU_JVM} -mminimal-toc -mcpu=powerpc64 -mtune=power5"
 806       elif test "x$FLAGS_CPU" = xppc64le; then
 807         # Little endian machine uses ELFv2 ABI.
 808         # Use Power8, this is the first CPU to support PPC64 LE with ELFv2 ABI.
 809         $1_CFLAGS_CPU_JVM="${$1_CFLAGS_CPU_JVM} -DABI_ELFv2 -mcpu=power8 -mtune=power8"
 810       fi
 811     elif test "x$FLAGS_CPU" = xs390x; then
 812       $1_CFLAGS_CPU="-mbackchain -march=z10"
 813     fi
 814 
 815     if test "x$FLAGS_CPU_ARCH" != xarm &&  test "x$FLAGS_CPU_ARCH" != xppc; then
 816       # for all archs except arm and ppc, prevent gcc to omit frame pointer
 817       $1_CFLAGS_CPU_JDK="${$1_CFLAGS_CPU_JDK} -fno-omit-frame-pointer"
 818     fi
 819 
 820   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 821     if test "x$FLAGS_OS" = xlinux; then
 822       # ppc test not really needed for clang
 823       if test "x$FLAGS_CPU_ARCH" != xarm &&  test "x$FLAGS_CPU_ARCH" != xppc; then
 824         # for all archs except arm and ppc, prevent gcc to omit frame pointer
 825         $1_CFLAGS_CPU_JDK="${$1_CFLAGS_CPU_JDK} -fno-omit-frame-pointer"
 826       fi
 827     fi
 828     if test "x$OPENJDK_TARGET_OS" = xaix; then
 829       $1_CFLAGS_CPU="-mcpu=pwr8"
 830     fi
 831 
 832   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 833     if test "x$FLAGS_CPU" = xppc64; then
 834       $1_CFLAGS_CPU_JVM="-qarch=ppc64"
 835     fi
 836 
 837   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 838     if test "x$FLAGS_CPU" = xx86; then
 839       $1_CFLAGS_CPU_JVM="-arch:IA32"
 840     elif test "x$OPENJDK_TARGET_CPU" = xx86_64; then
 841       if test "x$DEBUG_LEVEL" != xrelease; then
 842         # NOTE: This is probably redundant; -homeparams is default on
 843         # non-release builds.
 844         $1_CFLAGS_CPU_JVM="-homeparams"
 845       fi
 846     fi
 847   fi
 848 
 849   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 850     FLAGS_SETUP_GCC6_COMPILER_FLAGS($1, $3)
 851     $1_TOOLCHAIN_CFLAGS="${$1_GCC6_CFLAGS}"
 852 
 853     $1_WARNING_CFLAGS_JVM="-Wno-format-zero-length -Wtype-limits -Wuninitialized"
 854   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 855     NO_DELETE_NULL_POINTER_CHECKS_CFLAG="-fno-delete-null-pointer-checks"
 856     FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$NO_DELETE_NULL_POINTER_CHECKS_CFLAG],
 857         PREFIX: $3,
 858         IF_FALSE: [
 859             NO_DELETE_NULL_POINTER_CHECKS_CFLAG=
 860         ]
 861     )
 862     $1_TOOLCHAIN_CFLAGS="${NO_DELETE_NULL_POINTER_CHECKS_CFLAG}"
 863   fi
 864 
 865   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 866     REPRODUCIBLE_CFLAGS="-experimental:deterministic"
 867     FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${REPRODUCIBLE_CFLAGS}],
 868         PREFIX: $3,
 869         IF_FALSE: [
 870             REPRODUCIBLE_CFLAGS=
 871         ]
 872     )
 873     AC_SUBST(REPRODUCIBLE_CFLAGS)
 874   fi
 875 
 876   # Prevent the __FILE__ macro from generating absolute paths into the built
 877   # binaries. Depending on toolchain, different mitigations are possible.
 878   # * GCC and Clang of new enough versions have -fmacro-prefix-map.
 879   # * For most other toolchains, supplying all source files and -I flags as
 880   #   relative paths fixes the issue.
 881   FILE_MACRO_CFLAGS=
 882   if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
 883     if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 884       # Check if compiler supports -fmacro-prefix-map. If so, use that to make
 885       # the __FILE__ macro resolve to paths relative to the workspace root.
 886       workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
 887       FILE_MACRO_CFLAGS="-fmacro-prefix-map=${workspace_root_trailing_slash}="
 888       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${FILE_MACRO_CFLAGS}],
 889           PREFIX: $3,
 890           IF_FALSE: [
 891               FILE_MACRO_CFLAGS=
 892           ]
 893       )
 894     elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 895       # There is a known issue with the pathmap if the mapping is made to the
 896       # empty string. Add a minimal string "s" as prefix to work around this.
 897       # PATHMAP_FLAGS is also added to LDFLAGS in flags-ldflags.m4.
 898       PATHMAP_FLAGS="-pathmap:${WORKSPACE_ROOT}=s"
 899       FILE_MACRO_CFLAGS="$PATHMAP_FLAGS"
 900       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${FILE_MACRO_CFLAGS}],
 901           PREFIX: $3,
 902           IF_FALSE: [
 903               PATHMAP_FLAGS=
 904               FILE_MACRO_CFLAGS=
 905           ]
 906       )
 907       if test "x$FILE_MACRO_CFLAGS" != x; then
 908         # Add -pathmap for all VS system include paths using Windows
 909         # full Long path name that is generated by the compiler
 910         # Not enabled under WSL as there is no easy way to obtain the
 911         # Windows full long paths, thus reproducible WSL builds will
 912         # depend on building with the same VS toolchain install location.
 913         if test "x$OPENJDK_BUILD_OS_ENV" != "xwindows.wsl1" && test "x$OPENJDK_BUILD_OS_ENV" != "xwindows.wsl2"; then
 914           for ipath in ${$3SYSROOT_CFLAGS}; do
 915               if test "x${ipath:0:2}" == "x-I"; then
 916                   ipath_path=${ipath#"-I"}
 917                   UTIL_FIXUP_WIN_LONG_PATH(ipath_path)
 918                   FILE_MACRO_CFLAGS="$FILE_MACRO_CFLAGS -pathmap:\"$ipath_path\"=vsi"
 919               fi
 920           done
 921         fi
 922       fi
 923     fi
 924 
 925     AC_MSG_CHECKING([how to prevent absolute paths in output])
 926     if test "x$FILE_MACRO_CFLAGS" != x; then
 927       AC_MSG_RESULT([using compiler options])
 928     else
 929       AC_MSG_RESULT([using relative paths])
 930     fi
 931   fi
 932   AC_SUBST(FILE_MACRO_CFLAGS)
 933 
 934   FLAGS_SETUP_BRANCH_PROTECTION
 935 
 936   # EXPORT to API
 937   CFLAGS_JVM_COMMON="$ALWAYS_CFLAGS_JVM $ALWAYS_DEFINES_JVM \
 938       $TOOLCHAIN_CFLAGS_JVM ${$1_TOOLCHAIN_CFLAGS_JVM} \
 939       $OS_CFLAGS $OS_CFLAGS_JVM $CFLAGS_OS_DEF_JVM $DEBUG_CFLAGS_JVM \
 940       $WARNING_CFLAGS $WARNING_CFLAGS_JVM $JVM_PICFLAG $FILE_MACRO_CFLAGS \
 941       $REPRODUCIBLE_CFLAGS $BRANCH_PROTECTION_CFLAGS"
 942 
 943   CFLAGS_JDK_COMMON="$ALWAYS_CFLAGS_JDK $ALWAYS_DEFINES_JDK $TOOLCHAIN_CFLAGS_JDK \
 944       $OS_CFLAGS $CFLAGS_OS_DEF_JDK $DEBUG_CFLAGS_JDK $DEBUG_OPTIONS_FLAGS_JDK \
 945       $WARNING_CFLAGS $WARNING_CFLAGS_JDK $DEBUG_SYMBOLS_CFLAGS_JDK \
 946       $FILE_MACRO_CFLAGS $REPRODUCIBLE_CFLAGS $BRANCH_PROTECTION_CFLAGS"
 947 
 948   # Use ${$2EXTRA_CFLAGS} to block EXTRA_CFLAGS to be added to build flags.
 949   # (Currently we don't have any OPENJDK_BUILD_EXTRA_CFLAGS, but that might
 950   # change in the future.)
 951 
 952   CFLAGS_JDK_COMMON_CONLY="$TOOLCHAIN_CFLAGS_JDK_CONLY  \
 953       $WARNING_CFLAGS_JDK_CONLY ${$2EXTRA_CFLAGS}"
 954   CFLAGS_JDK_COMMON_CXXONLY="$ALWAYS_DEFINES_JDK_CXXONLY \
 955       $TOOLCHAIN_CFLAGS_JDK_CXXONLY \
 956       ${$1_TOOLCHAIN_CFLAGS_JDK_CXXONLY} \
 957       $WARNING_CFLAGS_JDK_CXXONLY ${$2EXTRA_CXXFLAGS}"
 958 
 959   $1_CFLAGS_JVM="${$1_DEFINES_CPU_JVM} ${$1_CFLAGS_CPU} ${$1_CFLAGS_CPU_JVM} ${$1_TOOLCHAIN_CFLAGS} ${$1_WARNING_CFLAGS_JVM}"
 960   $1_CFLAGS_JDK="${$1_DEFINES_CPU_JDK} ${$1_CFLAGS_CPU} ${$1_CFLAGS_CPU_JDK} ${$1_TOOLCHAIN_CFLAGS}"
 961 
 962   $2JVM_CFLAGS="$CFLAGS_JVM_COMMON ${$1_CFLAGS_JVM} ${$2EXTRA_CXXFLAGS}"
 963 
 964   $2CFLAGS_JDKEXE="$CFLAGS_JDK_COMMON $CFLAGS_JDK_COMMON_CONLY ${$1_CFLAGS_JDK} $PIEFLAG"
 965   $2CXXFLAGS_JDKEXE="$CFLAGS_JDK_COMMON $CFLAGS_JDK_COMMON_CXXONLY ${$1_CFLAGS_JDK} $PIEFLAG"
 966   $2CFLAGS_JDKLIB="$CFLAGS_JDK_COMMON $CFLAGS_JDK_COMMON_CONLY ${$1_CFLAGS_JDK} \
 967       $JDK_PICFLAG ${$1_CFLAGS_CPU_JDK_LIBONLY}"
 968   $2CXXFLAGS_JDKLIB="$CFLAGS_JDK_COMMON $CFLAGS_JDK_COMMON_CXXONLY ${$1_CFLAGS_JDK} \
 969       $JDK_PICFLAG ${$1_CFLAGS_CPU_JDK_LIBONLY}"
 970 
 971   AC_SUBST($2JVM_CFLAGS)
 972   AC_SUBST($2CFLAGS_JDKLIB)
 973   AC_SUBST($2CFLAGS_JDKEXE)
 974   AC_SUBST($2CXXFLAGS_JDKLIB)
 975   AC_SUBST($2CXXFLAGS_JDKEXE)
 976   AC_SUBST($2ADLC_LANGSTD_CXXFLAGS)
 977 
 978   COMPILER_FP_CONTRACT_OFF_FLAG="-ffp-contract=off"
 979   # Check that the compiler supports -ffp-contract=off flag
 980   # Set FDLIBM_CFLAGS to -ffp-contract=off if it does. Empty
 981   # otherwise.
 982   # These flags are required for GCC-based builds of
 983   # fdlibm with optimization without losing precision.
 984   # Notably, -ffp-contract=off needs to be added for GCC >= 4.6.
 985   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
 986     FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${COMPILER_FP_CONTRACT_OFF_FLAG}],
 987         PREFIX: $3,
 988         IF_TRUE: [$2FDLIBM_CFLAGS=${COMPILER_FP_CONTRACT_OFF_FLAG}],
 989         IF_FALSE: [$2FDLIBM_CFLAGS=""])
 990   fi
 991   AC_SUBST($2FDLIBM_CFLAGS)
 992 ])
 993 
 994 # FLAGS_SETUP_GCC6_COMPILER_FLAGS([PREFIX])
 995 # Arguments:
 996 # $1 - Prefix for each variable defined.
 997 # $2 - Prefix for compiler variables (either BUILD_ or nothing).
 998 AC_DEFUN([FLAGS_SETUP_GCC6_COMPILER_FLAGS],
 999 [
1000   # These flags are required for GCC 6 builds as undefined behavior in OpenJDK code
1001   # runs afoul of the more aggressive versions of these optimizations.
1002   # Notably, value range propagation now assumes that the this pointer of C++
1003   # member functions is non-null.
1004   NO_DELETE_NULL_POINTER_CHECKS_CFLAG="-fno-delete-null-pointer-checks"
1005   FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$NO_DELETE_NULL_POINTER_CHECKS_CFLAG],
1006       PREFIX: $2, IF_FALSE: [NO_DELETE_NULL_POINTER_CHECKS_CFLAG=""])
1007   NO_LIFETIME_DSE_CFLAG="-fno-lifetime-dse"
1008   FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$NO_LIFETIME_DSE_CFLAG],
1009       PREFIX: $2, IF_FALSE: [NO_LIFETIME_DSE_CFLAG=""])
1010   $1_GCC6_CFLAGS="${NO_DELETE_NULL_POINTER_CHECKS_CFLAG} ${NO_LIFETIME_DSE_CFLAG}"
1011 ])
1012 
1013 AC_DEFUN_ONCE([FLAGS_SETUP_BRANCH_PROTECTION],
1014 [
1015   # Is branch protection available?
1016   BRANCH_PROTECTION_AVAILABLE=false
1017   BRANCH_PROTECTION_FLAG="-mbranch-protection=standard"
1018 
1019   if test "x$OPENJDK_TARGET_CPU" = xaarch64; then
1020     if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
1021       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${BRANCH_PROTECTION_FLAG}],
1022           IF_TRUE: [BRANCH_PROTECTION_AVAILABLE=true])
1023     fi
1024   fi
1025 
1026   BRANCH_PROTECTION_CFLAGS=""
1027   UTIL_ARG_ENABLE(NAME: branch-protection, DEFAULT: false,
1028       RESULT: USE_BRANCH_PROTECTION, AVAILABLE: $BRANCH_PROTECTION_AVAILABLE,
1029       DESC: [enable branch protection when compiling C/C++],
1030       IF_ENABLED: [ BRANCH_PROTECTION_CFLAGS=${BRANCH_PROTECTION_FLAG}])
1031   AC_SUBST(BRANCH_PROTECTION_CFLAGS)
1032 ])