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

ffi fails to load linker script /usr/lib/libc.so on FreeBSD 10 #308

Closed
mathiasp opened this issue Nov 14, 2013 · 9 comments

Comments

Projects
None yet
8 participants
@mathiasp
Copy link

commented Nov 14, 2013

In FreeBSD 10 /usr/lib/libc.so has turned into a linker script with the following content (see http://svnweb.freebsd.org/base/head/lib/libc/libc.ldscript?revision=251668&view=markup)

/* $FreeBSD: stable/10/lib/libc/libc.ldscript 251668 2013-06-12 21:12:05Z jlh $ */
GROUP ( /lib/libc.so.7 /usr/lib/libssp_nonshared.a )

ffi does not like this:

marcopolo% middleman
== The Middleman is loading
/usr/local/lib/ruby/gems/2.0/gems/ffi-1.9.0/lib/ffi/library.rb:123:in block in ffi_lib': Could not open library 'libc.so': /usr/lib/libc.so: invalid file format (LoadError) from /usr/local/lib/ruby/gems/2.0/gems/ffi-1.9.0/lib/ffi/library.rb:90:inmap'
from /usr/local/lib/ruby/gems/2.0/gems/ffi-1.9.0/lib/ffi/library.rb:90:in ffi_lib' from /usr/local/lib/ruby/gems/2.0/gems/rb-kqueue-0.2.0/lib/rb-kqueue/native.rb:34:inmodule:Native'
....

Is there a way to force ffi to use /lib/libc.so.7?

Thanks, Mathias

@larskanis

This comment has been minimized.

Copy link
Member

commented Nov 14, 2013

ffi has some very limited ability to parse ld script files: https://github.com/ffi/ffi/blob/master/lib/ffi/library.rb#L116-122
Obviously it did not work in your case. I don't have FreeBSD to test this, but you could improve this section, so that it works for you and post the result eventually.

The worse alternative is to give ffi_lib an Array of possible library paths here: https://github.com/mat813/rb-kqueue/blob/master/lib/rb-kqueue/native.rb#L34

@ekollof

This comment has been minimized.

Copy link

commented Jan 29, 2014

This is still an issue. Diaspora is broken on FreeBSD 10 because of this as well.

require 'ffi'

module MyLib
          extend FFI::Library
            ffi_lib 'c'
              attach_function :puts, [ :string ], :int
end
MyLib.puts 'Hello, World using libc!'
[diaspora@misc ~]$ ruby test.rb 
/usr/local/lib/ruby/gems/1.9/gems/ffi-1.9.3/lib/ffi/library.rb:133:in `block in ffi_lib': Could not open library 'c': Shared object "c" not found, required by "ruby". (LoadError)
Could not open library 'libc.so': /usr/lib/libc.so: invalid file format
        from /usr/local/lib/ruby/gems/1.9/gems/ffi-1.9.3/lib/ffi/library.rb:100:in `map'
        from /usr/local/lib/ruby/gems/1.9/gems/ffi-1.9.3/lib/ffi/library.rb:100:in `ffi_lib'
        from test.rb:5:in `<module:MyLib>'
        from test.rb:3:in `<main>'
@iamasmith

This comment has been minimized.

Copy link

commented Feb 5, 2014

Until it's sorted out properly you can monkey patch it like this.. run this before requiring any of your other stuff that depend on the libc definitions..

require 'rubygems'
require 'ffi'

if RUBY_PLATFORM.include?('freebsd10')

module FFI
  module Platform
    remove_const 'LIBC'
    LIBC = 'libc.so.7'
  end
  module Library
    remove_const 'LIBC'
    LIBC = FFI::Platform::LIBC
  end
end

end

@arp242 arp242 referenced this issue Mar 8, 2014

Closed

Fix FreeBSD 10 #332

@ari

This comment has been minimized.

Copy link

commented Apr 11, 2014

Is anyone working on a fix for this?

@ekollof

This comment has been minimized.

@tduehr

This comment has been minimized.

Copy link
Member

commented Jul 1, 2014

Fixed with #328

@tduehr tduehr closed this Jul 1, 2014

@reicheltd

This comment has been minimized.

Copy link

commented Aug 3, 2014

gem 'ffi', git: 'git://github.com/ffi/ffi.git'in my Gemfile works for me on freebsd 10

@reicheltd

This comment has been minimized.

Copy link

commented Aug 18, 2014

Why is this issue closed? It doesnt work on the current 1.9.3 ffi version.

@swills

This comment has been minimized.

Copy link

commented Aug 22, 2014

I applied the patch in #328 to the current 1.9.3 release and it didn't work for me. Applying the patch from Carpetsmoker@ac63e07 did fix it for me. Perhaps there are other changes in the dev version that I need?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.