Bug #1977

test failed in test_isdigit in test/dl/test_func.rb on sparc-solaris-2.10 (64bit)

Added by ngoto (Naohisa Goto) almost 3 years ago. Updated about 1 year ago.

[ruby-dev:39152]
Status:Closed Start date:08/21/2009
Priority:Normal Due date:
Assignee:tenderlovemaking (Aaron Patterson) % Done:

0%

Category:ext
Target version:2.0.0
ruby -v:ruby 1.9.2dev (2009-08-19) [sparc-solaris2.10]

Description

sparc-solaris-2.10 にて64ビットコンパイルした場合、Bug #1967
([ruby-dev:39146])のパッチを適用した後では、以下の2つのdl関連
のテストが失敗(Failure)します。

  1) Failure:
test_isdigit(DL::TestFunc) [/XXX/test/dl/test_func.rb:21]:
Failed assertion, no message given.

  2) Failure:
test_isdigit(DL::TestImport) [/XXX/test/dl/test_import.rb:126]:
Failed assertion, no message given.

Solaris付属のシステムコール追跡コマンドtrussを使って、
$ truss -t '!all' -u 'libc:isdigit' /XXX/trunk-24578/bin/testrb test/dl -v
のような感じで、isdigit関数の呼び出しを追跡したところ、

(前略)
DL::TestFunc#test_isdigit: /1@1:        -> libc:isdigit(0x3100000000, 0xc, 0xffffffffffffffff, 0xfffffffffffffff8)
/1@1:   <- libc:isdigit() = 0
/1@1:   -> libc:isdigit(0x3200000000, 0xc, 0xffffffffffffffff, 0xfffffffffffffff8)
/1@1:   <- libc:isdigit() = 0
/1@1:   -> libc:isdigit(0x7200000000, 0xc, 0xffffffffffffffff, 0xfffffffffffffff8)
/1@1:   <- libc:isdigit() = 0
0.01 s: F
(中略)
DL::TestImport#test_isdigit: /1@1:      -> libc:isdigit(0x3100000000, 0xc, 0xffffffffffffffff, 0xfffffffffffffff8)
/1@1:   <- libc:isdigit() = 0
/1@1:   -> libc:isdigit(0x3200000000, 0xc, 0xffffffffffffffff, 0xfffffffffffffff8)
/1@1:   <- libc:isdigit() = 0
/1@1:   -> libc:isdigit(0x7200000000, 0xc, 0xffffffffffffffff, 0xfffffffffffffff8)
/1@1:   <- libc:isdigit() = 0
0.00 s: F
(後略)

1番目の引数は、本来 0x31, 0x32, 0x72 といった数であるべきところが、
0x3100000000, 0x3200000000, 0x7200000000 になってしまっています。

どうやら、sparc 環境では、引数のint は long に符号拡張されるようです。
(参考文献: http://sdc.sun.co.jp/solaris/tools/private/amd64_migration.html )

標準関数 int putchar(char) にて確認したところ、char も同様に long
に拡張されるので、short もおそらく同様だと思います。
float が double に拡張されるかどうかは確認できていません。
また、sparc上のLinuxなど、Solaris以外ではどうなのかは未確認です。

sparcの場合だけ特別な PACK_MAP と SIZE_MAP を持つようにしたパッチを
以下に添付します。このパッチを当てると dl のテストはすべて成功します。
(注:差分を小さくするためインデントが少々おかしくなっています。)

Index: ext/dl/lib/dl/stack.rb
===================================================================
--- ext/dl/lib/dl/stack.rb	(revision 24578)
+++ ext/dl/lib/dl/stack.rb	(working copy)
@@ -61,6 +61,36 @@
       TYPE_DOUBLE => ALIGN_DOUBLE,
     }

+    case RUBY_PLATFORM
+
+    when /sparc/i
+      PACK_MAP = {
+        TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG)? "q" : "l!"),
+        TYPE_CHAR  => "l!",
+        TYPE_SHORT => "l!",
+        TYPE_INT   => "l!",
+        TYPE_LONG  => "l!",
+        TYPE_FLOAT => "f",
+        TYPE_DOUBLE => "d",
+      }
+
+      SIZE_MAP = {
+        TYPE_VOIDP => SIZEOF_VOIDP,
+        TYPE_CHAR  => SIZEOF_LONG,
+        TYPE_SHORT => SIZEOF_LONG,
+        TYPE_INT   => SIZEOF_LONG,
+        TYPE_LONG  => SIZEOF_LONG,
+        TYPE_FLOAT => SIZEOF_FLOAT,
+        TYPE_DOUBLE => SIZEOF_DOUBLE,
+      }
+      if defined?(TYPE_LONG_LONG)
+        ALIGN_MAP[TYPE_LONG_LONG] = ALIGN_LONG_LONG
+        PACK_MAP[TYPE_LONG_LONG] = "q"
+        SIZE_MAP[TYPE_LONG_LONG] = SIZEOF_LONG_LONG
+      end
+
+    else
+
     PACK_MAP = {
       TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG)? "q" : "l!"),
       TYPE_CHAR  => "c",
@@ -86,6 +116,8 @@
       SIZE_MAP[TYPE_LONG_LONG] = SIZEOF_LONG_LONG
     end

+    end
+
     def parse_types(types)
       @types = types
       @template = ""

Related issues

related to ruby-trunk - Bug #1967: Segmentation fault at test_qsort1 and test_qsort2 in test... Rejected 08/20/2009

History

Updated by yugui (Yuki Sonoda) over 2 years ago

  • Category set to ext
  • Target version set to 2.0.0

Updated by tenderlovemaking (Aaron Patterson) over 2 years ago

  • Assignee set to tenderlovemaking (Aaron Patterson)

Updated by tenderlovemaking (Aaron Patterson) over 2 years ago

  • Status changed from Open to Closed
libffi で DL を変換しましたので、もうこの問題はない筈です。しかし、私の手元に sparc-solaris のコンピューターがないので、sparc-solaris でテストは出来ませんでした。

Updated by ngoto (Naohisa Goto) over 2 years ago

On Wed, 3 Feb 2010 10:51:32 +0900
Aaron Patterson <redmine@ruby-lang.org> wrote:

> libffi で DL を変換しましたので、もうこの問題はない筈です。しかし、私の手元に sparc-solaris のコンピューターがないので、sparc-solaris でテストは出来ませんでした。

libffi-3.0.9.tar.gz をダウンロードし、makeしようとしたのですが、
libffi が gcc 独自拡張の __attribute__ を使っているためか、
Sun Workshop 5.8 (SunStudio 11) の cc ではコンパイルできませんでした。

DLをlibffi依存にしたということは、RubyもGCCを要求することになるのでしょうか?

以下、libffiのmake時のエラーです。
"./include/ffi_common.h", line 103: syntax error before or at: __attribute__
"./include/ffi_common.h", line 103: warning: old-style declaration or incorrect type for: __attribute__
"./include/ffi_common.h", line 103: warning: syntax error:  empty declaration
"./include/ffi_common.h", line 104: syntax error before or at: __attribute__
"./include/ffi_common.h", line 104: warning: old-style declaration or incorrect type for: __attribute__
"./include/ffi_common.h", line 104: identifier redefined: __attribute__
        current : function() returning int
        previous: function() returning int : "./include/ffi_common.h", line 103
"./include/ffi_common.h", line 104: warning: syntax error:  empty declaration
"./include/ffi_common.h", line 105: syntax error before or at: __attribute__
"./include/ffi_common.h", line 105: warning: old-style declaration or incorrect type for: __attribute__
"./include/ffi_common.h", line 105: identifier redefined: __attribute__
        current : function() returning int
        previous: function() returning int : "./include/ffi_common.h", line 104
"./include/ffi_common.h", line 105: warning: syntax error:  empty declaration
"./include/ffi_common.h", line 106: syntax error before or at: __attribute__
"./include/ffi_common.h", line 106: warning: old-style declaration or incorrect type for: __attribute__
"./include/ffi_common.h", line 106: identifier redefined: __attribute__
        current : function() returning int
        previous: function() returning int : "./include/ffi_common.h", line 105
"./include/ffi_common.h", line 106: warning: syntax error:  empty declaration
"./include/ffi_common.h", line 107: syntax error before or at: __attribute__
"./include/ffi_common.h", line 107: warning: old-style declaration or incorrect type for: __attribute__
"./include/ffi_common.h", line 107: identifier redefined: __attribute__
        current : function() returning int
        previous: function() returning int : "./include/ffi_common.h", line 106
"./include/ffi_common.h", line 107: warning: syntax error:  empty declaration
"./include/ffi_common.h", line 108: syntax error before or at: __attribute__
"./include/ffi_common.h", line 108: warning: old-style declaration or incorrect type for: __attribute__
"./include/ffi_common.h", line 108: identifier redefined: __attribute__
        current : function() returning int
        previous: function() returning int : "./include/ffi_common.h", line 107
"./include/ffi_common.h", line 108: warning: syntax error:  empty declaration
"./include/ffi_common.h", line 109: syntax error before or at: __attribute__
"./include/ffi_common.h", line 109: warning: old-style declaration or incorrect type for: __attribute__
"./include/ffi_common.h", line 109: identifier redefined: __attribute__
        current : function() returning int
        previous: function() returning int : "./include/ffi_common.h", line 108
"./include/ffi_common.h", line 109: warning: syntax error:  empty declaration
"./include/ffi_common.h", line 110: syntax error before or at: __attribute__
"./include/ffi_common.h", line 110: warning: old-style declaration or incorrect type for: __attribute__
"./include/ffi_common.h", line 110: identifier redefined: __attribute__
        current : function() returning int
        previous: function() returning int : "./include/ffi_common.h", line 109
"./include/ffi_common.h", line 110: warning: syntax error:  empty declaration
cc: acomp failed for src/debug.c


-- 
後藤 直久  ngoto@gen-info.osaka-u.ac.jp

Updated by naruse (Yui NARUSE) over 2 years ago

成瀬です。

2010/2/3 Naohisa GOTO <ngoto@gen-info.osaka-u.ac.jp>:
> On Wed, 3 Feb 2010 10:51:32 +0900
> Aaron Patterson <redmine@ruby-lang.org> wrote:
>
>> libffi で DL を変換しましたので、もうこの問題はない筈です。しかし、私の手元に sparc-solaris のコンピューターがないので、sparc-solaris でテストは出来ませんでした。
>
> libffi-3.0.9.tar.gz をダウンロードし、makeしようとしたのですが、
> libffi が gcc 独自拡張の __attribute__ を使っているためか、
> Sun Workshop 5.8 (SunStudio 11) の cc ではコンパイルできませんでした。
>
> DLをlibffi依存にしたということは、RubyもGCCを要求することになるのでしょうか?

テストありがとうございます。

仰る通り、Sun Studio 11 ではダメなのですが、Sun Studio 12 では libffi をコンパイル可能なようです。
http://sourceware.org/ml/libffi-discuss/2010/msg00016.html
http://jp.sun.com/products/software/tools/studio12/documentation/ss12/whatsnew.html

また、Python 方面によると、頑張れば 11 でも __attribute__ の問題は回避できるようです。
http://inside.ascade.co.jp/node/54

以上で現実問題として解決可能なのかはわたしには判断つきかねますが。。

-- 
NARUSE, Yui
naruse@airemix.jp

Also available in: Atom PDF