1 //===- ArchiveWriter.h - ar archive file format writer ----------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Declares the writeArchive function for writing an archive file. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_OBJECT_ARCHIVEWRITER_H 14 #define LLVM_OBJECT_ARCHIVEWRITER_H 15 16 #include "llvm/Object/Archive.h" 17 #include "llvm/Support/Compiler.h" 18 19 namespace llvm { 20 21 struct NewArchiveMember { 22 std::unique_ptr<MemoryBuffer> Buf; 23 StringRef MemberName; 24 sys::TimePoint<std::chrono::seconds> ModTime; 25 unsigned UID = 0, GID = 0, Perms = 0644; 26 27 NewArchiveMember() = default; 28 LLVM_ABI NewArchiveMember(MemoryBufferRef BufRef); 29 30 // Detect the archive format from the object or bitcode file. This helps 31 // assume the archive format when creating or editing archives in the case 32 // one isn't explicitly set. 33 LLVM_ABI object::Archive::Kind detectKindFromObject() const; 34 35 LLVM_ABI static Expected<NewArchiveMember> 36 getOldMember(const object::Archive::Child &OldMember, bool Deterministic); 37 38 LLVM_ABI static Expected<NewArchiveMember> getFile(StringRef FileName, 39 bool Deterministic); 40 }; 41 42 LLVM_ABI Expected<std::string> computeArchiveRelativePath(StringRef From, 43 StringRef To); 44 45 enum class SymtabWritingMode { 46 NoSymtab, // Do not write symbol table. 47 NormalSymtab, // Write symbol table. For the Big Archive format, write both 48 // 32-bit and 64-bit symbol tables. 49 BigArchive32, // Only write the 32-bit symbol table. 50 BigArchive64 // Only write the 64-bit symbol table. 51 }; 52 53 LLVM_ABI void warnToStderr(Error Err); 54 55 // Write an archive directly to an output stream. 56 LLVM_ABI Error writeArchiveToStream( 57 raw_ostream &Out, ArrayRef<NewArchiveMember> NewMembers, 58 SymtabWritingMode WriteSymtab, object::Archive::Kind Kind, 59 bool Deterministic, bool Thin, std::optional<bool> IsEC = std::nullopt, 60 function_ref<void(Error)> Warn = warnToStderr); 61 62 LLVM_ABI Error 63 writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers, 64 SymtabWritingMode WriteSymtab, object::Archive::Kind Kind, 65 bool Deterministic, bool Thin, 66 std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr, 67 std::optional<bool> IsEC = std::nullopt, 68 function_ref<void(Error)> Warn = warnToStderr); 69 70 // writeArchiveToBuffer is similar to writeArchive but returns the Archive in a 71 // buffer instead of writing it out to a file. 72 LLVM_ABI Expected<std::unique_ptr<MemoryBuffer>> 73 writeArchiveToBuffer(ArrayRef<NewArchiveMember> NewMembers, 74 SymtabWritingMode WriteSymtab, object::Archive::Kind Kind, 75 bool Deterministic, bool Thin, 76 function_ref<void(Error)> Warn = warnToStderr); 77 } 78 79 #endif 80