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

2019-02-25 07:35发布

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 (e.g. 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

1条回答
家丑人穷心不美
2楼-- · 2019-02-25 07:55

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.

查看更多
登录 后发表回答