1 #
   2 # Copyright (c) 2011, 2016, 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 # Reset the global CFLAGS/LDFLAGS variables and initialize them with the
  27 # corresponding configure arguments instead
  28 AC_DEFUN_ONCE([FLAGS_SETUP_USER_SUPPLIED_FLAGS],
  29 [
  30   if test "x$CFLAGS" != "x${ADDED_CFLAGS}"; then
  31     AC_MSG_WARN([Ignoring CFLAGS($CFLAGS) found in environment. Use --with-extra-cflags])
  32   fi
  33 
  34   if test "x$CXXFLAGS" != "x${ADDED_CXXFLAGS}"; then
  35     AC_MSG_WARN([Ignoring CXXFLAGS($CXXFLAGS) found in environment. Use --with-extra-cxxflags])
  36   fi
  37 
  38   if test "x$LDFLAGS" != "x${ADDED_LDFLAGS}"; then
  39     AC_MSG_WARN([Ignoring LDFLAGS($LDFLAGS) found in environment. Use --with-extra-ldflags])
  40   fi
  41 
  42   AC_ARG_WITH(extra-cflags, [AS_HELP_STRING([--with-extra-cflags],
  43       [extra flags to be used when compiling jdk c-files])])
  44 
  45   AC_ARG_WITH(extra-cxxflags, [AS_HELP_STRING([--with-extra-cxxflags],
  46       [extra flags to be used when compiling jdk c++-files])])
  47 
  48   AC_ARG_WITH(extra-ldflags, [AS_HELP_STRING([--with-extra-ldflags],
  49       [extra flags to be used when linking jdk])])
  50 
  51   EXTRA_CFLAGS="$with_extra_cflags"
  52   EXTRA_CXXFLAGS="$with_extra_cxxflags"
  53   EXTRA_LDFLAGS="$with_extra_ldflags"
  54 
  55   # Hotspot needs these set in their legacy form
  56   LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS $EXTRA_CFLAGS"
  57   LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS $EXTRA_CXXFLAGS"
  58   LEGACY_EXTRA_LDFLAGS="$LEGACY_EXTRA_LDFLAGS $EXTRA_LDFLAGS"
  59 
  60   AC_SUBST(LEGACY_EXTRA_CFLAGS)
  61   AC_SUBST(LEGACY_EXTRA_CXXFLAGS)
  62   AC_SUBST(LEGACY_EXTRA_LDFLAGS)
  63 
  64   AC_SUBST(EXTRA_CFLAGS)
  65   AC_SUBST(EXTRA_CXXFLAGS)
  66   AC_SUBST(EXTRA_LDFLAGS)
  67 
  68   # The global CFLAGS and LDLAGS variables are used by configure tests and
  69   # should include the extra parameters
  70   CFLAGS="$EXTRA_CFLAGS"
  71   CXXFLAGS="$EXTRA_CXXFLAGS"
  72   LDFLAGS="$EXTRA_LDFLAGS"
  73   CPPFLAGS=""
  74 ])
  75 
  76 # Setup the sysroot flags and add them to global CFLAGS and LDFLAGS so
  77 # that configure can use them while detecting compilers.
  78 # TOOLCHAIN_TYPE is available here.
  79 # Param 1 - Optional prefix to all variables. (e.g BUILD_)
  80 AC_DEFUN([FLAGS_SETUP_SYSROOT_FLAGS],
  81 [
  82   if test "x[$]$1SYSROOT" != "x"; then
  83     if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
  84       if test "x$OPENJDK_TARGET_OS" = xsolaris; then
  85         # Solaris Studio does not have a concept of sysroot. Instead we must
  86         # make sure the default include and lib dirs are appended to each
  87         # compile and link command line. Must also add -I-xbuiltin to enable
  88         # inlining of system functions and intrinsics.
  89         $1SYSROOT_CFLAGS="-I-xbuiltin -I[$]$1SYSROOT/usr/include"
  90         $1SYSROOT_LDFLAGS="-L[$]$1SYSROOT/usr/lib$OPENJDK_TARGET_CPU_ISADIR \
  91             -L[$]$1SYSROOT/lib$OPENJDK_TARGET_CPU_ISADIR"
  92       fi
  93     elif test "x$TOOLCHAIN_TYPE" = xgcc; then
  94       $1SYSROOT_CFLAGS="--sysroot=[$]$1SYSROOT"
  95       $1SYSROOT_LDFLAGS="--sysroot=[$]$1SYSROOT"
  96     elif test "x$TOOLCHAIN_TYPE" = xclang; then
  97       $1SYSROOT_CFLAGS="-isysroot [$]$1SYSROOT"
  98       $1SYSROOT_LDFLAGS="-isysroot [$]$1SYSROOT"
  99     fi
 100     # Propagate the sysroot args to hotspot
 101     $1LEGACY_EXTRA_CFLAGS="[$]$1LEGACY_EXTRA_CFLAGS [$]$1SYSROOT_CFLAGS"
 102     $1LEGACY_EXTRA_CXXFLAGS="[$]$1LEGACY_EXTRA_CXXFLAGS [$]$1SYSROOT_CFLAGS"
 103     $1LEGACY_EXTRA_LDFLAGS="[$]$1LEGACY_EXTRA_LDFLAGS [$]$1SYSROOT_LDFLAGS"
 104     # The global CFLAGS and LDFLAGS variables need these for configure to function
 105     $1CFLAGS="[$]$1CFLAGS [$]$1SYSROOT_CFLAGS"
 106     $1CPPFLAGS="[$]$1CPPFLAGS [$]$1SYSROOT_CFLAGS"
 107     $1CXXFLAGS="[$]$1CXXFLAGS [$]$1SYSROOT_CFLAGS"
 108     $1LDFLAGS="[$]$1LDFLAGS [$]$1SYSROOT_LDFLAGS"
 109   fi
 110 
 111   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 112     # We also need -iframework<path>/System/Library/Frameworks
 113     $1SYSROOT_CFLAGS="[$]$1SYSROOT_CFLAGS -iframework [$]$1SYSROOT/System/Library/Frameworks"
 114     $1SYSROOT_LDFLAGS="[$]$1SYSROOT_LDFLAGS -iframework [$]$1SYSROOT/System/Library/Frameworks"
 115     # These always need to be set, or we can't find the frameworks embedded in JavaVM.framework
 116     # set this here so it doesn't have to be peppered throughout the forest
 117     $1SYSROOT_CFLAGS="[$]$1SYSROOT_CFLAGS -F [$]$1SYSROOT/System/Library/Frameworks/JavaVM.framework/Frameworks"
 118     $1SYSROOT_LDFLAGS="[$]$1SYSROOT_LDFLAGS -F [$]$1SYSROOT/System/Library/Frameworks/JavaVM.framework/Frameworks"
 119   fi
 120 
 121   AC_SUBST($1SYSROOT_CFLAGS)
 122   AC_SUBST($1SYSROOT_LDFLAGS)
 123 ])
 124 
 125 AC_DEFUN_ONCE([FLAGS_SETUP_INIT_FLAGS],
 126 [
 127   # COMPILER_TARGET_BITS_FLAG  : option for selecting 32- or 64-bit output
 128   # COMPILER_COMMAND_FILE_FLAG : option for passing a command file to the compiler
 129   # COMPILER_BINDCMD_FILE_FLAG : option for specifying a file which saves the binder
 130   #                              commands produced by the link step (currently AIX only)
 131   if test "x$TOOLCHAIN_TYPE" = xxlc; then
 132     COMPILER_TARGET_BITS_FLAG="-q"
 133     COMPILER_COMMAND_FILE_FLAG="-f"
 134     COMPILER_BINDCMD_FILE_FLAG="-bloadmap:"
 135   else
 136     COMPILER_TARGET_BITS_FLAG="-m"
 137     COMPILER_COMMAND_FILE_FLAG="@"
 138     COMPILER_BINDCMD_FILE_FLAG=""
 139 
 140     # The solstudio linker does not support @-files.
 141     if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 142       COMPILER_COMMAND_FILE_FLAG=
 143     fi
 144 
 145     # Check if @file is supported by gcc
 146     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 147       AC_MSG_CHECKING([if @file is supported by gcc])
 148       # Extra emtpy "" to prevent ECHO from interpreting '--version' as argument
 149       $ECHO "" "--version" > command.file
 150       if $CXX @command.file 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD; then
 151         AC_MSG_RESULT(yes)
 152         COMPILER_COMMAND_FILE_FLAG="@"
 153       else
 154         AC_MSG_RESULT(no)
 155         COMPILER_COMMAND_FILE_FLAG=
 156       fi
 157       $RM command.file
 158     fi
 159   fi
 160   AC_SUBST(COMPILER_TARGET_BITS_FLAG)
 161   AC_SUBST(COMPILER_COMMAND_FILE_FLAG)
 162   AC_SUBST(COMPILER_BINDCMD_FILE_FLAG)
 163 
 164   # FIXME: figure out if we should select AR flags depending on OS or toolchain.
 165   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 166     ARFLAGS="-r"
 167   elif test "x$OPENJDK_TARGET_OS" = xaix; then
 168     ARFLAGS="-X64"
 169   elif test "x$OPENJDK_TARGET_OS" = xwindows; then
 170     # lib.exe is used as AR to create static libraries.
 171     ARFLAGS="-nologo -NODEFAULTLIB:MSVCRT"
 172   else
 173     ARFLAGS=""
 174   fi
 175   AC_SUBST(ARFLAGS)
 176 
 177   ## Setup strip.
 178   # FIXME: should this really be per platform, or should it be per toolchain type?
 179   # strip is not provided by clang or solstudio; so guessing platform makes most sense.
 180   # FIXME: we should really only export STRIPFLAGS from here, not POST_STRIP_CMD.
 181   if test "x$OPENJDK_TARGET_OS" = xlinux; then
 182     STRIPFLAGS="-g"
 183   elif test "x$OPENJDK_TARGET_OS" = xsolaris; then
 184     STRIPFLAGS="-x"
 185   elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
 186     STRIPFLAGS="-S"
 187   elif test "x$OPENJDK_TARGET_OS" = xaix; then
 188     STRIPFLAGS="-X32_64"
 189   fi
 190 
 191   AC_SUBST(STRIPFLAGS)
 192 
 193   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 194     CC_OUT_OPTION=-Fo
 195     EXE_OUT_OPTION=-out:
 196     LD_OUT_OPTION=-out:
 197     AR_OUT_OPTION=-out:
 198   else
 199     # The option used to specify the target .o,.a or .so file.
 200     # When compiling, how to specify the to be created object file.
 201     CC_OUT_OPTION='-o$(SPACE)'
 202     # When linking, how to specify the to be created executable.
 203     EXE_OUT_OPTION='-o$(SPACE)'
 204     # When linking, how to specify the to be created dynamically linkable library.
 205     LD_OUT_OPTION='-o$(SPACE)'
 206     # When archiving, how to specify the to be create static archive for object files.
 207     AR_OUT_OPTION='rcs$(SPACE)'
 208   fi
 209   AC_SUBST(CC_OUT_OPTION)
 210   AC_SUBST(EXE_OUT_OPTION)
 211   AC_SUBST(LD_OUT_OPTION)
 212   AC_SUBST(AR_OUT_OPTION)
 213 
 214   # On Windows, we need to set RC flags.
 215   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 216     RC_FLAGS="-nologo -l0x409"
 217     JVM_RCFLAGS="-nologo"
 218     if test "x$DEBUG_LEVEL" = xrelease; then
 219       RC_FLAGS="$RC_FLAGS -DNDEBUG"
 220       JVM_RCFLAGS="$JVM_RCFLAGS -DNDEBUG"
 221     fi
 222 
 223     # The version variables used to create RC_FLAGS may be overridden
 224     # in a custom configure script, or possibly the command line.
 225     # Let those variables be expanded at make time in spec.gmk.
 226     # The \$ are escaped to the shell, and the $(...) variables
 227     # are evaluated by make.
 228     RC_FLAGS="$RC_FLAGS \
 229         -D\"JDK_VERSION_STRING=\$(VERSION_STRING)\" \
 230         -D\"JDK_COMPANY=\$(COMPANY_NAME)\" \
 231         -D\"JDK_COMPONENT=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) binary\" \
 232         -D\"JDK_VER=\$(VERSION_NUMBER)\" \
 233         -D\"JDK_COPYRIGHT=Copyright \xA9 $COPYRIGHT_YEAR\" \
 234         -D\"JDK_NAME=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) \$(VERSION_MAJOR)\" \
 235         -D\"JDK_FVER=\$(subst .,\$(COMMA),\$(VERSION_NUMBER_FOUR_POSITIONS))\""
 236 
 237     JVM_RCFLAGS="$JVM_RCFLAGS \
 238         -D\"HS_BUILD_ID=\$(VERSION_STRING)\" \
 239         -D\"HS_COMPANY=\$(COMPANY_NAME)\" \
 240         -D\"JDK_DOTVER=\$(VERSION_NUMBER_FOUR_POSITIONS)\" \
 241         -D\"HS_COPYRIGHT=Copyright $COPYRIGHT_YEAR\" \
 242         -D\"HS_NAME=\$(PRODUCT_NAME) \$(VERSION_SHORT)\" \
 243         -D\"JDK_VER=\$(subst .,\$(COMMA),\$(VERSION_NUMBER_FOUR_POSITIONS))\" \
 244         -D\"HS_FNAME=jvm.dll\" \
 245         -D\"HS_INTERNAL_NAME=jvm\""
 246   fi
 247   AC_SUBST(RC_FLAGS)
 248   AC_SUBST(JVM_RCFLAGS)
 249 
 250   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 251     # silence copyright notice and other headers.
 252     COMMON_CCXXFLAGS="$COMMON_CCXXFLAGS -nologo"
 253   fi
 254 ])
 255 
 256 AC_DEFUN([FLAGS_SETUP_COMPILER_FLAGS_FOR_LIBS],
 257 [
 258   ###############################################################################
 259   #
 260   # How to compile shared libraries.
 261   #
 262 
 263   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 264     PICFLAG="-fPIC"
 265     C_FLAG_REORDER=''
 266     CXX_FLAG_REORDER=''
 267 
 268     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 269       # Linking is different on MacOSX
 270       if test "x$STATIC_BUILD" = xtrue; then
 271         SHARED_LIBRARY_FLAGS ='-undefined dynamic_lookup'
 272       else
 273         SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
 274         JVM_CFLAGS="$JVM_CFLAGS $PICFLAG"
 275       fi
 276       SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path/.'
 277       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 278       SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
 279       SET_SHARED_LIBRARY_MAPFILE='-Wl,-exported_symbols_list,[$]1'
 280     else
 281       # Default works for linux, might work on other platforms as well.
 282       SHARED_LIBRARY_FLAGS='-shared'
 283       SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$$$ORIGIN[$]1'
 284       SET_SHARED_LIBRARY_ORIGIN="-Wl,-z,origin $SET_EXECUTABLE_ORIGIN"
 285       SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
 286       SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
 287     fi
 288   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 289     C_FLAG_REORDER=''
 290     CXX_FLAG_REORDER=''
 291 
 292     if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 293       # Linking is different on MacOSX
 294       PICFLAG=''
 295       SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
 296       SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path/.'
 297       SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 298       SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
 299       SET_SHARED_LIBRARY_MAPFILE='-Wl,-exported_symbols_list,[$]1'
 300 
 301       if test "x$STATIC_BUILD" = xfalse; then
 302         JVM_CFLAGS="$JVM_CFLAGS -fPIC"
 303       fi
 304     else
 305       # Default works for linux, might work on other platforms as well.
 306       PICFLAG='-fPIC'
 307       SHARED_LIBRARY_FLAGS='-shared'
 308       SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$$$ORIGIN[$]1'
 309       SET_SHARED_LIBRARY_ORIGIN="-Wl,-z,origin $SET_EXECUTABLE_ORIGIN"
 310       SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
 311       SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
 312     fi
 313   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 314     PICFLAG="-KPIC"
 315     C_FLAG_REORDER='-xF'
 316     CXX_FLAG_REORDER='-xF'
 317     SHARED_LIBRARY_FLAGS="-G"
 318     SET_EXECUTABLE_ORIGIN='-R\$$$$ORIGIN[$]1'
 319     SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
 320     SET_SHARED_LIBRARY_NAME='-h [$]1'
 321     SET_SHARED_LIBRARY_MAPFILE='-M[$]1'
 322   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 323     # '-qpic' defaults to 'qpic=small'. This means that the compiler generates only
 324     # one instruction for accessing the TOC. If the TOC grows larger than 64K, the linker
 325     # will have to patch this single instruction with a call to some out-of-order code which
 326     # does the load from the TOC. This is of course slow. But in that case we also would have
 327     # to use '-bbigtoc' for linking anyway so we could also change the PICFLAG to 'qpic=large'.
 328     # With 'qpic=large' the compiler will by default generate a two-instruction sequence which
 329     # can be patched directly by the linker and does not require a jump to out-of-order code.
 330     # Another alternative instead of using 'qpic=large -bbigtoc' may be to use '-qminimaltoc'
 331     # instead. This creates a distinct TOC for every compilation unit (and thus requires two
 332     # loads for accessing a global variable). But there are rumors that this may be seen as a
 333     # 'performance feature' because of improved code locality of the symbols used in a
 334     # compilation unit.
 335     PICFLAG="-qpic"
 336     JVM_CFLAGS="$JVM_CFLAGS $PICFLAG"
 337     C_FLAG_REORDER=''
 338     CXX_FLAG_REORDER=''
 339     SHARED_LIBRARY_FLAGS="-qmkshrobj -bM:SRE -bnoentry"
 340     SET_EXECUTABLE_ORIGIN=""
 341     SET_SHARED_LIBRARY_ORIGIN=''
 342     SET_SHARED_LIBRARY_NAME=''
 343     SET_SHARED_LIBRARY_MAPFILE=''
 344   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 345     PICFLAG=""
 346     C_FLAG_REORDER=''
 347     CXX_FLAG_REORDER=''
 348     SHARED_LIBRARY_FLAGS="-dll"
 349     SET_EXECUTABLE_ORIGIN=''
 350     SET_SHARED_LIBRARY_ORIGIN=''
 351     SET_SHARED_LIBRARY_NAME=''
 352     SET_SHARED_LIBRARY_MAPFILE='-def:[$]1'
 353   fi
 354 
 355   AC_SUBST(C_FLAG_REORDER)
 356   AC_SUBST(CXX_FLAG_REORDER)
 357   AC_SUBST(SET_EXECUTABLE_ORIGIN)
 358   AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
 359   AC_SUBST(SET_SHARED_LIBRARY_NAME)
 360   AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
 361   AC_SUBST(SHARED_LIBRARY_FLAGS)
 362 
 363   # The (cross) compiler is now configured, we can now test capabilities
 364   # of the target platform.
 365 ])
 366 
 367 # Documentation on common flags used for solstudio in HIGHEST.
 368 #
 369 # WARNING: Use of OPTIMIZATION_LEVEL=HIGHEST in your Makefile needs to be
 370 #          done with care, there are some assumptions below that need to
 371 #          be understood about the use of pointers, and IEEE behavior.
 372 #
 373 # -fns: Use non-standard floating point mode (not IEEE 754)
 374 # -fsimple: Do some simplification of floating point arithmetic (not IEEE 754)
 375 # -fsingle: Use single precision floating point with 'float'
 376 # -xalias_level=basic: Assume memory references via basic pointer types do not alias
 377 #   (Source with excessing pointer casting and data access with mixed
 378 #    pointer types are not recommended)
 379 # -xbuiltin=%all: Use intrinsic or inline versions for math/std functions
 380 #   (If you expect perfect errno behavior, do not use this)
 381 # -xdepend: Loop data dependency optimizations (need -xO3 or higher)
 382 # -xrestrict: Pointer parameters to functions do not overlap
 383 #   (Similar to -xalias_level=basic usage, but less obvious sometimes.
 384 #    If you pass in multiple pointers to the same data, do not use this)
 385 # -xlibmil: Inline some library routines
 386 #   (If you expect perfect errno behavior, do not use this)
 387 # -xlibmopt: Use optimized math routines (CURRENTLY DISABLED)
 388 #   (If you expect perfect errno behavior, do not use this)
 389 #  Can cause undefined external on Solaris 8 X86 on __sincos, removing for now
 390 
 391     # FIXME: this will never happen since sparc != sparcv9, ie 32 bit, which we don't build anymore.
 392     # Bug?
 393     #if test "x$OPENJDK_TARGET_CPU" = xsparc; then
 394     #  CFLAGS_JDK="${CFLAGS_JDK} -xmemalign=4s"
 395     #  CXXFLAGS_JDK="${CXXFLAGS_JDK} -xmemalign=4s"
 396     #fi
 397 
 398 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_FOR_OPTIMIZATION],
 399 [
 400 
 401   ###############################################################################
 402   #
 403   # Setup the opt flags for different compilers
 404   # and different operating systems.
 405   #
 406 
 407   # FIXME: this was indirectly the old default, but just inherited.
 408   # if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 409   #   C_FLAG_DEPS="-MMD -MF"
 410   # fi
 411 
 412   # Generate make dependency files
 413   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 414     C_FLAG_DEPS="-MMD -MF"
 415   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 416     C_FLAG_DEPS="-MMD -MF"
 417   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 418     C_FLAG_DEPS="-xMMD -xMF"
 419   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 420     C_FLAG_DEPS="-qmakedep=gcc -MF"
 421   fi
 422   CXX_FLAG_DEPS="$C_FLAG_DEPS"
 423   AC_SUBST(C_FLAG_DEPS)
 424   AC_SUBST(CXX_FLAG_DEPS)
 425 
 426   # Debug symbols
 427   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 428     if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" && test "x$DEBUG_LEVEL" = "xfastdebug"; then
 429       # reduce from default "-g2" option to save space
 430       CFLAGS_DEBUG_SYMBOLS="-g1"
 431       CXXFLAGS_DEBUG_SYMBOLS="-g1"
 432     else
 433       CFLAGS_DEBUG_SYMBOLS="-g"
 434       CXXFLAGS_DEBUG_SYMBOLS="-g"
 435     fi
 436   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 437     CFLAGS_DEBUG_SYMBOLS="-g"
 438     CXXFLAGS_DEBUG_SYMBOLS="-g"
 439   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 440     CFLAGS_DEBUG_SYMBOLS="-g -xs"
 441     # -g0 enables debug symbols without disabling inlining.
 442     CXXFLAGS_DEBUG_SYMBOLS="-g0 -xs"
 443   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 444     CFLAGS_DEBUG_SYMBOLS="-g"
 445     CXXFLAGS_DEBUG_SYMBOLS="-g"
 446   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 447     CFLAGS_DEBUG_SYMBOLS="-Zi"
 448     CXXFLAGS_DEBUG_SYMBOLS="-Zi"
 449   fi
 450   AC_SUBST(CFLAGS_DEBUG_SYMBOLS)
 451   AC_SUBST(CXXFLAGS_DEBUG_SYMBOLS)
 452 
 453   # Debug symbols for JVM_CFLAGS
 454   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 455     JVM_CFLAGS_SYMBOLS="$JVM_CFLAGS_SYMBOLS -xs"
 456     if test "x$DEBUG_LEVEL" = xslowdebug; then
 457       JVM_CFLAGS_SYMBOLS="$JVM_CFLAGS_SYMBOLS -g"
 458     else
 459       # -g0 does not disable inlining, which -g does.
 460       JVM_CFLAGS_SYMBOLS="$JVM_CFLAGS_SYMBOLS -g0"
 461     fi
 462   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 463     JVM_CFLAGS_SYMBOLS="$JVM_CFLAGS_SYMBOLS -Z7 -d2Zi+"
 464   else
 465     JVM_CFLAGS_SYMBOLS="$JVM_CFLAGS_SYMBOLS -g"
 466   fi
 467   AC_SUBST(JVM_CFLAGS_SYMBOLS)
 468 
 469   # bounds, memory and behavior checking options
 470   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 471     case $DEBUG_LEVEL in
 472     release )
 473       # no adjustment
 474       ;;
 475     fastdebug )
 476       # no adjustment
 477       ;;
 478     slowdebug )
 479       # FIXME: By adding this to C(XX)FLAGS_DEBUG_OPTIONS/JVM_CFLAGS_SYMBOLS it
 480       # get's added conditionally on whether we produce debug symbols or not.
 481       # This is most likely not really correct.
 482 
 483       # Add runtime stack smashing and undefined behavior checks.
 484       # Not all versions of gcc support -fstack-protector
 485       STACK_PROTECTOR_CFLAG="-fstack-protector-all"
 486       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$STACK_PROTECTOR_CFLAG -Werror], IF_FALSE: [STACK_PROTECTOR_CFLAG=""])
 487 
 488       CFLAGS_DEBUG_OPTIONS="$STACK_PROTECTOR_CFLAG --param ssp-buffer-size=1"
 489       CXXFLAGS_DEBUG_OPTIONS="$STACK_PROTECTOR_CFLAG --param ssp-buffer-size=1"
 490       if test "x$STACK_PROTECTOR_CFLAG" != x; then
 491         JVM_CFLAGS_SYMBOLS="$JVM_CFLAGS_SYMBOLS $STACK_PROTECTOR_CFLAG --param ssp-buffer-size=1"
 492       fi
 493       ;;
 494     esac
 495   fi
 496 
 497   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 498     if test "x$DEBUG_LEVEL" != xrelease; then
 499       if test "x$OPENJDK_TARGET_CPU" = xx86_64; then
 500         JVM_CFLAGS="$JVM_CFLAGS -homeparams"
 501       fi
 502     fi
 503   fi
 504 
 505   # Optimization levels
 506   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 507     CC_HIGHEST="$CC_HIGHEST -fns -fsimple -fsingle -xbuiltin=%all -xdepend -xrestrict -xlibmil"
 508 
 509     if test "x$OPENJDK_TARGET_CPU_ARCH" = "xx86"; then
 510       # FIXME: seems we always set -xregs=no%frameptr; put it elsewhere more global?
 511       C_O_FLAG_HIGHEST_JVM="-xO4"
 512       C_O_FLAG_HIGHEST="-xO4 -Wu,-O4~yz $CC_HIGHEST -xalias_level=basic -xregs=no%frameptr"
 513       C_O_FLAG_HI="-xO4 -Wu,-O4~yz -xregs=no%frameptr"
 514       C_O_FLAG_NORM="-xO2 -Wu,-O2~yz -xregs=no%frameptr"
 515       C_O_FLAG_DEBUG="-xregs=no%frameptr"
 516       C_O_FLAG_DEBUG_JVM=""
 517       C_O_FLAG_NONE="-xregs=no%frameptr"
 518       CXX_O_FLAG_HIGHEST_JVM="-xO4"
 519       CXX_O_FLAG_HIGHEST="-xO4 -Qoption ube -O4~yz $CC_HIGHEST -xregs=no%frameptr"
 520       CXX_O_FLAG_HI="-xO4 -Qoption ube -O4~yz -xregs=no%frameptr"
 521       CXX_O_FLAG_NORM="-xO2 -Qoption ube -O2~yz -xregs=no%frameptr"
 522       CXX_O_FLAG_DEBUG="-xregs=no%frameptr"
 523       CXX_O_FLAG_DEBUG_JVM=""
 524       CXX_O_FLAG_NONE="-xregs=no%frameptr"
 525       if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
 526         C_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST -xchip=pentium"
 527         CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HIGHEST -xchip=pentium"
 528       fi
 529     elif test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
 530       C_O_FLAG_HIGHEST_JVM="-xO4"
 531       C_O_FLAG_HIGHEST="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0 $CC_HIGHEST -xalias_level=basic -xprefetch=auto,explicit -xchip=ultra"
 532       C_O_FLAG_HI="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0"
 533       C_O_FLAG_NORM="-xO2 -Wc,-Qrm-s -Wc,-Qiselect-T0"
 534       C_O_FLAG_DEBUG=""
 535       C_O_FLAG_DEBUG_JVM=""
 536       C_O_FLAG_NONE=""
 537       CXX_O_FLAG_HIGHEST_JVM="-xO4"
 538       CXX_O_FLAG_HIGHEST="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
 539       CXX_O_FLAG_HI="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
 540       CXX_O_FLAG_NORM="-xO2 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
 541       CXX_O_FLAG_DEBUG=""
 542       CXX_O_FLAG_DEBUG_JVM=""
 543       CXX_O_FLAG_NONE=""
 544     fi
 545   else
 546     # The remaining toolchains share opt flags between CC and CXX;
 547     # setup for C and duplicate afterwards.
 548     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 549       if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 550         # On MacOSX we optimize for size, something
 551         # we should do for all platforms?
 552         C_O_FLAG_HIGHEST_JVM="-Os"
 553         C_O_FLAG_HIGHEST="-Os"
 554         C_O_FLAG_HI="-Os"
 555         C_O_FLAG_NORM="-Os"
 556         C_O_FLAG_SIZE="-Os"
 557       else
 558         C_O_FLAG_HIGHEST_JVM="-O3"
 559         C_O_FLAG_HIGHEST="-O3"
 560         C_O_FLAG_HI="-O3"
 561         C_O_FLAG_NORM="-O2"
 562         C_O_FLAG_SIZE="-Os"
 563       fi
 564       C_O_FLAG_DEBUG="-O0"
 565       if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 566         C_O_FLAG_DEBUG_JVM=""
 567       elif test "x$OPENJDK_TARGET_OS" = xlinux; then
 568         C_O_FLAG_DEBUG_JVM="-O0"
 569       fi
 570       C_O_FLAG_NONE="-O0"
 571     elif test "x$TOOLCHAIN_TYPE" = xclang; then
 572       if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 573         # On MacOSX we optimize for size, something
 574         # we should do for all platforms?
 575         C_O_FLAG_HIGHEST_JVM="-Os"
 576         C_O_FLAG_HIGHEST="-Os"
 577         C_O_FLAG_HI="-Os"
 578         C_O_FLAG_NORM="-Os"
 579         C_O_FLAG_SIZE="-Os"
 580       else
 581         C_O_FLAG_HIGHEST_JVM="-O3"
 582         C_O_FLAG_HIGHEST="-O3"
 583         C_O_FLAG_HI="-O3"
 584         C_O_FLAG_NORM="-O2"
 585         C_O_FLAG_SIZE="-Os"
 586       fi
 587       C_O_FLAG_DEBUG="-O0"
 588       if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 589         C_O_FLAG_DEBUG_JVM=""
 590       elif test "x$OPENJDK_TARGET_OS" = xlinux; then
 591         C_O_FLAG_DEBUG_JVM="-O0"
 592       fi
 593       C_O_FLAG_NONE="-O0"
 594     elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 595       C_O_FLAG_HIGHEST_JVM="-O3 -qhot=level=1 -qinline -qinlglue"
 596       C_O_FLAG_HIGHEST="-O3 -qhot=level=1 -qinline -qinlglue"
 597       C_O_FLAG_HI="-O3 -qinline -qinlglue"
 598       C_O_FLAG_NORM="-O2"
 599       C_O_FLAG_DEBUG="-qnoopt"
 600       # FIXME: Value below not verified.
 601       C_O_FLAG_DEBUG_JVM=""
 602       C_O_FLAG_NONE="-qnoopt"
 603     elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 604       C_O_FLAG_HIGHEST_JVM="-O2 -Oy-"
 605       C_O_FLAG_HIGHEST="-O2"
 606       C_O_FLAG_HI="-O1"
 607       C_O_FLAG_NORM="-O1"
 608       C_O_FLAG_DEBUG="-Od"
 609       C_O_FLAG_DEBUG_JVM=""
 610       C_O_FLAG_NONE="-Od"
 611       C_O_FLAG_SIZE="-Os"
 612     fi
 613     CXX_O_FLAG_HIGHEST_JVM="$C_O_FLAG_HIGHEST_JVM"
 614     CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
 615     CXX_O_FLAG_HI="$C_O_FLAG_HI"
 616     CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
 617     CXX_O_FLAG_DEBUG="$C_O_FLAG_DEBUG"
 618     CXX_O_FLAG_DEBUG_JVM="$C_O_FLAG_DEBUG_JVM"
 619     CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
 620     CXX_O_FLAG_SIZE="$C_O_FLAG_SIZE"
 621   fi
 622 
 623   # Adjust optimization flags according to debug level.
 624   case $DEBUG_LEVEL in
 625     release )
 626       # no adjustment
 627       ;;
 628     fastdebug )
 629       # Not quite so much optimization
 630       C_O_FLAG_HI="$C_O_FLAG_NORM"
 631       CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
 632       ;;
 633     slowdebug )
 634       # Disable optimization
 635       C_O_FLAG_HIGHEST_JVM="$C_O_FLAG_DEBUG_JVM"
 636       C_O_FLAG_HIGHEST="$C_O_FLAG_DEBUG"
 637       C_O_FLAG_HI="$C_O_FLAG_DEBUG"
 638       C_O_FLAG_NORM="$C_O_FLAG_DEBUG"
 639       C_O_FLAG_SIZE="$C_O_FLAG_DEBUG"
 640       CXX_O_FLAG_HIGHEST_JVM="$CXX_O_FLAG_DEBUG_JVM"
 641       CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_DEBUG"
 642       CXX_O_FLAG_HI="$CXX_O_FLAG_DEBUG"
 643       CXX_O_FLAG_NORM="$CXX_O_FLAG_DEBUG"
 644       CXX_O_FLAG_SIZE="$CXX_O_FLAG_DEBUG"
 645       ;;
 646   esac
 647 
 648   AC_SUBST(C_O_FLAG_HIGHEST_JVM)
 649   AC_SUBST(C_O_FLAG_HIGHEST)
 650   AC_SUBST(C_O_FLAG_HI)
 651   AC_SUBST(C_O_FLAG_NORM)
 652   AC_SUBST(C_O_FLAG_DEBUG)
 653   AC_SUBST(C_O_FLAG_NONE)
 654   AC_SUBST(C_O_FLAG_SIZE)
 655   AC_SUBST(CXX_O_FLAG_HIGHEST_JVM)
 656   AC_SUBST(CXX_O_FLAG_HIGHEST)
 657   AC_SUBST(CXX_O_FLAG_HI)
 658   AC_SUBST(CXX_O_FLAG_NORM)
 659   AC_SUBST(CXX_O_FLAG_DEBUG)
 660   AC_SUBST(CXX_O_FLAG_NONE)
 661   AC_SUBST(CXX_O_FLAG_SIZE)
 662 ])
 663 
 664 
 665 AC_DEFUN([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK],
 666 [
 667 
 668   FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK_HELPER([TARGET])
 669   FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK_HELPER([BUILD], [OPENJDK_BUILD_])
 670 
 671   # Tests are only ever compiled for TARGET
 672   # Flags for compiling test libraries
 673   CFLAGS_TESTLIB="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
 674   CXXFLAGS_TESTLIB="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA"
 675 
 676   # Flags for compiling test executables
 677   CFLAGS_TESTEXE="$COMMON_CCXXFLAGS_JDK $CFLAGS_JDK"
 678   CXXFLAGS_TESTEXE="$COMMON_CCXXFLAGS_JDK $CXXFLAGS_JDK"
 679 
 680   AC_SUBST(CFLAGS_TESTLIB)
 681   AC_SUBST(CFLAGS_TESTEXE)
 682   AC_SUBST(CXXFLAGS_TESTLIB)
 683   AC_SUBST(CXXFLAGS_TESTEXE)
 684 
 685   LDFLAGS_TESTLIB="$LDFLAGS_JDKLIB"
 686   LDFLAGS_TESTEXE="$LDFLAGS_JDKEXE $JAVA_BASE_LDFLAGS"
 687 
 688   AC_SUBST(LDFLAGS_TESTLIB)
 689   AC_SUBST(LDFLAGS_TESTEXE)
 690 
 691 ])
 692 
 693 ################################################################################
 694 # $1 - Either BUILD or TARGET to pick the correct OS/CPU variables to check
 695 #      conditionals against.
 696 # $2 - Optional prefix for each variable defined.
 697 AC_DEFUN([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK_HELPER],
 698 [
 699   # Special extras...
 700   if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 701     if test "x$OPENJDK_$1_CPU_ARCH" = "xsparc"; then
 702       $2CFLAGS_JDKLIB_EXTRA="${$2CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
 703       $2CXXFLAGS_JDKLIB_EXTRA="${$2CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
 704     fi
 705     $2CFLAGS_JDKLIB_EXTRA="${$2CFLAGS_JDKLIB_EXTRA} -errtags=yes -errfmt"
 706     $2CXXFLAGS_JDKLIB_EXTRA="${$2CXXFLAGS_JDKLIB_EXTRA} -errtags=yes -errfmt"
 707   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 708     $2CFLAGS_JDK="${$2CFLAGS_JDK} -qchars=signed -qfullpath -qsaveopt"
 709     $2CXXFLAGS_JDK="${$2CXXFLAGS_JDK} -qchars=signed -qfullpath -qsaveopt"
 710   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
 711     $2CXXSTD_CXXFLAG="-std=gnu++98"
 712     FLAGS_CXX_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [[$]$2CXXSTD_CXXFLAG -Werror],
 713                                                  IF_FALSE: [$2CXXSTD_CXXFLAG=""])
 714     $2CXXFLAGS_JDK="${$2CXXFLAGS_JDK} ${$2CXXSTD_CXXFLAG}"
 715     $2JVM_CFLAGS="${$2JVM_CFLAGS} ${$2CXXSTD_CXXFLAG}"
 716     AC_SUBST([$2CXXSTD_CXXFLAG])
 717   fi
 718   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 719     $2CFLAGS_JDK="${$2CFLAGS_JDK} -D__solaris__"
 720     $2CXXFLAGS_JDK="${$2CXXFLAGS_JDK} -D__solaris__"
 721   fi
 722 
 723   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 724     $2CFLAGS_JDK="${$2CFLAGS_JDK} -D__solaris__"
 725     $2CXXFLAGS_JDK="${$2CXXFLAGS_JDK} -D__solaris__"
 726   fi
 727 
 728   $2CFLAGS_JDK="${$2CFLAGS_JDK} ${$2EXTRA_CFLAGS}"
 729   $2CXXFLAGS_JDK="${$2CXXFLAGS_JDK} ${$2EXTRA_CXXFLAGS}"
 730   $2LDFLAGS_JDK="${$2LDFLAGS_JDK} ${$2EXTRA_LDFLAGS}"
 731 
 732   ###############################################################################
 733   #
 734   # Now setup the CFLAGS and LDFLAGS for the JDK build.
 735   # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
 736   #
 737 
 738   # Setup compiler/platform specific flags into
 739   #    $2CFLAGS_JDK    - C Compiler flags
 740   #    $2CXXFLAGS_JDK  - C++ Compiler flags
 741   #    $2COMMON_CCXXFLAGS_JDK - common to C and C++
 742   if test "x$TOOLCHAIN_TYPE" = xgcc; then
 743     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_GNU_SOURCE"
 744     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_REENTRANT"
 745     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -fcheck-new"
 746     if test "x$OPENJDK_$1_CPU" = xx86; then
 747       # Force compatibility with i586 on 32 bit intel platforms.
 748       $2COMMON_CCXXFLAGS="${$2COMMON_CCXXFLAGS} -march=i586"
 749       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -march=i586"
 750     fi
 751     $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS [$]$2COMMON_CCXXFLAGS_JDK -Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2 \
 752         -pipe -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
 753     case $OPENJDK_$1_CPU_ARCH in
 754       arm )
 755         # on arm we don't prevent gcc to omit frame pointer but do prevent strict aliasing
 756         $2CFLAGS_JDK="${$2CFLAGS_JDK} -fno-strict-aliasing"
 757         ;;
 758       ppc )
 759         # on ppc we don't prevent gcc to omit frame pointer but do prevent strict aliasing
 760         $2CFLAGS_JDK="${$2CFLAGS_JDK} -fno-strict-aliasing"
 761         ;;
 762       * )
 763         $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -fno-omit-frame-pointer"
 764         $2CFLAGS_JDK="${$2CFLAGS_JDK} -fno-strict-aliasing"
 765         ;;
 766     esac
 767     TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: 6, PREFIX: $2, IF_AT_LEAST: FLAGS_SETUP_GCC6_COMPILER_FLAGS($2))
 768   elif test "x$TOOLCHAIN_TYPE" = xclang; then
 769     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_GNU_SOURCE"
 770 
 771     # Restrict the debug information created by Clang to avoid
 772     # too big object files and speed the build up a little bit
 773     # (see http://llvm.org/bugs/show_bug.cgi?id=7554)
 774     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -flimit-debug-info"
 775     if test "x$OPENJDK_$1_OS" = xlinux; then
 776       if test "x$OPENJDK_$1_CPU" = xx86; then
 777         # Force compatibility with i586 on 32 bit intel platforms.
 778         $2COMMON_CCXXFLAGS="${$2COMMON_CCXXFLAGS} -march=i586"
 779         $2JVM_CFLAGS="[$]$2JVM_CFLAGS -march=i586"
 780       fi
 781       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -Wno-sometimes-uninitialized"
 782       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS [$]$2COMMON_CCXXFLAGS_JDK -Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2 \
 783           -pipe -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
 784       case $OPENJDK_$1_CPU_ARCH in
 785         ppc )
 786           # on ppc we don't prevent gcc to omit frame pointer but do prevent strict aliasing
 787           $2CFLAGS_JDK="${$2CFLAGS_JDK} -fno-strict-aliasing"
 788           ;;
 789         * )
 790           $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -fno-omit-frame-pointer"
 791           $2CFLAGS_JDK="${$2CFLAGS_JDK} -fno-strict-aliasing"
 792           ;;
 793       esac
 794     fi
 795   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
 796     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -DSPARC_WORKS"
 797     $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS [$]$2COMMON_CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
 798     if test "x$OPENJDK_$1_CPU_ARCH" = xx86; then
 799       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -DcpuIntel -Di586 -D$OPENJDK_$1_CPU_LEGACY_LIB"
 800     fi
 801 
 802     $2CFLAGS_JDK="[$]$2CFLAGS_JDK -xc99=%none -xCC -errshort=tags -Xa -v -mt -W0,-noglobal"
 803     $2CXXFLAGS_JDK="[$]$2CXXFLAGS_JDK -errtags=yes +w -mt -features=no%except -DCC_NOEX -norunpath -xnolib"
 804   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 805     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_REENTRANT -D__STDC_FORMAT_MACROS"
 806     $2CFLAGS_JDK="[$]$2CFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
 807     $2CXXFLAGS_JDK="[$]$2CXXFLAGS_JDK -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC"
 808   elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
 809     $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS [$]$2COMMON_CCXXFLAGS_JDK \
 810         -MD -Zc:wchar_t- -W3 -wd4800 \
 811         -DWIN32_LEAN_AND_MEAN \
 812         -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
 813         -D_WINSOCK_DEPRECATED_NO_WARNINGS \
 814         -DWIN32 -DIAL"
 815     if test "x$OPENJDK_$1_CPU" = xx86_64; then
 816       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_AMD64_ -Damd64"
 817     else
 818       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_X86_ -Dx86"
 819     fi
 820     # If building with Visual Studio 2010, we can still use _STATIC_CPPLIB to
 821     # avoid bundling msvcpNNN.dll. Doesn't work with newer versions of visual
 822     # studio.
 823     if test "x$TOOLCHAIN_VERSION" = "x2010"; then
 824       STATIC_CPPLIB_FLAGS="-D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB"
 825       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK $STATIC_CPPLIB_FLAGS"
 826       $2JVM_CFLAGS="[$]$2JVM_CFLAGS $STATIC_CPPLIB_FLAGS"
 827     fi
 828   fi
 829 
 830   ###############################################################################
 831 
 832   # Adjust flags according to debug level.
 833   case $DEBUG_LEVEL in
 834     fastdebug | slowdebug )
 835       $2CFLAGS_JDK="[$]$2CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS $CFLAGS_DEBUG_OPTIONS"
 836       $2CXXFLAGS_JDK="[$]$2CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS $CXXFLAGS_DEBUG_OPTIONS"
 837       JAVAC_FLAGS="$JAVAC_FLAGS -g"
 838       ;;
 839     release )
 840       ;;
 841     * )
 842       AC_MSG_ERROR([Unrecognized \$DEBUG_LEVEL: $DEBUG_LEVEL])
 843       ;;
 844   esac
 845 
 846   # Set some common defines. These works for all compilers, but assume
 847   # -D is universally accepted.
 848 
 849   # Setup endianness
 850   if test "x$OPENJDK_$1_CPU_ENDIAN" = xlittle; then
 851     # The macro _LITTLE_ENDIAN needs to be defined the same to avoid the
 852     #   Sun C compiler warning message: warning: macro redefined: _LITTLE_ENDIAN
 853     #   (The Solaris X86 system defines this in file /usr/include/sys/isa_defs.h).
 854     #   Note: -Dmacro         is the same as    #define macro 1
 855     #         -Dmacro=        is the same as    #define macro
 856     if test "x$OPENJDK_$1_OS" = xsolaris; then
 857       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_LITTLE_ENDIAN="
 858     else
 859       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_LITTLE_ENDIAN"
 860     fi
 861   else
 862     # Same goes for _BIG_ENDIAN. Do we really need to set *ENDIAN on Solaris if they
 863     # are defined in the system?
 864     if test "x$OPENJDK_$1_OS" = xsolaris; then
 865       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_BIG_ENDIAN="
 866     else
 867       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_BIG_ENDIAN"
 868     fi
 869   fi
 870 
 871   # Setup target OS define. Use OS target name but in upper case.
 872   OPENJDK_$1_OS_UPPERCASE=`$ECHO $OPENJDK_$1_OS | $TR 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
 873   $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D$OPENJDK_$1_OS_UPPERCASE"
 874 
 875   # Setup target CPU
 876   $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK \
 877       $OPENJDK_$1_ADD_LP64 \
 878       -DARCH='\"$OPENJDK_$1_CPU_LEGACY\"' -D$OPENJDK_$1_CPU_LEGACY"
 879 
 880   # Setup debug/release defines
 881   if test "x$DEBUG_LEVEL" = xrelease; then
 882     $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -DNDEBUG"
 883     if test "x$OPENJDK_$1_OS" = xsolaris; then
 884       $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -DTRIMMED"
 885     fi
 886   else
 887     $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -DDEBUG"
 888   fi
 889 
 890   # Set some additional per-OS defines.
 891   if test "x$OPENJDK_$1_OS" = xlinux; then
 892     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -DLINUX"
 893     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -pipe -fPIC -fno-rtti -fno-exceptions \
 894         -fvisibility=hidden -fno-strict-aliasing -fno-omit-frame-pointer"
 895   elif test "x$OPENJDK_$1_OS" = xsolaris; then
 896     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -DSOLARIS"
 897     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -template=no%extdef -features=no%split_init \
 898         -D_Crun_inline_placement -library=%none -KPIC -mt -xwe -features=no%except"
 899   elif test "x$OPENJDK_$1_OS" = xmacosx; then
 900     $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
 901     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_ALLBSD_SOURCE"
 902     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE"
 903     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -fno-rtti -fno-exceptions -fvisibility=hidden \
 904         -mno-omit-leaf-frame-pointer -mstack-alignment=16 -pipe -fno-strict-aliasing \
 905         -DMAC_OS_X_VERSION_MAX_ALLOWED=1070 -mmacosx-version-min=10.7.0 \
 906         -fno-omit-frame-pointer"
 907   elif test "x$OPENJDK_$1_OS" = xaix; then
 908     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -DAIX"
 909     # We may need '-qminimaltoc' or '-qpic=large -bbigtoc' if the TOC overflows.
 910     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -qtune=balanced \
 911         -qalias=noansi -qstrict -qtls=default -qlanglvl=c99vla \
 912         -qlanglvl=noredefmac -qnortti -qnoeh -qignerrno"
 913   elif test "x$OPENJDK_$1_OS" = xbsd; then
 914     $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_ALLBSD_SOURCE"
 915   elif test "x$OPENJDK_$1_OS" = xwindows; then
 916     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_WINDOWS -DWIN32 -D_JNI_IMPLEMENTATION_"
 917     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -nologo -W3 -MD -MP"
 918   fi
 919 
 920   # Set some additional per-CPU defines.
 921   if test "x$OPENJDK_$1_OS-$OPENJDK_$1_CPU" = xwindows-x86; then
 922     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -arch:IA32"
 923   elif test "x$OPENJDK_$1_CPU" = xsparcv9; then
 924     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -xarch=sparc"
 925   elif test "x$OPENJDK_$1_CPU" = xppc64; then
 926     if test "x$OPENJDK_$1_OS" = xlinux; then
 927       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -minsert-sched-nops=regroup_exact -mno-multiple -mno-string"
 928       # fixes `relocation truncated to fit' error for gcc 4.1.
 929       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -mminimal-toc"
 930       # Use ppc64 instructions, but schedule for power5
 931       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -mcpu=powerpc64 -mtune=power5"
 932     elif test "x$OPENJDK_$1_OS" = xaix; then
 933       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -qarch=ppc64"
 934     fi
 935   elif test "x$OPENJDK_$1_CPU" = xppc64le; then
 936     if test "x$OPENJDK_$1_OS" = xlinux; then
 937       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -minsert-sched-nops=regroup_exact -mno-multiple -mno-string"
 938       # Little endian machine uses ELFv2 ABI.
 939       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -DABI_ELFv2"
 940       # Use Power8, this is the first CPU to support PPC64 LE with ELFv2 ABI.
 941       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -mcpu=power7 -mtune=power8"
 942     fi
 943   fi
 944 
 945   if test "x$OPENJDK_$1_CPU_ENDIAN" = xlittle; then
 946     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -DVM_LITTLE_ENDIAN"
 947   fi
 948 
 949   if test "x$OPENJDK_$1_CPU_BITS" = x64; then
 950     if test "x$OPENJDK_$1_OS" != xsolaris && test "x$OPENJDK_$1_OS" != xaix; then
 951       # Solaris does not have _LP64=1 in the old build.
 952       # xlc on AIX defines _LP64=1 by default and issues a warning if we redefine it.
 953       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_LP64=1"
 954     fi
 955   fi
 956 
 957   # Set $2JVM_CFLAGS warning handling
 958   if test "x$OPENJDK_$1_OS" = xlinux; then
 959     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -Wpointer-arith -Wsign-compare -Wunused-function \
 960         -Wunused-value -Woverloaded-virtual"
 961 
 962     if test "x$TOOLCHAIN_TYPE" = xgcc; then
 963       TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: [4.8], PREFIX: $2,
 964           IF_AT_LEAST: [
 965             # These flags either do not work or give spurious warnings prior to gcc 4.8.
 966             $2JVM_CFLAGS="[$]$2JVM_CFLAGS -Wno-format-zero-length -Wtype-limits -Wuninitialized"
 967           ]
 968       )
 969     fi
 970     if ! HOTSPOT_CHECK_JVM_VARIANT(zero) && ! HOTSPOT_CHECK_JVM_VARIANT(zeroshark); then
 971       # Non-zero builds have stricter warnings
 972       $2JVM_CFLAGS="[$]$2JVM_CFLAGS -Wreturn-type -Wundef -Wformat=2"
 973     else
 974       if test "x$TOOLCHAIN_TYPE" = xclang; then
 975         # Some versions of llvm do not like -Wundef
 976         $2JVM_CFLAGS="[$]$2JVM_CFLAGS -Wno-undef"
 977       fi
 978     fi
 979   elif test "x$OPENJDK_$1_OS" = xmacosx; then
 980     $2JVM_CFLAGS="[$]$2JVM_CFLAGS -Wno-deprecated -Wpointer-arith \
 981         -Wsign-compare -Wundef -Wunused-function -Wformat=2"
 982   fi
 983 
 984   # Additional macosx handling
 985   if test "x$OPENJDK_$1_OS" = xmacosx; then
 986     # Setting these parameters makes it an error to link to macosx APIs that are
 987     # newer than the given OS version and makes the linked binaries compatible
 988     # even if built on a newer version of the OS.
 989     # The expected format is X.Y.Z
 990     MACOSX_VERSION_MIN=10.7.0
 991     AC_SUBST(MACOSX_VERSION_MIN)
 992 
 993     # The macro takes the version with no dots, ex: 1070
 994     # Let the flags variables get resolved in make for easier override on make
 995     # command line.
 996     $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -DMAC_OS_X_VERSION_MAX_ALLOWED=\$(subst .,,\$(MACOSX_VERSION_MIN)) -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
 997     $2LDFLAGS_JDK="[$]$2LDFLAGS_JDK -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
 998   fi
 999 
1000   # Setup some hard coded includes
1001   $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK \
1002       -I${JDK_TOPDIR}/src/java.base/share/native/include \
1003       -I${JDK_TOPDIR}/src/java.base/$OPENJDK_$1_OS/native/include \
1004       -I${JDK_TOPDIR}/src/java.base/$OPENJDK_$1_OS_TYPE/native/include \
1005       -I${JDK_TOPDIR}/src/java.base/share/native/libjava \
1006       -I${JDK_TOPDIR}/src/java.base/$OPENJDK_$1_OS_TYPE/native/libjava"
1007 
1008   # The shared libraries are compiled using the picflag.
1009   $2CFLAGS_JDKLIB="[$]$2COMMON_CCXXFLAGS_JDK \
1010       [$]$2CFLAGS_JDK [$]$2EXTRA_CFLAGS_JDK $PICFLAG [$]$2CFLAGS_JDKLIB_EXTRA"
1011   $2CXXFLAGS_JDKLIB="[$]$2COMMON_CCXXFLAGS_JDK \
1012       [$]$2CXXFLAGS_JDK [$]$2EXTRA_CXXFLAGS_JDK $PICFLAG [$]$2CXXFLAGS_JDKLIB_EXTRA"
1013 
1014   # Executable flags
1015   $2CFLAGS_JDKEXE="[$]$2COMMON_CCXXFLAGS_JDK [$]$2CFLAGS_JDK [$]$2EXTRA_CFLAGS_JDK"
1016   $2CXXFLAGS_JDKEXE="[$]$2COMMON_CCXXFLAGS_JDK [$]$2CXXFLAGS_JDK [$]$2EXTRA_CXXFLAGS_JDK"
1017 
1018   AC_SUBST($2CFLAGS_JDKLIB)
1019   AC_SUBST($2CFLAGS_JDKEXE)
1020   AC_SUBST($2CXXFLAGS_JDKLIB)
1021   AC_SUBST($2CXXFLAGS_JDKEXE)
1022 
1023   # Setup LDFLAGS et al.
1024   #
1025 
1026   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
1027     LDFLAGS_MICROSOFT="-nologo -opt:ref"
1028     $2LDFLAGS_JDK="[$]$2LDFLAGS_JDK $LDFLAGS_MICROSOFT -incremental:no"
1029     $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LDFLAGS_MICROSOFT -opt:icf,8 -subsystem:windows -base:0x8000000"
1030     if test "x$OPENJDK_$1_CPU_BITS" = "x32"; then
1031       LDFLAGS_SAFESH="-safeseh"
1032       $2LDFLAGS_JDK="[$]$2LDFLAGS_JDK $LDFLAGS_SAFESH"
1033       $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LDFLAGS_SAFESH"
1034       # NOTE: Old build added -machine. Probably not needed.
1035       $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS -machine:I386"
1036     else
1037       $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS -machine:AMD64"
1038     fi
1039   elif test "x$TOOLCHAIN_TYPE" = xclang; then
1040       $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS -mno-omit-leaf-frame-pointer -mstack-alignment=16 -stdlib=libstdc++ -fPIC"
1041       if test "x$OPENJDK_$1_OS" = xmacosx; then
1042         # FIXME: We should really generalize SET_SHARED_LIBRARY_ORIGIN instead.
1043         $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS -Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/.."
1044     fi
1045   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
1046     # If this is a --hash-style=gnu system, use --hash-style=both, why?
1047     # We have previously set HAS_GNU_HASH if this is the case
1048     if test -n "$HAS_GNU_HASH"; then
1049       $2LDFLAGS_HASH_STYLE="-Wl,--hash-style=both"
1050       $2LDFLAGS_JDK="${$2LDFLAGS_JDK} [$]$2LDFLAGS_HASH_STYLE"
1051       $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS [$]$2LDFLAGS_HASH_STYLE"
1052     fi
1053       if test "x$OPENJDK_$1_OS" = xmacosx; then
1054         $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS -Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/.."
1055     fi
1056     if test "x$OPENJDK_$1_OS" = xlinux; then
1057       # And since we now know that the linker is gnu, then add -z defs, to forbid
1058       # undefined symbols in object files.
1059       LDFLAGS_NO_UNDEF_SYM="-Wl,-z,defs"
1060       $2LDFLAGS_JDK="${$2LDFLAGS_JDK} $LDFLAGS_NO_UNDEF_SYM"
1061       $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS  $LDFLAGS_NO_UNDEF_SYM"
1062       LDFLAGS_NO_EXEC_STACK="-Wl,-z,noexecstack"
1063       $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LDFLAGS_NO_EXEC_STACK"
1064       if test "x$OPENJDK_$1_CPU" = xx86; then
1065         $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS -march=i586"
1066       fi
1067       case $DEBUG_LEVEL in
1068         release )
1069           # tell linker to optimize libraries.
1070           # Should this be supplied to the OSS linker as well?
1071           LDFLAGS_DEBUGLEVEL_release="-Wl,-O1"
1072           $2LDFLAGS_JDK="${$2LDFLAGS_JDK} $LDFLAGS_DEBUGLEVEL_release"
1073           $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LDFLAGS_DEBUGLEVEL_release"
1074           if test "x$HAS_LINKER_RELRO" = "xtrue"; then
1075             $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LINKER_RELRO_FLAG"
1076           fi
1077           ;;
1078         slowdebug )
1079           # Hotspot always let the linker optimize
1080           $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS -Wl,-O1"
1081           if test "x$HAS_LINKER_NOW" = "xtrue"; then
1082             # do relocations at load
1083             $2LDFLAGS_JDK="[$]$2LDFLAGS_JDK $LINKER_NOW_FLAG"
1084             $2LDFLAGS_CXX_JDK="[$]$2LDFLAGS_CXX_JDK $LINKER_NOW_FLAG"
1085             $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LINKER_NOW_FLAG"
1086           fi
1087           if test "x$HAS_LINKER_RELRO" = "xtrue"; then
1088             # mark relocations read only
1089             $2LDFLAGS_JDK="[$]$2LDFLAGS_JDK $LINKER_RELRO_FLAG"
1090             $2LDFLAGS_CXX_JDK="[$]$2LDFLAGS_CXX_JDK $LINKER_RELRO_FLAG"
1091             $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LINKER_RELRO_FLAG"
1092           fi
1093           ;;
1094         fastdebug )
1095           # Hotspot always let the linker optimize
1096           $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS -Wl,-O1"
1097           if test "x$HAS_LINKER_RELRO" = "xtrue"; then
1098             # mark relocations read only
1099             $2LDFLAGS_JDK="[$]$2LDFLAGS_JDK $LINKER_RELRO_FLAG"
1100             $2LDFLAGS_CXX_JDK="[$]$2LDFLAGS_CXX_JDK $LINKER_RELRO_FLAG"
1101             $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LINKER_RELRO_FLAG"
1102           fi
1103           ;;
1104         * )
1105           AC_MSG_ERROR([Unrecognized \$DEBUG_LEVEL: $DEBUG_LEVEL])
1106           ;;
1107         esac
1108     fi
1109   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
1110     LDFLAGS_SOLSTUDIO="-Wl,-z,defs"
1111     $2LDFLAGS_JDK="[$]$2LDFLAGS_JDK $LDFLAGS_SOLSTUDIO -ztext"
1112     LDFLAGS_CXX_SOLSTUDIO="-norunpath"
1113     $2LDFLAGS_CXX_JDK="[$]$2LDFLAGS_CXX_JDK $LDFLAGS_CXX_SOLSTUDIO -xnolib"
1114     $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LDFLAGS_SOLSTUDIO -library=%none -mt $LDFLAGS_CXX_SOLSTUDIO -z noversion"
1115     if test "x$OPENJDK_$1_CPU_ARCH" = "xsparc"; then
1116       $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS -xarch=sparc"
1117     fi
1118   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
1119     LDFLAGS_XLC="-b64 -brtl -bnolibpath -bexpall -bernotok"
1120     $2LDFLAGS_JDK="${$2LDFLAGS_JDK} $LDFLAGS_XLC"
1121     $2JVM_LDFLAGS="[$]$2JVM_LDFLAGS $LDFLAGS_XLC"
1122   fi
1123 
1124   # Customize LDFLAGS for executables
1125 
1126   $2LDFLAGS_JDKEXE="${$2LDFLAGS_JDK}"
1127 
1128   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
1129     if test "x$OPENJDK_$1_CPU_BITS" = "x64"; then
1130       LDFLAGS_STACK_SIZE=1048576
1131     else
1132       LDFLAGS_STACK_SIZE=327680
1133     fi
1134     $2LDFLAGS_JDKEXE="${$2LDFLAGS_JDKEXE} /STACK:$LDFLAGS_STACK_SIZE"
1135   elif test "x$OPENJDK_$1_OS" = xlinux; then
1136     $2LDFLAGS_JDKEXE="[$]$2LDFLAGS_JDKEXE -Wl,--allow-shlib-undefined"
1137   fi
1138 
1139   $2LDFLAGS_JDKEXE="${$2LDFLAGS_JDKEXE} ${$2EXTRA_LDFLAGS_JDK}"
1140 
1141   # Customize LDFLAGS for libs
1142   $2LDFLAGS_JDKLIB="${$2LDFLAGS_JDK}"
1143 
1144   $2LDFLAGS_JDKLIB="${$2LDFLAGS_JDKLIB} ${SHARED_LIBRARY_FLAGS}"
1145   if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
1146     $2JAVA_BASE_LDFLAGS="${$2JAVA_BASE_LDFLAGS} \
1147         -libpath:${OUTPUT_ROOT}/support/modules_libs/java.base"
1148     $2JDKLIB_LIBS=""
1149   else
1150     $2JAVA_BASE_LDFLAGS="${$2JAVA_BASE_LDFLAGS} \
1151         -L\$(SUPPORT_OUTPUTDIR)/modules_libs/java.base\$(OPENJDK_$1_CPU_LIBDIR)"
1152 
1153     if test "x$1" = "xTARGET"; then
1154     # On some platforms (mac) the linker warns about non existing -L dirs.
1155     # Add server first if available. Linking aginst client does not always produce the same results.
1156       # Only add client/minimal dir if client/minimal is being built.
1157     # Default to server for other variants.
1158       if HOTSPOT_CHECK_JVM_VARIANT(server); then
1159         $2JAVA_BASE_LDFLAGS="${$2JAVA_BASE_LDFLAGS} -L\$(SUPPORT_OUTPUTDIR)/modules_libs/java.base\$(OPENJDK_$1_CPU_LIBDIR)/server"
1160       elif HOTSPOT_CHECK_JVM_VARIANT(client); then
1161         $2JAVA_BASE_LDFLAGS="${$2JAVA_BASE_LDFLAGS} -L\$(SUPPORT_OUTPUTDIR)/modules_libs/java.base\$(OPENJDK_$1_CPU_LIBDIR)/client"
1162       elif HOTSPOT_CHECK_JVM_VARIANT(minimal); then
1163         $2JAVA_BASE_LDFLAGS="${$2JAVA_BASE_LDFLAGS} -L\$(SUPPORT_OUTPUTDIR)/modules_libs/java.base\$(OPENJDK_$1_CPU_LIBDIR)/minimal"
1164     else
1165         $2JAVA_BASE_LDFLAGS="${$2JAVA_BASE_LDFLAGS} -L\$(SUPPORT_OUTPUTDIR)/modules_libs/java.base\$(OPENJDK_$1_CPU_LIBDIR)/server"
1166     fi
1167     elif test "x$1" = "xBUILD"; then
1168       # When building a buildjdk, it's always only the server variant
1169       $2JAVA_BASE_LDFLAGS="${$2JAVA_BASE_LDFLAGS} \
1170           -L\$(SUPPORT_OUTPUTDIR)/modules_libs/java.base\$(OPENJDK_$1_CPU_LIBDIR)/server"
1171     fi
1172 
1173     $2JDKLIB_LIBS="-ljava -ljvm"
1174     if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
1175       $2JDKLIB_LIBS="[$]$2JDKLIB_LIBS -lc"
1176     fi
1177 
1178   fi
1179 
1180 $2LDFLAGS_JDKLIB="${$2LDFLAGS_JDKLIB} ${$2JAVA_BASE_LDFLAGS}"
1181 
1182   # Set $2JVM_LIBS (per os)
1183   if test "x$OPENJDK_$1_OS" = xlinux; then
1184     $2JVM_LIBS="[$]$2JVM_LIBS -lm -ldl -lpthread"
1185   elif test "x$OPENJDK_$1_OS" = xsolaris; then
1186     # FIXME: This hard-coded path is not really proper.
1187     if test "x$OPENJDK_$1_CPU" = xx86_64; then
1188       $2SOLARIS_LIBM_LIBS="/usr/lib/amd64/libm.so.1"
1189     elif test "x$OPENJDK_$1_CPU" = xsparcv9; then
1190       $2SOLARIS_LIBM_LIBS="/usr/lib/sparcv9/libm.so.1"
1191     fi
1192     $2JVM_LIBS="[$]$2JVM_LIBS -lsocket -lsched -ldl $SOLARIS_LIBM_LIBS -lCrun \
1193         -lthread -ldoor -lc -ldemangle -lnsl -lkstat -lrt"
1194   elif test "x$OPENJDK_$1_OS" = xmacosx; then
1195     $2JVM_LIBS="[$]$2JVM_LIBS -lm"
1196   elif test "x$OPENJDK_$1_OS" = xaix; then
1197     $2JVM_LIBS="[$]$2JVM_LIBS -Wl,-lC_r -lm -ldl -lpthread"
1198   elif test "x$OPENJDK_$1_OS" = xbsd; then
1199     $2JVM_LIBS="[$]$2JVM_LIBS -lm"
1200   elif test "x$OPENJDK_$1_OS" = xwindows; then
1201     $2JVM_LIBS="[$]$2JVM_LIBS kernel32.lib user32.lib gdi32.lib winspool.lib \
1202         comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib \
1203         wsock32.lib winmm.lib version.lib psapi.lib"
1204     fi
1205 
1206   # Set $2JVM_ASFLAGS
1207   if test "x$OPENJDK_$1_OS" = xlinux; then
1208     if test "x$OPENJDK_$1_CPU" = xx86; then
1209       $2JVM_ASFLAGS="[$]$2JVM_ASFLAGS -march=i586"
1210     fi
1211   elif test "x$OPENJDK_$1_OS" = xmacosx; then
1212     $2JVM_ASFLAGS="[$]$2JVM_ASFLAGS -x assembler-with-cpp -mno-omit-leaf-frame-pointer -mstack-alignment=16"
1213   fi
1214 
1215   $2LDFLAGS_JDKLIB="${$2LDFLAGS_JDKLIB} ${$2EXTRA_LDFLAGS_JDK}"
1216 
1217   AC_SUBST($2LDFLAGS_JDKLIB)
1218   AC_SUBST($2LDFLAGS_JDKEXE)
1219   AC_SUBST($2JDKLIB_LIBS)
1220   AC_SUBST($2JDKEXE_LIBS)
1221   AC_SUBST($2LDFLAGS_CXX_JDK)
1222   AC_SUBST($2LDFLAGS_HASH_STYLE)
1223 
1224   AC_SUBST($2JVM_CFLAGS)
1225   AC_SUBST($2JVM_LDFLAGS)
1226   AC_SUBST($2JVM_ASFLAGS)
1227   AC_SUBST($2JVM_LIBS)
1228 
1229 ])
1230 
1231 # FLAGS_C_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARGUMENT], IF_TRUE: [RUN-IF-TRUE],
1232 #                                  IF_FALSE: [RUN-IF-FALSE])
1233 # ------------------------------------------------------------
1234 # Check that the C compiler supports an argument
1235 BASIC_DEFUN_NAMED([FLAGS_C_COMPILER_CHECK_ARGUMENTS],
1236     [*ARGUMENT IF_TRUE IF_FALSE], [$@],
1237 [
1238   AC_MSG_CHECKING([if the C compiler supports "ARG_ARGUMENT"])
1239   supports=yes
1240 
1241   saved_cflags="$CFLAGS"
1242   CFLAGS="$CFLAGS ARG_ARGUMENT"
1243   AC_LANG_PUSH([C])
1244   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [],
1245       [supports=no])
1246   AC_LANG_POP([C])
1247   CFLAGS="$saved_cflags"
1248 
1249   AC_MSG_RESULT([$supports])
1250   if test "x$supports" = "xyes" ; then
1251     :
1252     ARG_IF_TRUE
1253   else
1254     :
1255     ARG_IF_FALSE
1256   fi
1257 ])
1258 
1259 # FLAGS_CXX_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARGUMENT], IF_TRUE: [RUN-IF-TRUE],
1260 #                                    IF_FALSE: [RUN-IF-FALSE])
1261 # ------------------------------------------------------------
1262 # Check that the C++ compiler supports an argument
1263 BASIC_DEFUN_NAMED([FLAGS_CXX_COMPILER_CHECK_ARGUMENTS],
1264     [*ARGUMENT IF_TRUE IF_FALSE], [$@],
1265 [
1266   AC_MSG_CHECKING([if the C++ compiler supports "ARG_ARGUMENT"])
1267   supports=yes
1268 
1269   saved_cxxflags="$CXXFLAGS"
1270   CXXFLAGS="$CXXFLAG ARG_ARGUMENT"
1271   AC_LANG_PUSH([C++])
1272   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [],
1273       [supports=no])
1274   AC_LANG_POP([C++])
1275   CXXFLAGS="$saved_cxxflags"
1276 
1277   AC_MSG_RESULT([$supports])
1278   if test "x$supports" = "xyes" ; then
1279     :
1280     ARG_IF_TRUE
1281   else
1282     :
1283     ARG_IF_FALSE
1284   fi
1285 ])
1286 
1287 # FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARGUMENT], IF_TRUE: [RUN-IF-TRUE],
1288 #                                IF_FALSE: [RUN-IF-FALSE])
1289 # ------------------------------------------------------------
1290 # Check that the C and C++ compilers support an argument
1291 BASIC_DEFUN_NAMED([FLAGS_COMPILER_CHECK_ARGUMENTS],
1292     [*ARGUMENT IF_TRUE IF_FALSE], [$@],
1293 [
1294   FLAGS_C_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARG_ARGUMENT],
1295                                              IF_TRUE: [C_COMP_SUPPORTS="yes"],
1296                                              IF_FALSE: [C_COMP_SUPPORTS="no"])
1297   FLAGS_CXX_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [ARG_ARGUMENT],
1298                                                IF_TRUE: [CXX_COMP_SUPPORTS="yes"],
1299                                                IF_FALSE: [CXX_COMP_SUPPORTS="no"])
1300 
1301   AC_MSG_CHECKING([if both compilers support "ARG_ARGUMENT"])
1302   supports=no
1303   if test "x$C_COMP_SUPPORTS" = "xyes" -a "x$CXX_COMP_SUPPORTS" = "xyes"; then supports=yes; fi
1304   
1305   AC_MSG_RESULT([$supports])
1306   if test "x$supports" = "xyes" ; then
1307     :
1308     ARG_IF_TRUE
1309   else
1310     :
1311     ARG_IF_FALSE
1312   fi
1313 ])
1314 
1315 # FLAGS_LINKER_CHECK_ARGUMENTS(ARGUMENT: [ARGUMENT], IF_TRUE: [RUN-IF-TRUE],
1316 #                                   IF_FALSE: [RUN-IF-FALSE])
1317 # ------------------------------------------------------------
1318 # Check that the linker support an argument
1319 BASIC_DEFUN_NAMED([FLAGS_LINKER_CHECK_ARGUMENTS],
1320     [*ARGUMENT IF_TRUE IF_FALSE], [$@],
1321 [
1322   AC_MSG_CHECKING([if linker supports "ARG_ARGUMENT"])
1323   supports=yes
1324 
1325   saved_ldflags="$LDFLAGS"
1326   LDFLAGS="$LDFLAGS ARG_ARGUMENT"
1327   AC_LANG_PUSH([C])
1328   AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
1329       [], [supports=no])
1330   AC_LANG_POP([C])
1331   LDFLAGS="$saved_ldflags"
1332 
1333   AC_MSG_RESULT([$supports])
1334   if test "x$supports" = "xyes" ; then
1335     :
1336     ARG_IF_TRUE
1337   else
1338     :
1339     ARG_IF_FALSE
1340   fi
1341 ])
1342 
1343 AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_MISC],
1344 [
1345   # Some Zero and Shark settings.
1346   # ZERO_ARCHFLAG tells the compiler which mode to build for
1347   case "${OPENJDK_TARGET_CPU}" in
1348     s390)
1349       ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}31"
1350       ;;
1351     *)
1352       ZERO_ARCHFLAG="${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}"
1353   esac
1354   FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$ZERO_ARCHFLAG], IF_FALSE: [ZERO_ARCHFLAG=""])
1355   AC_SUBST(ZERO_ARCHFLAG)
1356 
1357   # Check that the compiler supports -mX (or -qX on AIX) flags
1358   # Set COMPILER_SUPPORTS_TARGET_BITS_FLAG to 'true' if it does
1359   FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${COMPILER_TARGET_BITS_FLAG}${OPENJDK_TARGET_CPU_BITS}],
1360       IF_TRUE: [COMPILER_SUPPORTS_TARGET_BITS_FLAG=true],
1361       IF_FALSE: [COMPILER_SUPPORTS_TARGET_BITS_FLAG=false])
1362   AC_SUBST(COMPILER_SUPPORTS_TARGET_BITS_FLAG)
1363 
1364   AC_ARG_ENABLE([warnings-as-errors], [AS_HELP_STRING([--disable-warnings-as-errors],
1365       [do not consider native warnings to be an error @<:@enabled@:>@])])
1366 
1367   AC_MSG_CHECKING([if native warnings are errors])
1368   if test "x$enable_warnings_as_errors" = "xyes"; then
1369     AC_MSG_RESULT([yes (explicitely set)])
1370     WARNINGS_AS_ERRORS=true
1371   elif test "x$enable_warnings_as_errors" = "xno"; then
1372     AC_MSG_RESULT([no])
1373     WARNINGS_AS_ERRORS=false
1374   elif test "x$enable_warnings_as_errors" = "x"; then
1375     AC_MSG_RESULT([yes (default)])
1376     WARNINGS_AS_ERRORS=true
1377   else
1378     AC_MSG_ERROR([--enable-warnings-as-errors accepts no argument])
1379   fi
1380 
1381   if test "x$WARNINGS_AS_ERRORS" = "xfalse"; then
1382     # Set legacy hotspot variable
1383     HOTSPOT_SET_WARNINGS_AS_ERRORS="WARNINGS_ARE_ERRORS="
1384   else
1385     HOTSPOT_SET_WARNINGS_AS_ERRORS=""
1386   fi
1387 
1388   AC_SUBST(WARNINGS_AS_ERRORS)
1389   AC_SUBST(HOTSPOT_SET_WARNINGS_AS_ERRORS)
1390 
1391   case "${TOOLCHAIN_TYPE}" in
1392     microsoft)
1393       DISABLE_WARNING_PREFIX="-wd"
1394       CFLAGS_WARNINGS_ARE_ERRORS="-WX"
1395       ;;
1396     solstudio)
1397       DISABLE_WARNING_PREFIX="-erroff="
1398       CFLAGS_WARNINGS_ARE_ERRORS="-errtags -errwarn=%all"
1399       ;;
1400     gcc)
1401       # Prior to gcc 4.4, a -Wno-X where X is unknown for that version of gcc will cause an error
1402       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [-Wno-this-is-a-warning-that-do-not-exist],
1403           IF_TRUE: [GCC_CAN_DISABLE_WARNINGS=true],
1404           IF_FALSE: [GCC_CAN_DISABLE_WARNINGS=false]
1405       )
1406       if test "x$GCC_CAN_DISABLE_WARNINGS" = "xtrue"; then
1407         DISABLE_WARNING_PREFIX="-Wno-"
1408       else
1409         DISABLE_WARNING_PREFIX=
1410       fi
1411       CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
1412       # Repeate the check for the BUILD_CC and BUILD_CXX. Need to also reset
1413       # CFLAGS since any target specific flags will likely not work with the
1414       # build compiler
1415       CC_OLD="$CC"
1416       CXX_OLD="$CXX"
1417       CC="$BUILD_CC"
1418       CXX="$BUILD_CXX"
1419       CFLAGS_OLD="$CFLAGS"
1420       CFLAGS=""
1421       FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [-Wno-this-is-a-warning-that-do-not-exist],
1422           IF_TRUE: [BUILD_CC_CAN_DISABLE_WARNINGS=true],
1423           IF_FALSE: [BUILD_CC_CAN_DISABLE_WARNINGS=false]
1424       )
1425       if test "x$BUILD_CC_CAN_DISABLE_WARNINGS" = "xtrue"; then
1426         BUILD_CC_DISABLE_WARNING_PREFIX="-Wno-"
1427       else
1428         BUILD_CC_DISABLE_WARNING_PREFIX=
1429       fi
1430       CC="$CC_OLD"
1431       CXX="$CXX_OLD"
1432       CFLAGS="$CFLAGS_OLD"
1433       ;;
1434     clang)
1435       DISABLE_WARNING_PREFIX="-Wno-"
1436       CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
1437       ;;
1438     xlc)
1439       DISABLE_WARNING_PREFIX="-qsuppress="
1440       CFLAGS_WARNINGS_ARE_ERRORS="-qhalt=w"
1441       ;;
1442   esac
1443   AC_SUBST(DISABLE_WARNING_PREFIX)
1444   AC_SUBST(BUILD_CC_DISABLE_WARNING_PREFIX)
1445   AC_SUBST(CFLAGS_WARNINGS_ARE_ERRORS)
1446 ])
1447 
1448 # FLAGS_SETUP_GCC6_COMPILER_FLAGS([PREFIX])
1449 # Arguments:
1450 # $1 - Optional prefix for each variable defined.
1451 AC_DEFUN([FLAGS_SETUP_GCC6_COMPILER_FLAGS],
1452 [
1453   # These flags are required for GCC 6 builds as undefined behaviour in OpenJDK code
1454   # runs afoul of the more aggressive versions of these optimisations.
1455   # Notably, value range propagation now assumes that the this pointer of C++
1456   # member functions is non-null.
1457   NO_DELETE_NULL_POINTER_CHECKS_CFLAG="-fno-delete-null-pointer-checks"
1458   dnl Argument check is disabled until FLAGS_COMPILER_CHECK_ARGUMENTS handles cross-compilation
1459   dnl FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$NO_DELETE_NULL_POINTER_CHECKS_CFLAG -Werror],
1460   dnl                                        IF_FALSE: [NO_DELETE_NULL_POINTER_CHECKS_CFLAG=""])
1461   NO_LIFETIME_DSE_CFLAG="-fno-lifetime-dse"
1462   dnl Argument check is disabled until FLAGS_COMPILER_CHECK_ARGUMENTS handles cross-compilation
1463   dnl FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$NO_LIFETIME_DSE_CFLAG -Werror],
1464   dnl                                        IF_FALSE: [NO_LIFETIME_DSE_CFLAG=""])
1465   AC_MSG_NOTICE([GCC >= 6 detected; adding ${NO_DELETE_NULL_POINTER_CHECKS_CFLAG} and ${NO_LIFETIME_DSE_CFLAG}])
1466   $1CFLAGS_JDK="[$]$1CFLAGS_JDK ${NO_DELETE_NULL_POINTER_CHECKS_CFLAG} ${NO_LIFETIME_DSE_CFLAG}"
1467   $1JVM_CFLAGS="[$]$1JVM_CFLAGS ${NO_DELETE_NULL_POINTER_CHECKS_CFLAG} ${NO_LIFETIME_DSE_CFLAG}"
1468 ])