Since you said the simplest program, here is a real hack.
This is for Ubuntu 12.04 by running x86_64. If you have something else, then this may give you a clue what to do.
mkdir hack_code cd hack_code cp /usr/lib/ldscripts/elf_x86_64.x ldsimple.x
Now modify ldsimple.x to say ENTRY(main) instead of ENTRY(_start) at the beginning.
Create this mymain.c :
int main(void) { __asm__ __volatile__ ( "movq $60, %rax\n" "movq $2, %rdi\n" "syscall" ); return 0; }
And then:
gcc -c mymain.c ld -o mymain -T./ldsimple.x mymain.o
Voila: You now have a program that does not use a library, etc.
source share