LLVM  9.0.0svn
ArchiveWriter.cpp
Go to the documentation of this file.
1 //===- ArchiveWriter.cpp - ar File Format implementation --------*- 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 // This file defines the writeArchive function.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/StringRef.h"
17 #include "llvm/IR/LLVMContext.h"
18 #include "llvm/Object/Archive.h"
19 #include "llvm/Object/ObjectFile.h"
22 #include "llvm/Support/Errc.h"
24 #include "llvm/Support/Format.h"
25 #include "llvm/Support/Path.h"
28 
29 #include <map>
30 
31 #if !defined(_MSC_VER) && !defined(__MINGW32__)
32 #include <unistd.h>
33 #else
34 #include <io.h>
35 #endif
36 
37 using namespace llvm;
38 
40  : Buf(MemoryBuffer::getMemBuffer(BufRef, false)),
41  MemberName(BufRef.getBufferIdentifier()) {}
42 
45  bool Deterministic) {
47  if (!BufOrErr)
48  return BufOrErr.takeError();
49 
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) {
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.Buf = std::move(*MemberBufferOrErr);
101  M.MemberName = M.Buf->getBufferIdentifier();
102  if (!Deterministic) {
103  M.ModTime = std::chrono::time_point_cast<std::chrono::seconds>(
104  Status.getLastModificationTime());
105  M.UID = Status.getUser();
106  M.GID = Status.getGroup();
107  M.Perms = Status.permissions();
108  }
109  return std::move(M);
110 }
111 
112 template <typename T>
113 static void printWithSpacePadding(raw_ostream &OS, T Data, unsigned Size) {
114  uint64_t OldPos = OS.tell();
115  OS << Data;
116  unsigned SizeSoFar = OS.tell() - OldPos;
117  assert(SizeSoFar <= Size && "Data doesn't fit in Size");
118  OS.indent(Size - SizeSoFar);
119 }
120 
122  return Kind == object::Archive::K_DARWIN ||
124 }
125 
127  switch (Kind) {
130  return false;
134  return true;
136  break;
137  }
138  llvm_unreachable("not supported for writting");
139 }
140 
141 template <class T>
142 static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val) {
143  support::endian::write(Out, Val,
145 }
146 
149  unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
150  printWithSpacePadding(Out, sys::toTimeT(ModTime), 12);
151 
152  // The format has only 6 chars for uid and gid. Truncate if the provided
153  // values don't fit.
154  printWithSpacePadding(Out, UID % 1000000, 6);
155  printWithSpacePadding(Out, GID % 1000000, 6);
156 
157  printWithSpacePadding(Out, format("%o", Perms), 8);
158  printWithSpacePadding(Out, Size, 10);
159  Out << "`\n";
160 }
161 
162 static void
165  unsigned UID, unsigned GID, unsigned Perms,
166  unsigned Size) {
167  printWithSpacePadding(Out, Twine(Name) + "/", 16);
168  printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, Size);
169 }
170 
171 static void
174  unsigned UID, unsigned GID, unsigned Perms,
175  unsigned Size) {
176  uint64_t PosAfterHeader = Pos + 60 + Name.size();
177  // Pad so that even 64 bit object files are aligned.
178  unsigned Pad = OffsetToAlignment(PosAfterHeader, 8);
179  unsigned NameWithPadding = Name.size() + Pad;
180  printWithSpacePadding(Out, Twine("#1/") + Twine(NameWithPadding), 16);
181  printRestOfMemberHeader(Out, ModTime, UID, GID, Perms,
182  NameWithPadding + Size);
183  Out << Name;
184  while (Pad--)
185  Out.write(uint8_t(0));
186 }
187 
188 static bool useStringTable(bool Thin, StringRef Name) {
189  return Thin || Name.size() >= 16 || Name.contains('/');
190 }
191 
193  switch (Kind) {
198  return false;
201  return true;
202  }
203  llvm_unreachable("not supported for writting");
204 }
205 
206 static void
207 printMemberHeader(raw_ostream &Out, uint64_t Pos, raw_ostream &StringTable,
209  bool Thin, const NewArchiveMember &M,
211  if (isBSDLike(Kind))
212  return printBSDMemberHeader(Out, Pos, M.MemberName, ModTime, M.UID, M.GID,
213  M.Perms, Size);
214  if (!useStringTable(Thin, M.MemberName))
215  return printGNUSmallMemberHeader(Out, M.MemberName, ModTime, M.UID, M.GID,
216  M.Perms, Size);
217  Out << '/';
218  uint64_t NamePos;
219  if (Thin) {
220  NamePos = StringTable.tell();
221  StringTable << M.MemberName << "/\n";
222  } else {
223  auto Insertion = MemberNames.insert({M.MemberName, uint64_t(0)});
224  if (Insertion.second) {
225  Insertion.first->second = StringTable.tell();
226  StringTable << M.MemberName << "/\n";
227  }
228  NamePos = Insertion.first->second;
229  }
230  printWithSpacePadding(Out, NamePos, 15);
231  printRestOfMemberHeader(Out, ModTime, M.UID, M.GID, M.Perms, Size);
232 }
233 
234 namespace {
235 struct MemberData {
236  std::vector<unsigned> Symbols;
237  std::string Header;
238  StringRef Data;
239  StringRef Padding;
240 };
241 } // namespace
242 
243 static MemberData computeStringTable(StringRef Names) {
244  unsigned Size = Names.size();
245  unsigned Pad = OffsetToAlignment(Size, 2);
246  std::string Header;
247  raw_string_ostream Out(Header);
248  printWithSpacePadding(Out, "//", 48);
249  printWithSpacePadding(Out, Size + Pad, 10);
250  Out << "`\n";
251  Out.flush();
252  return {{}, std::move(Header), Names, Pad ? "\n" : ""};
253 }
254 
255 static sys::TimePoint<std::chrono::seconds> now(bool Deterministic) {
256  using namespace std::chrono;
257 
258  if (!Deterministic)
259  return time_point_cast<seconds>(system_clock::now());
260  return sys::TimePoint<seconds>();
261 }
262 
264  uint32_t Symflags = S.getFlags();
266  return false;
267  if (!(Symflags & object::SymbolRef::SF_Global))
268  return false;
269  if (Symflags & object::SymbolRef::SF_Undefined)
270  return false;
271  return true;
272 }
273 
275  uint64_t Val) {
276  if (is64BitKind(Kind))
277  print<uint64_t>(Out, Kind, Val);
278  else
279  print<uint32_t>(Out, Kind, Val);
280 }
281 
283  bool Deterministic, ArrayRef<MemberData> Members,
284  StringRef StringTable) {
285  // We don't write a symbol table on an archive with no members -- except on
286  // Darwin, where the linker will abort unless the archive has a symbol table.
287  if (StringTable.empty() && !isDarwin(Kind))
288  return;
289 
290  unsigned NumSyms = 0;
291  for (const MemberData &M : Members)
292  NumSyms += M.Symbols.size();
293 
294  unsigned Size = 0;
295  unsigned OffsetSize = is64BitKind(Kind) ? sizeof(uint64_t) : sizeof(uint32_t);
296 
297  Size += OffsetSize; // Number of entries
298  if (isBSDLike(Kind))
299  Size += NumSyms * OffsetSize * 2; // Table
300  else
301  Size += NumSyms * OffsetSize; // Table
302  if (isBSDLike(Kind))
303  Size += OffsetSize; // byte count
304  Size += StringTable.size();
305  // ld64 expects the members to be 8-byte aligned for 64-bit content and at
306  // least 4-byte aligned for 32-bit content. Opt for the larger encoding
307  // uniformly.
308  // We do this for all bsd formats because it simplifies aligning members.
309  unsigned Alignment = isBSDLike(Kind) ? 8 : 2;
310  unsigned Pad = OffsetToAlignment(Size, Alignment);
311  Size += Pad;
312 
313  if (isBSDLike(Kind)) {
314  const char *Name = is64BitKind(Kind) ? "__.SYMDEF_64" : "__.SYMDEF";
315  printBSDMemberHeader(Out, Out.tell(), Name, now(Deterministic), 0, 0, 0,
316  Size);
317  } else {
318  const char *Name = is64BitKind(Kind) ? "/SYM64" : "";
319  printGNUSmallMemberHeader(Out, Name, now(Deterministic), 0, 0, 0, Size);
320  }
321 
322  uint64_t Pos = Out.tell() + Size;
323 
324  if (isBSDLike(Kind))
325  printNBits(Out, Kind, NumSyms * 2 * OffsetSize);
326  else
327  printNBits(Out, Kind, NumSyms);
328 
329  for (const MemberData &M : Members) {
330  for (unsigned StringOffset : M.Symbols) {
331  if (isBSDLike(Kind))
332  printNBits(Out, Kind, StringOffset);
333  printNBits(Out, Kind, Pos); // member offset
334  }
335  Pos += M.Header.size() + M.Data.size() + M.Padding.size();
336  }
337 
338  if (isBSDLike(Kind))
339  // byte count of the string table
340  printNBits(Out, Kind, StringTable.size());
341  Out << StringTable;
342 
343  while (Pad--)
344  Out.write(uint8_t(0));
345 }
346 
348 getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject) {
349  std::vector<unsigned> Ret;
350 
351  // In the scenario when LLVMContext is populated SymbolicFile will contain a
352  // reference to it, thus SymbolicFile should be destroyed first.
354  std::unique_ptr<object::SymbolicFile> Obj;
357  Buf, file_magic::bitcode, &Context);
358  if (!ObjOrErr) {
359  // FIXME: check only for "not an object file" errors.
360  consumeError(ObjOrErr.takeError());
361  return Ret;
362  }
363  Obj = std::move(*ObjOrErr);
364  } else {
365  auto ObjOrErr = object::SymbolicFile::createSymbolicFile(Buf);
366  if (!ObjOrErr) {
367  // FIXME: check only for "not an object file" errors.
368  consumeError(ObjOrErr.takeError());
369  return Ret;
370  }
371  Obj = std::move(*ObjOrErr);
372  }
373 
374  HasObject = true;
375  for (const object::BasicSymbolRef &S : Obj->symbols()) {
376  if (!isArchiveSymbol(S))
377  continue;
378  Ret.push_back(SymNames.tell());
379  if (auto EC = S.printName(SymNames))
380  return errorCodeToError(EC);
381  SymNames << '\0';
382  }
383  return Ret;
384 }
385 
387 computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
388  object::Archive::Kind Kind, bool Thin, bool Deterministic,
389  ArrayRef<NewArchiveMember> NewMembers) {
390  static char PaddingData[8] = {'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'};
391 
392  // This ignores the symbol table, but we only need the value mod 8 and the
393  // symbol table is aligned to be a multiple of 8 bytes
394  uint64_t Pos = 0;
395 
396  std::vector<MemberData> Ret;
397  bool HasObject = false;
398 
399  // Deduplicate long member names in the string table and reuse earlier name
400  // offsets. This especially saves space for COFF Import libraries where all
401  // members have the same name.
402  StringMap<uint64_t> MemberNames;
403 
404  // UniqueTimestamps is a special case to improve debugging on Darwin:
405  //
406  // The Darwin linker does not link debug info into the final
407  // binary. Instead, it emits entries of type N_OSO in in the output
408  // binary's symbol table, containing references to the linked-in
409  // object files. Using that reference, the debugger can read the
410  // debug data directly from the object files. Alternatively, an
411  // invocation of 'dsymutil' will link the debug data from the object
412  // files into a dSYM bundle, which can be loaded by the debugger,
413  // instead of the object files.
414  //
415  // For an object file, the N_OSO entries contain the absolute path
416  // path to the file, and the file's timestamp. For an object
417  // included in an archive, the path is formatted like
418  // "/absolute/path/to/archive.a(member.o)", and the timestamp is the
419  // archive member's timestamp, rather than the archive's timestamp.
420  //
421  // However, this doesn't always uniquely identify an object within
422  // an archive -- an archive file can have multiple entries with the
423  // same filename. (This will happen commonly if the original object
424  // files started in different directories.) The only way they get
425  // distinguished, then, is via the timestamp. But this process is
426  // unable to find the correct object file in the archive when there
427  // are two files of the same name and timestamp.
428  //
429  // Additionally, timestamp==0 is treated specially, and causes the
430  // timestamp to be ignored as a match criteria.
431  //
432  // That will "usually" work out okay when creating an archive not in
433  // deterministic timestamp mode, because the objects will probably
434  // have been created at different timestamps.
435  //
436  // To ameliorate this problem, in deterministic archive mode (which
437  // is the default), on Darwin we will emit a unique non-zero
438  // timestamp for each entry with a duplicated name. This is still
439  // deterministic: the only thing affecting that timestamp is the
440  // order of the files in the resultant archive.
441  //
442  // See also the functions that handle the lookup:
443  // in lldb: ObjectContainerBSDArchive::Archive::FindObject()
444  // in llvm/tools/dsymutil: BinaryHolder::GetArchiveMemberBuffers().
445  bool UniqueTimestamps = Deterministic && isDarwin(Kind);
446  std::map<StringRef, unsigned> FilenameCount;
447  if (UniqueTimestamps) {
448  for (const NewArchiveMember &M : NewMembers)
449  FilenameCount[M.MemberName]++;
450  for (auto &Entry : FilenameCount)
451  Entry.second = Entry.second > 1 ? 1 : 0;
452  }
453 
454  for (const NewArchiveMember &M : NewMembers) {
455  std::string Header;
456  raw_string_ostream Out(Header);
457 
458  MemoryBufferRef Buf = M.Buf->getMemBufferRef();
459  StringRef Data = Thin ? "" : Buf.getBuffer();
460 
461  // ld64 expects the members to be 8-byte aligned for 64-bit content and at
462  // least 4-byte aligned for 32-bit content. Opt for the larger encoding
463  // uniformly. This matches the behaviour with cctools and ensures that ld64
464  // is happy with archives that we generate.
465  unsigned MemberPadding =
466  isDarwin(Kind) ? OffsetToAlignment(Data.size(), 8) : 0;
467  unsigned TailPadding = OffsetToAlignment(Data.size() + MemberPadding, 2);
468  StringRef Padding = StringRef(PaddingData, MemberPadding + TailPadding);
469 
471  if (UniqueTimestamps)
472  // Increment timestamp for each file of a given name.
473  ModTime = sys::toTimePoint(FilenameCount[M.MemberName]++);
474  else
475  ModTime = M.ModTime;
476  printMemberHeader(Out, Pos, StringTable, MemberNames, Kind, Thin, M,
477  ModTime, Buf.getBufferSize() + MemberPadding);
478  Out.flush();
479 
481  getSymbols(Buf, SymNames, HasObject);
482  if (auto E = Symbols.takeError())
483  return std::move(E);
484 
485  Pos += Header.size() + Data.size() + Padding.size();
486  Ret.push_back({std::move(*Symbols), std::move(Header), Data, Padding});
487  }
488  // If there are no symbols, emit an empty symbol table, to satisfy Solaris
489  // tools, older versions of which expect a symbol table in a non-empty
490  // archive, regardless of whether there are any symbols in it.
491  if (HasObject && SymNames.tell() == 0)
492  SymNames << '\0' << '\0' << '\0';
493  return Ret;
494 }
495 
496 namespace llvm {
497 // Compute the relative path from From to To.
500  return To;
501 
502  StringRef DirFrom = sys::path::parent_path(From);
503  auto FromI = sys::path::begin(DirFrom);
504  auto ToI = sys::path::begin(To);
505  while (*FromI == *ToI) {
506  ++FromI;
507  ++ToI;
508  }
509 
510  SmallString<128> Relative;
511  for (auto FromE = sys::path::end(DirFrom); FromI != FromE; ++FromI)
512  sys::path::append(Relative, "..");
513 
514  for (auto ToE = sys::path::end(To); ToI != ToE; ++ToI)
515  sys::path::append(Relative, *ToI);
516 
517  // Replace backslashes with slashes so that the path is portable between *nix
518  // and Windows.
519  return sys::path::convert_to_slash(Relative);
520 }
521 
523  bool WriteSymtab, object::Archive::Kind Kind,
524  bool Deterministic, bool Thin,
525  std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
526  assert((!Thin || !isBSDLike(Kind)) && "Only the gnu format has a thin mode");
527 
528  SmallString<0> SymNamesBuf;
529  raw_svector_ostream SymNames(SymNamesBuf);
530  SmallString<0> StringTableBuf;
531  raw_svector_ostream StringTable(StringTableBuf);
532 
534  StringTable, SymNames, Kind, Thin, Deterministic, NewMembers);
535  if (Error E = DataOrErr.takeError())
536  return E;
537  std::vector<MemberData> &Data = *DataOrErr;
538 
539  if (!StringTableBuf.empty())
540  Data.insert(Data.begin(), computeStringTable(StringTableBuf));
541 
542  // We would like to detect if we need to switch to a 64-bit symbol table.
543  if (WriteSymtab) {
544  uint64_t MaxOffset = 0;
545  uint64_t LastOffset = MaxOffset;
546  for (const auto &M : Data) {
547  // Record the start of the member's offset
548  LastOffset = MaxOffset;
549  // Account for the size of each part associated with the member.
550  MaxOffset += M.Header.size() + M.Data.size() + M.Padding.size();
551  // We assume 32-bit symbols to see if 32-bit symbols are possible or not.
552  MaxOffset += M.Symbols.size() * 4;
553  }
554 
555  // The SYM64 format is used when an archive's member offsets are larger than
556  // 32-bits can hold. The need for this shift in format is detected by
557  // writeArchive. To test this we need to generate a file with a member that
558  // has an offset larger than 32-bits but this demands a very slow test. To
559  // speed the test up we use this environment variable to pretend like the
560  // cutoff happens before 32-bits and instead happens at some much smaller
561  // value.
562  const char *Sym64Env = std::getenv("SYM64_THRESHOLD");
563  int Sym64Threshold = 32;
564  if (Sym64Env)
565  StringRef(Sym64Env).getAsInteger(10, Sym64Threshold);
566 
567  // If LastOffset isn't going to fit in a 32-bit varible we need to switch
568  // to 64-bit. Note that the file can be larger than 4GB as long as the last
569  // member starts before the 4GB offset.
570  if (LastOffset >= (1ULL << Sym64Threshold)) {
571  if (Kind == object::Archive::K_DARWIN)
573  else
575  }
576  }
577 
579  sys::fs::TempFile::create(ArcName + ".temp-archive-%%%%%%%.a");
580  if (!Temp)
581  return Temp.takeError();
582 
583  raw_fd_ostream Out(Temp->FD, false);
584  if (Thin)
585  Out << "!<thin>\n";
586  else
587  Out << "!<arch>\n";
588 
589  if (WriteSymtab)
590  writeSymbolTable(Out, Kind, Deterministic, Data, SymNamesBuf);
591 
592  for (const MemberData &M : Data)
593  Out << M.Header << M.Data << M.Padding;
594 
595  Out.flush();
596 
597  // At this point, we no longer need whatever backing memory
598  // was used to generate the NewMembers. On Windows, this buffer
599  // could be a mapped view of the file we want to replace (if
600  // we're updating an existing archive, say). In that case, the
601  // rename would still succeed, but it would leave behind a
602  // temporary file (actually the original file renamed) because
603  // a file cannot be deleted while there's a handle open on it,
604  // only renamed. So by freeing this buffer, this ensures that
605  // the last open handle on the destination file, if any, is
606  // closed before we attempt to rename.
607  OldArchiveBuf.reset();
608 
609  return Temp->keep(ArcName);
610 }
611 
612 } // namespace llvm
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:258
Represents either an error or a value T.
Definition: ErrorOr.h:56
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:249
This class represents lattice values for constants.
Definition: AllocatorList.h:23
std::error_code openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static Expected< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object, llvm::file_magic Type, LLVMContext *Context)
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:123
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:509
std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
Definition: Path.cpp:580
Error takeError()
Take ownership of the stored error.
Definition: Error.h:552
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:1222
Represents the result of a call to sys::fs::status().
Definition: FileSystem.h:246
Error writeArchive(StringRef ArcName, ArrayRef< NewArchiveMember > NewMembers, bool WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin, std::unique_ptr< MemoryBuffer > OldArchiveBuf=nullptr)
Bitcode file.
Definition: Magic.h:23
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:479
static bool is64BitKind(object::Archive::Kind Kind)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
static Expected< std::vector< unsigned > > getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject)
StringRef getBuffer() const
Definition: MemoryBuffer.h:272
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition: Magic.cpp:34
std::error_code make_error_code(BitcodeError E)
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition: Path.cpp:687
Tagged union holding either a T or a Error.
Definition: CachePruning.h:22
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
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)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition: Endian.h:99
static Expected< std::vector< MemberData > > computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames, object::Archive::Kind Kind, bool Thin, bool Deterministic, ArrayRef< NewArchiveMember > NewMembers)
Expected< sys::TimePoint< std::chrono::seconds > > getLastModified() const
Definition: Archive.h:117
size_t getBufferSize() const
Definition: MemoryBuffer.h:278
std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
Definition: Chrono.h:36
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
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:87
std::error_code getError() const
Definition: ErrorOr.h:159
TimePoint getLastModificationTime() const
The file modification time as reported from the underlying file system.
static sys::TimePoint< std::chrono::seconds > now(bool Deterministic)
static void printMemberHeader(raw_ostream &Out, uint64_t Pos, raw_ostream &StringTable, StringMap< uint64_t > &MemberNames, object::Archive::Kind Kind, bool Thin, const NewArchiveMember &M, sys::TimePoint< std::chrono::seconds > ModTime, unsigned Size)
static bool isDarwin(object::Archive::Kind Kind)
Expected< unsigned > getUID() const
Definition: Archive.h:125
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
LLVM_NODISCARD bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:432
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
Definition: Path.cpp:490
static void printWithSpacePadding(raw_ostream &OS, T Data, unsigned Size)
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:981
#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
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:478
BlockVerifier::State From
static bool useStringTable(bool Thin, StringRef Name)
reference get()
Returns a reference to the stored T value.
Definition: Error.h:532
static Expected< NewArchiveMember > getOldMember(const object::Archive::Child &OldMember, bool Deterministic)
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:365
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:41
static bool isArchiveSymbol(const object::BasicSymbolRef &S)
Expected< MemoryBufferRef > getMemoryBufferRef() const
Definition: Archive.cpp:507
static MemberData computeStringTable(StringRef Names)
uint32_t getFlags() const
Get symbol flags (bitwise OR of SymbolRef::Flags)
Definition: SymbolicFile.h:200
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:365
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:55
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:98
uint32_t Size
Definition: Profile.cpp:46
static Expected< NewArchiveMember > getFile(StringRef FileName, bool Deterministic)
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::string computeArchiveRelativePath(StringRef From, StringRef To)
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:482
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
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:726
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:99
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
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:24
Expected< unsigned > getGID() const
Definition: Archive.h:126
TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
Definition: Chrono.h:44
sys::TimePoint< std::chrono::seconds > ModTime
Definition: ArchiveWriter.h:26
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
Definition: Chrono.h:33