changeset 57839:62d7f4566b6d

8236714: enable link-time section-gc for linux to remove unused code Reviewed-by: erikj, ihse
author mbaesken
date Fri, 24 Jan 2020 10:16:35 +0100
parents 972e523f8309
children 4b2d33292638
files make/autoconf/flags-cflags.m4 make/autoconf/flags-ldflags.m4 make/autoconf/jdk-options.m4 make/autoconf/spec.gmk.in
diffstat 4 files changed, 41 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/make/autoconf/flags-cflags.m4	Fri Jan 24 13:48:35 2020 +0100
+++ b/make/autoconf/flags-cflags.m4	Fri Jan 24 10:16:35 2020 +0100
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -532,10 +532,13 @@
   if test "x$TOOLCHAIN_TYPE" = xgcc; then
     TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -fcheck-new -fstack-protector"
     TOOLCHAIN_CFLAGS_JDK="-pipe -fstack-protector"
-    # reduce lib size on s390x in link step, this needs also special compile flags
-    if test "x$OPENJDK_TARGET_CPU" = xs390x; then
-      TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -ffunction-sections -fdata-sections"
+    # reduce lib size on linux in link step, this needs also special compile flags
+    # do this on s390x also for libjvm (where serviceability agent is not supported)
+    if test "x$ENABLE_LINKTIME_GC" = xtrue; then
       TOOLCHAIN_CFLAGS_JDK="$TOOLCHAIN_CFLAGS_JDK -ffunction-sections -fdata-sections"
+      if test "x$OPENJDK_TARGET_CPU" = xs390x; then
+        TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -ffunction-sections -fdata-sections"
+      fi
     fi
     # technically NOT for CXX (but since this gives *worse* performance, use
     # no-strict-aliasing everywhere!)
--- a/make/autoconf/flags-ldflags.m4	Fri Jan 24 13:48:35 2020 +0100
+++ b/make/autoconf/flags-ldflags.m4	Fri Jan 24 10:16:35 2020 +0100
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -72,9 +72,13 @@
     # Add -z defs, to forbid undefined symbols in object files.
     # add relro (mark relocations read only) for all libs
     BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,-z,defs -Wl,-z,relro"
-    # s390x : remove unused code+data in link step
-    if test "x$OPENJDK_TARGET_CPU" = xs390x; then
-      BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,--gc-sections -Wl,--print-gc-sections"
+    # Linux : remove unused code+data in link step
+    if test "x$ENABLE_LINKTIME_GC" = xtrue; then
+      if test "x$OPENJDK_TARGET_CPU" = xs390x; then
+        BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,--gc-sections -Wl,--print-gc-sections"
+      else
+        BASIC_LDFLAGS_JDK_ONLY="$BASIC_LDFLAGS_JDK_ONLY -Wl,--gc-sections"
+      fi
     fi
 
     BASIC_LDFLAGS_JVM_ONLY="-Wl,-O1"
--- a/make/autoconf/jdk-options.m4	Fri Jan 24 13:48:35 2020 +0100
+++ b/make/autoconf/jdk-options.m4	Fri Jan 24 10:16:35 2020 +0100
@@ -139,6 +139,30 @@
 
   AC_SUBST(ENABLE_HEADLESS_ONLY)
 
+  # should we linktime gc unused code sections in the JDK build ?
+  AC_MSG_CHECKING([linktime gc])
+  AC_ARG_ENABLE([linktime-gc], [AS_HELP_STRING([--enable-linktime-gc],
+      [linktime gc unused code sections in the JDK build @<:@disabled@:>@])])
+
+  if test "x$enable_linktime_gc" = "xyes"; then
+    ENABLE_LINKTIME_GC="true"
+    AC_MSG_RESULT([yes])
+  elif test "x$enable_linktime_gc" = "xno"; then
+    ENABLE_LINKTIME_GC="false"
+    AC_MSG_RESULT([no])
+  elif test "x$OPENJDK_TARGET_OS" = "xlinux" && test "x$OPENJDK_TARGET_CPU" = xs390x; then
+    ENABLE_LINKTIME_GC="true"
+    AC_MSG_RESULT([yes])
+  elif test "x$enable_linktime_gc" = "x"; then
+    ENABLE_LINKTIME_GC="false"
+    AC_MSG_RESULT([no])
+  else
+    AC_MSG_ERROR([--enable-linktime-gc can only take yes or no])
+  fi
+
+  AC_SUBST(ENABLE_LINKTIME_GC)
+
+
   # Should we build the complete docs, or just a lightweight version?
   AC_ARG_ENABLE([full-docs], [AS_HELP_STRING([--enable-full-docs],
       [build complete documentation @<:@enabled if all tools found@:>@])])
--- a/make/autoconf/spec.gmk.in	Fri Jan 24 13:48:35 2020 +0100
+++ b/make/autoconf/spec.gmk.in	Fri Jan 24 10:16:35 2020 +0100
@@ -301,6 +301,8 @@
 # Only build headless support or not
 ENABLE_HEADLESS_ONLY := @ENABLE_HEADLESS_ONLY@
 
+ENABLE_LINKTIME_GC := @ENABLE_LINKTIME_GC@
+
 ENABLE_FULL_DOCS := @ENABLE_FULL_DOCS@
 
 # JDK_OUTPUTDIR specifies where a working jvm is built.