GCC 总览

文章详细阐述了GCC的编译过程,包括使用Crosstool-NG编译riscv64目标的GCC,以及GCC编译所需的代码如glibc和musllibc等。同时,讨论了GCC的各种编译选项,如-nostartfiles和-nodefaultlibs,以及它们在链接时的影响。此外,还提到了GCC编译出的低级运行时库libgcc.a的重要性。
摘要由CSDN通过智能技术生成

编译一个GCC

GCC 编译过程
编译出 GCC 所需的代码
  • gcc
  • glibc
stdlib
stdlib-c++
newlibc
glibc
musl libc
ulibc
crt0.o
crts.o
crtend.o
GCC 编译出的文件
https://web.mit.edu/rhel-doc/3/rhel-gcc-en-3/link-options.html

-nostartfiles
Do not use the standard system startup files when linking. 
The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used.

-nodefaultlibs
Do not use the standard system libraries when linking. Only the libraries you specify will be passed to the linker. 
The standard startup files are used normally, unless -nostartfiles is used. The compiler may generate calls to bcopy and bzero for BSD environments. 
These entries are usually resolved by entries in libc. 
These entry points should be supplied through some other mechanism when this option is specified.

-nostdlib
Do not use the standard system startup files or libraries when linking. 
No startup files and only the libraries you specify will be passed to the linker. 
The compiler may generate calls to bcopy and bzero for BSD environments. 
These entries are usually resolved by entries in libc. 
These entry points should be supplied through some other mechanism when this option is specified.

One of the standard libraries bypassed by -nostdlib and -nodefaultlibs is libgcc.a, a library of internal subroutines that GCC uses to overcome shortcomings of particular machines, or special needs for some languages. 
(, for more discussion of libgcc.a.) In most cases, you need libgcc.a even when you want to avoid other standard libraries. 
In other words, when you specify -nostdlib or -nodefaultlibs you should usually specify -lgcc as well. This ensures that you have no unresolved references to internal GCC library subroutines. 
(For example, __main, used to ensure C++ constructors will be called; .)

GCC 选项

GCC 使用文档

GCC 编译过程
预处理
gcc -E helloworld.c -o helloworld.i  

编译
gcc -S helloworld.i -o helloworld.s 

汇编
gcc -c helloworld.s -o helloworld.o  

 链接
gcc helloworld.o -o helloworld  
GCC 预处理选项
GCC 编译选项
GCC优化
GCC其他选项
-static
-fno-builtin
-nostartfiles
-nostdlib
GCC 汇编选项
-mcpu
-arch
GCC 链接选项
是谁执行 ld
如何传递给ld
-T 
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值