You already discovered the section(...)
attribute, but no matter what you apply it to (even struct {}
and char[0]
), it's gonna take up some space and create a non-empty segment.
It seems there is no way to do exactly what you're asking from actual C code, but you can achieve a workaround by using inline assembly.
Include this code block somewhere outside of a function:
asm(".section __RESTRICT,__restrict\n"
"empty:\n"
".no_dead_strip empty\n");
This will:
- add a truly empty (filesize: 0) segment/section to your object file.
- add an
empty
symbol to your symbol table, but:
- it's gonna be private (i.e. non-linkable).
- as long as it doesn't start with an underscore, the chances of it colliding with anything else are virtually zero.
- work in all of i386, x86_64, arm and arm64 assembly.