wiki:Howto/PreventGtkMessageLibGailWrongElfClass

Prevent Gtk-Message libgail.so Wrong ELF Class ELFCLASS64

When running 32-bit applications such as Eclipse (to use GWT Designer), Firefox (to use Adobe Flash) or Acrobat Reader on a 64-bit Linux a set of 32-bit libraries have to be installed. In Ubuntu that is ia32-libs. When running GUI applications from a terminal you might see these warnings:

Gtk-Message: Failed to load module "gail": /usr/lib/gtk-2.0/modules/libgail.so: wrong ELF class: ELFCLASS64
Gtk-Message: Failed to load module "atk-bridge": /usr/lib/gtk-2.0/modules/libatk-bridge.so: wrong ELF class: ELFCLASS64

If you've explored the binaries and the libraries they are linked to using ldd, the linux library dependency viewer, you might be puzzled as to what is trying to load these modules.

The explanation is buried and not well-explained anywhere - until now. After several hours debugging with gdb and research I finally discovered the explanation.

Gtk (Graphics Toolkit) uses environment variables to configure some common settings. Amongst them is the accessibility libraries to be used: libgail (GNOME Accessibility Implementation Library) and libatk-bridge (Accessibility ToolKit bridge). In most user environments you'll find:

GTK_MODULES=gail:atk-bridge

When a Gtk application loads, the core checks this variable and then tries to load the libraries named there. It has a quite sophisticated search pattern, too. When it sees simple names like these it will add the lib prefix and the .so (shared object) extension to get libgail.so, for example. It will then check the library paths in PATH and LD_LIBRARY_PATH for these files.

When running 32-bit on 64-bit the core doesn't realise the application's architecture and looks for the system-default libraries - in this case it finds the 64-bit libraries and when it tries to load them reports wrong ELF CLASS.

The easiest solution is to wrap the 32-bit application in a shell script that clears GTK_MODULES before launching the application:

#!/bin/bash
GTK_MODULES=""
exec $@

It is possible to define the specific 32-bit libraries instead:

#!/bin/bash
GTK_MODULES="/usr/lib32/gtk-2.0/modules/libgail.so:/usr/lib32/gtk-2.0/modules/ libatk-bridge.so"
exec $@

but this will lead to other errors such as:

** ERROR **: file accessible.c: line 554 (spi_accessible_construct): assertion failed: (o)
aborting...
Aborted (core dumped)

So, for the easy life, just unset GTK_MODULES, or as annoying as it is to us purists, install a decent 32-bit chroot and run those applications in a stable environment!