Compiling with the -fpic option fails when using GCC compilers
Failure can occur at the linking stage when building Position-Independent Code (PIC) on AArch64 using the lower-case
-fpic compiler flag with GCC compilers (gfortran, gcc, g++), in preference to using the upper-case
- This issue does not occur when using the
-fpicflag with Arm Compiler for Linux (armflang/armclang/armclang++), and it also does not occur on x86_64 because
-fpicoperates the same as
- PIC is code which is suitable for shared libraries.
-fpic compiler flag with GCC compilers on AArch64 causes the compiler to generate one less instruction per address computation in the code, and can provide code size and performance benefits. However, it also sets a limit of 32k for the Global Offset Table (GOT), and the build can fail at the executable linking stage because the GOT overflows.
-fpicdoes not set a limit for the GOT, and this issue does not occur.
Consider using the
-fPIC compiler flag with GCC compilers on AArch64, because it ensures that the size of the GOT for a dynamically linked executable will be large enough to allow the entries to be resolved by the dynamic loader.