2009年3月17日火曜日

options

gcc のソースコード中には、$ gcc -fPIC みたいなオプションが入ったときに値がセット (fpic の時は 1、fPIC の時は 2) される flag_pic のような変数が頻出するが、どこにも定義が存在しない。

これは c.opt とか common.opt から自動生成される、options.c というファイルの中に実体が存在する。

gcc-4.4-20090313/gcc/common.opt とかに、

...
fPIC
Common Report Var(flag_pic,2)
Generate position-independent code if possible (large mode)

fPIE
Common Report Var(flag_pie,2)
Generate position-independent code for executables if possible (large mode)

fpic
Common Report Var(flag_pic,1) VarExists
Generate position-independent code if possible (small mode)

fpie
Common Report Var(flag_pie,1) VarExists
Generate position-independent code for executables if possible (small mode)
...

みたいな定義があって、これから (ビルドディレクトリの方の) gcc/options.c に awk で生成されている感じ。

...

/* Set by -fPIC.
Generate position-independent code if possible (large mode) */
int flag_pic;

/* Set by -fPIE.
Generate position-independent code for executables if possible (large mode) */

...

int flag_pie;const struct cl_option cl_options[] =
{

...

{ "-fPIC",
"Generate position-independent code if possible (large mode)",
N_OPTS, 4, 244,
CL_COMMON | CL_REPORT,
&flag_pic, CLVC_EQUAL, 2 },
{ "-fPIE",
"Generate position-independent code for executables if possible (large mode)",
N_OPTS, 4, 245,
CL_COMMON | CL_REPORT,
&flag_pie, CLVC_EQUAL, 2 },
...


各ターゲットに固有のオプションは、例えば x86 ならば gcc/config/i386/i386.opt などに。
たぶん、全ての有効な opt ファイルの中身がまとめて options.c に展開されている。

0 件のコメント: