为什么使用 gcc 64 位构建的 apache 二进制文件混合了 32 位和 64 位?

为什么使用 gcc 64 位构建的 apache 二进制文件混合了 32 位和 64 位?

在 Solaris 10 上,我构建了 64 位的 gcc 4.9.0。至少我认为我做到了。我正在构建一个基于 Apache 的堆栈和其他必备工具。

如果我构建 apachefile显示 64 位 httpd:

file apache-test/bin/httpd 
apache-test/bin/httpd:        ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available

所以这向我表明我的 GCC 是 64 位的,但是在我构建二进制文件的目录中,我运行for f in *; do file $f; done以针对我得到的整个目录运行文件:

for f in *; do file $f; done 
a.out:          empty file 
addr2line:      ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
ar:             ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
as:             ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
c_rehash:       executable /usr/bin/perl script 
c++:            ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS], dynamically linked, not stripped
c++filt:        ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
compile_et:     executable shell script 
cpp:            ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS], dynamically linked, not stripped
elfedit:        ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3], dynamically linked, not stripped
g++:            ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS], dynamically linked, not stripped
gcc:            ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS], dynamically linked, not stripped
gcc-ar:         ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3], dynamically linked, not stripped
gcc-nm:         ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3], dynamically linked, not stripped
gcc-ranlib:     ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3], dynamically linked, not stripped
gcov:           ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS POPC], dynamically linked, not stripped
gprof:          ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS], dynamically linked, not stripped
gss-client:     ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
k5srvutil:      executable shell script 
kadmin:         ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
kdestroy:       ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
kinit:          ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
klist:          ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
kpasswd:        ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
krb5-config:    executable shell script 
kswitch:        ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
ktutil:         ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
kvno:           ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
ld:             ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
ld.bfd:         ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
nm:             ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
objcopy:        ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
objdump:        ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
openssl:        ELF 64-bit MSB executable SPARCV9 Version 1, UltraSPARC1 Extensions Required, dynamically linked, not stripped, no debugging information available
pcre-config:    executable shell script 
pcregrep:       ELF 64-bit MSB executable SPARCV9 Version 1, UltraSPARC3 Extensions Required, dynamically linked, not stripped
pcretest:       ELF 64-bit MSB executable SPARCV9 Version 1, UltraSPARC3 Extensions Required, dynamically linked, not stripped
ranlib:         ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
readelf:        ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
sclient:        ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
sim_client:     ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available
size:           ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
sparc-sun-solaris2.10-c++:      ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS], dynamically linked, not stripped
sparc-sun-solaris2.10-g++:      ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS], dynamically linked, not stripped
sparc-sun-solaris2.10-gcc:      ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS], dynamically linked, not stripped
sparc-sun-solaris2.10-gcc-4.9.0:        ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 FMAF VIS], dynamically linked, not stripped
sparc-sun-solaris2.10-gcc-ar:   ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3], dynamically linked, not stripped
sparc-sun-solaris2.10-gcc-nm:   ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3], dynamically linked, not stripped
sparc-sun-solaris2.10-gcc-ranlib:       ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3], dynamically linked, not stripped
strings:        ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
strip:          ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, UltraSPARC3 Extensions Required [CBCOND VIS3 VIS], dynamically linked, not stripped
uuclient:       ELF 64-bit MSB executable SPARCV9 Version 1, dynamically linked, not stripped, no debugging information available

为什么我看到这么多 32 位版本?如果我使用 gcc 构建 apache,当 gcc 文件显示 32 位时,它怎么可能是 64 位?

答案1

Solaris 上的 GCC 有一些与 Linux 上的 GCC 不同的默认值。

要编译 64 个二进制文件,您必须添加

-m64

到您的编译和链接行。

在这方面,这使得 GCC 与 Solaris Studio C 编译器兼容。

在 SPARC 上,将程序编译为 32 位不会有像 x86 那样的缺点,其中 64 位还为您提供了额外的寄存器。

答案2

您应该将编译器视为一个从某些输入生成输出的函数,或者

output_program = compile_function(input_source, args)

compile_function32 或 64 位二进制文​​件的存在会影响如何它完成了它的工作,但没有输出。

如果我们将 64 位的作用大大简化为简单地增加可寻址内存量,那么从技术上讲,32 位编译器应该只在需要超过 4GB 可寻址内存来生成输出的情况下才会出现问题。对于当今时代来说,这种情况基本上是不可想象的(尽管我确信有些人可以想出一个人为的例子来实现这一点)。

相关内容