2009年3月18日水曜日

speedup build process

開発中は何度も gcc のりビルドを繰り返すことになるので、少しでもターンアラウンドタイムを短くしたい。


とりあえず configure オプションは必要最小限にする。C フロントエンドのみで、libgcc も disable に。
$ ../gcc-4.4-20090313/configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-languages=c --enable-threads --disable-win32-registry --without-x --enable-hash-synchronization --without-included-gettext --disable-libgcc --disable-nls --disable-bootstrap --disable-libssp --disable-libstdcxx-pch

Makefile を修正して、-O2 を -O0 にすると、デバッガで追いやすくなるし、ビルドスピードも上がる。

最近の CPU (core2duo とか)ならば、make -j2 のように並列度を上げてみる。

make all-gcc の他に、何か良い Make target は無いのだろうか。Ian が、途中の gcc に入ったところで ^C して、make cc1 すれば、cc1 だけ作れるよ、みたいなことを言っていた。

GCC の開発者たちはどうしてるんだろうか ? まぁ、そもそも libbackend.a を再リンクするだけでもかなりの時間がかかるのだから、あんまり抜本的な解決策は無いのかもしれない。

ELF ターゲットの場合は、GNU ld の代わりに gold を使うと、リンクスピードが上がるらしい。これは良いと思ったが、私の場合は Windows の PE ターゲットの開発なので、gold は使えないみたい…

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 に展開されている。

2009年3月16日月曜日

gcc-4.4-20090313

ビルドしてみた。

環境は MinGW + MSYS の最新版に、flex 2.5.4 を入れたもの(で、たぶん大丈夫だと思う。他にもいろいろ入れてるけど)。そして make を 3.81 に入れ替える(後述)。

GCC の prerequisites を見ると、4.3 から必要になった GMP と MPFR の他に、Parma Polyhedra Library (PPL) と CLooG-PPL が必要となっている。

しかし、これらが入ってなければ、自動的に Graphite loop optimizations は disable になるので、ビルド自体は通るらしい。

というわけで、原則的に gcc-4.4.x は、gcc-4.3.x がビルドできる環境ならばビルドできる。

$ ../gcc-4.4-20090313/configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-languages=c,c++ --enable-threads --disable-win32-registry --without-x --enable-hash-synchronization --enable-libstdcxx-debug --enable-version-specific-runtime-libs --without-included-gettext --disable-nls --disable-bootstrap --disable-libssp --disable-libstdcxx-pch --with-build-time-tools=/mingw/bin

しかし、make が新しくないと、以下のようなエラーが出る。

$ make
Makefile:26: *** GNU make version 3.80 or newer is required.. Stop.

GNU make は、MSYS 専用のを持ってこないと、上手く PATH を見てくれなくてビルドが失敗してしまうようだ。

http://downloads.sourceforge.net/mingw/make-3.81-MSYS-1.0.11-2.tar.bz2?use_mirror=jaist

などを持ってきて、msys/1.0/ 以下に展開する。

あとは通常通り make; meke install

$ i686-pc-mingw32-gcc-4.4.0.exe -v
Using built-in specs.
Target: i686-pc-mingw32
Configured with: ../gcc-4.4-20090313/configure --with-gmp=/usr/local --with-mpfr
=/usr/local --enable-languages=c,c++ --enable-threads --disable-win32-registry -
-without-x --enable-hash-synchronization --enable-libstdcxx-debug --enable-versi
on-specific-runtime-libs --without-included-gettext --disable-nls --disable-boot
strap --disable-libssp --disable-libstdcxx-pch --with-build-time-tools=/mingw/bi
n
Thread model: win32
gcc version 4.4.0 20090313 (experimental) (GCC)

2008年12月9日火曜日

mipsel-nec-elf

Toppers/JSP の KZ-Vr4131PCI-01 ターゲットは、GCC の mipsel-nec-elf というターゲットを前提にしているらしいので、とりあえず作ってみた。

http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/jsp4cm3/jsp/doc/mips3.txt?rev=1.1
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/jsp4cm3/jsp/doc/gnu_install.txt?rev=1.1

(ただし、binutils-2.13.2.1、gcc-3.3.2、newlib-1.11.0 の環境らしいので、以下の環境で通るかどうかはわからない。)
$ tar zxvf binutils-2.19.tar.gz
$ mkdir build-binutils-mipsel-nec-elf
$ cd build-binutils-mipsel-nec-elf
$ ../binutils-2.19/configure --prefix=/usr/local/mips --target=mipsel-nec-elf --disable-nls
$ make -i
$ make -i install
$ tar zxvf gcc-4.3.2.tar.gz
$ tar zxvf newlib-1.16.0.tar.gz
$ cd gcc-4.3.2.tar.gz
$ ln -s ../newlib-1.16.0/newlib
$ ln -s ../newlib-1.16.0/libgloss
$ cd ..
$ mkdir build-gcc-mipsel-nec-elf
$ cd build-gcc-mipsel-nec-elf
$ ../gcc-4.3.2/configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-languages=c,c++ --disable-nls --disable-win32-regist
ry --disable-shared --disable-libssp --prefix=/usr/local/mips/ --target=mipsel-nec-elf --disable-multilib --without-fp --disable-li
bmudflap --disable-libstdcxx-pch --with-newlib --with-headers=/home/aloha/work/mips/build/gcc-4.3.2/newlib/libc/include/
$ make
$ make install

重要なのは configure オプションだけなので、展開のところとかは適宜読み替えて適当に。
texinfo 絡みでエラーが出るので、make -i で強制的にビルドとインストールを進めている (他に致命的なエラーがあった場合、ひどい事になる場合もあるので、本当は随時確認しながら無視した方が良い。今回はコケることが最初からわかっているので、最初からエラーを無視 (-i) してビルド & インストールしてる)

2008年12月6日土曜日

mips-unknown-elf gcc with newlib

以前は mips-linux-elf で作ったので、linux に依存するヘッダを要求されてコケた。

linux kernel をビルドすることに拘らなければ、mips-unknown-elf で普通に通った。

newlib-1.16.0 を展開して、gcc-4.3.2/ 以下に newlib-1.6.0/newlib と newlib-1.6.0/libgloss へのシンボリックリンクを張る。

binutils -> gcc -> newlib の順に、以下のように configure ; make ; make install する (別途 build-*** のようなディレクトリを掘って、そこで行う)。

途中で makeinfo がどうこうというエラーが出たら、make -i で無視してビルドを続行する。
$ ../binutils-2.19/configure --prefix=/usr/local/mips --target=mipsel-unknown-elf --disable-nls --without-included-gette
xt

$ ../gcc-4.3.2/configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-languages=c,c++ --disable-nls --disable-w
in32-registry --disable-shared --without-included-gettext --disable-libssp --prefix=/usr/local/mips/ --target=mipsel-unk
nown-elf --disable-multilib --without-fp --disable-libmudflap --disable-libstdcxx-pch --with-newlib --with-headers=/home
/aloha/work/mips/build/gcc-4.3.2/newlib/libc/include/

$ ../newlib-1.16.0/configure --target=mipsel-unknown-elf --prefix=/usr/loca/mips

(newlib のビルドは gcc と同時に行われるから不要かもしれない。未確認)

できた gcc で、-EB オプションを付けると
$ /usr/local/mips/bin/mipsel-unknown-elf-gcc.exe -EB test.c
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crti.o: compiled for a little endian system and target is big endian
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crti.o: endianness incompatible with that of the selected emulation
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: failed to merge target specific data of file c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crti.o
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crtbegin.o: compiled for a little endian system and target is big endian
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crtbegin.o: endianness incompatible with that of the selected emulation
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: failed to merge target specific data of file c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crtbegin.o
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crtend.o: compiled for a little endian system and target is big endian
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crtend.o: endianness incompatible with that of the selected emulation
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: failed to merge target specific data of file c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crtend.o
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crtn.o: compiled for a little endian system and target is big endian
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crtn.o: endianness incompatible with that of the selected emulation
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: failed to merge target specific data of file c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/crtn.o
c:/msys/1.0/local/mips/bin/../lib/gcc/mipsel-unknown-elf/4.3.2/../../../../mipsel-unknown-elf/bin/ld.exe: warning: cannot find entry symbol _start; defaulting to 0000000000400050
collect2: ld returned 1 exit status

エラーになってしまう (最後の警告は、crt0.o と ld script を用意してないから当たり前)

これを両方サポートできるようにするために、enable-targets とかでなんとかできるかと思ったけど、結局上手く行かなかった。

2008年12月5日金曜日

VEC

gcc の VEC (vec.[ch]) データ構造は、プリプロセッサを使って C++ の template みたいなことをやってるらしい (C++ 言語のカラクリ とかでも触れられてるけど、cfront 時代の template の実現手法としては比較的ポピュラー)

ほんと GCC は C++ の機能を C で無理やり実装するのが得意だよなぁ。

2008年12月4日木曜日

GCC の MIPS ターゲット

newlib で作ろうとしたら、asm/unistd.h が無いよ!と、明らかに Linux Kernel の header らしきファイルを要求されて上手く行かなかった。

しかたがないので、--disable-libstdc と --disable-libstdcxx で作ってみた (MinGW + MSYS + flex + bison)。
$ ../binutils-2.19/configure --prefix=/usr/local/mips --target=mips-elf --disable-nls --without-included-gettext
...
$ ../gcc-4.3.2/configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-languages=c,c++ --disable-nls --disable-win32-registry --di
sable-shared --without-x --without-included-gettext --disable-libssp --prefix=/usr/local/mips/ --target=mips-elf --disable-multilib --with
out-fp --disable-libmudflap --disable-libstdc --disable-libstdcxx --disable-libstdcxx-pch --enable-threads --enable-hash-synchronization
...

enable-threads とか enable-hash-synchronizasion は、特に意味が無いようだ。disable-libstdcxx-pch も、たぶんいらない気がする (MinGW では、pch (PreCompiled Header) のテストが通らないから、いつまでたっても gcc が 4 系にならないらしい。ssp (StackSmashingProtector) と pch は disable にしないと、普通の gcc もビルドできない。
$ /usr/local/mips/bin/mips-elf-gcc-4.3.2.exe -v
Using built-in specs.
Target: mips-elf
Configured with: ../gcc-4.3.2/configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-languages=c,c++ --disable-nls --disable-win32-registry --disable-shared --without-x --without-included-gettext --disable-libssp --prefix=/usr/local/mips/ --target=mips-elf --disable-multilib --without-fp --disable-libmudflap --disable-libstdc --disable-libstdcxx --disable-libstdcxx-pch --enable-threads --enable-hash-synchronization
Thread model: single
gcc version 4.3.2 (GCC)