-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm][object] Expose writeArchiveToStream
#98254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This internal helper is a useful API to have, when one wants to write an archive directly to some other preallocated stream.
@llvm/pr-subscribers-llvm-binary-utilities Author: Jeff Niu (Mogball) ChangesThis internal helper is a useful API to have, when one wants to write an archive directly to some other preallocated stream. Full diff: https://github.com/llvm/llvm-project/pull/98254.diff 2 Files Affected:
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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mogball, why was a PR created for this and then immediately merged? Just trying to understand what you're trying to achieve.
Hey thanks for taking a look! I found it odd that the only exposed APIs for writing a new archive were directly to a file or to a memory buffer. I have a use case where it would be more efficient to write directly to a stream to avoid copying out of the memory buffer. If you're not happy with this change, I'm more than willing to revert it for now |
No, I'm fine with the change actually (though I'd consider whether there's a way of having in-tree tests), but usually if you're putting something up for review, you don't immediately merge it into main before anybody has a chance to give that input, while if you think it doesn't need pre-commit review, you just push it directly without creating a PR, so I'm questioning the process you've gone through rather than the change itself. |
Thanks for letting me know! I'll be more mindful in the future. I can add a unit test as well |
This is documented here, btw: https://llvm.org/docs/CodeReview.html#code-review-workflow - if you did want to use a PR to run presubmits, there's a label you can apply that's just for documentation (in theory we could perhaps make the label suppress sending some notification emails, but haven't done that) so folks know your intent isn't to ask for precommit review/you believe this meets the bar (see documentation) for post-commit review. |
I am also fine with exposing the API. If this helps some projects you are working on, it's best to mention the use case, though. |
This internal helper is a useful API to have, when one wants to write an archive directly to some other preallocated stream.
This internal helper is a useful API to have, when one wants to write an archive directly to some other preallocated stream.