Bug #9928

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

Added by Rei Odaira 10 months ago. Updated 10 months ago.

[ruby-core:63080]
Status:Open
Priority:Normal
Assignee:Yutaka Kanemoto
ruby -v:ruby 2.2.0dev (2014-06-02 trunk 45270) [powerpc-aix7.1.0.0] Backport:2.0.0: UNKNOWN, 2.1: UNKNOWN

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']

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


Related issues

Related to Ruby trunk - Bug #10384: Fiddle::DLError: unknown symbol "Init_objspace" during Fiddle::TestHandle#test_NEXT and Fiddle::TestHandle#test_static_sym on Solaris Closed 10/14/2014

History

#1 Updated by Nobuyoshi Nakada 10 months 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?

#2 Updated by Rei Odaira 10 months 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.

#3 Updated by Nobuyoshi Nakada 10 months ago

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

#4 Updated by Hiroshi SHIBATA 3 months 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

Also available in: Atom PDF