Skip to content

Instantly share code, notes, and snippets.

@itaysk

itaysk/Makefile

Created Apr 29, 2020
Embed
What would you like to do?
Embed file in Go using ELF section
package main
import (
"debug/elf"
"fmt"
"os"
)
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()
}
}
fmt.Println(string(data))
}
build:
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.