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