Is -fPIC for shared libraries ONLY?

I know what is -fPICneeded for shared libraries and knows why.

However, I do not quite understand the question:

Should it -fPICnever be used when creating an executable or static library?

+4
source share
1 answer

Should it -fPICnever be used when creating an executable or static library?

It is never a strong word, and the above statement is false.

Code built with -fPIC(a little) is less than optimal, so why do you want to put it in something other than a shared library?

Let's start with a static library that has a simple answer.

, , , ?

3 ( -fPIC , -fPIE PIE "" ), ( , -fPIC).

, , 2 , .

, (-PIE) . -fPIC ?

, , , . , , PIE non-PIE.

3 ( -fPIC, -fPIE), ( -fPIC) , PIE -PIE . .

TL; DR: -fPIC , , ( ).

Update:

.

- ?

: .

. , . .text ( .rodata).

+4

Source: https://habr.com/ru/post/1695377/


All Articles