Skip to contentSkip to conversation

Makefile: respect strip exclusions for special libraries

PATCH Superseded John Keeping 4 participants 8 messages Jul 2, 2018 – Feb 4, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: respect strip exclusions for special libraries

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.

Instead of running one-off commands to strip each of these special binaries, build a single command for everything that needs $(STRIP_STRIP_DEBUG) and include the normal exclusion rules in this command.

---
 Makefile | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)
Makefile +21 -11
index 8d25c8a239..2deb5fd54a 100644
@@ -606,6 +606,26 @@ STRIP_FIND_CMD += -type f \( -perm /111 -o -name '*.so*' \)
 #   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
 
+# This is the command used to handle the special cases above.
+STRIP_SPECIAL_LIBS_CMD = find $(TARGET_DIR)/lib/
+ifneq (,$(filter lib/%,$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))))
+STRIP_SPECIAL_LIBS_CMD += \( $(call finddirclauses,$(TARGET_DIR),$(BR2_STRIP_EXCLUDE_DIRS)) \) -prune -o
+endif
+# Valgrind needs ld.so with enough information, so only strip
+# debugging symbols.
+STRIP_SPECIAL_LIBS_CMD += \( -name 'ld-*.so*'
+ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
+# 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"
+STRIP_SPECIAL_LIBS_CMD += -o -name 'libpthread*.so*'
+endif
+STRIP_SPECIAL_LIBS_CMD += \)
+ifneq (,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES)))
+STRIP_SPECIAL_LIBS_CMD += -not \( $(call qstrip,$(BR2_STRIP_EXCLUDE_FILES)) \)
+endif
+STRIP_SPECIAL_LIBS_CMD += | xargs -r $(STRIPCMD) $(STRIP_STRIP_DEBUG)
+
 ifeq ($(BR2_ECLIPSE_REGISTER),y)
 define TOOLCHAIN_ECLIPSE_REGISTER
 	./support/scripts/eclipse-register-toolchain `readlink -f $(O)` \
@@ -717,18 +737,8 @@ endif
 	rmdir $(TARGET_DIR)/usr/share 2>/dev/null || true
 	$(STRIP_FIND_CMD) | xargs -0 $(STRIPCMD) 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
+	$(STRIP_SPECIAL_LIBS_CMD) || true
 
-# 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 && \
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/1 Makefile: respect strip exclusions for special libraries

John, All,

On 2018-07-02 17:00 +0100, John Keeping spake thusly:

Quoted 33 lines

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.

Instead of running one-off commands to strip each of these special binaries, build a single command for everything that needs $(STRIP_STRIP_DEBUG) and include the normal exclusion rules in this command.

---
 Makefile | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)
Makefile +7 -0
index 8d25c8a239..2deb5fd54a 100644
@@ -606,6 +606,26 @@ STRIP_FIND_CMD += -type f \( -perm /111 -o -name '*.so*' \)
 #   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
 
+# This is the command used to handle the special cases above.
+STRIP_SPECIAL_LIBS_CMD = find $(TARGET_DIR)/lib/
+ifneq (,$(filter lib/%,$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))))
+STRIP_SPECIAL_LIBS_CMD += \( $(call finddirclauses,$(TARGET_DIR),$(BR2_STRIP_EXCLUDE_DIRS)) \) -prune -o
+endif
+# Valgrind needs ld.so with enough information, so only strip
+# debugging symbols.

Makefile STRIP_FIND_CMD += -type f \( -perm /111 -o -name '*.so*' \) · line 625

Quoted 10 lines
Makefile +10 -0
+STRIP_SPECIAL_LIBS_CMD += \( -name 'ld-*.so*'
+ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
+# 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"
+STRIP_SPECIAL_LIBS_CMD += -o -name 'libpthread*.so*'
+endif
+STRIP_SPECIAL_LIBS_CMD += \)
+ifneq (,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES)))
+STRIP_SPECIAL_LIBS_CMD += -not \( $(call qstrip,$(BR2_STRIP_EXCLUDE_FILES)) \)

I guess you forgot to use 'findfileclauses' here, that is:

    STRIP_SPECIAL_LIBS_CMD += -not \( $(call findfileclauses,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \)

Otherwise, expansion of the variable would give an invalide find pattern, like so:

-not \( some-excluded-file some-other-file a-tird-file \)

Or did I miss something?

Regards,
Yann E. MORIN.

Quoted 33 lines
Makefile +4 -11
+endif
+STRIP_SPECIAL_LIBS_CMD += | xargs -r $(STRIPCMD) $(STRIP_STRIP_DEBUG)
+
 ifeq ($(BR2_ECLIPSE_REGISTER),y)
 define TOOLCHAIN_ECLIPSE_REGISTER
 	./support/scripts/eclipse-register-toolchain `readlink -f $(O)` \
@@ -717,18 +737,8 @@ endif
 	rmdir $(TARGET_DIR)/usr/share 2>/dev/null || true
 	$(STRIP_FIND_CMD) | xargs -0 $(STRIPCMD) 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
+	$(STRIP_SPECIAL_LIBS_CMD) || true
 
-# 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 && \
Signature · 6 lines
2.18.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#2 lore raw

PATCH v2 1/1 Makefile: respect strip exclusions for special libraries

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.

Instead of running one-off commands to strip each of these special binaries, build a single command for everything that needs $(STRIP_STRIP_DEBUG) and include the normal exclusion rules in this command.

---

Quoted 11 lines · On Mon, 2 Jul 2018 18:40:44 +0200 "Yann E. MORIN" <[email protected]>…

I guess you forgot to use 'findfileclauses' here, that is:

    STRIP_SPECIAL_LIBS_CMD += -not \( $(call findfileclauses,$(call

qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \)

Otherwise, expansion of the variable would give an invalide find pattern, like so:

-not \( some-excluded-file some-other-file a-tird-file \)

Or did I miss something?

You're right, I'm not sure how this worked when I tested it. Here's an updated patch.

 Makefile | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)
Makefile +21 -11
index 8d25c8a239..a2d21be243 100644
@@ -606,6 +606,26 @@ STRIP_FIND_CMD += -type f \( -perm /111 -o -name '*.so*' \)
 #   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
 
+# This is the command used to handle the special cases above.
+STRIP_SPECIAL_LIBS_CMD = find $(TARGET_DIR)/lib/
+ifneq (,$(filter lib/%,$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))))
+STRIP_SPECIAL_LIBS_CMD += \( $(call finddirclauses,$(TARGET_DIR),$(BR2_STRIP_EXCLUDE_DIRS)) \) -prune -o
+endif
+# Valgrind needs ld.so with enough information, so only strip
+# debugging symbols.
+STRIP_SPECIAL_LIBS_CMD += \( -name 'ld-*.so*'
+ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
+# 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"
+STRIP_SPECIAL_LIBS_CMD += -o -name 'libpthread*.so*'
+endif
+STRIP_SPECIAL_LIBS_CMD += \)
+ifneq (,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES)))
+STRIP_SPECIAL_LIBS_CMD += -not \( $(call findfileclauses,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \)
+endif
+STRIP_SPECIAL_LIBS_CMD += | xargs -r $(STRIPCMD) $(STRIP_STRIP_DEBUG)
+
 ifeq ($(BR2_ECLIPSE_REGISTER),y)
 define TOOLCHAIN_ECLIPSE_REGISTER
 	./support/scripts/eclipse-register-toolchain `readlink -f $(O)` \
@@ -717,18 +737,8 @@ endif
 	rmdir $(TARGET_DIR)/usr/share 2>/dev/null || true
 	$(STRIP_FIND_CMD) | xargs -0 $(STRIPCMD) 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
+	$(STRIP_SPECIAL_LIBS_CMD) || true
 
-# 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 && \
Signature · 1 line
2.18.0
#3 lore raw

PATCH v2 1/1 Makefile: respect strip exclusions for special libraries

Hello,

Quoted 17 lines · John Keeping
Makefile +9 -0
index 8d25c8a239..a2d21be243 100644
@@ -606,6 +606,26 @@ STRIP_FIND_CMD += -type f \( -perm /111 -o -name '*.so*' \)
 #   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
 
+# This is the command used to handle the special cases above.
+STRIP_SPECIAL_LIBS_CMD = find $(TARGET_DIR)/lib/
+ifneq (,$(filter lib/%,$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))))
+STRIP_SPECIAL_LIBS_CMD += \( $(call finddirclauses,$(TARGET_DIR),$(BR2_STRIP_EXCLUDE_DIRS)) \) -prune -o
+endif
+# Valgrind needs ld.so with enough information, so only strip
+# debugging symbols.
+STRIP_SPECIAL_LIBS_CMD += \( -name 'ld-*.so*'
+ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)

Makefile STRIP_FIND_CMD += -type f \( -perm /111 -o -name '*.so*' \) · line 627

Quoted 10 lines
Makefile +10 -0
+# 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"
+STRIP_SPECIAL_LIBS_CMD += -o -name 'libpthread*.so*'
+endif
+STRIP_SPECIAL_LIBS_CMD += \)
+ifneq (,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES)))
+STRIP_SPECIAL_LIBS_CMD += -not \( $(call findfileclauses,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \)
+endif
+STRIP_SPECIAL_LIBS_CMD += | xargs -r $(STRIPCMD) $(STRIP_STRIP_DEBUG)

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 ?

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#4 lore raw

PATCH v2 1/1 Makefile: respect strip exclusions for special libraries

Thomas, John, All,

On 2018-07-02 22:25 +0200, Thomas Petazzoni spake thusly:

Quoted 27 lines

[...] 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*' \)
Quoted 6 lines

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 ?

Not tested, but it really looks nice.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#5 lore raw

PATCH v3 1/1 Makefile: respect strip exclusions for special libraries

In reply to Thomas Petazzoni

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.

---

Quoted 27 lines · On Mon, 2 Jul 2018 22:25:16 +0200 Thomas Petazzoni…

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*' \)
Quoted 6 lines

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(-)
Makefile +25 -19
index 8d25c8a239..ab081412d3 100644
@@ -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 && \
Signature · 1 line
2.18.0
#6 lore raw

PATCH v3 1/1 Makefile: respect strip exclusions for special libraries

John,

Quoted 8 lines · John Keeping

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.

Quoted 5 lines

Pull out the common find functionality so that we can build two find commands that re-use the common exclusion rules.

I did a test build with a set of folders and files set to exclude. Plus checked the symbols on the special libs. Looks ok when checking stripped vs not.

Quoted 122 lines

---

Quoted 27 lines · On Mon, 2 Jul 2018 22:25:16 +0200 Thomas Petazzoni…

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*' \)
Quoted 6 lines

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(-)
Makefile +25 -20
index 8d25c8a239..ab081412d3 100644
@@ -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 && \
--

2.18.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 8 lines
Matthew L Weber / Pr Software Engineer
Airborne Information Systems / RC Linux Secure Platforms
MS 131-100, C Ave NE, Cedar Rapids, IA, 52498, USA
www.rockwellcollins.com

Note: Any Export License Required Information and License Restricted
Third Party Intellectual Property (TPIP) content must be encrypted and
sent to matthew.weber at corp.rockwellcollins.com.
#7 lore raw

PATCH v3 1/1 Makefile: respect strip exclusions for special libraries

In reply to John Keeping

Hello,

Quoted 8 lines · On Tue, 3 Jul 2018 11:06:14 +0100 John Keeping <[email protected]> wrote:

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.

Quoted 5 lines

Pull out the common find functionality so that we can build two find commands that re-use the common exclusion rules.

I've applied to master, with a very minor change (see below).

Makefile RSYNC_VCS_EXCLUSIONS = \ · line 598

Quoted 5 lines
Makefile +0 -5
-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*' \)

So the permission check used to be here.

Quoted 10 lines
Makefile +9 -1
-# 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)), \

Makefile RSYNC_VCS_EXCLUSIONS = \ · line 612

Quoted 10 lines
Makefile +4 -0
+		-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

... but it's not below that comment so the "executable permission check above" is no longer true. I just deleted the "above" :)

Makefile RSYNC_VCS_EXCLUSIONS = \ · line 616

Quoted 5 lines

# done for kernel modules with incorrect permissions.

Makefile +3 -1
-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*' \) \

The executable permission check is now here.

Thanks a lot!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com