23 January 2010

gcc internals

gcc -v
gcc --print-search-dirs
gcc -print-prog-name=cc1
ld --verbose
objdump -h hello
objdump -d -j .text hello
readelf -S hello
objcopy -R .comment hello hello_new

objdump -t humble
nm humble

GCC Options:
-E (pre-process)
-S (assemble)
-c (compile)

.text    executable code
.data initialized global/local static variable.
.bss non initialized static global/local variable.

cat > hello.c << EOF
#include <stdio.h>
int main()
{
printf("hello world!!!\n");
_exit(0);
}
EOF
cat > hello.lds << EOF
SEARCH_DIR("/usr/lib"); SEARCH_DIR("/lib");
SECTIONS
{
. = 0x08048000 + SIZEOF_HEADERS;
.text : { *(.text) }
.rodata : { *(.rodata) }
.data : { *(.data) }
.got : { *(.got.plt) }
.bss : { *(.bss) }
}
EOF

gcc -E hello.c > hello.i
gcc -S hello.i
gcc -c hello.s
gcc hello.o -o hello
cpp hello.c > hello.i
`gcc -print-prog-name=cc1` hello.i
as hello.s -o hello.o
ld -dynamic-linker /lib/ld-linux.so.2 -Thello.lds -o hello hello.o -lc


Referance:
http://www.tenouk.com/ModuleW.html

No comments:

Post a Comment