Skip to content

Facter FFI extensions not working on AIX with 64 bit ruby #2787

Open
@SaltyAlan

Description

@SaltyAlan

Describe the Bug

Facter FFI extensions not working on AIX with 64 bit ruby

Thanks for the assistance with previous issue I logged running facter with FFI: #2785

That issue was resolved with the FFI project - it turns out there was a recent AIX bug I needed to install a patch for.

I got past that FFI issue now with the patch installed - it looks like there is another issue that was hiding behind that FFI AIX bug issue.

By default, ruby on AIX is 64 bit. When I install facter and ffi with 64 bit ruby, when I run facter it fails with invalid magic number errors for the FFI - indicating a 64/32 bit mismatch.

If I change the system to use 32 bit ruby, and reinstall facter and ffi with 32 bit ruby, facter works normally.

Expected Behavior

Facter and ffi working with 64 bit ruby

Steps to Reproduce

Install the gems after prerequisite RPMs installed (as in the environment below):

# dnf list installed ruby ruby-devel libffi libffi-devel gcc10
Installed Packages
gcc10.ppc                                                                       10.3.0-6 
libffi.ppc                                                                      3.4.4-2  
libffi-devel.ppc                                                                3.4.4-2  
ruby.ppc                                                                        3.3.5-1  
ruby-devel.ppc                                                                  3.3.5-1  

# gem install ffi-1.17.1.gem facter-4.10.0.gem
Building native extensions. This could take a while...
Successfully installed ffi-1.17.1
Successfully installed facter-4.10.0
2 gems installed

Calling FFI with ruby succeeds:

# ruby -rffi -e "puts FFI::Library::LIBC"
libc.so

However facter fails with:

[2025-01-15 15:36:55.161676 ] ERROR Facter::Resolvers::Aix::Networking - Resolving fact primary_interface, but got Could not open library 'libc.a(shr.o)':  0509-022 Cannot load module /usr/lib/libc.a(shr.o).
        0509-103   The module has an invalid magic number..
Could not open library 'libc.a(shr.o).so':      0509-022 Cannot load module .
        0509-026 System error: A file or directory in the path name does not exist..
Searched in <system library path> at /opt/freeware/share/ruby/gems/3.3/gems/ffi-1.17.1/lib/ffi/dynamic_library.rb:94:in `load_library'
...
...

Environment

AIX version:
AIX 7.3 TL3 SP0

Prerequisite RPMs installed (installed from AIX toolbox for open source applications - https://www.ibm.com/support/pages/node/882892) :
ruby-3.3.5
ruby-devel-3.3.5
libffi-3.4.4
libffi-devel-3.4.4
gcc10-10.3.0-6

GEMs:
facter-4.10.0.gem
ffi-1.17.1.gem

Additional Context

I can work around this as follows to use 32 bit ruby.

Uninstall facter and ffi that were installed in 64 bit mode.

# gem uninstall facter ffi
Successfully uninstalled ffi-1.17.1
Remove executables:
        facter

in addition to the gem? [Yn]  y
Removing facter
Successfully uninstalled facter-4.10.0

Change symbolic link for ruby from 64 to 32 bit version.

# cd /opt/freeware/bin
# rm ruby
# ls -l ruby*
-rwxr-xr-x    1 root     system        85056 Nov 20 18:02 ruby_32
-rwxr-xr-x    1 root     system        86807 Nov 20 18:01 ruby_64
# ln -s ruby_32 ruby

Reinstall gems with 32 bit ruby. This seems to compile FFI in 32 bit mode.

# gem install ffi-1.17.1.gem facter-4.10.0.gem
Building native extensions. This could take a while...
Successfully installed ffi-1.17.1
Successfully installed facter-4.10.0
2 gems installed

Then facter works normally.

Regarding the system library it is looking for in the error when run in 64 bit mode- the shr.o object only exists in the /usr/lib/libc.a archive in 32 bit mode.

# ar -X32 -tv /usr/lib/libc.a shr.o
r-xr-xr-x     2/2     1228445 Oct 15 06:05 2024 shr.o
# ar -X64 -tv /usr/lib/libc.a shr.o
ar: 0707-109 Member name shr.o does not exist.

The 64 bit version of the object is shr_64.o

# ar -X64 -tv /usr/lib/libc.a shr_64.o
r-xr-xr-x     2/2     1407032 Oct 15 06:05 2024 shr_64.o

Any further assistance appreciated.

Thanks,
Alan

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions