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
18namespace llvm {
19
20struct NewArchiveMember {
21 std::unique_ptr<MemoryBuffer> Buf;
22 StringRef MemberName;
23 sys::TimePoint<std::chrono::seconds> ModTime;
24 unsigned UID = 0, GID = 0, Perms = 0644;
25
26 NewArchiveMember() = default;
27 NewArchiveMember(MemoryBufferRef BufRef);
28
29 // Detect the archive format from the object or bitcode file. This helps
30 // assume the archive format when creating or editing archives in the case
31 // one isn't explicitly set.
32 object::Archive::Kind detectKindFromObject() const;
33
34 static Expected<NewArchiveMember>
35 getOldMember(const object::Archive::Child &OldMember, bool Deterministic);
36
37 static Expected<NewArchiveMember> getFile(StringRef FileName,
38 bool Deterministic);
39};
40
41Expected<std::string> computeArchiveRelativePath(StringRef From, StringRef To);
42
43enum class SymtabWritingMode {
44 NoSymtab, // Do not write symbol table.
45 NormalSymtab, // Write symbol table. For the Big Archive format, write both
46 // 32-bit and 64-bit symbol tables.
47 BigArchive32, // Only write the 32-bit symbol table.
48 BigArchive64 // Only write the 64-bit symbol table.
49};
50
51Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
52 SymtabWritingMode WriteSymtab, object::Archive::Kind Kind,
53 bool Deterministic, bool Thin,
54 std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr,
55 bool IsEC = false);
56
57// writeArchiveToBuffer is similar to writeArchive but returns the Archive in a
58// buffer instead of writing it out to a file.
59Expected<std::unique_ptr<MemoryBuffer>>
60writeArchiveToBuffer(ArrayRef<NewArchiveMember> NewMembers,
61 SymtabWritingMode WriteSymtab, object::Archive::Kind Kind,
62 bool Deterministic, bool Thin);
63}
64
65#endif
66

source code of llvm/include/llvm/Object/ArchiveWriter.h