Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8352284

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • infrastructure
    • None
    • generic
    • linux

      Building jdk with --with-extra-cflags='-Wno-incompatible-pointer-types' triggers 1000+ warning messages like "cc1plus: warning: command-line option ‘-Wno-incompatible-pointer-types’ is valid for C/ObjC but not for C++". This option is for C and Objective-C only but gets incorrectly applied to src/hotspot CPP files.

      Some Makefile configs use CFLAGS for CPP files intentionally if not specified CXXFLAGS, so another experiment is to set both extra flags like below:
      --with-extra-cflags='-Wno-incompatible-pointer-types'
      --with-extra-cxxflags='-Wno-narrowing'
      It shows same problematic warnings.

      The root cause could be:
      1) JVM_CFLAGS contains EXTRA_CXXFLAGS in make/autoconf/flags-cflags.m4
          > $2JVM_CFLAGS="$CFLAGS_JVM_COMMON ${$1_CFLAGS_JVM} ${$2EXTRA_CXXFLAGS}"

      2) Appended EXTRA_CFLAGS in make/hotspot/lib/JvmFlags.gmk
          > JVM_CFLAGS += \
          > $(JVM_CFLAGS_DEBUGLEVEL) \
          > $(JVM_CFLAGS_TARGET_DEFINES) \
          > $(JVM_CFLAGS_FEATURES) \
          > $(JVM_CFLAGS_INCLUDES) \
          > $(EXTRA_CFLAGS) \
          > #

      3) Passed JVM_CFLAGS as CFLAGS to call SetupJdkLibrary in make/hotspot/lib/CompileJvm.gmk
          > CFLAGS := $(JVM_CFLAGS), \

      4) Set to CXXFLAGS in make/common/native/Flags.gmk
          > ifeq ($$($1_CXXFLAGS), )
          > $1_CXXFLAGS := $$($1_CFLAGS)
          > endif

      5) CXXFLAGS used to compile CPP files in make/common/native/CompileFile.gmk. At this point it contains both EXTRA_CXXFLAGS and EXTRA_CFLAGS
          > else ifneq ($$(filter %.cpp %.cc %.mm, $$($1_FILENAME)), )
          > # Compile as a C++ or Objective-C++ file
          > $1_CXXFLAGS += $$($1_WARNINGS_FLAGS)
          > $1_FLAGS := $(CFLAGS_CCACHE) $$($1_USE_PCH_FLAGS) $$($1_BASE_CXXFLAGS) \
          > $$($1_OPT_CXXFLAGS) $$($1_CXXFLAGS) -c
          > $1_COMPILER := $$($$($1_BASE)_CXX)
          > else

      A possible fix can be:
      Not to append EXTRA_CFLAGS or EXTRA_CXXFLAGS into JVM_CFLAGS before calling SetupJdkLibrary, instead let SetupCompilerFlags accept and merge EXTRA_CFLAGS and EXTRA_CXXFLAGS passed from SetupJdkLibrary as parameters, so CPP compilation will only have EXTRA_CXXFLAGS as expected.

            Unassigned Unassigned
            qpzhang Patrick Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: