8196803: Fix build warnings in jdk libraries with Xcode 9
authorerikj
Tue, 06 Feb 2018 10:12:05 -0800
changeset 48751 54f355e65415
parent 48750 ffbb784a8873
child 48752 0b1138ce244f
8196803: Fix build warnings in jdk libraries with Xcode 9 Reviewed-by: tbell, ihse
make/autoconf/flags.m4
make/autoconf/lib-bundled.m4
make/autoconf/spec.gmk.in
make/lib/Awt2dLibraries.gmk
make/lib/CoreLibraries.gmk
make/lib/Lib-java.instrument.gmk
make/lib/LibCommon.gmk
src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m
--- a/make/autoconf/flags.m4	Tue Feb 06 16:04:46 2018 +0000
+++ b/make/autoconf/flags.m4	Tue Feb 06 10:12:05 2018 -0800
@@ -1113,10 +1113,11 @@
 
   # Additional macosx handling
   if test "x$OPENJDK_$1_OS" = xmacosx; then
-    # MACOSX_VERSION_MIN is the c++ and ld is -mmacosx-version-min argument. The expected
-    # format is X.Y.Z. It's hard-coded to the minimum OSX version on which the
-    # JDK can be built and makes the linked binaries compatible even if built on
-    # a newer version of the OS.
+    # MACOSX_VERSION_MIN specifies the lowest version of Macosx that the built
+    # binaries should be compatible with, even if compiled on a newer version
+    # of the OS. It currently has a hard coded value. Setting this also limits
+    # exposure to API changes in header files. Bumping this is likely to
+    # require code changes to build.
     MACOSX_VERSION_MIN=10.7.0
     AC_SUBST(MACOSX_VERSION_MIN)
 
@@ -1150,6 +1151,7 @@
     $2JVM_CFLAGS="[$]$2JVM_CFLAGS \
         -DMAC_OS_X_VERSION_MIN_REQUIRED=\$(subst .,,\$(MACOSX_VERSION_MIN)) \
         -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
+    $2ARFLAGS="$2$ARFLAGS -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
 
     if test -n "$MACOSX_VERSION_MAX"; then
         $2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK \
--- a/make/autoconf/lib-bundled.m4	Tue Feb 06 16:04:46 2018 +0000
+++ b/make/autoconf/lib-bundled.m4	Tue Feb 06 10:12:05 2018 -0800
@@ -209,7 +209,15 @@
     AC_MSG_ERROR([Invalid value for --with-zlib: ${with_zlib}, use 'system' or 'bundled'])
   fi
 
+  if test "x$USER_EXTERNAL_LIBZ" = "xfalse"; then
+    LIBZ_CFLAGS="$LIBZ_CFLAGS -I$TOPDIR/src/java.base/share/native/libzip/zlib"
+  else
+    LIBZ_LIBS="-lz"
+  fi
+
   AC_SUBST(USE_EXTERNAL_LIBZ)
+  AC_SUBST(LIBZ_CFLAGS)
+  AC_SUBST(LIBZ_LIBS)
 ])
 
 ################################################################################
--- a/make/autoconf/spec.gmk.in	Tue Feb 06 16:04:46 2018 +0000
+++ b/make/autoconf/spec.gmk.in	Tue Feb 06 10:12:05 2018 -0800
@@ -737,6 +737,8 @@
 USE_EXTERNAL_LIBJPEG:=@USE_EXTERNAL_LIBJPEG@
 USE_EXTERNAL_LIBGIF:=@USE_EXTERNAL_LIBGIF@
 USE_EXTERNAL_LIBZ:=@USE_EXTERNAL_LIBZ@
+LIBZ_CFLAGS:=@LIBZ_CFLAGS@
+LIBZ_LIBS:=@LIBZ_LIBS@
 LIBZIP_CAN_USE_MMAP:=@LIBZIP_CAN_USE_MMAP@
 MSVCR_DLL:=@MSVCR_DLL@
 MSVCP_DLL:=@MSVCP_DLL@
--- a/make/lib/Awt2dLibraries.gmk	Tue Feb 06 16:04:46 2018 +0000
+++ b/make/lib/Awt2dLibraries.gmk	Tue Feb 06 10:12:05 2018 -0800
@@ -905,9 +905,18 @@
 
   LIBSPLASHSCREEN_LIBS :=
 
-  ifneq ($(USE_EXTERNAL_LIBZ), true)
+  ifeq ($(USE_EXTERNAL_LIBZ), false)
     LIBSPLASHSCREEN_DIRS += $(TOPDIR)/src/java.base/share/native/libzip/zlib
-    LIBSPLASHSCREEN_CFLAGS += $(ZLIB_CPPFLAGS)
+  else
+    ifeq ($(OPENJDK_TARGET_OS), macosx)
+      ifeq ($(USE_EXTERNAL_LIBPNG), false)
+        # When building our own libpng and using an external libz, we need to
+        # inject our own libz.h to tweak the exported ZLIB_VERNUM macro. See
+        # $(TOPDIR)/src/java.desktop/macosx/native/libsplashscreen/libpng/zlib.h
+        # for details.
+        LIBSPLASHSCREEN_CFLAGS += -iquote $(TOPDIR)/src/java.desktop/macosx/native/libsplashscreen/libpng
+      endif
+    endif
   endif
 
   ifeq ($(OPENJDK_TARGET_OS), macosx)
@@ -933,7 +942,7 @@
       EXCLUDES := $(LIBSPLASHSCREEN_EXCLUDES), \
       OPTIMIZATION := LOW, \
       CFLAGS := $(LIBSPLASHSCREEN_CFLAGS) $(CFLAGS_JDKLIB) \
-                $(GIFLIB_CFLAGS) $(LIBJPEG_CFLAGS) $(PNG_CFLAGS), \
+          $(GIFLIB_CFLAGS) $(LIBJPEG_CFLAGS) $(PNG_CFLAGS) $(LIBZ_CFLAGS), \
       DISABLED_WARNINGS_gcc := sign-compare type-limits unused-result maybe-uninitialized shift-negative-value, \
       DISABLED_WARNINGS_clang := incompatible-pointer-types, \
       DISABLED_WARNINGS_solstudio := E_NEWLINE_NOT_LAST E_DECLARATION_IN_CODE \
@@ -942,8 +951,8 @@
       MAPFILE := $(TOPDIR)/make/mapfiles/libsplashscreen/mapfile-vers, \
       LDFLAGS := $(LIBSPLASHSCREEN_LDFLAGS) $(LDFLAGS_JDKLIB) \
           $(call SET_SHARED_LIBRARY_ORIGIN), \
-      LIBS := $(JDKLIB_LIBS) $(LIBSPLASHSCREEN_LIBS) $(LIBZ) \
-                        $(GIFLIB_LIBS) $(LIBJPEG_LIBS) $(PNG_LIBS), \
+      LIBS := $(JDKLIB_LIBS) $(LIBSPLASHSCREEN_LIBS) $(LIBZ_LIBS) \
+          $(GIFLIB_LIBS) $(LIBJPEG_LIBS) $(PNG_LIBS), \
       LIBS_aix := -liconv, \
       VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \
       RC_FLAGS := $(RC_FLAGS) \
--- a/make/lib/CoreLibraries.gmk	Tue Feb 06 16:04:46 2018 +0000
+++ b/make/lib/CoreLibraries.gmk	Tue Feb 06 10:12:05 2018 -0800
@@ -82,7 +82,7 @@
       OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libfdlibm, \
       SRC := $(LIBFDLIBM_SRC), \
       CFLAGS := $(CFLAGS_JDKLIB) $(LIBFDLIBM_CFLAGS), \
-      LDFLAGS := -nostdlib -r -arch x86_64, \
+      LDFLAGS := -nostdlib $(ARFLAGS), \
       OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libfdlibm, \
   ))
 
@@ -224,7 +224,7 @@
     SRC := $(TOPDIR)/src/java.base/share/native/libzip, \
     EXCLUDES := $(LIBZIP_EXCLUDES), \
     CFLAGS := $(CFLAGS_JDKLIB) \
-        $(ZLIB_CPPFLAGS) \
+        $(LIBZ_CFLAGS) \
         -I$(TOPDIR)/src/java.base/share/native/libjava \
         -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \
         -I$(SUPPORT_OUTPUTDIR)/headers/java.base, \
@@ -236,7 +236,7 @@
     LDFLAGS_windows := -export:ZIP_Open -export:ZIP_Close -export:ZIP_FindEntry \
         -export:ZIP_ReadEntry -export:ZIP_GetNextEntry \
         -export:ZIP_InflateFully -export:ZIP_CRC32 -export:ZIP_FreeEntry, \
-    LIBS_unix := -ljvm -ljava $(LIBZ), \
+    LIBS_unix := -ljvm -ljava $(LIBZ_LIBS), \
     LIBS_solaris := -lc, \
     LIBS_windows := jvm.lib $(WIN_JAVA_LIB), \
     VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \
@@ -341,8 +341,9 @@
 
 LIBJLI_CFLAGS += $(addprefix -I, $(LIBJLI_SRC_DIRS))
 
+LIBJLI_CFLAGS += $(LIBZ_CFLAGS)
+
 ifneq ($(USE_EXTERNAL_LIBZ), true)
-  LIBJLI_CFLAGS += $(ZLIB_CPPFLAGS)
   LIBJLI_EXTRA_FILES += \
       $(addprefix $(TOPDIR)/src/java.base/share/native/libzip/zlib/, \
           inflate.c \
@@ -390,7 +391,7 @@
         -export:JLI_PreprocessArg \
         -export:JLI_AddArgsFromEnvVar \
         -export:JLI_GetAppArgIndex, \
-    LIBS_unix := $(LIBZ), \
+    LIBS_unix := $(LIBZ_LIBS), \
     LIBS_linux := $(LIBDL) -lc -lpthread, \
     LIBS_solaris := $(LIBDL) -lc, \
     LIBS_aix := $(LIBDL),\
@@ -437,7 +438,7 @@
       EXTRA_FILES := $(LIBJLI_EXTRA_FILES), \
       OPTIMIZATION := HIGH, \
       CFLAGS := $(CFLAGS_JDKLIB) $(LIBJLI_CFLAGS), \
-      LDFLAGS := -nostdlib -r, \
+      LDFLAGS := -nostdlib $(ARFLAGS), \
       OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjli_static, \
   ))
 
--- a/make/lib/Lib-java.instrument.gmk	Tue Feb 06 16:04:46 2018 +0000
+++ b/make/lib/Lib-java.instrument.gmk	Tue Feb 06 10:12:05 2018 -0800
@@ -68,7 +68,7 @@
     LDFLAGS_macosx := -Wl$(COMMA)-all_load, \
     LDFLAGS_aix := -L$(SUPPORT_OUTPUTDIR)/native/java.base, \
     LIBS := $(JDKLIB_LIBS), \
-    LIBS_unix := -ljava -ljvm $(LIBZ), \
+    LIBS_unix := -ljava -ljvm $(LIBZ_LIBS), \
     LIBS_linux := -ljli $(LIBDL), \
     LIBS_solaris := -ljli $(LIBDL), \
     LIBS_aix := -liconv -ljli_static $(LIBDL), \
--- a/make/lib/LibCommon.gmk	Tue Feb 06 16:04:46 2018 +0000
+++ b/make/lib/LibCommon.gmk	Tue Feb 06 10:12:05 2018 -0800
@@ -68,12 +68,3 @@
 INSTALL_LIBRARIES_HERE := $(call FindLibDirForModule, $(MODULE))
 
 ################################################################################
-
-# Define it here since there are multiple uses.
-ifeq ($(USE_EXTERNAL_LIBZ), true)
-  LIBZ := -lz
-else
-  ZLIB_CPPFLAGS := -I$(TOPDIR)/src/java.base/share/native/libzip/zlib
-endif
-
-###############################################################################
--- a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m	Tue Feb 06 16:04:46 2018 +0000
+++ b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m	Tue Feb 06 10:12:05 2018 -0800
@@ -342,9 +342,7 @@
 
 #define DRAGMASK (NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseDraggedMask | NSLeftMouseUpMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask)
 
-#if defined(MAC_OS_X_VERSION_10_12) && \
-   MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12 && \
-   __LP64__
+#if defined(MAC_OS_X_VERSION_10_12) && __LP64__
    // 10.12 changed `mask` to NSEventMask (unsigned long long) for x86_64 builds.
 - (NSEvent *)nextEventMatchingMask:(NSEventMask)mask
 #else