LLVM 24.0.0git
Archive.cpp
Go to the documentation of this file.
1//===- Archive.cpp - ar File Format implementation ------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ArchiveObjectFile class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/Object/Archive.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/ADT/Twine.h"
18#include "llvm/Object/Binary.h"
19#include "llvm/Object/Error.h"
20#include "llvm/Support/Chrono.h"
22#include "llvm/Support/Endian.h"
24#include "llvm/Support/Error.h"
29#include "llvm/Support/Path.h"
32#include <cassert>
33#include <cstddef>
34#include <cstdint>
35#include <memory>
36#include <string>
37#include <system_error>
38
39using namespace llvm;
40using namespace object;
41using namespace llvm::support::endian;
42
43void Archive::anchor() {}
44
46 std::string StringMsg = "truncated or malformed archive (" + Msg.str() + ")";
47 return make_error<GenericBinaryError>(std::move(StringMsg),
49}
50
51static Error
53 const char *RawHeaderPtr, uint64_t Size) {
54 StringRef Msg("remaining size of archive too small for next archive "
55 "member header ");
56
57 Expected<StringRef> NameOrErr = ArMemHeader->getName(Size);
58 if (NameOrErr)
59 return malformedError(Msg + "for " + *NameOrErr);
60
61 consumeError(NameOrErr.takeError());
62 uint64_t Offset = RawHeaderPtr - ArMemHeader->Parent->getData().data();
63 return malformedError(Msg + "at offset " + Twine(Offset));
64}
65
66template <class T, std::size_t N>
68 return StringRef(Field, N).rtrim(" ");
69}
70
71template <class T>
75
76template <class T>
80
82 return getFieldRawString(ArMemHdr->UID);
83}
84
89template <class T> uint64_t CommonArchiveMemberHeader<T>::getOffset() const {
90 return reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
91}
92
95
97 const char *RawHeaderPtr,
98 uint64_t Size, Error *Err)
100 Parent, reinterpret_cast<const UnixArMemHdrType *>(RawHeaderPtr)) {
101 if (RawHeaderPtr == nullptr)
102 return;
103 ErrorAsOutParameter ErrAsOutParam(Err);
104
105 if (Size < getSizeOf()) {
106 *Err = createMemberHeaderParseError(this, RawHeaderPtr, Size);
107 return;
108 }
109 // '\x79\x15' is the EBCDIC equivalent of '`\n' for the z/OS archive
110 // terminator.
111 bool ValidTerminator =
112 Parent->kind() == Archive::K_ZOS
113 ? (ArMemHdr->Terminator[0] == '\x79' &&
114 ArMemHdr->Terminator[1] == '\x15')
115 : (ArMemHdr->Terminator[0] == '`' && ArMemHdr->Terminator[1] == '\n');
116 if (!ValidTerminator) {
117 if (Err) {
118 std::string Buf;
119 raw_string_ostream OS(Buf);
120 OS.write_escaped(
121 StringRef(ArMemHdr->Terminator, sizeof(ArMemHdr->Terminator)));
122 std::string Msg("terminator characters in archive member \"" + Buf +
123 "\" not the correct \"`\\n\" values for the archive "
124 "member header ");
125 Expected<StringRef> NameOrErr = getName(Size);
126 if (!NameOrErr) {
127 consumeError(NameOrErr.takeError());
128 uint64_t Offset = RawHeaderPtr - Parent->getData().data();
129 *Err = malformedError(Msg + "at offset " + Twine(Offset));
130 } else {
131 *Err = malformedError(Msg + "for " + NameOrErr.get());
132 }
133 }
134 return;
135 }
136}
137
139 const char *RawHeaderPtr,
140 uint64_t Size, Error *Err)
142 Parent, reinterpret_cast<const BigArMemHdrType *>(RawHeaderPtr)) {
143 if (RawHeaderPtr == nullptr)
144 return;
145 ErrorAsOutParameter ErrAsOutParam(Err);
146
147 if (RawHeaderPtr + getSizeOf() >= Parent->getData().end()) {
148 if (Err)
149 *Err = malformedError("malformed AIX big archive: remaining buffer is "
150 "unable to contain next archive member");
151 return;
152 }
153
154 if (Size < getSizeOf()) {
155 Error SubErr = createMemberHeaderParseError(this, RawHeaderPtr, Size);
156 if (Err)
157 *Err = std::move(SubErr);
158 }
159}
160
161// This gets the raw name from the ArMemHdr->Name field and checks that it is
162// valid for the kind of archive. If it is not valid it returns an Error.
164 char EndCond;
165 auto Kind = Parent->kind();
167 if (ArMemHdr->Name[0] == ' ') {
168 uint64_t Offset =
169 reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
170 return malformedError("name contains a leading space for archive member "
171 "header at offset " +
172 Twine(Offset));
173 }
174 EndCond = ' ';
175 } else if (ArMemHdr->Name[0] == '/' || ArMemHdr->Name[0] == '#')
176 EndCond = ' ';
177 else
178 EndCond = '/';
180 StringRef(ArMemHdr->Name, sizeof(ArMemHdr->Name)).find(EndCond);
181 if (end == StringRef::npos)
182 end = sizeof(ArMemHdr->Name);
183 assert(end <= sizeof(ArMemHdr->Name) && end > 0);
184 // Don't include the EndCond if there is one.
185 return StringRef(ArMemHdr->Name, end);
186}
187
189getArchiveMemberDecField(Twine FieldName, const StringRef RawField,
190 const Archive *Parent,
191 const AbstractArchiveMemberHeader *MemHeader) {
193 if (RawField.getAsInteger(10, Value)) {
194 uint64_t Offset = MemHeader->getOffset();
195 return malformedError("characters in " + FieldName +
196 " field in archive member header are not "
197 "all decimal numbers: '" +
198 RawField +
199 "' for the archive "
200 "member header at offset " +
201 Twine(Offset));
202 }
203 return Value;
204}
205
206Expected<uint64_t>
207getArchiveMemberOctField(Twine FieldName, const StringRef RawField,
208 const Archive *Parent,
209 const AbstractArchiveMemberHeader *MemHeader) {
211 if (RawField.getAsInteger(8, Value)) {
212 uint64_t Offset = MemHeader->getOffset();
213 return malformedError("characters in " + FieldName +
214 " field in archive member header are not "
215 "all octal numbers: '" +
216 RawField +
217 "' for the archive "
218 "member header at offset " +
219 Twine(Offset));
220 }
221 return Value;
222}
223
226 "NameLen", getFieldRawString(ArMemHdr->NameLen), Parent, this);
227 if (!NameLenOrErr)
228 // TODO: Out-of-line.
229 return NameLenOrErr.takeError();
230 uint64_t NameLen = NameLenOrErr.get();
231
232 // If the name length is odd, pad with '\0' to get an even length. After
233 // padding, there is the name terminator "`\n".
234 uint64_t NameLenWithPadding = alignTo(NameLen, 2);
235 StringRef NameTerminator = "`\n";
236 StringRef NameStringWithNameTerminator =
237 StringRef(ArMemHdr->Name, NameLenWithPadding + NameTerminator.size());
238 if (!NameStringWithNameTerminator.ends_with(NameTerminator)) {
239 uint64_t Offset =
240 reinterpret_cast<const char *>(ArMemHdr->Name + NameLenWithPadding) -
241 Parent->getData().data();
242 // TODO: Out-of-line.
243 return malformedError(
244 "name does not have name terminator \"`\\n\" for archive member"
245 "header at offset " +
246 Twine(Offset));
247 }
248 return StringRef(ArMemHdr->Name, NameLen);
249}
250
251// member including the header, so the size of any name following the header
252// is checked to make sure it does not overflow.
254
255 // This can be called from the ArchiveMemberHeader constructor when the
256 // archive header is truncated to produce an error message with the name.
257 // Make sure the name field is not truncated.
258 if (Size < offsetof(UnixArMemHdrType, Name) + sizeof(ArMemHdr->Name)) {
259 uint64_t ArchiveOffset =
260 reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
261 return malformedError("archive header truncated before the name field "
262 "for archive member header at offset " +
263 Twine(ArchiveOffset));
264 }
265
266 // The raw name itself can be invalid.
267 Expected<StringRef> NameOrErr = getRawName();
268 if (!NameOrErr)
269 return NameOrErr.takeError();
270 StringRef Name = NameOrErr.get();
271
272 // Check if it's a special name.
273 if (Name[0] == '/') {
274 if (Name.size() == 1) // Linker member.
275 return Name;
276 if (Name.size() == 2 && Name[1] == '/') // String table.
277 return Name;
278 // System libraries from the Windows SDK for Windows 11 contain this symbol.
279 // It looks like a CFG guard: we just skip it for now.
280 if (Name == "/<XFGHASHMAP>/")
281 return Name;
282 // Some libraries (e.g., arm64rt.lib) from the Windows WDK
283 // (version 10.0.22000.0) contain this undocumented special member.
284 if (Name == "/<ECSYMBOLS>/")
285 return Name;
286 // It's a long name.
287 // Get the string table offset.
288 std::size_t StringOffset;
289 if (Name.substr(1).rtrim(' ').getAsInteger(10, StringOffset)) {
290 std::string Buf;
291 raw_string_ostream OS(Buf);
292 OS.write_escaped(Name.substr(1).rtrim(' '));
293 uint64_t ArchiveOffset =
294 reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
295 return malformedError("long name offset characters after the '/' are "
296 "not all decimal numbers: '" +
297 Buf + "' for archive member header at offset " +
298 Twine(ArchiveOffset));
299 }
300
301 // Verify it.
302 if (StringOffset >= Parent->getStringTable().size()) {
303 uint64_t ArchiveOffset =
304 reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
305 return malformedError("long name offset " + Twine(StringOffset) +
306 " past the end of the string table for archive "
307 "member header at offset " +
308 Twine(ArchiveOffset));
309 }
310
311 // GNU long file names end with a "/\n".
312 if (Parent->kind() == Archive::K_GNU ||
313 Parent->kind() == Archive::K_GNU64) {
314 size_t End = Parent->getStringTable().find('\n', /*From=*/StringOffset);
315 if (End == StringRef::npos || End < 1 ||
316 Parent->getStringTable()[End - 1] != '/') {
317 return malformedError("string table at long name offset " +
318 Twine(StringOffset) + " not terminated");
319 }
320 return Parent->getStringTable().slice(StringOffset, End - 1);
321 }
322 return Parent->getStringTable().begin() + StringOffset;
323 }
324
325 if (Name.starts_with("#1/")) {
326 uint64_t NameLength;
327 if (Name.substr(3).rtrim(' ').getAsInteger(10, NameLength)) {
328 std::string Buf;
329 raw_string_ostream OS(Buf);
330 OS.write_escaped(Name.substr(3).rtrim(' '));
331 uint64_t ArchiveOffset =
332 reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
333 return malformedError("long name length characters after the #1/ are "
334 "not all decimal numbers: '" +
335 Buf + "' for archive member header at offset " +
336 Twine(ArchiveOffset));
337 }
338 if (getSizeOf() + NameLength > Size) {
339 uint64_t ArchiveOffset =
340 reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
341 return malformedError("long name length: " + Twine(NameLength) +
342 " extends past the end of the member or archive "
343 "for archive member header at offset " +
344 Twine(ArchiveOffset));
345 }
346 return StringRef(reinterpret_cast<const char *>(ArMemHdr) + getSizeOf(),
347 NameLength)
348 .rtrim('\0');
349 }
350
351 // It is not a long name so trim the blanks at the end of the name.
352 if (Name[Name.size() - 1] != '/')
353 return Name.rtrim(' ');
354
355 // It's a simple name.
356 return Name.drop_back(1);
357}
358
362
367
370 "size", getFieldRawString(ArMemHdr->Size), Parent, this);
371 if (!SizeOrErr)
372 return SizeOrErr.takeError();
373
374 Expected<uint64_t> NameLenOrErr = getRawNameSize();
375 if (!NameLenOrErr)
376 return NameLenOrErr.takeError();
377
378 return *SizeOrErr + alignTo(*NameLenOrErr, 2);
379}
380
381template <std::size_t N>
382std::string ebcdicFieldToASCII(const char (&Field)[N]) {
383 SmallString<64> Dst;
384 StringRef Src = StringRef(Field, N);
386 return Dst.str().rtrim(" ").str();
387}
388
390 const char *RawHeaderPtr,
391 uint64_t Size, Error *Err)
392 : ArchiveMemberHeader(Parent, RawHeaderPtr, Size, Err) {
393 ErrorAsOutParameter ErrAsOutParam(Err);
394 // If the base class constructor already detected an error
395 // do not attempt to read header fields
396 if (Err && *Err)
397 return;
399}
400
405
409
411 return StringRef(MemberName);
412}
413
417
421
423
425
427 uint64_t Offset =
428 reinterpret_cast<const char *>(ArMemHdr) - Parent->getData().data();
429
430 // Set RawMemberName
432 if (RawMemberName.empty() || RawMemberName[0] == ' ') {
433 *Err = malformedError("name contains a leading space for archive member "
434 "header at offset " +
435 Twine(Offset));
436 return;
437 }
438
439 // Set MemberName.
440 if (StringRef(RawMemberName).starts_with("#1/")) {
442 if (!NameOrErr) {
443 *Err = NameOrErr.takeError();
444 return;
445 }
446 StringRef Name = NameOrErr.get();
447 SmallString<64> ConvertedName;
448 ConverterEBCDIC::convertToUTF8(Name, ConvertedName);
449 MemberName = std::string(ConvertedName);
450 } else {
452 }
453
454 // LastModified
456 if (LastModified.empty()) {
457 *Err =
458 malformedError("LastModified field is empty or contains only spaces in "
459 "archive member header at offset " +
460 Twine(Offset));
461 return;
462 }
463
464 // UID
466 if (UID.empty()) {
467 *Err = malformedError("UID field is empty or contains only spaces in "
468 "archive member header at offset " +
469 Twine(Offset));
470 return;
471 }
472
473 // GID
475 if (GID.empty()) {
476 *Err = malformedError("GID field is empty or contains only spaces in "
477 "archive member header at offset " +
478 Twine(Offset));
479 return;
480 }
481
482 // AccessMode
484 if (AccessMode.empty()) {
485 *Err =
486 malformedError("AccessMode field is empty or contains only spaces in "
487 "archive member header at offset " +
488 Twine(Offset));
489 return;
490 }
491}
492
497
502
504 Expected<uint64_t> AccessModeOrErr =
505 getArchiveMemberOctField("AccessMode", getRawAccessMode(), Parent, this);
506 if (!AccessModeOrErr)
507 return AccessModeOrErr.takeError();
508 return static_cast<sys::fs::perms>(*AccessModeOrErr);
509}
510
514 "LastModified", getRawLastModified(), Parent, this);
515
516 if (!SecondsOrErr)
517 return SecondsOrErr.takeError();
518
519 return sys::toTimePoint(*SecondsOrErr);
520}
521
524 if (User.empty())
525 return 0;
526 return getArchiveMemberDecField("UID", User, Parent, this);
527}
528
530 StringRef Group = getRawGID();
531 if (Group.empty())
532 return 0;
533 return getArchiveMemberDecField("GID", Group, Parent, this);
534}
535
537 Expected<StringRef> NameOrErr = getRawName();
538 if (!NameOrErr)
539 return NameOrErr.takeError();
540 StringRef Name = NameOrErr.get();
541 return Parent->isThin() && Name != "/" && Name != "//" && Name != "/SYM64/";
542}
543
544static Error checkNextMemberOffset(uint64_t NextOffset, uint64_t ArchiveSize,
546 uint64_t MemberOffset) {
547 if (NextOffset <= ArchiveSize)
548 return Error::success();
549
550 std::string Member;
551 if (Expected<StringRef> NameOrErr = GetName()) {
552 Member = NameOrErr->str();
553 } else {
554 consumeError(NameOrErr.takeError());
555 Member = ("at offset " + Twine(MemberOffset)).str();
556 }
557
558 return malformedError(
559 "offset to next archive member (0x" + Twine::utohexstr(NextOffset) +
560 ") past the end of the archive (size 0x" + Twine::utohexstr(ArchiveSize) +
561 ") after member " + Member);
562}
563
565 uint64_t Size = getSizeOf();
566 Expected<bool> isThinOrErr = isThin();
567 if (!isThinOrErr)
568 return isThinOrErr.takeError();
569
570 bool isThin = isThinOrErr.get();
571 if (!isThin) {
572 Expected<uint64_t> MemberSize = getSize();
573 if (!MemberSize)
574 return MemberSize.takeError();
575
576 Size += MemberSize.get();
577 }
578
579 // If Size is odd, add 1 to make it even.
580 const char *NextLoc =
581 reinterpret_cast<const char *>(ArMemHdr) + alignTo(Size, 2);
582
583 if (NextLoc == Parent->getMemoryBufferRef().getBufferEnd())
584 return nullptr;
585
586 return NextLoc;
587}
588
590 if (getOffset() ==
591 static_cast<const BigArchive *>(Parent)->getLastChildOffset())
592 return nullptr;
593
594 Expected<uint64_t> NextOffsetOrErr = getNextOffset();
595 if (!NextOffsetOrErr)
596 return NextOffsetOrErr.takeError();
597
598 // NextOffset is read from the member header, so check it against the
599 // archive's size before forming the pointer. Adding a large offset to the
600 // start of the buffer wraps, and the result then compares as though it
601 // pointed inside the archive, so Child::getNext() cannot catch it.
602 uint64_t NextOffset = NextOffsetOrErr.get();
604 NextOffset, Parent->getData().size(),
605 [this]() { return getRawName(); }, getOffset()))
606 return std::move(Err);
607
608 return Parent->getData().data() + NextOffset;
609}
610
611Archive::Child::Child(const Archive *Parent, StringRef Data,
612 uint16_t StartOfFile)
613 : Parent(Parent), Data(Data), StartOfFile(StartOfFile) {
614 Header = Parent->createArchiveMemberHeader(Data.data(), Data.size(), nullptr);
615}
616
617Archive::Child::Child(const Archive *Parent, const char *Start, Error *Err)
618 : Parent(Parent) {
619 if (!Start) {
620 Header = nullptr;
621 StartOfFile = -1;
622 return;
623 }
624
625 Header = Parent->createArchiveMemberHeader(
626 Start, Parent->getData().size() - (Start - Parent->getData().data()),
627 Err);
628
629 // If we are pointed to real data, Start is not a nullptr, then there must be
630 // a non-null Err pointer available to report malformed data on. Only in
631 // the case sentinel value is being constructed is Err is permitted to be a
632 // nullptr.
633 assert(Err && "Err can't be nullptr if Start is not a nullptr");
634
635 ErrorAsOutParameter ErrAsOutParam(Err);
636
637 // If there was an error in the construction of the Header
638 // then just return with the error now set.
639 if (*Err)
640 return;
641
642 uint64_t Size = Header->getSizeOf();
643 Data = StringRef(Start, Size);
644 Expected<bool> isThinOrErr = isThinMember();
645 if (!isThinOrErr) {
646 *Err = isThinOrErr.takeError();
647 return;
648 }
649 bool isThin = isThinOrErr.get();
650 if (!isThin) {
651 Expected<uint64_t> MemberSize = getRawSize();
652 if (!MemberSize) {
653 *Err = MemberSize.takeError();
654 return;
655 }
656 Size += MemberSize.get();
657 Data = StringRef(Start, Size);
658 }
659
660 // Setup StartOfFile and PaddingBytes.
661 StartOfFile = Header->getSizeOf();
662 // Don't include attached name.
663 Expected<StringRef> NameOrErr = getRawName();
664 if (!NameOrErr) {
665 *Err = NameOrErr.takeError();
666 return;
667 }
668 StringRef Name = NameOrErr.get();
669
670 if (Parent->kind() == Archive::K_AIXBIG) {
671 // The actual start of the file is after the name and any necessary
672 // even-alignment padding.
673 StartOfFile += ((Name.size() + 1) >> 1) << 1;
674 } else if (Name.starts_with("#1/")) {
675 uint64_t NameSize;
676 StringRef RawNameSize = Name.substr(3).rtrim(' ');
677 if (RawNameSize.getAsInteger(10, NameSize)) {
678 uint64_t Offset = Start - Parent->getData().data();
679 *Err = malformedError("long name length characters after the #1/ are "
680 "not all decimal numbers: '" +
681 RawNameSize +
682 "' for archive member header at offset " +
683 Twine(Offset));
684 return;
685 }
686 StartOfFile += NameSize;
687 }
688}
689
691 if (Parent->IsThin)
692 return Header->getSize();
693 return Data.size() - StartOfFile;
694}
695
697 return Header->getSize();
698}
699
700Expected<bool> Archive::Child::isThinMember() const { return Header->isThin(); }
701
703 Expected<bool> isThin = isThinMember();
704 if (!isThin)
705 return isThin.takeError();
706 assert(isThin.get());
707 Expected<StringRef> NameOrErr = getName();
708 if (!NameOrErr)
709 return NameOrErr.takeError();
710 StringRef Name = *NameOrErr;
711 if (sys::path::is_absolute(Name))
712 return std::string(Name);
713
715 Parent->getMemoryBufferRef().getBufferIdentifier());
716 sys::path::append(FullName, Name);
717 return std::string(FullName);
718}
719
721 Expected<bool> isThinOrErr = isThinMember();
722 if (!isThinOrErr)
723 return isThinOrErr.takeError();
724 bool isThin = isThinOrErr.get();
725 if (!isThin) {
727 if (!Size)
728 return Size.takeError();
729 return StringRef(Data.data() + StartOfFile, Size.get());
730 }
731 Expected<std::string> FullNameOrErr = getFullName();
732 if (!FullNameOrErr)
733 return FullNameOrErr.takeError();
734 const std::string &FullName = *FullNameOrErr;
736 MemoryBuffer::getFile(FullName, false, /*RequiresNullTerminator=*/false);
737 if (std::error_code EC = Buf.getError())
738 return errorCodeToError(EC);
739 Parent->ThinBuffers.push_back(std::move(*Buf));
740 return Parent->ThinBuffers.back()->getBuffer();
741}
742
744 Expected<const char *> NextLocOrErr = Header->getNextChildLoc();
745 if (!NextLocOrErr)
746 return NextLocOrErr.takeError();
747
748 const char *NextLoc = *NextLocOrErr;
749
750 // Check to see if this is at the end of the archive.
751 if (NextLoc == nullptr)
752 return Child(nullptr, nullptr, nullptr);
753
754 // Check to see if this is past the end of the archive.
756 NextLoc - Parent->getData().data(), Parent->getData().size(),
757 [this]() { return getName(); },
758 Data.data() - Parent->getData().data()))
759 return std::move(Err);
760
761 Error Err = Error::success();
762 Child Ret(Parent, NextLoc, &Err);
763 if (Err)
764 return std::move(Err);
765 return Ret;
766}
767
769 const char *a = Parent->Data.getBuffer().data();
770 const char *c = Data.data();
771 uint64_t offset = c - a;
772 return offset;
773}
774
776 Expected<uint64_t> RawSizeOrErr = getRawSize();
777 if (!RawSizeOrErr)
778 return RawSizeOrErr.takeError();
779 uint64_t RawSize = RawSizeOrErr.get();
780 Expected<StringRef> NameOrErr =
781 Header->getName(Header->getSizeOf() + RawSize);
782 if (!NameOrErr)
783 return NameOrErr.takeError();
784 StringRef Name = NameOrErr.get();
785 return Name;
786}
787
789 Expected<StringRef> NameOrErr = getName();
790 if (!NameOrErr)
791 return NameOrErr.takeError();
792 StringRef Name = NameOrErr.get();
794 if (!Buf)
795 return createFileError(Name, Buf.takeError());
796 return MemoryBufferRef(*Buf, Name);
797}
798
802 if (!BuffOrErr)
803 return BuffOrErr.takeError();
804
805 auto BinaryOrErr = createBinary(BuffOrErr.get(), Context);
806 if (BinaryOrErr)
807 return std::move(*BinaryOrErr);
808 return BinaryOrErr.takeError();
809}
810
812 Error Err = Error::success();
813 std::unique_ptr<Archive> Ret;
814 StringRef Buffer = Source.getBuffer();
815
816 if (Buffer.starts_with(BigArchiveMagic))
817 Ret = std::make_unique<BigArchive>(Source, Err);
818 else if (Buffer.starts_with(ZOSArchiveMagic))
819 Ret = std::make_unique<ZOSArchive>(Source, Err);
820 else
821 Ret = std::make_unique<Archive>(Source, Err);
822
823 if (Err)
824 return std::move(Err);
825 return std::move(Ret);
826}
827
828std::unique_ptr<AbstractArchiveMemberHeader>
829Archive::createArchiveMemberHeader(const char *RawHeaderPtr, uint64_t Size,
830 Error *Err) const {
831 ErrorAsOutParameter ErrAsOutParam(Err);
832
833 if (kind() == K_ZOS)
834 return std::make_unique<ZOSArchiveMemberHeader>(this, RawHeaderPtr, Size,
835 Err);
836 if (kind() != K_AIXBIG)
837 return std::make_unique<ArchiveMemberHeader>(this, RawHeaderPtr, Size, Err);
838 return std::make_unique<BigArchiveMemberHeader>(this, RawHeaderPtr, Size,
839 Err);
840}
841
843 if (isThin())
844 return sizeof(ThinArchiveMagic) - 1;
845
846 if (Kind() == K_AIXBIG)
847 return sizeof(BigArchiveMagic) - 1;
848
849 return sizeof(ArchiveMagic) - 1;
850}
851
853 FirstRegularData = C.Data;
854 FirstRegularStartOfFile = C.StartOfFile;
855}
856
858 : Binary(Binary::ID_Archive, Source) {
859 ErrorAsOutParameter ErrAsOutParam(Err);
860 StringRef Buffer = Data.getBuffer();
861 // Check for sufficient magic.
862 if (Buffer.starts_with(ThinArchiveMagic)) {
863 IsThin = true;
864 } else if (Buffer.starts_with(ArchiveMagic)) {
865 IsThin = false;
866 } else if (Buffer.starts_with(BigArchiveMagic)) {
867 Format = K_AIXBIG;
868 IsThin = false;
869 return;
870 } else if (Buffer.starts_with(ZOSArchiveMagic)) {
871 Format = K_ZOS;
872 IsThin = false;
873 return;
874 } else {
875 Err = make_error<GenericBinaryError>("file too small to be an archive",
877 return;
878 }
879
880 // Make sure Format is initialized before any call to
881 // ArchiveMemberHeader::getName() is made. This could be a valid empty
882 // archive which is the same in all formats. So claiming it to be gnu to is
883 // fine if not totally correct before we look for a string table or table of
884 // contents.
885 Format = K_GNU;
886
887 // Get the special members.
888 child_iterator I = child_begin(Err, false);
889 if (Err)
890 return;
892
893 // See if this is a valid empty archive and if so return.
894 if (I == E) {
895 Err = Error::success();
896 return;
897 }
898 const Child *C = &*I;
899
900 auto Increment = [&]() {
901 ++I;
902 if (Err)
903 return true;
904 C = &*I;
905 return false;
906 };
907
908 Expected<StringRef> NameOrErr = C->getRawName();
909 if (!NameOrErr) {
910 Err = NameOrErr.takeError();
911 return;
912 }
913 StringRef Name = NameOrErr.get();
914
915 // Below is the pattern that is used to figure out the archive format
916 // GNU archive format
917 // First member : / (may exist, if it exists, points to the symbol table )
918 // Second member : // (may exist, if it exists, points to the string table)
919 // Note : The string table is used if the filename exceeds 15 characters
920 // BSD archive format
921 // First member : __.SYMDEF or "__.SYMDEF SORTED" (the symbol table)
922 // There is no string table, if the filename exceeds 15 characters or has a
923 // embedded space, the filename has #1/<size>, The size represents the size
924 // of the filename that needs to be read after the archive header
925 // COFF archive format
926 // First member : /
927 // Second member : / (provides a directory of symbols)
928 // Third member : // (may exist, if it exists, contains the string table)
929 // Note: Microsoft PE/COFF Spec 8.3 says that the third member is present
930 // even if the string table is empty. However, lib.exe does not in fact
931 // seem to create the third member if there's no member whose filename
932 // exceeds 15 characters. So the third member is optional.
933
934 if (Name == "__.SYMDEF" || Name == "__.SYMDEF_64") {
935 if (Name == "__.SYMDEF")
936 Format = K_BSD;
937 else // Name == "__.SYMDEF_64"
938 Format = K_DARWIN64;
939 // We know that the symbol table is not an external file, but we still must
940 // check any Expected<> return value.
941 Expected<StringRef> BufOrErr = C->getBuffer();
942 if (!BufOrErr) {
943 Err = BufOrErr.takeError();
944 return;
945 }
946 SymbolTable = BufOrErr.get();
947 if (Increment())
948 return;
950
951 Err = Error::success();
952 return;
953 }
954
955 if (Name.starts_with("#1/")) {
956 Format = K_BSD;
957 // We know this is BSD, so getName will work since there is no string table.
958 Expected<StringRef> NameOrErr = C->getName();
959 if (!NameOrErr) {
960 Err = NameOrErr.takeError();
961 return;
962 }
963 Name = NameOrErr.get();
964 if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
965 // We know that the symbol table is not an external file, but we still
966 // must check any Expected<> return value.
967 Expected<StringRef> BufOrErr = C->getBuffer();
968 if (!BufOrErr) {
969 Err = BufOrErr.takeError();
970 return;
971 }
972 SymbolTable = BufOrErr.get();
973 if (Increment())
974 return;
975 } else if (Name == "__.SYMDEF_64 SORTED" || Name == "__.SYMDEF_64") {
976 Format = K_DARWIN64;
977 // We know that the symbol table is not an external file, but we still
978 // must check any Expected<> return value.
979 Expected<StringRef> BufOrErr = C->getBuffer();
980 if (!BufOrErr) {
981 Err = BufOrErr.takeError();
982 return;
983 }
984 SymbolTable = BufOrErr.get();
985 if (Increment())
986 return;
987 }
989 return;
990 }
991
992 // MIPS 64-bit ELF archives use a special format of a symbol table.
993 // This format is marked by `ar_name` field equals to "/SYM64/".
994 // For detailed description see page 96 in the following document:
995 // http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf
996
997 bool has64SymTable = false;
998 if (Name == "/" || Name == "/SYM64/") {
999 // We know that the symbol table is not an external file, but we still
1000 // must check any Expected<> return value.
1001 Expected<StringRef> BufOrErr = C->getBuffer();
1002 if (!BufOrErr) {
1003 Err = BufOrErr.takeError();
1004 return;
1005 }
1006 SymbolTable = BufOrErr.get();
1007 if (Name == "/SYM64/")
1008 has64SymTable = true;
1009
1010 if (Increment())
1011 return;
1012 if (I == E) {
1013 Err = Error::success();
1014 return;
1015 }
1016 Expected<StringRef> NameOrErr = C->getRawName();
1017 if (!NameOrErr) {
1018 Err = NameOrErr.takeError();
1019 return;
1020 }
1021 Name = NameOrErr.get();
1022 }
1023
1024 if (Name == "//") {
1025 Format = has64SymTable ? K_GNU64 : K_GNU;
1026 // The string table is never an external member, but we still
1027 // must check any Expected<> return value.
1028 Expected<StringRef> BufOrErr = C->getBuffer();
1029 if (!BufOrErr) {
1030 Err = BufOrErr.takeError();
1031 return;
1032 }
1033 StringTable = BufOrErr.get();
1034 if (Increment())
1035 return;
1037 Err = Error::success();
1038 return;
1039 }
1040
1041 if (Name[0] != '/') {
1042 Format = has64SymTable ? K_GNU64 : K_GNU;
1044 Err = Error::success();
1045 return;
1046 }
1047
1048 if (Name != "/") {
1050 return;
1051 }
1052
1053 Format = K_COFF;
1054 // We know that the symbol table is not an external file, but we still
1055 // must check any Expected<> return value.
1056 Expected<StringRef> BufOrErr = C->getBuffer();
1057 if (!BufOrErr) {
1058 Err = BufOrErr.takeError();
1059 return;
1060 }
1061 SymbolTable = BufOrErr.get();
1062
1063 if (Increment())
1064 return;
1065
1066 if (I == E) {
1068 Err = Error::success();
1069 return;
1070 }
1071
1072 NameOrErr = C->getRawName();
1073 if (!NameOrErr) {
1074 Err = NameOrErr.takeError();
1075 return;
1076 }
1077 Name = NameOrErr.get();
1078
1079 if (Name == "//") {
1080 // The string table is never an external member, but we still
1081 // must check any Expected<> return value.
1082 Expected<StringRef> BufOrErr = C->getBuffer();
1083 if (!BufOrErr) {
1084 Err = BufOrErr.takeError();
1085 return;
1086 }
1087 StringTable = BufOrErr.get();
1088 if (Increment())
1089 return;
1090
1091 if (I == E) {
1093 Err = Error::success();
1094 return;
1095 }
1096
1097 NameOrErr = C->getRawName();
1098 if (!NameOrErr) {
1099 Err = NameOrErr.takeError();
1100 return;
1101 }
1102 Name = NameOrErr.get();
1103 }
1104
1105 if (Name == "/<ECSYMBOLS>/") {
1106 // ARM64EC-aware libraries contain an additional special member with
1107 // an EC symbol map after the string table. Its format is similar to a
1108 // regular symbol map, except it doesn't contain member offsets. Its indexes
1109 // refer to member offsets from the regular symbol table instead.
1110 Expected<StringRef> BufOrErr = C->getBuffer();
1111 if (!BufOrErr) {
1112 Err = BufOrErr.takeError();
1113 return;
1114 }
1115 ECSymbolTable = BufOrErr.get();
1116 if (Increment())
1117 return;
1118 }
1119
1121 Err = Error::success();
1122}
1123
1125 if (T.isOSDarwin())
1127 if (T.isOSAIX())
1129 if (T.isOSWindows())
1131 if (T.isOSzOS())
1134}
1135
1140
1142 bool SkipInternal) const {
1143 if (isEmpty())
1144 return child_end();
1145
1146 if (SkipInternal)
1147 return child_iterator::itr(
1148 Child(this, FirstRegularData, FirstRegularStartOfFile), Err);
1149
1150 const char *Loc = Data.getBufferStart() + getFirstChildOffset();
1151 Child C(this, Loc, &Err);
1152 if (Err)
1153 return child_end();
1154 return child_iterator::itr(C, Err);
1155}
1156
1158 return child_iterator::end(Child(nullptr, nullptr, nullptr));
1159}
1160
1162 // Symbols use SymbolCount..SymbolCount+getNumberOfECSymbols() for EC symbol
1163 // indexes.
1164 uint32_t SymbolCount = Parent->getNumberOfSymbols();
1165 return SymbolCount <= SymbolIndex &&
1166 SymbolIndex < SymbolCount + Parent->getNumberOfECSymbols();
1167}
1168
1170 assert(Parent->kind() == K_ZOS && "Cannot get z/OS attributes for non-z/OS "
1171 "archives");
1172 if (SymbolIndex >= Parent->getNumberOfSymbols())
1173 return 0;
1174
1175 // The z/OS symbol table layout is:
1176 // NumSyms * { uint32_t member_offset, uint32_t attrs } (big-endian)
1177 const char *Buf = Parent->getSymbolTable().begin();
1178 return read32be(Buf + sizeof(uint32_t) + SymbolIndex * 8 + sizeof(uint32_t));
1179}
1180
1182 if (isECSymbol())
1183 return Parent->ECSymbolTable.begin() + StringIndex;
1184 return Parent->getSymbolTable().begin() + StringIndex;
1185}
1186
1188 const char *Buf = Parent->getSymbolTable().begin();
1189 const char *Offsets = Buf;
1190 if (Parent->kind() == K_GNU64 || Parent->kind() == K_DARWIN64 ||
1191 Parent->kind() == K_AIXBIG)
1192 Offsets += sizeof(uint64_t);
1193 else
1194 Offsets += sizeof(uint32_t);
1195 uint64_t Offset = 0;
1196 if (Parent->kind() == K_GNU) {
1197 Offset = read32be(Offsets + SymbolIndex * 4);
1198 } else if (Parent->kind() == K_GNU64 || Parent->kind() == K_AIXBIG) {
1199 Offset = read64be(Offsets + SymbolIndex * 8);
1200 } else if (Parent->kind() == K_BSD) {
1201 // The SymbolIndex is an index into the ranlib structs that start at
1202 // Offsets (the first uint32_t is the number of bytes of the ranlib
1203 // structs). The ranlib structs are a pair of uint32_t's the first
1204 // being a string table offset and the second being the offset into
1205 // the archive of the member that defines the symbol. Which is what
1206 // is needed here.
1207 Offset = read32le(Offsets + SymbolIndex * 8 + 4);
1208 } else if (Parent->kind() == K_DARWIN64) {
1209 // The SymbolIndex is an index into the ranlib_64 structs that start at
1210 // Offsets (the first uint64_t is the number of bytes of the ranlib_64
1211 // structs). The ranlib_64 structs are a pair of uint64_t's the first
1212 // being a string table offset and the second being the offset into
1213 // the archive of the member that defines the symbol. Which is what
1214 // is needed here.
1215 Offset = read64le(Offsets + SymbolIndex * 16 + 8);
1216 } else if (Parent->kind() == K_ZOS) {
1217 // Each entry in the offset array is 8 bytes long:
1218 // A 4-byte offset followed by 4 bytes of coded attributes.
1219 // We multiply the SymbolIndex by 8 to reach the correct entry,
1220 // and read the first 4 bytes (the offset).
1221 Offset = read32be(Offsets + SymbolIndex * 8);
1222 } else {
1223 // Skip offsets.
1224 uint32_t MemberCount = read32le(Buf);
1225 Buf += MemberCount * 4 + 4;
1226
1227 uint32_t SymbolCount = read32le(Buf);
1228 uint16_t OffsetIndex;
1229 if (SymbolIndex < SymbolCount) {
1230 // Skip SymbolCount to get to the indices table.
1231 const char *Indices = Buf + 4;
1232
1233 // Get the index of the offset in the file member offset table for this
1234 // symbol.
1235 OffsetIndex = read16le(Indices + SymbolIndex * 2);
1236 } else if (isECSymbol()) {
1237 // Skip SymbolCount to get to the indices table.
1238 const char *Indices = Parent->ECSymbolTable.begin() + 4;
1239
1240 // Get the index of the offset in the file member offset table for this
1241 // symbol.
1242 OffsetIndex = read16le(Indices + (SymbolIndex - SymbolCount) * 2);
1243 } else {
1245 }
1246 // Subtract 1 since OffsetIndex is 1 based.
1247 --OffsetIndex;
1248
1249 if (OffsetIndex >= MemberCount)
1251
1252 Offset = read32le(Offsets + OffsetIndex * 4);
1253 }
1254
1255 const char *Loc = Parent->getData().begin() + Offset;
1256 Error Err = Error::success();
1257 Child C(Parent, Loc, &Err);
1258 if (Err)
1259 return std::move(Err);
1260 return C;
1261}
1262
1264 Symbol t(*this);
1265 if (Parent->kind() == K_BSD) {
1266 // t.StringIndex is an offset from the start of the __.SYMDEF or
1267 // "__.SYMDEF SORTED" member into the string table for the ranlib
1268 // struct indexed by t.SymbolIndex . To change t.StringIndex to the
1269 // offset in the string table for t.SymbolIndex+1 we subtract the
1270 // its offset from the start of the string table for t.SymbolIndex
1271 // and add the offset of the string table for t.SymbolIndex+1.
1272
1273 // The __.SYMDEF or "__.SYMDEF SORTED" member starts with a uint32_t
1274 // which is the number of bytes of ranlib structs that follow. The ranlib
1275 // structs are a pair of uint32_t's the first being a string table offset
1276 // and the second being the offset into the archive of the member that
1277 // define the symbol. After that the next uint32_t is the byte count of
1278 // the string table followed by the string table.
1279 const char *Buf = Parent->getSymbolTable().begin();
1280 uint32_t RanlibCount = 0;
1281 RanlibCount = read32le(Buf) / 8;
1282 // If t.SymbolIndex + 1 will be past the count of symbols (the RanlibCount)
1283 // don't change the t.StringIndex as we don't want to reference a ranlib
1284 // past RanlibCount.
1285 if (t.SymbolIndex + 1 < RanlibCount) {
1286 const char *Ranlibs = Buf + 4;
1287 uint32_t CurRanStrx = 0;
1288 uint32_t NextRanStrx = 0;
1289 CurRanStrx = read32le(Ranlibs + t.SymbolIndex * 8);
1290 NextRanStrx = read32le(Ranlibs + (t.SymbolIndex + 1) * 8);
1291 t.StringIndex -= CurRanStrx;
1292 t.StringIndex += NextRanStrx;
1293 }
1294 } else if (t.isECSymbol()) {
1295 // Go to one past next null.
1296 t.StringIndex = Parent->ECSymbolTable.find('\0', t.StringIndex) + 1;
1297 } else {
1298 // Go to one past next null.
1299 t.StringIndex = Parent->getSymbolTable().find('\0', t.StringIndex) + 1;
1300 }
1301 ++t.SymbolIndex;
1302 return t;
1303}
1304
1306 if (!hasSymbolTable())
1307 return symbol_iterator(Symbol(this, 0, 0));
1308
1309 const char *buf = getSymbolTable().begin();
1310 if (kind() == K_GNU) {
1311 uint32_t symbol_count = 0;
1312 symbol_count = read32be(buf);
1313 buf += sizeof(uint32_t) + (symbol_count * (sizeof(uint32_t)));
1314 } else if (kind() == K_GNU64) {
1315 uint64_t symbol_count = read64be(buf);
1316 buf += sizeof(uint64_t) + (symbol_count * (sizeof(uint64_t)));
1317 } else if (kind() == K_BSD) {
1318 // The __.SYMDEF or "__.SYMDEF SORTED" member starts with a uint32_t
1319 // which is the number of bytes of ranlib structs that follow. The ranlib
1320 // structs are a pair of uint32_t's the first being a string table offset
1321 // and the second being the offset into the archive of the member that
1322 // define the symbol. After that the next uint32_t is the byte count of
1323 // the string table followed by the string table.
1324 uint32_t ranlib_count = 0;
1325 ranlib_count = read32le(buf) / 8;
1326 const char *ranlibs = buf + 4;
1327 uint32_t ran_strx = 0;
1328 ran_strx = read32le(ranlibs);
1329 buf += sizeof(uint32_t) + (ranlib_count * (2 * (sizeof(uint32_t))));
1330 // Skip the byte count of the string table.
1331 buf += sizeof(uint32_t);
1332 buf += ran_strx;
1333 } else if (kind() == K_DARWIN64) {
1334 // The __.SYMDEF_64 or "__.SYMDEF_64 SORTED" member starts with a uint64_t
1335 // which is the number of bytes of ranlib_64 structs that follow. The
1336 // ranlib_64 structs are a pair of uint64_t's the first being a string
1337 // table offset and the second being the offset into the archive of the
1338 // member that define the symbol. After that the next uint64_t is the byte
1339 // count of the string table followed by the string table.
1340 uint64_t ranlib_count = 0;
1341 ranlib_count = read64le(buf) / 16;
1342 const char *ranlibs = buf + 8;
1343 uint64_t ran_strx = 0;
1344 ran_strx = read64le(ranlibs);
1345 buf += sizeof(uint64_t) + (ranlib_count * (2 * (sizeof(uint64_t))));
1346 // Skip the byte count of the string table.
1347 buf += sizeof(uint64_t);
1348 buf += ran_strx;
1349 } else if (kind() == K_AIXBIG) {
1350 buf = getStringTable().begin();
1351 } else if (kind() == K_ZOS) {
1352 // The contents of the z/OS symbol table member are:
1353 // 1. The number of symbols, NS (4-byte integer).
1354 // 2. NS pairs of 4-byte integers (offset and attributes). Length is NS*8
1355 // bytes.
1356 // 3. NS null terminated strings of corresponding symbol names.
1357 // Here we skip parts 1 and 2 to reach the start of the string table.
1358 uint32_t SymbolCount = read32be(buf);
1359 buf += sizeof(uint32_t) + (SymbolCount * (sizeof(uint64_t)));
1360 } else {
1361 uint32_t member_count = 0;
1362 uint32_t symbol_count = 0;
1363 member_count = read32le(buf);
1364 buf += 4 + (member_count * 4); // Skip offsets.
1365 symbol_count = read32le(buf);
1366 buf += 4 + (symbol_count * 2); // Skip indices.
1367 }
1368 uint32_t string_start_offset = buf - getSymbolTable().begin();
1369 return symbol_iterator(Symbol(this, 0, string_start_offset));
1370}
1371
1375
1377 uint32_t Count = 0;
1378
1379 // Validate EC symbol table.
1380 if (!ECSymbolTable.empty()) {
1381 if (ECSymbolTable.size() < sizeof(uint32_t))
1382 return malformedError("invalid EC symbols size (" +
1383 Twine(ECSymbolTable.size()) + ")");
1384 if (SymbolTable.size() < sizeof(uint32_t))
1385 return malformedError("invalid symbols size (" +
1386 Twine(ECSymbolTable.size()) + ")");
1387
1388 Count = read32le(ECSymbolTable.begin());
1389 size_t StringIndex = sizeof(uint32_t) + Count * sizeof(uint16_t);
1390 if (ECSymbolTable.size() < StringIndex)
1391 return malformedError("invalid EC symbols size. Size was " +
1392 Twine(ECSymbolTable.size()) + ", but expected " +
1393 Twine(StringIndex));
1394
1395 uint32_t MemberCount = read32le(SymbolTable.begin());
1396 const char *Indexes = ECSymbolTable.begin() + sizeof(uint32_t);
1397
1398 for (uint32_t i = 0; i < Count; ++i) {
1399 uint16_t Index = read16le(Indexes + i * sizeof(uint16_t));
1400 if (!Index)
1401 return malformedError("invalid EC symbol index 0");
1402 if (Index > MemberCount)
1403 return malformedError("invalid EC symbol index " + Twine(Index) +
1404 " is larger than member count " +
1405 Twine(MemberCount));
1406
1407 StringIndex = ECSymbolTable.find('\0', StringIndex);
1408 if (StringIndex == StringRef::npos)
1409 return malformedError("malformed EC symbol names: not null-terminated");
1410 ++StringIndex;
1411 }
1412 }
1413
1414 uint32_t SymbolCount = getNumberOfSymbols();
1415 return make_range(
1416 symbol_iterator(Symbol(this, SymbolCount,
1417 sizeof(uint32_t) + Count * sizeof(uint16_t))),
1418 symbol_iterator(Symbol(this, SymbolCount + Count, 0)));
1419}
1420
1422 if (!hasSymbolTable())
1423 return 0;
1424 const char *buf = getSymbolTable().begin();
1425 if (kind() == K_GNU)
1426 return read32be(buf);
1427 if (kind() == K_GNU64 || kind() == K_AIXBIG)
1428 return read64be(buf);
1429 if (kind() == K_BSD)
1430 return read32le(buf) / 8;
1431 if (kind() == K_DARWIN64)
1432 return read64le(buf) / 16;
1433 if (kind() == K_ZOS)
1434 return read32be(buf);
1435 uint32_t member_count = 0;
1436 member_count = read32le(buf);
1437 buf += 4 + (member_count * 4); // Skip offsets.
1438 return read32le(buf);
1439}
1440
1442 if (ECSymbolTable.size() < sizeof(uint32_t))
1443 return 0;
1444 return read32le(ECSymbolTable.begin());
1445}
1446
1450
1451 for (; bs != es; ++bs) {
1452 StringRef SymName = bs->getName();
1453 if (SymName == name) {
1454 if (auto MemberOrErr = bs->getMember())
1455 return Child(*MemberOrErr);
1456 else
1457 return MemberOrErr.takeError();
1458 }
1459 }
1460 return std::nullopt;
1461}
1462
1463// Returns true if archive file contains no member file.
1464bool Archive::isEmpty() const {
1465 return Data.getBufferSize() == getArchiveMagicLen();
1466}
1467
1468bool Archive::hasSymbolTable() const { return !SymbolTable.empty(); }
1469
1471 uint64_t GlobalSymtabOffset,
1472 const char *&GlobalSymtabLoc,
1473 uint64_t &Size, const char *BitMessage) {
1474 uint64_t BufferSize = Data.getBufferSize();
1475 uint64_t GlobalSymtabContentOffset =
1476 GlobalSymtabOffset + sizeof(BigArMemHdrType);
1477 if (GlobalSymtabContentOffset > BufferSize)
1478 return malformedError(
1479 Twine(BitMessage) + " global symbol table header at offset 0x" +
1480 Twine::utohexstr(GlobalSymtabOffset) + " and size 0x" +
1482 " goes past the end of file");
1483
1484 GlobalSymtabLoc = Data.getBufferStart() + GlobalSymtabOffset;
1485 const BigArMemHdrType *GlobalSymHdr =
1486 reinterpret_cast<const BigArMemHdrType *>(GlobalSymtabLoc);
1487 StringRef RawOffset = getFieldRawString(GlobalSymHdr->Size);
1488 if (RawOffset.getAsInteger(10, Size))
1489 return malformedError(Twine(BitMessage) + " global symbol table size \"" +
1490 RawOffset + "\" is not a number");
1491
1492 if (GlobalSymtabContentOffset + Size > BufferSize)
1493 return malformedError(
1494 Twine(BitMessage) + " global symbol table content at offset 0x" +
1495 Twine::utohexstr(GlobalSymtabContentOffset) + " and size 0x" +
1496 Twine::utohexstr(Size) + " goes past the end of file");
1497
1498 return Error::success();
1499}
1500
1507
1508static void
1510 const char *GlobalSymtabLoc, uint64_t Size) {
1511 // In a big archive, a global symbol table contains the following information:
1512 // - The number of symbols.
1513 // - The array of offsets into the archive file. The length is eight
1514 // times the number of symbols.
1515 // - The name-string table. The size is:
1516 // Size-(8*(the number of symbols + 1)).
1517
1519 StringRef(GlobalSymtabLoc + sizeof(BigArMemHdrType), Size);
1520 uint64_t SymNum = read64be(GlobalSymtabLoc + sizeof(BigArMemHdrType));
1521 StringRef SymbolOffsetTable = StringRef(SymbolTable.data() + 8, 8 * SymNum);
1522 unsigned SymOffsetsSize = 8 * (SymNum + 1);
1523 uint64_t SymbolTableStringSize = Size - SymOffsetsSize;
1525 StringRef(SymbolTable.data() + SymOffsetsSize, SymbolTableStringSize);
1526 SymtabInfos.push_back({SymNum, SymbolTable, SymbolOffsetTable, StringTable});
1527}
1528
1530 : Archive(Source, Err) {
1531 ErrorAsOutParameter ErrAsOutParam(&Err);
1532 StringRef Buffer = Data.getBuffer();
1533 ArFixLenHdr = reinterpret_cast<const FixLenHdr *>(Buffer.data());
1534 uint64_t BufferSize = Data.getBufferSize();
1535
1536 if (BufferSize < sizeof(FixLenHdr)) {
1537 Err = malformedError("malformed AIX big archive: incomplete fixed length "
1538 "header, the archive is only" +
1539 Twine(BufferSize) + " byte(s)");
1540 return;
1541 }
1542
1543 StringRef RawOffset = getFieldRawString(ArFixLenHdr->FirstChildOffset);
1544 if (RawOffset.getAsInteger(10, FirstChildOffset))
1545 // TODO: Out-of-line.
1546 Err = malformedError("malformed AIX big archive: first member offset \"" +
1547 RawOffset + "\" is not a number");
1548
1549 RawOffset = getFieldRawString(ArFixLenHdr->LastChildOffset);
1550 if (RawOffset.getAsInteger(10, LastChildOffset))
1551 // TODO: Out-of-line.
1552 Err = malformedError("malformed AIX big archive: last member offset \"" +
1553 RawOffset + "\" is not a number");
1554
1555 uint64_t GlobSymtab32Offset = 0;
1556 RawOffset = getFieldRawString(ArFixLenHdr->GlobSymOffset);
1557 if (RawOffset.getAsInteger(10, GlobSymtab32Offset)) {
1558 Err = malformedError("global symbol table "
1559 "offset of 32-bit members \"" +
1560 RawOffset + "\" is not a number");
1561 return;
1562 }
1563
1564 uint64_t GlobSymtab64Offset = 0;
1565 RawOffset = getFieldRawString(ArFixLenHdr->GlobSym64Offset);
1566 if (RawOffset.getAsInteger(10, GlobSymtab64Offset)) {
1567 Err = malformedError("global symbol table "
1568 "offset of 64-bit members\"" +
1569 RawOffset + "\" is not a number");
1570 return;
1571 }
1572
1573 const char *GlobSymtab32Loc = nullptr;
1574 const char *GlobSymtab64Loc = nullptr;
1575 uint64_t GlobSymtab32Size = 0;
1576 uint64_t GlobSymtab64Size = 0;
1577 const MemoryBufferRef &MemBuffRef = getMemoryBufferRef();
1578
1579 if (GlobSymtab32Offset) {
1580 Err =
1581 getGlobalSymtabLocAndSize(MemBuffRef, GlobSymtab32Offset,
1582 GlobSymtab32Loc, GlobSymtab32Size, "32-bit");
1583 if (Err)
1584 return;
1585
1586 Has32BitGlobalSymtab = true;
1587 }
1588
1589 if (GlobSymtab64Offset) {
1590 Err =
1591 getGlobalSymtabLocAndSize(MemBuffRef, GlobSymtab64Offset,
1592 GlobSymtab64Loc, GlobSymtab64Size, "64-bit");
1593 if (Err)
1594 return;
1595
1596 Has64BitGlobalSymtab = true;
1597 }
1598
1600
1601 if (GlobSymtab32Offset)
1602 appendGlobalSymbolTableInfo(SymtabInfos, GlobSymtab32Loc, GlobSymtab32Size);
1603 if (GlobSymtab64Offset)
1604 appendGlobalSymbolTableInfo(SymtabInfos, GlobSymtab64Loc, GlobSymtab64Size);
1605
1606 if (SymtabInfos.size() == 1) {
1607 SymbolTable = SymtabInfos[0].SymbolTable;
1608 StringTable = SymtabInfos[0].StringTable;
1609 } else if (SymtabInfos.size() == 2) {
1610 // In order to let the Archive::Symbol::getNext() work for both 32-bit and
1611 // 64-bit global symbol tables, we need to merge them into a single table.
1613 uint64_t SymNum = SymtabInfos[0].SymNum + SymtabInfos[1].SymNum;
1614 write(Out, SymNum, llvm::endianness::big);
1615 // Merge symbol offset.
1616 Out << SymtabInfos[0].SymbolOffsetTable;
1617 Out << SymtabInfos[1].SymbolOffsetTable;
1618 // Merge string table.
1619 Out << SymtabInfos[0].StringTable;
1620 Out << SymtabInfos[1].StringTable;
1622 // The size of the symbol offset to the member file is 8 bytes.
1623 StringTable = StringRef(SymbolTable.begin() + (SymNum + 1) * 8,
1624 SymtabInfos[0].StringTable.size() +
1625 SymtabInfos[1].StringTable.size());
1626 }
1627
1628 child_iterator I = child_begin(Err, false);
1629 if (Err)
1630 return;
1632 if (I == E) {
1633 Err = Error::success();
1634 return;
1635 }
1637 Err = Error::success();
1638}
1639
1641 : Archive(Source, Err) {
1642 ErrorAsOutParameter ErrAsOutParam(&Err);
1643
1644 // Get the special members.
1645 child_iterator I = child_begin(Err, false);
1646 if (Err)
1647 return;
1649
1650 // See if this is a valid empty archive and if so return.
1651 if (I == E) {
1652 Err = Error::success();
1653 return;
1654 }
1655 const Child *C = &*I;
1656
1657 Expected<StringRef> NameOrErr = C->getRawName();
1658 if (!NameOrErr) {
1659 Err = NameOrErr.takeError();
1660 return;
1661 }
1662 StringRef Name = NameOrErr.get();
1663
1664 if (Name == "__.SYMDEF") {
1665 // Copy symbol table converting embedded EBCDIC names to ASCII.
1666 // getBuffer() cannot fail here because the Child constructor and
1667 // getNext() already validate that the member's size fits within
1668 // the archive.
1669 StringRef EbcdicSymbolTable = cantFail(C->getBuffer());
1670 if (EbcdicSymbolTable.size() < sizeof(uint32_t)) {
1671 Err = malformedError(
1672 "z/OS archive symbol table is too small to read the symbol count, "
1673 "symbol table size is " +
1674 Twine(EbcdicSymbolTable.size()));
1675 return;
1676 }
1677 uint64_t EbcdicSymbolCount = read32be(EbcdicSymbolTable.data());
1678 uint64_t OffsetToEbcdicNames =
1679 sizeof(uint32_t) + (EbcdicSymbolCount * (sizeof(uint64_t)));
1680 if (OffsetToEbcdicNames > EbcdicSymbolTable.size()) {
1681 Err = malformedError("z/OS archive symbol table names offset " +
1682 Twine(OffsetToEbcdicNames) +
1683 " exceeds symbol table size " +
1684 Twine(EbcdicSymbolTable.size()));
1685 return;
1686 }
1687 uint64_t EbcdicNamesSize = EbcdicSymbolTable.size() - OffsetToEbcdicNames;
1688 const char *EbcdicNamesPtr = EbcdicSymbolTable.data() + OffsetToEbcdicNames;
1689 StringRef EbcdicNames(EbcdicNamesPtr, EbcdicNamesSize);
1690
1691 SmallString<64> Dst;
1692 ConverterEBCDIC::convertToUTF8(EbcdicNames, Dst);
1693 SymbolTableBuf.append(EbcdicSymbolTable.data(), OffsetToEbcdicNames);
1694 SymbolTableBuf.append(Dst.str());
1695 SymbolTable = StringRef(SymbolTableBuf.data(), SymbolTableBuf.size());
1696
1697 ++I;
1698 if (Err)
1699 return;
1700 C = &*I;
1701
1703 Err = Error::success();
1704 return;
1705 }
1706
1708 Err = Error::success();
1709 return;
1710}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
uint64_t uint64_t
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file provides utility functions for converting between EBCDIC-1047 and UTF-8.
Provides ErrorOr<T> smart pointer.
#define offsetof(TYPE, MEMBER)
#define I(x, y, z)
Definition MD5.cpp:57
#define T
std::string ebcdicFieldToASCII(const char(&Field)[N])
Definition Archive.cpp:382
static void appendGlobalSymbolTableInfo(SmallVector< GlobalSymtabInfo > &SymtabInfos, const char *GlobalSymtabLoc, uint64_t Size)
Definition Archive.cpp:1509
static Error getGlobalSymtabLocAndSize(const MemoryBufferRef &Data, uint64_t GlobalSymtabOffset, const char *&GlobalSymtabLoc, uint64_t &Size, const char *BitMessage)
Definition Archive.cpp:1470
static Error malformedError(Twine Msg)
Definition Archive.cpp:45
StringRef getFieldRawString(const T(&Field)[N])
Definition Archive.cpp:67
Expected< uint64_t > getArchiveMemberOctField(Twine FieldName, const StringRef RawField, const Archive *Parent, const AbstractArchiveMemberHeader *MemHeader)
Definition Archive.cpp:207
static Error checkNextMemberOffset(uint64_t NextOffset, uint64_t ArchiveSize, function_ref< Expected< StringRef >()> GetName, uint64_t MemberOffset)
Definition Archive.cpp:544
Expected< uint64_t > getArchiveMemberDecField(Twine FieldName, const StringRef RawField, const Archive *Parent, const AbstractArchiveMemberHeader *MemHeader)
Definition Archive.cpp:189
static Error createMemberHeaderParseError(const AbstractArchiveMemberHeader *ArMemHeader, const char *RawHeaderPtr, uint64_t Size)
Definition Archive.cpp:52
OptimizedStructLayoutField Field
static StringRef getName(Value *V)
const char * Msg
static const char * name
This file defines the SmallString class.
DEMANGLE_NAMESPACE_BEGIN bool starts_with(std::string_view self, char C) noexcept
static unsigned getSize(unsigned Kind)
Helper for Errors used as out-parameters.
Definition Error.h:1160
Represents either an error or a value T.
Definition ErrorOr.h:56
std::error_code getError() const
Definition ErrorOr.h:152
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
reference get()
Returns a reference to the stored T value.
Definition Error.h:582
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition StringRef.h:490
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
iterator begin() const
Definition StringRef.h:114
size_t size_type
Definition StringRef.h:62
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
StringRef rtrim(char Char) const
Return string with consecutive Char characters starting from the right removed.
Definition StringRef.h:838
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition StringRef.h:290
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition StringRef.h:270
A table of densely packed, null-terminated strings indexed by offset.
Definition StringTable.h:34
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static Twine utohexstr(uint64_t Val)
Definition Twine.h:385
LLVM Value Representation.
Definition Value.h:75
static fallible_iterator end(ChildFallibleIterator I)
static fallible_iterator itr(ChildFallibleIterator I, Error &Err)
An efficient, type-erasing, non-owning reference to a callable.
virtual StringRef getRawGID() const =0
virtual StringRef getRawUID() const =0
LLVM_ABI Expected< unsigned > getUID() const
Definition Archive.cpp:522
LLVM_ABI Expected< sys::fs::perms > getAccessMode() const
Definition Archive.cpp:503
LLVM_ABI Expected< unsigned > getGID() const
Definition Archive.cpp:529
virtual uint64_t getOffset() const =0
LLVM_ABI Expected< sys::TimePoint< std::chrono::seconds > > getLastModified() const
Definition Archive.cpp:512
virtual StringRef getRawAccessMode() const =0
virtual StringRef getRawLastModified() const =0
virtual Expected< StringRef > getName(uint64_t Size) const =0
Get the name looking up long names.
ArchiveMemberHeader(const Archive *Parent, const char *RawHeaderPtr, uint64_t Size, Error *Err)
Definition Archive.cpp:96
Expected< StringRef > getName(uint64_t Size) const override
Get the name looking up long names.
Definition Archive.cpp:253
Expected< StringRef > getRawName() const override
Get the name without looking up long names.
Definition Archive.cpp:163
Expected< bool > isThin() const override
Definition Archive.cpp:536
Expected< uint64_t > getSize() const override
Definition Archive.cpp:363
Expected< const char * > getNextChildLoc() const override
Get next file member location.
Definition Archive.cpp:564
LLVM_ABI Expected< StringRef > getBuffer() const
Definition Archive.cpp:720
LLVM_ABI Expected< Child > getNext() const
Definition Archive.cpp:743
LLVM_ABI Expected< std::string > getFullName() const
Definition Archive.cpp:702
LLVM_ABI uint64_t getChildOffset() const
Definition Archive.cpp:768
LLVM_ABI Expected< uint64_t > getRawSize() const
Definition Archive.cpp:696
LLVM_ABI Expected< StringRef > getName() const
Definition Archive.cpp:775
LLVM_ABI Expected< uint64_t > getSize() const
Definition Archive.cpp:690
Expected< StringRef > getRawName() const
Definition Archive.h:270
LLVM_ABI Expected< std::unique_ptr< Binary > > getAsBinary(LLVMContext *Context=nullptr) const
Definition Archive.cpp:800
LLVM_ABI Expected< MemoryBufferRef > getMemoryBufferRef() const
Definition Archive.cpp:788
LLVM_ABI Child(const Archive *Parent, const char *Start, Error *Err)
Definition Archive.cpp:617
LLVM_ABI Symbol getNext() const
Definition Archive.cpp:1263
Symbol(const Archive *p, uint32_t symi, uint32_t stri)
Definition Archive.h:340
LLVM_ABI Expected< Child > getMember() const
Definition Archive.cpp:1187
LLVM_ABI StringRef getName() const
Definition Archive.cpp:1181
LLVM_ABI uint32_t getZOSAttributes() const
For K_ZOS archives, returns the 32-bit attribute word stored alongside the symbol table entry.
Definition Archive.cpp:1169
LLVM_ABI bool isECSymbol() const
Definition Archive.cpp:1161
std::unique_ptr< AbstractArchiveMemberHeader > createArchiveMemberHeader(const char *RawHeaderPtr, uint64_t Size, Error *Err) const
Definition Archive.cpp:829
symbol_iterator symbol_begin() const
Definition Archive.cpp:1305
virtual uint64_t getFirstChildOffset() const
Definition Archive.h:440
bool isThin() const
Definition Archive.h:410
StringRef getStringTable() const
Definition Archive.h:437
uint32_t getNumberOfSymbols() const
Definition Archive.cpp:1421
fallible_iterator< ChildFallibleIterator > child_iterator
Definition Archive.h:332
uint32_t getNumberOfECSymbols() const
Definition Archive.cpp:1441
void setFirstRegular(const Child &C)
Definition Archive.cpp:852
uint64_t getArchiveMagicLen() const
Definition Archive.cpp:842
StringRef getSymbolTable() const
Definition Archive.h:436
StringRef ECSymbolTable
Definition Archive.h:455
symbol_iterator symbol_end() const
Definition Archive.cpp:1372
static object::Archive::Kind getDefaultKind()
Definition Archive.cpp:1136
virtual bool isEmpty() const
Definition Archive.cpp:1464
child_iterator child_end() const
Definition Archive.cpp:1157
bool hasSymbolTable() const
Definition Archive.cpp:1468
StringRef StringTable
Definition Archive.h:456
Archive(MemoryBufferRef Source, Error &Err)
Definition Archive.cpp:857
Kind kind() const
Definition Archive.h:409
static object::Archive::Kind getDefaultKindForTriple(const Triple &T)
Definition Archive.cpp:1124
StringRef SymbolTable
Definition Archive.h:454
Expected< iterator_range< symbol_iterator > > ec_symbols() const
Definition Archive.cpp:1376
Expected< std::optional< Child > > findSym(StringRef name) const
Definition Archive.cpp:1447
child_iterator child_begin(Error &Err, bool SkipInternal=true) const
Definition Archive.cpp:1141
static Expected< std::unique_ptr< Archive > > create(MemoryBufferRef Source)
Definition Archive.cpp:811
Expected< uint64_t > getSize() const override
Definition Archive.cpp:368
Expected< StringRef > getRawName() const override
Get the name without looking up long names.
Definition Archive.cpp:224
Expected< const char * > getNextChildLoc() const override
Get next file member location.
Definition Archive.cpp:589
Expected< StringRef > getName(uint64_t Size) const override
Get the name looking up long names.
Definition Archive.cpp:359
Expected< uint64_t > getRawNameSize() const
Definition Archive.cpp:493
Expected< uint64_t > getNextOffset() const
Definition Archive.cpp:498
BigArchiveMemberHeader(Archive const *Parent, const char *RawHeaderPtr, uint64_t Size, Error *Err)
Definition Archive.cpp:138
std::string MergedGlobalSymtabBuf
Definition Archive.h:484
const FixLenHdr * ArFixLenHdr
Definition Archive.h:481
LLVM_ABI BigArchive(MemoryBufferRef Source, Error &Err)
Definition Archive.cpp:1529
MemoryBufferRef Data
Definition Binary.h:38
StringRef getData() const
Definition Binary.cpp:23
Binary(unsigned int Type, MemoryBufferRef Source)
Definition Binary.cpp:20
MemoryBufferRef getMemoryBufferRef() const
Definition Binary.cpp:27
StringRef getRawLastModified() const override
Definition Archive.cpp:77
StringRef getRawUID() const override
Definition Archive.cpp:81
CommonArchiveMemberHeader(const Archive *Parent, const UnixArMemHdrType *RawHeaderPtr)
Definition Archive.h:83
uint64_t getOffset() const override
Definition Archive.cpp:89
StringRef getRawAccessMode() const override
Definition Archive.cpp:72
StringRef getRawGID() const override
Definition Archive.cpp:85
StringRef getRawGID() const override
Definition Archive.cpp:424
StringRef getRawAccessMode() const override
Definition Archive.cpp:414
ZOSArchiveMemberHeader(Archive const *Parent, const char *RawHeaderPtr, uint64_t Size, Error *Err)
Definition Archive.cpp:389
void setMemberHeaderStrings(Error *Err, uint64_t Size)
Definition Archive.cpp:426
StringRef getRawUID() const override
Definition Archive.cpp:422
Expected< StringRef > getRawName() const override
Get the name without looking up long names.
Definition Archive.cpp:406
Expected< StringRef > getName(uint64_t Size) const override
Get the name looking up long names.
Definition Archive.cpp:410
Expected< uint64_t > getSize() const override
Definition Archive.cpp:401
StringRef getRawLastModified() const override
Definition Archive.cpp:418
LLVM_ABI ZOSArchive(MemoryBufferRef Source, Error &Err)
Definition Archive.cpp:1640
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
A raw_ostream that writes to an std::string.
LLVM_ABI void convertToUTF8(StringRef Source, SmallVectorImpl< char > &Result)
constexpr size_t NameSize
Definition XCOFF.h:30
const char ArchiveMagic[]
Definition Archive.h:34
const char ZOSArchiveMagic[]
Definition Archive.h:37
const char ThinArchiveMagic[]
Definition Archive.h:35
const char BigArchiveMagic[]
Definition Archive.h:36
LLVM_ABI Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)
Create a Binary from Source, autodetecting the file type.
uint64_t read64le(const void *P)
Definition Endian.h:415
uint16_t read16le(const void *P)
Definition Endian.h:409
uint64_t read64be(const void *P)
Definition Endian.h:424
uint32_t read32be(const void *P)
Definition Endian.h:421
uint32_t read32le(const void *P)
Definition Endian.h:412
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
Definition Path.cpp:478
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition Path.cpp:688
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition Path.cpp:467
LLVM_ABI std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
Definition Chrono.h:65
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition Error.h:1415
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition Error.cpp:107
@ Increment
Incrementally increasing token ID.
Definition AllocToken.h:26
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:267
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106
LLVM_ABI Error write(DWPWriter &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue, raw_pwrite_stream *OS=nullptr)
Definition DWP.cpp:746
#define N
StringRef StringTable
Definition Archive.cpp:1505
StringRef SymbolTable
Definition Archive.cpp:1503
StringRef SymbolOffsetTable
Definition Archive.cpp:1504