33 #if !defined(_MSC_VER) && !defined(__MINGW32__) 43 MemberName(BufRef.getBufferIdentifier()) {}
58 return ModTimeOrErr.takeError();
81 return FDOrErr.takeError();
96 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);
178 uint64_t PosAfterHeader = Pos + 60 + Name.
size();
181 unsigned NameWithPadding = Name.
size() + Pad;
184 NameWithPadding + Size);
187 Out.
write(uint8_t(0));
222 NamePos = StringTable.
tell();
226 if (Insertion.second) {
227 Insertion.first->second = StringTable.
tell();
230 NamePos = Insertion.first->second;
238 std::vector<unsigned> Symbols;
254 return {{}, std::move(Header), Names, Pad ?
"\n" :
""};
279 print<uint64_t>(Out,
Kind, Val);
281 print<uint32_t>(Out,
Kind, Val);
292 unsigned NumSyms = 0;
293 for (
const MemberData &M : Members)
294 NumSyms += M.Symbols.size();
301 Size += NumSyms * OffsetSize * 2;
303 Size += NumSyms * OffsetSize;
306 Size += StringTable.
size();
327 printNBits(Out, Kind, NumSyms * 2 * OffsetSize);
331 for (
const MemberData &M : Members) {
332 for (
unsigned StringOffset : M.Symbols) {
337 Pos += M.Header.size() + M.Data.size() + M.Padding.size();
346 Out.
write(uint8_t(0));
351 std::vector<unsigned>
Ret;
356 std::unique_ptr<object::SymbolicFile> Obj;
365 Obj = std::move(*ObjOrErr);
373 Obj = std::move(*ObjOrErr);
380 Ret.push_back(SymNames.
tell());
381 if (
Error E = S.printName(SymNames))
392 static char PaddingData[8] = {
'\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n'};
398 std::vector<MemberData>
Ret;
399 bool HasObject =
false;
447 bool UniqueTimestamps = Deterministic &&
isDarwin(Kind);
448 std::map<StringRef, unsigned> FilenameCount;
449 if (UniqueTimestamps) {
451 FilenameCount[M.MemberName]++;
452 for (
auto &
Entry : FilenameCount)
467 unsigned MemberPadding =
469 unsigned TailPadding =
474 if (UniqueTimestamps)
482 std::string StringMsg =
483 "File " + M.MemberName.str() +
" exceeds size limit";
484 return make_error<object::GenericBinaryError>(
497 Pos += Header.size() + Data.
size() + Padding.size();
498 Ret.push_back({std::move(*Symbols), std::move(Header),
Data, Padding});
503 if (HasObject && SymNames.
tell() == 0)
504 SymNames <<
'\0' <<
'\0' <<
'\0';
523 if (!PathToOrErr || !DirFromOrErr)
537 auto FromI = FromTo.first;
538 auto ToI = FromTo.second;
542 for (
auto FromE =
sys::path::end(DirFrom); FromI != FromE; ++FromI)
548 return Relative.
str();
553 bool Deterministic,
bool Thin,
554 std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
555 assert((!Thin || !
isBSDLike(Kind)) &&
"Only the gnu format has a thin mode");
563 StringTable, SymNames, Kind, Thin, Deterministic, NewMembers);
566 std::vector<MemberData> &
Data = *DataOrErr;
568 if (!StringTableBuf.
empty())
573 uint64_t MaxOffset = 0;
574 uint64_t LastOffset = MaxOffset;
575 for (
const auto &M : Data) {
577 LastOffset = MaxOffset;
579 MaxOffset += M.Header.size() + M.Data.size() + M.Padding.size();
581 MaxOffset += M.Symbols.size() * 4;
591 const char *Sym64Env = std::getenv(
"SYM64_THRESHOLD");
592 int Sym64Threshold = 32;
599 if (LastOffset >= (1ULL << Sym64Threshold)) {
621 for (
const MemberData &M : Data)
622 Out << M.Header << M.Data << M.Padding;
636 OldArchiveBuf.reset();
638 return Temp->keep(ArcName);
const file_t kInvalidFile
const_iterator end(StringRef path)
Get end iterator over path.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Represents either an error or a value T.
static void printBSDMemberHeader(raw_ostream &Out, uint64_t Pos, StringRef Name, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, uint64_t Size)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
This class represents lattice values for constants.
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.
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().
static void printRestOfMemberHeader(raw_ostream &Out, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, uint64_t Size)
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
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, uint64_t Size)
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)
void make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
StringRef getBuffer() const
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(sys::fs::file_t 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::error_code make_error_code(BitcodeError E)
Tagged union holding either a T or a Error.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
StringRef str() const
Explicit conversion to StringRef.
static ErrorOr< SmallString< 128 > > canonicalizePath(StringRef P)
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 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.
static const uint64_t MaxMemberSize
Size field is 10 decimal digits long.
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)
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
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
bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
In-place remove any '.
static bool useStringTable(bool Thin, StringRef Name)
StringRef root_name(StringRef path, Style style=Style::native)
Get root name.
Expected< file_t > openNativeFileForRead(const Twine &Name, 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.
reference get()
Returns a reference to the stored T value.
std::error_code closeFile(file_t &F)
Close the file object.
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)
Expected< std::string > computeArchiveRelativePath(StringRef From, StringRef To)
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)
static void printGNUSmallMemberHeader(raw_ostream &Out, StringRef Name, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, uint64_t Size)
LLVM_NODISCARD bool empty() const
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())
A raw_ostream that writes to an std::string.
Lightweight error class with error context and mandatory checking.
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.
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.