changeset 1185:545d0f49a0d3

Stripping binaries
author erikj
date Fri, 19 Sep 2014 14:14:19 +0200
parents f811c6354ec2
children 75fd07699dde
files make/Images.gmk make/Main.gmk make/StripBinaries.gmk
diffstat 3 files changed, 86 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/make/Images.gmk	Fri Sep 19 12:33:09 2014 +0200
+++ b/make/Images.gmk	Fri Sep 19 14:14:19 2014 +0200
@@ -66,11 +66,19 @@
 
 ################################################################################
 
+ifneq ($(POST_STRIP_CMD), )
+  MODULES_CMDS := $(SUPPORT_OUTPUTDIR)/modules_cmds-stripped
+  MODULES_LIBS := $(SUPPORT_OUTPUTDIR)/modules_libs-stripped
+else
+  MODULES_CMDS := $(SUPPORT_OUTPUTDIR)/modules_cmds
+  MODULES_LIBS := $(SUPPORT_OUTPUTDIR)/modules_libs
+endif
+
 JIMAGE_TOOL := $(JAVA_SMALL) \
     -Xbootclasspath/p:$(BUILDTOOLS_OUTPUTDIR)/interim_jimage_classes \
     -cp $(BUILDTOOLS_OUTPUTDIR)/jdk_bt_classes build.tools.module.ImageBuilder \
-    --cmds $(SUPPORT_OUTPUTDIR)/modules_cmds \
-    --libs $(SUPPORT_OUTPUTDIR)/modules_libs \
+    --cmds $(MODULES_CMDS) \
+    --libs $(MODULES_LIBS) \
     --classes $(JDK_OUTPUTDIR)/modules \
     #
 
--- a/make/Main.gmk	Fri Sep 19 12:33:09 2014 +0200
+++ b/make/Main.gmk	Fri Sep 19 14:14:19 2014 +0200
@@ -259,12 +259,15 @@
 	@$(ECHO) Boot cycle build step 2: Building a new JDK image using previously built image
 	+$(MAKE) $(MAKE_ARGS) -f Main.gmk SPEC=$(dir $(SPEC))bootcycle-spec.gmk images
 
+strip-binaries:
+	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f StripBinaries.gmk)
+
 jimages:
 	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f Images.gmk)
 
 ALL_TARGETS += source-tips security-jars nashorn-jar main-jars legacy-images \
     $(PROFILE_JARS_TARGETS) $(PROFILE_IMAGES_TARGETS) profiles-oscheck \
-    bootcycle-images jimages
+    bootcycle-images strip-binaries jimages
 
 ################################################################################
 # Docs targets
@@ -401,7 +404,9 @@
 
   legacy-images: jars demos samples exploded-image source-tips
 
-  jimages: exploded-image source-tips
+  strip-binaries: libs launchers gendata copy
+
+  jimages: exploded-image strip-binaries source-tips
 
   bootcycle-images: legacy-images
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/StripBinaries.gmk	Fri Sep 19 14:14:19 2014 +0200
@@ -0,0 +1,69 @@
+#
+# Copyright (c) 2014, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+default: all
+
+include $(SPEC)
+include MakeBase.gmk
+
+################################################################################
+# Copy native libraries and executables to a secondary location and strip them
+
+ifneq ($(POST_STRIP_CMD), )
+  MODULES_CMDS_STRIPPED := $(SUPPORT_OUTPUTDIR)/modules_cmds-stripped
+  MODULES_LIBS_STRIPPED := $(SUPPORT_OUTPUTDIR)/modules_libs-stripped
+
+  ALL_CMDS_SRC := $(call CacheFind, $(SUPPORT_OUTPUTDIR)/modules_cmds)
+  ALL_LIBS_SRC := $(call CacheFind, $(SUPPORT_OUTPUTDIR)/modules_libs)
+
+  $(eval $(call SetupCopyFiles,COPY_MODULES_CMDS, \
+      SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds, \
+      DEST := $(MODULES_CMDS_STRIPPED), \
+      FILES := $(ALL_CMDS_SRC)))
+
+  $(eval $(call SetupCopyFiles,COPY_MODULES_LIBS, \
+      SRC := $(SUPPORT_OUTPUTDIR)/modules_libs, \
+      DEST := $(MODULES_LIBS_STRIPPED), \
+      FILES := $(ALL_LIBS_SRC)))
+
+  FILES_TO_STRIP := $(filter-out %.debuginfo %.diz %.cgi, $(COPY_MODULES_CMDS)) \
+      $(filter %$(SHARED_LIBRARY_SUFFIX), $(COPY_MODULES_LIBS))
+
+  STRIP_TOUCH_TARGETS := $(patsubst $(SUPPORT_OUTPUTDIR)/%, \
+      $(SUPPORT_OUTPUTDIR)/_strip/%.stripped, $(FILES_TO_STRIP))
+
+  # Setup a rule for stripping files based on touch files
+  $(SUPPORT_OUTPUTDIR)/_strip/%.stripped: $(SUPPORT_OUTPUTDIR)/%
+	$(ECHO) Stripping $(LOG_INFO) $(patsubst $(OUTPUT_ROOT)/%,%,$<)
+	$(CHMOD) u+w $<
+	$(POST_STRIP_CMD) $<
+	$(if $(POST_MCS_CMD), $(POST_MCS_CMD) $<)
+	$(CHMOD) go-w $<
+	$(MKDIR) -p $(@D)
+	$(TOUCH) $@
+
+  all: $(COPY_MODULES_CMDS) $(COPY_MODULES_LIBS) $(STRIP_TOUCH_TARGETS)
+
+endif