aboutsummaryrefslogtreecommitdiff
path: root/tools/driver/NativeCompiler.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 08:11:39 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 08:11:39 +0000
commitcd3c09a5c2566d674680193042baf6474b6d0976 (patch)
tree50276c3de1ee4262eccbddb4240bf4267c04a15f /tools/driver/NativeCompiler.cc
parent30fced09675acfd2b9ab6db6be8359a70d3f0402 (diff)
feat(driver): load the embedded C++ runtime into the JIT
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/driver/NativeCompiler.cc')
-rw-r--r--tools/driver/NativeCompiler.cc20
1 files changed, 20 insertions, 0 deletions
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<std::unique_ptr<llvm::MemoryBuffer>> &Archives) {
+ llvm::json::Object *Metadata = nullptr;
+ std::optional<llvm::json::Value> Manifest;
+ llvm::SmallVector<uint8_t, 0> 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<const char *>(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<std::string> &Objects) {
TemporaryDirectory Runtime;