How to communicate with Linux kernel " The power of assembly programming "
Last updated 2001-07-30 5:35 pm
Independence from GLIBC
There is no standard function calls in the source. Do we really need libraries? Why not to shave off the flab? -nostdlib option ceases to link standard system libraries and startup files.
|
Fmm..., GCC complained there is no entry point named as _start. Executable and Linking Format (ELF) assumes _start as an initial entry point. Do you know "where is _start"?
|
Here it is. A startup file crt1.o contains a program whose entry point is _start and the code also includes main() calling statement (NOTE main entry is Undefined in crt1.o). So, the famous "main()" is implicitly called within crt1.o. I'll show you how to escape from the problem.
|
After compile of test0.c (-c force compile only), link the program using main as an entry point (-e main). Look, the code size is only 989 bytes! It is one fifth of original program. ldd tells you test0 does not depend on GLIBC any more. It is a standalone program. As a result, many symbols has disappeared (nm). Now, it is time to execution.
|
Oh my god... What happened? The answer appears in next section .