3

I'm trying to run perl executable provided by a debug library on Ubuntu 16.04, but for some reason the file "isn't executable" even though it seems to be a match for my architecture.

The perl executable that ships with Ubuntu 16.04 is stripped

$ nm /usr/bin/perl
nm: /usr/bin/perl: no symbols

The perl-debug package provides a perl under /usr/lib/debug that is not stripped.

$ nm /usr/lib/debug/usr/bin/perl | head
                 U abort@@GLIBC_2.2.5
0000000000589020 r AboveLatin1_invlist
                 U accept@@GLIBC_2.2.5
                 U access@@GLIBC_2.2.5
000000000058e002 r a_hash.16944
                 U alarm@@GLIBC_2.2.5
000000000058e010 r an_array.16943
00000000005795c0 r ASCII_invlist
0000000000543430 T ASCII_TO_NEED
                 U atan2@@GLIBC_2.2.5

However, when you try to run it, exec* fails and bash gives you a nice message:

$ /usr/lib/debug/usr/bin/perl
bash: /usr/lib/debug/usr/bin/perl: cannot execute binary file: Exec format error

When I run file on the two perls though, I see that the debug perl is marked as "having an empty interpreter" where the regular perl has some ld shared object. It probably has some relationship to the linker ld, but I don't know what it is.

$ file /usr/bin/perl
/usr/bin/perl: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=e6106890a64a3316b2adfc04bbf202f13f82b5bb, stripped
$ file /usr/lib/debug/usr/bin/perl
/usr/lib/debug/usr/bin/perl: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter *empty*, for GNU/Linux 2.6.32, BuildID[sha1]=e6106890a64a3316b2adfc04bbf202f13f82b5bb, not stripped

What exactly is file telling me when it reports that the interpreter is empty?

3

The perl-debug perl is for use with (for example) GDB, containing the symbols for understanding a running process or dump of the other perl. For example, given a running process perl script.pl with pid $PID, you can use:

$ gdb /usr/lib/debug/usr/bin/perl $PID

to attach to it, and do all the usual GDB things at that point. It's not a runnable executable on its own and lacks the necessary elements to launch.

The symbols are kept separately because they're more than twice the size of the main executable and very rarely needed. In this case, the symbols are useful for debugging perl, rather than debugging a Perl script, and probably only useful if you're developing extensions to link in.

I don't think setting the executable bit is actually required, but Debian doesn't remove them from any of its debug-symbol files that I see so there may be some situation that needs it. file is telling you the interpreter is empty because it is, since all of the file unrelated to debug information is missing.

1

file is calling ELF tools having noticed that the file is in ELF format; what the interpreter is is not really well documented in elf(5)

PT_INTERP   The array element specifies the location and size of a
            null-terminated pathname to invoke as an  interpreter. 
            This segment type is meaningful only for executable files
...
.interp   This section holds the pathname of a program interpreter.

Given interpreter /lib64/ld-linux-x86-64.so.2 for a file with the interpreter we can look for docs...

$ man -k ld-linux
ld.so (8)            - enlazador/cargador dinámico
ld-linux (8)         - dynamic linker/loader
ld-linux.so (8)      - dynamic linker/loader

And the very informative ld.so(8) page tells us:

   The  programs ld.so and ld-linux.so* find and load the shared libraries
   needed by a program, prepare the program to run, and then run it.

Also you do not necessarily need the .interp section, as instead one can run:

/lib/ld-linux.so.*  [OPTIONS] [PROGRAM [ARGUMENTS]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.