我在我的树莓派上编译了一个 aarch64 elf 可执行文件:
$ 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
当我尝试在我的 x64 机器(wsl)上删除它的符号时,它失败了:
$ strip kbgen.elf.aarch64
strip: Unable to recognise the format of the input file `kbgen.elf.aarch64'
这很奇怪,对吧?我的意思是精灵部分是“跨平台的”,不是吗?
# 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
我的意思是精灵部分是“跨平台的”,不是吗?
他们是。
strip
没有理由依赖于平台,除了Peter Cordes提到的历史实现事故:strip
使用libbfd
(objcopy
、objdump
等也使用) ,并且 that 库确实有很多特定于架构的部分(因为它处理的不仅仅是 ELF 部分)。
您应该尝试使用 eu-strip
(
elfutils
包的一部分)。我怀疑
eu-strip
会起作用。