GRRedWings / python3-android

Python 3 cross-compilation tools for Android.
BSD Zero Clause License
68 stars 17 forks source link

How can I enable -fPIE #8

Closed isaaclo123 closed 2 years ago

isaaclo123 commented 5 years ago

even when i set CFLAGSEXTRA to include -fPIE, it seems somewhere in the build process, -fPIC is added, causing the resulting binary to be build with PIC. Is there any particular way to disable the -fPIC?

GRRedWings commented 5 years ago

Did you look at build_single.sh, it is setting it in CFLAGS. Also what branch are you working off?

isaaclo123 commented 5 years ago

Um i'm really not sure. When i run a grep on the files in the master branch, no occourences of any flag with "PIC" show up. Let me attach my make output. output.txt

GRRedWings commented 5 years ago

I guess moving backwards, why are you trying to remove it? I'm pretty sure Python needs it to build, at least in my experience

isaaclo123 commented 5 years ago

Android versions past 5.0 will only execute PIE enabled executables, so ones compiled with PIC won't run

GRRedWings commented 5 years ago

I will have to look into this. I'm using this on the latest version of Android, granted still using NDK 16 I think. Trying to get a non gcc build has been a struggle in my fork.

4ntoine commented 4 years ago

is it resolved? Seems to be as easy as adding -fPIE to flags (and i believe recent NDK already add the required flags)

4ntoine commented 4 years ago

After adding the flags:

export CFLAGS_EXTRA="-fPIE"
export CPPFLAGS_EXTRA="-fPIE"
export CXXFLAGS_EXTRA="-fPIE"
export LDFLAGS_EXTRA="-pie"
export MAKEOPTS_EXTRA=""

Got the following error:

aarch64-linux-android-ranlib libpython3.5m.a
aarch64-linux-android-gcc -shared --sysroot /home/anton/python3-android/build-tools/16b-22-aarch64-linux-android-4.9/sysroot -L/home/anton/python3-android/build/16b-22-aarch64-linux-android-4.9/lib -L/home/anton/python3-android/build-tools/16b-22-aarch64-linux-android-4.9/lib -pie --sysroot /home/anton/python3-android/build-tools/16b-22-aarch64-linux-android-4.9/sysroot -L/home/anton/python3-android/build/16b-22-aarch64-linux-android-4.9/lib -L/home/anton/python3-android/build-tools/16b-22-aarch64-linux-android-4.9/lib -pie -Wl,-hlibpython3.5m.so -o libpython3.5m.so Modules/getbuildinfo.o Parser/acceler.o Parser/grammar1.o Parser/listnode.o Parser/node.o Parser/parser.o Parser/bitset.o Parser/metagrammar.o Parser/firstsets.o Parser/grammar.o Parser/pgen.o Parser/myreadline.o Parser/parsetok.o Parser/tokenizer.o Objects/abstract.o Objects/accu.o Objects/boolobject.o Objects/bytes_methods.o Objects/bytearrayobject.o Objects/bytesobject.o Objects/cellobject.o Objects/classobject.o Objects/codeobject.o Objects/complexobject.o Objects/descrobject.o Objects/enumobject.o Objects/exceptions.o Objects/genobject.o Objects/fileobject.o Objects/floatobject.o Objects/frameobject.o Objects/funcobject.o Objects/iterobject.o Objects/listobject.o Objects/longobject.o Objects/dictobject.o Objects/odictobject.o Objects/memoryobject.o Objects/methodobject.o Objects/moduleobject.o Objects/namespaceobject.o Objects/object.o Objects/obmalloc.o Objects/capsule.o Objects/rangeobject.o Objects/setobject.o Objects/sliceobject.o Objects/structseq.o Objects/tupleobject.o Objects/typeobject.o Objects/unicodeobject.o Objects/unicodectype.o Objects/weakrefobject.o Python/_warnings.o Python/Python-ast.o Python/asdl.o Python/ast.o Python/bltinmodule.o Python/ceval.o Python/compile.o Python/codecs.o Python/dynamic_annotations.o Python/errors.o Python/frozenmain.o Python/future.o Python/getargs.o Python/getcompiler.o Python/getcopyright.o Python/getplatform.o Python/getversion.o Python/graminit.o Python/import.o Python/importdl.o Python/marshal.o Python/modsupport.o Python/mystrtoul.o Python/mysnprintf.o Python/peephole.o Python/pyarena.o Python/pyctype.o Python/pyfpe.o Python/pyhash.o Python/pylifecycle.o Python/pymath.o Python/pystate.o Python/pythonrun.o Python/pytime.o Python/random.o Python/structmember.o Python/symtable.o Python/sysmodule.o Python/traceback.o Python/getopt.o Python/pystrcmp.o Python/pystrtod.o Python/pystrhex.o Python/dtoa.o Python/formatter_unicode.o Python/fileutils.o Python/dynload_shlib.o   Python/thread.o Modules/config.o Modules/getpath.o Modules/main.o Modules/gcmodule.o  Modules/_threadmodule.o  Modules/signalmodule.o  Modules/posixmodule.o  Modules/errnomodule.o  Modules/pwdmodule.o  Modules/_sre.o  Modules/_codecsmodule.o  Modules/_weakref.o  Modules/_functoolsmodule.o  Modules/_operator.o  Modules/_collectionsmodule.o  Modules/itertoolsmodule.o  Modules/atexitmodule.o  Modules/_stat.o  Modules/timemodule.o  Modules/_iomodule.o Modules/iobase.o Modules/fileio.o Modules/bytesio.o Modules/bufferedio.o Modules/textio.o Modules/stringio.o  Modules/zipimport.o  Modules/faulthandler.o  Modules/_tracemalloc.o Modules/hashtable.o  Modules/symtablemodule.o  Modules/xxsubtype.o Python/frozen.o   -ldl   -lm ; \
    if test libpython3.5m.so != libpython3.5m.so; then \
        ln -f libpython3.5m.so libpython3.5m.so; \
    fi
/home/anton/python3-android/build-tools/16b-22-aarch64-linux-android-4.9/sysroot/usr/lib/crtbegin_dynamic.o: In function `do_arm64_start':
crtbegin.c:(.text+0x20): undefined reference to `main'
crtbegin.c:(.text+0x4c): undefined reference to `main'
collect2: error: ld returned 1 exit status
aarch64-linux-android-gcc -shared --sysroot /home/anton/python3-android/build-tools/16b-22-aarch64-linux-android-4.9/sysroot -L/home/anton/python3-android/build/16b-22-aarch64-linux-android-4.9/lib -L/home/anton/python3-android/build-tools/16b-22-aarch64-linux-android-4.9/lib -pie --sysroot /home/anton/python3-android/build-tools/16b-22-aarch64-linux-android-4.9/sysroot -L/home/anton/python3-android/build/16b-22-aarch64-linux-android-4.9/lib -L/home/anton/python3-android/build-tools/16b-22-aarch64-linux-android-4.9/lib -pie -Wl,--no-as-needed -o libpython3.so -Wl,-hlibpython3.so libpython3.5m.so
aarch64-linux-android-gcc: error: libpython3.5m.so: No such file or directory
make[1]: *** [libpython3.so] Error 1
make[1]: Leaving directory `/home/anton/python3-android/src/Python-3.5.1'
Makefile:34: recipe for target 'python-3.5.1' failed
make: *** [python-3.5.1] Error 1
GRRedWings commented 2 years ago

I'll close this issue, if this is something still needed we can look at it for 3.10