diff --git a/src/runtime/proc.go b/src/runtime/proc.go index e596cab9bd..7b6183d905 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -99,6 +99,11 @@ func main() { needUnlock = false unlockOSThread() + if isarchive { + // A program compiled with -buildmode=c-archive has a main, + // but it is not executed. + return + } main_main() if raceenabled { racefini() diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 842ebe52f5..1f4f0daec4 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -621,9 +621,12 @@ var ( cpuid_ecx uint32 cpuid_edx uint32 lfenceBeforeRdtsc bool +) - // Set by the linker when linking with -shared. - islibrary bool +// Set by the linker so the runtime can determine the buildmode. +var ( + islibrary bool // -buildmode=c-shared + isarchive bool // -buildmode=c-archive ) /*