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 <cherryyz@google.com>
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Than McIntosh 2022-02-07 15:30:34 -05:00
parent 2ea9376266
commit cdee8004ab

View File

@ -665,6 +665,21 @@ func loadWindowsHostArchives(ctxt *Link) {
any = true 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 // TODO: maybe do something similar to peimporteddlls to collect
// all lib names and try link them all to final exe just like // all lib names and try link them all to final exe just like
// libmingwex.a and libmingw32.a: // libmingwex.a and libmingw32.a: