2009年3月31日火曜日

Linux で apt-cross

とりあえず VMWare に Debian をインストール。特に悩むところは無いはず。

http://cdimage.debian.org/debian-cd/5.0.0/i386/iso-cd/debian-500-i386-netinst.iso

# export LANG=C
# export LC_ALL=C
# export LANGUAGE=English
# apt-get update
# apt-get install apt-cross
# apt-cross -a arm -S stable -m http://ftp.jp.debian.org/debian/ --update
# apt-cross -a arm -S stable -m http://ftp.jp.debian.org/debian/ --install gcc gcc-4.3 libgcc1 cpp cpp-4.3 gcc-4.3-base libgomp1 libc6-dev

apt-cross は依存関係解決してくれないらしいので、全て手打ちする。(参考

後は普通に binutils と gcc の ARM 版のインストール。

# apt-get build-dep gcc-4.3

一応 arm-gcc-cross とか gcc-4.3-arm-cross が apt にあるけど、どうなんだろうな…

追記

CodeSourcery から持ってくるのが一番楽。

qemu memo 2009年4月7日 kernel 2.6.29 と差し替えてみる

2009年3月30日月曜日

MinGW runtime の再構築

ビルドディレクトリ内で

mingwrt-3.15.1-mingw32-src.tar.gz



w32api-3.12-mingw32-src.tar.gz

を展開して、w32api-3.12-mingw32/include ディレクトリを一つ持ち上げる (同一階層に持ってくる)。

次に同 include を mingwrt-3.15.1-mingw32 の中にコピー。

後は mingwrt-3.15.1-mingw32 内のソースに適切な変更を施した後、

./configure --prefix=/c/MinGW

して make ; make install すれば MinGW ランタイムを再構築できる。

もっとちゃんとしたやり方があるのかもしれないけど、とりあえずこれでビルドは通る。

2009年3月25日水曜日

ffixed option

ソースを変えなくても、オプションで特定のレジスタを使わないコードを出せるらしい。

(via https://www.codeblog.org/blog/kkojima/20070330.html)

例えば r12 を使わないコードを出すときには

$ sh-elf-gcc.exe -ffixed-r12 ...

ちょっと修正

GCJ 限定らしい余計な opution を削った。

$ ../../gcc-4.4-20090313/configure --prefix=/c/msys/1.0/home/aloha/work/gcc/sh --with-as=/c/msys/1.0/home/aloha/work/gcc/sh/sh-elf/bin/as.exe --with-gnu-as --with-ld=/c/msys/1.0/home/aloha/work/gcc/sh/sh-elf/bin/ld.exe --with-gnu-ld --with-ar=/c/msys/1.0/home/aloha/work/gcc/sh/sh-elf/bin/ar.exe --with-gnu-ar --with-gmp=/usr/local/ --with-mpfr=/usr/local --without-newlib --without-headers --enable-languages=c,c++ --disable-shared --disable-multilib --disable-nls --disable-threads --disable-libstdc --disable-libstdcxx --disable-libstdcxx-v3 --disable-libssp --disable-libstdcxx-pch --disable-bootstrap --without-included-gettext --target=sh-elf --enable-checking=rtl

あと RTL をチェックしとかないと非常に厳しい。

2009年3月23日月曜日

sh 版のビルド

例のごとく configure を自分のためにメモ(もともとこのブログ自体がメモだけど…)。
$ ../../binutils-2.19/configure --prefix=/c/msys/1.0/home/aloha/work/gcc/sh/ --target=sh-elf --with-sysroot=/c/msys/1.0/home/aloha/work/gcc/sh/root

途中で MinGW の texinfo (?) が古いのでエラーになる。けど、無視してインストール (make -i install)。
$ ../../gcc-4.4-20090313/configure --prefix=/c/msys/1.0/home/aloha/work/gcc/sh --with-as=/c/msys/1.0/home/aloha/work/gcc/sh/sh-elf/bin/as.exe --with-gnu-as --with-ld=/c/msys/1.0/home/aloha/work/gcc/sh/sh-elf/bin/ld.exe --with-gnu-ld --with-ar=/c/msys/1.0/home/aloha/work/gcc/sh/sh-elf/bin/ar.exe --with-gnu-ar --with-gmp=/usr/local/ --with-mpfr=/usr/local --without-newlib --enable-languages=c,c++ --disable-shared --disable-multilib --disable-nls --disable-threads --disable-libstdc --disable-libstdcxx --disable-libssp --disable-libstdcxx-pch --disable-bootstrap --disable-win32-registry --without-included-gettext --enable-hash-synchronization --without-x --target=sh-elf

こっちも、なぜか disable-listdcxx してるのに、stdc++ を configure しに行ってエラーになってしまう。しかし、gcc のバイナリ自体はできているので、無視してインストール(今回は独自のライブラリを使うので libgcc libc libstdc++ はいらない)

gcc 4.4 からは libssp も MinGW で通るとは思うけど、習慣で disable にしてしまった。

2009年3月19日木曜日

masm option

gcc の全オプションは gcc -v --help で出る。

ATT syntax を Intel に変える、-masm=intel なんていうオプションがあったのか…

2009年3月18日水曜日

fixed_regs

例えば PIC のための GOT ebx 相対など、レジスタに特定の役割を与えるために、他の用途には使わせたくない場合がある。

そういう時は、fixed_regs[] のレジスタ番号番目の要素に 1 を入れる。
各バックエンドの override_options() などでやると良い。


if (flag_xxx) {
call_used_regs[BX_REG] = fixed_regs[BX_REG] = 1;
}


ちなみに、call_used_regs[] にも 1 をセットしておかないと、reginfo.c の gcc_assert() で落ちるので注意。

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)