GCC, PIE, PIC, archives and shared objects - what works with them?

I have a question about GCC, ThreadSanitizer, and using archives, shared libraries, and PIE and PIC.

I read about how best I can all morning, but I just can't find useful, clear information online.

I understand what PIC does. I think I understand that PIE is if you like the optimized version of PIC, which is only for executable files.

Now questions come ...

  • Is it possible to compile an executable with a PIC rather than a PIE?

  • If I compile a shared library (.so) with a PIC, should I use PIC with any executable that uses this library, and not PIE?

  • If I compile the archive (.a), can I use PIE? (I read -static and -pie should not be used together, which implies not).

I am using ThreadSanitizer. This requires PIC (and perhaps PIRO, also good), but as you can see, I don’t understand this). I have a library that can be compiled as an archive (.a) or a shared library (.so). The library needs to use ThreadSanitizer. However, the binary file that uses it should also use ThreadSanitizer (since it has its own native code that needs to be verified).

The library when building as a shared library is not actually linked when used with ThreadSanitizer - I think the link is not related to libtsan (but I suspect that this is not a real library, but a bunch of instrincs compilers built into the NCA). It is almost certain that I was doing something wrong.

, , (.a), ( / - makefile test binary ).

PIE (.a), PIE . PIE , , PIC , . , ThreadSanitizer TLS ( ), TLS.

+4
1

pic pie , gcc -fpic , -fpie exes. 1. , pic 2. , pie (PIE ) execs . (ld.so) . 3. exec . exec , exec, compile-time. , . .

+5

All Articles