From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id A6C4F1FF173
	for <inbox@lore.proxmox.com>; Mon, 11 Nov 2024 14:15:29 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 6C20DB0B8;
	Mon, 11 Nov 2024 14:15:28 +0100 (CET)
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Mon, 11 Nov 2024 14:14:57 +0100
Message-ID: <20241111131519.867887-2-c.heiss@proxmox.com>
X-Mailer: git-send-email 2.47.0
In-Reply-To: <20241111131519.867887-1-c.heiss@proxmox.com>
References: <20241111131519.867887-1-c.heiss@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.030 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH installer v4 01/12] debian: strip unused library
 dependencies
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Rust links in some dynamic libraries even if only used by a disabled
feature gate.

This will be needed due to moving http-related code into the
proxmox-installer-common crate and thus pulling it in at more places.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Changes v3 -> v4:
  * use/copy script from proxmox-backup

Changes v2 -> v3:
  * no changes

Changes v1 -> v2:
  * print libraries being stripped from each binary

 debian/control                                |  1 +
 debian/rules                                  |  9 +++++++++
 .../scripts/elf-strip-unused-dependencies.sh  | 20 +++++++++++++++++++
 3 files changed, 30 insertions(+)
 create mode 100755 debian/scripts/elf-strip-unused-dependencies.sh

diff --git a/debian/control b/debian/control
index 04b0c6e..ff00cc2 100644
--- a/debian/control
+++ b/debian/control
@@ -26,6 +26,7 @@ Build-Depends: cargo:native,
                librust-toml-0.8-dev,
                librust-ureq-2.10-dev,
                libtest-mockmodule-perl,
+               patchelf,
                perl,
                rustc:native,
                shellcheck,
diff --git a/debian/rules b/debian/rules
index 1c03065..8a3f879 100755
--- a/debian/rules
+++ b/debian/rules
@@ -10,3 +10,12 @@ export BUILD_MODE=release
 
 override_dh_missing:
 	dh_missing --fail-missing
+
+override_dh_strip:
+	dh_strip
+	for exe in $$(find \
+	    debian/proxmox-installer \
+	    debian/proxmox-auto-install-assistant \
+	    -executable -type f); do \
+	  debian/scripts/elf-strip-unused-dependencies.sh "$$exe" || true; \
+	done
diff --git a/debian/scripts/elf-strip-unused-dependencies.sh b/debian/scripts/elf-strip-unused-dependencies.sh
new file mode 100755
index 0000000..9f89c09
--- /dev/null
+++ b/debian/scripts/elf-strip-unused-dependencies.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+binary=$1
+
+exec 3< <(ldd -u "$binary" | grep -oP '[^/:]+$')
+
+patchargs=""
+dropped=""
+while read -r dep; do
+    dropped="$dep $dropped"
+    patchargs="--remove-needed $dep $patchargs"
+done <&3
+exec 3<&-
+
+if [[ $dropped == "" ]]; then
+    exit 0
+fi
+
+echo -e "patchelf '$binary' - removing unused dependencies:\n $dropped"
+patchelf $patchargs $binary
-- 
2.47.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel