I would like to be able to associate some stringy, easily-extractible key-value pairs with my ELF executables.
I've noticed gcc-compiled ELFs have a .comment
section
$ readelf -p .comment a.out
So I tried to replicate that:
main.c:
#include <stdio.h>
int main(){ puts("Hello world"); return 0; }
const char str[] __attribute__((section(".meta"))) = "hello meta world";
Test:
$ readelf -p .meta a.out
String dump of section '.meta':
[ 0] hello meta world
or
$ readelf -p .meta a.out | sed -n 's/^[^]]*] //p'
hello meta world
This works.
Is there a better way to attach such stringly key-value pairs to an ELF file (without breaking it down to multiple files)? Is there a namespace (e.g. .user.meta
) for user sections that would prevent me from breaking something?