[lld] lld: Add initial support for GNU LTO format (PR #157175)

Tulio Magno Quites Machado Filho via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 14 13:49:42 PDT 2025


================
@@ -29,32 +30,96 @@
 
 namespace llvm::lto {
 class LTO;
+struct SymbolResolution;
 }
 
 namespace lld::elf {
 struct Ctx;
 class BitcodeFile;
+class ELFFileBase;
 class InputFile;
+class IRFile;
+class BinaryFile;
+
+class IRCompiler {
+protected:
+  Ctx &ctx;
+  llvm::DenseSet<StringRef> thinIndices;
+  llvm::DenseSet<StringRef> usedStartStop;
+  virtual void addObject(IRFile &f,
+                         std::vector<llvm::lto::SymbolResolution> &r) = 0;
+
+public:
+  IRCompiler(Ctx &ctx) : ctx(ctx) {}
+  virtual ~IRCompiler() {};
+  void add(IRFile &f);
+  virtual SmallVector<std::unique_ptr<InputFile>, 0> compile() = 0;
+};
+
+class BitcodeCompiler : public IRCompiler {
+protected:
+  void addObject(IRFile &f,
+                 std::vector<llvm::lto::SymbolResolution> &r) override;
 
-class BitcodeCompiler {
 public:
   BitcodeCompiler(Ctx &ctx);
-  ~BitcodeCompiler();
+  ~BitcodeCompiler() {};
 
-  void add(BitcodeFile &f);
-  SmallVector<std::unique_ptr<InputFile>, 0> compile();
+  void add(BinaryFile &f);
+  SmallVector<std::unique_ptr<InputFile>, 0> compile() override;
 
 private:
-  Ctx &ctx;
   std::unique_ptr<llvm::lto::LTO> ltoObj;
   // An array of (module name, native relocatable file content) pairs.
   SmallVector<std::pair<std::string, SmallString<0>>, 0> buf;
   std::vector<std::unique_ptr<MemoryBuffer>> files;
   SmallVector<std::string, 0> filenames;
-  llvm::DenseSet<StringRef> usedStartStop;
   std::unique_ptr<llvm::raw_fd_ostream> indexFile;
-  llvm::DenseSet<StringRef> thinIndices;
 };
+
+#if LLD_ENABLE_GNU_LTO
+#include <plugin-api.h>
----------------
tuliom wrote:

@tstellar We could build the support for the GNU LTO format on systems without having GNU Binutils installed. This may simplify bootstrapping on some OSes, e.g. when an OS prefers LLVM tools over GNU Binutils.

https://github.com/llvm/llvm-project/pull/157175


More information about the llvm-commits mailing list