RFR: 8352284: EXTRA_CFLAGS incorrectly applied to BUILD_LIBJVM src/hotspot C++ source files

Erik Joelsson erikj at openjdk.org
Thu Mar 20 17:04:09 UTC 2025


On Thu, 20 Mar 2025 04:55:32 GMT, Patrick Zhang <qpzhang at openjdk.org> wrote:

> > Wouldn't just the change in JvmFlags.gmk be enough to solve your issue?
> 
> Forgot to mention, one of my initial try-outs (hacking) was: Remove `$(EXTRA_CFLAGS)` from `JVM_CFLAGS`, based on an assumption that all source files under `$(TOPDIR)/src/hotspot` are (according to `hotspot/variant-server/libjvm/objs/BUILD_LIBJVM.d`) and will be C++ files only which has `$(EXTRA_CXXFLAGS)` and does **not** need `$(EXTRA_CFLAGS)` . This practically solved the issue I observed, however I don't think it was an elegant solution. Is this more acceptable than adding parameters to `SetupNativeCompilation` (actually the call to `SetupJdkLibrary`)?

I can see what you mean. The current state of the build system is that we aren't consistent with the use of CFLAGS vs CXXFLAGS. For libraries that are C++ or use a mix of C and C++, SetupNativeLibrary will accept flags in two ways, either as just CFLAGS, which will then apply to both C and C++, or as separate CFLAGS and CXXFLAGS, which will then be treated separately. To properly solve your issue, we would need to stop this automatic fallback and be explicit with CFLAGS vs CXXFLAGS throughout the build system. That would certainly be cleaner.

Hotspot is currently only C++ and there is little reason to believe that would ever change. The build setup for hotspot is currently only setting CFLAGS, which will then get applied to CXXFLAGS as well. Given that we are currently going with that choice, I think the correct fix is indeed to just remove `EXTRA_CFLAGS` from `JVM_CFLAGS`. If we were to ever add C source files to hotspot, then we would need to start handling JVM_CFLAGS and JVM_CXXFLAGS separately, not just for the EXTRA flags, but for all of them.

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

PR Comment: https://git.openjdk.org/jdk/pull/24115#issuecomment-2741117905


More information about the build-dev mailing list