トップ «前の日記(2011-11-04) 最新 次の日記(2011-11-06)» 編集

日々の破片

著作一覧

2011-11-05

_ Macでruby

そろそろ時期かなぁとOS X LionをAppStoreで買って、MBP17に入れた。OSXみたいに不安定なソフトウェアを販売するのにはAppStoreみたいなダウンロード販売は良い仕組みだな。もしこれがDVD販売だったら、せっかく時期をずらしたのに、結局はバギーでギャの嵐を呼んだ10.7.0を掴ませられることになっただろう。でもAppStoreが現在置いているのは10.7.2で普通に導入できた。

インストールが終わったので今度はXcodeをAppStoreで買った(無料)。AppStoreの表示がインストールに変わり、それが終了したので、ターミナルを開いて./configureするとCコンパイラが無いよというエラーになった。

はて、と不思議に思うわけだが、確かにls /usr/bin/ccとやると、そんなものは無いと言われる。

でいろいろ探し回って、ApplicationにXcodeのインストーラがいることに気付いた。そういう意味だったのか。というわけで起動してインストールする(と、いきなり画面がバカでかいアイコンが並んだ妙なものに変わってびびるのだが、後でそれはLaunchPadというものだとわかる)。 で、Xcodeのインストールが終わったので、あらためて./configure --prefix=/usr/localと打つとエラーになった。

$ ./configure --prefix=/usr/local
checking build system type... x86_64-apple-darwin11.2.0
checking host system type... x86_64-apple-darwin11.2.0
checking target system type... x86_64-apple-darwin11.2.0
checking whether the C compiler works... no
configure: error: in `/Users/arton/devl/ruby-1.9.3-p0':
configure: error: C compiler cannot create executables
See `config.log' for more details

なぜだ? と不思議になって、cat >hello.cとかしてハローワールドを作って、cc hello.c;./a.outでちゃんとコンパイル、リンク、実行できるのを確認して考え込む。

See config.logと書いてあることに気付いて読んでみると、

configure:3385: gcc-4.2 --version >&5
./configure: line 3387: gcc-4.2: command not found

と出力されていることに気付いた。

実はNEWSに

==== OS X Lion
  
* You have to configure ruby with '--with-gcc=gcc-4.2' if you're using
  Xcode 4.1, or, if you're using Xcode 4.2, you have to configure ruby
  with '--with-gcc=clang'.

と書いてあるのだが、そこを読まずにtwitterにごにょごにょ書いていたら、sora_hさんやknuさんに教えてもらえて、で、途中回り道したが、結局、./configure --prefix=/usr/local --with-gcc=clangとしてmakeに成功した。

続けてmake testも成功。でもなんとなくmake test-allしたらSEGVする。

.................../Users/arton/devl/ruby-1.9.3-p0/lib/net/imap.rb:1439: [BUG] Segmentation fault
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
 
-- Control frame information -----------------------------------------------
c:0034 p:---- s:0146 b:0146 l:000145 d:000145 CFUNC  :connect
c:0033 p:0198 s:0143 b:0143 l:000142 d:000142 METHOD /Users/arton/devl/ruby-1.9.3-p0/lib/net/imap.rb:1439

わからん。なぜconnect? と、make test-all TESTS=socket すると、これは通る。で、しょうがないので、

-- C level backtrace information -------------------------------------------
 
   See Crash Report log file under ~/Library/Logs/CrashReporter or
   /Library/Logs/CrashReporter, for the more detail of.

と出力されているのでクラッシュレポートを眺める。するとSnow Leopardかその前あたりに、OSXのOpenSSLのバージョンが古いんだかそもそも入っていないんだか忘れたが、自前で~/libに入れたlibcryptoと/usr/libのlibcryptoが競合していることに気付いた。

+libcrypto.0.9.8.dylib (0.9.8 - compatibility 0.9.8)  /Users/USER/*/libcrypto.0.9.8.dylib
libcrypto.0.9.8.dylib (44.0.0 - compatibility 0.9.8) <3A8E1F89-5E26-3C8B-B538-81F5D61DBF8A> /usr/lib/libcrypto.0.9.8.dylib

なんかまだありそうな気がする(しかし、~/libの下には他にもいろいろ入っているので思い切って全部消すのはためらわれるのでピンポイント削除作戦で行くことにする)ので、クラッシュレポートが報告するライブラリをソートして表示するフィルタを作る。

# coding: utf-8
 
class DupChecker
  def collect(fin)
    lines = []
    fin.each_line do |line|
      break if line =~ /\AExternal Modification/
      if line =~ /0x[0-9a-f]+\s+-\s+0x[0-9a-f]+\s+(\+?([^)]+\)).+)\Z/
        lines << [$2, $1]
      end
    end
    lines.sort do |x, y|
      x[0] <=> y[0]
    end.each do |line|
      puts line[1]
    end
  end
  
  def check_dup(fin)
    File.open(fin) do |f|
      f.each_line do |line|
        if line =~ /\ABinary Images:/
          collect f
          break
        end
      end
    end
  end
end
 
if $0 == __FILE__
  if ARGV.size == 0
    $stderr.puts 'usage: ruby duplib.rb crush-files'
    exit 1
  end
  d = DupChecker.new
  ARGV.each do |fin|
    d.check_dup fin
  end
end

で、~/libのやつを消して、無事net/imapは通った。が、その後もまだSEGVするのであった(で、上のスクリプトでクラッシュダンプを調べたらzlibの重複があったので、それも解消させた)。

が、まだSEGVする。←今ここ

何しろ、これまでの経緯からはRubyのバグではなくて、こちらの環境固有の問題の可能性が高すぎるのだが、さてどうしたものか。

TestCSV::Interface#test_write_lineno = 0.00 s = .
/Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:780: [BUG] cfp consistency error - send
ruby 1.9.3p0 (2011-10-30) [x86_64-darwin11.2.0]
 
-- Control frame information -----------------------------------------------
c:0019 p:---- s:0075 b:0075 l:000074 d:000074 CFUNC  :map
c:0018 p:0124 s:0072 b:0072 l:000071 d:000071 METHOD /Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:780
c:0017 p:0020 s:0064 b:0063 l:001340 d:000062 BLOCK  /Users/arton/devl/ruby-1.9.3-p0/lib/test/unit.rb:565
c:0016 p:---- s:0059 b:0059 l:000058 d:000058 FINISH
(省略)
-- Ruby level backtrace information ----------------------------------------
./test/runner.rb:15:in `
' /Users/arton/devl/ruby-1.9.3-p0/lib/test/unit.rb:634:in `run' /Users/arton/devl/ruby-1.9.3-p0/lib/test/unit.rb:630:in `run' /Users/arton/devl/ruby-1.9.3-p0/lib/test/unit.rb:21:in `run' /Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:884:in `run' /Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:895:in `_run' /Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:895:in `each' /Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:896:in `block in _run' /Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:909:in `run_tests' /Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:746:in `_run_anything' /Users/arton/devl/ruby-1.9.3-p0/lib/test/unit.rb:563:in `_run_suites' /Users/arton/devl/ruby-1.9.3-p0/lib/test/unit.rb:563:in `each' /Users/arton/devl/ruby-1.9.3-p0/lib/test/unit.rb:565:in `block in _run_suites' /Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:780:in `_run_suite' /Users/arton/devl/ruby-1.9.3-p0/lib/minitest/unit.rb:780:in `map'
(CrushReport)
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib              0x00007fff8e600ce2 __pthread_kill + 10
1   libsystem_c.dylib                   0x00007fff8cc657d2 pthread_kill + 95
2   libsystem_c.dylib                   0x00007fff8cc56a7a abort + 143
3   ruby                                0x000000010abb5088 rb_bug + 184
4   ruby                                0x000000010acc0850 vm_call_method + 2576
5   ruby                                0x000000010acb0f5e vm_exec_core + 9326
6   ruby                                0x000000010acba614 vm_exec + 100
7   ruby                                0x000000010acb7909 rb_yield + 105
8   ruby                                0x000000010ab8c1dd rb_ary_each + 45
本日のツッコミ(全5件) [ツッコミを入れる]
_ naruse (2011-11-05 16:19)

たぶんLLVM/clangのバグですね。-O0でビルドするか、Ruby側のどこかにvolatile入れるか、clang側を直すかが必要だと思います

_ arton (2011-11-06 11:54)

うーん、確かに僕の環境固有の問題じゃなさそうです(開発環境クリーンなOSXでも試してみた)。最小再現コードを作るのも難しい(たとえばtest-all TEST=j2とかだと再現しない)mapである回数以上くるくるさせないと発生しない)ってどういう仕組みなんだろうなぁ。

_ naruse (2011-11-06 20:13)

trunkでは動きますか?いくつか1.9.3の後で試行錯誤的なコミットがあったと思うんですが

_ arton (2011-11-06 21:16)

試してみました。結果は0F0E46Sで問題ないですね。というわけで、その試行錯誤コミットの何かをバックポートする必要が(多分)あるのだと思います。「多分」なのは、なぜ、僕のところでしか出てないかわからないから(OSXのRVM用のバイナリとか作っている人はtest-allしてないのかなぁ)。

_ arton (2011-11-06 21:17)

というわけで、私のOSX用Rubyは早くも2.0になってしまったのであった。


2003|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|

ジェズイットを見習え