1//===- Archive.h - ar archive file format -----------------------*- C++ -*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file declares the ar archive file format class. 11//===----------------------------------------------------------------------===// 13#ifndef LLVM_OBJECT_ARCHIVE_H 14#define LLVM_OBJECT_ARCHIVE_H 45virtual std::unique_ptr<AbstractArchiveMemberHeader>
clone()
const = 0;
48 /// Get the name without looking up long names. 55 /// Get the name looking up long names. 60 /// Get next file member location. 69 /// Returns the size in bytes of the format-defined member header of the 70 /// concrete archive type. 98charSize[10];
///< Size of data, not including header or padding. 107 std::unique_ptr<AbstractArchiveMemberHeader>
clone()
const override{
108return std::make_unique<ArchiveMemberHeader>(*
this);
121charSize[20];
// File member size in decimal 128charNameLen[4];
// File member name length in decimal 130charName[2];
// Start of member name 135// Define file member header of AIX big archive. 142 std::unique_ptr<AbstractArchiveMemberHeader>
clone()
const override{
143return std::make_unique<BigArchiveMemberHeader>(*
this);
165 std::unique_ptr<AbstractArchiveMemberHeader> Header;
166 /// Includes header but not padding byte. 168 /// Offset from Data to the start of the file. 178 : Parent(
C.Parent), Data(
C.Data), StartOfFile(
C.StartOfFile) {
180 Header =
C.Header->clone();
184 Parent = std::move(
C.Parent);
185 Header = std::move(
C.Header);
187 StartOfFile =
C.StartOfFile;
194 Parent = std::move(
C.Parent);
195 Header = std::move(
C.Header);
197 StartOfFile =
C.StartOfFile;
208 Header =
C.Header->clone();
210 StartOfFile =
C.StartOfFile;
216assert(!Parent || !other.Parent || Parent == other.Parent);
217return Data.begin() == other.Data.
begin();
228return Header->getLastModified();
232return Header->getRawLastModified();
239return Header->getAccessMode();
242 /// \return the size of the archive member without the header or padding. 244 /// \return the size in the archive header for this member. 268// Ignore errors here: If an error occurred during increment then getNext 269// will have been set to child_end(), and the following comparison should 270// do the right thing. 275return !(*
this == other);
279auto NextChild = C.getNext();
281return NextChild.takeError();
282 C = std::move(*NextChild);
292uint32_t StringIndex;
// Extra index to the string. 296 : Parent(p), SymbolIndex(symi), StringIndex(stri) {}
299return (Parent == other.Parent) && (SymbolIndex == other.SymbolIndex);
318return symbol == other.symbol;
322return !(*
this == other);
334 /// Size field is 10 decimal digits long 347bool SkipInternal =
true)
const{
361// check if a symbol is in the archive 373return std::move(ThinBuffers);
376 std::unique_ptr<AbstractArchiveMemberHeader>
390uint16_t FirstRegularStartOfFile = -1;
394mutable std::vector<std::unique_ptr<MemoryBuffer>> ThinBuffers;
399 /// Fixed-Length Header. 428}
// end namespace object 429}
// end namespace llvm 431#endif// LLVM_OBJECT_ARCHIVE_H assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
This is an important class for using LLVM in a threaded context.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
A wrapper class for fallible iterators.
A range adaptor for a pair of iterators.
virtual StringRef getRawGID() const =0
virtual StringRef getRawUID() const =0
Expected< unsigned > getUID() const
virtual Expected< uint64_t > getSize() const =0
Expected< sys::fs::perms > getAccessMode() const
AbstractArchiveMemberHeader(const Archive *Parent)
virtual ~AbstractArchiveMemberHeader()=default
Expected< unsigned > getGID() const
virtual uint64_t getOffset() const =0
virtual Expected< const char * > getNextChildLoc() const =0
Get next file member location.
virtual Expected< StringRef > getRawName() const =0
Get the name without looking up long names.
virtual Expected< bool > isThin() const =0
Expected< sys::TimePoint< std::chrono::seconds > > getLastModified() const
virtual uint64_t getSizeOf() const =0
Returns the size in bytes of the format-defined member header of the concrete archive type.
virtual StringRef getRawAccessMode() const =0
virtual std::unique_ptr< AbstractArchiveMemberHeader > clone() const =0
virtual StringRef getRawLastModified() const =0
virtual Expected< StringRef > getName(uint64_t Size) const =0
Get the name looking up long names.
std::unique_ptr< AbstractArchiveMemberHeader > clone() const override
Expected< StringRef > getName(uint64_t Size) const override
Get the name looking up long names.
Expected< StringRef > getRawName() const override
Get the name without looking up long names.
Expected< bool > isThin() const override
Expected< uint64_t > getSize() const override
Expected< const char * > getNextChildLoc() const override
Get next file member location.
const Child * operator->() const
bool operator==(const ChildFallibleIterator &other) const
const Child & operator*() const
bool operator!=(const ChildFallibleIterator &other) const
ChildFallibleIterator(const Child &C)
Expected< StringRef > getBuffer() const
StringRef getRawLastModified() const
Expected< Child > getNext() const
bool operator==(const Child &other) const
Expected< std::string > getFullName() const
uint64_t getChildOffset() const
Expected< uint64_t > getRawSize() const
Expected< StringRef > getName() const
Expected< uint64_t > getSize() const
Child & operator=(const Child &C)
Expected< unsigned > getGID() const
uint64_t getDataOffset() const
Expected< StringRef > getRawName() const
Expected< std::unique_ptr< Binary > > getAsBinary(LLVMContext *Context=nullptr) const
Expected< MemoryBufferRef > getMemoryBufferRef() const
Expected< unsigned > getUID() const
Child & operator=(Child &&C) noexcept
Expected< sys::fs::perms > getAccessMode() const
Expected< sys::TimePoint< std::chrono::seconds > > getLastModified() const
const Archive * getParent() const
Symbol(const Archive *p, uint32_t symi, uint32_t stri)
Expected< Child > getMember() const
bool operator==(const Symbol &other) const
StringRef getName() const
symbol_iterator & operator++()
const Symbol & operator*() const
bool operator!=(const symbol_iterator &other) const
const Symbol * operator->() const
symbol_iterator(const Symbol &s)
bool operator==(const symbol_iterator &other) const
std::unique_ptr< AbstractArchiveMemberHeader > createArchiveMemberHeader(const char *RawHeaderPtr, uint64_t Size, Error *Err) const
symbol_iterator symbol_begin() const
iterator_range< symbol_iterator > symbols() const
virtual uint64_t getFirstChildOffset() const
StringRef getStringTable() const
uint32_t getNumberOfSymbols() const
fallible_iterator< ChildFallibleIterator > child_iterator
uint32_t getNumberOfECSymbols() const
void setFirstRegular(const Child &C)
uint64_t getArchiveMagicLen() const
StringRef getSymbolTable() const
symbol_iterator symbol_end() const
static object::Archive::Kind getDefaultKind()
iterator_range< child_iterator > children(Error &Err, bool SkipInternal=true) const
virtual bool isEmpty() const
child_iterator child_end() const
bool hasSymbolTable() const
static bool classof(Binary const *v)
static object::Archive::Kind getDefaultKindForTriple(const Triple &T)
Expected< iterator_range< symbol_iterator > > ec_symbols() const
Expected< std::optional< Child > > findSym(StringRef name) const
child_iterator child_begin(Error &Err, bool SkipInternal=true) const
static const uint64_t MaxMemberSize
Size field is 10 decimal digits long.
std::vector< std::unique_ptr< MemoryBuffer > > takeThinBuffers()
static Expected< std::unique_ptr< Archive > > create(MemoryBufferRef Source)
Expected< uint64_t > getSize() const override
Expected< StringRef > getRawName() const override
Get the name without looking up long names.
Expected< bool > isThin() const override
std::unique_ptr< AbstractArchiveMemberHeader > clone() const override
Expected< const char * > getNextChildLoc() const override
Get next file member location.
Expected< StringRef > getName(uint64_t Size) const override
Get the name looking up long names.
Expected< uint64_t > getRawNameSize() const
Expected< uint64_t > getNextOffset() const
bool isEmpty() const override
bool Has32BitGlobalSymtab
uint64_t getLastChildOffset() const
std::string MergedGlobalSymtabBuf
bool Has64BitGlobalSymtab
const FixLenHdr * ArFixLenHdr
uint64_t FirstChildOffset
bool has32BitGlobalSymtab()
uint64_t getFirstChildOffset() const override
bool has64BitGlobalSymtab()
StringRef getRawLastModified() const override
StringRef getRawUID() const override
CommonArchiveMemberHeader(const Archive *Parent, const T *RawHeaderPtr)
uint64_t getSizeOf() const override
Returns the size in bytes of the format-defined member header of the concrete archive type.
uint64_t getOffset() const override
StringRef getRawAccessMode() const override
StringRef getRawGID() const override
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
const char ArchiveMagic[]
const char ThinArchiveMagic[]
const char BigArchiveMagic[]
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
char Magic[sizeof(BigArchiveMagic) - 1]
Big archive magic string.
char FirstChildOffset[20]
Offset to first archive member.
char LastChildOffset[20]
Offset to last archive member.
char FreeOffset[20]
Offset to first mem on free list.
char GlobSym64Offset[20]
Offset global symbol table for 64-bit objects.
char MemOffset[20]
Offset to member table.
char GlobSymOffset[20]
Offset to global symbol table.
char Size[10]
Size of data, not including header or padding.