The behavior of the linker is that it defines a character called main in the program data or BSS segment. It has a length of 4 bytes and is initialized to 0. It usually creates a character in a segment of program code (usually called .text ) with executable code for the main function.
The C startup environment starts with a fixed entry point (usually called _start ), initializes a bunch of stuff (for example, sets program arguments), and calls the main function. When main is executable code, everything is fine and dandy, but if 4 zero bytes are used instead, the program transfers control to these zero bytes and tries to execute them.
Typically, data segments and BSS are marked as non-executable, so when you try to execute code there, the processor will throw an exception that the OS will interpret and then terminate your program with a signal. If somehow the segment in which it is located is executable, then it will try to execute the machine instructions defined 00 00 00 00 . On x86 and x86-64, this is an illegal instruction, so you will also receive a SIGILL signal on the POSIX OS.
source share