crt0.o and crt1.o — What's the difference?

本文解释了avr-gcc编译器中Crt0和Crt1文件的作用,它们在不同系统上的使用情况及功能差异,强调了它们在初始化阶段的功能相似性,但基于是否支持构造函数和析构函数而有所区分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原帖: http://stackoverflow.com/questions/2709998/crt0-o-and-crt1-o-whats-the-difference

==============================================================================================================================

recently I've been trying to debug some low level work and I could not find the crt0.S for the compiler(avr-gcc) but I did find a crt1.S (and the same with the corresponding .o files)

What is the difference between these two files? Is crt1 something completely different or what? They both seem to have to do with something for bootstrapping(setting up stack frame and such), but why the distinction?

===============================================================================================================================

Both crt0/crt1 do the same thing, basically do what is needed before calling main() (like initializing stack, setting irqs, etc.). You should link with one or the other but not both. They are not really libraries but really inline assembly code.

As far as I understand, crt comes in two "flavors"

  • crt1 is used on system that support constructors and destructors (functions called before and after main and exit). In this case main is treated like a normal function call.
  • crt0 is used on systems that does not support constructors/destructors.
===============================================================================================================================


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值