32 #if !defined(_MSC_VER) && !defined(__MINGW32__) 42 MemberName(BufRef.getBufferIdentifier()) {}
58 return ModTimeOrErr.takeError();
95 if (!MemberBufferOrErr)
103 M.
Buf = std::move(*MemberBufferOrErr);
105 if (!Deterministic) {
106 M.
ModTime = std::chrono::time_point_cast<std::chrono::seconds>(
115 template <
typename T>
117 uint64_t OldPos = OS.
tell();
119 unsigned SizeSoFar = OS.
tell() - OldPos;
120 assert(SizeSoFar <= Size &&
"Data doesn't fit in Size");
121 OS.
indent(Size - SizeSoFar);
179 uint64_t PosAfterHeader = Pos + 60 + Name.
size();
182 unsigned NameWithPadding = Name.
size() + Pad;
185 NameWithPadding + Size);
188 Out.
write(uint8_t(0));
203 while (*FromI == *ToI) {
209 for (
auto FromE =
sys::path::end(DirFrom); FromI != FromE; ++FromI)
221 return Relative.
str();
268 NamePos = StringTable.
tell();
272 if (Insertion.second) {
273 Insertion.first->second = StringTable.
tell();
276 NamePos = Insertion.first->second;
284 std::vector<unsigned> Symbols;
300 return {{}, std::move(Header), Names, Pad ?
"\n" :
""};
304 using namespace std::chrono;
325 print<uint64_t>(Out,
Kind, Val);
327 print<uint32_t>(Out,
Kind, Val);
338 unsigned NumSyms = 0;
339 for (
const MemberData &M : Members)
340 NumSyms += M.Symbols.size();
347 Size += NumSyms * OffsetSize * 2;
349 Size += NumSyms * OffsetSize;
352 Size += StringTable.
size();
357 unsigned Alignment =
isBSDLike(Kind) ? 8 : 2;
373 printNBits(Out, Kind, NumSyms * 2 * OffsetSize);
377 for (
const MemberData &M : Members) {
378 for (
unsigned StringOffset : M.Symbols) {
383 Pos += M.Header.size() + M.Data.size() + M.Padding.size();
392 Out.
write(uint8_t(0));
397 std::vector<unsigned>
Ret;
402 std::unique_ptr<object::SymbolicFile> Obj;
411 Obj = std::move(*ObjOrErr);
419 Obj = std::move(*ObjOrErr);
426 Ret.push_back(SymNames.
tell());
427 if (
auto EC = S.printName(SymNames))
438 static char PaddingData[8] = {
'\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n'};
444 std::vector<MemberData>
Ret;
445 bool HasObject =
false;
493 bool UniqueTimestamps = Deterministic &&
isDarwin(Kind);
494 std::map<StringRef, unsigned> FilenameCount;
495 if (UniqueTimestamps) {
497 FilenameCount[M.MemberName]++;
498 for (
auto &Entry : FilenameCount)
499 Entry.second = Entry.second > 1 ? 1 : 0;
513 unsigned MemberPadding =
519 if (UniqueTimestamps)
533 Pos += Header.size() + Data.
size() + Padding.size();
534 Ret.push_back({std::move(*Symbols), std::move(Header),
Data, Padding});
539 if (HasObject && SymNames.
tell() == 0)
540 SymNames <<
'\0' <<
'\0' <<
'\0';
547 bool Deterministic,
bool Thin,
548 std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
549 assert((!Thin || !
isBSDLike(Kind)) &&
"Only the gnu format has a thin mode");
557 StringTable, SymNames, Kind, Thin, ArcName, Deterministic, NewMembers);
560 std::vector<MemberData> &
Data = *DataOrErr;
562 if (!StringTableBuf.
empty())
567 uint64_t MaxOffset = 0;
568 uint64_t LastOffset = MaxOffset;
569 for (
const auto &M : Data) {
571 LastOffset = MaxOffset;
573 MaxOffset += M.Header.size() + M.Data.size() + M.Padding.size();
575 MaxOffset += M.Symbols.size() * 4;
585 const char *Sym64Env = std::getenv(
"SYM64_THRESHOLD");
586 int Sym64Threshold = 32;
593 if (LastOffset >= (1ULL << Sym64Threshold)) {
615 for (
const MemberData &M : Data)
616 Out << M.Header << M.Data << M.Padding;
630 OldArchiveBuf.reset();
632 return Temp->keep(ArcName);
const_iterator end(StringRef path)
Get end iterator over path.
Represents either an error or a value T.
LLVM_ATTRIBUTE_ALWAYS_INLINE std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_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.
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.
static Expected< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object, llvm::file_magic Type, LLVMContext *Context)
perms permissions() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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.
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().
LLVM_ATTRIBUTE_ALWAYS_INLINE TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
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)
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...
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.
StringRef str() const
Explicit conversion to StringRef.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE 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)...
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.
Expected< sys::TimePoint< std::chrono::seconds > > getLastModified() const
size_t getBufferSize() const
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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 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
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.
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 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.
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)
static void addToStringTable(raw_ostream &Out, StringRef ArcName, const NewArchiveMember &M, bool Thin)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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)
static std::string computeRelativePath(StringRef From, StringRef To)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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
sys::TimePoint< std::chrono::seconds > ModTime
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.