Commit 9ae3c560 authored by Russ Cox's avatar Russ Cox

cmd/link: implement -buildid for non-ELF binaries

Non-ELF binary formats are much less flexible and typically do not
have a good place to store the build ID.

We store it as raw bytes at the beginning of the text segment.

The only system I know of that will be upset about this is NaCl,
and NaCl is an ELF system and does not use this.

For #11048.

Change-Id: Iaa7ace703c4cf36392e752eea9b55e2ce49e9826
Reviewed-on: https://go-review.googlesource.com/10708Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 16ebe9f7
......@@ -37,6 +37,7 @@ import (
"fmt"
"log"
"os"
"strconv"
"strings"
)
......@@ -1546,6 +1547,29 @@ func dodata() {
}
}
// Add buildid to beginning of text segment, on non-ELF systems.
// Non-ELF binary formats are not always flexible enough to
// give us a place to put the Go build ID. On those systems, we put it
// at the very beginning of the text segment.
// This ``header'' is read by cmd/go.
func textbuildid() {
if Iself || buildid == "" {
return
}
sym := Linklookup(Ctxt, "go.buildid", 0)
sym.Reachable = true
// The \xff is invalid UTF-8, meant to make it less likely
// to find one of these accidentally.
data := "\xff Go build ID: " + strconv.Quote(buildid) + "\n \xff"
sym.Type = obj.STEXT
sym.P = []byte(data)
sym.Size = int64(len(sym.P))
sym.Next = Ctxt.Textp
Ctxt.Textp = sym
}
// assign addresses to text
func textaddress() {
var sub *LSym
......
......@@ -231,6 +231,7 @@ func Ldmain() {
}
addexport()
Thearch.Gentext() // trampolines, call stubs, etc.
textbuildid()
textaddress()
pclntab()
findfunctab()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment