Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9663760
Dynamically link libc in musl distributions
zanieb Feb 26, 2025
18ff4fc
Fix dynlib loading
zanieb Feb 26, 2025
f156f44
Update musl dist metadata
zanieb Feb 26, 2025
c78bb9b
Update validation to support dynamic musl
zanieb Feb 26, 2025
d590f87
Update comment
zanieb Feb 26, 2025
51a5e29
Fix verify test for dynamic musl
zanieb Feb 26, 2025
7b2b0f2
Add path context to test run failure
zanieb Feb 26, 2025
2cef305
Format
zanieb Feb 26, 2025
a173de8
Install musl-dev for validation
zanieb Feb 26, 2025
94cadca
Fix musl build mode loading
zanieb Feb 26, 2025
7b8ff31
Downgrade to musl 1.2.2
zanieb Feb 26, 2025
280f345
Debug `LD_LIBRARY_PATH`
zanieb Feb 26, 2025
902fcd0
Add comment
zanieb Feb 26, 2025
b60e292
Refactor static / dynamic linking into build options
zanieb Feb 27, 2025
28d5d6e
Merge branch 'zb/ref-static' into zb/musl-dynamic
zanieb Mar 5, 2025
01172ad
Add dynamic CI targets
zanieb Mar 5, 2025
75ff237
Use the musl version from downloads in the metadata
zanieb Mar 5, 2025
d05620a
Remove the `+shared` build option; enable implicitly
zanieb Mar 5, 2025
567768d
Remove commented line
zanieb Mar 5, 2025
fd04e37
Apply `_blake2` musl fixes when doing non-static builds
zanieb Mar 5, 2025
88b335b
Split the musl versions for static and shared buildsl
zanieb Mar 5, 2025
6b6f103
Properly toggle `--enable-shared` when building the musl toolchain
zanieb Mar 6, 2025
6f88ed4
Fix syntax error
zanieb Mar 6, 2025
c0b9ce9
Set `-x` in the musl build
zanieb Mar 6, 2025
44c1959
Only enable `fPIC` during shared musl builds
zanieb Mar 6, 2025
4385eb8
Trim some extraneous whitespace
zanieb Mar 6, 2025
1990014
Change the triple during static musl tcl builds to get past duplicate…
zanieb Mar 6, 2025
7153487
Format
zanieb Mar 6, 2025
4c685db
Fix typo
zanieb Mar 6, 2025
4670133
Fix missing variable
zanieb Mar 6, 2025
c4e081d
Fix configuration of tcl build
zanieb Mar 7, 2025
c410304
Update validation
zanieb Mar 7, 2025
a745841
Remove extra "
zanieb Mar 10, 2025
6a79ece
Clean up ELF validation logic
zanieb Mar 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,8 @@ CONFIGURE_FLAGS="
${EXTRA_CONFIGURE_FLAGS}"

if [ "${CC}" = "musl-clang" ]; then
CFLAGS="${CFLAGS} -static"
CPPFLAGS="${CPPFLAGS} -static"
LDFLAGS="${LDFLAGS} -static"
PYBUILD_SHARED=0
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-shared"
PYBUILD_SHARED=1

# In order to build the _blake2 extension module with SSE3+ instructions, we need
# musl-clang to find headers that provide access to the intrinsics, as they are not
Expand Down Expand Up @@ -874,6 +872,7 @@ EOF
${BUILD_PYTHON} ${ROOT}/generate_metadata.py ${ROOT}/metadata.json
cat ${ROOT}/metadata.json

# TODO: Output a dynamic library version for musl
if [ "${CC}" != "musl-clang" ]; then
objdump -T ${LIBPYTHON_SHARED_LIBRARY} | grep GLIBC_ | awk '{print $5}' | awk -F_ '{print $2}' | sort -V | tail -n 1 > ${ROOT}/glibc_version.txt
cat ${ROOT}/glibc_version.txt
Expand Down
24 changes: 24 additions & 0 deletions cpython-unix/build-libX11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ if [ -n "${CROSS_COMPILING}" ]; then
s390x-unknown-linux-gnu)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
x86_64-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
aarch64-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
i686-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
mips-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
mipsel-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
Comment on lines +90 to +92
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a little overzealous including all these here, but of no real consequence.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming we were previously implicitly doing this for musl?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We were normalizing the triple to gnu beforehand.

ppc64le-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
riscv64-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
s390x-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
*)
echo "cross-compiling but malloc(0) override not set; failures possible"
;;
Expand Down
5 changes: 3 additions & 2 deletions cpython-unix/build-musl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ index 4a6ebe4..0000000
-}
EOF

./configure \

CFLAGS="${CFLAGS} -fPIC" CPPFLAGS="${CPPFLAGS} -fPIC" ./configure \
--prefix=/tools/host \
--disable-shared
--enable-shared

make -j `nproc`
make -j `nproc` install DESTDIR=/build/out
Expand Down
15 changes: 14 additions & 1 deletion cpython-unix/build-xextproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig
tar -xf xextproto-${XEXTPROTO_VERSION}.tar.gz
pushd xextproto-${XEXTPROTO_VERSION}

EXTRA_CONFIGURE_FLAGS=


if [ -n "${CROSS_COMPILING}" ]; then
if echo "${TARGET_TRIPLE}" | grep -q -- "-unknown-linux-musl"; then
# xextproto does not support configuration of musl targets so we pretend the target matches the
# build triple and enable cross-compilation manually
TARGET_TRIPLE="$(echo "${TARGET_TRIPLE}" | sed -e 's/-unknown-linux-musl/-unknown-linux-gnu/g')"
EXTRA_CONFIGURE_FLAGS="cross_compiling=yes"
fi
fi

CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LDFLAGS="${EXTRA_TARGET_LDFLAGS}" ./configure \
--build=${BUILD_TRIPLE} \
--host=${TARGET_TRIPLE} \
--prefix=/tools/deps
--prefix=/tools/deps \
"${EXTRA_CONFIGURE_FLAGS}"

make -j `nproc`
make -j `nproc` install DESTDIR=${ROOT}/out
15 changes: 14 additions & 1 deletion cpython-unix/build-xproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@ export PKG_CONFIG_PATH=${TOOLS_PATH}/deps/share/pkgconfig
tar -xf xproto-${XPROTO_VERSION}.tar.gz
pushd xproto-${XPROTO_VERSION}

EXTRA_CONFIGURE_FLAGS=


if [ -n "${CROSS_COMPILING}" ]; then
if echo "${TARGET_TRIPLE}" | grep -q -- "-unknown-linux-musl"; then
# xproto does not support configuration of musl targets so we pretend the target matches the
# build triple and enable cross-compilation manually
TARGET_TRIPLE="$(echo "${TARGET_TRIPLE}" | sed -e 's/-unknown-linux-musl/-unknown-linux-gnu/g')"
EXTRA_CONFIGURE_FLAGS="cross_compiling=yes"
fi
fi

CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LDFLAGS="${EXTRA_TARGET_LDFLAGS}" ./configure \
--build=${BUILD_TRIPLE} \
--host=${TARGET_TRIPLE} \
--prefix=/tools/deps
--prefix=/tools/deps \
"${EXTRA_CONFIGURE_FLAGS}"

make -j ${NUM_CPUS}
make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out
5 changes: 4 additions & 1 deletion cpython-unix/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def add_target_env(env, build_platform, target_triple, build_env):
.replace("x86_64_v3-", "x86_64-")
.replace("x86_64_v4-", "x86_64-")
# TODO should the musl target be normalized?
.replace("-unknown-linux-musl", "-unknown-linux-gnu")
# .replace("-unknown-linux-musl", "-unknown-linux-gnu")
)

# This will make x86_64_v2, etc count as cross-compiling. This is
Expand Down Expand Up @@ -506,6 +506,7 @@ def python_build_info(
)
)

# TODO: Update this for non-static musl
if not musl:
bi["core"]["shared_lib"] = "install/lib/libpython%s%s.so.1.0" % (
version,
Expand Down Expand Up @@ -834,6 +835,7 @@ def build_cpython(
crt_features = []

if host_platform == "linux64":
# TODO: Update the musl target triple to reflect it is dynamic
if "musl" in target_triple:
crt_features.append("static")
else:
Expand Down Expand Up @@ -874,6 +876,7 @@ def build_cpython(
"python_stdlib_test_packages": sorted(STDLIB_TEST_PACKAGES),
"python_symbol_visibility": python_symbol_visibility,
"python_extension_module_loading": extension_module_loading,
# TODO: Update this for dynamic musl
"libpython_link_mode": "static" if "musl" in target_triple else "shared",
"crt_features": crt_features,
"run_tests": "build/run_tests.py",
Expand Down
Loading