Skip to content

test_dlopen_linker_script_input_linux is failed with ArchLinux #166

Closed

Description

@hsbt

After merging ruby/ruby@b5ed7aa, Ruby CI is failed at ArchLinux.

http://rubyci.s3.amazonaws.com/arch/ruby-master/log/20241211T030006Z.fail.html.gz

TestFiddle#test_dlopen_linker_script_input_linux:
Fiddle::DLError: -lncursesw: cannot open shared object file: No such file or directory
[hsbt@arch ~]$ cat /usr/lib/libncurses.so
INPUT(-lncursesw)
[hsbt@arch ~]$ ls -lA /usr/lib/libncurses*
-rw-r--r-- 1 root root     20 May 25  2024 /usr/lib/libncurses++.so
-rw-r--r-- 1 root root     18 May 25  2024 /usr/lib/libncurses.so
-rw-r--r-- 1 root root   8448 May 25  2024 /usr/lib/libncurses++w_g.a
-rw-r--r-- 1 root root 185526 May 25  2024 /usr/lib/libncursesw_g.a
lrwxrwxrwx 1 root root     18 May 25  2024 /usr/lib/libncurses++w.so -> libncurses++w.so.6
lrwxrwxrwx 1 root root     16 May 25  2024 /usr/lib/libncursesw.so -> libncursesw.so.6
lrwxrwxrwx 1 root root     20 May 25  2024 /usr/lib/libncurses++w.so.6 -> libncurses++w.so.6.5
lrwxrwxrwx 1 root root     18 May 25  2024 /usr/lib/libncursesw.so.6 -> libncursesw.so.6.5
-rwxr-xr-x 1 root root  75840 May 25  2024 /usr/lib/libncurses++w.so.6.5
-rwxr-xr-x 1 root root 453896 May 25  2024 /usr/lib/libncursesw.so.6.5
[hsbt@arch ~]$ ls -lA /usr/
total 124
drwxr-xr-x   6 root root 36864 Dec 11 03:02 bin
drwxr-xr-x 126 root root 16384 Dec 11 03:02 include
drwxr-xr-x  78 root root 45056 Dec 11 03:44 lib
drwxr-xr-x   5 root root  4096 Dec 11 02:05 lib32
lrwxrwxrwx   1 root root     3 Nov 21 08:56 lib64 -> lib
drwxr-xr-x   6 root root  4096 Dec 11 02:05 libx32
drwxr-xr-x  11 root root  4096 Jun  3  2021 local
lrwxrwxrwx   1 root root     3 Nov 21 08:56 sbin -> bin
drwxr-xr-x  84 root root  4096 Dec 11 02:05 share
drwxr-xr-x   3 root root  4096 Dec 11 02:05 src

I'm not sure why Arch Linux couldn't open libncursesw.so in that case.

Activity

  1. hsbt commented on Dec 11, 2024

    @hsbt
    MemberAuthor

    I manually update libncurses.so to INPUT(libncursesw.so). Fiddle.dlopen works fine.

    But TestFiddle#test_dlopen_linker_script_input_linux is failing with:

    TestFiddle#test_dlopen_linker_script_input_linux [/home/hsbt/dev/ruby/test/fiddle/test_fiddle.rb:42]:
    <"libncurses.so"> expected but was
    <"libncursesw">.
    

    Should I update that test case for inconsistency case like ArchLinux?

  2. kou commented on Dec 11, 2024

    @kou
    Member

    Oh, does this work?

    diff --git a/lib/fiddle.rb b/lib/fiddle.rb
    index 6718b01..4723d70 100644
    --- a/lib/fiddle.rb
    +++ b/lib/fiddle.rb
    @@ -111,7 +111,11 @@ module Fiddle
               case line
               when /\A\s*(?:INPUT|GROUP)\s*\(\s*([^\s,\)]+)/
                 # TODO: Should we support multiple files?
    -            return dlopen($1)
    +            first_input = $1
    +            if first_input.start_with?("-l")
    +              first_input = "lib#{first_input[2..-1]}.so"
    +            end
    +            return dlopen(first_input)
               end
             end
           end
    diff --git a/test/fiddle/test_fiddle.rb b/test/fiddle/test_fiddle.rb
    index d16c2a0..ee6c546 100644
    --- a/test/fiddle/test_fiddle.rb
    +++ b/test/fiddle/test_fiddle.rb
    @@ -34,13 +34,22 @@ class TestFiddle < Fiddle::TestCase
           omit("Fiddle::Handle#file_name doesn't exist in FFI backend")
         end
     
    -    # libncurses.so uses INPUT() on Debian GNU/Linux
    +    # libncurses.so uses INPUT() on Debian GNU/Linux and Arch Linux:
    +    #
    +    # Debian GNU/Linux:
    +    #
         # $ cat /usr/lib/x86_64-linux-gnu/libncurses.so
         # INPUT(libncurses.so.6 -ltinfo)
    +    #
    +    # Arch Linux:
    +    # $ cat /usr/lib/libncurses.so
    +    # INPUT(-lncursesw)
         handle = Fiddle.dlopen("libncurses.so")
         begin
    -      assert_equal("libncurses.so",
    -                   File.basename(handle.file_name, ".*"))
    +      normalized_file_name = File.basename(handle.file_name, ".*")
    +      # Arch Linux uses -lncursesw for libncurses.so
    +      normalized_file_name = normalized_file_name.sub(/ncursesw/, "ncurses")
    +      assert_equal("libncurses.so", normalized_file_name)
         ensure
           handle.close
         end
  3. hsbt commented on Dec 11, 2024

    @hsbt
    MemberAuthor

    Thanks. I understood INPUT file of .so now. lib/fiddle.rb is working fine.

    But test is still failing.

    TestFiddle#test_dlopen_linker_script_input_linux [/home/hsbt/dev/ruby/test/fiddle/test_fiddle.rb:52]:
    <"libncurses.so"> expected but was
    <"libncurses">.
    
  4. kou commented on Dec 11, 2024

    @kou
    Member

    Ah, libncursesw.so doesn't have version suffix such as .6. How about this?

    diff --git a/lib/fiddle.rb b/lib/fiddle.rb
    index 6718b01..4723d70 100644
    --- a/lib/fiddle.rb
    +++ b/lib/fiddle.rb
    @@ -111,7 +111,11 @@ module Fiddle
               case line
               when /\A\s*(?:INPUT|GROUP)\s*\(\s*([^\s,\)]+)/
                 # TODO: Should we support multiple files?
    -            return dlopen($1)
    +            first_input = $1
    +            if first_input.start_with?("-l")
    +              first_input = "lib#{first_input[2..-1]}.so"
    +            end
    +            return dlopen(first_input)
               end
             end
           end
    diff --git a/test/fiddle/test_fiddle.rb b/test/fiddle/test_fiddle.rb
    index d16c2a0..69d0c3d 100644
    --- a/test/fiddle/test_fiddle.rb
    +++ b/test/fiddle/test_fiddle.rb
    @@ -34,13 +34,34 @@ class TestFiddle < Fiddle::TestCase
           omit("Fiddle::Handle#file_name doesn't exist in FFI backend")
         end
     
    -    # libncurses.so uses INPUT() on Debian GNU/Linux
    +    # libncurses.so uses INPUT() on Debian GNU/Linux and Arch Linux:
    +    #
    +    # Debian GNU/Linux:
    +    #
         # $ cat /usr/lib/x86_64-linux-gnu/libncurses.so
         # INPUT(libncurses.so.6 -ltinfo)
    +    #
    +    # Arch Linux:
    +    # $ cat /usr/lib/libncurses.so
    +    # INPUT(-lncursesw)
         handle = Fiddle.dlopen("libncurses.so")
         begin
    -      assert_equal("libncurses.so",
    -                   File.basename(handle.file_name, ".*"))
    +      # /usr/lib/x86_64-linux-gnu/libncurses.so.6 ->
    +      # libncurses.so.6
    +      normalized_file_name = File.basename(handle.file_name)
    +      # libncurses.so.6 ->
    +      # libncurses.so
    +      #
    +      # libncursesw.so ->
    +      # libncursesw.so
    +      normalized_file_name = normalized_file_name.sub(/\.so(\.\d+)+\z/, ".so")
    +      # libncurses.so ->
    +      # libncurses.so
    +      #
    +      # libncursesw.so ->
    +      # libncurses.so
    +      normalized_file_name = normalized_file_name.sub(/ncursesw/, "ncurses")
    +      assert_equal("libncurses.so", normalized_file_name)
         ensure
           handle.close
         end
  5. hsbt commented on Dec 11, 2024

    @hsbt
    MemberAuthor

    👍 The latest patch passed on ArchLinux of Ruby CI. Thanks.

  6. kou commented on Dec 11, 2024

    @kou
    Member

    Thanks for confirming it. I'll push this.

  7. hsbt commented on Dec 11, 2024

    @hsbt
    MemberAuthor
  8. added a commit that references this issue on Dec 11, 2024
    77d3dc9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions