From patchwork Tue Jul 3 10:06:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Keeping X-Patchwork-Id: 938582 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=metanate.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=metanate.com header.i=@metanate.com header.b="t8kPQKhv"; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Kfs62Q04z9s29 for ; Tue, 3 Jul 2018 20:06:01 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 9821028BE0; Tue, 3 Jul 2018 10:05:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lv7T6kbxV1A3; Tue, 3 Jul 2018 10:05:56 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 96E3227BB4; Tue, 3 Jul 2018 10:05:56 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 912FE1C3EBC for ; Tue, 3 Jul 2018 10:05:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8E90082114 for ; Tue, 3 Jul 2018 10:05:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g7z2db9PY9EL for ; Tue, 3 Jul 2018 10:05:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from metanate.com (dougal.metanate.com [90.155.101.14]) by whitealder.osuosl.org (Postfix) with ESMTPS id AFE8C82104 for ; Tue, 3 Jul 2018 10:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=simple/simple; d=metanate.com; s=stronger; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References :In-Reply-To:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1OopIwMCthO4P1Y/wy3K+KRyn4vC/HwFV/hqf375xHk=; b=t8kPQKhvHC6VHCRE/fjICYq2GM 1EFf0UuqLxB3hJL+Fw9dNuUYm/mWsFWNTwrJlVcq9hdg24pSLIy3LX3ETH/EurmjFU1tW07g+v1ox gZ7UNwQ1VxfE8t7F+Dt4GirZ51IBGgYs5e+wWMIt2lOGezh+9oubXIr/vDJYueea0meEHvIflutcS SVlIH4OqRm6yJdcuQEVpjh1QoWU/uvr7TtKN9qFGMJr6jGQdoIjJ9YBATBahVc+gfOcuRdxmIwc/W R40BjOS7F7Zycg/pii3dfjHHzeavCODloZKO/TqArVsT3mXvLxIXCrW41kn091huj7TPlZXAyJxtS 3bR0tvUg==; Received: from johnkeeping.plus.com ([81.174.171.191] helo=donbot) by shrek.metanate.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1faIBw-00060M-PQ; Tue, 03 Jul 2018 11:05:49 +0100 Date: Tue, 3 Jul 2018 11:06:14 +0100 From: John Keeping To: Thomas Petazzoni Message-ID: <20180703110614.59009bdb@donbot> In-Reply-To: <20180702222516.5467cc60@windsurf.home> References: <20180702160027.28557-1-john@metanate.com> <20180702164044.GD2604@scaer> <20180702175711.70bf95c7@donbot> <20180702222516.5467cc60@windsurf.home> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Subject: [Buildroot] [PATCH v3] Makefile: respect strip exclusions for special libraries X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: buildroot@busybox.net, "Yann E. MORIN" Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" ld-*.so and libpthread*.so* are not stripped in the same way as other binaries because some applications need symbols in these libraries in order to operate correctly. However, the special handling for these binaries ignores the usual BR2_STRIP_EXCLUDE_* rules so it is not possible to build an image which has debugging symbols in these binaries. Pull out the common find functionality so that we can build two find commands that re-use the common exclusion rules. Fix-suggested-by: Thomas Petazzoni Signed-off-by: John Keeping Tested-by: Matt Weber --- On Mon, 2 Jul 2018 22:25:16 +0200 Thomas Petazzoni wrote: > I understand the problem, and I know you will find my comment a bit > useless, but I find this whole thing pretty complex/noisy. Can we do > better ? > > Here is some untested initial proposal: > > # When stripping, obey to BR2_STRIP_EXCLUDE_DIRS and > # BR2_STRIP_EXCLUDE_FILES > STRIP_FIND_COMMON_CMD = \ > find $(TARGET_DIR) \ > $(if $(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS)),, \ > \( $(call finddirclauses,$(TARGET_DIR),$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))) \) -prune -o ) \ > -not $(call findfileclauses,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \) \ > -print0 > > # Regular stripping for everything, except libpthread, ld-*.so and > # kernel modules. > STRIP_FIND_CMD = \ > $(STRIP_FIND_COMMON_CMD) \ > -type f \( -perm /111 -o -name '*.so*' \) \ > -not \( $(call findfileclauses,libpthread*.so* ld-*.so* *.ko) \) > > # Special stripping (only debugging symbols) for libpthread and > ld-*.so. STRIP_FIND_SPECIAL_LIBS_CMD = \ > $(STRIP_FIND_COMMON_CMD) \ > \( -name 'ld-*.so*' -o -name 'libpthread*.so*' \) > > And then: > > $(STRIP_FIND_CMD) | xargs -0 $(STRIPCMD) 2>/dev/null || true > $(STRIP_FIND_SPECIAL_LIBS_CMD) | xargs -0 $(STRIPCMD) $(STRIP_STRIP_DEBUG) || true > > Thoughts ? This looks much nicer. I've tested it and fixed a few issues, so we end up with this patch. Makefile | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 8d25c8a239..ab081412d3 100644 --- a/Makefile +++ b/Makefile @@ -591,20 +591,37 @@ RSYNC_VCS_EXCLUSIONS = \ --exclude .svn --exclude .git --exclude .hg --exclude .bzr \ --exclude CVS -STRIP_FIND_CMD = find $(TARGET_DIR) -ifneq (,$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))) -STRIP_FIND_CMD += \( $(call finddirclauses,$(TARGET_DIR),$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))) \) -prune -o -endif -STRIP_FIND_CMD += -type f \( -perm /111 -o -name '*.so*' \) -# file exclusions: +# When stripping, obey to BR2_STRIP_EXCLUDE_DIRS and +# BR2_STRIP_EXCLUDE_FILES +STRIP_FIND_COMMON_CMD = \ + find $(TARGET_DIR) \ + $(if $(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS)), \ + \( $(call finddirclauses,$(TARGET_DIR),$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))) \) \ + -prune -o \ + ) \ + $(if $(call qstrip,$(BR2_STRIP_EXCLUDE_FILES)), \ + -not \( $(call findfileclauses,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \) ) + +# Regular stripping for everything, except libpthread, ld-*.so and +# kernel modules: # - libpthread.so: a non-stripped libpthread shared library is needed for # proper debugging of pthread programs using gdb. # - ld.so: a non-stripped dynamic linker library is needed for valgrind # - kernel modules (*.ko): do not function properly when stripped like normal # applications and libraries. Normally kernel modules are already excluded # by the executable permission check above, so the explicit exclusion is only # done for kernel modules with incorrect permissions. -STRIP_FIND_CMD += -not \( $(call findfileclauses,libpthread*.so* ld-*.so* *.ko $(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \) -print0 +STRIP_FIND_CMD = \ + $(STRIP_FIND_COMMON_CMD) \ + -type f \( -perm /111 -o -name '*.so*' \) \ + -not \( $(call findfileclauses,libpthread*.so* ld-*.so* *.ko) \) \ + -print0 + +# Special stripping (only debugging symbols) for libpthread and ld-*.so. +STRIP_FIND_SPECIAL_LIBS_CMD = \ + $(STRIP_FIND_COMMON_CMD) \ + \( -name 'ld-*.so*' -o -name 'libpthread*.so*' \) \ + -print0 ifeq ($(BR2_ECLIPSE_REGISTER),y) define TOOLCHAIN_ECLIPSE_REGISTER @@ -716,19 +733,8 @@ endif rm -rf $(TARGET_DIR)/usr/share/gtk-doc rmdir $(TARGET_DIR)/usr/share 2>/dev/null || true $(STRIP_FIND_CMD) | xargs -0 $(STRIPCMD) 2>/dev/null || true + $(STRIP_FIND_SPECIAL_LIBS_CMD) | xargs -0 -r $(STRIPCMD) $(STRIP_STRIP_DEBUG) 2>/dev/null || true -# See http://sourceware.org/gdb/wiki/FAQ, "GDB does not see any threads -# besides the one in which crash occurred; or SIGTRAP kills my program when -# I set a breakpoint" -ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y) - find $(TARGET_DIR)/lib/ -type f -name 'libpthread*.so*' | \ - xargs -r $(STRIPCMD) $(STRIP_STRIP_DEBUG) -endif - -# Valgrind needs ld.so with enough information, so only strip -# debugging symbols. - find $(TARGET_DIR)/lib/ -type f -name 'ld-*.so*' | \ - xargs -r $(STRIPCMD) $(STRIP_STRIP_DEBUG) test -f $(TARGET_DIR)/etc/ld.so.conf && \ { echo "ERROR: we shouldn't have a /etc/ld.so.conf file"; exit 1; } || true test -d $(TARGET_DIR)/etc/ld.so.conf.d && \