RFR: 8234525: enable link-time section-gc for linux s390x to remove unused code
Baesken, Matthias
matthias.baesken at sap.com
Thu Nov 21 08:54:39 UTC 2019
Hello,
gcc and ld can be instructed to work together to "garbage collect" unused input sections.
This feature eliminates unused code from native libraries. As a prerequisite to take full advantage of the feature,
the source files need to be compiled with "-ffunction-sections -fdata-sections".
Details on what happens can be found in the ld documentation: https://linux.die.net/man/1/ld .
See the description of --gc-sections and --print-gc-sections therein.
For more detailed insights there is a talk available from ELC2010: https://elinux.org/images/2/2d/ELC2010-gc-sections_Denys_Vlasenko.pdf
My change enables the unused code elimination on linux s390x .
(on the other Linux platforms, there are still issues to be solved with the serviceability agent, but we do not have the serviceability agent on linux s390x).
The change has 2 benefits :
- native libs with unused code get smaller (some get alot smaller)
some example lib sizes from linuxs390x (product build) :
default settings / link-time gc-sections
libmlib_image.so 556K 536K
libjavajpeg.so 300K 292K
libsplashscreen.so 412K 268K
libfontmanager.so 1.4M 864K
libjvm.so 19M 17M
- the flag --print-gc-sections outputs the removed sections when calling the linker;
this helps a lot to find coding "waiting for" cross-platform removal.
Here is an example output of --print-gc-sections for the libnet-build (linux s390x) :
/bin/ld: Removing unused section '.bss.my_gconf_init_func' in file '/builddir/support/native/java.base/libnet/DefaultProxySelector.o' <--- seems to be dead
/bin/ld: Removing unused section '.text.NET_ReadV' in file '/builddir/support/native/java.base/libnet/linux_close.o' <--- seems to be dead, I requested cross-platform removal with https://bugs.openjdk.java.net/browse/JDK-8234501
/bin/ld: Removing unused section '.text.getInet6Address_scopeifname' in file '/builddir/support/native/java.base/libnet/net_util.o' <--- seems to be dead
/bin/ld: Removing unused section '.text.getInet6Address_scopeid_set' in file '/builddir/support/native/java.base/libnet/net_util.o' <--- seems to be dead
/bin/ld: Removing unused section '.text.getInetAddress_hostName' in file '/builddir/support/native/java.base/libnet/net_util.o' <--- seems to be dead
/bin/ld: Removing unused section '.text.setDefaultScopeID' in file '/builddir/support/native/java.base/libnet/net_util_md.o' <--- seems to be dead indeed
/bin/ld: Removing unused section '.text.getDefaultScopeID' in file '/builddir/support/native/java.base/libnet/net_util_md.o' <--- seems to be dead indeed
/bin/ld: Removing unused section '.text.kernelIsV24' in file '/builddir/support/native/java.base/libnet/net_util_md.o' <--- seems to be dead indeed
/bin/ld: Removing unused section '.bss.ni_defaultIndexID.8722' in file '/builddir/support/native/java.base/libnet/net_util_md.o' <--- only used in getDefaultScopeID , which is dead
/bin/ld: Removing unused section '.bss.ni_class.8721' in file '/builddir/support/native/java.base/libnet/net_util_md.o' <--- only used in getDefaultScopeID , which is dead
/bin/ld: Removing unused section '.bss.vinit24' in file '/builddir/support/native/java.base/libnet/net_util_md.o' <--- only used in kernelIsV24 which is dead
/bin/ld: Removing unused section '.bss.kernelV24' in file '/builddir/support/native/java.base/libnet/net_util_md.o' <--- only used in kernelIsV24 which is dead
bug/webrev :
https://bugs.openjdk.java.net/browse/JDK-8234525
http://cr.openjdk.java.net/~mbaesken/webrevs/8234525.1/
Thanks, Matthias
More information about the build-dev
mailing list