Last active
April 14, 2025 18:21
-
-
Save sbz/cc7807a9f937b2c37a5cedac5f20ccf5 to your computer and use it in GitHub Desktop.
Add ELF section .sbz using compiler __attribute__((section))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat test.c | |
#include <stdio.h> | |
void | |
test() __attribute__ ((section (".sbz"))) | |
{ | |
printf("Test called located in %p and section .sbz\n", &test); | |
} | |
int | |
main(int argc, char* argv[]) | |
{ | |
test(); | |
return 0; | |
} | |
$ make test CFLAGS+=-Wgcc-compat | |
$ ./test | |
Test called located in 0x201950 and section .sbz | |
$ readelf -S test|grep .sbz | |
[16] .sbz PROGBITS 0000000000201950 00000950 | |
$ elfdump -a test|grep -A4 .sbz | |
sh_name: .sbz | |
sh_type: SHT_PROGBITS | |
sh_flags: SHF_ALLOC|SHF_EXECINSTR | |
sh_addr: 0x201950 | |
sh_offset: 2384 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment