GCC 显示完整的编译过程

2018-01-27 10:27:35来源:oschina作者:老汉-憨憨人点击

分享

源码: f1.c


#include
#include
#include
#include
int main(int argc, const char *argv[])
{
ucontext_t context;
int count = 0;
getcontext(&context);
int value = 0;
printf("Hello World! count = %d, value = %d/n", count++, value++);
sleep(1);
setcontext(&context);
return 0;
}

显示完整编译链接过程


user_00@(none):asm> gcc --verbose f1.c -m32
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.1.2 --enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new --program-suffix= --enable-version-specific-runtime-libs --without-system-libunwind --with-cpu=generic --host=x86_64-suse-linux
Thread model: posix
gcc version 4.1.2 20070115 (prerelease) (SUSE Linux)
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/cc1 -quiet -v f1.c -quiet -dumpbase f1.c -m32 -m32 -mtune=generic -auxbase f1 -version -o /tmp/cckOI3iI.s
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/include
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/include
/usr/include
End of search list.
GNU C version 4.1.2 20070115 (prerelease) (SUSE Linux) (x86_64-suse-linux)
compiled by GNU C version 4.1.2 20070115 (prerelease) (SUSE Linux).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 3417495ce02f6bde0aa6fd5f0bddeaf6
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/bin/as -V -Qy --32 -o /tmp/ccAJKu3f.o /tmp/cckOI3iI.s
GNU assembler version 2.16.91.0.5 (x86_64-suse-linux) using BFD version 2.16.91.0.5 20051219 (SUSE Linux)
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/32/crtbegin.o -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/32 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib/../lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../.. /tmp/ccAJKu3f.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib64/gcc/x86_64-suse-linux/4.1.2/32/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib/crtn.o

我的 gcc 是 x86_64 4.1.2 版本


在 x86_64 gcc 机器上写 i38632bit 的汇编编译与运行:


汇编代码 hello.s


.data
msg : .string "Hello World!/n"
len = . - msg
.text
.global _start
_start:
movl $len, %edx
movl $msg, %ecx
movl $1, %ebx
movl $4, %eax
int $0x80
movl $0, %ebx
movl $1, %eax
int $0x80

编译与运行:


user_00@(none):asm> as -V -Qy --32 -o hello.o hello.s
GNU assembler version 2.16.91.0.5 (x86_64-suse-linux) using BFD version 2.16.91.0.5 20051219 (SUSE Linux)
user_00@(none):asm> ld-m elf_i386 -s -o hello hello.o
user_00@(none):asm> ./hello
Hello World!

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台