android: try harder to force PIE for android 5+
This may work around ghc's -no-pie flag. Untested.
This commit is contained in:
parent
f4e1cd2a8a
commit
1bed62bda9
4 changed files with 62 additions and 38 deletions
56
standalone/android/toolchainpath
Executable file
56
standalone/android/toolchainpath
Executable file
|
@ -0,0 +1,56 @@
|
|||
#!/bin/sh
|
||||
# Outputs a new PATH setting that is prefixed by the path to the
|
||||
# Android cross-compiler toolchain to use for a given Android version.
|
||||
#
|
||||
# For Android 5, force PIE build flags
|
||||
#
|
||||
# Since the ghc-android wrappers actually hardcode the path to the
|
||||
# toolchain, and we want to wrap the toolchain programs, the binaries
|
||||
# are moved to bin/orig/ and replaced by wrappers.
|
||||
|
||||
androidversion="$1"
|
||||
|
||||
wrap () {
|
||||
sed -e "s!PROG!$1!" -e "s!OPTS!$3!" < wrapper.pl > "$2"
|
||||
chmod +x "$2"
|
||||
}
|
||||
|
||||
# Allow running from the top or inside this directory.
|
||||
if [ -e abiversion ]; then
|
||||
abiversion=$(cat abiversion)
|
||||
else
|
||||
abiversion=$(cat standalone/android/abiversion)
|
||||
fi
|
||||
|
||||
# location to toolchain as installed by ghc-android
|
||||
androidtoolchain="$HOME/.ghc/$abiversion/bin"
|
||||
|
||||
mkdir -p "$androidtoolchain/orig"
|
||||
|
||||
for f in $(find "$androidtoolchain" -maxdepth 1 -not -type d -printf '%f\n'); do
|
||||
bin="$androidtoolchain/$f"
|
||||
orig="$androidtoolchain/orig/$f"
|
||||
if [ ! -e "$orig" ]; then
|
||||
cp -a "$bin" "$orig"
|
||||
fi
|
||||
if [ "$androidversion" = 5 ]; then
|
||||
case "$f" in
|
||||
*-ld*)
|
||||
wrap "$orig" "$bin" "-pie"
|
||||
;;
|
||||
*-gcc)
|
||||
wrap "$orig" "$bin" "-pie -fPIE"
|
||||
;;
|
||||
*'-g++')
|
||||
wrap "$orig" "$bin" "-pie -fPIE"
|
||||
;;
|
||||
*)
|
||||
cp -a "$orig" "$bin"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
cp -a "$orig" "$bin"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$androidtoolchain:$PATH"
|
Loading…
Add table
Add a link
Reference in a new issue