cmd/internal/obj, cmd/link: record ABIs and aliases in Go obj files

This repurposes the "version" field of a symbol reference in the Go
object file format to be an ABI field. Currently, this is just 0 or 1
depending on whether the symbol is static (the linker turns it into a
different internal version number), so it's already only tenuously a
symbol version. We change this to be -1 for static symbols and
otherwise by the ABI number.

This also adds a separate list of ABI alias symbols to be recorded in
the object file. The ABI aliases must be a separate list and not just
part of the symbol definitions because it's possible to have a symbol
defined in one package and the alias "defined" in a different package.
For example, this can happen if a symbol is defined in assembly in one
package and stubbed in a different package. The stub triggers the
generation of the ABI alias, but in a different package from the
definition.

For #27539.

Change-Id: I015c9fe54690c027de6ef77e22b5585976a01587
Reviewed-on: https://go-review.googlesource.com/c/147157
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Austin Clements 2018-10-26 13:53:02 -04:00
parent 07544c7e80
commit c5718b6b26
6 changed files with 96 additions and 26 deletions

View file

@ -82,7 +82,7 @@ func WriteObjFile(ctxt *Link, b *bufio.Writer) {
w := newObjWriter(ctxt, b)
// Magic header
w.wr.WriteString("\x00\x00go19ld")
w.wr.WriteString("\x00go112ld")
// Version
w.wr.WriteByte(1)
@ -102,6 +102,10 @@ func WriteObjFile(ctxt *Link, b *bufio.Writer) {
w.writeRefs(s)
w.addLengths(s)
}
for _, s := range ctxt.ABIAliases {
w.writeRefs(s)
w.addLengths(s)
}
// End symbol references
w.wr.WriteByte(0xff)
@ -137,9 +141,12 @@ func WriteObjFile(ctxt *Link, b *bufio.Writer) {
for _, s := range ctxt.Data {
w.writeSym(s)
}
for _, s := range ctxt.ABIAliases {
w.writeSym(s)
}
// Magic footer
w.wr.WriteString("\xff\xffgo19ld")
w.wr.WriteString("\xffgo112ld")
}
// Symbols are prefixed so their content doesn't get confused with the magic footer.
@ -155,8 +162,12 @@ func (w *objWriter) writeRef(s *LSym, isPath bool) {
} else {
w.writeString(s.Name)
}
// Write "version".
w.writeBool(s.Static())
// Write ABI/static information.
abi := int64(s.ABI())
if s.Static() {
abi = -1
}
w.writeInt(abi)
w.nRefs++
s.RefIdx = w.nRefs
}