Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:17

0001 //===- ArchiveWriter.h - ar archive file format writer ----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Declares the writeArchive function for writing an archive file.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_OBJECT_ARCHIVEWRITER_H
0014 #define LLVM_OBJECT_ARCHIVEWRITER_H
0015 
0016 #include "llvm/Object/Archive.h"
0017 
0018 namespace llvm {
0019 
0020 struct NewArchiveMember {
0021   std::unique_ptr<MemoryBuffer> Buf;
0022   StringRef MemberName;
0023   sys::TimePoint<std::chrono::seconds> ModTime;
0024   unsigned UID = 0, GID = 0, Perms = 0644;
0025 
0026   NewArchiveMember() = default;
0027   NewArchiveMember(MemoryBufferRef BufRef);
0028 
0029   // Detect the archive format from the object or bitcode file. This helps
0030   // assume the archive format when creating or editing archives in the case
0031   // one isn't explicitly set.
0032   object::Archive::Kind detectKindFromObject() const;
0033 
0034   static Expected<NewArchiveMember>
0035   getOldMember(const object::Archive::Child &OldMember, bool Deterministic);
0036 
0037   static Expected<NewArchiveMember> getFile(StringRef FileName,
0038                                             bool Deterministic);
0039 };
0040 
0041 Expected<std::string> computeArchiveRelativePath(StringRef From, StringRef To);
0042 
0043 enum class SymtabWritingMode {
0044   NoSymtab,     // Do not write symbol table.
0045   NormalSymtab, // Write symbol table. For the Big Archive format, write both
0046                 // 32-bit and 64-bit symbol tables.
0047   BigArchive32, // Only write the 32-bit symbol table.
0048   BigArchive64  // Only write the 64-bit symbol table.
0049 };
0050 
0051 void warnToStderr(Error Err);
0052 
0053 // Write an archive directly to an output stream.
0054 Error writeArchiveToStream(raw_ostream &Out,
0055                            ArrayRef<NewArchiveMember> NewMembers,
0056                            SymtabWritingMode WriteSymtab,
0057                            object::Archive::Kind Kind, bool Deterministic,
0058                            bool Thin, std::optional<bool> IsEC = std::nullopt,
0059                            function_ref<void(Error)> Warn = warnToStderr);
0060 
0061 Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
0062                    SymtabWritingMode WriteSymtab, object::Archive::Kind Kind,
0063                    bool Deterministic, bool Thin,
0064                    std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr,
0065                    std::optional<bool> IsEC = std::nullopt,
0066                    function_ref<void(Error)> Warn = warnToStderr);
0067 
0068 // writeArchiveToBuffer is similar to writeArchive but returns the Archive in a
0069 // buffer instead of writing it out to a file.
0070 Expected<std::unique_ptr<MemoryBuffer>>
0071 writeArchiveToBuffer(ArrayRef<NewArchiveMember> NewMembers,
0072                      SymtabWritingMode WriteSymtab, object::Archive::Kind Kind,
0073                      bool Deterministic, bool Thin,
0074                      function_ref<void(Error)> Warn = warnToStderr);
0075 }
0076 
0077 #endif