3 ms·
The attribute approach seems a lot more convenient: const unsigned char add[] __attribute__((section("text"))) = { 0x48, 0x89, 0xf8, /* mov %rdi,%r
by pdw 10y ago
The attribute approach seems a lot more convenient:
const unsigned char add[] __attribute__((section("text"))) = {
0x48, 0x89, 0xf8, /* mov %rdi,%rax */
0x48, 0x01, 0xf0, /* add %rsi,%rax */
0xc3, /* retq */
};
- byuu 10y agoInteresting ... with section("text"), it crashes. With section(".text"), it works, but spews out this: <gibberish>.s: Assembler messages: <gibberish>.s:155: Warning: Ignoring changed section attributes for .text However, it does compile and work :/
- JoshTriplett 10y ago"text" isn't the right section name; that'll create a new data section named "text", and then you'll segfault trying to execute out of a data section. Specifying ".text" causes the toolchain to attempt to create a data section named ".text", which causes the "changed section attributes" message; the array then correctly ends up in the executable ".text" section, though. I'd like to see a way to declare a section without attempting to make it a data section, but I think the compiler folks' answer to that would probably be "use a linker script". And I don't know a way to disable the warning.