[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: x86 Debian 下的 gcc 默认生成的目标文件究竟是 i486 还是 i686 ?



2012/3/12 Dongsheng Song <dongsheng.song@gmail.com>:
> 2012/3/11 wolf python london <lyh19901223@gmail.com>
>>
>> 2012/3/11 Plain_Text <resation@gmail.com>:
>> >
>> >
>> >   前几天列表里讨论了相关问题,我做了一个这样的试验。
>> >
>> > $ gcc -c main.c -o main.o
>> > $ gcc -march=i486 -c main.c -o main_i486.o
>> > $ gcc -march=i686 -c main.c -o main_i686.o
>> >
>> > $ diff main.o main_i486.o
>> > Binary files main.o and main_486.o differ
>> >
>> > $ diff main.o main_i686.o
>> >
>> $ gcc -v
>> Using built-in specs.
>> COLLECT_GCC=gcc
>> COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.6/lto-wrapper
>> Target: i486-linux-gnu
>> Configured with: ../src/configure -v --with-pkgversion='Debian
>> 4.6.3-1' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
>> --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
>> --program-suffix=-4.6 --enable-shared --enable-linker-build-id
>> --with-system-zlib --libexecdir=/usr/lib --without-included-gettext
>> --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
>> --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
>> --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin
>> --enable-objc-gc --enable-targets=all --with-arch-32=i586
>> --with-tune=generic --enable-checking=release --build=i486-linux-gnu
>> --host=i486-linux-gnu --target=i486-linux-gnu
>> Thread model: posix
>> gcc version 4.6.3 (Debian 4.6.3-1)
>>
>> 可能问题是在这里: --with-tune=generic 这个参数指定了缺省值是i686
>> **quotation**
>> -mtune=generic can now be used to generate code running well on common
>> x86 chips. This includes AMD Athlon, AMD Opteron, Intel Pentium-M,
>> Intel Pentium 4 and Intel Core 2.
>> (http://gcc.gnu.org/gcc-4.2/changes.html)
>> **quotation**
>> >
>> >   其中 main.c 是一个简单的 C 程序。可以看出,默认生成的是 i686 版本。
>> > 可问题是,在 gcc -v 下却看到 Target: i486-linux-gnu .
>> >
>> >   究竟是怎么回事?
>> >
>
>
> --with-arch-32=i586 --with-tune=generic 说明 gcc 默认生成的32bit代码是 i586 指令集,
> 针对 i686 架构优化.
>
> --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
> 看起来是与 --with-arch-32=i586
> 矛盾,但是可以从以下gcc的输出看出:
> # gcc -dM -E - < /dev/null | grep "i[3-9]*86"
> #define __i586 1
> #define __i386 1
> #define __i586__ 1
> #define __i386__ 1
> #define i386 1
>
> 实际生成的代码是 i586 指令集, --build=i486-linux-gnu --host=i486-linux-gnu
> --target=i486-linux-gnu
> 应该是 --build=i586-linux-gnu --host=i586-linux-gnu --target=i586-linux-gnu
>

"--with-arch-32" 影响的是 "-march",即由 gcc 编译出来的程序优化架构。而 "--target" 则指定的是 gcc 自己的架构。

Reply to: