Skip to content

Commit

Permalink
cmd/internal/goobj: make mkbuiltin.go automatically update Magic const
Browse files Browse the repository at this point in the history
Fixes #69928

Change-Id: Icf4f800be496eabcdb0cce44374cb67a8c948a95
  • Loading branch information
callthingsoff committed Nov 13, 2024
1 parent c759ea7 commit 9c2b679
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/cmd/internal/goobj/builtinlist.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/cmd/internal/goobj/mkbuiltin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go/format"
"go/parser"
"go/token"
"internal/goversion"
"io"
"log"
"os"
Expand All @@ -33,6 +34,7 @@ func main() {
fmt.Fprintln(&b)
fmt.Fprintln(&b, "package goobj")

mkmagic(&b)
mkbuiltin(&b)

out, err := format.Source(b.Bytes())
Expand All @@ -49,6 +51,11 @@ func main() {
}
}

func mkmagic(w io.Writer) {
version := fmt.Sprintf("go1%d", goversion.Version)
fmt.Fprintln(w, fmt.Sprintf(`const Magic = "\x00%sld"`, version))
}

func mkbuiltin(w io.Writer) {
pkg := "runtime"
fset := token.NewFileSet()
Expand Down
2 changes: 0 additions & 2 deletions src/cmd/internal/goobj/objfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ type Header struct {
Offsets [NBlk]uint32
}

const Magic = "\x00go120ld"

func (h *Header) Write(w *Writer) {
w.RawString(h.Magic)
w.Bytes(h.Fingerprint[:])
Expand Down

0 comments on commit 9c2b679

Please sign in to comment.