From e7e9318a9efa5ba9660abae8aab4372c9c91e351 Mon Sep 17 00:00:00 2001 From: Zdenek Zambersky Date: Tue, 2 Sep 2025 15:18:15 +0200 Subject: [PATCH] backport 03428d73fc3618202627bbe9d9880a63221c1811 --- doc/building.html | 4 ++++ doc/building.md | 5 +++++ make/autoconf/flags-cflags.m4 | 26 +++++++++++++++++++++++++- make/lib/Awt2dLibraries.gmk | 1 - 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/doc/building.html b/doc/building.html index 13ee9b7b6fc..6433786904f 100644 --- a/doc/building.html +++ b/doc/building.html @@ -296,6 +296,10 @@

Native Compiler (Toolchain) Requ +

All compilers are expected to be able to compile to the C99 language standard, +as some C99 features are used in the source code. Microsoft Visual Studio +doesn't fully support C99 so in practice shared code is limited to using C99 +features that it does support.

gcc

The minimum accepted version of gcc is 4.8. Older versions will generate a warning by configure and are unlikely to work.

The JDK is currently known to be able to compile with at least version 7.4 of gcc.

diff --git a/doc/building.md b/doc/building.md index 648be30b4af..d7eb913995f 100644 --- a/doc/building.md +++ b/doc/building.md @@ -313,6 +313,11 @@ issues. | Solaris | Oracle Solaris Studio 12.4 (with compiler version 5.13) | | Windows | Microsoft Visual Studio 2017 update 15.9.16 | +All compilers are expected to be able to compile to the C99 language standard, +as some C99 features are used in the source code. Microsoft Visual Studio +doesn't fully support C99 so in practice shared code is limited to using C99 +features that it does support. + ### gcc The minimum accepted version of gcc is 4.8. Older versions will generate a warning diff --git a/make/autoconf/flags-cflags.m4 b/make/autoconf/flags-cflags.m4 index 8ead0e22d64..cb86f3acf09 100644 --- a/make/autoconf/flags-cflags.m4 +++ b/make/autoconf/flags-cflags.m4 @@ -563,7 +563,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER], TOOLCHAIN_CFLAGS="-errshort=tags" TOOLCHAIN_CFLAGS_JDK="-mt $TOOLCHAIN_FLAGS" - TOOLCHAIN_CFLAGS_JDK_CONLY="-xCC -Xa -W0,-noglobal $TOOLCHAIN_CFLAGS" # C only + TOOLCHAIN_CFLAGS_JDK_CONLY="-W0,-noglobal $TOOLCHAIN_CFLAGS" # C only TOOLCHAIN_CFLAGS_JDK_CXXONLY="-features=no%except -norunpath -xnolib" # CXX only TOOLCHAIN_CFLAGS_JVM="-template=no%extdef -features=no%split_init \ -library=stlport4 -mt -features=no%except $TOOLCHAIN_FLAGS" @@ -584,6 +584,30 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER], TOOLCHAIN_CFLAGS_JDK="-nologo -MD -Zc:wchar_t-" fi + # CFLAGS C language level for JDK sources (hotspot only uses C++) + # Ideally we would have a common level across all toolchains so that all sources + # are sure to conform to the same standard. Unfortunately neither our sources nor + # our toolchains are in a condition to support that. But what we loosely aim for is + # C99 level. + if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang || test "x$TOOLCHAIN_TYPE" = xxlc; then + # This raises the language level for older 4.8 gcc, while lowering it for later + # versions. clang and xlclang support the same flag. + LANGSTD_CFLAGS="-std=c99" + elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then + # We can't turn on -std=c99 without breaking compilation of the splashscreen/png + # utilities. But we can enable c99 as below (previously achieved by using -Xa). + # It is the no_lib that makes the difference. + LANGSTD_CFLAGS="-xc99=all,no_lib" + elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then + # MSVC doesn't support C99/C11 explicitly, unless you compile as C++: + # LANGSTD_CFLAGS="/TP" + # but that requires numerous changes to the sources files. So we are limited + # to C89/C90 plus whatever extensions Visual Studio has decided to implement. + # This is the lowest bar for shared code. + LANGSTD_CFLAGS="" + fi + TOOLCHAIN_CFLAGS_JDK_CONLY="$LANGSTD_CFLAGS $TOOLCHAIN_CFLAGS_JDK_CONLY" + # CFLAGS WARNINGS STUFF # Set JVM_CFLAGS warning handling if test "x$TOOLCHAIN_TYPE" = xgcc; then diff --git a/make/lib/Awt2dLibraries.gmk b/make/lib/Awt2dLibraries.gmk index 7eaf5119a0f..4ab8c9a6e11 100644 --- a/make/lib/Awt2dLibraries.gmk +++ b/make/lib/Awt2dLibraries.gmk @@ -382,7 +382,6 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBLCMS, \ OPTIMIZATION := HIGHEST, \ CFLAGS := $(CFLAGS_JDKLIB) \ $(LCMS_CFLAGS), \ - CFLAGS_solaris := -xc99=no_lib, \ CFLAGS_windows := -DCMS_IS_WINDOWS_, \ EXTRA_HEADER_DIRS := \ common/awt/debug \