8236714: enable link-time section-gc for linux to remove unused code

Reviewed-by: erikj, ihse
This commit is contained in:
Matthias Baesken 2020-01-24 10:16:35 +01:00
parent 1ca54e1455
commit e438fb4c62
4 changed files with 41 additions and 8 deletions

View File

@ -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 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
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!)

View File

@ -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 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
# 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"

View File

@ -139,6 +139,30 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_JDK_OPTIONS],
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@:>@])])

View File

@ -301,6 +301,8 @@ USE_PRECOMPILED_HEADER := @USE_PRECOMPILED_HEADER@
# 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.