From patchwork Tue Oct 1 01:36:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 1169675 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.133; helo=hemlock.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="M3fQVvpn"; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46j22S62Mqz9sDB for ; Tue, 1 Oct 2019 11:37:36 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id CFC8C87B40; Tue, 1 Oct 2019 01:37:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6MIsvAgzEGl7; Tue, 1 Oct 2019 01:37:30 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id A1A3B85FFD; Tue, 1 Oct 2019 01:37:30 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 3F9661BF20D for ; Tue, 1 Oct 2019 01:37:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 3CDF185FA7 for ; Tue, 1 Oct 2019 01:37:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id i4cAeDKcuCII for ; Tue, 1 Oct 2019 01:37:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 6ACD583659 for ; Tue, 1 Oct 2019 01:37:11 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id u40so19576017qth.11 for ; Mon, 30 Sep 2019 18:37:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vHvbPx4Tw39oJYpJuxDM5AhIw87zJL7ow3iejMtxjEE=; b=M3fQVvpnlcjpmqLRx9J134/C11kD81kNgNqZGJsxrbDi7DrCyp/pWAmzFqhaO37/2X W4FA5Nla+KkOu40OsK57KJ4w+p6ElLv3ayNFhRmdaHFFy8sYvPlfh5WvOWAHfP694pf6 APQSPoVzXYpEPH1RPzLy9zPkvaJIbOyBT2CWbuuvMDpE+N1APGQb1O+uD6/2u72OqGAZ c2cNijL+pPgGla4N1zYAlDxBHA+oZ7CKUt1TxyxA+b09YRlWfUD/Gms+7fsvrziRZ3N5 MfhJ2AWb8EfQ93gwuhdRxqyIi7dWOcRfrPbyXlAYvGsGDNTv5PF3/7mJ/ObMpCAcqD9j AjxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vHvbPx4Tw39oJYpJuxDM5AhIw87zJL7ow3iejMtxjEE=; b=n/6wGZsogkde2SxAz54dGylwasFrG4YbY2b+qMFdZdVEG1UF3hfo+AmPuNS5iRd+9b ly2UPLtqDhQZnP9XEmNH9ex+Z8Oxvqs9AWE9gRfuqaOkAyj58E32DkSyJWjMHI60wJ0j VG9S6FjlZ81YCXBi+pHdeNCyBiI+NFjz/0Oj9cDMa7ZKB4enqf3Jbe1mM8mg9kLy/syR xbq3Wv+vhx6kPUJhE/yuYXDWjmvIJa8r8BGSoyXw2/H7SlrEi1UoTEgPsQDU4DG2VYLD Ho2CTkYNbOYWCJ/4fbeU2LGmP0GpVVoMx2GzSlG1DLdonuN5V9/NIvVRkCpInDLXChbg kTXA== X-Gm-Message-State: APjAAAUQ6Ki5yiSSMILahY3g5byR2OECIr30wRFKrFbVEKZosZTAAq60 jWnfiTaNwK+bUJIZ1IGBHUJDK5wSSd0= X-Google-Smtp-Source: APXvYqx4YkwRb19rp5HFDfgyg4r002dJ6UMzujdBHcNl1rZY+2+T3owa5LQ4XdqXSidnhnstEVcAqg== X-Received: by 2002:ac8:3644:: with SMTP id n4mr27232837qtb.92.1569893830237; Mon, 30 Sep 2019 18:37:10 -0700 (PDT) Received: from casantos.remote.csb (177.204.230.110.dynamic.adsl.gvt.net.br. [177.204.230.110]) by smtp.gmail.com with ESMTPSA id t73sm6824587qke.113.2019.09.30.18.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 18:37:09 -0700 (PDT) From: unixmania@gmail.com To: buildroot@buildroot.org Date: Mon, 30 Sep 2019 22:36:53 -0300 Message-Id: <20191001013654.22298-2-unixmania@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20191001013654.22298-1-unixmania@gmail.com> References: <20191001013654.22298-1-unixmania@gmail.com> Subject: [Buildroot] [PATCH v2 1/2] Strip binaries in the rootfs creation instead of in target-finalize X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Carlos Santos , Ciro Santilli , Thomas De Schampheleire , Thomas Petazzoni MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Carlos Santos Since commit 118534fe54 the root filesystem image is generated from a temporary copy of TARGET_DIR, so we can strip the binaries in the copy, only. This allows us to easily find the non-stripped executables to debug with gdbserver, as they are at the same relative path in TARGET_DIR as in the target device, rather than searching inside the build directory. Fixes: https://bugs.busybox.net/show_bug.cgi?id=10386 Signed-off-by: Carlos Santos Reviewed-by: Arnout Vandecappelle (Essensium/Mind) --- CC: Ciro Santilli --- Changes v1->v2: - Strip before running the fakeroot script, as suggested by Arnout Vandecappelle - Change commit message accordingly. Removed paragraph about setting sysroot to TARGET_DIR in gdb, which is done in the next commit. --- Makefile | 34 ---------------------------------- fs/common.mk | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index ecaae13846..57314e5f1d 100644 --- a/Makefile +++ b/Makefile @@ -614,38 +614,6 @@ RSYNC_VCS_EXCLUSIONS = \ --exclude .svn --exclude .git --exclude .hg --exclude .bzr \ --exclude CVS -# 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, so the explicit exclusion is only -# done for kernel modules with incorrect permissions. -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 ./support/scripts/eclipse-register-toolchain `readlink -f $(O)` \ @@ -761,8 +729,6 @@ endif rm -rf $(TARGET_DIR)/usr/doc $(TARGET_DIR)/usr/share/doc 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 test -f $(TARGET_DIR)/etc/ld.so.conf && \ { echo "ERROR: we shouldn't have a /etc/ld.so.conf file"; exit 1; } || true diff --git a/fs/common.mk b/fs/common.mk index 842ea924a5..caa7825cbb 100644 --- a/fs/common.mk +++ b/fs/common.mk @@ -61,6 +61,38 @@ ROOTFS_COMMON_FINAL_RECURSIVE_DEPENDENCIES = $(sort \ ) \ $(ROOTFS_COMMON_FINAL_RECURSIVE_DEPENDENCIES__X)) +# 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, so the explicit exclusion is only +# done for kernel modules with incorrect permissions. +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 + .PHONY: rootfs-common rootfs-common: $(ROOTFS_COMMON_DEPENDENCIES) target-finalize @$(call MESSAGE,"Generating root filesystems common tables") @@ -157,9 +189,11 @@ $$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME): $$(ROOTFS_$(2)_DEPENDENCIES) $$(BASE_TARGET_DIR)/ \ $$(TARGET_DIR) + $$(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 + echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT) echo "set -e" >> $$(FAKEROOT_SCRIPT) - echo "chown -h -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT) PATH=$$(BR_PATH) $$(TOPDIR)/support/scripts/mkusers $$(ROOTFS_FULL_USERS_TABLE) $$(TARGET_DIR) >> $$(FAKEROOT_SCRIPT) echo "$$(HOST_DIR)/bin/makedevs -d $$(ROOTFS_FULL_DEVICES_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)