Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] fs: allow strip binaries when create rootfs
@ 2021-11-10 16:10 Tan Xiaofan
  2021-11-10 19:00 ` Yann E. MORIN
  0 siblings, 1 reply; 5+ messages in thread
From: Tan Xiaofan @ 2021-11-10 16:10 UTC (permalink / raw)
  To: buildroot@buildroot.org

From 2f74b5bedffdf32e71a3786ca740c82257982f80 Mon Sep 17 00:00:00 2001
From: xiaofan <xfan1024@live.com>
Date: Wed, 10 Nov 2021 23:13:25 +0800
Subject: [PATCH] fs: allow strip binaries when create rootfs

Add BR2_STRIP_ROOTFS option, it is useful when using gdbserver on
target board. Host need unstriped binares for debug info and target
need only striped binares for rootfs size.

Signed-off-by: xiaofan <xfan1024@live.com>
---
 Config.in           | 21 +++++++++++++++++----
 fs/common.mk        |  4 ++++
 package/Makefile.in |  5 +++--
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/Config.in b/Config.in
index 3db2c8d..60a15ae 100644
--- a/Config.in
+++ b/Config.in
@@ -425,10 +425,10 @@ config BR2_ENABLE_RUNTIME_DEBUG
 	  Note: disabling this option is not a guarantee that all
 	  packages effectively removed these runtime debugging elements.
 
-config BR2_STRIP_strip
-	bool "strip target binaries"
-	default y
-	depends on !BR2_PACKAGE_HOST_ELF2FLT
+choice
+	prompt "strip target binaries"
+	default BR2_STRIP_strip if !BR2_PACKAGE_HOST_ELF2FLT
+	default BR2_STRIP_DISABLE if BR2_PACKAGE_HOST_ELF2FLT
 	help
 	  Binaries and libraries in the target filesystem will be
 	  stripped using the normal 'strip' command. This allows to save
@@ -436,6 +436,19 @@ config BR2_STRIP_strip
 	  on the target are needed for native debugging, but not when
 	  remote debugging is used.
 
+config BR2_STRIP_strip
+	bool "enable"
+	depends on !BR2_PACKAGE_HOST_ELF2FLT
+
+config BR2_STRIP_ROOTFS
+	bool "enable: only affects on rootfs image"
+	depends on !BR2_PACKAGE_HOST_ELF2FLT
+
+config BR2_STRIP_DISABLE
+	bool "disable"
+
+endchoice
+
 config BR2_STRIP_EXCLUDE_FILES
 	string "executables that should not be stripped"
 	default ""
diff --git a/fs/common.mk b/fs/common.mk
index afab7b5..ac261ba 100644
--- a/fs/common.mk
+++ b/fs/common.mk
@@ -171,6 +171,10 @@ $$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME): $$(ROOTFS_$(2)_DEPENDENCIES)
 		--exclude=/$$(notdir $$(TARGET_DIR_WARNING_FILE)) \
 		$$(BASE_TARGET_DIR)/ \
 		$$(TARGET_DIR)
+ifeq ($$(BR2_STRIP_ROOTFS),y)
+	$$(STRIP_FIND_CMD) | xargs -0 $$(STRIPCMD_ALWAYS) 2>/dev/null || true
+	$$(STRIP_FIND_SPECIAL_LIBS_CMD) | xargs -0 -r $$(STRIPCMD_ALWAYS) $$(STRIP_STRIP_DEBUG) 2>/dev/null || true
+endif
 
 	echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT)
 	echo "set -e" >> $$(FAKEROOT_SCRIPT)
diff --git a/package/Makefile.in b/package/Makefile.in
index dae7a85..d623837 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -224,10 +224,11 @@ TARGET_READELF  = $(TARGET_CROSS)readelf
 TARGET_OBJCOPY  = $(TARGET_CROSS)objcopy
 TARGET_OBJDUMP  = $(TARGET_CROSS)objdump
 
-ifeq ($(BR2_STRIP_strip),y)
 STRIP_STRIP_DEBUG := --strip-debug
+STRIPCMD_ALWAYS = $(TARGET_CROSS)strip --remove-section=.comment --remove-section=.note
+ifeq ($(BR2_STRIP_strip),y)
 TARGET_STRIP = $(TARGET_CROSS)strip
-STRIPCMD = $(TARGET_CROSS)strip --remove-section=.comment --remove-section=.note
+STRIPCMD = $(STRIPCMD_ALWAYS)
 else
 TARGET_STRIP = /bin/true
 STRIPCMD = $(TARGET_STRIP)
-- 
2.17.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-25 19:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-10 16:10 [Buildroot] [PATCH] fs: allow strip binaries when create rootfs Tan Xiaofan
2021-11-10 19:00 ` Yann E. MORIN
2021-11-11  3:16   ` [Buildroot] 回复: " Tan Xiaofan
2021-11-12 22:36   ` [Buildroot] " Thomas Petazzoni
2022-07-25 19:46     ` Arnout Vandecappelle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox