On 15/11/2012, at 10:39 PM, Alexander Ivchenko wrote:

>>> 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.

We seem to be saying the same thing, but it sounds like a disagreement.  Native 
(as in non-java) applications should be compiled with -fno-pic as -fpic (and 
-fPIE) is unnecessary.

> 
>>> 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.

Assuming normal build process (i.e., when one doesn't compile and link 
application in one command), by the time you provide -shared to the driver all 
the object files are already compiled.  They /need/ to be compiled as PIC for 
use in shared library or /can/ be compiled as non-PIC for use in native 
executable.  And there are also various games with partial linking.

> 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.

I don't see why it would be a good idea to use -fPIE for most normal user-space 
applications when -fno-pic would suffice and provide better code.

Am I missing something?

Thank you,

--
Maxim Kuvyrkov
CodeSourcery / Mentor Graphics

Reply via email to