Skip to content

Commit

Permalink
toolchain: add -fPIC to CPPFLAGS for i686
Browse files Browse the repository at this point in the history
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
#7215 (comment)
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
  • Loading branch information
Grimler91 committed Aug 27, 2021
1 parent 0435f77 commit 4b5a941
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/libandroid-spawn/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
3 changes: 3 additions & 0 deletions scripts/build/termux_step_setup_toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/termux_step_start_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4b5a941

Please sign in to comment.