From cd3c09a5c2566d674680193042baf6474b6d0976 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 08:11:39 +0000 Subject: feat(driver): load the embedded C++ runtime into the JIT Co-Authored-By: Claude Opus 5.5 --- tools/driver/NativeCompiler.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tools/driver/NativeCompiler.cc') diff --git a/tools/driver/NativeCompiler.cc b/tools/driver/NativeCompiler.cc index 4547203..e09fe98 100644 --- a/tools/driver/NativeCompiler.cc +++ b/tools/driver/NativeCompiler.cc @@ -180,6 +180,26 @@ bool collectLibcSymbols(llvm::StringSet<> &Out) { return true; } +bool unpackCxxRuntime(std::vector> &Archives) { + llvm::json::Object *Metadata = nullptr; + std::optional Manifest; + llvm::SmallVector Data; + if (!unpackRuntime(Metadata, Manifest, Data)) return false; + for (const auto &Entry : *Metadata->getArray("files")) { + const auto &File = *Entry.getAsObject(); + llvm::StringRef Path = *File.getString("path"); + llvm::StringRef Name = llvm::sys::path::filename(Path); + // The unwind and C libraries continue to come from the host process. + if (*File.getBoolean("script") || + !(Name == "libstdc++.a" || Name == "libc++.a" || Name == "libc++abi.a" || + Name == "libgcc.a" || Name == "libmingwex.a" || Name == "libm.a")) continue; + llvm::StringRef Contents(reinterpret_cast(Data.data()) + + *File.getInteger("offset"), *File.getInteger("size")); + Archives.push_back(llvm::MemoryBuffer::getMemBufferCopy(Contents, Path)); + } + return true; +} + bool compileNative(const cps::CodeGen &CG, llvm::StringRef OutputPath, const char *Argv0, const std::vector &Objects) { TemporaryDirectory Runtime; -- cgit v1.3.1-4-g156e