gerard4143 explained 6 years ago how to store binary code in memory and then execute it. See

In the example, we create an array of unsigned char containing these values:

This works fine when I use the binary code provided with the example.

How does one generate the binary code that can be used in this manner?

I'm trying to generalize this "Hello, World!" example. The goal is to load binary code for a set of functions into memory, as an array of arrays of unsigned char, for instance. Set page attributes to permit execution. And execute the functions by treating pointers to memory locations as function pointers.

It seems eminently doable, but I don't know how to generate binary code suitable for loading into memory and executing from that. I thought maybe generate object code files and ignore the ELF header? Working with Linux on x86_64 systems.

I'm going to answer this a different way. What you are essentially doing is Inline Assembler. There are priors on that at but some basic knowledge is required here.

That is, you could put the assembler code in there or run it through the assmbler and pick over the bytes to copy into your app's inline assembler code.

Seasoned coders will not put byte code like that into an app so I don't expect a lot of support for this today.