]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: implement -buildid for non-ELF binaries
authorRuss Cox <rsc@golang.org>
Thu, 4 Jun 2015 19:15:48 +0000 (15:15 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 5 Jun 2015 04:06:46 +0000 (04:06 +0000)
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/10708
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/pobj.go

index fd1cdd64bbf20e7839d577db0816409f5165f8c2..2ffba875c5234539d1aad3e2628874365142486d 100644 (file)
@@ -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
index b3252c181b93a8866fd41b9baf660d176e1c77fe..60d584fc73e7787fbee9b72044bc6a6a9be9fb9e 100644 (file)
@@ -231,6 +231,7 @@ func Ldmain() {
        }
        addexport()
        Thearch.Gentext() // trampolines, call stubs, etc.
+       textbuildid()
        textaddress()
        pclntab()
        findfunctab()