31 #if !defined(_MSC_VER) && !defined(__MINGW32__) 41 MemberName(BufRef.getBufferIdentifier()) {}
56 return ModTimeOrErr.takeError();
93 if (!MemberBufferOrErr)
100 M.
Buf = std::move(*MemberBufferOrErr);
102 if (!Deterministic) {
103 M.
ModTime = std::chrono::time_point_cast<std::chrono::seconds>(
112 template <
typename T>
114 uint64_t OldPos = OS.
tell();
116 unsigned SizeSoFar = OS.
tell() - OldPos;
117 assert(SizeSoFar <= Size &&
"Data doesn't fit in Size");
118 OS.
indent(Size - SizeSoFar);
176 uint64_t PosAfterHeader = Pos + 60 + Name.
size();
179 unsigned NameWithPadding = Name.
size() + Pad;
182 NameWithPadding + Size);
185 Out.
write(uint8_t(0));
220 NamePos = StringTable.
tell();
224 if (Insertion.second) {
225 Insertion.first->second = StringTable.
tell();
228 NamePos = Insertion.first->second;
236 std::vector<unsigned> Symbols;
252 return {{}, std::move(Header), Names, Pad ?
"\n" :
""};
256 using namespace std::chrono;
277 print<uint64_t>(Out,
Kind, Val);
279 print<uint32_t>(Out,
Kind, Val);
290 unsigned NumSyms = 0;
291 for (
const MemberData &M : Members)
292 NumSyms += M.Symbols.size();
299 Size += NumSyms * OffsetSize * 2;
301 Size += NumSyms * OffsetSize;
304 Size += StringTable.
size();
309 unsigned Alignment =
isBSDLike(Kind) ? 8 : 2;
325 printNBits(Out, Kind, NumSyms * 2 * OffsetSize);
329 for (
const MemberData &M : Members) {
330 for (
unsigned StringOffset : M.Symbols) {
335 Pos += M.Header.size() + M.Data.size() + M.Padding.size();
344 Out.
write(uint8_t(0));
349 std::vector<unsigned>
Ret;
354 std::unique_ptr<object::SymbolicFile> Obj;
363 Obj = std::move(*ObjOrErr);
371 Obj = std::move(*ObjOrErr);
378 Ret.push_back(SymNames.
tell());
379 if (
auto EC = S.printName(SymNames))
390 static char PaddingData[8] = {
'\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n'};
396 std::vector<MemberData>
Ret;
397 bool HasObject =
false;
445 bool UniqueTimestamps = Deterministic &&
isDarwin(Kind);
446 std::map<StringRef, unsigned> FilenameCount;
447 if (UniqueTimestamps) {
449 FilenameCount[M.MemberName]++;
450 for (
auto &Entry : FilenameCount)
451 Entry.second = Entry.second > 1 ? 1 : 0;
465 unsigned MemberPadding =
471 if (UniqueTimestamps)
485 Pos += Header.size() + Data.
size() + Padding.size();
486 Ret.push_back({std::move(*Symbols), std::move(Header),
Data, Padding});
491 if (HasObject && SymNames.
tell() == 0)
492 SymNames <<
'\0' <<
'\0' <<
'\0';
505 while (*FromI == *ToI) {
511 for (
auto FromE =
sys::path::end(DirFrom); FromI != FromE; ++FromI)
524 bool Deterministic,
bool Thin,
525 std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
526 assert((!Thin || !
isBSDLike(Kind)) &&
"Only the gnu format has a thin mode");
534 StringTable, SymNames, Kind, Thin, Deterministic, NewMembers);
537 std::vector<MemberData> &
Data = *DataOrErr;
539 if (!StringTableBuf.
empty())
544 uint64_t MaxOffset = 0;
545 uint64_t LastOffset = MaxOffset;
546 for (
const auto &M : Data) {
548 LastOffset = MaxOffset;
550 MaxOffset += M.Header.size() + M.Data.size() + M.Padding.size();
552 MaxOffset += M.Symbols.size() * 4;
562 const char *Sym64Env = std::getenv(
"SYM64_THRESHOLD");
563 int Sym64Threshold = 32;
570 if (LastOffset >= (1ULL << Sym64Threshold)) {
592 for (
const MemberData &M : Data)
593 Out << M.Header << M.Data << M.Padding;
607 OldArchiveBuf.reset();
609 return Temp->keep(ArcName);
const_iterator end(StringRef path)
Get end iterator over path.
Represents either an error or a value T.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
This class represents lattice values for constants.
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)
perms permissions() const
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.
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 'NumSpaces' spaces.
A raw_ostream that writes to an SmallVector or SmallString.
std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
Error takeError()
Take ownership of the stored error.
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...
Represents the result of a call to sys::fs::status().
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.
static bool is64BitKind(object::Archive::Kind Kind)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Expected< std::vector< unsigned > > getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject)
StringRef getBuffer() const
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
std::error_code make_error_code(BitcodeError E)
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Tagged union holding either a T or a Error.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD size_t size() const
size - Get the string size.
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.
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
size_t getBufferSize() const
std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
This is an important class for using LLVM in a threaded context.
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.
std::error_code getError() const
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
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.
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
static void printWithSpacePadding(raw_ostream &OS, T Data, unsigned Size)
void consumeError(Error Err)
Consume a Error without doing anything.
#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
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.
BlockVerifier::State From
static bool useStringTable(bool Thin, StringRef Name)
reference get()
Returns a reference to the stored T value.
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.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
uint32_t getGroup() const
static bool isArchiveSymbol(const object::BasicSymbolRef &S)
Expected< MemoryBufferRef > getMemoryBufferRef() const
static MemberData computeStringTable(StringRef Names)
uint32_t getFlags() const
Get symbol flags (bitwise OR of SymbolRef::Flags)
A raw_ostream that writes to a file descriptor.
static void writeSymbolTable(raw_ostream &Out, object::Archive::Kind Kind, bool Deterministic, ArrayRef< MemberData > Members, StringRef StringTable)
LLVM_NODISCARD bool empty() const
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...
static Expected< NewArchiveMember > getFile(StringRef FileName, bool Deterministic)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::string computeArchiveRelativePath(StringRef From, StringRef To)
A raw_ostream that writes to an std::string.
Lightweight error class with error context and mandatory checking.
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...
uint64_t tell() const
tell - Return the current offset with the file.
NewArchiveMember()=default
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
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
Expected< unsigned > getGID() const
TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
sys::TimePoint< std::chrono::seconds > ModTime
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.