LLVM 18.0.0git
ELFObject.h
Go to the documentation of this file.
1//===- ELFObject.h ----------------------------------------------*- C++ -*-===//
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#ifndef LLVM_LIB_OBJCOPY_ELF_ELFOBJECT_H
10#define LLVM_LIB_OBJCOPY_ELF_ELFOBJECT_H
11
12#include "llvm/ADT/ArrayRef.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/ADT/Twine.h"
19#include "llvm/Support/Errc.h"
22#include <cstddef>
23#include <cstdint>
24#include <functional>
25#include <memory>
26#include <set>
27#include <vector>
28
29namespace llvm {
30enum class DebugCompressionType;
31namespace objcopy {
32namespace elf {
33
34class SectionBase;
35class Section;
36class OwnedDataSection;
37class StringTableSection;
38class SymbolTableSection;
39class RelocationSection;
40class DynamicRelocationSection;
41class GnuDebugLinkSection;
42class GroupSection;
43class SectionIndexSection;
44class CompressedSection;
45class DecompressedSection;
46class Segment;
47class Object;
48struct Symbol;
49
52
53public:
55
56 explicit SectionTableRef(ArrayRef<std::unique_ptr<SectionBase>> Secs)
57 : Sections(Secs) {}
58 SectionTableRef(const SectionTableRef &) = default;
59
60 iterator begin() const { return iterator(Sections.data()); }
61 iterator end() const { return iterator(Sections.data() + Sections.size()); }
62 size_t size() const { return Sections.size(); }
63
65
66 template <class T>
68 Twine TypeErrMsg);
69};
70
72
74public:
75 virtual ~SectionVisitor() = default;
76
77 virtual Error visit(const Section &Sec) = 0;
78 virtual Error visit(const OwnedDataSection &Sec) = 0;
79 virtual Error visit(const StringTableSection &Sec) = 0;
80 virtual Error visit(const SymbolTableSection &Sec) = 0;
81 virtual Error visit(const RelocationSection &Sec) = 0;
82 virtual Error visit(const DynamicRelocationSection &Sec) = 0;
83 virtual Error visit(const GnuDebugLinkSection &Sec) = 0;
84 virtual Error visit(const GroupSection &Sec) = 0;
85 virtual Error visit(const SectionIndexSection &Sec) = 0;
86 virtual Error visit(const CompressedSection &Sec) = 0;
87 virtual Error visit(const DecompressedSection &Sec) = 0;
88};
89
91public:
92 virtual ~MutableSectionVisitor() = default;
93
94 virtual Error visit(Section &Sec) = 0;
95 virtual Error visit(OwnedDataSection &Sec) = 0;
96 virtual Error visit(StringTableSection &Sec) = 0;
97 virtual Error visit(SymbolTableSection &Sec) = 0;
98 virtual Error visit(RelocationSection &Sec) = 0;
100 virtual Error visit(GnuDebugLinkSection &Sec) = 0;
101 virtual Error visit(GroupSection &Sec) = 0;
102 virtual Error visit(SectionIndexSection &Sec) = 0;
103 virtual Error visit(CompressedSection &Sec) = 0;
104 virtual Error visit(DecompressedSection &Sec) = 0;
105};
106
108protected:
110
111public:
112 virtual ~SectionWriter() = default;
113
114 Error visit(const Section &Sec) override;
115 Error visit(const OwnedDataSection &Sec) override;
116 Error visit(const StringTableSection &Sec) override;
117 Error visit(const DynamicRelocationSection &Sec) override;
118 Error visit(const SymbolTableSection &Sec) override = 0;
119 Error visit(const RelocationSection &Sec) override = 0;
120 Error visit(const GnuDebugLinkSection &Sec) override = 0;
121 Error visit(const GroupSection &Sec) override = 0;
122 Error visit(const SectionIndexSection &Sec) override = 0;
123 Error visit(const CompressedSection &Sec) override = 0;
124 Error visit(const DecompressedSection &Sec) override = 0;
125
126 explicit SectionWriter(WritableMemoryBuffer &Buf) : Out(Buf) {}
127};
128
129template <class ELFT> class ELFSectionWriter : public SectionWriter {
130private:
131 using Elf_Word = typename ELFT::Word;
132 using Elf_Rel = typename ELFT::Rel;
133 using Elf_Rela = typename ELFT::Rela;
134 using Elf_Sym = typename ELFT::Sym;
135
136public:
137 virtual ~ELFSectionWriter() {}
138 Error visit(const SymbolTableSection &Sec) override;
139 Error visit(const RelocationSection &Sec) override;
140 Error visit(const GnuDebugLinkSection &Sec) override;
141 Error visit(const GroupSection &Sec) override;
142 Error visit(const SectionIndexSection &Sec) override;
143 Error visit(const CompressedSection &Sec) override;
144 Error visit(const DecompressedSection &Sec) override;
145
147};
148
149template <class ELFT> class ELFSectionSizer : public MutableSectionVisitor {
150private:
151 using Elf_Rel = typename ELFT::Rel;
152 using Elf_Rela = typename ELFT::Rela;
153 using Elf_Sym = typename ELFT::Sym;
154 using Elf_Word = typename ELFT::Word;
155 using Elf_Xword = typename ELFT::Xword;
156
157public:
158 Error visit(Section &Sec) override;
159 Error visit(OwnedDataSection &Sec) override;
160 Error visit(StringTableSection &Sec) override;
161 Error visit(DynamicRelocationSection &Sec) override;
162 Error visit(SymbolTableSection &Sec) override;
163 Error visit(RelocationSection &Sec) override;
164 Error visit(GnuDebugLinkSection &Sec) override;
165 Error visit(GroupSection &Sec) override;
166 Error visit(SectionIndexSection &Sec) override;
167 Error visit(CompressedSection &Sec) override;
168 Error visit(DecompressedSection &Sec) override;
169};
170
171#define MAKE_SEC_WRITER_FRIEND \
172 friend class SectionWriter; \
173 friend class IHexSectionWriterBase; \
174 friend class IHexSectionWriter; \
175 template <class ELFT> friend class ELFSectionWriter; \
176 template <class ELFT> friend class ELFSectionSizer;
177
179public:
181
182 Error visit(const SymbolTableSection &Sec) override;
183 Error visit(const RelocationSection &Sec) override;
184 Error visit(const GnuDebugLinkSection &Sec) override;
185 Error visit(const GroupSection &Sec) override;
186 Error visit(const SectionIndexSection &Sec) override;
187 Error visit(const CompressedSection &Sec) override;
188 Error visit(const DecompressedSection &Sec) override;
189
191 : SectionWriter(Buf) {}
192};
193
195
197 // Memory address of the record.
199 // Record type (see below).
201 // Record data in hexadecimal form.
203
204 // Helper method to get file length of the record
205 // including newline character
206 static size_t getLength(size_t DataSize) {
207 // :LLAAAATT[DD...DD]CC'
208 return DataSize * 2 + 11;
209 }
210
211 // Gets length of line in a file (getLength + CRLF).
212 static size_t getLineLength(size_t DataSize) {
213 return getLength(DataSize) + 2;
214 }
215
216 // Given type, address and data returns line which can
217 // be written to output file.
218 static IHexLineData getLine(uint8_t Type, uint16_t Addr,
220
221 // Parses the line and returns record if possible.
222 // Line should be trimmed from whitespace characters.
224
225 // Calculates checksum of stringified record representation
226 // S must NOT contain leading ':' and trailing whitespace
227 // characters
228 static uint8_t getChecksum(StringRef S);
229
230 enum Type {
231 // Contains data and a 16-bit starting address for the data.
232 // The byte count specifies number of data bytes in the record.
233 Data = 0,
234 // Must occur exactly once per file in the last line of the file.
235 // The data field is empty (thus byte count is 00) and the address
236 // field is typically 0000.
238 // The data field contains a 16-bit segment base address (thus byte
239 // count is always 02) compatible with 80x86 real mode addressing.
240 // The address field (typically 0000) is ignored. The segment address
241 // from the most recent 02 record is multiplied by 16 and added to each
242 // subsequent data record address to form the physical starting address
243 // for the data. This allows addressing up to one megabyte of address
244 // space.
246 // or 80x86 processors, specifies the initial content of the CS:IP
247 // registers. The address field is 0000, the byte count is always 04,
248 // the first two data bytes are the CS value, the latter two are the
249 // IP value.
251 // Allows for 32 bit addressing (up to 4GiB). The record's address field
252 // is ignored (typically 0000) and its byte count is always 02. The two
253 // data bytes (big endian) specify the upper 16 bits of the 32 bit
254 // absolute address for all subsequent type 00 records
256 // The address field is 0000 (not used) and the byte count is always 04.
257 // The four data bytes represent a 32-bit address value. In the case of
258 // 80386 and higher CPUs, this address is loaded into the EIP register.
260 // We have no other valid types
261 InvalidType = 6
262 };
263};
264
265// Base class for IHexSectionWriter. This class implements writing algorithm,
266// but doesn't actually write records. It is used for output buffer size
267// calculation in IHexWriter::finalize.
269 // 20-bit segment address
270 uint32_t SegmentAddr = 0;
271 // Extended linear address
272 uint32_t BaseAddr = 0;
273
274 // Write segment address corresponding to 'Addr'
275 uint64_t writeSegmentAddr(uint64_t Addr);
276 // Write extended linear (base) address corresponding to 'Addr'
277 uint64_t writeBaseAddr(uint64_t Addr);
278
279protected:
280 // Offset in the output buffer
282
284 virtual void writeData(uint8_t Type, uint16_t Addr, ArrayRef<uint8_t> Data);
285
286public:
288 : BinarySectionWriter(Buf) {}
289
290 uint64_t getBufferOffset() const { return Offset; }
291 Error visit(const Section &Sec) final;
292 Error visit(const OwnedDataSection &Sec) final;
293 Error visit(const StringTableSection &Sec) override;
294 Error visit(const DynamicRelocationSection &Sec) final;
296};
297
298// Real IHEX section writer
300public:
302
303 void writeData(uint8_t Type, uint16_t Addr, ArrayRef<uint8_t> Data) override;
304 Error visit(const StringTableSection &Sec) override;
305};
306
307class Writer {
308protected:
310 std::unique_ptr<WritableMemoryBuffer> Buf;
312
313public:
314 virtual ~Writer();
315 virtual Error finalize() = 0;
316 virtual Error write() = 0;
317
319};
320
321template <class ELFT> class ELFWriter : public Writer {
322private:
323 using Elf_Addr = typename ELFT::Addr;
324 using Elf_Shdr = typename ELFT::Shdr;
325 using Elf_Phdr = typename ELFT::Phdr;
326 using Elf_Ehdr = typename ELFT::Ehdr;
327
328 void initEhdrSegment();
329
330 void writeEhdr();
331 void writePhdr(const Segment &Seg);
332 void writeShdr(const SectionBase &Sec);
333
334 void writePhdrs();
335 void writeShdrs();
336 Error writeSectionData();
337 void writeSegmentData();
338
339 void assignOffsets();
340
341 std::unique_ptr<ELFSectionWriter<ELFT>> SecWriter;
342
343 size_t totalSize() const;
344
345public:
346 virtual ~ELFWriter() {}
348
349 // For --only-keep-debug, select an alternative section/segment layout
350 // algorithm.
352
353 Error finalize() override;
354 Error write() override;
355 ELFWriter(Object &Obj, raw_ostream &Out, bool WSH, bool OnlyKeepDebug);
356};
357
358class BinaryWriter : public Writer {
359private:
360 std::unique_ptr<BinarySectionWriter> SecWriter;
361
362 uint64_t TotalSize = 0;
363
364public:
366 Error finalize() override;
367 Error write() override;
369};
370
371class IHexWriter : public Writer {
372 struct SectionCompare {
373 bool operator()(const SectionBase *Lhs, const SectionBase *Rhs) const;
374 };
375
376 std::set<const SectionBase *, SectionCompare> Sections;
377 size_t TotalSize = 0;
378
379 Error checkSection(const SectionBase &Sec);
380 uint64_t writeEntryPointRecord(uint8_t *Buf);
381 uint64_t writeEndOfFileRecord(uint8_t *Buf);
382
383public:
385 Error finalize() override;
386 Error write() override;
388};
389
391public:
392 std::string Name;
396
400 uint64_t OriginalOffset = std::numeric_limits<uint64_t>::max();
401
413 bool HasSymbol = false;
414
415 SectionBase() = default;
416 SectionBase(const SectionBase &) = default;
417
418 virtual ~SectionBase() = default;
419
420 virtual Error initialize(SectionTableRef SecTable);
421 virtual void finalize();
422 // Remove references to these sections. The list of sections must be sorted.
423 virtual Error
424 removeSectionReferences(bool AllowBrokenLinks,
425 function_ref<bool(const SectionBase *)> ToRemove);
426 virtual Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove);
427 virtual Error accept(SectionVisitor &Visitor) const = 0;
428 virtual Error accept(MutableSectionVisitor &Visitor) = 0;
429 virtual void markSymbols();
430 virtual void
432 virtual bool hasContents() const { return false; }
433 // Notify the section that it is subject to removal.
434 virtual void onRemove();
435
437};
438
439class Segment {
440private:
441 struct SectionCompare {
442 bool operator()(const SectionBase *Lhs, const SectionBase *Rhs) const {
443 // Some sections might have the same address if one of them is empty. To
444 // fix this we can use the lexicographic ordering on ->Addr and the
445 // original index.
446 if (Lhs->OriginalOffset == Rhs->OriginalOffset)
447 return Lhs->OriginalIndex < Rhs->OriginalIndex;
448 return Lhs->OriginalOffset < Rhs->OriginalOffset;
449 }
450 };
451
452public:
461
466 std::set<const SectionBase *, SectionCompare> Sections;
467
469 Segment() = default;
470
471 const SectionBase *firstSection() const {
472 if (!Sections.empty())
473 return *Sections.begin();
474 return nullptr;
475 }
476
477 void removeSection(const SectionBase *Sec) { Sections.erase(Sec); }
478 void addSection(const SectionBase *Sec) { Sections.insert(Sec); }
479
481};
482
483class Section : public SectionBase {
485
486 ArrayRef<uint8_t> Contents;
487 SectionBase *LinkSection = nullptr;
488 bool HasSymTabLink = false;
489
490public:
491 explicit Section(ArrayRef<uint8_t> Data) : Contents(Data) {}
492
493 Error accept(SectionVisitor &Visitor) const override;
494 Error accept(MutableSectionVisitor &Visitor) override;
496 bool AllowBrokenLinks,
497 function_ref<bool(const SectionBase *)> ToRemove) override;
498 Error initialize(SectionTableRef SecTable) override;
499 void finalize() override;
500 bool hasContents() const override {
501 return Type != ELF::SHT_NOBITS && Type != ELF::SHT_NULL;
502 }
503 void restoreSymTabLink(SymbolTableSection &SymTab) override;
504};
505
508
509 std::vector<uint8_t> Data;
510
511public:
513 : Data(std::begin(Data), std::end(Data)) {
514 Name = SecName.str();
516 Size = Data.size();
517 OriginalOffset = std::numeric_limits<uint64_t>::max();
518 }
519
520 OwnedDataSection(const Twine &SecName, uint64_t SecAddr, uint64_t SecFlags,
521 uint64_t SecOff) {
522 Name = SecName.str();
524 Addr = SecAddr;
525 Flags = OriginalFlags = SecFlags;
526 OriginalOffset = SecOff;
527 }
528
530 : SectionBase(S), Data(std::begin(Data), std::end(Data)) {
531 Size = Data.size();
532 }
533
534 void appendHexData(StringRef HexData);
535 Error accept(SectionVisitor &Sec) const override;
536 Error accept(MutableSectionVisitor &Visitor) override;
537 bool hasContents() const override { return true; }
538};
539
542
543 uint32_t ChType = 0;
544 DebugCompressionType CompressionType;
545 uint64_t DecompressedSize;
546 uint64_t DecompressedAlign;
547 SmallVector<uint8_t, 128> CompressedData;
548
549public:
551 DebugCompressionType CompressionType, bool Is64Bits);
552 CompressedSection(ArrayRef<uint8_t> CompressedData, uint32_t ChType,
553 uint64_t DecompressedSize, uint64_t DecompressedAlign);
554
555 uint64_t getDecompressedSize() const { return DecompressedSize; }
556 uint64_t getDecompressedAlign() const { return DecompressedAlign; }
557 uint64_t getChType() const { return ChType; }
558
559 Error accept(SectionVisitor &Visitor) const override;
560 Error accept(MutableSectionVisitor &Visitor) override;
561
562 static bool classof(const SectionBase *S) {
564 }
565};
566
569
570public:
573 : SectionBase(Sec), ChType(Sec.getChType()) {
576 Flags = OriginalFlags = (Flags & ~ELF::SHF_COMPRESSED);
577 }
578
579 Error accept(SectionVisitor &Visitor) const override;
580 Error accept(MutableSectionVisitor &Visitor) override;
581};
582
583// There are two types of string tables that can exist, dynamic and not dynamic.
584// In the dynamic case the string table is allocated. Changing a dynamic string
585// table would mean altering virtual addresses and thus the memory image. So
586// dynamic string tables should not have an interface to modify them or
587// reconstruct them. This type lets us reconstruct a string table. To avoid
588// this class being used for dynamic string tables (which has happened) the
589// classof method checks that the particular instance is not allocated. This
590// then agrees with the makeSection method used to construct most sections.
593
594 StringTableBuilder StrTabBuilder;
595
596public:
599 }
600
603 void prepareForLayout();
604 Error accept(SectionVisitor &Visitor) const override;
605 Error accept(MutableSectionVisitor &Visitor) override;
606
607 static bool classof(const SectionBase *S) {
609 return false;
610 return S->OriginalType == ELF::SHT_STRTAB;
611 }
612};
613
614// Symbols have a st_shndx field that normally stores an index but occasionally
615// stores a different special value. This enum keeps track of what the st_shndx
616// field means. Most of the values are just copies of the special SHN_* values.
617// SYMBOL_SIMPLE_INDEX means that the st_shndx is just an index of a section.
637};
638
639struct Symbol {
640 uint8_t Binding;
644 std::string Name;
647 uint8_t Type;
649 uint8_t Visibility;
650 bool Referenced = false;
651
652 uint16_t getShndx() const;
653 bool isCommon() const;
654};
655
658
659private:
660 std::vector<uint32_t> Indexes;
661 SymbolTableSection *Symbols = nullptr;
662
663public:
666 assert(Size > 0);
667 Indexes.push_back(Index);
668 }
669
670 void reserve(size_t NumSymbols) {
671 Indexes.reserve(NumSymbols);
672 Size = NumSymbols * 4;
673 }
674 void setSymTab(SymbolTableSection *SymTab) { Symbols = SymTab; }
675 Error initialize(SectionTableRef SecTable) override;
676 void finalize() override;
677 Error accept(SectionVisitor &Visitor) const override;
678 Error accept(MutableSectionVisitor &Visitor) override;
679
681 Name = ".symtab_shndx";
682 Align = 4;
683 EntrySize = 4;
685 }
686};
687
690
691 void setStrTab(StringTableSection *StrTab) { SymbolNames = StrTab; }
692 void assignIndices();
693
694protected:
695 std::vector<std::unique_ptr<Symbol>> Symbols;
698 bool IndicesChanged = false;
699
700 using SymPtr = std::unique_ptr<Symbol>;
701
702public:
704
705 void addSymbol(Twine Name, uint8_t Bind, uint8_t Type, SectionBase *DefinedIn,
706 uint64_t Value, uint8_t Visibility, uint16_t Shndx,
707 uint64_t SymbolSize);
708 void prepareForLayout();
709 // An 'empty' symbol table still contains a null symbol.
710 bool empty() const { return Symbols.size() == 1; }
711 bool indicesChanged() const { return IndicesChanged; }
713 SectionIndexTable = ShndxTable;
714 }
716 void fillShndxTable();
717 const SectionBase *getStrTab() const { return SymbolNames; }
720 void updateSymbols(function_ref<void(Symbol &)> Callable);
721
723 bool AllowBrokenLinks,
724 function_ref<bool(const SectionBase *)> ToRemove) override;
725 Error initialize(SectionTableRef SecTable) override;
726 void finalize() override;
727 Error accept(SectionVisitor &Visitor) const override;
728 Error accept(MutableSectionVisitor &Visitor) override;
729 Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override;
731 const DenseMap<SectionBase *, SectionBase *> &FromTo) override;
732
733 static bool classof(const SectionBase *S) {
734 return S->OriginalType == ELF::SHT_SYMTAB;
735 }
736};
737
739 Symbol *RelocSymbol = nullptr;
743};
744
745// All relocation sections denote relocations to apply to another section.
746// However, some relocation sections use a dynamic symbol table and others use
747// a regular symbol table. Because the types of the two symbol tables differ in
748// our system (because they should behave differently) we can't uniformly
749// represent all relocations with the same base class if we expose an interface
750// that mentions the symbol table type. So we split the two base types into two
751// different classes, one which handles the section the relocation is applied to
752// and another which handles the symbol table type. The symbol table type is
753// taken as a type parameter to the class (see RelocSectionWithSymtabBase).
755protected:
757
758public:
759 const SectionBase *getSection() const { return SecToApplyRel; }
761
762 StringRef getNamePrefix() const;
763
764 static bool classof(const SectionBase *S) {
766 }
767};
768
769// Takes the symbol table type to use as a parameter so that we can deduplicate
770// that code between the two symbol table types.
771template <class SymTabType>
773 void setSymTab(SymTabType *SymTab) { Symbols = SymTab; }
774
775protected:
777
778 SymTabType *Symbols = nullptr;
779
780public:
781 Error initialize(SectionTableRef SecTable) override;
782 void finalize() override;
783};
784
786 : public RelocSectionWithSymtabBase<SymbolTableSection> {
788
789 std::vector<Relocation> Relocations;
790 const Object &Obj;
791
792public:
793 RelocationSection(const Object &O) : Obj(O) {}
794 void addRelocation(Relocation Rel) { Relocations.push_back(Rel); }
795 Error accept(SectionVisitor &Visitor) const override;
796 Error accept(MutableSectionVisitor &Visitor) override;
798 bool AllowBrokenLinks,
799 function_ref<bool(const SectionBase *)> ToRemove) override;
800 Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override;
801 void markSymbols() override;
803 const DenseMap<SectionBase *, SectionBase *> &FromTo) override;
804 const Object &getObject() const { return Obj; }
805
806 static bool classof(const SectionBase *S) {
808 return false;
810 }
811};
812
813// TODO: The way stripping and groups interact is complicated
814// and still needs to be worked on.
815
816class GroupSection : public SectionBase {
818 const SymbolTableSection *SymTab = nullptr;
819 Symbol *Sym = nullptr;
820 ELF::Elf32_Word FlagWord;
822
823public:
824 // TODO: Contents is present in several classes of the hierarchy.
825 // This needs to be refactored to avoid duplication.
827
829
830 void setSymTab(const SymbolTableSection *SymTabSec) { SymTab = SymTabSec; }
831 void setSymbol(Symbol *S) { Sym = S; }
832 void setFlagWord(ELF::Elf32_Word W) { FlagWord = W; }
833 void addMember(SectionBase *Sec) { GroupMembers.push_back(Sec); }
834
835 Error accept(SectionVisitor &) const override;
836 Error accept(MutableSectionVisitor &Visitor) override;
837 void finalize() override;
839 bool AllowBrokenLinks,
840 function_ref<bool(const SectionBase *)> ToRemove) override;
841 Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override;
842 void markSymbols() override;
844 const DenseMap<SectionBase *, SectionBase *> &FromTo) override;
845 void onRemove() override;
846
847 static bool classof(const SectionBase *S) {
848 return S->OriginalType == ELF::SHT_GROUP;
849 }
850};
851
853public:
855
856 static bool classof(const SectionBase *S) {
857 return S->OriginalType == ELF::SHT_DYNSYM;
858 }
859};
860
861class DynamicSection : public Section {
862public:
864
865 static bool classof(const SectionBase *S) {
866 return S->OriginalType == ELF::SHT_DYNAMIC;
867 }
868};
869
871 : public RelocSectionWithSymtabBase<DynamicSymbolTableSection> {
873
874private:
875 ArrayRef<uint8_t> Contents;
876
877public:
879
880 Error accept(SectionVisitor &) const override;
881 Error accept(MutableSectionVisitor &Visitor) override;
883 bool AllowBrokenLinks,
884 function_ref<bool(const SectionBase *)> ToRemove) override;
885
886 static bool classof(const SectionBase *S) {
887 if (!(S->OriginalFlags & ELF::SHF_ALLOC))
888 return false;
890 }
891};
892
895
896private:
897 StringRef FileName;
898 uint32_t CRC32;
899
900 void init(StringRef File);
901
902public:
903 // If we add this section from an external source we can use this ctor.
904 explicit GnuDebugLinkSection(StringRef File, uint32_t PrecomputedCRC);
905 Error accept(SectionVisitor &Visitor) const override;
906 Error accept(MutableSectionVisitor &Visitor) override;
907};
908
909class Reader {
910public:
911 virtual ~Reader();
912 virtual Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const = 0;
913};
914
915using object::Binary;
916using object::ELFFile;
919
921protected:
922 std::unique_ptr<Object> Obj;
923
924 void initFileHeader();
925 void initHeaderSegment();
929
930public:
931 BasicELFBuilder() : Obj(std::make_unique<Object>()) {}
932};
933
935 MemoryBuffer *MemBuf;
936 uint8_t NewSymbolVisibility;
937 void addData(SymbolTableSection *SymTab);
938
939public:
940 BinaryELFBuilder(MemoryBuffer *MB, uint8_t NewSymbolVisibility)
941 : MemBuf(MB), NewSymbolVisibility(NewSymbolVisibility) {}
942
944};
945
947 const std::vector<IHexRecord> &Records;
948
949 void addDataSections();
950
951public:
952 IHexELFBuilder(const std::vector<IHexRecord> &Records) : Records(Records) {}
953
955};
956
957template <class ELFT> class ELFBuilder {
958private:
959 using Elf_Addr = typename ELFT::Addr;
960 using Elf_Shdr = typename ELFT::Shdr;
961 using Elf_Word = typename ELFT::Word;
962
963 const ELFFile<ELFT> &ElfFile;
964 Object &Obj;
965 size_t EhdrOffset = 0;
966 std::optional<StringRef> ExtractPartition;
967
968 void setParentSegment(Segment &Child);
969 Error readProgramHeaders(const ELFFile<ELFT> &HeadersFile);
970 Error initGroupSection(GroupSection *GroupSec);
971 Error initSymbolTable(SymbolTableSection *SymTab);
972 Error readSectionHeaders();
973 Error readSections(bool EnsureSymtab);
974 Error findEhdrOffset();
975 Expected<SectionBase &> makeSection(const Elf_Shdr &Shdr);
976
977public:
978 ELFBuilder(const ELFObjectFile<ELFT> &ElfObj, Object &Obj,
979 std::optional<StringRef> ExtractPartition);
980
981 Error build(bool EnsureSymtab);
982};
983
984class BinaryReader : public Reader {
985 MemoryBuffer *MemBuf;
986 uint8_t NewSymbolVisibility;
987
988public:
989 BinaryReader(MemoryBuffer *MB, const uint8_t NewSymbolVisibility)
990 : MemBuf(MB), NewSymbolVisibility(NewSymbolVisibility) {}
991 Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
992};
993
994class IHexReader : public Reader {
995 MemoryBuffer *MemBuf;
996
998 Error parseError(size_t LineNo, Error E) const {
999 return LineNo == -1U
1000 ? createFileError(MemBuf->getBufferIdentifier(), std::move(E))
1001 : createFileError(MemBuf->getBufferIdentifier(), LineNo,
1002 std::move(E));
1003 }
1004 template <typename... Ts>
1005 Error parseError(size_t LineNo, char const *Fmt, const Ts &...Vals) const {
1007 return parseError(LineNo, std::move(E));
1008 }
1009
1010public:
1011 IHexReader(MemoryBuffer *MB) : MemBuf(MB) {}
1012
1013 Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
1014};
1015
1016class ELFReader : public Reader {
1017 Binary *Bin;
1018 std::optional<StringRef> ExtractPartition;
1019
1020public:
1021 Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
1022 explicit ELFReader(Binary *B, std::optional<StringRef> ExtractPartition)
1023 : Bin(B), ExtractPartition(ExtractPartition) {}
1024};
1025
1026class Object {
1027private:
1028 using SecPtr = std::unique_ptr<SectionBase>;
1029 using SegPtr = std::unique_ptr<Segment>;
1030
1031 std::vector<SecPtr> Sections;
1032 std::vector<SegPtr> Segments;
1033 std::vector<SecPtr> RemovedSections;
1035
1036 static bool sectionIsAlloc(const SectionBase &Sec) {
1037 return Sec.Flags & ELF::SHF_ALLOC;
1038 };
1039
1040public:
1041 template <class T>
1043 typename std::vector<std::unique_ptr<T>>::const_iterator>>;
1044
1045 // It is often the case that the ELF header and the program header table are
1046 // not present in any segment. This could be a problem during file layout,
1047 // because other segments may get assigned an offset where either of the
1048 // two should reside, which will effectively corrupt the resulting binary.
1049 // Other than that we use these segments to track program header offsets
1050 // when they may not follow the ELF header.
1053
1055 uint8_t OSABI;
1056 uint8_t ABIVersion;
1063
1064 bool HadShdrs = true;
1065 bool MustBeRelocatable = false;
1069
1070 bool IsMips64EL = false;
1071
1072 SectionTableRef sections() const { return SectionTableRef(Sections); }
1075 decltype(&sectionIsAlloc)>>
1077 return make_filter_range(make_pointee_range(Sections), sectionIsAlloc);
1078 }
1079
1080 const auto &getUpdatedSections() const { return UpdatedSections; }
1082
1084 auto SecIt =
1085 find_if(Sections, [&](const SecPtr &Sec) { return Sec->Name == Name; });
1086 return SecIt == Sections.end() ? nullptr : SecIt->get();
1087 }
1088 SectionTableRef removedSections() { return SectionTableRef(RemovedSections); }
1089
1091
1092 Error removeSections(bool AllowBrokenLinks,
1093 std::function<bool(const SectionBase &)> ToRemove);
1096 template <class T, class... Ts> T &addSection(Ts &&...Args) {
1097 auto Sec = std::make_unique<T>(std::forward<Ts>(Args)...);
1098 auto Ptr = Sec.get();
1099 MustBeRelocatable |= isa<RelocationSection>(*Ptr);
1100 Sections.emplace_back(std::move(Sec));
1101 Ptr->Index = Sections.size();
1102 return *Ptr;
1103 }
1106 Segments.emplace_back(std::make_unique<Segment>(Data));
1107 return *Segments.back();
1108 }
1109 bool isRelocatable() const {
1110 return (Type != ELF::ET_DYN && Type != ELF::ET_EXEC) || MustBeRelocatable;
1111 }
1112};
1113
1114} // end namespace elf
1115} // end namespace objcopy
1116} // end namespace llvm
1117
1118#endif // LLVM_LIB_OBJCOPY_ELF_ELFOBJECT_H
ReachingDefAnalysis InstSet & ToRemove
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Elf_Shdr Shdr
uint64_t Addr
std::string Name
#define MAKE_SEC_WRITER_FRIEND
Definition: ELFObject.h:171
Symbol * Sym
Definition: ELF_riscv.cpp:468
#define T
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
const T * data() const
Definition: ArrayRef.h:162
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:474
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:51
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:76
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
Utility for building string tables with deduplicated suffixes.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
This class is an extension of MemoryBuffer, which allows copy-on-write access to the underlying conte...
Definition: MemoryBuffer.h:181
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:507
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
StringTableSection * addStrTab()
Definition: ELFObject.cpp:1252
SymbolTableSection * addSymTab(StringTableSection *StrTab)
Definition: ELFObject.cpp:1260
std::unique_ptr< Object > Obj
Definition: ELFObject.h:922
BinaryELFBuilder(MemoryBuffer *MB, uint8_t NewSymbolVisibility)
Definition: ELFObject.h:940
Expected< std::unique_ptr< Object > > build()
Definition: ELFObject.cpp:1306
BinaryReader(MemoryBuffer *MB, const uint8_t NewSymbolVisibility)
Definition: ELFObject.h:989
Expected< std::unique_ptr< Object > > create(bool EnsureSymtab) const override
Definition: ELFObject.cpp:1917
Error visit(const SymbolTableSection &Sec) override
Definition: ELFObject.cpp:148
BinarySectionWriter(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:190
BinaryWriter(Object &Obj, raw_ostream &Out)
Definition: ELFObject.h:368
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:564
static bool classof(const SectionBase *S)
Definition: ELFObject.h:562
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:486
DecompressedSection(const CompressedSection &Sec)
Definition: ELFObject.h:572
Error accept(SectionVisitor &) const override
Definition: ELFObject.cpp:1013
DynamicRelocationSection(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:878
static bool classof(const SectionBase *S)
Definition: ELFObject.h:886
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:1021
DynamicSection(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:863
static bool classof(const SectionBase *S)
Definition: ELFObject.h:865
static bool classof(const SectionBase *S)
Definition: ELFObject.h:856
DynamicSymbolTableSection(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:854
Error build(bool EnsureSymtab)
Definition: ELFObject.cpp:1883
ELFReader(Binary *B, std::optional< StringRef > ExtractPartition)
Definition: ELFObject.h:1022
Expected< std::unique_ptr< Object > > create(bool EnsureSymtab) const override
Definition: ELFObject.cpp:1956
Error visit(Section &Sec) override
Definition: ELFObject.cpp:83
ELFSectionWriter(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:146
Error visit(const SymbolTableSection &Sec) override
Definition: ELFObject.cpp:845
GroupSection(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:828
void setSymTab(const SymbolTableSection *SymTabSec)
Definition: ELFObject.h:830
void replaceSectionReferences(const DenseMap< SectionBase *, SectionBase * > &FromTo) override
Definition: ELFObject.cpp:1096
Error accept(SectionVisitor &) const override
Definition: ELFObject.cpp:1184
static bool classof(const SectionBase *S)
Definition: ELFObject.h:847
ArrayRef< uint8_t > Contents
Definition: ELFObject.h:826
void addMember(SectionBase *Sec)
Definition: ELFObject.h:833
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:1066
void setFlagWord(ELF::Elf32_Word W)
Definition: ELFObject.h:832
Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove) override
Definition: ELFObject.cpp:1082
IHexELFBuilder(const std::vector< IHexRecord > &Records)
Definition: ELFObject.h:952
Expected< std::unique_ptr< Object > > build()
Definition: ELFObject.cpp:1366
IHexReader(MemoryBuffer *MB)
Definition: ELFObject.h:1011
Expected< std::unique_ptr< Object > > create(bool EnsureSymtab) const override
Definition: ELFObject.cpp:1948
IHexSectionWriterBase(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:287
void writeSection(const SectionBase *Sec, ArrayRef< uint8_t > Data)
Definition: ELFObject.cpp:335
Error visit(const Section &Sec) final
Definition: ELFObject.cpp:384
virtual void writeData(uint8_t Type, uint16_t Addr, ArrayRef< uint8_t > Data)
Definition: ELFObject.cpp:379
IHexSectionWriter(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:301
void writeData(uint8_t Type, uint16_t Addr, ArrayRef< uint8_t > Data) override
Definition: ELFObject.cpp:409
Error visit(const StringTableSection &Sec) override
Definition: ELFObject.cpp:416
IHexWriter(Object &Obj, raw_ostream &Out)
Definition: ELFObject.h:387
virtual Error visit(OwnedDataSection &Sec)=0
virtual Error visit(SymbolTableSection &Sec)=0
virtual Error visit(DecompressedSection &Sec)=0
virtual Error visit(StringTableSection &Sec)=0
virtual Error visit(GnuDebugLinkSection &Sec)=0
virtual Error visit(SectionIndexSection &Sec)=0
virtual Error visit(DynamicRelocationSection &Sec)=0
virtual Error visit(Section &Sec)=0
virtual Error visit(GroupSection &Sec)=0
virtual Error visit(CompressedSection &Sec)=0
virtual Error visit(RelocationSection &Sec)=0
SectionTableRef sections() const
Definition: ELFObject.h:1072
StringTableSection * SectionNames
Definition: ELFObject.h:1066
SectionTableRef removedSections()
Definition: ELFObject.h:1088
bool isRelocatable() const
Definition: ELFObject.h:1109
iterator_range< filter_iterator< pointee_iterator< std::vector< SecPtr >::const_iterator >, decltype(&sectionIsAlloc)> > allocSections() const
Definition: ELFObject.h:1076
Error updateSection(StringRef Name, ArrayRef< uint8_t > Data)
Definition: ELFObject.cpp:2120
SectionIndexSection * SectionIndexTable
Definition: ELFObject.h:1068
Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove)
Definition: ELFObject.cpp:2227
T & addSection(Ts &&...Args)
Definition: ELFObject.h:1096
Error removeSections(bool AllowBrokenLinks, std::function< bool(const SectionBase &)> ToRemove)
Definition: ELFObject.cpp:2151
Segment & addSegment(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:1105
ConstRange< Segment > segments() const
Definition: ELFObject.h:1090
SymbolTableSection * SymbolTable
Definition: ELFObject.h:1067
const auto & getUpdatedSections() const
Definition: ELFObject.h:1080
SectionBase * findSection(StringRef Name)
Definition: ELFObject.h:1083
Error replaceSections(const DenseMap< SectionBase *, SectionBase * > &FromTo)
Definition: ELFObject.cpp:2203
void appendHexData(StringRef HexData)
Definition: ELFObject.cpp:502
OwnedDataSection(const Twine &SecName, uint64_t SecAddr, uint64_t SecFlags, uint64_t SecOff)
Definition: ELFObject.h:520
Error accept(SectionVisitor &Sec) const override
Definition: ELFObject.cpp:494
OwnedDataSection(StringRef SecName, ArrayRef< uint8_t > Data)
Definition: ELFObject.h:512
OwnedDataSection(SectionBase &S, ArrayRef< uint8_t > Data)
Definition: ELFObject.h:529
bool hasContents() const override
Definition: ELFObject.h:537
virtual Expected< std::unique_ptr< Object > > create(bool EnsureSymtab) const =0
Error initialize(SectionTableRef SecTable) override
Definition: ELFObject.cpp:908
const SectionBase * getSection() const
Definition: ELFObject.h:759
static bool classof(const SectionBase *S)
Definition: ELFObject.h:764
void addRelocation(Relocation Rel)
Definition: ELFObject.h:794
const Object & getObject() const
Definition: ELFObject.h:804
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:976
Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove) override
Definition: ELFObject.cpp:984
void replaceSectionReferences(const DenseMap< SectionBase *, SectionBase * > &FromTo) override
Definition: ELFObject.cpp:1001
static bool classof(const SectionBase *S)
Definition: ELFObject.h:806
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:880
ArrayRef< uint8_t > OriginalData
Definition: ELFObject.h:412
virtual Error initialize(SectionTableRef SecTable)
Definition: ELFObject.cpp:60
virtual Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove)
Definition: ELFObject.cpp:51
virtual void restoreSymTabLink(SymbolTableSection &)
Definition: ELFObject.h:436
virtual void replaceSectionReferences(const DenseMap< SectionBase *, SectionBase * > &)
Definition: ELFObject.cpp:63
virtual Error accept(MutableSectionVisitor &Visitor)=0
virtual ~SectionBase()=default
virtual bool hasContents() const
Definition: ELFObject.h:432
SectionBase(const SectionBase &)=default
virtual Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove)
Definition: ELFObject.cpp:56
virtual Error accept(SectionVisitor &Visitor) const =0
void setSymTab(SymbolTableSection *SymTab)
Definition: ELFObject.h:674
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:623
void reserve(size_t NumSymbols)
Definition: ELFObject.h:670
Error initialize(SectionTableRef SecTable) override
Definition: ELFObject.cpp:604
pointee_iterator< const std::unique_ptr< SectionBase > * > iterator
Definition: ELFObject.h:54
Expected< T * > getSectionOfType(uint32_t Index, Twine IndexErrMsg, Twine TypeErrMsg)
Definition: ELFObject.cpp:1662
SectionTableRef(ArrayRef< std::unique_ptr< SectionBase > > Secs)
Definition: ELFObject.h:56
SectionTableRef(const SectionTableRef &)=default
Expected< SectionBase * > getSection(uint32_t Index, Twine ErrMsg)
Definition: ELFObject.cpp:1654
virtual Error visit(const CompressedSection &Sec)=0
virtual Error visit(const Section &Sec)=0
virtual Error visit(const DecompressedSection &Sec)=0
virtual Error visit(const GroupSection &Sec)=0
virtual Error visit(const SymbolTableSection &Sec)=0
virtual Error visit(const RelocationSection &Sec)=0
virtual Error visit(const SectionIndexSection &Sec)=0
virtual Error visit(const DynamicRelocationSection &Sec)=0
virtual Error visit(const GnuDebugLinkSection &Sec)=0
virtual Error visit(const StringTableSection &Sec)=0
virtual Error visit(const OwnedDataSection &Sec)=0
Error visit(const GroupSection &Sec) override=0
Error visit(const RelocationSection &Sec) override=0
Error visit(const SectionIndexSection &Sec) override=0
Error visit(const CompressedSection &Sec) override=0
Error visit(const Section &Sec) override
Definition: ELFObject.cpp:170
Error visit(const GnuDebugLinkSection &Sec) override=0
Error visit(const SymbolTableSection &Sec) override=0
WritableMemoryBuffer & Out
Definition: ELFObject.h:109
Error visit(const DecompressedSection &Sec) override=0
SectionWriter(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:126
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:1041
Error initialize(SectionTableRef SecTable) override
Definition: ELFObject.cpp:1110
Section(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:491
void restoreSymTabLink(SymbolTableSection &SymTab) override
Definition: ELFObject.cpp:432
bool hasContents() const override
Definition: ELFObject.h:500
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:424
void addSection(const SectionBase *Sec)
Definition: ELFObject.h:478
Segment(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:468
ArrayRef< uint8_t > Contents
Definition: ELFObject.h:465
void removeSection(const SectionBase *Sec)
Definition: ELFObject.h:477
const SectionBase * firstSection() const
Definition: ELFObject.h:471
ArrayRef< uint8_t > getContents() const
Definition: ELFObject.h:480
std::set< const SectionBase *, SectionCompare > Sections
Definition: ELFObject.h:466
static bool classof(const SectionBase *S)
Definition: ELFObject.h:607
uint32_t findIndex(StringRef Name) const
Definition: ELFObject.cpp:574
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:589
const SectionBase * getStrTab() const
Definition: ELFObject.h:717
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:722
const SectionIndexSection * getShndxTable() const
Definition: ELFObject.h:715
std::vector< std::unique_ptr< Symbol > > Symbols
Definition: ELFObject.h:695
SectionIndexSection * SectionIndexTable
Definition: ELFObject.h:697
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:861
void addSymbol(Twine Name, uint8_t Bind, uint8_t Type, SectionBase *DefinedIn, uint64_t Value, uint8_t Visibility, uint16_t Shndx, uint64_t SymbolSize)
Definition: ELFObject.cpp:697
void updateSymbols(function_ref< void(Symbol &)> Callable)
Definition: ELFObject.cpp:739
static bool classof(const SectionBase *S)
Definition: ELFObject.h:733
Expected< const Symbol * > getSymbolByIndex(uint32_t Index) const
Definition: ELFObject.cpp:828
Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove) override
Definition: ELFObject.cpp:748
Error initialize(SectionTableRef SecTable) override
Definition: ELFObject.cpp:769
void replaceSectionReferences(const DenseMap< SectionBase *, SectionBase * > &FromTo) override
Definition: ELFObject.cpp:762
std::unique_ptr< Symbol > SymPtr
Definition: ELFObject.h:700
void setShndxTable(SectionIndexSection *ShndxTable)
Definition: ELFObject.h:712
StringTableSection * SymbolNames
Definition: ELFObject.h:696
virtual Error finalize()=0
virtual Error write()=0
std::unique_ptr< WritableMemoryBuffer > Buf
Definition: ELFObject.h:310
Writer(Object &O, raw_ostream &Out)
Definition: ELFObject.h:318
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ SHN_HEXAGON_SCOMMON_2
Definition: ELF.h:653
@ SHN_HEXAGON_SCOMMON_4
Definition: ELF.h:654
@ SHN_HEXAGON_SCOMMON_8
Definition: ELF.h:655
@ SHN_HEXAGON_SCOMMON
Definition: ELF.h:651
@ ET_DYN
Definition: ELF.h:118
@ ET_EXEC
Definition: ELF.h:117
@ SHT_STRTAB
Definition: ELF.h:1002
@ SHT_GROUP
Definition: ELF.h:1014
@ SHT_PROGBITS
Definition: ELF.h:1000
@ SHT_REL
Definition: ELF.h:1008
@ SHT_NULL
Definition: ELF.h:999
@ SHT_NOBITS
Definition: ELF.h:1007
@ SHT_SYMTAB
Definition: ELF.h:1001
@ SHT_DYNAMIC
Definition: ELF.h:1005
@ SHT_SYMTAB_SHNDX
Definition: ELF.h:1015
@ SHT_RELA
Definition: ELF.h:1003
@ SHT_DYNSYM
Definition: ELF.h:1010
@ SHN_XINDEX
Definition: ELF.h:993
@ SHN_HIOS
Definition: ELF.h:990
@ SHN_ABS
Definition: ELF.h:991
@ SHN_COMMON
Definition: ELF.h:992
@ SHN_LOOS
Definition: ELF.h:989
@ SHN_LOPROC
Definition: ELF.h:987
@ SHN_UNDEF
Definition: ELF.h:985
@ SHN_HIPROC
Definition: ELF.h:988
@ SHN_AMDGPU_LDS
Definition: ELF.h:1758
@ SHF_ALLOC
Definition: ELF.h:1089
@ SHF_COMPRESSED
Definition: ELF.h:1117
@ SHN_MIPS_TEXT
Definition: ELF.h:571
@ SHN_MIPS_DATA
Definition: ELF.h:572
@ SHN_MIPS_SUNDEFINED
Definition: ELF.h:574
@ SHN_MIPS_SCOMMON
Definition: ELF.h:573
@ SHN_MIPS_ACOMMON
Definition: ELF.h:570
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition: Error.h:1325
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1244
iterator_range< pointee_iterator< WrappedIteratorT > > make_pointee_range(RangeT &&Range)
Definition: iterator.h:336
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition: STLExtras.h:582
DebugCompressionType
Definition: Compression.h:27
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1754
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
static IHexLineData getLine(uint8_t Type, uint16_t Addr, ArrayRef< uint8_t > Data)
Definition: ELFObject.cpp:216
static uint8_t getChecksum(StringRef S)
Definition: ELFObject.cpp:206
static size_t getLength(size_t DataSize)
Definition: ELFObject.h:206
static size_t getLineLength(size_t DataSize)
Definition: ELFObject.h:212
uint16_t getShndx() const
Definition: ELFObject.cpp:667
SectionBase * DefinedIn
Definition: ELFObject.h:641
SymbolShndxType ShndxType
Definition: ELFObject.h:642
An iterator type that allows iterating over the pointees via some other iterator.
Definition: iterator.h:324
Definition: regcomp.c:192