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>
This commit is contained in:
Than McIntosh 2023-01-26 15:12:00 -05:00
parent 8fd6cc8bb5
commit 55bd193575
9 changed files with 30 additions and 0 deletions

View file

@ -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.