Dimitry Vyukov wrote:
> On Sun, Oct 12, 2014 at 2:25 AM, Toebs Douglass <
to...@winterflaw.net> wrote:
>> If I'm building dynamic, then I must use -fPIC. Do I then use PIE or PIC
>> with the executable? I think I must use PIC...
>
> For executable you use -fPIE (which stands for Position-Independent
> *Executable*).
As I understand it, PIC and PIE do the same thing but in a different
way, and PIE is more optimal than PIC but can only be used with executables.
My concern is that if I've built some of the code with PIC (the
libraries) and then the executable with PIE, *will it all still work?*
i.e. I've now built a final executable which in part is using one method
(PIE) and in part another (PIC). Will this not cause problems?
>> If I'm building an archive, I think I can then use PIE, since it'll be
>
> For static archives it depends on what it will be linked to. If it is
> linked only to executable, then you can use -fPIE; if it is linked to
> shared libraries (and optionally to executables), then you need to use
> -fPIC.
Yes. I meant only to the executable, and I understand what you say in
general. This of course harks back to my earlier point - it looks like
you cannot mix PIE and PIC.
>> linked directly into the executable, which would then mean I can as
>> specified in the instructions use PIE to build the executable... however,
>> I've read -static should not be used with -pie, which confuses the hell out
>> of me. Is it actually meant that archives *typically* are not built -pie,
>> so don't use -pie with -static?
>
> Why do you want to use -static? It's not for creation of static
> archives. And it's not supported with tsan, don't use it.
I don't want to and I'm not using -static.
The reason I mentioned it was because of the *implications* of -static
and -pie being mutually exclusive. If that is true, then it seems to
imply I cannot make static libraries with -pie (which in fact looks to
be possible - so as I say, it confuses me).
I'm afraid I still don't know how to build tsan with a shared library.
I have to build the shared library with PIC - that's mandatory for
shared libraries. Do I build with the shared library with
-fthread=sanitize? if so, do I then build the executable with PIE, or
with PIC?