简体   繁体   中英

Why does arm-linux-androideabi-gcc enforce -fpic?

I was surprised to see that gcc enforces code to be position independent, even if such flag wasn't provided explicitly in the command line.

I suspect it might have to do with certain expectations from Android's dynamic loader (eg expectations on relocation types and freedom to put code wherever it wants) but I am not certain.

Can anybody explain why that really is?

$ arm-linux-androideabi-gcc --version | grep GCC
arm-linux-androideabi-gcc (GCC) 4.4.3

$ arm-linux-androideabi-gcc -v -S main.c |& grep fpic
 /home1/local64/android-toolchain/bin/../libexec/gcc/arm-linux-androideabi/4.4.3/cc1 -quiet -v -iprefix /home1/local64/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.4.3/ -isysroot /home1/local64/android-toolchain/bin/../sysroot main.c -mbionic -fpic -quiet -dumpbase main.c -march=armv5te -mfloat-abi=soft -mfpu=vfp -auxbase main -version -o main.s

Starting with Android 4.1, Google is forcing full ASLR to overcome common security exploits, see this article for more details.

Position Independent Code (PIC) is required for this to work but also PIE (Position Independent Executable) too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM