【发布时间】: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。