Skip to content

Commit e11721c

Browse files
authored
Try #1063: --target mips*musl --cpp 1
2 parents 62b8a69 + 331af9f commit e11721c

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

.changes/1063.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"type": "changed",
4+
"description": "changed musl targets to use static-pie linkage by default, consistent with Alpine.",
5+
"breaking": true
6+
},
7+
{
8+
"type": "fixed",
9+
"description": "fixed C++ support for musl targets.",
10+
"issues": [902],
11+
"breaking": true
12+
}
13+
]

docker/musl-symlink.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ main() {
4949
fi
5050
done
5151

52+
# despite using a completely static build, the 32-bit MIPS targets
53+
# link to libgcc_s, the shared libgcc, erroneously.
54+
if [[ "${arch}" == "mips-sf" ]] || [[ "${arch}" == "mipsel-sf" ]]; then
55+
local toolchain=
56+
local gcc_lib=
57+
local gcc_ver=
58+
toolchain=$(basename "${sysroot}")
59+
gcc_lib="/usr/local/lib/gcc/${toolchain}"
60+
# shellcheck disable=SC2012
61+
gcc_ver=$(ls -1 "${gcc_lib}" | head -n 1)
62+
ln -s "${gcc_lib}/${gcc_ver}/libgcc.a" "${gcc_lib}/${gcc_ver}/libgcc_s.a"
63+
fi
64+
5265
echo "${sysroot}/lib" >> "/etc/ld-musl-${arch}.path"
5366

5467
rm -rf "${0}"

docker/musl.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,33 @@ main() {
3636
# Don't depend on the mirrors of sabotage linux that musl-cross-make uses.
3737
local linux_headers_site=https://ci-mirrors.rust-lang.org/rustc/sabotage-linux-tarballs
3838

39+
# we need -fPIC for CFLAGS because old binutils versions
40+
# don't understand debug symbols for more recent builds
41+
set +u
42+
export CFLAGS="-fPIC -fPIE ${CFLAGS}"
43+
export CXXFLAGS="-fPIC -fPIE ${CXXFLAGS}"
44+
set -u
45+
# we need to enable `-fPIE` or to avoid relocations in libstdc++
46+
# we also don't want dynamic linking to the standard libraries
47+
# enable -fPIC just to be safe. alpine GCC is built with
48+
# `--enable-default-pie`, so we want to ensure we use that.
49+
# `--disable-shared` is required to avoid issues when linking
50+
# to the wrong standard library, which would cause a segfault.
51+
# rust itself disables shared libraries with musl:
52+
# https://github.com/rust-lang/rust/blob/e42c4d7218b2596276152c5eb1e69335621f3086/src/ci/docker/scripts/musl.sh#L36
53+
#
54+
# on alpine, binaries use static-pie linked, so our behavior has
55+
# maximum portability, and is consistent with popular musl distros.
3956
hide_output make install "-j$(nproc)" \
4057
GCC_VER=9.2.0 \
4158
MUSL_VER=1.1.24 \
4259
BINUTILS_VER=2.33.1 \
4360
DL_CMD='curl --retry 3 -sSfL -C - -o' \
44-
LINUX_HEADERS_SITE=$linux_headers_site \
61+
LINUX_HEADERS_SITE="${linux_headers_site}" \
4562
OUTPUT=/usr/local/ \
63+
"COMMON_CONFIG += --disable-shared" \
64+
"COMMON_CONFIG += CFLAGS=\"-fPIC -fPIE\" CXXFLAGS=\"-fPIC -fPIE\"" \
65+
"GCC_CONFIG += --enable-default-pie" \
4666
"${@}"
4767

4868
purge_packages

targets.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ deploy = true
2222
[[target]]
2323
target = "x86_64-unknown-linux-musl"
2424
os = "ubuntu-latest"
25+
cpp = true
26+
dylib = true
2527
std = true
2628
run = true
29+
runners = "native qemu-user"
2730
deploy = true
2831

2932
[[target]]

0 commit comments

Comments
 (0)