8296115: Allow for compiling the JDK with strict standards conformance

8241499: Enable new "permissive-" for standard C++ compliance on Visual Studio if possible

Reviewed-by: erikj, ihse
This commit is contained in:
Julian Waters 2022-11-02 17:03:19 +00:00 committed by Erik Joelsson
parent 491d43c187
commit a124d8e047
4 changed files with 41 additions and 2 deletions

View File

@ -45,6 +45,7 @@
<li><a href="#apple-xcode">Apple Xcode</a></li>
<li><a href="#microsoft-visual-studio">Microsoft Visual Studio</a></li>
<li><a href="#ibm-xl-cc">IBM XL C/C++</a></li>
<li><a href="#support-for-checking-standards-conforming-code">Support for checking standards conforming code</a></li>
</ul></li>
<li><a href="#boot-jdk-requirements">Boot JDK Requirements</a><ul>
<li><a href="#getting-jdk-binaries">Getting JDK binaries</a></li>
@ -239,7 +240,7 @@
<h3 id="aix">AIX</h3>
<p>Please consult the AIX section of the <a href="https://wiki.openjdk.org/display/Build/Supported+Build+Platforms">Supported Build Platforms</a> OpenJDK Build Wiki page for details about which versions of AIX are supported.</p>
<h2 id="native-compiler-toolchain-requirements">Native Compiler (Toolchain) Requirements</h2>
<p>Large portions of the JDK consists of native code, that needs to be compiled to be able to run on the target platform. In theory, toolchain and operating system should be independent factors, but in practice there's more or less a one-to-one correlation between target operating system and toolchain.</p>
<p>Large portions of the JDK consists of native code, that needs to be compiled to be able to run on the target platform. In theory, toolchain and operating system should be independent factors, but in practice there's more or less a one-to-one correlation between target operating system and toolchain. There are ongoing efforts to loosen this strict coupling between compiler and operating system (see <a href="https://bugs.openjdk.org/browse/JDK-8288293">JDK-8288293</a>) but it will likely be a very long time before this goal can be realized.</p>
<table>
<thead>
<tr class="header">
@ -309,6 +310,8 @@
<p>If you have Visual Studio installed but <code>configure</code> fails to detect it, it may be because of <a href="#spaces-in-path">spaces in path</a>.</p>
<h3 id="ibm-xl-cc">IBM XL C/C++</h3>
<p>Please consult the AIX section of the <a href="https://wiki.openjdk.org/display/Build/Supported+Build+Platforms">Supported Build Platforms</a> OpenJDK Build Wiki page for details about which versions of XLC are supported.</p>
<h3 id="support-for-checking-standards-conforming-code">Support for checking standards conforming code</h3>
<p>The make system has a strict mode that enforces conforming code based on the standard that is used by the build, which can be useful to ensure that native code behaves strictly according to said standard. This option can by enabled by passing <code>--enable-conforming-compilation</code> during configure, but is off by default. If you just want to compile a working JDK it is not recommended that you set this flag, as it is mainly meant to aid developers that are working with native code.</p>
<h2 id="boot-jdk-requirements">Boot JDK Requirements</h2>
<p>Paradoxically, building the JDK requires a pre-existing JDK. This is called the &quot;boot JDK&quot;. The boot JDK does not, however, have to be a JDK built directly from the source code available in the OpenJDK Community. If you are porting the JDK to a new platform, chances are that there already exists another JDK for that platform that is usable as boot JDK.</p>
<p>The rule of thumb is that the boot JDK for building JDK major version <em>N</em> should be a JDK of major version <em>N-1</em>, so for building JDK 9 a JDK 8 would be suitable as boot JDK. However, the JDK should be able to &quot;build itself&quot;, so an up-to-date build of the current JDK source is an acceptable alternative. If you are following the <em>N-1</em> rule, make sure you've got the latest update version, since JDK 8 GA might not be able to build JDK 9 on all platforms.</p>

View File

@ -311,7 +311,10 @@ Build Wiki page for details about which versions of AIX are supported.
Large portions of the JDK consists of native code, that needs to be compiled to
be able to run on the target platform. In theory, toolchain and operating
system should be independent factors, but in practice there's more or less a
one-to-one correlation between target operating system and toolchain.
one-to-one correlation between target operating system and toolchain. There are
ongoing efforts to loosen this strict coupling between compiler and operating
system (see [JDK-8288293](https://bugs.openjdk.org/browse/JDK-8288293)) but it
will likely be a very long time before this goal can be realized.
Operating system Supported toolchain
------------------ -------------------------
@ -400,6 +403,15 @@ Please consult the AIX section of the [Supported Build Platforms](
https://wiki.openjdk.org/display/Build/Supported+Build+Platforms) OpenJDK
Build Wiki page for details about which versions of XLC are supported.
### Support for checking standards conforming code
The make system has a strict mode that enforces conforming code based on the
standard that is used by the build, which can be useful to ensure that native code
behaves strictly according to said standard. This option can by enabled by passing
`--enable-conforming-compilation` during configure, but is off by default.
If you just want to compile a working JDK it is not recommended that you set this
flag, as it is mainly meant to aid developers that are working with native code.
## Boot JDK Requirements

View File

@ -500,6 +500,13 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
# no-strict-aliasing everywhere!)
TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing"
if test "x$ENABLE_CONFORMING_COMPILATION" = xtrue; then
# -Werror=pedantic is not equivalent to -pedantic-errors on gcc, if code that
# conforms is desired both have to be set
TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -pedantic-errors -Werror=pedantic"
TOOLCHAIN_CFLAGS_JDK="$TOOLCHAIN_CFLAGS_JDK -pedantic-errors -Werror=pedantic"
fi
elif test "x$TOOLCHAIN_TYPE" = xclang; then
# Restrict the debug information created by Clang to avoid
# too big object files and speed the build up a little bit
@ -523,6 +530,11 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing" # technically NOT for CXX
fi
if test "x$ENABLE_CONFORMING_COMPILATION" = xtrue; then
TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -pedantic-errors"
TOOLCHAIN_CFLAGS_JDK="$TOOLCHAIN_CFLAGS_JDK -pedantic-errors"
fi
elif test "x$TOOLCHAIN_TYPE" = xxlc; then
# Suggested additions: -qsrcmsg to get improved error reporting
# set -qtbtable=full for a better traceback table/better stacks in hs_err when xlc16 is used
@ -532,6 +544,10 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
TOOLCHAIN_CFLAGS_JVM="-nologo -MD -Zc:preprocessor -Zc:strictStrings -MP"
TOOLCHAIN_CFLAGS_JDK="-nologo -MD -Zc:preprocessor -Zc:strictStrings -Zc:wchar_t-"
if test "x$ENABLE_CONFORMING_COMPILATION" = xtrue; then
TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -permissive-"
TOOLCHAIN_CFLAGS_JDK="$TOOLCHAIN_CFLAGS_JDK -permissive-"
fi
fi
# CFLAGS C language level for JDK sources (hotspot only uses C++)

View File

@ -102,6 +102,14 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_JDK_OPTIONS],
CHECKING_MSG: [if we should build headless-only (no GUI)])
AC_SUBST(ENABLE_HEADLESS_ONLY)
# Should the compiler only accept code that strictly conforms to the standard used by
# the build?
UTIL_ARG_ENABLE(NAME: conforming-compilation, DEFAULT: false,
RESULT: ENABLE_CONFORMING_COMPILATION,
DESC: [enforce conforming code during compilation],
CHECKING_MSG: [if compiler should enforce conforming code (conforming-compilation)])
AC_SUBST(ENABLE_CONFORMING_COMPILATION)
# should we linktime gc unused code sections in the JDK build ?
if test "x$OPENJDK_TARGET_OS" = "xlinux" && test "x$OPENJDK_TARGET_CPU" = xs390x; then
LINKTIME_GC_DEFAULT=true