【问题标题】:`file`, why executables not reported as executables?`file`,为什么可执行文件不报告为可执行文件?
【发布时间】:2020-04-03 23:08:05
【问题描述】:

在 GNU/Linux Debian 9.9 (stretch) 中,我的程序报告为:

build/debug/program_g:              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]=be082fb3..., not stripped
build/debug/stripped_program_g:     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]=be082fb3..., stripped
build/release/program:              ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=6477469..., stripped
build/release/program_not_stripped: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=6477469..., not stripped

编译器是 GCC(香草发行版,即gcc (Debian 6.3.0-18+deb9u1) 6.3.0 2017051),标志用于“发布”:

 -ansi -pedantic -Wall -Wextra -Werror -Wunused-result -Wmissing-include-dirs 
 -Wparentheses -std=c89 -DPROGRAM_USE_STD_C89 -O2 -DNDEBUG

对于“调试”:

 -ansi -pedantic -Wall -Wextra -Werror -Wunused-result -Wmissing-include-dirs 
 -Wparentheses -std=c89 -DPROGRAM_USE_STD_C89 -O0 -g -fprofile-arcs -ftest-coverage -DTRACE_U0 -DTRACE_U1 -no-pie

问题是为什么“发布”可执行文件报告为shared object而不是executable

【问题讨论】:

  • 奇怪。在 openSUSE (gcc (SUSE Linux) 7.4.1) 和 Archlinux (gcc (Arch Linux 9.3.0-1)) 上使用您的 "release" 选项编译都会报告 "ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=...., for GNU/Linux 3.2.0, not stripped" - 所以有些奇怪。您是在使用 Automake 脚本、Makefile,还是只是使用上述选项启动 gcc?
  • 我通常使用 Autotools,但目前它是一个特别的手写 Makefile。

标签: linux gcc debian


【解决方案1】:

因为

1. 您在“调试”版本中使用了-no-pie 选项。构建与位置无关的可执行文件 (-pie) 是最近的 Linux 发行版的默认设置。为什么要在调试版本中禁用它?

2. 您系统上的file 程序(Debian 延伸)不知道PIE 可执行文件。其魔术文件的较新版本将正确地将其识别为pie executable

示例(/mnt/old 是 Debian 9.9 root fs):

$ cc -xc - 共享对象,x86-64,版本 1 (SYSV),动态链接,解释器 /lib64/ld-linux-x86-64.so.2,用于 GNU /Linux 3.2.0,BuildID[sha1]=df3780407016f3ea1a936c35d786288b1c0d4486,未剥离 $文件a.out a.out:ELF 64 位 LSB pie 可执行文件,x86-64,版本 1 (SYSV),动态链接,解释器 /lib64/ld-linux-x86-64.so.2,用于 GNU /Linux 3.2.0,BuildID[sha1]=df3780407016f3ea1a936c35d786288b1c0d4486,未剥离

【讨论】:

  • 来自 VCS 注释:https://hastebin.com/xakalulifa.pl。 ?
  • 哦不,hastebin 的paste 消失了!我应该再次粘贴原因。
  • 简而言之,在-no-pie 上方添加了一条注释 - 在解决与gprof 相关的问题时添加,它可能会消失
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-06
  • 2010-11-14
  • 1970-01-01
相关资源
最近更新 更多