c++ c gcc fpic

c++ - ¿Qué significa-fPIC cuando construyes una biblioteca compartida?



gcc (3)

El f es el prefijo gcc para las opciones que "controlan las convenciones de interfaz utilizadas en la generación de código"

El PIC significa "Código independiente de posición", es una especialización de fpic para m68K y SPARC.

Editar: Después de leer la página 11 del documento referenciado por 0x6adb015 y el comentario de coryan, realicé algunos cambios:

Esta opción solo tiene sentido para las bibliotecas compartidas y le dice al sistema operativo que está utilizando una tabla de compensación global, GOT. Esto significa que todas las referencias de su dirección son relativas al GOT, y el código se puede compartir a través de múltiples procesos.

De lo contrario, sin esta opción, el cargador debería modificar todas las compensaciones.

Huelga decir que casi siempre usamos -fpic / PIC.

Sé que la opción '' -fPIC '' tiene algo que ver con la resolución de direcciones y la independencia entre módulos individuales, pero no estoy seguro de lo que realmente significa. ¿Puedes explicar?


PIC significa Código de Posición Independiente

y citar a man gcc :

Si es compatible con la máquina de destino, emita un código independiente de la posición, adecuado para enlaces dinámicos y evite cualquier límite en el tamaño de la tabla de compensación global. Esta opción hace una diferencia en m68k, PowerPC y SPARC. El código independiente de la posición requiere soporte especial, y por lo tanto funciona solo en ciertas máquinas.

utilízalo cuando construyas objetos compartidos (* .so) en esas arquitecturas mencionadas.


man gcc dice:

-fpic Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table (GOT). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message from the linker indicating that -fpic does not work; in that case, recompile with -fPIC instead. (These maximums are 8k on the SPARC and 32k on the m68k and RS/6000. The 386 has no such limit.) Position-independent code requires special support, and therefore works only on certain machines. For the 386, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM RS/6000 is always position-independent. -fPIC If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset table. This option makes a difference on the m68k and the SPARC. Position-independent code requires special support, and therefore works only on certain machines.