Let's Embed a Go Program into the Linux Kernel (2023)

# · 🔥 129 · 💬 47 · 17 days ago · sigma-star.at · st_goliath · 📷
Instead of launching a program from a file system, regardless of whether it's virtual or not, it is also possible to embed a user-space program directly into the kernel image itself and start it from there. Go programs are statically linked by default, and to illustrate that the following approach works with any kind of program, we have chosen to embed a Go program into the kernel. How do we get our Go program into that buffer? We don't want a new user space interface where the program has to be loaded into the kernel first. The kernel build system, specifically the GNU assembler, can assist us in embedding the Go program into the resulting kernel image during the build process. O, with our Linux device driver, we can utilize the symbols to locate the contents of the Go program within the kernel image. S, The assembly source file we use to embed the Go program into a C object. Every five seconds the Go program will write Hello, world! via standard output to the kernel driver which prints the string to the kernel log buffer.
Let's Embed a Go Program into the Linux Kernel (2023)



Send Feedback | WebAssembly Version (beta)