From 0126fa578c466d1ded28d7e7c04e3743431d4571 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Thu, 31 Aug 2017 17:13:41 +0000 Subject: gnu-toolchain: Fix debug stripping for cross-builds of stage2 The stage2 elements were all using the default strip-commands which don't take into account the fact that we might be cross-compiling. An `objcopy` build for one architecture will ignore binaries for other architectures that it doesn't understand, so in practice no stripping was taking place for the stage2 components when we were doing cross-builds. With this change, a stage2 sysroot containing just the 'runtime' and 'devel' domains has gone from 889MB to 306MB. --- project.conf | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'project.conf') diff --git a/project.conf b/project.conf index 36da61d4..83a09073 100644 --- a/project.conf +++ b/project.conf @@ -14,6 +14,26 @@ variables: target-stage1: "%{cpu}-bootstrap-linux-%{abi}" target: "%{cpu}-baserock-linux-%{abi}" + # This should match the %{strip-binaries} variable in BuildStream's default + # project config. But when doing a cross-build of stage2.bst we need to force + # use the cross binutils; the native binutils from the base sysroot will + # ignore the non-native binaries and leave them unstripped. + stage2-strip-binaries: | + find "%{install-root}" -type f \ + '(' -perm -111 -o -name '*.so*' \ + -o -name '*.cmxs' -o -name '*.node' ')' \ + -exec sh -ec \ + 'read -n4 hdr <"$1" # check for elf header + if [ "$hdr" != "$(printf \\x7fELF)" ]; then + exit 0 + fi + debugfile="%{install-root}%{debugdir}/$(basename "$1")" + mkdir -p "$(dirname "$debugfile")" + %{target-stage1}-objcopy --only-keep-debug "$1" "$debugfile" + chmod 644 "$debugfile" + %{target-stage1}-strip --remove-section=.comment --remove-section=.note --strip-unneeded "$1" + %{target-stage1}-objcopy --add-gnu-debuglink "$debugfile" "$1"' - {} ';' + # Resolve the cpu and ABI portions of the host triple based # on architecture names. arches: -- cgit v1.2.1