gcc 9.2.0

Node.jsをコンパイルしたときにgccが古い!と指摘された。
wikiを見ると最新版は9.2なんだそうな。

ps. 今は、gcc-10.2.0 らしい。

インストしてみることにした。
参考:gccをソースからビルド/インストールする
ps.2019/11/26

1.ReadyRAS-212の/rootは容量が少ない(3.7GB)ので
エラーが出るから、/home/xxxxx(5.5TB:HDD容量に依る)で作成する。

/./mpfr/src/.libs -L/root/gcc-9.2.0/build/./mpc/src/.libs -lmpc -lmpfr -lgmp -rdynamic -ldl  -L./../zlib -lz libcommon.a ../libcpp/libcpp.a   ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a
collect2: error: ld returned 1 exit status
../../gcc/lto/Make-lang.in:81: recipe for target 'lto1' failed

2.–prefix=/usr/localで、楽にシェルで使えるしようとすると
make install で失敗してしまった。
make uninstallが使えなくなっていたので、そのせいかもしれない。
–prefix=/usr/local/gcc-9.2.0にする。

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/plugin
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use :q, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[3]: Leaving directory '/home/****/gcc-9.2.0/build/libcc1'
make[2]: Leaving directory '/home/****/gcc-9.2.0/build/libcc1'
make[2]: Entering directory '/home/****/gcc-9.2.0/build/armv7l-unknown-linux-gnueabi/libgcc'
make[2]: *** No rule to make target 'install'.  Stop.
make[2]: Leaving directory '/home/****/gcc-9.2.0/build/armv7l-unknown-linux-gnueabi/libgcc'
Makefile:14301: recipe for target 'install-target-libgcc' failed
make[1]: *** [install-target-libgcc] Error 2
make[1]: Leaving directory '/home/****/gcc-9.2.0/build'
Makefile:2349: recipe for target 'install' failed
make: *** [install] Error 2

ついでなのでお行儀よくsudoを使うようにしてみた。
※CentOSならグループはwheel。
※Ubuntuは、usemod -G のパラメータの順序が逆だそうで非常に危険。

$ su -
# apt-get install sudo
# usermod -G sudo ${development-user}
# exit
$ exit

再構築直後のHDD(6TB×2)の状況をメモ

# df -H
Filesystem      Size  Used Avail Use% Mounted on
udev             11M  4.1k   11M   1% /dev
/dev/md0        4.0G  542M  3.2G  15% /
tmpfs           1.1G  8.2k  1.1G   1% /dev/shm
tmpfs           1.1G  377k  1.1G   1% /run
tmpfs           529M  1.1M  528M   1% /run/lock
tmpfs           1.1G     0  1.1G   0% /sys/fs/cgroup
/dev/md127      6.0T   20M  6.0T   1% /data
/dev/md127      6.0T   20M  6.0T   1% /apps
/dev/md127      6.0T   20M  6.0T   1% /home

※以下、開発用ユーザでログイン。
※usemodの指定は指定後にログインしないと無効。
gccのビルドに必要なパッケージをインストール
libnss-mdnsもあった方がいいような気はしている。

$ sudo apt-get install build-essential
$ sudo apt-get install libssl-dev
$ wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-9.2.0/gcc-9.2.0.tar.gz
$ tar xvzf gcc-9.2.0.tar.gz
$ cd gcc-9.2.0

gccのビルドに必要なパッケージやモジュールをダウンロード

$ ./contrib/download_prerequisites
2019-11-26 21:42:37 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2019-11-26 21:42:40 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2019-11-26 21:42:43 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925] -> "./mpc-1.0.3.tar.gz" [1]
2019-11-26 21:42:47 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291] -> "./isl-0.18.tar.bz2" [1]
gmp-6.1.0.tar.bz2: OK
mpfr-3.1.4.tar.bz2: OK
mpc-1.0.3.tar.gz: OK
isl-0.18.tar.bz2: OK
All prerequisites downloaded successfully.

ビルド用のディレクトリを作成し、移動して設定
※32bitなので–disable-multilibで失敗しないハズなので指定しない。

$ mkdir build
$ cd build
$ ../configure --enable-languages=c,c++ --prefix=/usr/local/gcc-9.2.0 --disable-bootstrap

コンパイル

$ date; make; date
前回:Sat Nov  9 23:25:55 JST 2019 ~ Sun Nov 10 01:58:37 JST 2019
今回:Tue Nov 26 21:44:02 JST 2019 ~ Wed Nov 27 00:16:30 JST 2019

2時間かな。今回はNASが同期中だったので3時間かかっている。

$ date; sudo make install; date
前回:Sun Nov 10 05:39:48 JST 2019 ~ Sun Nov 10 05:41:12 JST 2019
今回:Wed Nov 27 00:31:58 JST 2019 ~ Wed Nov 27 00:33:21 JST 2019

確認してみると

$ gcc --version
gcc (Debian 4.9.2-10+deb8u2) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

古いgccが呼び出される

$ /usr/local/gcc-9.2.0/bin/gcc --version
gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

パスが通っていないので、viで ~/.bash_profile を作って
export PATH=/usr/local/gcc-9.2.0/bin:$PATH
を追加。再ログインして確認

$ gcc --version
gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

しかし、このままではincludeやlibや共通ライブラリィが古いバージョンのものを使いそうだ。どの辺にあるのかな?

$ sudo find / -name stdio.h -print
/home/****/gcc-9.2.0/fixincludes/tests/base/stdio.h
/home/****/gcc-9.2.0/fixincludes/tests/base/rtldef/stdio.h
/home/****/gcc-9.2.0/libstdc++-v3/include/tr1/stdio.h
/home/****/gcc-9.2.0/libstdc++-v3/include/c_compatibility/stdio.h
/home/****/gcc-9.2.0/libssp/ssp/stdio.h
/home/****/gcc-9.2.0/build/armv7l-unknown-linux-gnueabi/libstdc++-v3/include/tr1/stdio.h
/run/nfs4/home/****/gcc-9.2.0/fixincludes/tests/base/stdio.h
/run/nfs4/home/****/gcc-9.2.0/fixincludes/tests/base/rtldef/stdio.h
/run/nfs4/home/****/gcc-9.2.0/libstdc++-v3/include/tr1/stdio.h
/run/nfs4/home/****/gcc-9.2.0/libstdc++-v3/include/c_compatibility/stdio.h
/run/nfs4/home/****/gcc-9.2.0/libssp/ssp/stdio.h
/run/nfs4/home/****/gcc-9.2.0/build/armv7l-unknown-linux-gnueabi/libstdc++-v3/include/tr1/stdio.h
/data/home/****/gcc-9.2.0/fixincludes/tests/base/stdio.h
/data/home/****/gcc-9.2.0/fixincludes/tests/base/rtldef/stdio.h
/data/home/****/gcc-9.2.0/libstdc++-v3/include/tr1/stdio.h
/data/home/****/gcc-9.2.0/libstdc++-v3/include/c_compatibility/stdio.h
/data/home/****/gcc-9.2.0/libssp/ssp/stdio.h
/data/home/****/gcc-9.2.0/build/armv7l-unknown-linux-gnueabi/libstdc++-v3/include/tr1/stdio.h
/usr/include/c++/4.9/tr1/stdio.h
/usr/include/arm-linux-gnueabi/bits/stdio.h
/usr/include/stdio.h
/usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/include/ssp/stdio.h
/usr/local/gcc-9.2.0/include/c++/9.2.0/tr1/stdio.h

実際どうなんだろう。

$ gcc -v a.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-9.2.0/libexec/gcc/armv7l-unknown-linux-gnueabi/9.2.0/lto-wrapper
Target: armv7l-unknown-linux-gnueabi
Configured with: ../configure --enable-languages=c,c++ --prefix=/usr/local/gcc-9.2.0 --disable-bootstrap
Thread model: posix
gcc version 9.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-mcpu=arm10tdmi' '-mtls-dialect=gnu' '-marm' '-march=armv5t'
 /usr/local/gcc-9.2.0/libexec/gcc/armv7l-unknown-linux-gnueabi/9.2.0/cc1 -quiet -v -imultilib . -imultiarch arm-linux-gnueabi a.c -quiet -dumpbase a.c -mcpu=arm10tdmi -mtls-dialect=gnu -marm -march=armv5t -auxbase a -version -o /tmp/ccRJs92o.s
GNU C17 (GCC) version 9.2.0 (armv7l-unknown-linux-gnueabi)
        compiled by GNU C version 4.9.2, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/../../../../armv7l-unknown-linux-gnueabi/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/include
 /usr/local/include
 /usr/local/gcc-9.2.0/include
 /usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/include-fixed
 /usr/include/arm-linux-gnueabi
 /usr/include
End of search list.
GNU C17 (GCC) version 9.2.0 (armv7l-unknown-linux-gnueabi)
        compiled by GNU C version 4.9.2, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 20ffebffab78fa72e422119a97fa84c2
COLLECT_GCC_OPTIONS='-v' '-mcpu=arm10tdmi' '-mtls-dialect=gnu' '-marm' '-march=armv5t'
 as -v -march=armv5t -meabi=5 -o /tmp/ccmD4DyI.o /tmp/ccRJs92o.s
GNU assembler version 2.25 (arm-linux-gnueabi) using BFD version (GNU Binutils for Debian) 2.25
COMPILER_PATH=/usr/local/gcc-9.2.0/libexec/gcc/armv7l-unknown-linux-gnueabi/9.2.0/:/usr/local/gcc-9.2.0/libexec/gcc/armv7l-unknown-linux-gnueabi/9.2.0/:/usr/local/gcc-9.2.0/libexec/gcc/armv7l-unknown-linux-gnueabi/:/usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/:/usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/
LIBRARY_PATH=/usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/:/usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/../../../:/lib/arm-linux-gnueabi/:/lib/:/usr/lib/arm-linux-gnueabi/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mcpu=arm10tdmi' '-mtls-dialect=gnu' '-marm' '-march=armv5t'
 /usr/local/gcc-9.2.0/libexec/gcc/armv7l-unknown-linux-gnueabi/9.2.0/collect2 -plugin /usr/local/gcc-9.2.0/libexec/gcc/armv7l-unknown-linux-gnueabi/9.2.0/liblto_plugin.so -plugin-opt=/usr/local/gcc-9.2.0/libexec/gcc/armv7l-unknown-linux-gnueabi/9.2.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccpu0ZV5.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --eh-frame-hdr -dynamic-linker /lib/ld-linux.so.3 -X -m armelf_linux_eabi /usr/lib/arm-linux-gnueabi/crt1.o /usr/lib/arm-linux-gnueabi/crti.o /usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/crtbegin.o -L/usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0 -L/usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/../../.. -L/lib/arm-linux-gnueabi -L/usr/lib/arm-linux-gnueabi /tmp/ccmD4DyI.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/crtend.o /usr/lib/arm-linux-gnueabi/crtn.o
COLLECT_GCC_OPTIONS='-v' '-mcpu=arm10tdmi' '-mtls-dialect=gnu' '-marm' '-march=armv5t'

/usr/local/gcc-9.2.0/lib/gcc/armv7l-unknown-linux-gnueabi/9.2.0/includeに

aaa.hを作り、int aaa=123; と書いて、
#include <aaa.h>
printf(“aaa=%d\n”,aaa);
をコンパイルすれば通る。

但し、stdio.hはそこには無いので、/usr/includeのstdio.hが使われる。

ps.2019/11/28

sudo でgcc-9.2.0を使うために

/etc/sudoers を修正

Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
↓
Defaults	secure_path="/usr/local/gcc-9.2.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Node.jsの記事にもあるように
/etc/ld.so.conf.dにgcc-9.2.0用のファイルを作っておく。

# gcc-9.2.0 configuration
/usr/local/gcc-9.2.0/lib

そして
$ sudo ldconfig




コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA