30 #if !defined(_MSC_VER) && !defined(__MINGW32__)
40 MemberName(BufRef.getBufferIdentifier()) {}
56 return ModTimeOrErr.takeError();
93 if (!MemberBufferOrErr)
101 M.
Buf = std::move(*MemberBufferOrErr);
103 if (!Deterministic) {
104 M.
ModTime = std::chrono::time_point_cast<std::chrono::seconds>(
106 M.
UID = Status.getUser();
107 M.
GID = Status.getGroup();
113 template <
typename T>
115 bool MayTruncate =
false) {
116 uint64_t OldPos = OS.
tell();
118 unsigned SizeSoFar = OS.
tell() - OldPos;
119 if (Size > SizeSoFar) {
120 OS.
indent(Size - SizeSoFar);
121 }
else if (Size < SizeSoFar) {
122 assert(MayTruncate &&
"Data doesn't fit in Size");
125 OS.
seek(OldPos + Size);
154 unsigned UID,
unsigned GID,
unsigned Perms,
unsigned Size) {
166 unsigned UID,
unsigned GID,
unsigned Perms,
175 unsigned UID,
unsigned GID,
unsigned Perms,
177 uint64_t PosAfterHeader = Out.
tell() + 60 + Name.
size();
180 unsigned NameWithPadding = Name.
size() + Pad;
183 NameWithPadding + Size);
187 Out.
write(uint8_t(0));
197 std::vector<unsigned>::iterator &StringMapIndexIter,
199 unsigned UID,
unsigned GID,
unsigned Perms,
unsigned Size) {
217 while (*FromI == *ToI) {
223 for (
auto FromE =
sys::path::end(DirFrom); FromI != FromE; ++FromI)
235 return Relative.
str();
240 std::vector<unsigned> &StringMapIndexes,
242 unsigned StartOffset = 0;
244 StringRef Path = M.Buf->getBufferIdentifier();
248 if (StartOffset == 0) {
251 StartOffset = Out.
tell();
253 StringMapIndexes.push_back(Out.
tell() - StartOffset);
259 Out << M.Buf->getBufferIdentifier();
265 if (StartOffset == 0)
269 int Pos = Out.
tell();
270 Out.
seek(StartOffset - 12);
276 using namespace std::chrono;
287 std::vector<unsigned> &MemberOffsetRefs,
bool Deterministic) {
288 unsigned HeaderStartOffset = 0;
289 unsigned BodyStartOffset = 0;
293 for (
unsigned MemberNum = 0,
N = Members.
size(); MemberNum <
N; ++MemberNum) {
294 MemoryBufferRef MemberBuffer = Members[MemberNum].Buf->getMemBufferRef();
305 if (!HeaderStartOffset) {
306 HeaderStartOffset = Out.
tell();
311 BodyStartOffset = Out.
tell();
325 unsigned NameOffset = NameOS.
tell();
326 if (
auto EC = S.printName(NameOS))
329 MemberOffsetRefs.push_back(MemberNum);
331 print32(Out, Kind, NameOffset);
336 if (HeaderStartOffset == 0)
352 if (StringTable.size() == 0)
359 Out.
write(uint8_t(0));
362 unsigned Pos = Out.
tell();
363 const unsigned MemberHeaderSize = 60;
364 Out.
seek(HeaderStartOffset + 48);
368 Out.
seek(BodyStartOffset);
369 unsigned NumSyms = MemberOffsetRefs.size();
371 print32(Out, Kind, NumSyms * 8);
376 return BodyStartOffset + 4;
379 std::pair<StringRef, std::error_code>
381 std::vector<NewArchiveMember> &NewMembers,
383 bool Deterministic,
bool Thin,
384 std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
385 assert((!Thin || !
isBSDLike(Kind)) &&
"Only the gnu format has a thin mode");
389 TmpArchiveFD, TmpArchive))
390 return std::make_pair(ArcName, EC);
399 std::vector<unsigned> MemberOffsetRefs;
401 unsigned MemberReferenceOffset = 0;
404 Out, Kind, NewMembers, MemberOffsetRefs, Deterministic);
405 if (
auto EC = MemberReferenceOffsetOrErr.
getError())
406 return std::make_pair(ArcName, EC);
407 MemberReferenceOffset = MemberReferenceOffsetOrErr.
get();
410 std::vector<unsigned> StringMapIndexes;
414 std::vector<unsigned>::iterator StringMapIndexIter = StringMapIndexes.begin();
415 std::vector<unsigned> MemberOffset;
418 unsigned Padding = 0;
420 unsigned Pos = Out.
tell();
421 MemberOffset.push_back(Pos);
431 M.ModTime, M.UID, M.GID, M.Perms,
432 M.Buf->getBufferSize() + Padding);
443 if (MemberReferenceOffset) {
444 Out.
seek(MemberReferenceOffset);
445 for (
unsigned MemberNum : MemberOffsetRefs) {
448 print32(Out, Kind, MemberOffset[MemberNum]);
465 OldArchiveBuf.reset();
468 return std::make_pair(
"", std::error_code());
const_iterator end(StringRef path)
Get end iterator over path.
std::error_code getError() const
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.
std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
Create a uniquely named file.
std::error_code openFileForRead(const Twine &Name, int &ResultFD, SmallVectorImpl< char > *RealPath=nullptr)
static Expected< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object, llvm::file_magic Type, LLVMContext *Context)
static void printMemberHeader(raw_fd_ostream &Out, object::Archive::Kind Kind, bool Thin, StringRef Name, std::vector< unsigned >::iterator &StringMapIndexIter, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, unsigned Size)
Expected< unsigned > getGID() const
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
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.
file_status - Represents the result of a call to stat and friends.
static void print32(raw_ostream &Out, object::Archive::Kind Kind, uint32_t Val)
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
static void printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, unsigned Size)
std::pair< StringRef, std::error_code > writeArchive(StringRef ArcName, std::vector< NewArchiveMember > &NewMembers, bool WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin, std::unique_ptr< MemoryBuffer > OldArchiveBuf=nullptr)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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.
uint64_t tell() const
tell - Return the current offset with the file.
static ErrorOr< unsigned > writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind, ArrayRef< NewArchiveMember > Members, std::vector< unsigned > &MemberOffsetRefs, bool Deterministic)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
size_t size() const
size - Get the array size.
static bool isBSDLike(object::Archive::Kind Kind)
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.
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Expected< sys::fs::perms > getAccessMode() const
Function Alias Analysis false
static void printRestOfMemberHeader(raw_fd_ostream &Out, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, unsigned Size)
Expected< unsigned > getUID() 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().
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static sys::TimePoint< std::chrono::seconds > now(bool Deterministic)
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
perms permissions() const
static void write(bool isBE, void *P, T V)
void consumeError(Error Err)
Consume a Error without doing anything.
raw_ostream & write(unsigned char C)
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
StringRef getBuffer() const
static bool useStringTable(bool Thin, StringRef Name)
StringRef str()
Return a StringRef for the vector contents.
reference get()
Returns a reference to the stored T value.
static Expected< NewArchiveMember > getOldMember(const object::Archive::Child &OldMember, bool Deterministic)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Expected< sys::TimePoint< std::chrono::seconds > > getLastModified() const
StringRef str() const
Explicit conversion to StringRef.
basic_symbol_iterator_range symbols() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
A raw_ostream that writes to a file descriptor.
static void printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, unsigned Size)
static void writeStringTable(raw_fd_ostream &Out, StringRef ArcName, ArrayRef< NewArchiveMember > Members, std::vector< unsigned > &StringMapIndexes, bool Thin)
This is a value type class that represents a single symbol in the list of symbols in the object file...
TimePoint getLastModificationTime() const
static Expected< NewArchiveMember > getFile(StringRef FileName, bool Deterministic)
void close()
Manually flush the stream and close the file.
static std::string computeRelativePath(StringRef From, StringRef To)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void printWithSpacePadding(raw_fd_ostream &OS, T Data, unsigned Size, bool MayTruncate=false)
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...
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 Expected< std::string > replace(StringRef S, StringRef From, StringRef To)
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
sys::TimePoint< std::chrono::seconds > ModTime
Expected< MemoryBufferRef > getMemoryBufferRef() const
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.