How to assemble the output of gcc -S ?
I am reading a book on Assembly Language (Programming from the ground up)... and suddenly had the urge to learn by examining gcc's assembly output, because some of the computer architecture stuff boring to me now and seems not really necessary(I know the general picture pretty well) for getting the basics of asm.
SO, I compiled
Code:
int main(void)
{
return 0;
}
to get
Code:
.file "a.c"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
movl $0, %eax
popl %ebp
ret
.size main, .-main
.ident "GCC: (GNU) 4.6.1 20110908 (Red Hat 4.6.1-9)"
.section .note.GNU-stack,"",@progbits
But this does not have a _start and the following fails to assemble and link it correctly.
Code:
as foo.s -o foo.o
ld foo.o -o foo
How should I modify the assembly and linking commands to correctly assemble the code without modification ?
P.S.
1. gcc's verbose option may show it .. but I am unable to decipher the gobbledygook.
2. Linking libc in the linker step leads to a segfault at execution .