Skip to content

Instantly share code, notes, and snippets.



Created Apr 29, 2020
What would you like to do?
Embed file in Go using ELF section
package main
import (
func main() {
selfPath, _ := os.Executable()
selfFile, _ := os.Open(selfPath)
selfElf, _ := elf.NewFile(selfFile)
var data []byte
for _, s := range selfElf.Sections {
if s.Name == "myfile" {
data, _ = s.Data()
go build -o _main
objcopy --add-section myfile=myfile _main main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.