From cf93b25366aa418dea3eea49a7b85447631c2a1d Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Thu, 17 Nov 2022 14:41:18 -0500 Subject: cmd/link: revise DLL import symbol handling This patch reworks the handling of DLL import symbols in the PE host object loader to ensure that the Go linker can deal with them properly during internal linking. Prior to this point the strategy was to immediately treat an import symbol reference of the form "__imp__XXX" as if it were a reference to the corresponding DYNIMPORT symbol XXX, except for certain special cases. This worked for the most part, but ran into problems in situations where the target ("XXX") wasn't a previously created DYNIMPORT symbol (and when these problems happened, the root cause was not always easy to see). The new strategy is to not do any renaming or forwarding immediately, but to delay handling until host object loading is complete. At that point we make a scan through the newly introduced text+data sections looking at the relocations that target import symbols, forwarding the references to the corresponding DYNIMPORT sym where appropriate and where there are direct refs to the DYNIMPORT syms, tagging them for stub generation later on. Updates #35006. Updates #53540. Change-Id: I2d42b39141ae150a9f82ecc334001749ae8a3b4a Reviewed-on: https://go-review.googlesource.com/c/go/+/451738 Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: David Chase Run-TryBot: Than McIntosh --- src/cmd/link/internal/ld/lib.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/cmd/link/internal/ld/lib.go') diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index c6410b7c39..d225a8a163 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -711,6 +711,13 @@ func loadWindowsHostArchives(ctxt *Link) { ctxt.loader.SetAttrSpecial(sb.Sym(), true) } } + + // Fix up references to DLL import symbols now that we're done + // pulling in new objects. + if err := loadpe.PostProcessImports(); err != nil { + Errorf(nil, "%v", err) + } + // 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: -- cgit v1.3