OBR_EXO
OBR_EXO

Reputation: 600

gdb reports wrong ELF version even though library matches gdb filetype?

So I'm trying to debug some code with gdb, I've got a 32-bit environment installed on a 64-bit OS (Ubuntu18), everything compiles/links correctly....

I run the binary, it executes, works, no problems.

I try to run it using gdb - the following happens:

(gdb) run
Starting program: /usr/src/Duris/dms
/bin/bash: error while loading shared libraries: libtinfo.so.5: wrong ELF class: ELFCLASS32
During startup program exited with code 127.

All of the files/libraries involved seem to be the correct 32-bit version... so what exactly am I doing wrong here?

obr@melbourne:/usr/src/Duris$ file dms
dms: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=fdf6e191894c459ebb5abe9287841eafdc858fa5, with debug_info, not stripped
obr@melbourne:/usr/src/Duris$ file /usr/bin/gdb
/usr/bin/gdb: ELF 32-bit LSB shared object, Intel 80386, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=fd1c820fe9165e82c09af64b7dd4ae728347a179, stripped
obr@melbourne:/usr/src/Duris$ file /usr/lib/libtinfo.so.5
/usr/lib/libtinfo.so.5: symbolic link to /lib/i386-linux-gnu/libtinfo.so.5.9
obr@melbourne:/usr/src/Duris$ file /lib/i386-linux-gnu/libtinfo.so.5.9
/lib/i386-linux-gnu/libtinfo.so.5.9: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=adf5caf5c1be713bfc7846377c08b3164ffa50ea, stripped
obr@melbourne:/usr/src/Duris$

Any advice?

Upvotes: 1

Views: 388

Answers (1)

Employed Russian
Employed Russian

Reputation: 213526

what exactly am I doing wrong here?

You have set up LD_LIBRARY_PATH in such a way that 32-bit libtinfo.so.5 is found before 64-bit one.

When you run a 32-bit dms binary, it runs fine.

But GDB doesn't run the dms binary directly. Instead it invokes bash -c dms, and has bash handle input/output redirection (if any).

However, the 64-bit bash binary also depends on libtinfo.so.5, and when it finds the 32-bit version, it complains with the error you are getting: /bin/bash: error while loading shared libraries: libtinfo.so.5: wrong ELF class....

Note in particular that the error is from /bin/bash, not from dms.


There are a few possible solutions:

  • stop setting LD_LIBRARY_PATH or at least including /lib/i386-linux-gnu in it -- the 32-bit dynamic loader should look in /lib/i386-linux-gnu automatically.
  • use set startup-with-shell off GDB command (documentation) before running the binary from GDB.

Upvotes: 1

Related Questions