]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: resolve __CTOR_LIST__/__DTOR_LIST__ refs for PE
authorThan McIntosh <thanm@google.com>
Mon, 7 Feb 2022 20:30:34 +0000 (15:30 -0500)
committerThan McIntosh <thanm@google.com>
Thu, 31 Mar 2022 14:57:20 +0000 (14:57 +0000)
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 <cherryyz@google.com>
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/link/internal/ld/lib.go

index 7c9ec4e107283f9ef140ae5dd6d3ed75c243f068..6f9c7c26272c3873f8641dbe177b5689f6cfcd6b 100644 (file)
@@ -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: