whoah - I find that construction astonishing.
My gcc compiles it with only this warning:
foo.c:2:6: warning: ‘main’ is usually a function [-Wmain]
hah!My gcc compiles it with only this warning:
foo.c:2:6: warning: ‘main’ is usually a function [-Wmain]
hah! [23] .got.plt PROGBITS 0804954c 00054c 000014 04 WA 0 0 4
[24] .data PROGBITS 08049560 000560 000010 00 WA 0 0 4 <---
[25] .bss NOBITS 08049570 000570 000008 00 WA 0 0 4
66: 0804840a 0 FUNC GLOBAL HIDDEN 14 __i686.get_pc_thunk.bx
67: 08049568 5 OBJECT GLOBAL DEFAULT 24 main <---
68: 08048278 0 FUNC GLOBAL DEFAULT 12 _init
The main symbol is a relocation in .data, not .text. Which is as you would expect given that declaration. You might be able to get around that by doing something like unsigned char code[] = { 0xf0, 0x0f, 0xc7, 0xc8, 0xc3 };
int main(void)
{
((void (*)())code)();
return 0;
}
But these days NX will usually ruin the fun.char main[] __attribute__((section(".text")));
(You get a warning from the assembler.)
I didn't know gcc attributes included that kind of thing. I've really gotta dig though the manual some time.