Co oznacza-fPIC podczas budowania biblioteki współdzielonej?
Wiem, że opcja '-fPIC
' ma coś wspólnego z rozwiązywaniem adresów i niezależnością między poszczególnymi modułami, ale nie jestem pewien, co to naprawdę znaczy. Możesz to wyjaśnić?
3 answers
PIC oznacza kod niezależny od pozycji
I cytuję man gcc
:
Jeśli jest obsługiwany dla maszyny docelowej, emituje kod niezależny od pozycji, odpowiedni do dynamicznego łączenia i unikania ograniczeń wielkości globalnej tabeli offsetowej. Ta opcja robi różnicę w m68k, PowerPC i SPARC. Kod niezależny od pozycji wymaga specjalnego wsparcia i dlatego działa tylko na niektórych maszynach.
Użyj tego podczas budowania wspólnych obiektów ( * . so) na tych wymienione architektury.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-14 15:26:15
f
jest przedrostkiem gcc dla opcji, które "kontrolują używane konwencje interfejsu
w generowaniu kodu "
PIC
oznacza "Position Independent Code", jest specjalizacją fpic
dla m68K i SPARC.
Edit: po przeczytaniu strony 11 dokumentu o numerze 0x6adb015 i komentarzu coryana wprowadziłem kilka zmian:
Ta opcja ma sens tylko dla bibliotek współdzielonych i informujesz SYSTEM OPERACYJNY, że używasz globalnej tabeli przesunięć, Mam. Oznacza to, że wszystkie odniesienia adresowe są względem GOT, a kod może być współdzielony przez wiele procesów.
W przeciwnym razie, bez tej opcji, ładowacz musiałby sam zmodyfikować wszystkie offsety.
Nie trzeba dodawać, że prawie zawsze używamy -fpic / PIC.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-01-25 11:44:34
man gcc
says:
-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.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-06-08 21:02:52