x86-64elfarm64debug-symbols

Why is elf strip not cross platform


I have an aarch64 elf executable compiled on my raspberry pi:

$ file kbgen.elf.aarch64
kbgen.elf.aarch64: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=4cf36e84c30ea8e53073bb64cf99df1d82084702, with debug_info, not stripped

When I try to strip its symbols on my x64 machine ( wsl ) it fails:

$ strip kbgen.elf.aarch64
strip: Unable to recognise the format of the input file `kbgen.elf.aarch64'

That's weird, right? I mean the elf sections are "cross-platform", aren't they?

# get inside raspberry pi to make sure stripping is ok there
$ ls -l kbgen.elf.aarch64
-rwxr-xr-x 1 oren oren 73257408 Oct 26 08:40 kbgen.elf.aarch64
$ sudo strip kbgen.elf.aarch64
$ ls -l kbgen.elf.aarch64 # <----- size reduced by a half, good !
-rwxr-xr-x 1 root root 36358680 Oct 26 08:42 kbgen.elf.aarch64

# make sure elf was stripped with file utility
$ file kbgen.elf.aarch64
kbgen.elf.aarch64: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=4cf36e84c30ea8e53073bb64cf99df1d82084702, stripped

Solution

  • I mean the elf sections are "cross-platform", aren't they?

    They are.

    There is no reason for strip to be ELF-platform dependent1, except for historical accident of implementation that Peter Cordes alluded to: strip uses libbfd (which is also used by objcopy, objdump, etc.), and that library does have a lot of architecture-specific parts (since it deals with a lot more than just ELF sections).

    You should try to use eu-strip (part of elfutils package) instead. I suspect that eu-strip will just work.


    1There are lots of reasons why strip would have different implementation between say ELF and COFF. But all variants of ELF are pretty much the same as far as strip goes.