Skip to content

Commit 03428d7

Browse files
author
David Holmes
committed
8224087: Compile C code for at least C99 Standard compliance
Reviewed-by: simonis, aph, erikj, serb, stuefe
1 parent 2531942 commit 03428d7

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
@@ -297,6 +297,10 @@ <h2 id="native-compiler-toolchain-requirements">Native Compiler (Toolchain) Requ
297297
</tr>
298298
</tbody>
299299
</table>
300+
<p>All compilers are expected to be able to compile to the C99 language standard,
301+
as some C99 features are used in the source code. Microsoft Visual Studio
302+
doesn't fully support C99 so in practice shared code is limited to using C99
303+
features that it does support.</p>
300304
<h3 id="gcc">gcc</h3>
301305
<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>
302306
<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
@@ -328,6 +328,11 @@ issues.
328328
Solaris Oracle Solaris Studio 12.6 (with compiler version 5.15)
329329
Windows Microsoft Visual Studio 2017 update 15.9.6
330330

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

333338
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
@@ -564,7 +564,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
564564
TOOLCHAIN_CFLAGS="-errshort=tags"
565565
566566
TOOLCHAIN_CFLAGS_JDK="-mt $TOOLCHAIN_FLAGS"
567-
TOOLCHAIN_CFLAGS_JDK_CONLY="-xCC -Xa -W0,-noglobal $TOOLCHAIN_CFLAGS" # C only
567+
TOOLCHAIN_CFLAGS_JDK_CONLY="-W0,-noglobal $TOOLCHAIN_CFLAGS" # C only
568568
TOOLCHAIN_CFLAGS_JDK_CXXONLY="-features=no%except -norunpath -xnolib" # CXX only
569569
TOOLCHAIN_CFLAGS_JVM="-template=no%extdef -features=no%split_init \
570570
-library=stlport4 -mt -features=no%except $TOOLCHAIN_FLAGS"
@@ -585,6 +585,30 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
585585
TOOLCHAIN_CFLAGS_JDK="-nologo -MD -Zc:wchar_t-"
586586
fi
587587
588+
# CFLAGS C language level for JDK sources (hotspot only uses C++)
589+
# Ideally we would have a common level across all toolchains so that all sources
590+
# are sure to conform to the same standard. Unfortunately neither our sources nor
591+
# our toolchains are in a condition to support that. But what we loosely aim for is
592+
# C99 level.
593+
if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang || test "x$TOOLCHAIN_TYPE" = xxlc; then
594+
# This raises the language level for older 4.8 gcc, while lowering it for later
595+
# versions. clang and xlclang support the same flag.
596+
LANGSTD_CFLAGS="-std=c99"
597+
elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
598+
# We can't turn on -std=c99 without breaking compilation of the splashscreen/png
599+
# utilities. But we can enable c99 as below (previously achieved by using -Xa).
600+
# It is the no_lib that makes the difference.
601+
LANGSTD_CFLAGS="-xc99=all,no_lib"
602+
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
603+
# MSVC doesn't support C99/C11 explicitly, unless you compile as C++:
604+
# LANGSTD_CFLAGS="/TP"
605+
# but that requires numerous changes to the sources files. So we are limited
606+
# to C89/C90 plus whatever extensions Visual Studio has decided to implement.
607+
# This is the lowest bar for shared code.
608+
LANGSTD_CFLAGS=""
609+
fi
610+
TOOLCHAIN_CFLAGS_JDK_CONLY="$LANGSTD_CFLAGS $TOOLCHAIN_CFLAGS_JDK_CONLY"
611+
588612
# CFLAGS WARNINGS STUFF
589613
# Set JVM_CFLAGS warning handling
590614
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
@@ -378,7 +378,6 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBLCMS, \
378378
OPTIMIZATION := HIGHEST, \
379379
CFLAGS := $(CFLAGS_JDKLIB) \
380380
$(LCMS_CFLAGS), \
381-
CFLAGS_solaris := -xc99=no_lib, \
382381
CFLAGS_windows := -DCMS_IS_WINDOWS_, \
383382
EXTRA_HEADER_DIRS := \
384383
common/awt/debug \

0 commit comments

Comments
 (0)