[patch] fix the build with a toolchain with a linker defaulting to ld --as-needed

Matthias Klose doko at ubuntu.com
Mon Oct 19 20:06:15 UTC 2015


Toolchains for some Linux distributions (e.g. Ubuntu, OpenSuse) are configured 
to pass --as-needed to the linker by default, only linking with libraries when 
required.  A common build failure triggered by this default is having a required 
library on the command line before the object files being linked.  This happens 
when linking with a system zlib or system jpeg library.

Patch is attached, checked with b87.

There is one unrelated change, removing the explicit linking with the C library. 
  Is there any reason to keep that?

Matthias


-------------- next part --------------
# DP: Fix build failures with -Wl,--as-needed, don't explicitly link with -lc

Index: b/jdk/make/launcher/Launcher-jdk.pack200.gmk
===================================================================
--- a/jdk/make/launcher/Launcher-jdk.pack200.gmk
+++ b/jdk/make/launcher/Launcher-jdk.pack200.gmk
@@ -40,7 +40,7 @@ UNPACKEXE_CFLAGS := -I$(JDK_TOPDIR)/src/
 
 ifeq ($(USE_EXTERNAL_LIBZ), true)
   UNPACKEXE_CFLAGS += -DSYSTEM_ZLIB
-  UNPACKEXE_ZIPOBJS := -lz
+  UNPACKEXE_LIBS := -lz
 else
   UNPACKEXE_CFLAGS += -I$(JDK_TOPDIR)/src/java.base/share/native/libzip/zlib-1.2.8
   UNPACKEXE_ZIPOBJS := $(SUPPORT_OUTPUTDIR)/native/java.base/libzip/zcrc32$(OBJ_SUFFIX) \
@@ -90,9 +90,9 @@ $(eval $(call SetupNativeCompilation,BUI
         $(LDFLAGS_JDKEXE) $(LDFLAGS_CXX_JDK) \
         $(call SET_SHARED_LIBRARY_NAME,$(LIBRARY_PREFIX)unpack$(SHARED_LIBRARY_SUFFIX)) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
-    LDFLAGS_linux := -lc, \
+    LDFLAGS_linux := , \
     LDFLAGS_solaris := $(UNPACKEXE_LDFLAGS_solaris) -lc, \
-    LDFLAGS_SUFFIX := $(LIBCXX), \
+    LDFLAGS_SUFFIX := $(UNPACKEXE_LIBS) $(LIBCXX), \
     OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/unpackexe$(OUTPUT_SUBDIR), \
     OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_cmds/$(MODULE), \
     PROGRAM := unpack200, \
Index: b/jdk/make/lib/Awt2dLibraries.gmk
===================================================================
--- a/jdk/make/lib/Awt2dLibraries.gmk
+++ b/jdk/make/lib/Awt2dLibraries.gmk
@@ -498,10 +498,10 @@ $(eval $(call SetupNativeCompilation,BUI
     DISABLED_WARNINGS_clang := logical-op-parentheses, \
     DISABLED_WARNINGS_microsoft := 4267, \
     MAPFILE := $(BUILD_LIBJAVAJPEG_MAPFILE), \
-    LDFLAGS := $(LDFLAGS_JDKLIB) $(LIBJPEG_LIBS) \
+    LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LDFLAGS_windows := $(WIN_JAVA_LIB) jvm.lib, \
-    LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX), \
+    LDFLAGS_SUFFIX := $(LIBJPEG_LIBS) $(LDFLAGS_JDKLIB_SUFFIX), \
     VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \
     RC_FLAGS := $(RC_FLAGS) \
         -D "JDK_FNAME=javajpeg.dll" \


More information about the jdk9-dev mailing list