Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_dlopen_linker_script_input_linux is failed with ArchLinux #166

Closed
hsbt opened this issue Dec 11, 2024 · 7 comments
Closed

test_dlopen_linker_script_input_linux is failed with ArchLinux #166

hsbt opened this issue Dec 11, 2024 · 7 comments

Comments

@hsbt
Copy link
Member

hsbt commented Dec 11, 2024

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.

@hsbt
Copy link
Member Author

hsbt commented Dec 11, 2024

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?

@kou
Copy link
Member

kou commented Dec 11, 2024

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

@hsbt
Copy link
Member Author

hsbt commented Dec 11, 2024

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">.

@kou
Copy link
Member

kou commented Dec 11, 2024

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

@hsbt
Copy link
Member Author

hsbt commented Dec 11, 2024

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

@kou
Copy link
Member

kou commented Dec 11, 2024

Thanks for confirming it. I'll push this.

@kou kou closed this as completed in 77d3dc9 Dec 11, 2024
matzbot pushed a commit to ruby/ruby that referenced this issue Dec 11, 2024
@hsbt
Copy link
Member Author

hsbt commented Dec 11, 2024

The latest result fixed this.

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

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants