Skip to content

Commit ed27d56

Browse files
Force patchelf to use 64KB page size on loongarch64
Signed-off-by: 吴小白 <296015668@qq.com>
1 parent 7c9f6cf commit ed27d56

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

cpython-unix/build-cpython.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,12 @@ else
786786
BUILD_PYTHON=${ROOT}/out/python/install/bin/python3
787787
fi
788788

789+
PATCHELF=patchelf
790+
if [ "${TARGET_TRIPLE}" = "loongarch64-unknown-linux-gnu" ]; then
791+
# Fix loongarch64 64k page size.
792+
PATCHELF="${PATCHELF} --page-size 65536"
793+
fi
794+
789795
# If we're building a shared library hack some binaries so rpath is set.
790796
# This ensures we can run the binary in any location without
791797
# LD_LIBRARY_PATH pointing to the directory containing libpython.
@@ -896,11 +902,11 @@ if [ "${PYBUILD_SHARED}" = "1" ]; then
896902
# empty dummy libpython.so, which allows the link to succeed but
897903
# ensures they do not use any unwanted symbols. That might be
898904
# worth doing at some point.)
899-
patchelf --force-rpath --set-rpath "\$ORIGIN/../lib" \
905+
${PATCHELF} --force-rpath --set-rpath "\$ORIGIN/../lib" \
900906
"${ROOT}/out/python/install/bin/python${PYTHON_MAJMIN_VERSION}"
901907

902908
if [ -n "${PYTHON_BINARY_SUFFIX}" ]; then
903-
patchelf --force-rpath --set-rpath "\$ORIGIN/../lib" \
909+
${PATCHELF} --force-rpath --set-rpath "\$ORIGIN/../lib" \
904910
"${ROOT}/out/python/install/bin/python${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX}"
905911
fi
906912

@@ -922,13 +928,13 @@ if [ "${PYBUILD_SHARED}" = "1" ]; then
922928
if [ "${CC}" == "musl-clang" ]; then
923929
# libpython3.so isn't present in debug builds.
924930
if [ -z "${CPYTHON_DEBUG}" ]; then
925-
patchelf --set-rpath "\$ORIGIN/../lib" \
931+
${PATCHELF} --set-rpath "\$ORIGIN/../lib" \
926932
"${ROOT}/out/python/install/lib/libpython3.so"
927933
fi
928934
else
929935
# libpython3.so isn't present in debug builds.
930936
if [ -z "${CPYTHON_DEBUG}" ]; then
931-
patchelf --replace-needed "${LIBPYTHON_SHARED_LIBRARY_BASENAME}" "\$ORIGIN/../lib/${LIBPYTHON_SHARED_LIBRARY_BASENAME}" \
937+
${PATCHELF} --replace-needed "${LIBPYTHON_SHARED_LIBRARY_BASENAME}" "\$ORIGIN/../lib/${LIBPYTHON_SHARED_LIBRARY_BASENAME}" \
932938
"${ROOT}/out/python/install/lib/libpython3.so"
933939
fi
934940
fi

cpython-unix/targets.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ loongarch64-unknown-linux-gnu:
267267
- '3.12'
268268
- '3.13'
269269
- '3.14'
270+
- '3.15'
270271
docker_image_suffix: .cross-loongarch64
271272
host_cc: /usr/bin/x86_64-linux-gnu-gcc
272273
host_cxx: /usr/bin/x86_64-linux-gnu-g++
@@ -275,6 +276,7 @@ loongarch64-unknown-linux-gnu:
275276
target_ldflags:
276277
# Hardening
277278
- '-Wl,-z,noexecstack'
279+
- '-Wl,-z,max-page-size=0x10000'
278280
needs:
279281
- autoconf
280282
- bdb

0 commit comments

Comments
 (0)