Plamo-7.
ここ10年ほどの間に発売されたx86系のCPUは、
しかし、
しかしながら32ビット版のバイナリを作成するにはgccやgasといった開発ツールから32/
どうせ32ビット版を作るなら、
その安直な思い付きが長きに渡る苦闘のはじまりになるのですが
7月XX日:Multilibな開発環境構築に着手
一般にMultilibと呼ばれている、
さまざまなCPU上で動くように設計されているGCC/
このあたりはビルド時に指定するオプションやビルドの順番がきわめて重要なので、
CLFSには日本語訳もあるものの、
7月XY日:Glibcビルド用のコンパイル環境の構築
Linuxが採用している共有ライブラリは、
CLFSによると、
ビルド時のオプションや必要なパッチ等はCLFSに詳しいので省くものの、
前述のように、
$ ls /mnt/clfs/cross-tools/bin/ file x86_64-unknown-linux-gnu-gcov m4 x86_64-unknown-linux-gnu-gcov-dump pkg-config x86_64-unknown-linux-gnu-gcov-tool tic x86_64-unknown-linux-gnu-gprof x86_64-unknown-linux-gnu-addr2line x86_64-unknown-linux-gnu-ld x86_64-unknown-linux-gnu-ar x86_64-unknown-linux-gnu-ld.bfd x86_64-unknown-linux-gnu-as x86_64-unknown-linux-gnu-ld.gold x86_64-unknown-linux-gnu-c++filt x86_64-unknown-linux-gnu-nm x86_64-unknown-linux-gnu-cpp x86_64-unknown-linux-gnu-objcopy ...
lib/
$ ls -F /mnt/clfs/cross-tools/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/ 32/ crtbeginS.o crtend.o crtfastmath.o crtprec64.o include/ install-tools/ libgcov.a crtbegin.o crtbeginT.o crtendS.o crtprec32.o crtprec80.o include-fixed/ libgcc.a plugin/ $ ls -F /mnt/clfs/cross-tools/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/32 crtbeginT.o crtfastmath.o crtprec80.o install-tools plugin crtbegin.o crtend.o crtprec32.o include libgcc.a crtbeginS.o crtendS.o crtprec64.o include-fixed libgcov.a
とりあえず32ビット版のGlibcをビルドするために必要なツールは揃ったので、
7月XZ日:32/64ビットなGlibcのビルド
先に作ったBinutils/
make[2]: Entering directory '/mnt/clfs/sources/Glibc/glibc-2.30/support' x86_64-unknown-linux-gnu-gcc -m32 -B/cross-tools/bin/ -Wl,-rpath-link=/mnt/clfs/sources/Glibc/build32: .... /mnt/clfs/cross-tools/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld: cannot find -lstdc++ /mnt/clfs/cross-tools/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld: cannot find -lgcc_s collect2: error: ld returned 1 exit status make[2]: *** [../Rules:215: /mnt/clfs/sources/Glibc/build32/support/links-dso-program] Error 1 make[2]: Leaving directory '/mnt/clfs/sources/Glibc/glibc-2.30/support' make[1]: *** [Makefile:259: support/others] Error 2 make[1]: Leaving directory '/mnt/clfs/sources/Glibc/glibc-2.30' make: *** [Makefile:9: all] Error 2
エラー自体は必要なライブラリが見つからない、
これはどうやらGlibcのバージョンに依存する問題のようなので、
../string/bits/string2.h:84:32: error: '__builtin_strncpy' output truncated before terminating nul copying 4 bytes from a string of the same length [-Werror=stringop-truncation] 84 | # define strncpy(dest, src, n) __builtin_strncpy (dest, src, n) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ zic.c:1822:3: note: in expansion of macro 'strncpy' 1822 | strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic); | ^~~~~~~ cc1: all warnings being treated as errors make[2]: *** [../o-iterator.mk:9: /mnt/clfs/sources/Glibc/build32-2.25/timezone/zic.o] Error 1 make[2]: Leaving directory '/mnt/clfs/sources/Glibc/glibc-2.25/timezone' make[1]: *** [Makefile:215: timezone/others] Error 2 make[1]: Leaving directory '/mnt/clfs/sources/Glibc/glibc-2.25' make: *** [Makefile:9: all] Error 2
もっともこのエラーには見覚えがあり、
configureオプションを調べてみると、
/tmp/ccRoISbw.s: Assembler messages: /tmp/ccRoISbw.s: Error: `loc1@GLIBC_2.0' can't be versioned to common symbol 'loc1' /tmp/ccRoISbw.s: Error: `loc2@GLIBC_2.0' can't be versioned to common symbol 'loc2' /tmp/ccRoISbw.s: Error: `locs@GLIBC_2.0' can't be versioned to common symbol 'locs' make[2]: *** [../o-iterator.mk:9: /mnt/clfs/sources/Glibc/build32-2.25/misc/regexp.os] Error 1 make[2]: *** Waiting for unfinished jobs.... make[2]: Leaving directory '/mnt/clfs/sources/Glibc/glibc-2.25/misc' make[1]: *** [Makefile:215: misc/subdir_lib] Error 2 make[1]: Leaving directory '/mnt/clfs/sources/Glibc/glibc-2.25' make: *** [Makefile:9: all] Error 2
と言って止まってしまった。メッセージを見る限り正規表現に関わる機能あたりでエラーになっているようだけど、
こういう時は世間の知恵を借りた方が吉、
パッチを適用すると無事ビルドは通り、
$ ls -F /tools/lib/libc* /tools/lib/libc-2.25.so* /tools/lib/libc.so.6@ /tools/lib/libcidn.so@ /tools/lib/libcrypt.a /tools/lib/libc.a /tools/lib/libc_nonshared.a /tools/lib/libcidn.so.1@ /tools/lib/libcrypt.so@ /tools/lib/libc.so /tools/lib/libcidn-2.25.so* /tools/lib/libcrypt-2.25.so* /tools/lib/libcrypt.so.1@ $ file /tools/lib/libc-2.25.so /tools/lib/libc-2.25.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (GNU/Linux), dynamically linked, interpreter /tools/lib/ld-linux.so.2, for GNU/Linux 3.12.0, with debug_info, not stripped
同じソースコードを64ビット用にconfigureし直してビルド、
$ ls -F /tools/lib64/libc* /tools/lib64/libc-2.25.so* /tools/lib64/libc.so.6@ /tools/lib64/libcidn.so@ /tools/lib64/libcrypt.a /tools/lib64/libc.a /tools/lib64/libc_nonshared.a /tools/lib64/libcidn.so.1@ /tools/lib64/libcrypt.so@ /tools/lib64/libc.so /tools/lib64/libcidn-2.25.so* /tools/lib64/libcrypt-2.25.so* /tools/lib64/libcrypt.so.1@ $ file /tools/lib64/libc-2.25.so /tools/lib64/libc-2.25.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /tools/lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.12.0, with debug_info, not stripped
Glibc2の32ビット版と64ビット版がビルドできたので、
再構築したGCCは問題なくビルド、
$ cat > hello.c #include <stdio.h> void main() { printf("Hello World !\n"); } ^D $ /usr/bin/gcc hello.c
当然のことながら作成されたバイナリは64ビット版で、
$ file a.out a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-x86-64.so.2, BuildID[sha1]=f698ece45dc3fbab11d590f5f3c49812a291617c, for GNU/Linux 3.2.0, with debug_info, not stripped
次に、
$ /cross-tools/bin/x86_64-unknown-linux-gnu-gcc hello.c $ file a.out a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /tools/lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.12.0, with debug_info, not stripped
32ビット版を作成するには-m32オプションを追加するだけでいい。
$ /cross-tools/bin/x86_64-unknown-linux-gnu-gcc -m32 hello.c $ file a.out a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /tools/lib/ld-linux.so.2, for GNU/Linux 3.12.0, with debug_info, not stripped
作成されたバイナリはIntel 80386用の32ビット版で、
$ ./a.out Hello World!
CLFSの手順によると、
このように、
今回はシリーズの最初ということで、
次回以降はもう少し話を端折って、