Skip to content

Commit 77d3dc9

Browse files
committed
dlopen: add support for INPUT(-lXXX)
GitHub: fix GH-166 Arch Linux's libncurses.so uses this style.
1 parent 0bd963d commit 77d3dc9

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

lib/fiddle.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ def dlopen library
111111
case line
112112
when /\A\s*(?:INPUT|GROUP)\s*\(\s*([^\s,\)]+)/
113113
# TODO: Should we support multiple files?
114-
return dlopen($1)
114+
first_input = $1
115+
if first_input.start_with?("-l")
116+
first_input = "lib#{first_input[2..-1]}.so"
117+
end
118+
return dlopen(first_input)
115119
end
116120
end
117121
end

test/fiddle/test_fiddle.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,34 @@ def test_dlopen_linker_script_input_linux
3434
omit("Fiddle::Handle#file_name doesn't exist in FFI backend")
3535
end
3636

37-
# libncurses.so uses INPUT() on Debian GNU/Linux
37+
# libncurses.so uses INPUT() on Debian GNU/Linux and Arch Linux:
38+
#
39+
# Debian GNU/Linux:
40+
#
3841
# $ cat /usr/lib/x86_64-linux-gnu/libncurses.so
3942
# INPUT(libncurses.so.6 -ltinfo)
43+
#
44+
# Arch Linux:
45+
# $ cat /usr/lib/libncurses.so
46+
# INPUT(-lncursesw)
4047
handle = Fiddle.dlopen("libncurses.so")
4148
begin
42-
assert_equal("libncurses.so",
43-
File.basename(handle.file_name, ".*"))
49+
# /usr/lib/x86_64-linux-gnu/libncurses.so.6 ->
50+
# libncurses.so.6
51+
normalized_file_name = File.basename(handle.file_name)
52+
# libncurses.so.6 ->
53+
# libncurses.so
54+
#
55+
# libncursesw.so ->
56+
# libncursesw.so
57+
normalized_file_name = normalized_file_name.sub(/\.so(\.\d+)+\z/, ".so")
58+
# libncurses.so ->
59+
# libncurses.so
60+
#
61+
# libncursesw.so ->
62+
# libncurses.so
63+
normalized_file_name = normalized_file_name.sub(/ncursesw/, "ncurses")
64+
assert_equal("libncurses.so", normalized_file_name)
4465
ensure
4566
handle.close
4667
end

0 commit comments

Comments
 (0)