[llvm] [ORC] Add automatic shared library resolver for unresolved symbols. (PR #148410)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 22:36:51 PDT 2025
================
@@ -0,0 +1,497 @@
+//===- LibraryResolver.h - Automatic Dynamic Library Symbol Resolution -*- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides support for automatically searching symbols across
+// dynamic libraries that have not yet been loaded.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_DYNAMICLOADER_H
+#define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_DYNAMICLOADER_H
+
+#include "llvm/ADT/FunctionExtras.h"
+#include "llvm/ExecutionEngine/Orc/Shared/SymbolFilter.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/LibraryScanner.h"
+#include "llvm/Support/Path.h"
+
+#include <atomic>
+#include <shared_mutex>
+#include <unordered_map>
+
+namespace llvm {
+namespace orc {
+
+/// Manages library metadata and state for symbol resolution.
+///
+/// Tracks libraries by load state and kind (user/system), and stores
+/// associated Bloom filters and hash maps to speed up symbol lookups.
+/// Thread-safe for concurrent access.
+class LibraryManager {
+public:
+ enum class State : uint8_t { Unloaded = 0, Loaded = 1, Queried = 2 };
+
+ class LibraryInfo {
+ public:
+ LibraryInfo(const LibraryInfo &) = delete;
+ LibraryInfo &operator=(const LibraryInfo &) = delete;
+
+ LibraryInfo(std::string filePath, State s, PathType k,
+ std::optional<BloomFilter> filter = std::nullopt)
+ : filePath(std::move(filePath)), state(s), kind(k),
+ filter(std::move(filter)) {}
+
+ StringRef getBasePath() const { return sys::path::parent_path(filePath); }
+ StringRef getFileName() const { return sys::path::filename(filePath); }
+
+ std::string getFullPath() const { return filePath; }
+
+ bool setFilter(BloomFilter F) {
+ std::lock_guard<std::shared_mutex> lock(mutex);
----------------
lhames wrote:
Note: I think that `std::scoped_lock` is preferred to `std::lock_guard` these days. They're equivalent for your purposes though -- if you want to land as is we can replace later in-tree.
https://github.com/llvm/llvm-project/pull/148410
More information about the llvm-commits
mailing list