2009年12月13日

2009年12月13日:MSYS と CLAPACK

 Cocoa 使いが wxWidgets を使ってみる (3) で書いた CLAPACK のビルド。ある事情でもう一度やってみたところ、コンパイルはうまくいったがテストで失敗するではないか。前は、コンパイルだけやってテストはすっぽかしていたらしい。これはよくない、と調査にかかったが、こいつが難航した。MSYS のコンソールから実行すると、「予期せず終了しました」ダイアログが出る。gdb で調べてみると、_do_global_dtors 中の probe という関数で SIGSEGV で死んでいる。dtors って何よ、C++ なんか使ってないぜ? と思ったのだが、ネット検索してみるとこんな記事が見つかった。

Re: [uClinux-dev] do_global_dtors problem
From: David McCullough
Date: Sun Nov 04 2001 - 17:37:38 EST
(中略)
> Has anyone else seen this behavior? Isn't do_global_dtors
> a c++ function? Any enlightenment on the constructor/
> destructor functions would be appreciated.

It is unlikely that the problem is with do_global_dtors. What happens is in the later version of gcc (ie 2.95) main calls __main which processes do_global_[cd]tors lists. So you get them with 'C' as well. Actually, I think that atexit is processed this way, but I may be wrong.

The fact that the program has run to completion and then crashed would make me look at the stack size and see if it could be overflowing into the top of the BSS/data sections.

 ひぇー、スタックサイズ。そんな落とし穴があったんか。ちなみに、MinGW でのデフォルトスタックサイズは 2MB らしい。FORTRAN プログラムを f2c でコンバートしているので、自動変数 2MB ぐらいなら平気で使ってそうだ(確認してないけど)。そこで、make.inc に

LOADOPTS = -Wl,--stack=33554432

という1行を加えてみたら、見事にテスト通過。いやはや、これだから FORTRAN は。(というか f2c を使うというのがそもそも筋悪という話も。)

Posted at 2009年12月13日 01:06:48
email.png