[jdk8u-dev] RFR: 8374917: [8u] C++ flags get passed to C compiles in the HotSpot build

Andrew John Hughes andrew at openjdk.org
Mon Jan 12 16:20:55 UTC 2026


On Fri, 9 Jan 2026 22:46:39 GMT, Andrew John Hughes <andrew at openjdk.org> wrote:

> In gcc, this has been throwing a warning for a long time:
> ~~~
> cc1: warning: command line option '-std=gnu++98' is valid for C++/ObjC++ but not for C
> ~~~
> 
> With clang builds, this is instead an error.
> 
> ~~~
> 2026-01-09T18:17:34.1713580Z error: invalid argument '-std=gnu++98' not allowed with 'C'
> ~~~
> 
> This escalates the problem for newer MacOS builds which need the `-std` flag for the C++ code to compile.  It also causes Linux+clang builds to fail.
> 
> This fix does the minimum to get C++ flags out of the C code builds (the serviceability agent & jsig):
> 
> * `NO_DELETE_NULL_POINTER_CHECKS_CFLAG`, `NO_LIFETIME_DSE_CFLAG` and `CXXSTD_CXXFLAG`
> are moved from `EXTRA_CFLAGS` to `EXTRA_CXXFLAGS`. The last of these is essential to fix the problem described above. The others should be safe for the little C code in the HotSpot build; `fno-lifetime-dse` is a C++ flag anyway and the null pointer checks in question are comparisons of `this` with `NULL` from what I can see (again C++ only). Both have been removed in 21u and later, with the required fixes being in the C1 & ADLC code (see [JDK-8316893](https://bugs.openjdk.org/browse/JDK-8316893) and [JDK-8245051](https://bugs.openjdk.org/browse/JDK-8245051))
> * The same for `HOST_CFLAGS` and `HOST_CXXFLAGS` used by the ADLC build.
> * `CFLAGS` and `LFLAGS` in `hotspot/make/<platform>/makefiles/adlc.make`are switched to use `HOST_CXXFLAGS` as this compiles C++ code
> * `CFLAGS` and `LFLAGS` in `hotspot/make/<platform>/makefiles/vm.make`are switched to use `EXTRA_CXXFLAGS` as this compiles C++ code
> * `CXXFLAGS` are removed from `CC_COMPILE` in `hotspot/make/<platform>/makefiles/rules.make`. We leave `CXX_COMPILE` untouched to reduce risk.
>  
> `CXXFLAGS` is rarely used (though most of the code is C++) while `CFLAGS` is used for most flags.  `EXTRA_CXXFLAGS` and `HOST_CXXFLAGS` were unused prior to this change. So the risk of changing these is low, while we leave `CFLAGS` untouched.
> 
> We also move `NO_DELETE_NULL_POINTER_CHECKS_CFLAG`, `NO_LIFETIME_DSE_CFLAG` and `CXXSTD_CXXFLAG` to `hotspot-spec.gmk.in` from `spec.gmk.in`. They are now no longer used by the JDK build (which instead adds them to `CCXXFLAGS_JDK` as can be seen in https://github.com/openjdk/jdk8u-dev/pull/740) and this makes it easier to check the values and their usage in a single generated file.
> 
> I've built this locally on GNU/Linux with both gcc (8.5.0) and clang (20.1.8). This fix, along with https://github.com/openjdk/jdk8u-dev/pull/740 and a few additional warning remova...

Thanks Severin.

-------------

PR Comment: https://git.openjdk.org/jdk8u-dev/pull/741#issuecomment-3739381944


More information about the jdk8u-dev mailing list