macOS Mojaveでx10言語で書かれたコードがコンパイルできなくなったのでトラブルシュートの記録を残しておく
環境
- macOS mojave 10.14.1
- Apple LLVM version 10.0.0 (clang-1000.11.45.5)
- x10 2.6.1
- native版 (c++にコンパイルするタイプのもの)
経緯
x10で書かれたコードをx10c++コマンドでビルドしようとしたところ以下のようなエラーが出てコンパイルできなくなった。
x10は公式のダウンロードページからダウンロードしたもの。
http://x10-lang.org/releases/x10-release-261.html
$ x10c++ -d build Main.x10 -VERBOSE_CHECKS
x10c++: clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from caravan/Main.cc:3:
In file included from ~/work/caravan/caravan_scheduler/build/caravan/Main.h:4:
In file included from ~/work/x10-2.6.1_macosx_x86/stdlib/include/x10rt.h:6:
/Users/murase/work/x10-2.6.1_macosx_x86/stdlib/include/x10aux/config.h:89:12: fatal error: 'iostream' file not found
# include <iostream>
^~~~~~~~~~
1 warning and 1 error generated.
<以下、同じエラーが続く>
エラーを見てもよくわからないが、おそらくx10cからc++に変換したあと、c++をコンパイルしようとしているところでエラーが起きている模様。
clangに渡すコンパイラオプションが正しくないのかもしれない。
試行錯誤
この問題を解決するためにx10のソースからビルドしてみる。
$ git clone https://github.com/x10-lang/x10.git
$ cd x10
$ git checkout -b SF_RELEASE_2_6_1 refs/tags/SF_RELEASE_2_6_1
$ cd x10.dist
$ ant -Doptimize=true -DNO_CHECKS=true -Davailable.procs=8 dist
これでx10c, x10c++が新規にビルドされた。
ここで作成されたx10コンパイラを使って、x10アプリをコンパイルすると先ほどのエラーはでなくなり、無事にコンパイルが通る様になった。
しかし、ビルドされたアプリを実行するとsegmentation faultが起きてしまう。
$ ./a.out
segmentation fault
LLDBででバッグしてみたところどうやら、GCが悪さをしているらしいことが判明。
$ lldb ./a.out
(lldb) target create "./a.out"
Current executable set to './a.out' (x86_64).
(lldb) run
Process 71498 launched: './a.out' (x86_64)
Process 71498 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x7ffeefc00000)
frame #0: 0x0000000100518695 libx10.so`GC_push_all_eager + 133
libx10.so`GC_push_all_eager:
-> 0x100518695 <+133>: movq (%rax), %rax
0x100518698 <+136>: movq %rax, -0x30(%rbp)
0x10051869c <+140>: movq -0x30(%rbp), %rax
0x1005186a0 <+144>: movq -0x48(%rbp), %rcx
Target 0: (scheduler) stopped.
そこで、GCをオフにしてx10cを再ビルドすることにした。
$ ant -Doptimize=true -DNO_CHECKS=true -Davailable.procs=8 -DDISABLE_GC=true dist
このx10コンパイラでビルドした結果、ようやくsegmentation faultが起きずに実行できる様になった。
ただし、これは緊急回避的な処理で本質的な問題解決ではない。当然GCが行われないので、長時間走らせるジョブではメモリーが溢れる可能性が高い。
これを解決する方法は今の所不明。