From cdee8004ab5fa71d705979eaaee0948200256ed0 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Mon, 7 Feb 2022 15:30:34 -0500 Subject: [PATCH] cmd/link: resolve __CTOR_LIST__/__DTOR_LIST__ refs for PE When doing an internal link on Windows, it's possible to see unresolved references to the symbols "__CTOR_LIST__" and/or "__DTOR_LIST__" (which are needed in some circumstances). If these are still unresolved at the point where we're done reading host objects, then synthesize dummy versions of them. Updates #35006. Change-Id: I408bf18499bba05752710cf5a41621123bd84a3b Reviewed-on: https://go-review.googlesource.com/c/go/+/383836 Reviewed-by: Cherry Mui Trust: Than McIntosh Run-TryBot: Than McIntosh TryBot-Result: Gopher Robot --- src/cmd/link/internal/ld/lib.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 7c9ec4e107..6f9c7c2627 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -665,6 +665,21 @@ func loadWindowsHostArchives(ctxt *Link) { any = true } } + // If needed, create the __CTOR_LIST__ and __DTOR_LIST__ + // symbols (referenced by some of the mingw support library + // routines). Creation of these symbols is normally done by the + // linker if not already present. + want := []string{"__CTOR_LIST__", "__DTOR_LIST__"} + isunresolved := symbolsAreUnresolved(ctxt, want) + for k, w := range want { + if isunresolved[k] { + sb := ctxt.loader.CreateSymForUpdate(w, 0) + sb.SetType(sym.SDATA) + sb.AddUint64(ctxt.Arch, 0) + sb.SetReachable(true) + ctxt.loader.SetAttrSpecial(sb.Sym(), true) + } + } // TODO: maybe do something similar to peimporteddlls to collect // all lib names and try link them all to final exe just like // libmingwex.a and libmingw32.a: