[39/50] strip: Make this work when cross-compiling

Message ID 20220222125135.1211290-40-michael.tremer@ipfire.org
State Accepted
Commit d79715dbf9de0131e69048e545c9684652d8151a
Headers
Series [01/50] expat: Update to version 2.4.6 - Security/CVE fixes |

Commit Message

Michael Tremer Feb. 22, 2022, 12:51 p.m. UTC
  The host might not have the correct tools to strip a foreign
architecture, therefore we need to use the cross tools.

The crosstools might be built in an architecture that they
cannot strip themselves and since they are not being part of the
packaged toolchain, we will just skip them.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 lfs/strip    |  5 ++++-
 src/stripper | 13 ++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
  

Patch

diff --git a/lfs/strip b/lfs/strip
index 466dfd9d5..c577c954b 100644
--- a/lfs/strip
+++ b/lfs/strip
@@ -48,7 +48,10 @@  md5 :
 $(TARGET) :
 ifeq "$(TOOLCHAIN)" "1"
 	# Strip everything in the toolchain
-	$(DIR_SRC)/src/stripper $(TOOLS_DIR)
+	$(DIR_SRC)/src/stripper $(TOOLS_DIR) \
+		--strip="$(TOOLS_DIR)/$(CROSSTARGET)/bin/strip" \
+		--ignore-errors \
+		--exclude=$(TOOLS_DIR)/$(CROSSTARGET)
 else
 	# Don't strip VDR binaries, because they use a weird plugin system
 	# which does not work when unneeded symbols get stripped from
diff --git a/src/stripper b/src/stripper
index fa624815b..498a8a30e 100755
--- a/src/stripper
+++ b/src/stripper
@@ -2,12 +2,20 @@ 
 
 paths=()
 excludes=()
+strip="strip"
+break_on_error="1"
 
 while [ $# -gt 0 ]; do
 	case "${1}" in
+		--strip=*)
+			strip="${1#*=}"
+			;;
 		--exclude=*)
 			excludes+=( "!" "-path" "${1#*=}/*" )
 			;;
+		--ignore-errors)
+			break_on_error="0"
+			;;
 		*)
 			paths+=( "${1}" )
 			;;
@@ -49,11 +57,10 @@  function _strip() {
 		--absolute-names --dump "${file}" 2>/dev/null)"
 
 	echo "Stripping ${file}..."
-	if ! strip "${args[@]}" "${file}"; then
-		return 1
+	if ! "${strip}" "${args[@]}" "${file}"; then
+		return ${break_on_error}
 	fi
 
-
 	# Restore capabilities
 	if [ -n "${capabilities}" ]; then
 		setfattr --no-dereference --restore=<(echo "${capabilities}")