To prevent some performance overhead I would like to append some binary data created by openssl to a Rust executable as an ELF section. While the data itself might have a variable length, its actual length may be parse from the header though.
If you're just trying to include the file so your program can read them, you can use include_bytes rather than manually modifying the executable. The compiler will keep track of the number of bytes included.
Apparently I missed to write down the initial idea in form of an example. I would like to work with the [link-section] attribute to access the data that is attached in the custom ELF section similar to this example
#[link_section = ".additional_data"]
static ADDITIONAL_DATA: <special type>;
fn main(){
...
// do some computing with ADDITIONAL_DATA
...
}
Though I don't know how to make it happen, it should be possible to use partial linking to produce an object file of your program with an unresolved symbol referring to the OpenSSL data.
You can then use objcopy to pack up the data into a second object file that exports this symbol, and the linker can put the two together into a final executable without recompiling the program.