Commit 15634a02 authored by Than McIntosh's avatar Than McIntosh

[dev.link] cmd: convert symbol "shared" flag to object file flag

For the new object file format, don't tag individual symbols with a
"shared" flag, since that characteristic is better off as an attribute
of the containing object file as opposed to the individual symbol. Add
a new flags field in the object file header and put a bit in the flags
if the shared flags is in effect during compilation.

Change-Id: I2cf6d33bf7bf2fd8a7614ae0cd6ef03914777498
Reviewed-on: https://go-review.googlesource.com/c/go/+/201398
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJeremy Faller <jeremy@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 2bbf2e02
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
// //
// Header struct { // Header struct {
// Magic [...]byte // "\x00go114LD" // Magic [...]byte // "\x00go114LD"
// Flags uint32
// // TODO: Fingerprint // // TODO: Fingerprint
// Offsets [...]uint32 // byte offset of each block below // Offsets [...]uint32 // byte offset of each block below
// } // }
...@@ -148,6 +149,7 @@ const ( ...@@ -148,6 +149,7 @@ const (
// TODO: probably no need to export this. // TODO: probably no need to export this.
type Header struct { type Header struct {
Magic string Magic string
Flags uint32
Offsets [NBlk]uint32 Offsets [NBlk]uint32
} }
...@@ -155,6 +157,7 @@ const Magic = "\x00go114LD" ...@@ -155,6 +157,7 @@ const Magic = "\x00go114LD"
func (h *Header) Write(w *Writer) { func (h *Header) Write(w *Writer) {
w.RawString(h.Magic) w.RawString(h.Magic)
w.Uint32(h.Flags)
for _, x := range h.Offsets { for _, x := range h.Offsets {
w.Uint32(x) w.Uint32(x)
} }
...@@ -167,6 +170,8 @@ func (h *Header) Read(r *Reader) error { ...@@ -167,6 +170,8 @@ func (h *Header) Read(r *Reader) error {
return errors.New("wrong magic, not a Go object file") return errors.New("wrong magic, not a Go object file")
} }
off := uint32(len(h.Magic)) off := uint32(len(h.Magic))
h.Flags = r.uint32At(off)
off += 4
for i := range h.Offsets { for i := range h.Offsets {
h.Offsets[i] = r.uint32At(off) h.Offsets[i] = r.uint32At(off)
off += 4 off += 4
...@@ -175,7 +180,7 @@ func (h *Header) Read(r *Reader) error { ...@@ -175,7 +180,7 @@ func (h *Header) Read(r *Reader) error {
} }
func (h *Header) Size() int { func (h *Header) Size() int {
return len(h.Magic) + 4*len(h.Offsets) return len(h.Magic) + 4 + 4*len(h.Offsets)
} }
// Symbol definition. // Symbol definition.
...@@ -189,6 +194,10 @@ type Sym struct { ...@@ -189,6 +194,10 @@ type Sym struct {
const SymABIstatic = ^uint16(0) const SymABIstatic = ^uint16(0)
const (
ObjFlagShared = 1 << iota
)
const ( const (
SymFlagDupok = 1 << iota SymFlagDupok = 1 << iota
SymFlagLocal SymFlagLocal
...@@ -196,7 +205,6 @@ const ( ...@@ -196,7 +205,6 @@ const (
SymFlagLeaf SymFlagLeaf
SymFlagCFunc SymFlagCFunc
SymFlagReflectMethod SymFlagReflectMethod
SymFlagShared // This is really silly
SymFlagTopFrame SymFlagTopFrame
) )
...@@ -226,7 +234,6 @@ func (s *Sym) Typelink() bool { return s.Flag&SymFlagTypelink != 0 } ...@@ -226,7 +234,6 @@ func (s *Sym) Typelink() bool { return s.Flag&SymFlagTypelink != 0 }
func (s *Sym) Leaf() bool { return s.Flag&SymFlagLeaf != 0 } func (s *Sym) Leaf() bool { return s.Flag&SymFlagLeaf != 0 }
func (s *Sym) CFunc() bool { return s.Flag&SymFlagCFunc != 0 } func (s *Sym) CFunc() bool { return s.Flag&SymFlagCFunc != 0 }
func (s *Sym) ReflectMethod() bool { return s.Flag&SymFlagReflectMethod != 0 } func (s *Sym) ReflectMethod() bool { return s.Flag&SymFlagReflectMethod != 0 }
func (s *Sym) Shared() bool { return s.Flag&SymFlagShared != 0 }
func (s *Sym) TopFrame() bool { return s.Flag&SymFlagTopFrame != 0 } func (s *Sym) TopFrame() bool { return s.Flag&SymFlagTopFrame != 0 }
// Symbol reference. // Symbol reference.
...@@ -596,3 +603,8 @@ func (r *Reader) PcdataBase() uint32 { ...@@ -596,3 +603,8 @@ func (r *Reader) PcdataBase() uint32 {
func (r *Reader) ReadOnly() bool { func (r *Reader) ReadOnly() bool {
return r.readonly return r.readonly
} }
// Flags returns the flag bits read from the object file header.
func (r *Reader) Flags() uint32 {
return r.h.Flags
}
...@@ -35,7 +35,11 @@ func WriteObjFile2(ctxt *Link, b *bio.Writer, pkgpath string) { ...@@ -35,7 +35,11 @@ func WriteObjFile2(ctxt *Link, b *bio.Writer, pkgpath string) {
// Header // Header
// We just reserve the space. We'll fill in the offsets later. // We just reserve the space. We'll fill in the offsets later.
h := goobj2.Header{Magic: goobj2.Magic} flags := uint32(0)
if ctxt.Flag_shared {
flags |= goobj2.ObjFlagShared
}
h := goobj2.Header{Magic: goobj2.Magic, Flags: flags}
h.Write(w.Writer) h.Write(w.Writer)
// String table // String table
...@@ -231,9 +235,6 @@ func (w *writer) Sym(s *LSym) { ...@@ -231,9 +235,6 @@ func (w *writer) Sym(s *LSym) {
if s.ReflectMethod() { if s.ReflectMethod() {
flag |= goobj2.SymFlagReflectMethod flag |= goobj2.SymFlagReflectMethod
} }
if w.ctxt.Flag_shared { // This is really silly
flag |= goobj2.SymFlagShared
}
if s.TopFrame() { if s.TopFrame() {
flag |= goobj2.SymFlagTopFrame flag |= goobj2.SymFlagTopFrame
} }
......
...@@ -57,6 +57,7 @@ type oReader struct { ...@@ -57,6 +57,7 @@ type oReader struct {
*goobj2.Reader *goobj2.Reader
unit *sym.CompilationUnit unit *sym.CompilationUnit
version int // version of static symbol version int // version of static symbol
flags uint32 // read from object file
pkgprefix string pkgprefix string
} }
...@@ -460,7 +461,7 @@ func (l *Loader) Preload(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib * ...@@ -460,7 +461,7 @@ func (l *Loader) Preload(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *
} }
localSymVersion := syms.IncVersion() localSymVersion := syms.IncVersion()
pkgprefix := objabi.PathToPrefix(lib.Pkg) + "." pkgprefix := objabi.PathToPrefix(lib.Pkg) + "."
or := &oReader{r, unit, localSymVersion, pkgprefix} or := &oReader{r, unit, localSymVersion, r.Flags(), pkgprefix}
// Autolib // Autolib
lib.ImportStrings = append(lib.ImportStrings, r.Autolib()...) lib.ImportStrings = append(lib.ImportStrings, r.Autolib()...)
...@@ -770,7 +771,7 @@ func loadObjFull(l *Loader, r *oReader) { ...@@ -770,7 +771,7 @@ func loadObjFull(l *Loader, r *oReader) {
if osym.ReflectMethod() { if osym.ReflectMethod() {
s.Attr |= sym.AttrReflectMethod s.Attr |= sym.AttrReflectMethod
} }
if osym.Shared() { if r.Flags()&goobj2.ObjFlagShared != 0 {
s.Attr |= sym.AttrShared s.Attr |= sym.AttrShared
} }
if osym.TopFrame() { if osym.TopFrame() {
......
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