diff --git a/core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp b/core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp index f7e1cf110..0e9e7244e 100644 --- a/core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp +++ b/core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp @@ -30,9 +30,11 @@ void writeDiagnosticsImports(const std::vector& imports) { void writeGotStub(std::vector& sections, const std::uint32_t targetRva, const std::uint32_t stubRva) { for (auto& section : sections) { - if (targetRva < section.Rva || targetRva - section.Rva > section.Data.size() - 4) + if (section.Data.size() < 8 || targetRva < section.Rva || targetRva - section.Rva > section.Data.size() - 8) continue; - Io::WriteU32(section.Data, targetRva - section.Rva, stubRva); + // A DIR64 base relocation only adds the load delta to the stored value, so the slot must hold the + // preferred-VA form (ImageBase + rva); a bare RVA would end up as (loadBase - ImageBase + rva) at runtime. + Io::WriteU64(section.Data, targetRva - section.Rva, ImageBase + stubRva); return; } throw Domain::RelinkerException("Lazy import GOT slot is not contained in any section", targetRva); @@ -72,12 +74,6 @@ std::vector WindowsPePatcher::Patch(const std::vector WindowsPePatcher::Patch(const std::vector