From c58b98b2d617ab2dfe839c4e5ef1e2008c9b60cf Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Mon, 9 Oct 2017 16:04:44 -0400 Subject: cmd/link, runtime: put hasmain bit in moduledata Currently we look to see if the main.main symbol address is in the module data text range. This requires access to the main.main symbol, which usually the runtime has, but does not when building a plugin. To avoid a dynamic relocation to main.main (which I haven't worked out how to have the linker generate on darwin), stop using the symbol. Instead record a boolean in the moduledata if the module has the main function. Fixes #22175 Change-Id: If313a118f17ab499d0a760bbc2519771ed654530 Reviewed-on: https://go-review.googlesource.com/69370 Run-TryBot: David Crawshaw TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/symtab.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/runtime') 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 -- cgit v1.3