pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: PKGSRC_MKPIE question



On Tue, Oct 22, 2024 at 05:40:30PM +0100, Sad Clouds wrote:
> However, GCC man page talks about two separate options:
> 
> -fPIC used for position independent libraries

There is a reason GCC's documentation talks about -fPIC being
"for shared libraries" and it's mostly a legacy matter. Shared libraries
require you to generate position-independent code. However, there's
reasons you might want to use PIC for a regular executable:

(a) to make ASLR more effective
(b) because your architecture's ABI requires it

You are correct in assuming that telling whether a shared
library or regular executable is being generated is A Hard Problem.
Particularly, many shared object file formats exist, and a build
system may reuse compiled object code and then link it into
_both_ a library and an executable.  Note that -fPIC is a
compiler flag, not a linker flag.


Home | Main Index | Thread Index | Old Index