This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Android] -fpic default option


You are right, we are talking about the same things. The only open
question I see is regarding:

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

Do you agree that if the driver knows that the executable will be at
the end of the build
we can safely use -fno-pic or -fPIE to override -fpic default? I'm not
quite sure which one is better for Android; -fPIE will
give us all the security advantages of the position independent code
and probably is a better option.


2012/11/16 Maxim Kuvyrkov <maxim@codesourcery.com>:
> 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
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]