3 ms·
OK, yes, that does work. You can totally put application specific stuff in the elf and reflect on it at runtime. Much easier is to point a symbol value at the s
by JonChesterfield 3y ago
OK, yes, that does work. You can totally put application specific stuff in the elf and reflect on it at runtime. Much easier is to point a symbol value at the start of the data in the elf and refer to that symbol, then you don't have to crawl the headers yourself. The linker does it for you.
See https://github.com/graphitemaster/incbin https://github.com/graphitemaster/incbin for a pretty wrapper around that.
Aside from there being a drastically simpler answer to this problem available in sketchily documented fashion (the asm guys know .incbin is a thing, but higher level languages overcomplicate it), it's a good post. Idea is sound and goal was achieved.
ELF linkers will create symbols pointing to sections with C identifiers as names too if you want to do that instead of inline asm. Without linker scripts I mean, they just do that out of the box.
- zokier 3y agoRust has `#[link_section]`, `#[export_name]`, and `include_bytes!()`, which together allow you to put data from a file under specific symbol in a specific section. Maybe not applicable to the problem in tfa but seems to accomplish all that incbin does too.
- trealira 3y agoAlso, C23 has #embed included as a preprocessor directive. It serves similar purpose to include_bytes!(), although I don't think there's a way to specify the section it goes in within the executable. https://thephd.dev/finally-embed-in-c23 https://thephd.dev/finally-embed-in-c23
- saagarjha 3y agoI haven't used #embed yet personally, but if it gives you an array or similar back then you should be able to apply attributes to the variable to tell the compiler where to store it?
- trealira 3y agoI know GCC has section attributes, but I don't think there's any standard C23 attribute equivalent.