📁 What is the csu Folder in glibc?
The csu (C Startup) folder in the glibc source tree contains the low-level startup code that runs **before **main() in a C program. This code sets up the environment necessary for a C program to start correctly.
It plays a vital role in:
🚀 Responsibilities
-
C runtime startup sequence (prepares arguments, environment, etc.)
-
**Calling **
main()safely after setup -
Setting up
.initand.finifunctions for constructors and destructors -
Entry points for both static and dynamic binaries
-
Setting up PIE (Position Independent Executable) vs non-PIE execution
🧩 Key Files
-
crt1.c,crt1.o– Startup code for dynamically linked executables -
Scrt1.c,Scrt1.o– Startup for statically linked executables -
rcrt1.c– For PIE executables -
initfini.c– Calls.initand.finisections for constructor/destructor support -
start.S– Assembly entry point, very architecture-specific -
dlstart.c– Support for dynamic linker (ld.so) startup
🔧 How It Works
When you compile a C program, crt1.o or Scrt1.o is linked in by default. These startup files:
-
Set up the stack and registers (in assembly)
-
Call the C-level startup routine (
__libc_start_main) -
That function sets up things like:
-
Environment variables
-
Standard I/O
-
Constructors (
__init_array__,.init)
-
-
Finally, it calls your
main()function -
When
main()returns,exit()is called