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