================
@@ -0,0 +1,115 @@
+//===- ArchiveLinker.h - Archive member selection for offloading -*- 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 declares shared functionality for linking static libraries
+// (archives) in offloading tools. It provides a symbol-driven fixed-point
+// archive member selection algorithm used by both clang-nvlink-wrapper and
+// clang-sycl-linker.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_FRONTEND_OFFLOADING_ARCHIVELINKER_H
+#define LLVM_FRONTEND_OFFLOADING_ARCHIVELINKER_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Object/IRSymtab.h"
+#include "llvm/Object/SymbolicFile.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBufferRef.h"
+#include <functional>
+#include <memory>
+
+namespace llvm {
+class MemoryBuffer;
+
+namespace object {
+class SymbolRef;
+} // namespace object
+
+namespace offloading {
+
+/// A minimum symbol interface that provides the necessary information to
+/// extract archive members and resolve LTO symbols.
+struct Symbol {
+ enum Flags {
+ None = 0,
+ Undefined = 1 << 0,
+ Weak = 1 << 1,
+ };
+
+ Symbol() : File(), SymFlags(None), UsedInRegularObj(false) {}
+ Symbol(Symbol::Flags F) : File(), SymFlags(F), UsedInRegularObj(true) {}
+
+ Symbol(MemoryBufferRef File, const irsymtab::Reader::SymbolRef Sym)
+ : File(File), SymFlags(0), UsedInRegularObj(false) {
+ if (Sym.isUndefined())
+ SymFlags |= Undefined;
+ if (Sym.isWeak())
+ SymFlags |= Weak;
+ }
+
+ /// Create a Symbol from an object file symbol reference.
+ /// Returns an error if symbol flags cannot be retrieved.
+ static Expected<Symbol> createFromObject(MemoryBufferRef File,
+ const object::SymbolRef &Sym);
+
+ bool isWeak() const { return SymFlags & Weak; }
+ bool isUndefined() const { return SymFlags & Undefined; }
+
+ MemoryBufferRef File;
+ uint32_t SymFlags;
+ bool UsedInRegularObj;
+};
+
+/// Description of a single input (file or library).
+struct InputDesc {
+ StringRef Value; // file path, or library name for -l (the value after -l)
+ enum KindTy { File, Library } Kind;
----------------
YuriPlyakhin wrote:
```suggestion
enum class KindTy { File, Library } Kind;
```
https://github.com/llvm/llvm-project/pull/201253
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits