Project

General

Profile

Actions

Bug #9928

closed

Fiddle::TestHandle#test_NEXT fails on AIX due to unexported symbols of extension libraries

Added by ReiOdaira (Rei Odaira) over 10 years ago. Updated over 5 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.2.0dev (2014-06-02 trunk 45270) [powerpc-aix7.1.0.0]
[ruby-core:63080]

Description

Fiddle::TestHandle#test_NEXT fails on AIX.

[ 4/21] Fiddle::TestHandle#test_NEXT = 0.00 s                         
  1) Error:
Fiddle::TestHandle#test_NEXT:
Fiddle::DLError: unknown symbol "Init_objspace"
    /ss/home/rayod/Dev/Contribution/ruby-trunk-blue1/test/fiddle/test_handle.rb:171:in `[]'
    /ss/home/rayod/Dev/Contribution/ruby-trunk-blue1/test/fiddle/test_handle.rb:171:in `rescue in test_NEXT'
    /ss/home/rayod/Dev/Contribution/ruby-trunk-blue1/test/fiddle/test_handle.rb:144:in `test_NEXT'

The reason for this is a little bit complicated. Fiddle::TestHandle#test_NEXT tests the behavior of RTLD_NEXT for dlsym(3). According to the manual, RTLD_NEXT of AIX should behave like that of BSD, so the following part in Fiddle::TestHandle#test_NEXT should succeed, but in fact it fails.

          # BSD
          #
<snip>
          require 'objspace'
          handle = Handle::NEXT
          refute_nil handle['Init_objspace']

The problem is that on AIX, Ruby's extension libraries do not export their symbols, because they are loaded not by dlopen(3)/dlsym(3) but by load(3). The build process on AIX only specifies Init_* functions as the entry points of the extension shared libraries. This means Init_objspace cannot be the search target of RTLD_NEXT, and the test above results in nil. (FYI, the symbols in the modules loaded by load(3) can be found by RTLD_NEXT if they are exported.)

One way to solve this is to somehow export the Init_objspace function. However, specifying -Wl,-bexpall does not export the entry points, so we need to specify -Wl,-bexpfull, which looks like overkill for just passing this test.

Fortunately, on AIX, test/fiddle/helper.rb creates and loads a dummy shared library, libaixdltest.so, which contains and exports strcpy and some other functions, so we can take advantage of it for testing RTLD_NEXT. That is, we can simply query strcpy to check whether or not RTLD_NEXT works correctly, as follows. The patch is attached.

          handle = Handle::NEXT
          refute_nil handle['strcpy']

Files

test_NEXT_for_aix.patch (2.96 KB) test_NEXT_for_aix.patch ReiOdaira (Rei Odaira), 06/10/2014 08:00 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #10384: Fiddle::DLError: unknown symbol "Init_objspace" during Fiddle::TestHandle#test_NEXT and Fiddle::TestHandle#test_static_sym on SolarisClosedActions

Updated by nobu (Nobuyoshi Nakada) over 10 years ago

Rei Odaira wrote:

The reason for this is a little bit complicated. Fiddle::TestHandle#test_NEXT tests the behavior of RTLD_NEXT for dlsym(3). According to the manual, RTLD_NEXT of AIX should behave like that of BSD, so the following part in Fiddle::TestHandle#test_NEXT should succeed, but in fact it fails.

Does AIX support dlopen() now?

The problem is that on AIX, Ruby's extension libraries do not export their symbols, because they are loaded not by dlopen(3)/dlsym(3) but by load(3). The build process on AIX only specifies Init_* functions as the entry points of the extension shared libraries. This means Init_objspace cannot be the search target of RTLD_NEXT, and the test above results in nil. (FYI, the symbols in the modules loaded by load(3) can be found by RTLD_NEXT if they are exported.)

Will it solve if dlopen()/dlsym() is used instead?

One way to solve this is to somehow export the Init_objspace function. However, specifying -Wl,-bexpall does not export the entry points, so we need to specify -Wl,-bexpfull, which looks like overkill for just passing this test.

Or by using -bE option?

Updated by ReiOdaira (Rei Odaira) over 10 years ago

Yes, AIX supports dlopen(). According to the discussion at [Bug #1914], only relatively old versions of AIX did not support dlopen(). The problem I reported will be solved if dlopen()/dlsym() is used on AIX too, because it will mean exporting the Init_* functions, but I am not sure if such a change is worth making.

I forgot to mention the -bE option. Yes, we can also use -bE, but generating export files will complicate the build process a bit, and again, I am not sure if it is worthwhile doing so only for passing this test.

Updated by nobu (Nobuyoshi Nakada) over 10 years ago

Export files are used on Windows already, so it would not be a trouble.

Updated by hsbt (Hiroshi SHIBATA) almost 10 years ago

  • Related to Bug #10384: Fiddle::DLError: unknown symbol "Init_objspace" during Fiddle::TestHandle#test_NEXT and Fiddle::TestHandle#test_static_sym on Solaris added
Actions #5

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0