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

Improved lib name standardization #796

Merged
merged 5 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/truffle/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class DynamicLibrary
RTLD_GLOBAL = Rubinius::Config['rbx.platform.dlopen.RTLD_GLOBAL']
RTLD_LOCAL = Rubinius::Config['rbx.platform.dlopen.RTLD_LOCAL']

attr_reader :name

def self.open(libname, flags)
code = libname ? "load #{libname}" : 'default'
code = libname ? "load '#{libname}'" : 'default'
handle = Truffle::Interop.eval('application/x-native', code)
DynamicLibrary.new(libname, handle)
end
Expand Down
21 changes: 15 additions & 6 deletions src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,21 @@ def self.library_in_search_path_or_default(lib, search_paths)
lib
end

def self.standardize_lib_name(lib)
if lib.start_with?('lib') or lib.start_with?('/')
lib
else
"lib#{lib}.#{RbConfig::CONFIG['NATIVE_DLEXT']}"
end
def self.standardize_lib_name(lib_name)
require 'ffi'
extend FFI::Library

# Take a first pass at normalizing the library name much like the linker would normally do for us.
# Since we ultimately call `dlopen` to open the library, the name must be in a form that `dlopen` can
# handle. This pass will, for example, map "jpeg" -> "libjpeg.so".
normalized_lib_name = FFI.map_library_name(lib_name)

# Mapping a library name is a best effort approach towards standardizing a library name. It works in many cases,
# but in others the simple mapping is not sufficient. On Linux, for example, that name may correspond to an `ld`
# script, rather than the actual library we want to load. So, we try loading the library here, which will properly
# resolve the full library path if necessary (and possible).
dynamic_lib = ffi_lib(normalized_lib_name).first
dynamic_lib.name
end
end

Expand Down