LLVM  6.0.0svn
ArchiveWriter.cpp
Go to the documentation of this file.
1 //===- ArchiveWriter.cpp - ar File Format implementation --------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the writeArchive function.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/StringRef.h"
18 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/Object/Archive.h"
20 #include "llvm/Object/ObjectFile.h"
23 #include "llvm/Support/Errc.h"
25 #include "llvm/Support/Format.h"
26 #include "llvm/Support/Path.h"
29 
30 #if !defined(_MSC_VER) && !defined(__MINGW32__)
31 #include <unistd.h>
32 #else
33 #include <io.h>
34 #endif
35 
36 using namespace llvm;
37 
39  : Buf(MemoryBuffer::getMemBuffer(BufRef, false)),
40  MemberName(BufRef.getBufferIdentifier()) {}
41 
44  bool Deterministic) {
46  if (!BufOrErr)
47  return BufOrErr.takeError();
48 
50  assert(M.IsNew == false);
51  M.Buf = MemoryBuffer::getMemBuffer(*BufOrErr, false);
52  M.MemberName = M.Buf->getBufferIdentifier();
53  if (!Deterministic) {
54  auto ModTimeOrErr = OldMember.getLastModified();
55  if (!ModTimeOrErr)
56  return ModTimeOrErr.takeError();
57  M.ModTime = ModTimeOrErr.get();
58  Expected<unsigned> UIDOrErr = OldMember.getUID();
59  if (!UIDOrErr)
60  return UIDOrErr.takeError();
61  M.UID = UIDOrErr.get();
62  Expected<unsigned> GIDOrErr = OldMember.getGID();
63  if (!GIDOrErr)
64  return GIDOrErr.takeError();
65  M.GID = GIDOrErr.get();
66  Expected<sys::fs::perms> AccessModeOrErr = OldMember.getAccessMode();
67  if (!AccessModeOrErr)
68  return AccessModeOrErr.takeError();
69  M.Perms = AccessModeOrErr.get();
70  }
71  return std::move(M);
72 }
73 
75  bool Deterministic) {
76  sys::fs::file_status Status;
77  int FD;
78  if (auto EC = sys::fs::openFileForRead(FileName, FD))
79  return errorCodeToError(EC);
80  assert(FD != -1);
81 
82  if (auto EC = sys::fs::status(FD, Status))
83  return errorCodeToError(EC);
84 
85  // Opening a directory doesn't make sense. Let it fail.
86  // Linux cannot open directories with open(2), although
87  // cygwin and *bsd can.
90 
91  ErrorOr<std::unique_ptr<MemoryBuffer>> MemberBufferOrErr =
92  MemoryBuffer::getOpenFile(FD, FileName, Status.getSize(), false);
93  if (!MemberBufferOrErr)
94  return errorCodeToError(MemberBufferOrErr.getError());
95 
96  if (close(FD) != 0)
97  return errorCodeToError(std::error_code(errno, std::generic_category()));
98 
100  M.IsNew = true;
101  M.Buf = std::move(*MemberBufferOrErr);
102  M.MemberName = M.Buf->getBufferIdentifier();
103  if (!Deterministic) {
104  M.ModTime = std::chrono::time_point_cast<std::chrono::seconds>(
105  Status.getLastModificationTime());
106  M.UID = Status.getUser();
107  M.GID = Status.getGroup();
108  M.Perms = Status.permissions();
109  }
110  return std::move(M);
111 }
112 
113 template <typename T>
114 static void printWithSpacePadding(raw_ostream &OS, T Data, unsigned Size) {
115  uint64_t OldPos = OS.tell();
116  OS << Data;
117  unsigned SizeSoFar = OS.tell() - OldPos;
118  assert(SizeSoFar <= Size && "Data doesn't fit in Size");
119  OS.indent(Size - SizeSoFar);
120 }
121 
123  switch (Kind) {
126  return false;
129  return true;
132  break;
133  }
134  llvm_unreachable("not supported for writting");
135 }
136 
137 template <class T>
138 static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val) {
139  if (isBSDLike(Kind))
141  else
143 }
144 
147  unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
148  printWithSpacePadding(Out, sys::toTimeT(ModTime), 12);
149 
150  // The format has only 6 chars for uid and gid. Truncate if the provided
151  // values don't fit.
152  printWithSpacePadding(Out, UID % 1000000, 6);
153  printWithSpacePadding(Out, GID % 1000000, 6);
154 
155  printWithSpacePadding(Out, format("%o", Perms), 8);
156  printWithSpacePadding(Out, Size, 10);
157  Out << "`\n";
158 }
159 
160 static void
163  unsigned UID, unsigned GID, unsigned Perms,
164  unsigned Size) {
165  printWithSpacePadding(Out, Twine(Name) + "/", 16);
166  printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, Size);
167 }
168 
169 static void
172  unsigned UID, unsigned GID, unsigned Perms,
173  unsigned Size) {
174  uint64_t PosAfterHeader = Pos + 60 + Name.size();
175  // Pad so that even 64 bit object files are aligned.
176  unsigned Pad = OffsetToAlignment(PosAfterHeader, 8);
177  unsigned NameWithPadding = Name.size() + Pad;
178  printWithSpacePadding(Out, Twine("#1/") + Twine(NameWithPadding), 16);
179  printRestOfMemberHeader(Out, ModTime, UID, GID, Perms,
180  NameWithPadding + Size);
181  Out << Name;
182  while (Pad--)
183  Out.write(uint8_t(0));
184 }
185 
186 static bool useStringTable(bool Thin, StringRef Name) {
187  return Thin || Name.size() >= 16 || Name.contains('/');
188 }
189 
190 // Compute the relative path from From to To.
191 static std::string computeRelativePath(StringRef From, StringRef To) {
193  return To;
194 
195  StringRef DirFrom = sys::path::parent_path(From);
196  auto FromI = sys::path::begin(DirFrom);
197  auto ToI = sys::path::begin(To);
198  while (*FromI == *ToI) {
199  ++FromI;
200  ++ToI;
201  }
202 
203  SmallString<128> Relative;
204  for (auto FromE = sys::path::end(DirFrom); FromI != FromE; ++FromI)
205  sys::path::append(Relative, "..");
206 
207  for (auto ToE = sys::path::end(To); ToI != ToE; ++ToI)
208  sys::path::append(Relative, *ToI);
209 
210 #ifdef LLVM_ON_WIN32
211  // Replace backslashes with slashes so that the path is portable between *nix
212  // and Windows.
213  std::replace(Relative.begin(), Relative.end(), '\\', '/');
214 #endif
215 
216  return Relative.str();
217 }
218 
220  switch (Kind) {
225  return false;
228  return true;
229  }
230  llvm_unreachable("not supported for writting");
231 }
232 
233 static void addToStringTable(raw_ostream &Out, StringRef ArcName,
234  const NewArchiveMember &M, bool Thin) {
235  StringRef ID = M.Buf->getBufferIdentifier();
236  if (Thin) {
237  if (M.IsNew)
238  Out << computeRelativePath(ArcName, ID);
239  else
240  Out << ID;
241  } else
242  Out << M.MemberName;
243  Out << "/\n";
244 }
245 
246 static void printMemberHeader(raw_ostream &Out, uint64_t Pos,
247  raw_ostream &StringTable,
248  object::Archive::Kind Kind, bool Thin,
249  StringRef ArcName, const NewArchiveMember &M,
250  unsigned Size) {
251  if (isBSDLike(Kind))
252  return printBSDMemberHeader(Out, Pos, M.MemberName, M.ModTime, M.UID, M.GID,
253  M.Perms, Size);
254  if (!useStringTable(Thin, M.MemberName))
255  return printGNUSmallMemberHeader(Out, M.MemberName, M.ModTime, M.UID, M.GID,
256  M.Perms, Size);
257  Out << '/';
258  uint64_t NamePos = StringTable.tell();
259  addToStringTable(StringTable, ArcName, M, Thin);
260  printWithSpacePadding(Out, NamePos, 15);
261  printRestOfMemberHeader(Out, M.ModTime, M.UID, M.GID, M.Perms, Size);
262 }
263 
264 namespace {
265 struct MemberData {
266  std::vector<unsigned> Symbols;
267  std::string Header;
268  StringRef Data;
269  StringRef Padding;
270 };
271 } // namespace
272 
273 static MemberData computeStringTable(StringRef Names) {
274  unsigned Size = Names.size();
275  unsigned Pad = OffsetToAlignment(Size, 2);
276  std::string Header;
277  raw_string_ostream Out(Header);
278  printWithSpacePadding(Out, "//", 48);
279  printWithSpacePadding(Out, Size + Pad, 10);
280  Out << "`\n";
281  Out.flush();
282  return {{}, std::move(Header), Names, Pad ? "\n" : ""};
283 }
284 
285 static sys::TimePoint<std::chrono::seconds> now(bool Deterministic) {
286  using namespace std::chrono;
287 
288  if (!Deterministic)
289  return time_point_cast<seconds>(system_clock::now());
290  return sys::TimePoint<seconds>();
291 }
292 
294  uint32_t Symflags = S.getFlags();
296  return false;
297  if (!(Symflags & object::SymbolRef::SF_Global))
298  return false;
299  if (Symflags & object::SymbolRef::SF_Undefined &&
300  !(Symflags & object::SymbolRef::SF_Indirect))
301  return false;
302  return true;
303 }
304 
306  uint64_t Val) {
307  if (is64BitKind(Kind))
308  print<uint64_t>(Out, Kind, Val);
309  else
310  print<uint32_t>(Out, Kind, Val);
311 }
312 
314  bool Deterministic, ArrayRef<MemberData> Members,
315  StringRef StringTable) {
316  if (StringTable.empty())
317  return;
318 
319  unsigned NumSyms = 0;
320  for (const MemberData &M : Members)
321  NumSyms += M.Symbols.size();
322 
323  unsigned Size = 0;
324  Size += is64BitKind(Kind) ? 8 : 4; // Number of entries
325  if (isBSDLike(Kind))
326  Size += NumSyms * 8; // Table
327  else if (is64BitKind(Kind))
328  Size += NumSyms * 8; // Table
329  else
330  Size += NumSyms * 4; // Table
331  if (isBSDLike(Kind))
332  Size += 4; // byte count
333  Size += StringTable.size();
334  // ld64 expects the members to be 8-byte aligned for 64-bit content and at
335  // least 4-byte aligned for 32-bit content. Opt for the larger encoding
336  // uniformly.
337  // We do this for all bsd formats because it simplifies aligning members.
338  unsigned Alignment = isBSDLike(Kind) ? 8 : 2;
339  unsigned Pad = OffsetToAlignment(Size, Alignment);
340  Size += Pad;
341 
342  if (isBSDLike(Kind))
343  printBSDMemberHeader(Out, Out.tell(), "__.SYMDEF", now(Deterministic), 0, 0,
344  0, Size);
345  else if (is64BitKind(Kind))
346  printGNUSmallMemberHeader(Out, "/SYM64", now(Deterministic), 0, 0, 0, Size);
347  else
348  printGNUSmallMemberHeader(Out, "", now(Deterministic), 0, 0, 0, Size);
349 
350  uint64_t Pos = Out.tell() + Size;
351 
352  if (isBSDLike(Kind))
353  print<uint32_t>(Out, Kind, NumSyms * 8);
354  else
355  printNBits(Out, Kind, NumSyms);
356 
357  for (const MemberData &M : Members) {
358  for (unsigned StringOffset : M.Symbols) {
359  if (isBSDLike(Kind))
360  print<uint32_t>(Out, Kind, StringOffset);
361  printNBits(Out, Kind, Pos); // member offset
362  }
363  Pos += M.Header.size() + M.Data.size() + M.Padding.size();
364  }
365 
366  if (isBSDLike(Kind))
367  // byte count of the string table
368  print<uint32_t>(Out, Kind, StringTable.size());
369  Out << StringTable;
370 
371  while (Pad--)
372  Out.write(uint8_t(0));
373 }
374 
376 getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject) {
377  std::vector<unsigned> Ret;
379 
382  &Context);
383  if (!ObjOrErr) {
384  // FIXME: check only for "not an object file" errors.
385  consumeError(ObjOrErr.takeError());
386  return Ret;
387  }
388 
389  HasObject = true;
390  object::SymbolicFile &Obj = *ObjOrErr.get();
391  for (const object::BasicSymbolRef &S : Obj.symbols()) {
392  if (!isArchiveSymbol(S))
393  continue;
394  Ret.push_back(SymNames.tell());
395  if (auto EC = S.printName(SymNames))
396  return errorCodeToError(EC);
397  SymNames << '\0';
398  }
399  return Ret;
400 }
401 
403 computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
404  object::Archive::Kind Kind, bool Thin, StringRef ArcName,
405  ArrayRef<NewArchiveMember> NewMembers) {
406  static char PaddingData[8] = {'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'};
407 
408  // This ignores the symbol table, but we only need the value mod 8 and the
409  // symbol table is aligned to be a multiple of 8 bytes
410  uint64_t Pos = 0;
411 
412  std::vector<MemberData> Ret;
413  bool HasObject = false;
414  for (const NewArchiveMember &M : NewMembers) {
415  std::string Header;
416  raw_string_ostream Out(Header);
417 
418  MemoryBufferRef Buf = M.Buf->getMemBufferRef();
419  StringRef Data = Thin ? "" : Buf.getBuffer();
420 
421  // ld64 expects the members to be 8-byte aligned for 64-bit content and at
422  // least 4-byte aligned for 32-bit content. Opt for the larger encoding
423  // uniformly. This matches the behaviour with cctools and ensures that ld64
424  // is happy with archives that we generate.
425  unsigned MemberPadding = Kind == object::Archive::K_DARWIN
426  ? OffsetToAlignment(Data.size(), 8)
427  : 0;
428  unsigned TailPadding = OffsetToAlignment(Data.size() + MemberPadding, 2);
429  StringRef Padding = StringRef(PaddingData, MemberPadding + TailPadding);
430 
431  printMemberHeader(Out, Pos, StringTable, Kind, Thin, ArcName, M,
432  Buf.getBufferSize() + MemberPadding);
433  Out.flush();
434 
436  getSymbols(Buf, SymNames, HasObject);
437  if (auto E = Symbols.takeError())
438  return std::move(E);
439 
440  Pos += Header.size() + Data.size() + Padding.size();
441  Ret.push_back({std::move(*Symbols), std::move(Header), Data, Padding});
442  }
443  // If there are no symbols, emit an empty symbol table, to satisfy Solaris
444  // tools, older versions of which expect a symbol table in a non-empty
445  // archive, regardless of whether there are any symbols in it.
446  if (HasObject && SymNames.tell() == 0)
447  SymNames << '\0' << '\0' << '\0';
448  return Ret;
449 }
450 
452  ArrayRef<NewArchiveMember> NewMembers,
453  bool WriteSymtab, object::Archive::Kind Kind,
454  bool Deterministic, bool Thin,
455  std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
456  assert((!Thin || !isBSDLike(Kind)) && "Only the gnu format has a thin mode");
457 
458  SmallString<0> SymNamesBuf;
459  raw_svector_ostream SymNames(SymNamesBuf);
460  SmallString<0> StringTableBuf;
461  raw_svector_ostream StringTable(StringTableBuf);
462 
464  computeMemberData(StringTable, SymNames, Kind, Thin, ArcName, NewMembers);
465  if (Error E = DataOrErr.takeError())
466  return E;
467  std::vector<MemberData> &Data = *DataOrErr;
468 
469  if (!StringTableBuf.empty())
470  Data.insert(Data.begin(), computeStringTable(StringTableBuf));
471 
472  // We would like to detect if we need to switch to a 64-bit symbol table.
473  if (WriteSymtab) {
474  uint64_t MaxOffset = 0;
475  uint64_t LastOffset = MaxOffset;
476  for (const auto& M : Data) {
477  // Record the start of the member's offset
478  LastOffset = MaxOffset;
479  // Account for the size of each part associated with the member.
480  MaxOffset += M.Header.size() + M.Data.size() + M.Padding.size();
481  // We assume 32-bit symbols to see if 32-bit symbols are possible or not.
482  MaxOffset += M.Symbols.size() * 4;
483  }
484  // If LastOffset isn't going to fit in a 32-bit varible we need to switch
485  // to 64-bit. Note that the file can be larger than 4GB as long as the last
486  // member starts before the 4GB offset.
487  if (LastOffset >> 32 != 0)
489  }
490 
492  sys::fs::TempFile::create(ArcName + ".temp-archive-%%%%%%%.a");
493  if (!Temp)
494  return Temp.takeError();
495 
496  raw_fd_ostream Out(Temp->FD, false);
497  if (Thin)
498  Out << "!<thin>\n";
499  else
500  Out << "!<arch>\n";
501 
502  if (WriteSymtab)
503  writeSymbolTable(Out, Kind, Deterministic, Data, SymNamesBuf);
504 
505  for (const MemberData &M : Data)
506  Out << M.Header << M.Data << M.Padding;
507 
508  Out.flush();
509 
510  // At this point, we no longer need whatever backing memory
511  // was used to generate the NewMembers. On Windows, this buffer
512  // could be a mapped view of the file we want to replace (if
513  // we're updating an existing archive, say). In that case, the
514  // rename would still succeed, but it would leave behind a
515  // temporary file (actually the original file renamed) because
516  // a file cannot be deleted while there's a handle open on it,
517  // only renamed. So by freeing this buffer, this ensures that
518  // the last open handle on the destination file, if any, is
519  // closed before we attempt to rename.
520  OldArchiveBuf.reset();
521 
522  return Temp->keep(ArcName);
523 }
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:244
Represents either an error or a value T.
Definition: ErrorOr.h:69
LLVM_ATTRIBUTE_ALWAYS_INLINE std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
Definition: Chrono.h:37
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:235
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:448
std::error_code openFileForRead(const Twine &Name, int &ResultFD, SmallVectorImpl< char > *RealPath=nullptr)
static Expected< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object, llvm::file_magic Type, LLVMContext *Context)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
static void printBSDMemberHeader(raw_ostream &Out, uint64_t Pos, StringRef Name, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, unsigned Size)
raw_ostream & indent(unsigned NumSpaces)
indent - Insert &#39;NumSpaces&#39; spaces.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:489
Error takeError()
Take ownership of the stored error.
Definition: Error.h:537
static Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write)
This creates a temporary file with createUniqueFile and schedules it for deletion with sys::RemoveFil...
Definition: Path.cpp:830
Represents the result of a call to sys::fs::status().
Definition: FileSystem.h:219
Error writeArchive(StringRef ArcName, ArrayRef< NewArchiveMember > NewMembers, bool WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin, std::unique_ptr< MemoryBuffer > OldArchiveBuf=nullptr)
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:465
static bool is64BitKind(object::Archive::Kind Kind)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
static Expected< std::vector< unsigned > > getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject)
StringRef getBuffer() const
Definition: MemoryBuffer.h:170
std::error_code make_error_code(BitcodeError E)
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition: Path.cpp:673
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:267
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
static void printGNUSmallMemberHeader(raw_ostream &Out, StringRef Name, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, unsigned Size)
static bool isBSDLike(object::Archive::Kind Kind)
Expected< sys::TimePoint< std::chrono::seconds > > getLastModified() const
Definition: Archive.h:117
size_t getBufferSize() const
Definition: MemoryBuffer.h:176
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
static void printNBits(raw_ostream &Out, object::Archive::Kind Kind, uint64_t Val)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:78
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:116
std::error_code getError() const
Definition: ErrorOr.h:172
TimePoint getLastModificationTime() const
static sys::TimePoint< std::chrono::seconds > now(bool Deterministic)
Expected< unsigned > getUID() const
Definition: Archive.h:125
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
Definition: Path.cpp:476
static void printWithSpacePadding(raw_ostream &OS, T Data, unsigned Size)
static void write(bool isBE, void *P, T V)
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:962
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
raw_ostream & write(unsigned char C)
Expected< sys::fs::perms > getAccessMode() const
Definition: Archive.h:128
static Expected< std::vector< MemberData > > computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames, object::Archive::Kind Kind, bool Thin, StringRef ArcName, ArrayRef< NewArchiveMember > NewMembers)
static bool useStringTable(bool Thin, StringRef Name)
reference get()
Returns a reference to the stored T value.
Definition: Error.h:517
static Expected< NewArchiveMember > getOldMember(const object::Archive::Child &OldMember, bool Deterministic)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:40
static bool isArchiveSymbol(const object::BasicSymbolRef &S)
Expected< MemoryBufferRef > getMemoryBufferRef() const
Definition: Archive.cpp:504
static MemberData computeStringTable(StringRef Names)
static void addToStringTable(raw_ostream &Out, StringRef ArcName, const NewArchiveMember &M, bool Thin)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:120
uint32_t getFlags() const
Get symbol flags (bitwise OR of SymbolRef::Flags)
Definition: SymbolicFile.h:201
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:361
static void writeSymbolTable(raw_ostream &Out, object::Archive::Kind Kind, bool Deterministic, ArrayRef< MemberData > Members, StringRef StringTable)
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
static void printRestOfMemberHeader(raw_ostream &Out, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, unsigned Size)
This is a value type class that represents a single symbol in the list of symbols in the object file...
Definition: SymbolicFile.h:99
basic_symbol_iterator_range symbols() const
Definition: SymbolicFile.h:160
static Expected< NewArchiveMember > getFile(StringRef FileName, bool Deterministic)
const unsigned Kind
static std::string computeRelativePath(StringRef From, StringRef To)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:462
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
uint64_t OffsetToAlignment(uint64_t Value, uint64_t Align)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
Definition: MathExtras.h:719
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:98
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static Expected< std::string > replace(StringRef S, StringRef From, StringRef To)
static void printMemberHeader(raw_ostream &Out, uint64_t Pos, raw_ostream &StringTable, object::Archive::Kind Kind, bool Thin, StringRef ArcName, const NewArchiveMember &M, unsigned Size)
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(int FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
std::unique_ptr< MemoryBuffer > Buf
Definition: ArchiveWriter.h:25
Expected< unsigned > getGID() const
Definition: Archive.h:126
Unrecognized file.
Definition: Magic.h:23
sys::TimePoint< std::chrono::seconds > ModTime
Definition: ArchiveWriter.h:27
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
Definition: Chrono.h:34