aboutsummaryrefslogtreecommitdiff
path: root/tools/driver
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-19 10:51:13 +0000
committer_ov4 <ov4@ov4.org>2026-10-19 10:51:13 +0000
commitcf0fb69b3d489cd0aebaa2d759b2d2c0c4e230b1 (patch)
tree477fef3a8f50bb6c49d45af53012be1383eee046 /tools/driver
parenteaabdf5796594be87084758fa524622db1c1dbaa (diff)
fix(driver): normalize MinGW JIT archive symbol definitions
Make absolute-zero pure virtual fallbacks local and compute runtime archive interfaces from normalized objects so ORC definitions match JITLink. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/driver')
-rw-r--r--tools/driver/EmbeddedRunner.cc15
-rw-r--r--tools/driver/MinGWCOFF.h12
2 files changed, 26 insertions, 1 deletions
diff --git a/tools/driver/EmbeddedRunner.cc b/tools/driver/EmbeddedRunner.cc
index 28fe2db..c8c3fcd 100644
--- a/tools/driver/EmbeddedRunner.cc
+++ b/tools/driver/EmbeddedRunner.cc
@@ -5,6 +5,7 @@
#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
#include "llvm/Support/Error.h"
@@ -439,6 +440,18 @@ static llvm::Error loadCxxRuntime(llvm::orc::LLJIT &J) {
if (!unpackCxxRuntime(Archives))
return llvm::make_error<llvm::StringError>("cannot unpack the C++ runtime", llvm::inconvertibleErrorCode());
for (auto &Archive : Archives) {
+ llvm::orc::StaticLibraryDefinitionGenerator::GetObjectFileInterface GetInterface;
+#if defined(_WIN32) && defined(__x86_64__)
+ // Match the normalized object that MinGWObjectLinkingLayer::emit links.
+ GetInterface = [](llvm::orc::ExecutionSession &ES, llvm::MemoryBufferRef Ref)
+ -> llvm::Expected<llvm::orc::MaterializationUnit::Interface> {
+ auto Normalized = normalizeMinGWObject(
+ llvm::MemoryBuffer::getMemBuffer(Ref, false));
+ if (!Normalized)
+ return Normalized.takeError();
+ return llvm::orc::getObjectFileInterface(ES, (*Normalized)->getMemBufferRef());
+ };
+#endif
auto Generator = llvm::orc::StaticLibraryDefinitionGenerator::Create(
J.getObjLinkingLayer(), std::move(Archive),
[](llvm::object::Archive &, llvm::MemoryBufferRef Buffer, size_t) -> llvm::Expected<bool> {
@@ -458,7 +471,7 @@ static llvm::Error loadCxxRuntime(llvm::orc::LLJIT &J) {
N.starts_with("_Unwind_") || N == "_ZTIi") return false;
}
return true;
- });
+ }, std::move(GetInterface));
if (!Generator) return Generator.takeError();
J.getMainJITDylib().addGenerator(std::move(*Generator));
}
diff --git a/tools/driver/MinGWCOFF.h b/tools/driver/MinGWCOFF.h
index 186d981..555dcc8 100644
--- a/tools/driver/MinGWCOFF.h
+++ b/tools/driver/MinGWCOFF.h
@@ -50,6 +50,7 @@ normalizeMinGWObject(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
struct Association { size_t Offset; int32_t Parent; };
SmallVector<Association, 16> Associations;
SmallVector<size_t, 2> PureVirtualReferences;
+ SmallVector<size_t, 2> PureVirtualFallbacks;
for (const auto &Symbol : COFF->symbols()) {
auto Sym = COFF->getCOFFSymbol(Symbol);
if (auto *Weak = Sym.getWeakExternal()) {
@@ -68,6 +69,13 @@ normalizeMinGWObject(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
? offsetof(object::coff_symbol32, StorageClass)
: offsetof(object::coff_symbol16, StorageClass);
PureVirtualReferences.push_back(Offset);
+ size_t FallbackOffset =
+ reinterpret_cast<const char *>(Fallback->getRawPtr()) -
+ Buffer->getBufferStart();
+ FallbackOffset += Fallback->isBigObj()
+ ? offsetof(object::coff_symbol32, StorageClass)
+ : offsetof(object::coff_symbol16, StorageClass);
+ PureVirtualFallbacks.push_back(FallbackOffset);
}
}
}
@@ -118,6 +126,10 @@ normalizeMinGWObject(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
// entry count intact so the remaining symbol indices do not move.
for (size_t Offset : PureVirtualReferences)
Copy->getBufferStart()[Offset] = COFF::IMAGE_SYM_CLASS_EXTERNAL;
+ // Only the now-unused weak auxiliary record references the fallback.
+ // Keep it local so archive interfaces do not advertise a global definition.
+ for (size_t Offset : PureVirtualFallbacks)
+ Copy->getBufferStart()[Offset] = COFF::IMAGE_SYM_CLASS_STATIC;
return std::unique_ptr<MemoryBuffer>(std::move(Copy));
}