1 #
   2 # Copyright (c) 2011, 2025, 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 # Set the debug level
  28 #    release: no debug information, all optimizations, no asserts.
  29 #    optimized: no debug information, all optimizations, no asserts, HotSpot target is 'optimized'.
  30 #    fastdebug: debug information (-g), all optimizations, all asserts
  31 #    slowdebug: debug information (-g), no optimizations, all asserts
  32 AC_DEFUN_ONCE([JDKOPT_SETUP_DEBUG_LEVEL],
  33 [
  34   DEBUG_LEVEL="release"
  35 
  36   UTIL_ARG_ENABLE(NAME: debug, DEFAULT: false, RESULT: ENABLE_DEBUG,
  37       DESC: [enable debugging (shorthand for --with-debug-level=fastdebug)],
  38       IF_ENABLED: [ DEBUG_LEVEL="fastdebug" ])
  39 
  40   AC_MSG_CHECKING([which debug level to use])
  41   AC_ARG_WITH([debug-level], [AS_HELP_STRING([--with-debug-level],
  42       [set the debug level (release, fastdebug, slowdebug, optimized) @<:@release@:>@])],
  43       [
  44         DEBUG_LEVEL="${withval}"
  45         if test "x$ENABLE_DEBUG" = xtrue; then
  46           AC_MSG_ERROR([You cannot use both --enable-debug and --with-debug-level at the same time.])
  47         fi
  48       ])
  49   AC_MSG_RESULT([$DEBUG_LEVEL])
  50 
  51   if test "x$DEBUG_LEVEL" != xrelease && \
  52       test "x$DEBUG_LEVEL" != xoptimized && \
  53       test "x$DEBUG_LEVEL" != xfastdebug && \
  54       test "x$DEBUG_LEVEL" != xslowdebug; then
  55     AC_MSG_ERROR([Allowed debug levels are: release, fastdebug, slowdebug and optimized])
  56   fi
  57 
  58   # Translate DEBUG_LEVEL to debug level used by Hotspot
  59   HOTSPOT_DEBUG_LEVEL="$DEBUG_LEVEL"
  60   if test "x$DEBUG_LEVEL" = xrelease; then
  61     HOTSPOT_DEBUG_LEVEL="product"
  62   elif test "x$DEBUG_LEVEL" = xslowdebug; then
  63     HOTSPOT_DEBUG_LEVEL="debug"
  64   fi
  65 
  66   if test "x$DEBUG_LEVEL" = xoptimized; then
  67     # The debug level 'optimized' is a little special because it is currently only
  68     # applicable to the HotSpot build where it means to build a completely
  69     # optimized version of the VM without any debugging code (like for the
  70     # 'release' debug level which is called 'product' in the HotSpot build) but
  71     # with the exception that it can contain additional code which is otherwise
  72     # protected by '#ifndef PRODUCT' macros. These 'optimized' builds are used to
  73     # test new and/or experimental features which are not intended for customer
  74     # shipment. Because these new features need to be tested and benchmarked in
  75     # real world scenarios, we want to build the containing JDK at the 'release'
  76     # debug level.
  77     DEBUG_LEVEL="release"
  78   fi
  79 
  80   AC_SUBST(HOTSPOT_DEBUG_LEVEL)
  81   AC_SUBST(DEBUG_LEVEL)
  82 ])
  83 
  84 ################################################################################
  85 #
  86 # Should we build only OpenJDK even if closed sources are present?
  87 #
  88 AC_DEFUN_ONCE([JDKOPT_SETUP_OPEN_OR_CUSTOM],
  89 [
  90   UTIL_ARG_ENABLE(NAME: openjdk-only, DEFAULT: false,
  91       RESULT: SUPPRESS_CUSTOM_EXTENSIONS,
  92       DESC: [suppress building custom source even if present],
  93       CHECKING_MSG: [if custom source is suppressed (openjdk-only)])
  94 ])
  95 
  96 AC_DEFUN_ONCE([JDKOPT_SETUP_JDK_OPTIONS],
  97 [
  98   # Should we build a JDK without a graphical UI?
  99   UTIL_ARG_ENABLE(NAME: headless-only, DEFAULT: false,
 100       RESULT: ENABLE_HEADLESS_ONLY,
 101       DESC: [only build headless (no GUI) support],
 102       CHECKING_MSG: [if we should build headless-only (no GUI)])
 103   AC_SUBST(ENABLE_HEADLESS_ONLY)
 104 
 105   # should we linktime gc unused code sections in the JDK build ?
 106   if test "x$OPENJDK_TARGET_OS" = "xlinux"; then
 107     if test "x$OPENJDK_TARGET_CPU" = "xs390x" || test "x$OPENJDK_TARGET_CPU" = "xppc64le"; then
 108       LINKTIME_GC_DEFAULT=true
 109     else
 110       LINKTIME_GC_DEFAULT=false
 111     fi
 112   else
 113     LINKTIME_GC_DEFAULT=false
 114   fi
 115 
 116   UTIL_ARG_ENABLE(NAME: linktime-gc, DEFAULT: $LINKTIME_GC_DEFAULT,
 117       DEFAULT_DESC: [auto], RESULT: ENABLE_LINKTIME_GC,
 118       DESC: [use link time gc on unused code sections in the JDK build],
 119       CHECKING_MSG: [if linker should clean out unused code (linktime-gc)])
 120   AC_SUBST(ENABLE_LINKTIME_GC)
 121 
 122   # Check for full doc dependencies
 123   FULL_DOCS_AVAILABLE=true
 124   AC_MSG_CHECKING([for graphviz dot])
 125   if test "x$DOT" != "x"; then
 126     AC_MSG_RESULT([yes])
 127   else
 128     AC_MSG_RESULT([no, cannot generate full docs or man pages])
 129     FULL_DOCS_AVAILABLE=false
 130   fi
 131 
 132   AC_MSG_CHECKING([for pandoc])
 133   if test "x$ENABLE_PANDOC" = "xtrue"; then
 134     AC_MSG_RESULT([yes])
 135   else
 136     AC_MSG_RESULT([no, cannot generate full docs or man pages])
 137     FULL_DOCS_AVAILABLE=false
 138   fi
 139 
 140   # Should we build the complete docs, or just a lightweight version?
 141   UTIL_ARG_ENABLE(NAME: full-docs, DEFAULT: auto, RESULT: ENABLE_FULL_DOCS,
 142       AVAILABLE: $FULL_DOCS_AVAILABLE, DESC: [build complete documentation],
 143       DEFAULT_DESC: [enabled if all tools found])
 144   AC_SUBST(ENABLE_FULL_DOCS)
 145 
 146   # Choose cacerts source file
 147   AC_ARG_WITH(cacerts-file, [AS_HELP_STRING([--with-cacerts-file],
 148       [specify alternative cacerts file])])
 149   AC_MSG_CHECKING([for cacerts file])
 150   if test "x$with_cacerts_file" == x; then
 151     AC_MSG_RESULT([default])
 152   else
 153     CACERTS_FILE=$with_cacerts_file
 154     if test ! -f "$CACERTS_FILE"; then
 155       AC_MSG_RESULT([fail])
 156       AC_MSG_ERROR([Specified cacerts file "$CACERTS_FILE" does not exist])
 157     fi
 158     AC_MSG_RESULT([$CACERTS_FILE])
 159   fi
 160   AC_SUBST(CACERTS_FILE)
 161 
 162   # Choose cacerts source folder for user provided PEM files
 163   AC_ARG_WITH(cacerts-src, [AS_HELP_STRING([--with-cacerts-src],
 164       [specify alternative cacerts source folder containing certificates])])
 165   CACERTS_SRC=""
 166   AC_MSG_CHECKING([for cacerts source])
 167   if test "x$with_cacerts_src" == x; then
 168     AC_MSG_RESULT([default])
 169   else
 170     CACERTS_SRC=$with_cacerts_src
 171     if test ! -d "$CACERTS_SRC"; then
 172       AC_MSG_RESULT([fail])
 173       AC_MSG_ERROR([Specified cacerts source folder "$CACERTS_SRC" does not exist])
 174     fi
 175     AC_MSG_RESULT([$CACERTS_SRC])
 176   fi
 177   AC_SUBST(CACERTS_SRC)
 178 
 179   # Enable or disable unlimited crypto
 180   UTIL_ARG_ENABLE(NAME: unlimited-crypto, DEFAULT: true, RESULT: UNLIMITED_CRYPTO,
 181       DESC: [enable unlimited crypto policy])
 182   AC_SUBST(UNLIMITED_CRYPTO)
 183 
 184   # Should we build the serviceability agent (SA)?
 185   INCLUDE_SA=true
 186   if HOTSPOT_CHECK_JVM_VARIANT(zero); then
 187     INCLUDE_SA=false
 188   fi
 189   if test "x$OPENJDK_TARGET_OS" = xaix ; then
 190     INCLUDE_SA=false
 191   fi
 192   if test "x$OPENJDK_TARGET_CPU" = xs390x ; then
 193     INCLUDE_SA=false
 194   fi
 195   AC_SUBST(INCLUDE_SA)
 196 
 197   # Setup default CDS alignment. On platforms where one build may run on machines with different
 198   # page sizes, the JVM choses a compatible alignment to fit all possible page sizes. This slightly
 199   # increases archive size.
 200   # The only platform having this problem at the moment is Linux on aarch64, which may encounter
 201   # three different page sizes: 4K, 64K, and if run on Mac m1 hardware, 16K.
 202   COMPATIBLE_CDS_ALIGNMENT_DEFAULT=false
 203   if test "x$OPENJDK_TARGET_OS" = "xlinux" && test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
 204     COMPATIBLE_CDS_ALIGNMENT_DEFAULT=auto
 205   fi
 206 
 207   # Compress jars
 208   COMPRESS_JARS=false
 209 
 210   AC_SUBST(COMPRESS_JARS)
 211 
 212   # Setup default copyright year. Mostly overridden when building close to a new year.
 213   AC_ARG_WITH(copyright-year, [AS_HELP_STRING([--with-copyright-year],
 214       [Set copyright year value for build @<:@current year/source-date@:>@])])
 215   if test "x$with_copyright_year" = xyes; then
 216     AC_MSG_ERROR([Copyright year must have a value])
 217   elif test "x$with_copyright_year" != x; then
 218     COPYRIGHT_YEAR="$with_copyright_year"
 219   elif test "x$SOURCE_DATE" != xupdated; then
 220     if test "x$IS_GNU_DATE" = xyes; then
 221       COPYRIGHT_YEAR=`$DATE --date=@$SOURCE_DATE +%Y`
 222     else
 223       COPYRIGHT_YEAR=`$DATE -j -f %s $SOURCE_DATE +%Y`
 224     fi
 225   else
 226     COPYRIGHT_YEAR=`$DATE +'%Y'`
 227   fi
 228   AC_SUBST(COPYRIGHT_YEAR)
 229 
 230   # Override default library path
 231   AC_ARG_WITH([jni-libpath], [AS_HELP_STRING([--with-jni-libpath],
 232       [override default JNI library search path])])
 233   AC_MSG_CHECKING([for jni library path])
 234   if test "x${with_jni_libpath}" = "x" || test "x${with_jni_libpath}" = "xno"; then
 235     AC_MSG_RESULT([default])
 236   elif test "x${with_jni_libpath}" = "xyes"; then
 237     AC_MSG_RESULT([invalid])
 238     AC_MSG_ERROR([The --with-jni-libpath option requires an argument.])
 239   else
 240     HOTSPOT_OVERRIDE_LIBPATH=${with_jni_libpath}
 241     if test "x$OPENJDK_TARGET_OS" != "xlinux" &&
 242         test "x$OPENJDK_TARGET_OS" != "xbsd" &&
 243         test "x$OPENJDK_TARGET_OS" != "xaix"; then
 244       AC_MSG_RESULT([fail])
 245       AC_MSG_ERROR([Overriding JNI library path is supported only on Linux, BSD and AIX.])
 246     fi
 247     AC_MSG_RESULT(${HOTSPOT_OVERRIDE_LIBPATH})
 248   fi
 249   AC_SUBST(HOTSPOT_OVERRIDE_LIBPATH)
 250 
 251 ])
 252 
 253 ################################################################################
 254 
 255 AC_DEFUN_ONCE([JDKOPT_SETUP_DEBUG_SYMBOLS],
 256 [
 257   #
 258   # Native debug symbols.
 259   # This must be done after the toolchain is setup, since we're looking at objcopy.
 260   #
 261   AC_MSG_CHECKING([what type of native debug symbols to use])
 262   AC_ARG_WITH([native-debug-symbols],
 263       [AS_HELP_STRING([--with-native-debug-symbols],
 264       [set the native debug symbol configuration (none, internal, external, zipped) @<:@varying@:>@])],
 265       [
 266         if test "x$OPENJDK_TARGET_OS" = xwindows; then
 267           if test "x$withval" = xinternal; then
 268             AC_MSG_ERROR([Windows does not support the parameter 'internal' for --with-native-debug-symbols])
 269           fi
 270         fi
 271       ],
 272       [
 273         with_native_debug_symbols="external"
 274       ])
 275   AC_MSG_RESULT([$with_native_debug_symbols])
 276 
 277   if test "x$with_native_debug_symbols" = xnone; then
 278     COMPILE_WITH_DEBUG_SYMBOLS=false
 279     COPY_DEBUG_SYMBOLS=false
 280     ZIP_EXTERNAL_DEBUG_SYMBOLS=false
 281   elif test "x$with_native_debug_symbols" = xinternal; then
 282     COMPILE_WITH_DEBUG_SYMBOLS=true
 283     COPY_DEBUG_SYMBOLS=false
 284     ZIP_EXTERNAL_DEBUG_SYMBOLS=false
 285   elif test "x$with_native_debug_symbols" = xexternal; then
 286 
 287     if test "x$OPENJDK_TARGET_OS" = xlinux; then
 288       if test "x$OBJCOPY" = x; then
 289         # enabling of enable-debug-symbols and can't find objcopy
 290         # this is an error
 291         AC_MSG_ERROR([Unable to find objcopy, cannot enable native debug symbols])
 292       fi
 293     fi
 294 
 295     COMPILE_WITH_DEBUG_SYMBOLS=true
 296     COPY_DEBUG_SYMBOLS=true
 297     ZIP_EXTERNAL_DEBUG_SYMBOLS=false
 298   elif test "x$with_native_debug_symbols" = xzipped; then
 299 
 300     if test "x$OPENJDK_TARGET_OS" = xlinux; then
 301       if test "x$OBJCOPY" = x; then
 302         # enabling of enable-debug-symbols and can't find objcopy
 303         # this is an error
 304         AC_MSG_ERROR([Unable to find objcopy, cannot enable native debug symbols])
 305       fi
 306     fi
 307 
 308     COMPILE_WITH_DEBUG_SYMBOLS=true
 309     COPY_DEBUG_SYMBOLS=true
 310     ZIP_EXTERNAL_DEBUG_SYMBOLS=true
 311   else
 312     AC_MSG_ERROR([Allowed native debug symbols are: none, internal, external, zipped])
 313   fi
 314 
 315   AC_SUBST(COMPILE_WITH_DEBUG_SYMBOLS)
 316   AC_SUBST(COPY_DEBUG_SYMBOLS)
 317   AC_SUBST(ZIP_EXTERNAL_DEBUG_SYMBOLS)
 318 
 319   # Should we add external native debug symbols to the shipped bundles?
 320   AC_MSG_CHECKING([if we should add external native debug symbols to the shipped bundles])
 321   AC_ARG_WITH([external-symbols-in-bundles],
 322       [AS_HELP_STRING([--with-external-symbols-in-bundles],
 323       [which type of external native debug symbol information shall be shipped with bundles/images (none, public, full).
 324       @<:@none in release builds, full otherwise. --with-native-debug-symbols=external/zipped is a prerequisite. public is only supported on Windows@:>@])],
 325       [],
 326       [with_external_symbols_in_bundles=default])
 327 
 328   if test "x$with_external_symbols_in_bundles" = x || test "x$with_external_symbols_in_bundles" = xnone ; then
 329     AC_MSG_RESULT([no])
 330   elif test "x$with_external_symbols_in_bundles" = xfull || test "x$with_external_symbols_in_bundles" = xpublic ; then
 331     if test "x$COPY_DEBUG_SYMBOLS" != xtrue ; then
 332       AC_MSG_ERROR([--with-external-symbols-in-bundles only works when --with-native-debug-symbols=external/zipped is used!])
 333     elif test "x$with_external_symbols_in_bundles" = xpublic && test "x$OPENJDK_TARGET_OS" != xwindows ; then
 334       AC_MSG_ERROR([--with-external-symbols-in-bundles=public is only supported on Windows!])
 335     fi
 336 
 337     if test "x$with_external_symbols_in_bundles" = xfull ; then
 338       AC_MSG_RESULT([full])
 339       SHIP_DEBUG_SYMBOLS=full
 340     else
 341       AC_MSG_RESULT([public])
 342       SHIP_DEBUG_SYMBOLS=public
 343     fi
 344   elif test "x$with_external_symbols_in_bundles" = xdefault ; then
 345     if test "x$DEBUG_LEVEL" = xrelease ; then
 346       AC_MSG_RESULT([no (default)])
 347     elif test "x$COPY_DEBUG_SYMBOLS" = xtrue ; then
 348       AC_MSG_RESULT([full (default)])
 349       SHIP_DEBUG_SYMBOLS=full
 350     else
 351       AC_MSG_RESULT([no (default, native debug symbols are not external/zipped)])
 352     fi
 353   else
 354     AC_MSG_ERROR([$with_external_symbols_in_bundles is an unknown value for --with-external-symbols-in-bundles])
 355   fi
 356 
 357   AC_SUBST(SHIP_DEBUG_SYMBOLS)
 358 ])
 359 
 360 ################################################################################
 361 #
 362 # Native and Java code coverage
 363 #
 364 AC_DEFUN_ONCE([JDKOPT_SETUP_CODE_COVERAGE],
 365 [
 366   UTIL_ARG_ENABLE(NAME: native-coverage, DEFAULT: false, RESULT: GCOV_ENABLED,
 367       DESC: [enable native compilation with code coverage data],
 368       CHECK_AVAILABLE: [
 369         AC_MSG_CHECKING([if native coverage is available])
 370         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
 371             test "x$TOOLCHAIN_TYPE" = "xclang"; then
 372           AC_MSG_RESULT([yes])
 373         else
 374           AC_MSG_RESULT([no])
 375           AVAILABLE=false
 376         fi
 377       ],
 378       IF_ENABLED: [
 379         GCOV_CFLAGS="-fprofile-arcs -ftest-coverage -fno-inline"
 380         GCOV_LDFLAGS="-fprofile-arcs"
 381         JVM_CFLAGS="$JVM_CFLAGS $GCOV_CFLAGS"
 382         JVM_LDFLAGS="$JVM_LDFLAGS $GCOV_LDFLAGS"
 383         CFLAGS_JDKLIB="$CFLAGS_JDKLIB $GCOV_CFLAGS"
 384         CFLAGS_JDKEXE="$CFLAGS_JDKEXE $GCOV_CFLAGS"
 385         CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $GCOV_CFLAGS"
 386         CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $GCOV_CFLAGS"
 387         LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $GCOV_LDFLAGS"
 388         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $GCOV_LDFLAGS"
 389         LDFLAGS_STATIC_JDK="$LDFLAGS_STATIC_JDK $GCOV_LDFLAGS"
 390       ])
 391   AC_SUBST(GCOV_ENABLED)
 392 
 393   AC_ARG_WITH(jcov, [AS_HELP_STRING([--with-jcov],
 394       [jcov library location])])
 395   AC_ARG_WITH(jcov-input-jdk, [AS_HELP_STRING([--with-jcov-input-jdk],
 396       [jdk image to instrument])])
 397   AC_ARG_WITH(jcov-filters, [AS_HELP_STRING([--with-jcov-filters],
 398       [filters to limit code for jcov instrumentation and report generation])])
 399   JCOV_HOME=
 400   JCOV_INPUT_JDK=
 401   JCOV_ENABLED=
 402   JCOV_FILTERS=
 403   if test "x$with_jcov" = "x" ; then
 404     JCOV_ENABLED="false"
 405   else
 406     JCOV_HOME="$with_jcov"
 407     if test ! -f "$JCOV_HOME/lib/jcov.jar"; then
 408       AC_MSG_RESULT([fail])
 409       AC_MSG_ERROR([Invalid JCov bundle: "$JCOV_HOME/lib/jcov.jar" does not exist])
 410     fi
 411     JCOV_ENABLED="true"
 412     UTIL_FIXUP_PATH(JCOV_HOME)
 413     if test "x$with_jcov_input_jdk" != "x" ; then
 414       JCOV_INPUT_JDK="$with_jcov_input_jdk"
 415       if test ! -f "$JCOV_INPUT_JDK/bin/java" && test ! -f "$JCOV_INPUT_JDK/bin/java.exe"; then
 416         AC_MSG_RESULT([fail])
 417         AC_MSG_ERROR([Invalid JDK bundle: "$JCOV_INPUT_JDK/bin/java" does not exist])
 418       fi
 419       UTIL_FIXUP_PATH(JCOV_INPUT_JDK)
 420     fi
 421     if test "x$with_jcov_filters" != "x" ; then
 422       JCOV_FILTERS="$with_jcov_filters"
 423     fi
 424   fi
 425 
 426   UTIL_ARG_WITH(NAME: jcov-modules, TYPE: string,
 427       DEFAULT: [], RESULT: JCOV_MODULES_COMMMA_SEPARATED,
 428       DESC: [which modules to include in jcov (comma-separated)],
 429       OPTIONAL: true)
 430 
 431   # Replace ","  with " ".
 432   JCOV_MODULES=${JCOV_MODULES_COMMMA_SEPARATED//,/ }
 433   AC_SUBST(JCOV_ENABLED)
 434   AC_SUBST(JCOV_HOME)
 435   AC_SUBST(JCOV_INPUT_JDK)
 436   AC_SUBST(JCOV_FILTERS)
 437   AC_SUBST(JCOV_MODULES)
 438 ])
 439 
 440 ################################################################################
 441 #
 442 # AddressSanitizer
 443 #
 444 AC_DEFUN_ONCE([JDKOPT_SETUP_ADDRESS_SANITIZER],
 445 [
 446   UTIL_ARG_ENABLE(NAME: asan, DEFAULT: false, RESULT: ASAN_ENABLED,
 447       DESC: [enable AddressSanitizer],
 448       CHECK_AVAILABLE: [
 449         AC_MSG_CHECKING([if AddressSanitizer (asan) is available])
 450         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
 451             test "x$TOOLCHAIN_TYPE" = "xclang" ||
 452             test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
 453           AC_MSG_RESULT([yes])
 454         else
 455           AC_MSG_RESULT([no])
 456           AVAILABLE=false
 457         fi
 458       ],
 459       IF_ENABLED: [
 460         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
 461             test "x$TOOLCHAIN_TYPE" = "xclang"; then
 462           # ASan is simply incompatible with gcc -Wstringop-truncation. See
 463           # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85650
 464           # It's harmless to be suppressed in clang as well.
 465           ASAN_CFLAGS="-fsanitize=address -Wno-stringop-truncation -fno-omit-frame-pointer -fno-common -DADDRESS_SANITIZER"
 466           ASAN_LDFLAGS="-fsanitize=address"
 467           # detect_stack_use_after_return causes ASAN to offload stack-local
 468           # variables to c-heap and therefore breaks assumptions in hotspot
 469           # that rely on data (e.g. Marks) living in thread stacks.
 470           if test "x$TOOLCHAIN_TYPE" = "xgcc"; then
 471             ASAN_CFLAGS="$ASAN_CFLAGS --param asan-use-after-return=0"
 472           fi
 473           if test "x$TOOLCHAIN_TYPE" = "xclang"; then
 474             ASAN_CFLAGS="$ASAN_CFLAGS -fsanitize-address-use-after-return=never"
 475             ASAN_LDFLAGS="$ASAN_LDFLAGS -shared-libasan"
 476           fi
 477         elif test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
 478           # -Oy- is equivalent to -fno-omit-frame-pointer in GCC/Clang.
 479           ASAN_CFLAGS="-fsanitize=address -Oy- -DADDRESS_SANITIZER"
 480           # MSVC produces a warning if you pass -fsanitize=address to the linker. It also complains
 481           $ if -DEBUG is not passed to the linker when building with ASan.
 482           ASAN_LDFLAGS="-debug"
 483           # -fsanitize-address-use-after-return is off by default in MS Visual Studio 22 (19.37.32824).
 484           # cl : Command line warning D9002 : ignoring unknown option '-fno-sanitize-address-use-after-return'
 485         fi
 486         JVM_CFLAGS="$JVM_CFLAGS $ASAN_CFLAGS"
 487         JVM_LDFLAGS="$JVM_LDFLAGS $ASAN_LDFLAGS"
 488         CFLAGS_JDKLIB="$CFLAGS_JDKLIB $ASAN_CFLAGS"
 489         CFLAGS_JDKEXE="$CFLAGS_JDKEXE $ASAN_CFLAGS"
 490         CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $ASAN_CFLAGS"
 491         CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $ASAN_CFLAGS"
 492         LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $ASAN_LDFLAGS"
 493         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $ASAN_LDFLAGS"
 494         LDFLAGS_STATIC_JDK="$LDFLAGS_STATIC_JDK $ASAN_LDFLAGS"
 495       ])
 496   AC_SUBST(ASAN_ENABLED)
 497 ])
 498 
 499 ################################################################################
 500 #
 501 # Static analyzer
 502 #
 503 AC_DEFUN_ONCE([JDKOPT_SETUP_STATIC_ANALYZER],
 504 [
 505   UTIL_ARG_ENABLE(NAME: static-analyzer, DEFAULT: false, RESULT: STATIC_ANALYZER_ENABLED,
 506       DESC: [enable the GCC static analyzer],
 507       CHECK_AVAILABLE: [
 508         AC_MSG_CHECKING([if static analyzer is available])
 509         if test "x$TOOLCHAIN_TYPE" = "xgcc"; then
 510           AC_MSG_RESULT([yes])
 511         else
 512           AC_MSG_RESULT([no])
 513           AVAILABLE=false
 514         fi
 515       ],
 516       IF_ENABLED: [
 517         STATIC_ANALYZER_CFLAGS="-fanalyzer -Wno-analyzer-fd-leak"
 518         CFLAGS_JDKLIB="$CFLAGS_JDKLIB $STATIC_ANALYZER_CFLAGS"
 519         CFLAGS_JDKEXE="$CFLAGS_JDKEXE $STATIC_ANALYZER_CFLAGS"
 520       ])
 521   AC_SUBST(STATIC_ANALYZER_ENABLED)
 522 ])
 523 
 524 ################################################################################
 525 #
 526 # LeakSanitizer
 527 #
 528 AC_DEFUN_ONCE([JDKOPT_SETUP_LEAK_SANITIZER],
 529 [
 530   UTIL_ARG_ENABLE(NAME: lsan, DEFAULT: false, RESULT: LSAN_ENABLED,
 531       DESC: [enable LeakSanitizer],
 532       CHECK_AVAILABLE: [
 533         AC_MSG_CHECKING([if LeakSanitizer (lsan) is available])
 534         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
 535             test "x$TOOLCHAIN_TYPE" = "xclang"; then
 536           AC_MSG_RESULT([yes])
 537         else
 538           AC_MSG_RESULT([no])
 539           AVAILABLE=false
 540         fi
 541       ],
 542       IF_ENABLED: [
 543         LSAN_CFLAGS="-fsanitize=leak -fno-omit-frame-pointer -DLEAK_SANITIZER"
 544         LSAN_LDFLAGS="-fsanitize=leak"
 545         JVM_CFLAGS="$JVM_CFLAGS $LSAN_CFLAGS"
 546         JVM_LDFLAGS="$JVM_LDFLAGS $LSAN_LDFLAGS"
 547         CFLAGS_JDKLIB="$CFLAGS_JDKLIB $LSAN_CFLAGS"
 548         CFLAGS_JDKEXE="$CFLAGS_JDKEXE $LSAN_CFLAGS"
 549         CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $LSAN_CFLAGS"
 550         CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $LSAN_CFLAGS"
 551         LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $LSAN_LDFLAGS"
 552         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $LSAN_LDFLAGS"
 553         LDFLAGS_STATIC_JDK="$LDFLAGS_STATIC_JDK $LSAN_LDFLAGS"
 554       ])
 555   AC_SUBST(LSAN_ENABLED)
 556 ])
 557 
 558 ################################################################################
 559 #
 560 # UndefinedBehaviorSanitizer
 561 #
 562 AC_DEFUN_ONCE([JDKOPT_SETUP_UNDEFINED_BEHAVIOR_SANITIZER],
 563 [
 564   UTIL_ARG_WITH(NAME: additional-ubsan-checks, TYPE: string,
 565       DEFAULT: [],
 566       DESC: [Customizes the ubsan checks],
 567       OPTIONAL: true)
 568 
 569   # GCC reports lots of likely false positives for stringop-truncation and format-overflow.
 570   # GCC 13 also for array-bounds and stringop-overflow
 571   # Silence them for now.
 572   UBSAN_CHECKS="-fsanitize=undefined -fsanitize=float-divide-by-zero -fno-sanitize=shift-base -fno-sanitize=alignment \
 573       $ADDITIONAL_UBSAN_CHECKS"
 574   UBSAN_CFLAGS="$UBSAN_CHECKS -Wno-array-bounds -fno-omit-frame-pointer -DUNDEFINED_BEHAVIOR_SANITIZER"
 575   if test "x$TOOLCHAIN_TYPE" = "xgcc"; then
 576     UBSAN_CFLAGS="$UBSAN_CFLAGS -Wno-format-overflow -Wno-stringop-overflow -Wno-stringop-truncation"
 577   fi
 578   UBSAN_LDFLAGS="$UBSAN_CHECKS"
 579   # On AIX, the llvm_symbolizer is not found out of the box, so we have to provide the
 580   # full qualified llvm_symbolizer path in the __ubsan_default_options() function in
 581   # make/data/ubsan/ubsan_default_options.c. To get it there we compile our sources
 582   # with an additional define LLVM_SYMBOLIZER, which we set here.
 583   # To calculate the correct llvm_symbolizer path we can use the location of the compiler, because
 584   # their relation is fixed.
 585   # In the ubsan case we have to link every binary with the C++-compiler as linker, because inherently
 586   # the C-Compiler and the C++-compiler used as linker provide a different set of ubsan exports.
 587   # Linking an executable with the C-compiler and one of its shared libraries with the C++-compiler
 588   # leeds to unresolved symbols.
 589   if test "x$TOOLCHAIN_TYPE" = "xclang" && test "x$OPENJDK_TARGET_OS" = "xaix"; then
 590     UBSAN_CFLAGS="$UBSAN_CFLAGS -DLLVM_SYMBOLIZER=$(dirname $(dirname $CC))/tools/ibm-llvm-symbolizer"
 591     UBSAN_LDFLAGS="$UBSAN_LDFLAGS -Wl,-bbigtoc"
 592     LD="$LDCXX"
 593   fi
 594   UTIL_ARG_ENABLE(NAME: ubsan, DEFAULT: false, RESULT: UBSAN_ENABLED,
 595       DESC: [enable UndefinedBehaviorSanitizer],
 596       CHECK_AVAILABLE: [
 597         AC_MSG_CHECKING([if UndefinedBehaviorSanitizer (ubsan) is available])
 598         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
 599             test "x$TOOLCHAIN_TYPE" = "xclang"; then
 600           AC_MSG_RESULT([yes])
 601         else
 602           AC_MSG_RESULT([no])
 603           AVAILABLE=false
 604         fi
 605       ],
 606       IF_ENABLED: [
 607         JVM_CFLAGS="$JVM_CFLAGS $UBSAN_CFLAGS"
 608         JVM_LDFLAGS="$JVM_LDFLAGS $UBSAN_LDFLAGS"
 609         CFLAGS_JDKLIB="$CFLAGS_JDKLIB $UBSAN_CFLAGS"
 610         CFLAGS_JDKEXE="$CFLAGS_JDKEXE $UBSAN_CFLAGS"
 611         CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $UBSAN_CFLAGS"
 612         CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $UBSAN_CFLAGS"
 613         LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $UBSAN_LDFLAGS"
 614         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $UBSAN_LDFLAGS"
 615         LDFLAGS_STATIC_JDK="$LDFLAGS_STATIC_JDK $UBSAN_LDFLAGS"
 616       ])
 617   if test "x$UBSAN_ENABLED" = xfalse; then
 618     UBSAN_CFLAGS=""
 619     UBSAN_LDFLAGS=""
 620   fi
 621   AC_SUBST(UBSAN_CFLAGS)
 622   AC_SUBST(UBSAN_LDFLAGS)
 623   AC_SUBST(UBSAN_ENABLED)
 624 ])
 625 
 626 ################################################################################
 627 #
 628 # jmod options.
 629 #
 630 AC_DEFUN_ONCE([JDKOPT_SETUP_JMOD_OPTIONS],
 631 [
 632   # Final JMODs are recompiled often during development, and java.base JMOD
 633   # includes the JVM libraries. In release mode, prefer to compress JMODs fully.
 634   # In debug mode, pay with a little extra space, but win a lot of CPU time back
 635   # with the lightest (but still some) compression.
 636   if test "x$DEBUG_LEVEL" = xrelease; then
 637     DEFAULT_JMOD_COMPRESS="zip-6"
 638   else
 639     DEFAULT_JMOD_COMPRESS="zip-1"
 640   fi
 641 
 642   UTIL_ARG_WITH(NAME: jmod-compress, TYPE: literal,
 643     VALID_VALUES: [zip-0 zip-1 zip-2 zip-3 zip-4 zip-5 zip-6 zip-7 zip-8 zip-9],
 644     DEFAULT: $DEFAULT_JMOD_COMPRESS,
 645     CHECKING_MSG: [for JMOD compression type],
 646     DESC: [specify JMOD compression type (zip-[0-9])]
 647   )
 648   AC_SUBST(JMOD_COMPRESS)
 649 ])
 650 
 651 ################################################################################
 652 #
 653 # jlink options.
 654 #
 655 AC_DEFUN_ONCE([JDKOPT_SETUP_JLINK_OPTIONS],
 656 [
 657 
 658   ################################################################################
 659   #
 660   # Configure option for building a JDK that is suitable for linking from the
 661   # run-time image without JMODs.
 662   #
 663   # Determines whether or not a suitable run-time image is being produced from
 664   # packaged modules. If set to 'true, changes the *default* of packaged
 665   # modules to 'false'.
 666   #
 667   UTIL_ARG_ENABLE(NAME: linkable-runtime, DEFAULT: false,
 668       RESULT: JLINK_PRODUCE_LINKABLE_RUNTIME,
 669       DESC: [enable a JDK build suitable for linking from the run-time image],
 670       CHECKING_MSG: [whether or not a JDK suitable for linking from the run-time image should be produced])
 671   AC_SUBST(JLINK_PRODUCE_LINKABLE_RUNTIME)
 672 
 673   if test "x$JLINK_PRODUCE_LINKABLE_RUNTIME" = xtrue; then
 674     DEFAULT_PACKAGED_MODULES=false
 675   else
 676     DEFAULT_PACKAGED_MODULES=true
 677   fi
 678 
 679   ################################################################################
 680   #
 681   # Configure option for packaged modules
 682   #
 683   # We keep packaged modules in the JDK image unless --enable-linkable-runtime is
 684   # requested.
 685   #
 686   UTIL_ARG_ENABLE(NAME: keep-packaged-modules, DEFAULT: $DEFAULT_PACKAGED_MODULES,
 687       RESULT: JLINK_KEEP_PACKAGED_MODULES,
 688       DESC: [enable keeping of packaged modules in jdk image],
 689       DEFAULT_DESC: [enabled by default unless --enable-linkable-runtime is set],
 690       CHECKING_MSG: [if packaged modules are kept])
 691   AC_SUBST(JLINK_KEEP_PACKAGED_MODULES)
 692 
 693   ################################################################################
 694   #
 695   # Extra jlink options to be (optionally) passed to the JDK build
 696   #
 697   UTIL_ARG_WITH(NAME: extra-jlink-flags, TYPE: string,
 698       DEFAULT: [],
 699       DESC: [extra flags to be passed to jlink during the build],
 700       OPTIONAL: true)
 701 
 702   JLINK_USER_EXTRA_FLAGS="$EXTRA_JLINK_FLAGS"
 703   AC_SUBST(JLINK_USER_EXTRA_FLAGS)
 704 ])
 705 
 706 ################################################################################
 707 #
 708 # Enable or disable generation of the classlist at build time
 709 #
 710 AC_DEFUN_ONCE([JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST],
 711 [
 712   # In GenerateLinkOptData.gmk, DumpLoadedClassList is used to generate the
 713   # classlist file. It never will work if CDS is disabled, since the VM will report
 714   # an error for DumpLoadedClassList.
 715   UTIL_ARG_ENABLE(NAME: generate-classlist, DEFAULT: auto,
 716       RESULT: ENABLE_GENERATE_CLASSLIST, AVAILABLE: $ENABLE_CDS,
 717       DESC: [enable generation of a CDS classlist at build time],
 718       DEFAULT_DESC: [enabled if the JVM feature 'cds' is enabled for all JVM variants],
 719       CHECKING_MSG: [if the CDS classlist generation should be enabled])
 720   AC_SUBST(ENABLE_GENERATE_CLASSLIST)
 721 ])
 722 
 723 ################################################################################
 724 #
 725 # Optionally filter resource translations
 726 #
 727 AC_DEFUN([JDKOPT_EXCLUDE_TRANSLATIONS],
 728 [
 729   AC_ARG_WITH([exclude-translations], [AS_HELP_STRING([--with-exclude-translations],
 730       [a comma separated list of locales to exclude translations for. Default is
 731       to include all translations present in the source.])])
 732 
 733   EXCLUDE_TRANSLATIONS=""
 734   AC_MSG_CHECKING([if any translations should be excluded])
 735   if test "x$with_exclude_translations" != "x"; then
 736     EXCLUDE_TRANSLATIONS="${with_exclude_translations//,/ }"
 737     AC_MSG_RESULT([yes: $EXCLUDE_TRANSLATIONS])
 738   else
 739     AC_MSG_RESULT([no])
 740   fi
 741 
 742   AC_SUBST(EXCLUDE_TRANSLATIONS)
 743 ])
 744 
 745 ################################################################################
 746 #
 747 # Disable the default CDS archive generation
 748 #
 749 AC_DEFUN([JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE],
 750 [
 751   UTIL_ARG_ENABLE(NAME: cds-archive, DEFAULT: auto, RESULT: BUILD_CDS_ARCHIVE,
 752       DESC: [enable generation of a default CDS archive in the product image],
 753       DEFAULT_DESC: [enabled if possible],
 754       CHECKING_MSG: [if a default CDS archive should be generated],
 755       CHECK_AVAILABLE: [
 756         AC_MSG_CHECKING([if CDS archive is available])
 757         if test "x$ENABLE_CDS" = "xfalse"; then
 758           AC_MSG_RESULT([no (CDS is disabled)])
 759           AVAILABLE=false
 760         elif test "x$COMPILE_TYPE" = "xcross"; then
 761           AC_MSG_RESULT([no (not possible with cross compilation)])
 762           AVAILABLE=false
 763         else
 764           AC_MSG_RESULT([yes])
 765         fi
 766       ])
 767   AC_SUBST(BUILD_CDS_ARCHIVE)
 768 ])
 769 
 770 ################################################################################
 771 #
 772 # Enable or disable the default CDS archive generation for Compact Object Headers
 773 #
 774 AC_DEFUN([JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE_COH],
 775 [
 776   UTIL_ARG_ENABLE(NAME: cds-archive-coh, DEFAULT: auto, RESULT: BUILD_CDS_ARCHIVE_COH,
 777       DESC: [enable generation of default CDS archives for compact object headers (requires --enable-cds-archive)],
 778       DEFAULT_DESC: [auto],
 779       CHECKING_MSG: [if default CDS archives for compact object headers should be generated],
 780       CHECK_AVAILABLE: [
 781         AC_MSG_CHECKING([if CDS archive with compact object headers is available])
 782         if test "x$BUILD_CDS_ARCHIVE" = "xfalse"; then
 783           AC_MSG_RESULT([no (CDS default archive generation is disabled)])
 784           AVAILABLE=false
 785         elif test "x$OPENJDK_TARGET_CPU" != "xx86_64" &&
 786              test "x$OPENJDK_TARGET_CPU" != "xaarch64" &&
 787              test "x$OPENJDK_TARGET_CPU" != "xppc64" &&
 788              test "x$OPENJDK_TARGET_CPU" != "xppc64le" &&
 789              test "x$OPENJDK_TARGET_CPU" != "xriscv64" &&
 790              test "x$OPENJDK_TARGET_CPU" != "xs390x"; then
 791           AC_MSG_RESULT([no (compact object headers not supported for this platform)])
 792           AVAILABLE=false
 793         else
 794           AC_MSG_RESULT([yes])
 795           AVAILABLE=true
 796         fi
 797       ])
 798   AC_SUBST(BUILD_CDS_ARCHIVE_COH)
 799 ])
 800 
 801 ################################################################################
 802 #
 803 # Enable the alternative CDS core region alignment
 804 #
 805 AC_DEFUN([JDKOPT_ENABLE_DISABLE_COMPATIBLE_CDS_ALIGNMENT],
 806 [
 807   UTIL_ARG_ENABLE(NAME: compatible-cds-alignment, DEFAULT: $COMPATIBLE_CDS_ALIGNMENT_DEFAULT,
 808       RESULT: ENABLE_COMPATIBLE_CDS_ALIGNMENT,
 809       DESC: [enable use alternative compatible cds core region alignment],
 810       DEFAULT_DESC: [disabled except on linux-aarch64],
 811       CHECKING_MSG: [if compatible cds region alignment enabled],
 812       CHECK_AVAILABLE: [
 813         AC_MSG_CHECKING([if CDS archive is available])
 814         if test "x$ENABLE_CDS" = "xfalse"; then
 815           AVAILABLE=false
 816           AC_MSG_RESULT([no (CDS is disabled)])
 817         else
 818           AVAILABLE=true
 819           AC_MSG_RESULT([yes])
 820         fi
 821       ])
 822   AC_SUBST(ENABLE_COMPATIBLE_CDS_ALIGNMENT)
 823 ])
 824 
 825 ################################################################################
 826 #
 827 # Disallow any output from containing absolute paths from the build system.
 828 # This setting defaults to allowed on debug builds and not allowed on release
 829 # builds.
 830 #
 831 AC_DEFUN([JDKOPT_ALLOW_ABSOLUTE_PATHS_IN_OUTPUT],
 832 [
 833   AC_ARG_ENABLE([absolute-paths-in-output],
 834       [AS_HELP_STRING([--disable-absolute-paths-in-output],
 835       [Set to disable to prevent any absolute paths from the build to end up in
 836       any of the build output. @<:@disabled in release builds, otherwise enabled@:>@])])
 837 
 838   AC_MSG_CHECKING([if absolute paths should be allowed in the build output])
 839   if test "x$enable_absolute_paths_in_output" = "xno"; then
 840     AC_MSG_RESULT([no, forced])
 841     ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="false"
 842   elif test "x$enable_absolute_paths_in_output" = "xyes"; then
 843     AC_MSG_RESULT([yes, forced])
 844     ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="true"
 845   elif test "x$DEBUG_LEVEL" = "xrelease"; then
 846     AC_MSG_RESULT([no, release build])
 847     ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="false"
 848   else
 849     AC_MSG_RESULT([yes, debug build])
 850     ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="true"
 851   fi
 852 
 853   AC_SUBST(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT)
 854 ])
 855 
 856 ################################################################################
 857 #
 858 # Check and set options related to reproducible builds.
 859 #
 860 AC_DEFUN_ONCE([JDKOPT_SETUP_REPRODUCIBLE_BUILD],
 861 [
 862   AC_ARG_WITH([source-date], [AS_HELP_STRING([--with-source-date],
 863       [how to set SOURCE_DATE_EPOCH ('updated', 'current', 'version' a timestamp or an ISO-8601 date) @<:@current/value of SOURCE_DATE_EPOCH@:>@])],
 864       [with_source_date_present=true], [with_source_date_present=false])
 865 
 866   if test "x$SOURCE_DATE_EPOCH" != x && test "x$with_source_date" != x; then
 867     AC_MSG_WARN([--with-source-date will override SOURCE_DATE_EPOCH])
 868   fi
 869 
 870   AC_MSG_CHECKING([what source date to use])
 871 
 872   if test "x$with_source_date" = xyes; then
 873     AC_MSG_ERROR([--with-source-date must have a value])
 874   elif test "x$with_source_date" = x; then
 875     if test "x$SOURCE_DATE_EPOCH" != x; then
 876       SOURCE_DATE=$SOURCE_DATE_EPOCH
 877       with_source_date_present=true
 878       AC_MSG_RESULT([$SOURCE_DATE, from SOURCE_DATE_EPOCH])
 879     else
 880       # Tell makefiles to take the time from configure
 881       SOURCE_DATE=$($DATE +"%s")
 882       AC_MSG_RESULT([$SOURCE_DATE, from 'current' (default)])
 883     fi
 884   elif test "x$with_source_date" = xupdated; then
 885     SOURCE_DATE=updated
 886     AC_MSG_RESULT([determined at build time, from 'updated'])
 887   elif test "x$with_source_date" = xcurrent; then
 888     # Set the current time
 889     SOURCE_DATE=$($DATE +"%s")
 890     AC_MSG_RESULT([$SOURCE_DATE, from 'current'])
 891   elif test "x$with_source_date" = xversion; then
 892     # Use the date from version-numbers.conf
 893     UTIL_GET_EPOCH_TIMESTAMP(SOURCE_DATE, $DEFAULT_VERSION_DATE)
 894     if test "x$SOURCE_DATE" = x; then
 895       AC_MSG_RESULT([unavailable])
 896       AC_MSG_ERROR([Cannot convert DEFAULT_VERSION_DATE to timestamp])
 897     fi
 898     AC_MSG_RESULT([$SOURCE_DATE, from 'version'])
 899   else
 900     # It's a timestamp, an ISO-8601 date, or an invalid string
 901     # Additional [] needed to keep m4 from mangling shell constructs.
 902     if [ [[ "$with_source_date" =~ ^[0-9][0-9]*$ ]] ] ; then
 903       SOURCE_DATE=$with_source_date
 904       AC_MSG_RESULT([$SOURCE_DATE, from timestamp on command line])
 905     else
 906       UTIL_GET_EPOCH_TIMESTAMP(SOURCE_DATE, $with_source_date)
 907       if test "x$SOURCE_DATE" != x; then
 908         AC_MSG_RESULT([$SOURCE_DATE, from ISO-8601 date on command line])
 909       else
 910         AC_MSG_RESULT([unavailable])
 911         AC_MSG_ERROR([Cannot parse date string "$with_source_date"])
 912       fi
 913     fi
 914   fi
 915 
 916   ISO_8601_FORMAT_STRING="%Y-%m-%dT%H:%M:%SZ"
 917   if test "x$SOURCE_DATE" != xupdated; then
 918     # If we have a fixed value for SOURCE_DATE, we need to set SOURCE_DATE_EPOCH
 919     # for the rest of configure.
 920     SOURCE_DATE_EPOCH="$SOURCE_DATE"
 921     if test "x$IS_GNU_DATE" = xyes; then
 922       SOURCE_DATE_ISO_8601=`$DATE --utc --date="@$SOURCE_DATE" +"$ISO_8601_FORMAT_STRING" 2> /dev/null`
 923     else
 924       SOURCE_DATE_ISO_8601=`$DATE -u -j -f "%s" "$SOURCE_DATE" +"$ISO_8601_FORMAT_STRING" 2> /dev/null`
 925     fi
 926   fi
 927 
 928   AC_SUBST(SOURCE_DATE)
 929   AC_SUBST(ISO_8601_FORMAT_STRING)
 930   AC_SUBST(SOURCE_DATE_ISO_8601)
 931 ])
 932 
 933 ################################################################################
 934 #
 935 # Setup signing on macOS. This can either be setup to sign with a real identity
 936 # and enabling the hardened runtime, or it can simply add the debug entitlement
 937 # com.apple.security.get-task-allow without actually signing any binaries. The
 938 # latter is needed to be able to debug processes and dump core files on modern
 939 # versions of macOS. It can also be skipped completely.
 940 #
 941 # Check if codesign will run with the given parameters
 942 # $1: Parameters to run with
 943 # $2: Checking message
 944 # Sets CODESIGN_SUCCESS=true/false
 945 AC_DEFUN([JDKOPT_CHECK_CODESIGN_PARAMS],
 946 [
 947   PARAMS="$1"
 948   MESSAGE="$2"
 949   CODESIGN_TESTFILE="$CONFIGURESUPPORT_OUTPUTDIR/codesign-testfile"
 950   $RM "$CODESIGN_TESTFILE"
 951   $TOUCH "$CODESIGN_TESTFILE"
 952   CODESIGN_SUCCESS=false
 953 
 954   $ECHO "check codesign, calling $CODESIGN $PARAMS $CODESIGN_TESTFILE" >&AS_MESSAGE_LOG_FD
 955 
 956   eval \"$CODESIGN\" $PARAMS \"$CODESIGN_TESTFILE\" 2>&AS_MESSAGE_LOG_FD \
 957       >&AS_MESSAGE_LOG_FD && CODESIGN_SUCCESS=true
 958   $RM "$CODESIGN_TESTFILE"
 959   AC_MSG_CHECKING([$MESSAGE])
 960   if test "x$CODESIGN_SUCCESS" = "xtrue"; then
 961     AC_MSG_RESULT([yes])
 962   else
 963     AC_MSG_RESULT([no])
 964   fi
 965 ])
 966 
 967 AC_DEFUN([JDKOPT_CHECK_CODESIGN_HARDENED],
 968 [
 969   JDKOPT_CHECK_CODESIGN_PARAMS([-s \"$MACOSX_CODESIGN_IDENTITY\" --option runtime],
 970       [if codesign with hardened runtime is possible])
 971 ])
 972 
 973 AC_DEFUN([JDKOPT_CHECK_CODESIGN_DEBUG],
 974 [
 975   JDKOPT_CHECK_CODESIGN_PARAMS([-s -], [if debug mode codesign is possible])
 976 ])
 977 
 978 AC_DEFUN([JDKOPT_SETUP_MACOSX_SIGNING],
 979 [
 980   MACOSX_CODESIGN_MODE=disabled
 981   if test "x$OPENJDK_TARGET_OS" = "xmacosx" && test "x$CODESIGN" != "x"; then
 982 
 983     UTIL_ARG_WITH(NAME: macosx-codesign, TYPE: literal, OPTIONAL: true,
 984         VALID_VALUES: [hardened debug auto], DEFAULT: auto,
 985         ENABLED_DEFAULT: true,
 986         CHECKING_MSG: [for macosx code signing mode],
 987         DESC: [set the macosx code signing mode (hardened, debug, auto)]
 988     )
 989 
 990     if test "x$MACOSX_CODESIGN_ENABLED" = "xtrue"; then
 991 
 992       # Check for user provided code signing identity.
 993       UTIL_ARG_WITH(NAME: macosx-codesign-identity, TYPE: string,
 994           DEFAULT: openjdk_codesign, CHECK_VALUE: [UTIL_CHECK_STRING_NON_EMPTY],
 995           DESC: [specify the macosx code signing identity],
 996           CHECKING_MSG: [for macosx code signing identity]
 997       )
 998       AC_SUBST(MACOSX_CODESIGN_IDENTITY)
 999 
1000       if test "x$MACOSX_CODESIGN" = "xauto"; then
1001         # Only try to default to hardened signing on release builds
1002         if test "x$DEBUG_LEVEL" = "xrelease"; then
1003           JDKOPT_CHECK_CODESIGN_HARDENED
1004           if test "x$CODESIGN_SUCCESS" = "xtrue"; then
1005             MACOSX_CODESIGN_MODE=hardened
1006           fi
1007         fi
1008         if test "x$MACOSX_CODESIGN_MODE" = "xdisabled"; then
1009           JDKOPT_CHECK_CODESIGN_DEBUG
1010           if test "x$CODESIGN_SUCCESS" = "xtrue"; then
1011             MACOSX_CODESIGN_MODE=debug
1012           fi
1013         fi
1014         AC_MSG_CHECKING([for macosx code signing mode])
1015         AC_MSG_RESULT([$MACOSX_CODESIGN_MODE])
1016       elif test "x$MACOSX_CODESIGN" = "xhardened"; then
1017         JDKOPT_CHECK_CODESIGN_HARDENED
1018         if test "x$CODESIGN_SUCCESS" = "xfalse"; then
1019           AC_MSG_ERROR([Signing with hardened runtime is not possible])
1020         fi
1021         MACOSX_CODESIGN_MODE=hardened
1022       elif test "x$MACOSX_CODESIGN" = "xdebug"; then
1023         JDKOPT_CHECK_CODESIGN_DEBUG
1024         if test "x$CODESIGN_SUCCESS" = "xfalse"; then
1025           AC_MSG_ERROR([Signing in debug mode is not possible])
1026         fi
1027         MACOSX_CODESIGN_MODE=debug
1028       else
1029         AC_MSG_ERROR([unknown value for --with-macosx-codesign: $MACOSX_CODESIGN])
1030       fi
1031     fi
1032   fi
1033   AC_SUBST(MACOSX_CODESIGN_IDENTITY)
1034   AC_SUBST(MACOSX_CODESIGN_MODE)
1035 ])
1036 
1037 ################################################################################
1038 #
1039 # Setup a hook to invoke a script that runs for file produced by the native
1040 # compilation steps, after linking.
1041 # Parameter is the path to the script to be called.
1042 #
1043 AC_DEFUN([JDKOPT_SETUP_SIGNING_HOOK],
1044 [
1045   UTIL_ARG_WITH(NAME: signing-hook, TYPE: executable,
1046       OPTIONAL: true, DEFAULT: "",
1047       DESC: [specify path to script used to code sign native binaries]
1048   )
1049 
1050   AC_MSG_CHECKING([for signing hook])
1051   if test "x$SIGNING_HOOK" != x; then
1052     UTIL_FIXUP_EXECUTABLE(SIGNING_HOOK)
1053     AC_MSG_RESULT([$SIGNING_HOOK])
1054   else
1055     AC_MSG_RESULT([none])
1056   fi
1057   AC_SUBST(SIGNING_HOOK)
1058 ])
1059 
1060 ################################################################################
1061 #
1062 # Setup how javac should handle warnings.
1063 #
1064 AC_DEFUN([JDKOPT_SETUP_JAVA_WARNINGS],
1065 [
1066   UTIL_ARG_ENABLE(NAME: java-warnings-as-errors, DEFAULT: true,
1067       RESULT: JAVA_WARNINGS_AS_ERRORS,
1068       DESC: [consider java warnings to be an error])
1069   AC_SUBST(JAVA_WARNINGS_AS_ERRORS)
1070 ])
1071 
1072 ################################################################################
1073 #
1074 # fallback linker
1075 #
1076 AC_DEFUN_ONCE([JDKOPT_SETUP_FALLBACK_LINKER],
1077 [
1078   FALLBACK_LINKER_DEFAULT=false
1079 
1080   if HOTSPOT_CHECK_JVM_VARIANT(zero); then
1081     FALLBACK_LINKER_DEFAULT=true
1082   fi
1083 
1084   UTIL_ARG_ENABLE(NAME: fallback-linker, DEFAULT: $FALLBACK_LINKER_DEFAULT,
1085       RESULT: ENABLE_FALLBACK_LINKER,
1086       DESC: [enable libffi-based fallback implementation of java.lang.foreign.Linker],
1087       CHECKING_MSG: [if fallback linker enabled])
1088   AC_SUBST(ENABLE_FALLBACK_LINKER)
1089 ])