aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/link/internal/ld/symtab.go7
-rw-r--r--src/runtime/symtab.go5
2 files changed, 10 insertions, 2 deletions
diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go
index 0a819fcd23..c77298e870 100644
--- a/src/cmd/link/internal/ld/symtab.go
+++ b/src/cmd/link/internal/ld/symtab.go
@@ -641,6 +641,13 @@ func (ctxt *Link) symtab() {
moduledata.AddUint(ctxt.Arch, uint64(len(ctxt.Shlibs)))
}
+ hasmain := ctxt.BuildMode == BuildModeExe || ctxt.BuildMode == BuildModePIE
+ if hasmain {
+ moduledata.AddUint8(1)
+ } else {
+ moduledata.AddUint8(0)
+ }
+
// The rest of moduledata is zero initialized.
// When linking an object that does not contain the runtime we are
// creating the moduledata from scratch and it does not have a
diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go
index 542c29ecd6..2f426c7bf1 100644
--- a/src/runtime/symtab.go
+++ b/src/runtime/symtab.go
@@ -375,6 +375,8 @@ type moduledata struct {
modulename string
modulehashes []modulehash
+ hasmain uint8 // 1 if module contains the main function, 0 otherwise
+
gcdatamask, gcbssmask bitvector
typemap map[typeOff]*_type // offset to *_rtype in previous module
@@ -472,9 +474,8 @@ func modulesinit() {
// contains the main function.
//
// See Issue #18729.
- mainText := funcPC(main_main)
for i, md := range *modules {
- if md.text <= mainText && mainText <= md.etext {
+ if md.hasmain != 0 {
(*modules)[0] = md
(*modules)[i] = &firstmoduledata
break