[llvm] [llvm][object] Expose `writeArchiveToStream` (PR #98254)

Jeff Niu via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 17:25:43 PDT 2024


https://github.com/Mogball created https://github.com/llvm/llvm-project/pull/98254

This internal helper is a useful API to have, when one wants to write an archive directly to some other preallocated stream.

>From bbfcdd0f9fb0356f8e011c621be7b15f38cce86d Mon Sep 17 00:00:00 2001
From: Mogball <jeff at modular.com>
Date: Tue, 9 Jul 2024 17:22:32 -0700
Subject: [PATCH] [llvm][object] Expose `writeArchiveToStream`

This internal helper is a useful API to have, when one wants to write an
archive directly to some other preallocated stream.
---
 llvm/include/llvm/Object/ArchiveWriter.h | 7 +++++++
 llvm/lib/Object/ArchiveWriter.cpp        | 9 +++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/Object/ArchiveWriter.h b/llvm/include/llvm/Object/ArchiveWriter.h
index a19f8fcc79d74..e41b3d51173d4 100644
--- a/llvm/include/llvm/Object/ArchiveWriter.h
+++ b/llvm/include/llvm/Object/ArchiveWriter.h
@@ -48,6 +48,13 @@ enum class SymtabWritingMode {
   BigArchive64  // Only write the 64-bit symbol table.
 };
 
+// Write an archive directly to an output stream.
+Error writeArchiveToStream(raw_ostream &Out,
+                           ArrayRef<NewArchiveMember> NewMembers,
+                           SymtabWritingMode WriteSymtab,
+                           object::Archive::Kind Kind, bool Deterministic,
+                           bool Thin, std::optional<bool> IsEC = std::nullopt);
+
 Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
                    SymtabWritingMode WriteSymtab, object::Archive::Kind Kind,
                    bool Deterministic, bool Thin,
diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index 913b74c110b36..34f12cf0111cf 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -997,10 +997,11 @@ Expected<std::string> computeArchiveRelativePath(StringRef From, StringRef To) {
   return std::string(Relative);
 }
 
-static Error
-writeArchiveToStream(raw_ostream &Out, ArrayRef<NewArchiveMember> NewMembers,
-                     SymtabWritingMode WriteSymtab, object::Archive::Kind Kind,
-                     bool Deterministic, bool Thin, std::optional<bool> IsEC) {
+Error writeArchiveToStream(raw_ostream &Out,
+                           ArrayRef<NewArchiveMember> NewMembers,
+                           SymtabWritingMode WriteSymtab,
+                           object::Archive::Kind Kind, bool Deterministic,
+                           bool Thin, std::optional<bool> IsEC) {
   assert((!Thin || !isBSDLike(Kind)) && "Only the gnu format has a thin mode");
 
   SmallString<0> SymNamesBuf;



More information about the llvm-commits mailing list