Linux `文件“”,为什么不将可执行文件报告为可执行文件?
在GNU/Linux Debian 9.9(stretch)中,我的程序报告如下:Linux `文件“”,为什么不将可执行文件报告为可执行文件?,linux,gcc,debian,Linux,Gcc,Debian,在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 strip
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
),标志用于“发布”:
对于“调试”:
问题是为什么对于“release”,可执行文件被报告为共享对象,而不是可执行文件
?,因为
1。您在“调试”构建中使用了-no pie
选项。构建独立于位置的可执行文件(-pie
)是最新Linux发行版的默认值。为什么要在调试版本中禁用它
2.系统上的文件
程序(Debian stretch)不知道PIE可执行文件。新版本的魔法文件将正确地将其标识为可执行文件
示例(/mnt/old
是Debian 9.9根fs):
$cc-xc-奇怪。使用openSUSE(gcc(SUSE Linux)7.4.1)和Archlinux(gcc(Arch Linux 9.3.0-1))上的“release”
选项编译都报告“ELF 64位LSB饼图可执行文件,x86-64,版本1(SYSV),动态链接,解释器/lib64/ld-Linux-x86-64.so.2,BuildID[sha1]=…,用于GNU/Linux 3.2.0,未剥离”
——所以有些事情很奇怪。您是在使用自动生成脚本、生成文件,还是只是使用上面的选项启动gcc?我通常使用自动工具,但目前这是一个例外的手写生成文件。来自VCS注释:。哦,不,哈斯捷宾走了!我应该再次粘贴原因。简言之,上面的-没有馅饼
此外,在与gprof
相关的问题进行斗争时,添加了一个注释,它可能会消失。
-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
$ cc -xc - <<<'int main(){}'
$ file -m /mnt/old/usr/share/misc/magic a.out
a.out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=df3780407016f3ea1a936c35d786288b1c0d4486, not stripped
$ file a.out
a.out: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=df3780407016f3ea1a936c35d786288b1c0d4486, not stripped