summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2017-08-31 17:13:41 (GMT)
committerSam Thursfield <sam.thursfield@codethink.co.uk>2017-08-31 17:16:39 (GMT)
commit0126fa578c466d1ded28d7e7c04e3743431d4571 (patch)
treee072cbfc6ac60f4d324104b8d569977963e96170
parentda48508a880dca2faed2b2c1a23f2de3535b3223 (diff)
downloaddefinitions-0126fa578c466d1ded28d7e7c04e3743431d4571.tar.gz
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.
-rw-r--r--elements/gnu-toolchain/stage2-binutils.bst4
-rw-r--r--elements/gnu-toolchain/stage2-gawk.bst4
-rw-r--r--elements/gnu-toolchain/stage2-gcc.bst4
-rw-r--r--elements/gnu-toolchain/stage2-glibc.bst4
-rw-r--r--elements/gnu-toolchain/stage2-libstdcxx.bst4
-rw-r--r--elements/gnu-toolchain/stage2-make.bst4
-rw-r--r--project.conf20
7 files changed, 44 insertions, 0 deletions
diff --git a/elements/gnu-toolchain/stage2-binutils.bst b/elements/gnu-toolchain/stage2-binutils.bst
index e3ef2ea..612b31b 100644
--- a/elements/gnu-toolchain/stage2-binutils.bst
+++ b/elements/gnu-toolchain/stage2-binutils.bst
@@ -38,3 +38,7 @@ config:
- |
export STAGE2_SYSROOT="$(dirname $(dirname $(pwd)))"
make
+
+ strip-commands:
+ - |
+ %{stage2-strip-binaries}
diff --git a/elements/gnu-toolchain/stage2-gawk.bst b/elements/gnu-toolchain/stage2-gawk.bst
index 1c15d53..aa80f82 100644
--- a/elements/gnu-toolchain/stage2-gawk.bst
+++ b/elements/gnu-toolchain/stage2-gawk.bst
@@ -28,3 +28,7 @@ config:
--build=$(sh config.guess) --host=%{target-stage1}
build-commands:
- STAGE2_SYSROOT="$(dirname $(dirname $(pwd)))" make
+
+ strip-commands:
+ - |
+ %{stage2-strip-binaries}
diff --git a/elements/gnu-toolchain/stage2-gcc.bst b/elements/gnu-toolchain/stage2-gcc.bst
index beaff58..dffa443 100644
--- a/elements/gnu-toolchain/stage2-gcc.bst
+++ b/elements/gnu-toolchain/stage2-gcc.bst
@@ -100,3 +100,7 @@ config:
install -d "%{install-root}/lib"
ln -s "%{prefix}/$libdir/libgcc_s.so" "%{install-root}/lib/"
ln -s "%{prefix}/$libdir/libgcc_s.so.1" "%{install-root}/lib/"
+
+ strip-commands:
+ - |
+ %{stage2-strip-binaries}
diff --git a/elements/gnu-toolchain/stage2-glibc.bst b/elements/gnu-toolchain/stage2-glibc.bst
index 8c75e78..fd2c9b8 100644
--- a/elements/gnu-toolchain/stage2-glibc.bst
+++ b/elements/gnu-toolchain/stage2-glibc.bst
@@ -129,3 +129,7 @@ config:
[ -z $loader ] && ( echo "Bug in stage2-glibc ld.so symlinks" ; exit 1 )
ln -s "%{prefix}/lib/$loader" "%{install-root}/lib/$loader"
esac
+
+ strip-commands:
+ - |
+ %{stage2-strip-binaries}
diff --git a/elements/gnu-toolchain/stage2-libstdcxx.bst b/elements/gnu-toolchain/stage2-libstdcxx.bst
index 12ea73f..58055e8 100644
--- a/elements/gnu-toolchain/stage2-libstdcxx.bst
+++ b/elements/gnu-toolchain/stage2-libstdcxx.bst
@@ -53,3 +53,7 @@ config:
install-commands:
- cd o && make DESTDIR="%{install-root}" install
+
+ strip-commands:
+ - |
+ %{stage2-strip-binaries}
diff --git a/elements/gnu-toolchain/stage2-make.bst b/elements/gnu-toolchain/stage2-make.bst
index 9c804f1..0cb4cdb 100644
--- a/elements/gnu-toolchain/stage2-make.bst
+++ b/elements/gnu-toolchain/stage2-make.bst
@@ -27,3 +27,7 @@ config:
--build=$(sh config/config.guess) --host=%{target-stage1}
build-commands:
- STAGE2_SYSROOT="$(dirname $(dirname $(pwd)))" make
+
+ strip-commands:
+ - |
+ %{stage2-strip-binaries}
diff --git a/project.conf b/project.conf
index 36da61d..83a0907 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: