Skip to content

Commit 156d998

Browse files
zzambersjerboaa
authored andcommitted
8224087: Compile C code for at least C99 Standard compliance
Reviewed-by: andrew Backport-of: 03428d7
1 parent 26a8aca commit 156d998

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

doc/building.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ <h2 id="native-compiler-toolchain-requirements">Native Compiler (Toolchain) Requ
296296
</tr>
297297
</tbody>
298298
</table>
299+
<p>All compilers are expected to be able to compile to the C99 language standard,
300+
as some C99 features are used in the source code. Microsoft Visual Studio
301+
doesn't fully support C99 so in practice shared code is limited to using C99
302+
features that it does support.</p>
299303
<h3 id="gcc">gcc</h3>
300304
<p>The minimum accepted version of gcc is 4.8. Older versions will generate a warning by <code>configure</code> and are unlikely to work.</p>
301305
<p>The JDK is currently known to be able to compile with at least version 7.4 of gcc.</p>

doc/building.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ issues.
313313
| Solaris | Oracle Solaris Studio 12.4 (with compiler version 5.13) |
314314
| Windows | Microsoft Visual Studio 2017 update 15.9.16 |
315315

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

318323
The minimum accepted version of gcc is 4.8. Older versions will generate a warning

make/autoconf/flags-cflags.m4

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
563563
TOOLCHAIN_CFLAGS="-errshort=tags"
564564
565565
TOOLCHAIN_CFLAGS_JDK="-mt $TOOLCHAIN_FLAGS"
566-
TOOLCHAIN_CFLAGS_JDK_CONLY="-xCC -Xa -W0,-noglobal $TOOLCHAIN_CFLAGS" # C only
566+
TOOLCHAIN_CFLAGS_JDK_CONLY="-W0,-noglobal $TOOLCHAIN_CFLAGS" # C only
567567
TOOLCHAIN_CFLAGS_JDK_CXXONLY="-features=no%except -norunpath -xnolib" # CXX only
568568
TOOLCHAIN_CFLAGS_JVM="-template=no%extdef -features=no%split_init \
569569
-library=stlport4 -mt -features=no%except $TOOLCHAIN_FLAGS"
@@ -584,6 +584,30 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
584584
TOOLCHAIN_CFLAGS_JDK="-nologo -MD -Zc:wchar_t-"
585585
fi
586586
587+
# CFLAGS C language level for JDK sources (hotspot only uses C++)
588+
# Ideally we would have a common level across all toolchains so that all sources
589+
# are sure to conform to the same standard. Unfortunately neither our sources nor
590+
# our toolchains are in a condition to support that. But what we loosely aim for is
591+
# C99 level.
592+
if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang || test "x$TOOLCHAIN_TYPE" = xxlc; then
593+
# This raises the language level for older 4.8 gcc, while lowering it for later
594+
# versions. clang and xlclang support the same flag.
595+
LANGSTD_CFLAGS="-std=c99"
596+
elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
597+
# We can't turn on -std=c99 without breaking compilation of the splashscreen/png
598+
# utilities. But we can enable c99 as below (previously achieved by using -Xa).
599+
# It is the no_lib that makes the difference.
600+
LANGSTD_CFLAGS="-xc99=all,no_lib"
601+
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
602+
# MSVC doesn't support C99/C11 explicitly, unless you compile as C++:
603+
# LANGSTD_CFLAGS="/TP"
604+
# but that requires numerous changes to the sources files. So we are limited
605+
# to C89/C90 plus whatever extensions Visual Studio has decided to implement.
606+
# This is the lowest bar for shared code.
607+
LANGSTD_CFLAGS=""
608+
fi
609+
TOOLCHAIN_CFLAGS_JDK_CONLY="$LANGSTD_CFLAGS $TOOLCHAIN_CFLAGS_JDK_CONLY"
610+
587611
# CFLAGS WARNINGS STUFF
588612
# Set JVM_CFLAGS warning handling
589613
if test "x$TOOLCHAIN_TYPE" = xgcc; then

make/lib/Awt2dLibraries.gmk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBLCMS, \
382382
OPTIMIZATION := HIGHEST, \
383383
CFLAGS := $(CFLAGS_JDKLIB) \
384384
$(LCMS_CFLAGS), \
385-
CFLAGS_solaris := -xc99=no_lib, \
386385
CFLAGS_windows := -DCMS_IS_WINDOWS_, \
387386
EXTRA_HEADER_DIRS := \
388387
common/awt/debug \

0 commit comments

Comments
 (0)