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