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

Andrew John Hughes andrew at openjdk.org
Fri Jan 9 23:06:11 UTC 2026


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 removal flags, allowed the clang build to complete. I compared the flags in the logs with a previous build from the 8u repository and all desired flags are preserved as before.

Builders may need to adjust their compilation flags if they are relying on `--with-extra-cxxflags` passing flags to the C code part of the HotSpot build instead of `--with-extra-cflags`. This is likely worth a release note.

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

Commit messages:
 - 8374917: [8u] C++ flags get passed to C compiles in the HotSpot build

Changes: https://git.openjdk.org/jdk8u-dev/pull/741/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk8u-dev&pr=741&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8374917
  Stats: 33 lines in 14 files changed: 4 ins; 4 del; 25 mod
  Patch: https://git.openjdk.org/jdk8u-dev/pull/741.diff
  Fetch: git fetch https://git.openjdk.org/jdk8u-dev.git pull/741/head:pull/741

PR: https://git.openjdk.org/jdk8u-dev/pull/741


More information about the jdk8u-dev mailing list