Hacker News new | ask | show | jobs
by ache7 2115 days ago
Using compiler hints, data can be placed directly in the code section.

Works on x86/x86_64 Linux:

char main[] __attribute__ ((section(".text"))) = "\xe8\x0d\0\0\0Hello world!\n"

#ifdef __x86_64__

"\x31\xc0\x8d\x50\x0d\xff\xc0\x89\xc7\x5e\x0f\x05\x31\xff\x8d\x47\x3c\x0f\x05";

#else

"\x31\xdb\x8d\x53\x0d\x59\x8d\x43\x04\x43\xcd\x80\x31\xdb\x8d\x43\x01\xcd\x80";

#endif