0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Gcc 8.5.0をつかって,Gcc 4.8.5をビルドする(Rockylinux)

Posted at

背景

古いOpenFOAMをIntelコンパイラでビルドできますが,いきなり計算が落ちる場合があって困ってました。
Gcc 4.8くらいを使ってOpenFOAMビルドしたいなとおもってやってみた記録です。

OpenFOAM 2.3.xの最終版とThirdParty 2.3.1を使います。ThirdParty 2.3.1内にあるmakeGcc48を多少変更します。

下記のメモはOpenFOAMとか関係なしにGccをビルドするときもほぼ同様の対応することになると思うので,OpenFOAMなんて知らないひとにも参考になるかと思います。

環境

  • Rockylinux 8.5
  • システムのGccは8.5.0

はじめに

gmp 5.1.2
mpfr 3.1.2
mpc 1.0.1
をいれておきます。これはホームのなかにusr/localとか作っていれて,パス設定もしておきます。

Gccビルドのconfigure

  • 新しいGccで古いGccをビルドする
  • もとからあるOpenFOAMのmakeGcc48のconfigureの内容

の兼ね合いで以下のようにします。prefix,with-gmp, with-mpfr, with-mpcの設定は省略してあるので,自分の環境に合わせて下さい。--disable-multilibと--disable-stage1-checkingを追加してます。

    --enable-languages=c,c++ \
    --enable-__cxa_atexit \
    --enable-libstdcxx-allocator=new \
    --with-system-zlib \
    --disable-multilib \
    --disable-stage1-checking \

makeのオプション

 make  STAGE1_CFLAGS="-O2 -g -std=gnu89" STAGE1_CXXFLAGS="-O2 -g -std=gnu++98"

でmakeします。
参考 https://gcc.gnu.org/legacy-ml/gcc-help/2018-09/msg00109.html

perlの処理で落ちる

makeしていると何回かとまるので,Gccのソースを修正します。

メモがなくて,申し訳ないですが,makeの途中でperlの文字列処理が原因でビルドが落ちる部分があります。

perlが{}をそのまま処理できないのが原因です。gccのソースファイルに{, }が含まれる部分があるので,バックスラッシュをつけます。{, }みたいなかんじ。

ucontextがどうだこうだ

https://gcc.gnu.org/legacy-ml/gcc-help/2018-09/msg00110.html
ここにありますが,

md-unwind-support.h:65:47: error: dereferencing pointer to incomplete type
sc = (struct sigcontext *) (void *) &uc_->uc_mcontext;

が出ます。

https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=883312dc79806f513275b72502231c751c14ff72
https://stackoverflow.com/questions/46999900/how-to-compile-gcc-6-4-0-with-gcc-7-2-in-archlinux
ここを参考にして,libgcc/config/i386/linux-unwind.h等の
struct ucontext uc;を
ucontext_t uc;
に修正。

@tex should only appear at a line beginningとかいうWarning

Warningですが,ビルドが落ちます。gcc.texiを修正。

https://osmocom.org/issues/1916
ここにあるpatchを参考にします。@texなんちゃらが1行だと困るみたいです。

--- ./gcc/doc/gcc.texi.orig	
+++ ./gcc/doc/gcc.texi	
@@ -86,9 +86,15 @@
 @item GNU Press
 @tab Website: www.gnupress.org
 @item a division of the
-@tab General: @tex press@@gnu.org @end tex
+@tab General: 
+@tex 
+press@@gnu.org 
+@end tex
 @item Free Software Foundation
-@tab Orders:  @tex sales@@gnu.org @end tex
+@tab Orders:  
+@tex 
+sales@@gnu.org 
+@end tex

SGSEGV was not declared

libsanitizer/asan/asan_linux.cc:222:20: error: 'SIGSEGV' was not declared in this scope
return signum == SIGSEGV && common_flags()->handle_segv;

これはhttps://patchwork.ozlabs.org/project/gcc/patch/6824253.3U2boEivI2@devpool21/
を参考にして,
libsanitizer/asan/asan_linux.cc
に#include を追加。

libsanitizer/tsan/tsan_platform_linux.ccの修正

エラーがどうだったか情報がないんですが,
libsanitizer/tsan/tsan_platform_linux.ccを修正。

--- old libsanitizer/tsan/tsan_platform_linux.cc 
+++ new libsanitizer/tsan/tsan_platform_linux.cc 
@@ -291,7 +291,7 @@
 int ExtractResolvFDs(void *state, int *fds, int nfd) {
 #if SANITIZER_LINUX
   int cnt = 0;
-  __res_state *statp = (__res_state*)state;
+  struct __res_state *statp = (struct __res_state*)state;
   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
       fds[cnt++] = statp->_u._ext.nssocks[i];

参考 https://stackoverflow.com/questions/46999900/how-to-compile-gcc-6-4-0-with-gcc-7-2-in-archlinux

ThirdPartyにあるmakeGcc48でやると,途中でビルドが止まる

上記の修正をしたあとでも一回止まります。build/linux64/gcc-4.8.5内で直接makeを実行するとビルドが最後まで行きます。

make installまで終わらせたgccでOpenFOAMビルドすると,うまくいきます。
これで本当に問題ないかはまだ検証してません。

結論

あたらしいGccで古いGccをビルドするのはかなりしんどいです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?