2009-06-08 12 views

答えて

45

PICが位置独立コード

を表し、man gccを引用する:

ターゲットマシンではサポートされている場合、位置独立コードを放出する、動的リンクに適したサイズの任意の制限を回避しますグローバルオフセットテーブルこのオプションは、m68k、PowerPC、およびSPARCの違いになります。位置独立コードは特別なサポートを必要とするため、特定のマシンでのみ動作します。

これらのアーキテクチャで共有オブジェクト(* .so)を構築する場合は、これを使用します。

+1

FPicの意味は何ですか? –

+1

fは何も意味するものではなく、オプション名の一部です。 – Zifre

+15

fpicとfPICには違いがあります。どちらも同じことをしますが、fpicは利用可能な場合に相対オフセットを短くします。したがって、fpicを使用してコンパイルすると、小さなファイルが生成される可能性があります。残念ながら、それはいつも期待どおりに機能しないので、fPICを使用してください。また、すべてのプロセッサが短いオフセットをサポートしているわけではありませんので、違いはありません。 –

15

man gccは言う:

 
-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. 
20

f「は位置独立コード」の

PICスタンド「インターフェースの規則は、コード生成に を使用コントロール」というオプション用のgccのプレフィックスは、それがされていますm68KとSPARC用のfpicの特化です。

編集:このオプションは、共有ライブラリのみのために理にかなっている

、あなたが使用しているOSを言っている:document referenced by 0x6adb015の11ページ、およびcoryanによってコメントを読んだ後、私はいくつかの変更を加えましたグローバルオフセットテーブル、GOT。これは、すべてのアドレス参照がGOTに関連しており、複数のプロセスにわたってコードを共有できることを意味します。

このオプションを指定しないと、ローダーはすべてのオフセット自体を変更する必要があります。

言うまでもなく、ほとんど常に-fpic/PICを使用しています。

+0

私はOSが任意の仮想アドレスにライブラリをロードすることが自由だと思ったが、pic/PICなしでは、ローダーはコードを修正し、ルーチン/ライブラリの実際の場所へのすべての絶対ジャンプ+ pic/PICでは、コードは変更されていないため、実際には複数のプロセスで共有されます。 – coryan

+0

複数のプロセスは大部分が偶然です。重要なポイントは、絶対アドレスのフィックスアップを最小限に抑えて、任意の仮想アドレスにコードをロードできることです。 –

関連する問題