From b782c7da0ea50edd82989d4777cde809b769b0ed Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Thu, 26 Aug 2021 09:59:19 +0200 Subject: [PATCH] toolchain: add -fPIC to CPPFLAGS for i686 When adding this, we go from compiling with /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/clang++ [...] -mrelocation-model pic -pic-level 2 -pic-is-pie [...] to /home/builder/.termux-build/_cache/android-r21d-api-24-v5/bin/clang++ [...] -mrelocation-model pic -pic-level 2 [...] Before, we got a warning when compiling libandroid-spawn: /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable and trying to use a program linked against libandroid-spawn gave an error, see https://github.com/termux/termux-packages/issues/7215#issuecomment-906154438 the Without this, libraries might end up with text relocations. For some reason it does not seem to be an issue on the other arches. %ci:no-build --- packages/libandroid-spawn/build.sh | 2 +- scripts/build/termux_step_setup_toolchain.sh | 3 +++ scripts/build/termux_step_start_build.sh | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/libandroid-spawn/build.sh b/packages/libandroid-spawn/build.sh index b6242aa116..d8564ba7f9 100644 --- a/packages/libandroid-spawn/build.sh +++ b/packages/libandroid-spawn/build.sh @@ -8,7 +8,7 @@ TERMUX_PKG_SKIP_SRC_EXTRACT=true TERMUX_PKG_BUILD_IN_SRC=true termux_step_make() { - $CXX $CFLAGS $CPPFLAGS -fPIC -I$TERMUX_PKG_BUILDER_DIR -c $TERMUX_PKG_BUILDER_DIR/posix_spawn.cpp + $CXX $CFLAGS $CPPFLAGS -I$TERMUX_PKG_BUILDER_DIR -c $TERMUX_PKG_BUILDER_DIR/posix_spawn.cpp $CXX $LDFLAGS -shared posix_spawn.o -o libandroid-spawn.so $AR rcu libandroid-spawn.a posix_spawn.o cp -f $TERMUX_PKG_BUILDER_DIR/LICENSE $TERMUX_PKG_SRCDIR/ diff --git a/scripts/build/termux_step_setup_toolchain.sh b/scripts/build/termux_step_setup_toolchain.sh index b41f197bf3..b729df1e91 100644 --- a/scripts/build/termux_step_setup_toolchain.sh +++ b/scripts/build/termux_step_setup_toolchain.sh @@ -44,6 +44,9 @@ termux_step_setup_toolchain() { elif [ "$TERMUX_ARCH" = "i686" ]; then # From $NDK/docs/CPU-ARCH-ABIS.html: CFLAGS+=" -march=i686 -msse3 -mstackrealign -mfpmath=sse" + # i686 seem to explicitly require -fPIC, see + # https://github.com/termux/termux-packages/issues/7215#issuecomment-906154438 + CPPFLAGS+=" -fPIC" export GOARCH=386 export GO386=sse2 elif [ "$TERMUX_ARCH" = "aarch64" ]; then diff --git a/scripts/build/termux_step_start_build.sh b/scripts/build/termux_step_start_build.sh index 4d9f08ea3f..c263ede4ac 100644 --- a/scripts/build/termux_step_start_build.sh +++ b/scripts/build/termux_step_start_build.sh @@ -2,7 +2,7 @@ termux_step_start_build() { TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_COMMON_CACHEDIR/android-r${TERMUX_NDK_VERSION}-api-${TERMUX_PKG_API_LEVEL}" # Bump the below version if a change is made in toolchain setup to ensure # that everyone gets an updated toolchain: - TERMUX_STANDALONE_TOOLCHAIN+="-v4" + TERMUX_STANDALONE_TOOLCHAIN+="-v5" # shellcheck source=/dev/null source "$TERMUX_PKG_BUILDER_SCRIPT"