aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2023-01-26 15:12:00 -0500
committerThan McIntosh <thanm@google.com>2023-02-06 20:25:30 +0000
commit55bd193575152ea09db3a0bd33f9dda49725d8f4 (patch)
treeacf08121305305be3b4368f88f72b5daa98ca8fe /src/cmd/internal/obj
parent8fd6cc8bb51ff09990ab13422ef66e18e9295911 (diff)
downloadgo-55bd193575152ea09db3a0bd33f9dda49725d8f4.tar.xz
cmd/internal/obj: flag init functions in object file
Introduce a flag in the object file indicating whether a given function corresponds to a compiler-generated (not user-written) init function, such as "os.init" or "syscall.init". Add code to the compiler to fill in the correct value for the flag, and add support to the loader package in the linker for testing the flag. The new loader API is currently unused, but will be needed in the next CL in this stack. Updates #2559. Updates #36021. Updates #14840. Change-Id: Iea7ad2adda487e4af7a44f062f9817977c53b394 Reviewed-on: https://go-review.googlesource.com/c/go/+/463855 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/internal/obj')
-rw-r--r--src/cmd/internal/obj/link.go5
-rw-r--r--src/cmd/internal/obj/objfile.go3
-rw-r--r--src/cmd/internal/obj/plist.go1
-rw-r--r--src/cmd/internal/obj/textflag.go3
4 files changed, 12 insertions, 0 deletions
diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go
index 6d40b334af..d153afbfae 100644
--- a/src/cmd/internal/obj/link.go
+++ b/src/cmd/internal/obj/link.go
@@ -724,6 +724,9 @@ const (
// IsPcdata indicates this is a pcdata symbol.
AttrPcdata
+ // PkgInit indicates this is a compiler-generated package init func.
+ AttrPkgInit
+
// attrABIBase is the value at which the ABI is encoded in
// Attribute. This must be last; all bits after this are
// assumed to be an ABI value.
@@ -752,6 +755,7 @@ func (a *Attribute) UsedInIface() bool { return a.load()&AttrUsedInIface
func (a *Attribute) ContentAddressable() bool { return a.load()&AttrContentAddressable != 0 }
func (a *Attribute) ABIWrapper() bool { return a.load()&AttrABIWrapper != 0 }
func (a *Attribute) IsPcdata() bool { return a.load()&AttrPcdata != 0 }
+func (a *Attribute) IsPkgInit() bool { return a.load()&AttrPkgInit != 0 }
func (a *Attribute) Set(flag Attribute, value bool) {
for {
@@ -800,6 +804,7 @@ var textAttrStrings = [...]struct {
{bit: AttrIndexed, s: ""},
{bit: AttrContentAddressable, s: ""},
{bit: AttrABIWrapper, s: "ABIWRAPPER"},
+ {bit: AttrPkgInit, s: "PKGINIT"},
}
// String formats a for printing in as part of a TEXT prog.
diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go
index 85e49e248c..73c29d9686 100644
--- a/src/cmd/internal/obj/objfile.go
+++ b/src/cmd/internal/obj/objfile.go
@@ -344,6 +344,9 @@ func (w *writer) Sym(s *LSym) {
if strings.HasPrefix(s.Name, w.ctxt.Pkgpath) && strings.HasPrefix(s.Name[len(w.ctxt.Pkgpath):], ".") && strings.HasPrefix(s.Name[len(w.ctxt.Pkgpath)+1:], objabi.GlobalDictPrefix) {
flag2 |= goobj.SymFlagDict
}
+ if s.IsPkgInit() {
+ flag2 |= goobj.SymFlagPkgInit
+ }
name := s.Name
if strings.HasPrefix(name, "gofile..") {
name = filepath.ToSlash(name)
diff --git a/src/cmd/internal/obj/plist.go b/src/cmd/internal/obj/plist.go
index fe9d2e1fb7..835f37f2ff 100644
--- a/src/cmd/internal/obj/plist.go
+++ b/src/cmd/internal/obj/plist.go
@@ -193,6 +193,7 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int, start src.XPos) {
s.Set(AttrABIWrapper, flag&ABIWRAPPER != 0)
s.Set(AttrNeedCtxt, flag&NEEDCTXT != 0)
s.Set(AttrNoFrame, flag&NOFRAME != 0)
+ s.Set(AttrPkgInit, flag&PKGINIT != 0)
s.Type = objabi.STEXT
ctxt.Text = append(ctxt.Text, s)
diff --git a/src/cmd/internal/obj/textflag.go b/src/cmd/internal/obj/textflag.go
index 5ae75027c2..bf9c8c99f1 100644
--- a/src/cmd/internal/obj/textflag.go
+++ b/src/cmd/internal/obj/textflag.go
@@ -55,4 +55,7 @@ const (
// Function is an ABI wrapper.
ABIWRAPPER = 4096
+
+ // Function is a compiler-generated package init function.
+ PKGINIT = 8192
)