Skip to content

Global GCC notes

arguments

argumentdescription
--prefixThe directory where the package will be installed.
-fPICCompile with position independent code.
-DPICCompile with position independent code.
-fPIECompile with position independent code (for an executable).
-march=nativeCompile for the current machine.

-fPIC vs -DPIC

  • -fPIC is a GCC compiler option, that generates position-independent code (PIC) suitable for use in a shared library. It a type of relocation that is independent of any other code generated by a program. This is useful when you want to compile shared libraries, because it allows the same code to be loaded in a location-independent manner.

  • -DPIC is a preprocessor option that defines the macro PIC to the value 1. This is useful when you want to write code that behaves differently depending on whether it is being compiled with -fPIC or not. For example, you might want to write a function that behaves differently depending on whether it is being compiled with -fPIC or not.

-fPIC vs -fPIE

fPIE allows for Address Space Layout Randomization (ASLR), a security feature which makes it harder for an attacker to predict the memory layout of a running program, thus making certain types of attacks more difficult.

Both -fPIC and -fPIE generate position-independent code. The difference is that -fPIC generates code that is suitable for use in a shared library, while -fPIE generates code that is suitable for use in an executable.

In summary, use -fPIC for shared libraries and -fPIE for executables.