aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/runtime/symtab.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go
index f52190661c..ed82783ca9 100644
--- a/src/runtime/symtab.go
+++ b/src/runtime/symtab.go
@@ -285,6 +285,25 @@ func modulesinit() {
md.gcbssmask = progToPointerMask((*byte)(unsafe.Pointer(md.gcbss)), md.ebss-md.bss)
}
}
+
+ // Modules appear in the moduledata linked list in the order they are
+ // loaded by the dynamic loader, with one exception: the
+ // firstmoduledata itself the module that contains the runtime. This
+ // is not always the first module (when using -buildmode=shared, it
+ // is typically libstd.so, the second module). The order matters for
+ // typelinksinit, so we swap the first module with whatever module
+ // contains the main function.
+ //
+ // See Issue #18729.
+ mainText := funcPC(main_main)
+ for i, md := range *modules {
+ if md.text <= mainText && mainText <= md.etext {
+ (*modules)[0] = md
+ (*modules)[i] = &firstmoduledata
+ break
+ }
+ }
+
atomicstorep(unsafe.Pointer(&modulesSlice), unsafe.Pointer(modules))
}