>> The canonical way of building native applications for Android is to add >> -fno-pic to the compiler flags. That’s true for programs in userspace, but for Android system-level programs (standalone executables) like system tools, console apps or tests it seems -fpic doesn’t make much sense.
>> The intent was to make the most common behavior the default, and for Android >> that >> happens to be building shared libraries that can then be called through JNI. Okay, but for building shared libs we either provide -shared to the driver, or -c, right? In these cases we can go with -fPIC by default. In other cases we can safely assume that the executable will be created and in such case it would be a good idea to use -fPIE. That would solve the problem with a lot of tests that failed on Android and also with native applications (executables, not libs) that are built with -fPIC now. What do you think? 2012/11/15 H.J. Lu <hjl.to...@gmail.com>: > On Wed, Nov 14, 2012 at 5:26 AM, Alexander Ivchenko <aivch...@gmail.com> > wrote: >> By default in Android we always compile with -fpic or -fPIC, even when >> compiling executable. Because of that we have some test fails on >> Android: >> >> For example: >> gcc/testsuite/gcc.target/i386/pr47312.c >> /* { dg-do run } */ >> /* { dg-options "-O2" } */ >> >> void exit (int); >> void noreturn_autodetection_failed (); >> __attribute__ ((noinline)) >> detect_noreturn () >> { >> exit (0); >> } >> int >> main (void) >> { >> detect_noreturn (); >> noreturn_autodetection_failed (); >> return 0; >> } >> >> If gcc knew, that we are not going to make a shared library (which is >> implied if we are using pic option), then it would delete the call of >> noreturn_autodetection_failed as a dead code. But in case of pic we >> cannot rely on the fact that detect_noreturn () will not be >> overwritten on runtime, eventhough we are compiling executable and >> that will never happen! So in addition to several testfails, it seems >> that we are losing an optimization opportunity here also. >> I'm wondering, maybe we can use -fpie instead of -fpic by default in >> the compiler (of course if there are no -shared or -c options; those >> cases will mean that we cannot rely on the fact that we will have an >> executable after linking)? It seems that it would solve the problem.. >> Of course we always can add something like { target nonpic } to all > > We should add { target nonpic } independent of Android. > >> tests that fail on Android, but probably the problem is deeper than >> that and that would be only hiding our head in the sand. > > Using -fPIE to compile executables is a good idea. > > -- > H.J.