Skip to content

Commit e97317c

Browse files
committed
Build musl dist artifacts with debuginfo enabled
Since our musl targets link to a version of musl we build and bundle with the targets, if users need to debug into musl or generate backtraces which contain parts of the musl library, they will be unable to do so unless we enable and ship the debug info. This patch changes our dist builds so they enabled debug info when building musl. This patch also includes a fix for CFI detection in musl's `configure` script which has been posted upstream[1]. The net effect of this is that we now ship debug info for musl in those targets. This adds ~90kb to those artifacts but running `strip` on binaries produced removes all of that. For a "hello world" Rust binary on x86_64, the numbers are: | | debug | release | release + strip | | - | - | - | - | | without musl debuginfo | 507kb | 495kb | 410kb | | with musl debuginfo | 595kb | 584kb | 410kb | Once stripped, the final binaries are the same size (down to the byte). [1]: https://www.openwall.com/lists/musl/2021/10/21/2
1 parent 07acdb4 commit e97317c

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

src/ci/docker/host-x86_64/dist-arm-linux/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RUN sh /scripts/crosstool-ng-1.24.sh
88

99
WORKDIR /build
1010

11+
COPY scripts/musl-patch-configure.diff /build/
1112
COPY scripts/musl-toolchain.sh /build/
1213
# We need to mitigate rust-lang/rust#34978 when compiling musl itself as well
1314
RUN CFLAGS="-Wa,--compress-debug-sections=none -Wl,--compress-debug-sections=none" \

src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ WORKDIR /build/
2424
COPY scripts/cmake.sh /scripts/
2525
RUN /scripts/cmake.sh
2626

27+
COPY scripts/musl-patch-configure.diff /build/
2728
COPY scripts/musl-toolchain.sh /build/
2829
# We need to mitigate rust-lang/rust#34978 when compiling musl itself as well
2930
RUN CFLAGS="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none -Wl,--compress-debug-sections=none" \

src/ci/docker/host-x86_64/test-various/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RUN curl -sL https://nodejs.org/dist/v15.14.0/node-v15.14.0-linux-x64.tar.xz | \
2222
tar -xJ
2323

2424
WORKDIR /build/
25+
COPY scripts/musl-patch-configure.diff /build/
2526
COPY scripts/musl-toolchain.sh /build/
2627
RUN bash musl-toolchain.sh x86_64 && rm -rf build
2728
WORKDIR /
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/configure b/configure
2+
index 86801281..ed2f7998 100755
3+
--- a/configure
4+
+++ b/configure
5+
@@ -398,7 +398,7 @@ test "$debug" = yes && CFLAGS_AUTO=-g
6+
#
7+
printf "checking whether we should preprocess assembly to add debugging information... "
8+
if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" &&
9+
- test -f "tools/add-cfi.$ARCH.awk" &&
10+
+ test -f "$srcdir/tools/add-cfi.$ARCH.awk" &&
11+
printf ".file 1 \"srcfile.s\"\n.line 1\n.cfi_startproc\n.cfi_endproc" | $CC -g -x assembler -c -o /dev/null 2>/dev/null -
12+
then
13+
ADD_CFI=yes

src/ci/docker/scripts/musl-toolchain.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,20 @@ shift
3838

3939
# Ancient binutils versions don't understand debug symbols produced by more recent tools.
4040
# Apparently applying `-fPIC` everywhere allows them to link successfully.
41-
export CFLAGS="-fPIC $CFLAGS"
41+
# Enable debug info. If we don't do so, users can't debug into musl code,
42+
# debuggers can't walk the stack, etc. Fixes #90103.
43+
export CFLAGS="-fPIC -g1 $CFLAGS"
4244

4345
git clone https://github.com/richfelker/musl-cross-make # -b v0.9.9
4446
cd musl-cross-make
4547
# A few commits ahead of v0.9.9 to include the cowpatch fix:
4648
git checkout a54eb56f33f255dfca60be045f12a5cfaf5a72a9
4749

50+
# Fix the cfi detection script in musl's configure so cfi is generated
51+
# when debug info is asked for.
52+
mkdir patches/musl-1.1.24
53+
cp ../musl-patch-configure.diff patches/musl-1.1.24/0001-fix-cfi-detection.diff
54+
4855
hide_output make -j$(nproc) TARGET=$TARGET MUSL_VER=1.1.24 LINUX_HEADERS_SITE=$LINUX_HEADERS_SITE
4956
hide_output make install TARGET=$TARGET MUSL_VER=1.1.24 LINUX_HEADERS_SITE=$LINUX_HEADERS_SITE OUTPUT=$OUTPUT
5057

0 commit comments

Comments
 (0)