1//===- ArchiveWriter.cpp - ar File Format implementation --------*- 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 defines the writeArchive function. 11//===----------------------------------------------------------------------===// 41#if !defined(_MSC_VER) && !defined(__MINGW32__) 52 std::map<std::string, uint16_t>
Map;
53 std::map<std::string, uint16_t>
ECMap;
58 MemberName(BufRef.getBufferIdentifier()) {}
61auto MemBufferRef = this->
Buf->getMemBufferRef();
66if (isa<object::MachOObjectFile>(**OptionalObject))
68if (isa<object::XCOFFObjectFile>(**OptionalObject))
70if (isa<object::COFFObjectFile>(**OptionalObject) ||
71 isa<object::COFFImportFile>(**OptionalObject))
76// Squelch the error in case we had a non-object file. 79// If we're adding a bitcode file to the archive, detect the Archive kind 80// based on the target triple. 85auto &IRObject = cast<object::IRObjectFile>(**ObjOrErr);
86auto TargetTriple =
Triple(IRObject.getTargetTriple());
89// Squelch the error in case this was not a SymbolicFile. 106 M.MemberName = M.Buf->getBufferIdentifier();
110return ModTimeOrErr.takeError();
111 M.ModTime = ModTimeOrErr.get();
115 M.UID = UIDOrErr.
get();
119 M.GID = GIDOrErr.
get();
123 M.Perms = AccessModeOrErr.
get();
133return FDOrErr.takeError();
140// Opening a directory doesn't make sense. Let it fail. 141// Linux cannot open directories with open(2), although 142// cygwin and *bsd can. 148if (!MemberBufferOrErr)
155 M.Buf = std::move(*MemberBufferOrErr);
156 M.MemberName = M.Buf->getBufferIdentifier();
158 M.ModTime = std::chrono::time_point_cast<std::chrono::seconds>(
159Status.getLastModificationTime());
162 M.Perms =
Status.permissions();
171unsigned SizeSoFar =
OS.
tell() - OldPos;
172assert(SizeSoFar <=
Size &&
"Data doesn't fit in Size");
220// The format has only 6 chars for uid and gid. Truncate if the provided 233unsigned UID,
unsigned GID,
unsigned Perms,
244// Pad so that even 64 bit object files are aligned. 246unsigned NameWithPadding =
Name.size() + Pad;
249 NameWithPadding +
Size);
258unsigned UID,
unsigned GID,
unsigned Perms,
261unsigned NameLen =
Name.size();
267// The big archive format has 12 chars for uid and gid. 277 Out <<
"`\n";
// Terminator 281return Thin ||
Name.size() >= 16 ||
Name.contains(
'/');
317if (Insertion.second) {
325 NamePos = Insertion.first->second;
333 std::vector<unsigned> Symbols;
338 std::unique_ptr<SymbolicFile> SymFile =
nullptr;
351return {{}, std::move(Header), Names, Pad ?
"\n" :
""};
355using namespacestd::chrono;
358return time_point_cast<seconds>(system_clock::now());
365// TODO: Actually report errors helpfully. 379 print<uint64_t>(Out,
Kind, Val);
381 print<uint32_t>(Out,
Kind, Val);
388assert((OffsetSize == 4 || OffsetSize == 8) &&
"Unsupported OffsetSize");
391Size += NumSyms * OffsetSize * 2;
// Table 393Size += NumSyms * OffsetSize;
// Table 395Size += OffsetSize;
// byte count 396Size += StringTableSize;
397// ld64 expects the members to be 8-byte aligned for 64-bit content and at 398// least 4-byte aligned for 32-bit content. Opt for the larger encoding 400// We do this for all bsd formats because it simplifies aligning members. 401// For the big archive format, the symbol table is the last member, so there 402// is no need to align. 452 PrevMemberOffset, NextMemberOffset);
466auto computeSymbolTableHeaderSize = [=] {
472uint32_t HeaderSize = computeSymbolTableHeaderSize();
473uint64_tSize = strlen(
"!<arch>\n") + HeaderSize + SymtabSize;
481returnSize + StringMemberSize;
488// Don't attempt to read non-symbolic file types. 494// An error reading a bitcode file most likely indicates that the file 495// was created by a compiler from the future. Normally we don't try to 496// implement forwards compatibility for bitcode files, but when creating an 497// archive we can implement best-effort forwards compatibility by treating 498// the file as a blob and not creating symbol index entries for it. lld and 499// mold ignore the archive symbol index, so provided that you use one of 500// these linkers, LTO will work as long as lld or the gold plugin is newer 501// than the compiler. We only ignore errors if the archive format is one 502// that is supported by a linker that is known to ignore the index, 503// otherwise there's no chance of this working so we may as well error out. 504// We print a warning on read failure so that users of linkers that rely on 505// the symbol index can diagnose the issue. 507// This is the same behavior as GNU ar when the linker plugin returns an 508// error when reading the input file. If the bitcode file is actually 509// malformed, it will be diagnosed at link time. 515 Warn(ObjOrErr.takeError());
521return ObjOrErr.takeError();
524return std::move(*ObjOrErr);
528return ObjOrErr.takeError();
529return std::move(*ObjOrErr);
534return SymObj !=
nullptr ? SymObj->
is64Bit() :
false;
537// Log2 of PAGESIZE(4096) on an AIX system. 540// In the AIX big archive format, since the data content follows the member file 541// name, if the name ends on an odd byte, an extra byte will be added for 542// padding. This ensures that the data within the member file starts at an even 546template <
typename AuxiliaryHeader>
549// If the member doesn't have an auxiliary header, it isn't a loadable object 550// and so it just needs aligning at the minimum value. 551if (AuxHeader ==
nullptr)
554// If the auxiliary header does not have both MaxAlignOfData and 555// MaxAlignOfText field, it is not a loadable shared object file, so align at 556// the minimum value. The 'ModuleType' member is located right after 557// 'MaxAlignOfData' in the AuxiliaryHeader. 558if (AuxHeaderSize <
offsetof(AuxiliaryHeader, ModuleType))
561// If the XCOFF object file does not have a loader section, it is not 562// loadable, so align at the minimum value. 563if (AuxHeader->SecNumOfLoader == 0)
566// The content of the loadable member file needs to be aligned at MAX(maximum 567// alignment of .text, maximum alignment of .data) if there are both fields. 568// If the desired alignment is > PAGESIZE, 32-bit members are aligned on a 569// word boundary, while 64-bit members are aligned on a PAGESIZE(2^12=4096) 572 std::max(AuxHeader->MaxAlignOfText, AuxHeader->MaxAlignOfData);
576// AIX big archives may contain shared object members. The AIX OS requires these 577// members to be aligned if they are 64-bit and recommends it for 32-bit 578// members. This ensures that when these members are loaded they are aligned in 585// If the desired alignment is > PAGESIZE, 32-bit members are aligned on a 586// word boundary, while 64-bit members are aligned on a PAGESIZE boundary. 598unsigned NumSyms,
uint64_t PrevMemberOffset = 0,
600bool Is64Bit =
false) {
601// We don't write a symbol table on an archive with no members -- except on 602// Darwin, where the linker will abort unless the archive has a symbol table. 619for (
const MemberData &M : Members) {
621 Pos += M.PreHeadPadSize;
623 Pos += M.Header.size() + M.Data.size() + M.Padding.size();
628for (
unsigned StringOffset : M.Symbols) {
633 Pos += M.Header.size() + M.Data.size() + M.Padding.size();
637// byte count of the string table 654 printLE<uint32_t>(Out, Members.
size());
655for (
const MemberData &M : Members) {
656printLE(Out, Pos);
// member offset 657 Pos += M.Header.size() + M.Data.size() + M.Padding.size();
660 printLE<uint32_t>(Out,
SymMap.
Map.size());
665 Out << S.first <<
'\0';
684 Out << S.first <<
'\0';
691return cast<llvm::object::COFFObjectFile>(&Obj)->getMachine() !=
695return cast<llvm::object::COFFImportFile>(&Obj)->getMachine() !=
740 std::vector<unsigned> Ret;
745 std::map<std::string, uint16_t> *Map =
nullptr;
755if (
Error E = S.printName(NameStream))
757if (!Map->try_emplace(
Name, Index).second)
758continue;
// ignore duplicated symbol 760 Ret.push_back(SymNames.
tell());
761 SymNames <<
Name <<
'\0';
762// If EC is enabled, then the import descriptors are NOT put into EC 763// objects so we need to copy them to the EC map manually. 768 Ret.push_back(SymNames.
tell());
769if (
Error E = S.printName(SymNames))
783staticchar PaddingData[8] = {
'\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n'};
788 std::vector<MemberData> Ret;
789bool HasObject =
false;
791// Deduplicate long member names in the string table and reuse earlier name 792// offsets. This especially saves space for COFF Import libraries where all 793// members have the same name. 796// UniqueTimestamps is a special case to improve debugging on Darwin: 798// The Darwin linker does not link debug info into the final 799// binary. Instead, it emits entries of type N_OSO in the output 800// binary's symbol table, containing references to the linked-in 801// object files. Using that reference, the debugger can read the 802// debug data directly from the object files. Alternatively, an 803// invocation of 'dsymutil' will link the debug data from the object 804// files into a dSYM bundle, which can be loaded by the debugger, 805// instead of the object files. 807// For an object file, the N_OSO entries contain the absolute path 808// path to the file, and the file's timestamp. For an object 809// included in an archive, the path is formatted like 810// "/absolute/path/to/archive.a(member.o)", and the timestamp is the 811// archive member's timestamp, rather than the archive's timestamp. 813// However, this doesn't always uniquely identify an object within 814// an archive -- an archive file can have multiple entries with the 815// same filename. (This will happen commonly if the original object 816// files started in different directories.) The only way they get 817// distinguished, then, is via the timestamp. But this process is 818// unable to find the correct object file in the archive when there 819// are two files of the same name and timestamp. 821// Additionally, timestamp==0 is treated specially, and causes the 822// timestamp to be ignored as a match criteria. 824// That will "usually" work out okay when creating an archive not in 825// deterministic timestamp mode, because the objects will probably 826// have been created at different timestamps. 828// To ameliorate this problem, in deterministic archive mode (which 829// is the default), on Darwin we will emit a unique non-zero 830// timestamp for each entry with a duplicated name. This is still 831// deterministic: the only thing affecting that timestamp is the 832// order of the files in the resultant archive. 834// See also the functions that handle the lookup: 835// in lldb: ObjectContainerBSDArchive::Archive::FindObject() 836// in llvm/tools/dsymutil: BinaryHolder::GetArchiveMemberBuffers(). 838 std::map<StringRef, unsigned> FilenameCount;
839if (UniqueTimestamps) {
841 FilenameCount[M.MemberName]++;
842for (
auto &Entry : FilenameCount)
843 Entry.second = Entry.second > 1 ? 1 : 0;
846 std::vector<std::unique_ptr<SymbolicFile>> SymFiles;
851 M.Buf->getMemBufferRef(), Context,
Kind, [&](
Error Err) {
852 Warn(createFileError(M.MemberName, std::move(Err)));
856 SymFiles.push_back(std::move(*SymFileOrErr));
864// When IsEC is not specified by the caller, use it when we have both 865// any ARM64 object (ARM64 or ARM64EC) and any EC object (ARM64EC or 866// AMD64). This may be a single ARM64EC object, but may also be separate 867// ARM64 and AMD64 objects. 868bool HaveArm64 =
false, HaveEC =
false;
869for (std::unique_ptr<SymbolicFile> &SymFile : SymFiles) {
876if (HaveArm64 && HaveEC) {
884// The big archive format needs to know the offset of the previous member 889for (
uint32_t Index = 0; Index < NewMembers.
size(); ++Index) {
897// ld64 expects the members to be 8-byte aligned for 64-bit content and at 898// least 4-byte aligned for 32-bit content. Opt for the larger encoding 899// uniformly. This matches the behaviour with cctools and ensures that ld64 900// is happy with archives that we generate. 901unsigned MemberPadding =
903unsigned TailPadding =
909// Increment timestamp for each file of a given name. 912 ModTime = M->ModTime;
916 std::string StringMsg =
917"File " + M->MemberName.str() +
" exceeds size limit";
918return make_error<object::GenericBinaryError>(
922 std::unique_ptr<SymbolicFile> CurSymFile;
923if (!SymFiles.empty())
924 CurSymFile = std::move(SymFiles[Index]);
926// In the big archive file format, we need to calculate and include the next 927// member offset and previous member offset in the file member header. 930alignTo(M->MemberName.size(), 2);
932if (M == NewMembers.
begin())
938 MemHeadPadSize = NextMemHeadPadSize;
939 Pos += MemHeadPadSize;
943// If there is another member file after this, we need to calculate the 944// padding before the header. 945if (Index + 1 != SymFiles.size()) {
948alignTo(NewMembers[Index + 1].MemberName.
size(), 2);
953 NextOffset += NextMemHeadPadSize;
956 M->Perms,
Size, PrevOffset, NextOffset);
964 std::vector<unsigned> Symbols;
970 Symbols = std::move(*SymbolsOrErr);
975 Pos += Header.size() +
Data.size() + Padding.size();
976 Ret.push_back({std::move(Symbols), std::move(Header),
Data, Padding,
977 MemHeadPadSize, std::move(CurSymFile)});
979// If there are no symbols, emit an empty symbol table, to satisfy Solaris 980// tools, older versions of which expect a symbol table in a non-empty 981// archive, regardless of whether there are any symbols in it. 983 SymNames <<
'\0' <<
'\0' <<
'\0';
984return std::move(Ret);
998// Compute the relative path from From to To. 1002if (!PathToOrErr || !DirFromOrErr)
1008// Can't construct a relative path between different roots 1012// Skip common prefixes 1016auto FromI = FromTo.first;
1017auto ToI = FromTo.second;
1019// Construct relative path 1021for (
auto FromE =
sys::path::end(DirFrom); FromI != FromE; ++FromI)
1027return std::string(Relative);
1034bool Thin, std::optional<bool> IsEC,
1045// COFF symbol map uses 16-bit indexes, so we can't use it if there are too 1046// many members. COFF format also requires symbol table presence, so use 1047// GNU format when NoSymtab is requested. 1051// In the scenario when LLVMContext is populated SymbolicFile will contain a 1052// reference to it, thus SymbolicFile should be destroyed first. 1060 std::vector<MemberData> &
Data = *DataOrErr;
1063 MemberData StringTableMember;
1066 StringTableSize = StringTableMember.Header.size() +
1067 StringTableMember.Data.size() +
1068 StringTableMember.Padding.size();
1071// We would like to detect if we need to switch to a 64-bit symbol table. 1073uint64_t LastMemberHeaderOffset = 0;
1075uint64_t NumSyms32 = 0;
// Store symbol number of 32-bit member files. 1077for (
constauto &M :
Data) {
1078// Record the start of the member's offset 1079 LastMemberEndOffset += M.PreHeadPadSize;
1080 LastMemberHeaderOffset = LastMemberEndOffset;
1081// Account for the size of each part associated with the member. 1082 LastMemberEndOffset += M.Header.size() + M.Data.size() + M.Padding.size();
1083 NumSyms += M.Symbols.size();
1085// AIX big archive files may contain two global symbol tables. The 1086// first global symbol table locates 32-bit file members that define global 1087// symbols; the second global symbol table does the same for 64-bit file 1088// members. As a big archive can have both 32-bit and 64-bit file members, 1089// we need to know the number of symbols in each symbol table individually. 1092 NumSyms32 += M.Symbols.size();
1096 std::optional<uint64_t> HeadersSize;
1098// The symbol table is put at the end of the big archive file. The symbol 1099// table is at the start of the archive file for other archive formats. 1101// We assume 32-bit offsets to see if 32-bit symbols are possible or not. 1103 NumSyms, SymNamesBuf.
size(),
1106// The SYM64 format is used when an archive's member offsets are larger than 1107// 32-bits can hold. The need for this shift in format is detected by 1108// writeArchive. To test this we need to generate a file with a member that 1109// has an offset larger than 32-bits but this demands a very slow test. To 1110// speed the test up we use this environment variable to pretend like the 1111// cutoff happens before 32-bits and instead happens at some much smaller 1113uint64_t Sym64Threshold = 1ULL << 32;
1114constchar *Sym64Env = std::getenv(
"SYM64_THRESHOLD");
1118// If LastMemberHeaderOffset isn't going to fit in a 32-bit varible we need 1119// to switch to 64-bit. Note that the file can be larger than 4GB as long as 1120// the last member starts before the 4GB offset. 1121if (*HeadersSize + LastMemberHeaderOffset >= Sym64Threshold) {
1126 HeadersSize.reset();
1138if (ShouldWriteSymtab) {
1141Kind,
Data.size(), StringTableSize, NumSyms, SymNamesBuf.
size(),
1144 *HeadersSize, NumSyms);
1151 Out << StringTableMember.Header << StringTableMember.Data
1152 << StringTableMember.Padding;
1157for (
const MemberData &M :
Data)
1158 Out << M.Header << M.Data << M.Padding;
1161 LastMemberEndOffset += *HeadersSize;
1162 LastMemberHeaderOffset += *HeadersSize;
1164// For the big archive (AIX) format, compute a table of member names and 1165// offsets, used in the member table. 1166uint64_t MemberTableNameStrTblSize = 0;
1167 std::vector<size_t> MemberOffsets;
1168 std::vector<StringRef> MemberNames;
1169// Loop across object to find offset and names. 1173 MemberTableNameStrTblSize += Member.MemberName.size() + 1;
1174 MemberEndOffset +=
Data[
I].PreHeadPadSize;
1175 MemberOffsets.push_back(MemberEndOffset);
1176 MemberNames.push_back(Member.MemberName);
1177// File member name ended with "`\n". The length is included in 1181alignTo(Member.MemberName.size(), 2);
1184// AIX member table size. 1185uint64_t MemberTableSize = 20 +
// Number of members field 1186 20 * MemberOffsets.size() +
1187 MemberTableNameStrTblSize;
1194if (ShouldWriteSymtab && NumSyms)
1195// Generate the symbol names for the members. 1196for (
constauto &M :
Data) {
1206 LastMemberEndOffset +
1209// In AIX OS, The 'GlobSymOffset' field in the fixed-length header contains 1210// the offset to the 32-bit global symbol table, and the 'GlobSym64Offset' 1211// contains the offset to the 64-bit global symbol table. 1213 (ShouldWriteSymtab &&
1215 ? MemberTableEndOffset
1219uint64_t NumSyms64 = NumSyms - NumSyms32;
1222if (GlobalSymbolOffset == 0)
1223 GlobalSymbolOffset64 = MemberTableEndOffset;
1225// If there is a global symbol table for 32-bit members, 1226// the 64-bit global symbol table is after the 32-bit one. 1227 GlobalSymbolOffset64 =
1229 (NumSyms32 + 1) * 8 +
alignTo(SymNamesBuf32.
size(), 2);
1232// Fixed Sized Header. 1234 20);
// Offset to member table 1235// If there are no file members in the archive, there will be no global 1242Data[0].PreHeadPadSize
1244 20);
// Offset to first archive member 1246 20);
// Offset to last archive member 1249 20);
// Offset to first member of free list - Not supported yet 1251for (
const MemberData &M :
Data) {
1252 Out << std::string(M.PreHeadPadSize,
'\0');
1253 Out << M.Header << M.Data;
1254if (M.Data.size() % 2)
1258if (NewMembers.
size()) {
1261 MemberTableSize, LastMemberHeaderOffset,
1262 GlobalSymbolOffset ? GlobalSymbolOffset
1263 : GlobalSymbolOffset64);
1265for (
uint64_t MemberOffset : MemberOffsets)
1267 20);
// Offset to member file header. 1269 Out << MemberName <<
'\0';
// Member file name, null byte padding. 1271if (MemberTableNameStrTblSize % 2)
1272 Out <<
'\0';
// Name table must be tail padded to an even number of 1275if (ShouldWriteSymtab) {
1276// Write global symbol table for 32-bit file members. 1277if (GlobalSymbolOffset) {
1279 *HeadersSize, NumSyms32, LastMemberEndOffset,
1280 GlobalSymbolOffset64);
1281// Add padding between the symbol tables, if needed. 1282if (GlobalSymbolOffset64 && (SymNamesBuf32.
size() % 2))
1286// Write global symbol table for 64-bit file members. 1287if (GlobalSymbolOffset64)
1289 *HeadersSize, NumSyms64,
1290 GlobalSymbolOffset ? GlobalSymbolOffset
1291 : LastMemberEndOffset,
1306bool Deterministic,
bool Thin,
1307 std::unique_ptr<MemoryBuffer> OldArchiveBuf,
1316 Deterministic, Thin, IsEC, Warn)) {
1317if (
Error DiscardError = Temp->discard())
1318returnjoinErrors(std::move(E), std::move(DiscardError));
1322// At this point, we no longer need whatever backing memory 1323// was used to generate the NewMembers. On Windows, this buffer 1324// could be a mapped view of the file we want to replace (if 1325// we're updating an existing archive, say). In that case, the 1326// rename would still succeed, but it would leave behind a 1327// temporary file (actually the original file renamed) because 1328// a file cannot be deleted while there's a handle open on it, 1329// only renamed. So by freeing this buffer, this ensures that 1330// the last open handle on the destination file, if any, is 1331// closed before we attempt to rename. 1332 OldArchiveBuf.reset();
1334return Temp->keep(ArcName);
1340bool Deterministic,
bool Thin,
1347 Deterministic, Thin, std::nullopt, Warn))
1350return std::make_unique<SmallVectorMemoryBuffer>(
1351 std::move(ArchiveBufferVector),
/*RequiresNullTerminator=*/false);
This file defines the StringMap class.
#define offsetof(TYPE, MEMBER)
static void printNBits(raw_ostream &Out, object::Archive::Kind Kind, uint64_t Val)
bool isImportDescriptor(StringRef Name)
static sys::TimePoint< std::chrono::seconds > now(bool Deterministic)
static bool isDarwin(object::Archive::Kind Kind)
static uint64_t computeECSymbolsSize(SymMap &SymMap, uint32_t *Padding=nullptr)
static Expected< std::vector< unsigned > > getSymbols(SymbolicFile *Obj, uint16_t Index, raw_ostream &SymNames, SymMap *SymMap)
static bool is64BitSymbolicFile(const SymbolicFile *SymObj)
static uint64_t computeHeadersSize(object::Archive::Kind Kind, uint64_t NumMembers, uint64_t StringMemberSize, uint64_t NumSyms, uint64_t SymNamesSize, SymMap *SymMap)
static bool isBSDLike(object::Archive::Kind Kind)
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)
static void writeSymbolTable(raw_ostream &Out, object::Archive::Kind Kind, bool Deterministic, ArrayRef< MemberData > Members, StringRef StringTable, uint64_t MembersOffset, unsigned NumSyms, uint64_t PrevMemberOffset=0, uint64_t NextMemberOffset=0, bool Is64Bit=false)
static const uint32_t MinBigArchiveMemDataAlign
static void writeSymbolMap(raw_ostream &Out, object::Archive::Kind Kind, bool Deterministic, ArrayRef< MemberData > Members, SymMap &SymMap, uint64_t MembersOffset)
static MemberData computeStringTable(StringRef Names)
uint16_t getAuxMaxAlignment(uint16_t AuxHeaderSize, AuxiliaryHeader *AuxHeader, uint16_t Log2OfMaxAlign)
static const uint32_t Log2OfAIXPageSize
static bool isECObject(object::SymbolicFile &Obj)
static Expected< std::unique_ptr< SymbolicFile > > getSymbolicFile(MemoryBufferRef Buf, LLVMContext &Context, object::Archive::Kind Kind, function_ref< void(Error)> Warn)
static bool isAIXBigArchive(object::Archive::Kind Kind)
static void writeSymbolTableHeader(raw_ostream &Out, object::Archive::Kind Kind, bool Deterministic, uint64_t Size, uint64_t PrevMemberOffset=0, uint64_t NextMemberOffset=0)
static void printRestOfMemberHeader(raw_ostream &Out, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, uint64_t Size)
static uint64_t computeSymbolTableSize(object::Archive::Kind Kind, uint64_t NumSyms, uint64_t OffsetSize, uint64_t StringTableSize, uint32_t *Padding=nullptr)
static bool isArchiveSymbol(const object::BasicSymbolRef &S)
static bool isCOFFArchive(object::Archive::Kind Kind)
static Expected< std::vector< MemberData > > computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames, object::Archive::Kind Kind, bool Thin, bool Deterministic, SymtabWritingMode NeedSymbols, SymMap *SymMap, LLVMContext &Context, ArrayRef< NewArchiveMember > NewMembers, std::optional< bool > IsEC, function_ref< void(Error)> Warn)
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)
static void writeECSymbols(raw_ostream &Out, object::Archive::Kind Kind, bool Deterministic, ArrayRef< MemberData > Members, SymMap &SymMap)
static uint64_t computeSymbolMapSize(uint64_t NumObj, SymMap &SymMap, uint32_t *Padding=nullptr)
static void printLE(raw_ostream &Out, T Val)
static void printGNUSmallMemberHeader(raw_ostream &Out, StringRef Name, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, uint64_t Size)
static bool useStringTable(bool Thin, StringRef Name)
static bool is64BitKind(object::Archive::Kind Kind)
static uint32_t getMemberAlignment(SymbolicFile *SymObj)
static void printBigArchiveMemberHeader(raw_ostream &Out, StringRef Name, const sys::TimePoint< std::chrono::seconds > &ModTime, unsigned UID, unsigned GID, unsigned Perms, uint64_t Size, uint64_t PrevOffset, uint64_t NextOffset)
static void printWithSpacePadding(raw_ostream &OS, T Data, unsigned Size)
static bool isAnyArm64COFF(object::SymbolicFile &Obj)
BlockVerifier::State From
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Represents either an error or a value T.
std::error_code getError() const
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.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
This is an important class for using LLVM in a threaded context.
size_t getBufferSize() const
StringRef getBuffer() const
This interface provides simple read-only access to a block of memory, and provides simple methods for...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringRef - Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr size_t size() const
size - Get the string size.
A table of densely packed, null-terminated strings indexed by offset.
constexpr size_t size() const
Returns the byte size of the table.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
An efficient, type-erasing, non-owning reference to a callable.
Expected< unsigned > getGID() const
Expected< MemoryBufferRef > getMemoryBufferRef() const
Expected< unsigned > getUID() const
Expected< sys::fs::perms > getAccessMode() const
Expected< sys::TimePoint< std::chrono::seconds > > getLastModified() const
static object::Archive::Kind getDefaultKind()
static object::Archive::Kind getDefaultKindForTriple(const Triple &T)
static const uint64_t MaxMemberSize
Size field is 10 decimal digits long.
This is a value type class that represents a single symbol in the list of symbols in the object file.
Expected< uint32_t > getFlags() const
Get symbol flags (bitwise OR of SymbolRef::Flags)
bool isCOFFImportFile() const
MemoryBufferRef getMemoryBufferRef() const
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
static Expected< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object, llvm::file_magic Type, LLVMContext *Context, bool InitContent=true)
virtual bool is64Bit() const =0
basic_symbol_iterator_range symbols() const
static bool isSymbolicFile(file_magic Type, const LLVMContext *Context)
const XCOFFAuxiliaryHeader32 * auxiliaryHeader32() const
const XCOFFFileHeader64 * fileHeader64() const
const XCOFFFileHeader32 * fileHeader32() const
const XCOFFAuxiliaryHeader64 * auxiliaryHeader64() const
bool is64Bit() const override
A raw_ostream that writes to a file descriptor.
This class implements an extremely fast bulk output stream that can only output to a stream.
uint64_t tell() const
tell - Return the current offset with the file.
raw_ostream & write(unsigned char C)
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
static Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write, OpenFlags ExtraFlags=OF_None)
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().
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_FILE_MACHINE_ARM64
bool isAnyArm64(T Machine)
constexpr std::string_view NullImportDescriptorSymbolName
constexpr std::string_view NullThunkDataPrefix
constexpr std::string_view NullThunkDataSuffix
constexpr std::string_view ImportDescriptorPrefix
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
void make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
const file_t kInvalidFile
std::error_code closeFile(file_t &F)
Close the file object.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
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.
const_iterator begin(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get begin iterator over path.
bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
In-place remove any '.
StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
StringRef root_name(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get root name.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
const_iterator end(StringRef path LLVM_LIFETIME_BOUND)
Get end iterator over path.
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
This is an optimization pass for GlobalISel generic memory operations.
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Expected< std::unique_ptr< MemoryBuffer > > writeArchiveToBuffer(ArrayRef< NewArchiveMember > NewMembers, SymtabWritingMode WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin, function_ref< void(Error)> Warn=warnToStderr)
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Error writeArchive(StringRef ArcName, ArrayRef< NewArchiveMember > NewMembers, SymtabWritingMode WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin, std::unique_ptr< MemoryBuffer > OldArchiveBuf=nullptr, std::optional< bool > IsEC=std::nullopt, function_ref< void(Error)> Warn=warnToStderr)
std::error_code make_error_code(BitcodeError E)
Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
Error joinErrors(Error E1, Error E2)
Concatenate errors.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
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...
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void warnToStderr(Error Err)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Expected< std::string > computeArchiveRelativePath(StringRef From, StringRef To)
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
static ErrorOr< SmallString< 128 > > canonicalizePath(StringRef P)
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.
Error writeArchiveToStream(raw_ostream &Out, ArrayRef< NewArchiveMember > NewMembers, SymtabWritingMode WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin, std::optional< bool > IsEC=std::nullopt, function_ref< void(Error)> Warn=warnToStderr)
void consumeError(Error Err)
Consume a Error without doing anything.
std::map< std::string, uint16_t > ECMap
std::map< std::string, uint16_t > Map
This struct is a compact representation of a valid (non-zero power of two) alignment.
object::Archive::Kind detectKindFromObject() const
NewArchiveMember()=default
static Expected< NewArchiveMember > getFile(StringRef FileName, bool Deterministic)
static Expected< NewArchiveMember > getOldMember(const object::Archive::Child &OldMember, bool Deterministic)
std::unique_ptr< MemoryBuffer > Buf
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
support::ubig16_t AuxHeaderSize
support::ubig16_t AuxHeaderSize