LLVM  15.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"
15 #include "llvm/BinaryFormat/ELF.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 
29 namespace llvm {
30 enum class DebugCompressionType;
31 namespace objcopy {
32 namespace elf {
33 
34 class SectionBase;
35 class Section;
36 class OwnedDataSection;
37 class StringTableSection;
38 class SymbolTableSection;
39 class RelocationSection;
40 class DynamicRelocationSection;
41 class GnuDebugLinkSection;
42 class GroupSection;
43 class SectionIndexSection;
44 class CompressedSection;
45 class DecompressedSection;
46 class Segment;
47 class Object;
48 struct Symbol;
49 
52 
53 public:
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 
74 public:
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 
91 public:
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;
99  virtual Error visit(DynamicRelocationSection &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 
108 protected:
110 
111 public:
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  virtual Error visit(const SymbolTableSection &Sec) override = 0;
119  virtual Error visit(const RelocationSection &Sec) override = 0;
120  virtual Error visit(const GnuDebugLinkSection &Sec) override = 0;
121  virtual Error visit(const GroupSection &Sec) override = 0;
122  virtual Error visit(const SectionIndexSection &Sec) override = 0;
123  virtual Error visit(const CompressedSection &Sec) override = 0;
124  virtual Error visit(const DecompressedSection &Sec) override = 0;
125 
126  explicit SectionWriter(WritableMemoryBuffer &Buf) : Out(Buf) {}
127 };
128 
129 template <class ELFT> class ELFSectionWriter : public SectionWriter {
130 private:
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 
136 public:
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 
149 template <class ELFT> class ELFSectionSizer : public MutableSectionVisitor {
150 private:
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 
157 public:
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 
179 public:
180  virtual ~BinarySectionWriter() {}
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 
196 struct IHexRecord {
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.
223  static Expected<IHexRecord> parse(StringRef Line);
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
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 
279 protected:
280  // Offset in the output buffer
282 
283  void writeSection(const SectionBase *Sec, ArrayRef<uint8_t> Data);
284  virtual void writeData(uint8_t Type, uint16_t Addr, ArrayRef<uint8_t> Data);
285 
286 public:
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
300 public:
302 
303  void writeData(uint8_t Type, uint16_t Addr, ArrayRef<uint8_t> Data) override;
304  Error visit(const StringTableSection &Sec) override;
305 };
306 
307 class Writer {
308 protected:
310  std::unique_ptr<WritableMemoryBuffer> Buf;
312 
313 public:
314  virtual ~Writer();
315  virtual Error finalize() = 0;
316  virtual Error write() = 0;
317 
319 };
320 
321 template <class ELFT> class ELFWriter : public Writer {
322 private:
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 
345 public:
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 
358 class BinaryWriter : public Writer {
359 private:
360  std::unique_ptr<BinarySectionWriter> SecWriter;
361 
362  uint64_t TotalSize = 0;
363 
364 public:
366  Error finalize() override;
367  Error write() override;
369 };
370 
371 class 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 
383 public:
385  Error finalize() override;
386  Error write() override;
388 };
389 
390 class SectionBase {
391 public:
392  std::string Name;
393  Segment *ParentSegment = nullptr;
396 
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 };
436 
437 class Segment {
438 private:
439  struct SectionCompare {
440  bool operator()(const SectionBase *Lhs, const SectionBase *Rhs) const {
441  // Some sections might have the same address if one of them is empty. To
442  // fix this we can use the lexicographic ordering on ->Addr and the
443  // original index.
444  if (Lhs->OriginalOffset == Rhs->OriginalOffset)
445  return Lhs->OriginalIndex < Rhs->OriginalIndex;
446  return Lhs->OriginalOffset < Rhs->OriginalOffset;
447  }
448  };
449 
450 public:
459 
462  Segment *ParentSegment = nullptr;
464  std::set<const SectionBase *, SectionCompare> Sections;
465 
466  explicit Segment(ArrayRef<uint8_t> Data) : Contents(Data) {}
467  Segment() = default;
468 
469  const SectionBase *firstSection() const {
470  if (!Sections.empty())
471  return *Sections.begin();
472  return nullptr;
473  }
474 
475  void removeSection(const SectionBase *Sec) { Sections.erase(Sec); }
476  void addSection(const SectionBase *Sec) { Sections.insert(Sec); }
477 
479 };
480 
481 class Section : public SectionBase {
483 
484  ArrayRef<uint8_t> Contents;
485  SectionBase *LinkSection = nullptr;
486 
487 public:
488  explicit Section(ArrayRef<uint8_t> Data) : Contents(Data) {}
489 
490  Error accept(SectionVisitor &Visitor) const override;
491  Error accept(MutableSectionVisitor &Visitor) override;
493  bool AllowBrokenLinks,
494  function_ref<bool(const SectionBase *)> ToRemove) override;
495  Error initialize(SectionTableRef SecTable) override;
496  void finalize() override;
497  bool hasContents() const override {
498  return Type != ELF::SHT_NOBITS && Type != ELF::SHT_NULL;
499  }
500 };
501 
504 
505  std::vector<uint8_t> Data;
506 
507 public:
509  : Data(std::begin(Data), std::end(Data)) {
510  Name = SecName.str();
512  Size = Data.size();
514  }
515 
516  OwnedDataSection(const Twine &SecName, uint64_t SecAddr, uint64_t SecFlags,
517  uint64_t SecOff) {
518  Name = SecName.str();
520  Addr = SecAddr;
521  Flags = OriginalFlags = SecFlags;
522  OriginalOffset = SecOff;
523  }
524 
526  : SectionBase(S), Data(std::begin(Data), std::end(Data)) {
527  Size = Data.size();
528  }
529 
530  void appendHexData(StringRef HexData);
531  Error accept(SectionVisitor &Sec) const override;
532  Error accept(MutableSectionVisitor &Visitor) override;
533  bool hasContents() const override { return true; }
534 };
535 
538 
539  DebugCompressionType CompressionType;
540  uint64_t DecompressedSize;
541  uint64_t DecompressedAlign;
542  SmallVector<char, 128> CompressedData;
543 
544 public:
545  CompressedSection(const SectionBase &Sec,
546  DebugCompressionType CompressionType);
547  CompressedSection(ArrayRef<uint8_t> CompressedData, uint64_t DecompressedSize,
548  uint64_t DecompressedAlign);
549 
550  uint64_t getDecompressedSize() const { return DecompressedSize; }
551  uint64_t getDecompressedAlign() const { return DecompressedAlign; }
552 
553  Error accept(SectionVisitor &Visitor) const override;
554  Error accept(MutableSectionVisitor &Visitor) override;
555 
556  static bool classof(const SectionBase *S) {
557  return S->OriginalFlags & ELF::SHF_COMPRESSED;
558  }
559 };
560 
563 
564 public:
566  : SectionBase(Sec) {
567  Size = Sec.getDecompressedSize();
568  Align = Sec.getDecompressedAlign();
570  }
571 
572  Error accept(SectionVisitor &Visitor) const override;
573  Error accept(MutableSectionVisitor &Visitor) override;
574 };
575 
576 // There are two types of string tables that can exist, dynamic and not dynamic.
577 // In the dynamic case the string table is allocated. Changing a dynamic string
578 // table would mean altering virtual addresses and thus the memory image. So
579 // dynamic string tables should not have an interface to modify them or
580 // reconstruct them. This type lets us reconstruct a string table. To avoid
581 // this class being used for dynamic string tables (which has happened) the
582 // classof method checks that the particular instance is not allocated. This
583 // then agrees with the makeSection method used to construct most sections.
586 
587  StringTableBuilder StrTabBuilder;
588 
589 public:
592  }
593 
594  void addString(StringRef Name);
596  void prepareForLayout();
597  Error accept(SectionVisitor &Visitor) const override;
598  Error accept(MutableSectionVisitor &Visitor) override;
599 
600  static bool classof(const SectionBase *S) {
601  if (S->OriginalFlags & ELF::SHF_ALLOC)
602  return false;
603  return S->OriginalType == ELF::SHT_STRTAB;
604  }
605 };
606 
607 // Symbols have a st_shndx field that normally stores an index but occasionally
608 // stores a different special value. This enum keeps track of what the st_shndx
609 // field means. Most of the values are just copies of the special SHN_* values.
610 // SYMBOL_SIMPLE_INDEX means that the st_shndx is just an index of a section.
630 };
631 
632 struct Symbol {
633  uint8_t Binding;
634  SectionBase *DefinedIn = nullptr;
637  std::string Name;
640  uint8_t Type;
642  uint8_t Visibility;
643  bool Referenced = false;
644 
645  uint16_t getShndx() const;
646  bool isCommon() const;
647 };
648 
651 
652 private:
653  std::vector<uint32_t> Indexes;
654  SymbolTableSection *Symbols = nullptr;
655 
656 public:
657  virtual ~SectionIndexSection() {}
659  assert(Size > 0);
660  Indexes.push_back(Index);
661  }
662 
663  void reserve(size_t NumSymbols) {
664  Indexes.reserve(NumSymbols);
665  Size = NumSymbols * 4;
666  }
667  void setSymTab(SymbolTableSection *SymTab) { Symbols = SymTab; }
668  Error initialize(SectionTableRef SecTable) override;
669  void finalize() override;
670  Error accept(SectionVisitor &Visitor) const override;
671  Error accept(MutableSectionVisitor &Visitor) override;
672 
674  Name = ".symtab_shndx";
675  Align = 4;
676  EntrySize = 4;
678  }
679 };
680 
683 
684  void setStrTab(StringTableSection *StrTab) { SymbolNames = StrTab; }
685  void assignIndices();
686 
687 protected:
688  std::vector<std::unique_ptr<Symbol>> Symbols;
691 
692  using SymPtr = std::unique_ptr<Symbol>;
693 
694 public:
696 
697  void addSymbol(Twine Name, uint8_t Bind, uint8_t Type, SectionBase *DefinedIn,
698  uint64_t Value, uint8_t Visibility, uint16_t Shndx,
699  uint64_t SymbolSize);
700  void prepareForLayout();
701  // An 'empty' symbol table still contains a null symbol.
702  bool empty() const { return Symbols.size() == 1; }
703  void setShndxTable(SectionIndexSection *ShndxTable) {
704  SectionIndexTable = ShndxTable;
705  }
707  void fillShndxTable();
708  const SectionBase *getStrTab() const { return SymbolNames; }
711  void updateSymbols(function_ref<void(Symbol &)> Callable);
712 
714  bool AllowBrokenLinks,
715  function_ref<bool(const SectionBase *)> ToRemove) override;
716  Error initialize(SectionTableRef SecTable) override;
717  void finalize() override;
718  Error accept(SectionVisitor &Visitor) const override;
719  Error accept(MutableSectionVisitor &Visitor) override;
720  Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override;
722  const DenseMap<SectionBase *, SectionBase *> &FromTo) override;
723 
724  static bool classof(const SectionBase *S) {
725  return S->OriginalType == ELF::SHT_SYMTAB;
726  }
727 };
728 
729 struct Relocation {
730  Symbol *RelocSymbol = nullptr;
734 };
735 
736 // All relocation sections denote relocations to apply to another section.
737 // However, some relocation sections use a dynamic symbol table and others use
738 // a regular symbol table. Because the types of the two symbol tables differ in
739 // our system (because they should behave differently) we can't uniformly
740 // represent all relocations with the same base class if we expose an interface
741 // that mentions the symbol table type. So we split the two base types into two
742 // different classes, one which handles the section the relocation is applied to
743 // and another which handles the symbol table type. The symbol table type is
744 // taken as a type parameter to the class (see RelocSectionWithSymtabBase).
746 protected:
748 
749 public:
750  const SectionBase *getSection() const { return SecToApplyRel; }
751  void setSection(SectionBase *Sec) { SecToApplyRel = Sec; }
752 
753  StringRef getNamePrefix() const;
754 
755  static bool classof(const SectionBase *S) {
756  return S->OriginalType == ELF::SHT_REL || S->OriginalType == ELF::SHT_RELA;
757  }
758 };
759 
760 // Takes the symbol table type to use as a parameter so that we can deduplicate
761 // that code between the two symbol table types.
762 template <class SymTabType>
764  void setSymTab(SymTabType *SymTab) { Symbols = SymTab; }
765 
766 protected:
767  RelocSectionWithSymtabBase() = default;
768 
769  SymTabType *Symbols = nullptr;
770 
771 public:
772  Error initialize(SectionTableRef SecTable) override;
773  void finalize() override;
774 };
775 
777  : public RelocSectionWithSymtabBase<SymbolTableSection> {
779 
780  std::vector<Relocation> Relocations;
781  const Object &Obj;
782 
783 public:
784  RelocationSection(const Object &O) : Obj(O) {}
785  void addRelocation(Relocation Rel) { Relocations.push_back(Rel); }
786  Error accept(SectionVisitor &Visitor) const override;
787  Error accept(MutableSectionVisitor &Visitor) override;
789  bool AllowBrokenLinks,
790  function_ref<bool(const SectionBase *)> ToRemove) override;
791  Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override;
792  void markSymbols() override;
794  const DenseMap<SectionBase *, SectionBase *> &FromTo) override;
795  const Object &getObject() const { return Obj; }
796 
797  static bool classof(const SectionBase *S) {
798  if (S->OriginalFlags & ELF::SHF_ALLOC)
799  return false;
800  return S->OriginalType == ELF::SHT_REL || S->OriginalType == ELF::SHT_RELA;
801  }
802 };
803 
804 // TODO: The way stripping and groups interact is complicated
805 // and still needs to be worked on.
806 
807 class GroupSection : public SectionBase {
809  const SymbolTableSection *SymTab = nullptr;
810  Symbol *Sym = nullptr;
811  ELF::Elf32_Word FlagWord;
812  SmallVector<SectionBase *, 3> GroupMembers;
813 
814 public:
815  // TODO: Contents is present in several classes of the hierarchy.
816  // This needs to be refactored to avoid duplication.
818 
820 
821  void setSymTab(const SymbolTableSection *SymTabSec) { SymTab = SymTabSec; }
822  void setSymbol(Symbol *S) { Sym = S; }
823  void setFlagWord(ELF::Elf32_Word W) { FlagWord = W; }
824  void addMember(SectionBase *Sec) { GroupMembers.push_back(Sec); }
825 
826  Error accept(SectionVisitor &) const override;
827  Error accept(MutableSectionVisitor &Visitor) override;
828  void finalize() override;
830  bool AllowBrokenLinks,
831  function_ref<bool(const SectionBase *)> ToRemove) override;
832  Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override;
833  void markSymbols() override;
835  const DenseMap<SectionBase *, SectionBase *> &FromTo) override;
836  void onRemove() override;
837 
838  static bool classof(const SectionBase *S) {
839  return S->OriginalType == ELF::SHT_GROUP;
840  }
841 };
842 
844 public:
846 
847  static bool classof(const SectionBase *S) {
848  return S->OriginalType == ELF::SHT_DYNSYM;
849  }
850 };
851 
852 class DynamicSection : public Section {
853 public:
855 
856  static bool classof(const SectionBase *S) {
857  return S->OriginalType == ELF::SHT_DYNAMIC;
858  }
859 };
860 
862  : public RelocSectionWithSymtabBase<DynamicSymbolTableSection> {
864 
865 private:
866  ArrayRef<uint8_t> Contents;
867 
868 public:
869  explicit DynamicRelocationSection(ArrayRef<uint8_t> Data) : Contents(Data) {}
870 
871  Error accept(SectionVisitor &) const override;
872  Error accept(MutableSectionVisitor &Visitor) override;
874  bool AllowBrokenLinks,
875  function_ref<bool(const SectionBase *)> ToRemove) override;
876 
877  static bool classof(const SectionBase *S) {
878  if (!(S->OriginalFlags & ELF::SHF_ALLOC))
879  return false;
880  return S->OriginalType == ELF::SHT_REL || S->OriginalType == ELF::SHT_RELA;
881  }
882 };
883 
886 
887 private:
888  StringRef FileName;
889  uint32_t CRC32;
890 
891  void init(StringRef File);
892 
893 public:
894  // If we add this section from an external source we can use this ctor.
895  explicit GnuDebugLinkSection(StringRef File, uint32_t PrecomputedCRC);
896  Error accept(SectionVisitor &Visitor) const override;
897  Error accept(MutableSectionVisitor &Visitor) override;
898 };
899 
900 class Reader {
901 public:
902  virtual ~Reader();
903  virtual Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const = 0;
904 };
905 
906 using object::Binary;
907 using object::ELFFile;
910 
912 protected:
913  std::unique_ptr<Object> Obj;
914 
915  void initFileHeader();
916  void initHeaderSegment();
920 
921 public:
922  BasicELFBuilder() : Obj(std::make_unique<Object>()) {}
923 };
924 
926  MemoryBuffer *MemBuf;
927  uint8_t NewSymbolVisibility;
928  void addData(SymbolTableSection *SymTab);
929 
930 public:
931  BinaryELFBuilder(MemoryBuffer *MB, uint8_t NewSymbolVisibility)
932  : MemBuf(MB), NewSymbolVisibility(NewSymbolVisibility) {}
933 
935 };
936 
938  const std::vector<IHexRecord> &Records;
939 
940  void addDataSections();
941 
942 public:
943  IHexELFBuilder(const std::vector<IHexRecord> &Records) : Records(Records) {}
944 
946 };
947 
948 template <class ELFT> class ELFBuilder {
949 private:
950  using Elf_Addr = typename ELFT::Addr;
951  using Elf_Shdr = typename ELFT::Shdr;
952  using Elf_Word = typename ELFT::Word;
953 
954  const ELFFile<ELFT> &ElfFile;
955  Object &Obj;
956  size_t EhdrOffset = 0;
957  Optional<StringRef> ExtractPartition;
958 
959  void setParentSegment(Segment &Child);
960  Error readProgramHeaders(const ELFFile<ELFT> &HeadersFile);
961  Error initGroupSection(GroupSection *GroupSec);
962  Error initSymbolTable(SymbolTableSection *SymTab);
963  Error readSectionHeaders();
964  Error readSections(bool EnsureSymtab);
965  Error findEhdrOffset();
966  Expected<SectionBase &> makeSection(const Elf_Shdr &Shdr);
967 
968 public:
969  ELFBuilder(const ELFObjectFile<ELFT> &ElfObj, Object &Obj,
970  Optional<StringRef> ExtractPartition);
971 
972  Error build(bool EnsureSymtab);
973 };
974 
975 class BinaryReader : public Reader {
976  MemoryBuffer *MemBuf;
977  uint8_t NewSymbolVisibility;
978 
979 public:
980  BinaryReader(MemoryBuffer *MB, const uint8_t NewSymbolVisibility)
981  : MemBuf(MB), NewSymbolVisibility(NewSymbolVisibility) {}
982  Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
983 };
984 
985 class IHexReader : public Reader {
986  MemoryBuffer *MemBuf;
987 
989  Error parseError(size_t LineNo, Error E) const {
990  return LineNo == -1U
992  : createFileError(MemBuf->getBufferIdentifier(), LineNo,
993  std::move(E));
994  }
995  template <typename... Ts>
996  Error parseError(size_t LineNo, char const *Fmt, const Ts &...Vals) const {
998  return parseError(LineNo, std::move(E));
999  }
1000 
1001 public:
1002  IHexReader(MemoryBuffer *MB) : MemBuf(MB) {}
1003 
1004  Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
1005 };
1006 
1007 class ELFReader : public Reader {
1008  Binary *Bin;
1009  Optional<StringRef> ExtractPartition;
1010 
1011 public:
1012  Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
1013  explicit ELFReader(Binary *B, Optional<StringRef> ExtractPartition)
1014  : Bin(B), ExtractPartition(ExtractPartition) {}
1015 };
1016 
1017 class Object {
1018 private:
1019  using SecPtr = std::unique_ptr<SectionBase>;
1020  using SegPtr = std::unique_ptr<Segment>;
1021 
1022  std::vector<SecPtr> Sections;
1023  std::vector<SegPtr> Segments;
1024  std::vector<SecPtr> RemovedSections;
1026 
1027  static bool sectionIsAlloc(const SectionBase &Sec) {
1028  return Sec.Flags & ELF::SHF_ALLOC;
1029  };
1030 
1031 public:
1032  template <class T>
1034  typename std::vector<std::unique_ptr<T>>::const_iterator>>;
1035 
1036  // It is often the case that the ELF header and the program header table are
1037  // not present in any segment. This could be a problem during file layout,
1038  // because other segments may get assigned an offset where either of the
1039  // two should reside, which will effectively corrupt the resulting binary.
1040  // Other than that we use these segments to track program header offsets
1041  // when they may not follow the ELF header.
1044 
1045  uint8_t OSABI;
1046  uint8_t ABIVersion;
1053 
1054  bool HadShdrs = true;
1055  bool MustBeRelocatable = false;
1059 
1060  bool IsMips64EL = false;
1061 
1062  SectionTableRef sections() const { return SectionTableRef(Sections); }
1065  decltype(&sectionIsAlloc)>>
1066  allocSections() const {
1067  return make_filter_range(make_pointee_range(Sections), sectionIsAlloc);
1068  }
1069 
1070  const auto &getUpdatedSections() const { return UpdatedSections; }
1072 
1074  auto SecIt =
1075  find_if(Sections, [&](const SecPtr &Sec) { return Sec->Name == Name; });
1076  return SecIt == Sections.end() ? nullptr : SecIt->get();
1077  }
1078  SectionTableRef removedSections() { return SectionTableRef(RemovedSections); }
1079 
1080  ConstRange<Segment> segments() const { return make_pointee_range(Segments); }
1081 
1082  Error removeSections(bool AllowBrokenLinks,
1083  std::function<bool(const SectionBase &)> ToRemove);
1086  template <class T, class... Ts> T &addSection(Ts &&...Args) {
1087  auto Sec = std::make_unique<T>(std::forward<Ts>(Args)...);
1088  auto Ptr = Sec.get();
1089  MustBeRelocatable |= isa<RelocationSection>(*Ptr);
1090  Sections.emplace_back(std::move(Sec));
1091  Ptr->Index = Sections.size();
1092  return *Ptr;
1093  }
1096  Segments.emplace_back(std::make_unique<Segment>(Data));
1097  return *Segments.back();
1098  }
1099  bool isRelocatable() const {
1100  return (Type != ELF::ET_DYN && Type != ELF::ET_EXEC) || MustBeRelocatable;
1101  }
1102 };
1103 
1104 } // end namespace elf
1105 } // end namespace objcopy
1106 } // end namespace llvm
1107 
1108 #endif // LLVM_LIB_OBJCOPY_ELF_ELFOBJECT_H
llvm::objcopy::elf::Reader::create
virtual Expected< std::unique_ptr< Object > > create(bool EnsureSymtab) const =0
llvm::objcopy::elf::BinaryWriter::BinaryWriter
BinaryWriter(Object &Obj, raw_ostream &Out)
Definition: ELFObject.h:368
MemoryBuffer.h
llvm::objcopy::elf::RelocationSection::addRelocation
void addRelocation(Relocation Rel)
Definition: ELFObject.h:785
const_iterator
llvm::objcopy::elf::IHexSectionWriterBase::IHexSectionWriterBase
IHexSectionWriterBase(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:287
llvm::errc::invalid_argument
@ invalid_argument
llvm::objcopy::elf::SymbolTableSection::fillShndxTable
void fillShndxTable()
Definition: ELFObject.cpp:814
llvm::objcopy::elf::SectionWriter
Definition: ELFObject.h:107
llvm::objcopy::elf::OwnedDataSection::OwnedDataSection
OwnedDataSection(StringRef SecName, ArrayRef< uint8_t > Data)
Definition: ELFObject.h:508
llvm::objcopy::elf::BasicELFBuilder::initSections
Error initSections()
Definition: ELFObject.cpp:1271
llvm::objcopy::elf::GroupSection
Definition: ELFObject.h:807
llvm::objcopy::elf::SectionBase::removeSymbols
virtual Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove)
Definition: ELFObject.cpp:56
llvm::objcopy::elf::IHexRecord::StartAddr
@ StartAddr
Definition: ELFObject.h:259
llvm::objcopy::elf::SYMBOL_HEXAGON_SCOMMON_4
@ SYMBOL_HEXAGON_SCOMMON_4
Definition: ELFObject.h:619
llvm::objcopy::elf::IHexWriter::finalize
Error finalize() override
Definition: ELFObject.cpp:2738
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::objcopy::elf::Symbol::getShndx
uint16_t getShndx() const
Definition: ELFObject.cpp:673
llvm::objcopy::elf::IHexRecord::ExtendedAddr
@ ExtendedAddr
Definition: ELFObject.h:255
llvm::objcopy::elf::Segment::FileSize
uint64_t FileSize
Definition: ELFObject.h:456
llvm::objcopy::elf::Object::updateSection
Error updateSection(StringRef Name, ArrayRef< uint8_t > Data)
Definition: ELFObject.cpp:2117
llvm::objcopy::elf::ELFSectionWriter::ELFSectionWriter
ELFSectionWriter(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:146
llvm::objcopy::elf::SectionVisitor
Definition: ELFObject.h:73
llvm::objcopy::elf::ELFWriter::OnlyKeepDebug
bool OnlyKeepDebug
Definition: ELFObject.h:351
llvm::objcopy::elf::Object::ABIVersion
uint8_t ABIVersion
Definition: ELFObject.h:1046
llvm::ELF::SHN_MIPS_ACOMMON
@ SHN_MIPS_ACOMMON
Definition: ELF.h:569
llvm::objcopy::elf::SectionTableRef::SectionTableRef
SectionTableRef(ArrayRef< std::unique_ptr< SectionBase >> Secs)
Definition: ELFObject.h:56
llvm::objcopy::elf::BinaryWriter::~BinaryWriter
~BinaryWriter()
Definition: ELFObject.h:365
llvm::objcopy::elf::ELFWriter
Definition: ELFObject.h:321
llvm::objcopy::elf::Relocation
Definition: ELFObject.h:729
llvm::objcopy::elf::SectionBase::NameIndex
uint64_t NameIndex
Definition: ELFObject.h:408
llvm::objcopy::elf::ELFT_ELF64LE
@ ELFT_ELF64LE
Definition: ELFObject.h:71
llvm::objcopy::elf::BinarySectionWriter
Definition: ELFObject.h:178
StringRef.h
llvm::objcopy::elf::SYMBOL_ABS
@ SYMBOL_ABS
Definition: ELFObject.h:613
llvm::objcopy::elf::ELFReader::ELFReader
ELFReader(Binary *B, Optional< StringRef > ExtractPartition)
Definition: ELFObject.h:1013
llvm::objcopy::elf::Object::Entry
uint64_t Entry
Definition: ELFObject.h:1047
llvm::objcopy::elf::GroupSection::replaceSectionReferences
void replaceSectionReferences(const DenseMap< SectionBase *, SectionBase * > &FromTo) override
Definition: ELFObject.cpp:1096
llvm::objcopy::elf::ELFWriter::ELFWriter
ELFWriter(Object &Obj, raw_ostream &Out, bool WSH, bool OnlyKeepDebug)
Definition: ELFObject.cpp:2112
llvm::objcopy::elf::RelocationSectionBase::getSection
const SectionBase * getSection() const
Definition: ELFObject.h:750
llvm::objcopy::elf::RelocSectionWithSymtabBase::initialize
Error initialize(SectionTableRef SecTable) override
Definition: ELFObject.cpp:908
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::RISCVFenceField::W
@ W
Definition: RISCVBaseInfo.h:242
llvm::objcopy::elf::RelocationSection::RelocationSection
RelocationSection(const Object &O)
Definition: ELFObject.h:784
llvm::objcopy::elf::Section::removeSectionReferences
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:1041
llvm::objcopy::elf::DecompressedSection
Definition: ELFObject.h:561
llvm::ELF::SHN_HEXAGON_SCOMMON
@ SHN_HEXAGON_SCOMMON
Definition: ELF.h:644
llvm::objcopy::elf::SectionTableRef
Definition: ELFObject.h:50
llvm::objcopy::elf::SectionBase::finalize
virtual void finalize()
Definition: ELFObject.cpp:61
llvm::objcopy::elf::SectionBase::OriginalOffset
uint64_t OriginalOffset
Definition: ELFObject.h:400
llvm::ELF::SHN_LOPROC
@ SHN_LOPROC
Definition: ELF.h:942
ToRemove
ReachingDefAnalysis InstSet & ToRemove
Definition: ARMLowOverheadLoops.cpp:542
llvm::objcopy::elf::BasicELFBuilder
Definition: ELFObject.h:911
llvm::objcopy::elf::SectionTableRef::getSection
Expected< SectionBase * > getSection(uint32_t Index, Twine ErrMsg)
Definition: ELFObject.cpp:1652
llvm::objcopy::elf::DynamicSection
Definition: ELFObject.h:852
llvm::objcopy::elf::SYMBOL_LOPROC
@ SYMBOL_LOPROC
Definition: ELFObject.h:615
llvm::ELF::SHN_LOOS
@ SHN_LOOS
Definition: ELF.h:944
llvm::objcopy::elf::RelocationSection::markSymbols
void markSymbols() override
Definition: ELFObject.cpp:995
llvm::objcopy::elf::Writer::Obj
Object & Obj
Definition: ELFObject.h:309
llvm::objcopy::elf::Object::isRelocatable
bool isRelocatable() const
Definition: ELFObject.h:1099
llvm::objcopy::elf::Object::removeSymbols
Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove)
Definition: ELFObject.cpp:2224
llvm::ELF::SHT_SYMTAB_SHNDX
@ SHT_SYMTAB_SHNDX
Definition: ELF.h:970
llvm::objcopy::elf::IHexRecord::getLength
static size_t getLength(size_t DataSize)
Definition: ELFObject.h:206
llvm::objcopy::elf::SectionBase::EntrySize
uint32_t EntrySize
Definition: ELFObject.h:404
llvm::objcopy::elf::CompressedSection::CompressedSection
CompressedSection(const SectionBase &Sec, DebugCompressionType CompressionType)
Definition: ELFObject.cpp:543
llvm::ELF::SHT_STRTAB
@ SHT_STRTAB
Definition: ELF.h:957
llvm::objcopy::elf::SYMBOL_COMMON
@ SYMBOL_COMMON
Definition: ELFObject.h:614
Errc.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::objcopy::elf::SectionTableRef::size
size_t size() const
Definition: ELFObject.h:62
llvm::objcopy::elf::SYMBOL_LOOS
@ SYMBOL_LOOS
Definition: ELFObject.h:627
llvm::filter_iterator_impl
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:462
llvm::objcopy::elf::IHexReader::IHexReader
IHexReader(MemoryBuffer *MB)
Definition: ELFObject.h:1002
llvm::ELF::SHN_HIPROC
@ SHN_HIPROC
Definition: ELF.h:943
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:235
llvm::objcopy::elf::IHexRecord::SegmentAddr
@ SegmentAddr
Definition: ELFObject.h:245
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:226
llvm::objcopy::elf::SectionTableRef::begin
iterator begin() const
Definition: ELFObject.h:60
llvm::objcopy::elf::DynamicRelocationSection
Definition: ELFObject.h:861
llvm::objcopy::elf::Writer::Out
raw_ostream & Out
Definition: ELFObject.h:311
llvm::objcopy::elf::GroupSection::removeSectionReferences
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:1066
llvm::objcopy::elf::Segment::VAddr
uint64_t VAddr
Definition: ELFObject.h:454
llvm::objcopy::elf::SectionWriter::~SectionWriter
virtual ~SectionWriter()=default
llvm::objcopy::elf::SectionIndexSection::finalize
void finalize() override
Definition: ELFObject.cpp:627
llvm::Optional
Definition: APInt.h:33
llvm::objcopy::elf::SYMBOL_MIPS_SCOMMON
@ SYMBOL_MIPS_SCOMMON
Definition: ELFObject.h:624
T
#define T
Definition: Mips16ISelLowering.cpp:341
FileOutputBuffer.h
llvm::objcopy::elf::SymbolTableSection::getShndxTable
const SectionIndexSection * getShndxTable() const
Definition: ELFObject.h:706
llvm::objcopy::elf::Object::SectionIndexTable
SectionIndexSection * SectionIndexTable
Definition: ELFObject.h:1058
llvm::objcopy::elf::GroupSection::Contents
ArrayRef< uint8_t > Contents
Definition: ELFObject.h:817
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:1038
llvm::objcopy::elf::BinaryReader::BinaryReader
BinaryReader(MemoryBuffer *MB, const uint8_t NewSymbolVisibility)
Definition: ELFObject.h:980
llvm::objcopy::elf::SectionBase::Name
std::string Name
Definition: ELFObject.h:392
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::objcopy::elf::StringTableSection::findIndex
uint32_t findIndex(StringRef Name) const
Definition: ELFObject.cpp:580
llvm::objcopy::elf::SectionBase::Addr
uint64_t Addr
Definition: ELFObject.h:402
llvm::objcopy::elf::SectionWriter::visit
Error visit(const Section &Sec) override
Definition: ELFObject.cpp:170
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::objcopy::elf::SectionBase::OriginalIndex
uint32_t OriginalIndex
Definition: ELFObject.h:397
llvm::objcopy::elf::Section
Definition: ELFObject.h:481
llvm::objcopy::elf::Writer::Writer
Writer(Object &O, raw_ostream &Out)
Definition: ELFObject.h:318
llvm::objcopy::elf::IHexELFBuilder::IHexELFBuilder
IHexELFBuilder(const std::vector< IHexRecord > &Records)
Definition: ELFObject.h:943
llvm::objcopy::elf::CompressedSection::getDecompressedAlign
uint64_t getDecompressedAlign() const
Definition: ELFObject.h:551
llvm::ELF::SHN_MIPS_SUNDEFINED
@ SHN_MIPS_SUNDEFINED
Definition: ELF.h:573
llvm::objcopy::elf::Writer
Definition: ELFObject.h:307
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::objcopy::elf::Object::replaceSections
Error replaceSections(const DenseMap< SectionBase *, SectionBase * > &FromTo)
Definition: ELFObject.cpp:2200
llvm::ELF::SHN_HEXAGON_SCOMMON_4
@ SHN_HEXAGON_SCOMMON_4
Definition: ELF.h:647
llvm::MemoryBuffer
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
llvm::objcopy::elf::SectionBase::removeSectionReferences
virtual Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove)
Definition: ELFObject.cpp:51
llvm::objcopy::elf::SectionBase::hasContents
virtual bool hasContents() const
Definition: ELFObject.h:432
llvm::objcopy::elf::Object::addSection
T & addSection(Ts &&...Args)
Definition: ELFObject.h:1086
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:161
llvm::ELF::SHN_COMMON
@ SHN_COMMON
Definition: ELF.h:947
llvm::objcopy::elf::IHexRecord
Definition: ELFObject.h:196
llvm::objcopy::elf::IHexSectionWriterBase::getBufferOffset
uint64_t getBufferOffset() const
Definition: ELFObject.h:290
llvm::objcopy::elf::IHexWriter
Definition: ELFObject.h:371
llvm::objcopy::elf::SectionIndexSection
Definition: ELFObject.h:649
llvm::objcopy::elf::Object::ElfHdrSegment
Segment ElfHdrSegment
Definition: ELFObject.h:1042
llvm::objcopy::elf::ELFWriter::write
Error write() override
Definition: ELFObject.cpp:2482
llvm::SubDirectoryType::Bin
@ Bin
llvm::objcopy::elf::SectionTableRef::getSectionOfType
Expected< T * > getSectionOfType(uint32_t Index, Twine IndexErrMsg, Twine TypeErrMsg)
Definition: ELFObject.cpp:1660
llvm::objcopy::elf::Object::allocSections
iterator_range< filter_iterator< pointee_iterator< std::vector< SecPtr >::const_iterator >, decltype(&sectionIsAlloc)> > allocSections() const
Definition: ELFObject.h:1066
llvm::ELF::SHF_COMPRESSED
@ SHF_COMPRESSED
Definition: ELF.h:1066
llvm::objcopy::elf::Relocation::Type
uint32_t Type
Definition: ELFObject.h:733
llvm::objcopy::elf::ELFWriter::~ELFWriter
virtual ~ELFWriter()
Definition: ELFObject.h:346
llvm::objcopy::elf::StringTableSection::StringTableSection
StringTableSection()
Definition: ELFObject.h:590
llvm::objcopy::elf::Object::addSegment
Segment & addSegment(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:1095
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
llvm::objcopy::elf::SectionBase::~SectionBase
virtual ~SectionBase()=default
llvm::objcopy::elf::Section::finalize
void finalize() override
Definition: ELFObject.cpp:1128
llvm::objcopy::elf::SectionBase::Flags
uint64_t Flags
Definition: ELFObject.h:405
llvm::objcopy::elf::SectionBase::HasSymbol
bool HasSymbol
Definition: ELFObject.h:413
llvm::objcopy::elf::DecompressedSection::accept
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:488
llvm::objcopy::elf::Object::Machine
uint32_t Machine
Definition: ELFObject.h:1050
llvm::objcopy::elf::BasicELFBuilder::BasicELFBuilder
BasicELFBuilder()
Definition: ELFObject.h:922
llvm::objcopy::elf::SymbolTableSection::Symbols
std::vector< std::unique_ptr< Symbol > > Symbols
Definition: ELFObject.h:688
StringTableBuilder.h
llvm::objcopy::elf::CompressedSection::classof
static bool classof(const SectionBase *S)
Definition: ELFObject.h:556
llvm::objcopy::elf::Segment::Contents
ArrayRef< uint8_t > Contents
Definition: ELFObject.h:463
llvm::objcopy::elf::SectionIndexSection::initialize
Error initialize(SectionTableRef SecTable) override
Definition: ELFObject.cpp:610
llvm::objcopy::elf::Object
Definition: ELFObject.h:1017
llvm::objcopy::FileFormat::ELF
@ ELF
llvm::objcopy::elf::IHexRecord::Addr
uint16_t Addr
Definition: ELFObject.h:198
llvm::objcopy::elf::Object::findSection
SectionBase * findSection(StringRef Name)
Definition: ELFObject.h:1073
llvm::objcopy::elf::SectionWriter::SectionWriter
SectionWriter(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:126
llvm::objcopy::elf::Symbol::Type
uint8_t Type
Definition: ELFObject.h:640
llvm::objcopy::elf::Object::Flags
uint32_t Flags
Definition: ELFObject.h:1052
llvm::objcopy::elf::Object::addNewSymbolTable
Error addNewSymbolTable()
Definition: ELFObject.cpp:2232
ELF.h
llvm::objcopy::elf::SymbolTableSection::SymbolNames
StringTableSection * SymbolNames
Definition: ELFObject.h:689
llvm::objcopy::elf::RelocSectionWithSymtabBase::finalize
void finalize() override
Definition: ELFObject.cpp:938
llvm::objcopy::elf::SymbolTableSection::addSymbol
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:700
llvm::createFileError
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition: Error.h:1320
llvm::objcopy::elf::SectionBase::Offset
uint64_t Offset
Definition: ELFObject.h:409
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::objcopy::elf::Reader
Definition: ELFObject.h:900
llvm::objcopy::elf::DynamicSection::classof
static bool classof(const SectionBase *S)
Definition: ELFObject.h:856
Twine.h
llvm::objcopy::elf::Symbol::Size
uint64_t Size
Definition: ELFObject.h:639
llvm::ELF::SHN_MIPS_TEXT
@ SHN_MIPS_TEXT
Definition: ELF.h:570
llvm::objcopy::elf::IHexReader
Definition: ELFObject.h:985
llvm::objcopy::elf::BinarySectionWriter::visit
Error visit(const SymbolTableSection &Sec) override
Definition: ELFObject.cpp:148
llvm::objcopy::elf::SectionIndexSection::SectionIndexSection
SectionIndexSection()
Definition: ELFObject.h:673
llvm::objcopy::elf::SYMBOL_HEXAGON_SCOMMON_2
@ SYMBOL_HEXAGON_SCOMMON_2
Definition: ELFObject.h:618
llvm::objcopy::elf::SectionVisitor::~SectionVisitor
virtual ~SectionVisitor()=default
llvm::objcopy::elf::Writer::write
virtual Error write()=0
llvm::objcopy::elf::GroupSection::onRemove
void onRemove() override
Definition: ELFObject.cpp:1103
llvm::objcopy::elf::Object::SectionNames
StringTableSection * SectionNames
Definition: ELFObject.h:1056
llvm::objcopy::elf::IHexRecord::Type
Type
Definition: ELFObject.h:230
llvm::objcopy::elf::DynamicRelocationSection::classof
static bool classof(const SectionBase *S)
Definition: ELFObject.h:877
llvm::objcopy::elf::ELFSectionSizer
Definition: ELFObject.h:149
parse
Definition: regcomp.c:192
llvm::objcopy::elf::Object::Version
uint32_t Version
Definition: ELFObject.h:1051
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::objcopy::elf::ELFSectionSizer::visit
Error visit(Section &Sec) override
Definition: ELFObject.cpp:83
llvm::objcopy::elf::SYMBOL_MIPS_TEXT
@ SYMBOL_MIPS_TEXT
Definition: ELFObject.h:622
llvm::objcopy::elf::SymbolTableSection::prepareForLayout
void prepareForLayout()
Definition: ELFObject.cpp:798
llvm::objcopy::elf::SYMBOL_MIPS_ACOMMON
@ SYMBOL_MIPS_ACOMMON
Definition: ELFObject.h:621
llvm::objcopy::elf::DynamicSymbolTableSection
Definition: ELFObject.h:843
llvm::objcopy::elf::IHexWriter::~IHexWriter
~IHexWriter()
Definition: ELFObject.h:384
llvm::objcopy::elf::DynamicSymbolTableSection::DynamicSymbolTableSection
DynamicSymbolTableSection(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:845
llvm::objcopy::elf::SymbolTableSection::classof
static bool classof(const SectionBase *S)
Definition: ELFObject.h:724
llvm::ELF::SHN_ABS
@ SHN_ABS
Definition: ELF.h:946
llvm::objcopy::elf::RelocationSection
Definition: ELFObject.h:776
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::objcopy::elf::Segment::ParentSegment
Segment * ParentSegment
Definition: ELFObject.h:462
llvm::objcopy::elf::OwnedDataSection::appendHexData
void appendHexData(StringRef HexData)
Definition: ELFObject.cpp:504
llvm::objcopy::elf::OwnedDataSection
Definition: ELFObject.h:502
llvm::objcopy::elf::BinarySectionWriter::BinarySectionWriter
BinarySectionWriter(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:190
llvm::objcopy::elf::SymbolTableSection::getStrTab
const SectionBase * getStrTab() const
Definition: ELFObject.h:708
llvm::objcopy::elf::SymbolTableSection::setShndxTable
void setShndxTable(SectionIndexSection *ShndxTable)
Definition: ELFObject.h:703
llvm::objcopy::elf::SymbolTableSection::removeSymbols
Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove) override
Definition: ELFObject.cpp:751
llvm::objcopy::elf::IHexELFBuilder::build
Expected< std::unique_ptr< Object > > build()
Definition: ELFObject.cpp:1364
CommonConfig.h
llvm::objcopy::elf::SymbolShndxType
SymbolShndxType
Definition: ELFObject.h:611
llvm::objcopy::elf::SYMBOL_HIOS
@ SYMBOL_HIOS
Definition: ELFObject.h:628
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::objcopy::elf::BasicELFBuilder::initHeaderSegment
void initHeaderSegment()
Definition: ELFObject.cpp:1248
llvm::objcopy::elf::ELFReader
Definition: ELFObject.h:1007
llvm::objcopy::elf::SectionBase::accept
virtual Error accept(SectionVisitor &Visitor) const =0
llvm::StringRef::str
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:249
llvm::objcopy::elf::Section::Section
Section(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:488
llvm::objcopy::elf::SYMBOL_SIMPLE_INDEX
@ SYMBOL_SIMPLE_INDEX
Definition: ELFObject.h:612
llvm::objcopy::elf::ELFSectionWriter::~ELFSectionWriter
virtual ~ELFSectionWriter()
Definition: ELFObject.h:137
llvm::objcopy::elf::Section::hasContents
bool hasContents() const override
Definition: ELFObject.h:497
llvm::objcopy::elf::BinaryReader
Definition: ELFObject.h:975
llvm::objcopy::elf::MutableSectionVisitor::~MutableSectionVisitor
virtual ~MutableSectionVisitor()=default
llvm::objcopy::elf::SectionBase::OriginalFlags
uint64_t OriginalFlags
Definition: ELFObject.h:398
llvm::objcopy::elf::IHexRecord::getChecksum
static uint8_t getChecksum(StringRef S)
Definition: ELFObject.cpp:206
llvm::objcopy::elf::DecompressedSection::DecompressedSection
DecompressedSection(const CompressedSection &Sec)
Definition: ELFObject.h:565
llvm::objcopy::elf::GroupSection::addMember
void addMember(SectionBase *Sec)
Definition: ELFObject.h:824
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:962
llvm::objcopy::elf::IHexRecord::EndOfFile
@ EndOfFile
Definition: ELFObject.h:237
llvm::MemoryBuffer::getBufferIdentifier
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:75
llvm::Twine::str
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
llvm::objcopy::elf::IHexSectionWriterBase::writeSection
void writeSection(const SectionBase *Sec, ArrayRef< uint8_t > Data)
Definition: ELFObject.cpp:335
llvm::objcopy::elf::DynamicRelocationSection::accept
Error accept(SectionVisitor &) const override
Definition: ELFObject.cpp:1013
llvm::OutputFileType::Object
@ Object
llvm::objcopy::elf::Symbol
Definition: ELFObject.h:632
llvm::objcopy::elf::SectionBase::SectionBase
SectionBase()=default
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::objcopy::elf::BinarySectionWriter::~BinarySectionWriter
virtual ~BinarySectionWriter()
Definition: ELFObject.h:180
llvm::ELF::SHT_DYNAMIC
@ SHT_DYNAMIC
Definition: ELF.h:960
llvm::objcopy::elf::RelocationSectionBase::SecToApplyRel
SectionBase * SecToApplyRel
Definition: ELFObject.h:747
llvm::objcopy::elf::ELFT_ELF32BE
@ ELFT_ELF32BE
Definition: ELFObject.h:71
llvm::objcopy::elf::Segment::getContents
ArrayRef< uint8_t > getContents() const
Definition: ELFObject.h:478
llvm::objcopy::elf::Symbol::Value
uint64_t Value
Definition: ELFObject.h:641
llvm::objcopy::elf::RelocationSectionBase::getNamePrefix
StringRef getNamePrefix() const
Definition: ELFObject.cpp:869
llvm::ELF::ET_DYN
@ ET_DYN
Definition: ELF.h:118
llvm::objcopy::elf::GroupSection::GroupSection
GroupSection(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:819
llvm::objcopy::elf::Relocation::RelocSymbol
Symbol * RelocSymbol
Definition: ELFObject.h:730
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:240
llvm::objcopy::elf::ELFWriter::finalize
Error finalize() override
Definition: ELFObject.cpp:2518
llvm::ELF::ET_EXEC
@ ET_EXEC
Definition: ELF.h:117
llvm::objcopy::elf::SYMBOL_MIPS_DATA
@ SYMBOL_MIPS_DATA
Definition: ELFObject.h:623
llvm::objcopy::elf::GroupSection::accept
Error accept(SectionVisitor &) const override
Definition: ELFObject.cpp:1182
llvm::objcopy::elf::SectionIndexSection::~SectionIndexSection
virtual ~SectionIndexSection()
Definition: ELFObject.h:657
llvm::objcopy::elf::BinaryWriter::finalize
Error finalize() override
Definition: ELFObject.cpp:2639
llvm::objcopy::elf::BinaryReader::create
Expected< std::unique_ptr< Object > > create(bool EnsureSymtab) const override
Definition: ELFObject.cpp:1914
llvm::ELF::SHT_NULL
@ SHT_NULL
Definition: ELF.h:954
llvm::objcopy::elf::SectionBase::initialize
virtual Error initialize(SectionTableRef SecTable)
Definition: ELFObject.cpp:60
uint64_t
llvm::objcopy::elf::SectionBase::replaceSectionReferences
virtual void replaceSectionReferences(const DenseMap< SectionBase *, SectionBase * > &)
Definition: ELFObject.cpp:63
llvm::ELF::SHT_SYMTAB
@ SHT_SYMTAB
Definition: ELF.h:956
llvm::objcopy::elf::Segment::MemSize
uint64_t MemSize
Definition: ELFObject.h:457
llvm::ELF::SHN_AMDGPU_LDS
@ SHN_AMDGPU_LDS
Definition: ELF.h:1699
llvm::objcopy::elf::Segment
Definition: ELFObject.h:437
llvm::objcopy::elf::Writer::~Writer
virtual ~Writer()
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
llvm::objcopy::elf::Symbol::NameIndex
uint32_t NameIndex
Definition: ELFObject.h:638
llvm::objcopy::elf::Writer::Buf
std::unique_ptr< WritableMemoryBuffer > Buf
Definition: ELFObject.h:310
llvm::objcopy::elf::Segment::addSection
void addSection(const SectionBase *Sec)
Definition: ELFObject.h:476
llvm::objcopy::elf::Symbol::DefinedIn
SectionBase * DefinedIn
Definition: ELFObject.h:634
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::objcopy::elf::OwnedDataSection::OwnedDataSection
OwnedDataSection(const Twine &SecName, uint64_t SecAddr, uint64_t SecFlags, uint64_t SecOff)
Definition: ELFObject.h:516
llvm::objcopy::elf::Object::HadShdrs
bool HadShdrs
Definition: ELFObject.h:1054
llvm::objcopy::elf::Segment::PAddr
uint64_t PAddr
Definition: ELFObject.h:455
llvm::DenseMap
Definition: DenseMap.h:716
llvm::objcopy::elf::StringTableSection::prepareForLayout
void prepareForLayout()
Definition: ELFObject.cpp:584
llvm::objcopy::elf::DynamicRelocationSection::DynamicRelocationSection
DynamicRelocationSection(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:869
llvm::objcopy::elf::ELFReader::create
Expected< std::unique_ptr< Object > > create(bool EnsureSymtab) const override
Definition: ELFObject.cpp:1953
llvm::ELF::SHN_XINDEX
@ SHN_XINDEX
Definition: ELF.h:948
llvm::objcopy::elf::SectionBase::markSymbols
virtual void markSymbols()
Definition: ELFObject.cpp:62
llvm::ELF::SHN_HEXAGON_SCOMMON_2
@ SHN_HEXAGON_SCOMMON_2
Definition: ELF.h:646
llvm::objcopy::elf::BinaryELFBuilder
Definition: ELFObject.h:925
llvm::objcopy::elf::StringTableSection::classof
static bool classof(const SectionBase *S)
Definition: ELFObject.h:600
llvm::objcopy::elf::IHexELFBuilder
Definition: ELFObject.h:937
llvm::objcopy::elf::GroupSection::classof
static bool classof(const SectionBase *S)
Definition: ELFObject.h:838
llvm::objcopy::elf::IHexReader::create
Expected< std::unique_ptr< Object > > create(bool EnsureSymtab) const override
Definition: ELFObject.cpp:1945
ArrayRef.h
llvm::objcopy::elf::SectionVisitor::visit
virtual Error visit(const Section &Sec)=0
llvm::objcopy::elf::Reader::~Reader
virtual ~Reader()
llvm::make_pointee_range
iterator_range< pointee_iterator< WrappedIteratorT > > make_pointee_range(RangeT &&Range)
Definition: iterator.h:336
llvm::objcopy::elf::Segment::OriginalOffset
uint64_t OriginalOffset
Definition: ELFObject.h:461
llvm::objcopy::elf::SectionWriter::Out
WritableMemoryBuffer & Out
Definition: ELFObject.h:109
llvm::objcopy::elf::BasicELFBuilder::addStrTab
StringTableSection * addStrTab()
Definition: ELFObject.cpp:1250
llvm::objcopy::elf::ELFT_ELF64BE
@ ELFT_ELF64BE
Definition: ELFObject.h:71
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::objcopy::elf::Symbol::Visibility
uint8_t Visibility
Definition: ELFObject.h:642
llvm::objcopy::elf::SymbolTableSection::SymbolTableSection
SymbolTableSection()
Definition: ELFObject.h:695
llvm::objcopy::elf::Segment::Segment
Segment(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:466
llvm::objcopy::elf::BasicELFBuilder::addSymTab
SymbolTableSection * addSymTab(StringTableSection *StrTab)
Definition: ELFObject.cpp:1258
llvm::objcopy::elf::IHexRecord::HexData
StringRef HexData
Definition: ELFObject.h:202
llvm::objcopy::elf::IHexWriter::write
Error write() override
Definition: ELFObject.cpp:2706
llvm::objcopy::elf::BinaryELFBuilder::BinaryELFBuilder
BinaryELFBuilder(MemoryBuffer *MB, uint8_t NewSymbolVisibility)
Definition: ELFObject.h:931
llvm::objcopy::elf::RelocationSection::removeSectionReferences
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:880
llvm::objcopy::elf::Object::Type
uint32_t Type
Definition: ELFObject.h:1049
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::objcopy::elf::CompressedSection::accept
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:570
llvm::objcopy::elf::SectionTableRef::iterator
pointee_iterator< const std::unique_ptr< SectionBase > * > iterator
Definition: ELFObject.h:54
llvm::objcopy::elf::MutableSectionVisitor
Definition: ELFObject.h:90
llvm::objcopy::elf::ELFT_ELF32LE
@ ELFT_ELF32LE
Definition: ELFObject.h:71
llvm::objcopy::elf::CompressedSection::getDecompressedSize
uint64_t getDecompressedSize() const
Definition: ELFObject.h:550
llvm::objcopy::elf::SymbolTableSection
Definition: ELFObject.h:681
llvm::ELF::SHT_RELA
@ SHT_RELA
Definition: ELF.h:958
llvm::objcopy::elf::Object::ProgramHdrSegment
Segment ProgramHdrSegment
Definition: ELFObject.h:1043
llvm::objcopy::elf::Relocation::Addend
uint64_t Addend
Definition: ELFObject.h:732
llvm::objcopy::elf::SectionIndexSection::reserve
void reserve(size_t NumSymbols)
Definition: ELFObject.h:663
llvm::objcopy::elf::Segment::Offset
uint64_t Offset
Definition: ELFObject.h:453
llvm::irsymtab::storage::Word
support::ulittle32_t Word
Definition: IRSymtab.h:52
llvm::objcopy::elf::StringTableSection::addString
void addString(StringRef Name)
Definition: ELFObject.cpp:578
llvm::objcopy::elf::GroupSection::setSymTab
void setSymTab(const SymbolTableSection *SymTabSec)
Definition: ELFObject.h:821
llvm::objcopy::elf::Object::segments
ConstRange< Segment > segments() const
Definition: ELFObject.h:1080
llvm::objcopy::elf::DynamicSection::DynamicSection
DynamicSection(ArrayRef< uint8_t > Data)
Definition: ELFObject.h:854
llvm::objcopy::elf::RelocationSection::classof
static bool classof(const SectionBase *S)
Definition: ELFObject.h:797
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::objcopy::elf::Object::MustBeRelocatable
bool MustBeRelocatable
Definition: ELFObject.h:1055
llvm::DebugCompressionType
DebugCompressionType
Definition: MCTargetOptions.h:28
llvm::objcopy::elf::SYMBOL_HEXAGON_SCOMMON
@ SYMBOL_HEXAGON_SCOMMON
Definition: ELFObject.h:617
llvm::ELF::SHN_HEXAGON_SCOMMON_8
@ SHN_HEXAGON_SCOMMON_8
Definition: ELF.h:648
llvm::objcopy::elf::SymbolTableSection::empty
bool empty() const
Definition: ELFObject.h:702
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::object::Binary
Definition: Binary.h:32
llvm::objcopy::elf::BinaryWriter::write
Error write() override
Definition: ELFObject.cpp:2628
llvm::objcopy::elf::Symbol::Index
uint32_t Index
Definition: ELFObject.h:636
uint32_t
llvm::objcopy::elf::ELFBuilder::build
Error build(bool EnsureSymtab)
Definition: ELFObject.cpp:1881
llvm::objcopy::elf::IHexSectionWriter
Definition: ELFObject.h:299
llvm::objcopy::elf::Symbol::Binding
uint8_t Binding
Definition: ELFObject.h:633
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::objcopy::elf::GroupSection::finalize
void finalize() override
Definition: ELFObject.cpp:1055
llvm::objcopy::elf::SYMBOL_HIPROC
@ SYMBOL_HIPROC
Definition: ELFObject.h:626
llvm::objcopy::elf::SectionBase::Link
uint64_t Link
Definition: ELFObject.h:407
llvm::objcopy::elf::ELFBuilder
Definition: ELFObject.h:948
llvm::objcopy::elf::GroupSection::setSymbol
void setSymbol(Symbol *S)
Definition: ELFObject.h:822
llvm::objcopy::elf::BasicELFBuilder::initFileHeader
void initFileHeader()
Definition: ELFObject.cpp:1238
llvm::make_filter_range
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:534
llvm::objcopy::elf::SectionBase::OriginalType
uint64_t OriginalType
Definition: ELFObject.h:399
llvm::ELF::SHT_GROUP
@ SHT_GROUP
Definition: ELF.h:969
llvm::objcopy::elf::IHexSectionWriterBase::Offset
uint64_t Offset
Definition: ELFObject.h:281
ELFObjectFile.h
MAKE_SEC_WRITER_FRIEND
#define MAKE_SEC_WRITER_FRIEND
Definition: ELFObject.h:171
llvm::objcopy::elf::ELFBuilder::ELFBuilder
ELFBuilder(const ELFObjectFile< ELFT > &ElfObj, Object &Obj, Optional< StringRef > ExtractPartition)
Definition: ELFObject.cpp:1377
llvm::find_if
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:1644
llvm::objcopy::elf::Symbol::Name
std::string Name
Definition: ELFObject.h:637
llvm::objcopy::elf::IHexRecord::Type
uint16_t Type
Definition: ELFObject.h:200
llvm::objcopy::elf::GroupSection::markSymbols
void markSymbols() override
Definition: ELFObject.cpp:1091
llvm::objcopy::elf::SectionIndexSection::accept
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:629
llvm::objcopy::elf::SymbolTableSection::updateSymbols
void updateSymbols(function_ref< void(Symbol &)> Callable)
Definition: ELFObject.cpp:742
llvm::objcopy::elf::IHexSectionWriter::visit
Error visit(const StringTableSection &Sec) override
Definition: ELFObject.cpp:416
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::ELF::SHN_HIOS
@ SHN_HIOS
Definition: ELF.h:945
llvm::objcopy::elf::Segment::Flags
uint32_t Flags
Definition: ELFObject.h:452
llvm::objcopy::elf::StringTableSection
Definition: ELFObject.h:584
llvm::objcopy::elf::Object::sections
SectionTableRef sections() const
Definition: ELFObject.h:1062
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1239
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
std
Definition: BitVector.h:851
llvm::objcopy::elf::OwnedDataSection::accept
Error accept(SectionVisitor &Sec) const override
Definition: ELFObject.cpp:496
uint16_t
llvm::objcopy::elf::IHexSectionWriterBase
Definition: ELFObject.h:268
llvm::object::OwningBinary
Definition: RuntimeDyld.h:36
llvm::objcopy::elf::CompressedSection
Definition: ELFObject.h:536
llvm::objcopy::elf::Object::removeSections
Error removeSections(bool AllowBrokenLinks, std::function< bool(const SectionBase &)> ToRemove)
Definition: ELFObject.cpp:2148
llvm::objcopy::elf::Relocation::Offset
uint64_t Offset
Definition: ELFObject.h:731
llvm::objcopy::elf::IHexRecord::Data
@ Data
Definition: ELFObject.h:233
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::objcopy::elf::IHexSectionWriter::writeData
void writeData(uint8_t Type, uint16_t Addr, ArrayRef< uint8_t > Data) override
Definition: ELFObject.cpp:409
llvm::objcopy::elf::SymbolTableSection::removeSectionReferences
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:725
llvm::objcopy::elf::SymbolTableSection::initialize
Error initialize(SectionTableRef SecTable) override
Definition: ELFObject.cpp:769
llvm::objcopy::elf::Writer::finalize
virtual Error finalize()=0
llvm::objcopy::elf::Segment::firstSection
const SectionBase * firstSection() const
Definition: ELFObject.h:469
llvm::ELF::SHT_REL
@ SHT_REL
Definition: ELF.h:963
llvm::objcopy::elf::StringTableSection::accept
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:595
llvm::objcopy::elf::Segment::Segment
Segment()=default
llvm::objcopy::elf::GroupSection::removeSymbols
Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove) override
Definition: ELFObject.cpp:1082
llvm::objcopy::elf::SYMBOL_XINDEX
@ SYMBOL_XINDEX
Definition: ELFObject.h:629
llvm::objcopy::elf::RelocSectionWithSymtabBase::RelocSectionWithSymtabBase
RelocSectionWithSymtabBase()=default
llvm::objcopy::elf::RelocSectionWithSymtabBase
Definition: ELFObject.h:763
llvm::objcopy::elf::IHexSectionWriterBase::writeData
virtual void writeData(uint8_t Type, uint16_t Addr, ArrayRef< uint8_t > Data)
Definition: ELFObject.cpp:379
llvm::objcopy::elf::Segment::Sections
std::set< const SectionBase *, SectionCompare > Sections
Definition: ELFObject.h:464
llvm::StringTableBuilder
Utility for building string tables with deduplicated suffixes.
Definition: StringTableBuilder.h:23
llvm::objcopy::elf::SectionIndexSection::setSymTab
void setSymTab(SymbolTableSection *SymTab)
Definition: ELFObject.h:667
llvm::objcopy::elf::ELFSectionWriter::visit
Error visit(const SymbolTableSection &Sec) override
Definition: ELFObject.cpp:845
llvm::objcopy::elf::GroupSection::setFlagWord
void setFlagWord(ELF::Elf32_Word W)
Definition: ELFObject.h:823
llvm::objcopy::elf::RelocationSection::accept
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:976
llvm::objcopy::elf::ElfType
ElfType
Definition: ELFObject.h:71
llvm::objcopy::elf::SectionBase::Info
uint64_t Info
Definition: ELFObject.h:406
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
llvm::ELF::SHT_DYNSYM
@ SHT_DYNSYM
Definition: ELF.h:965
llvm::objcopy::elf::RelocationSectionBase::classof
static bool classof(const SectionBase *S)
Definition: ELFObject.h:755
llvm::objcopy::elf::SectionBase::onRemove
virtual void onRemove()
Definition: ELFObject.cpp:65
llvm::objcopy::elf::RelocSectionWithSymtabBase::Symbols
SymTabType * Symbols
Definition: ELFObject.h:769
llvm::objcopy::elf::RelocationSectionBase::setSection
void setSection(SectionBase *Sec)
Definition: ELFObject.h:751
llvm::objcopy::elf::SymbolTableSection::SymPtr
std::unique_ptr< Symbol > SymPtr
Definition: ELFObject.h:692
llvm::ELF::SHN_UNDEF
@ SHN_UNDEF
Definition: ELF.h:940
llvm::objcopy::elf::RelocationSection::replaceSectionReferences
void replaceSectionReferences(const DenseMap< SectionBase *, SectionBase * > &FromTo) override
Definition: ELFObject.cpp:1001
llvm::objcopy::elf::SectionBase
Definition: ELFObject.h:390
llvm::objcopy::elf::Object::OSABI
uint8_t OSABI
Definition: ELFObject.h:1045
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:955
llvm::objcopy::elf::IHexRecord::getLineLength
static size_t getLineLength(size_t DataSize)
Definition: ELFObject.h:212
llvm::objcopy::elf::SYMBOL_AMDGPU_LDS
@ SYMBOL_AMDGPU_LDS
Definition: ELFObject.h:616
llvm::objcopy::elf::DynamicSymbolTableSection::classof
static bool classof(const SectionBase *S)
Definition: ELFObject.h:847
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::objcopy::elf::OwnedDataSection::hasContents
bool hasContents() const override
Definition: ELFObject.h:533
llvm::objcopy::elf::SectionBase::Size
uint64_t Size
Definition: ELFObject.h:410
llvm::objcopy::elf::SectionBase::ParentSegment
Segment * ParentSegment
Definition: ELFObject.h:393
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::objcopy::elf::SymbolTableSection::getSymbolByIndex
Expected< const Symbol * > getSymbolByIndex(uint32_t Index) const
Definition: ELFObject.cpp:828
llvm::objcopy::elf::IHexRecord::InvalidType
@ InvalidType
Definition: ELFObject.h:261
llvm::ELF::SHN_MIPS_SCOMMON
@ SHN_MIPS_SCOMMON
Definition: ELF.h:572
llvm::objcopy::elf::BasicELFBuilder::Obj
std::unique_ptr< Object > Obj
Definition: ELFObject.h:913
llvm::objcopy::elf::ELFSectionWriter
Definition: ELFObject.h:129
llvm::objcopy::elf::RelocationSection::getObject
const Object & getObject() const
Definition: ELFObject.h:795
llvm::objcopy::elf::Section::accept
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:424
llvm::objcopy::elf::Symbol::ShndxType
SymbolShndxType ShndxType
Definition: ELFObject.h:635
llvm::objcopy::elf::Object::IsMips64EL
bool IsMips64EL
Definition: ELFObject.h:1060
llvm::objcopy::elf::IHexRecord::parse
static Expected< IHexRecord > parse(StringRef Line)
Definition: ELFObject.cpp:298
llvm::objcopy::elf::SymbolTableSection::finalize
void finalize() override
Definition: ELFObject.cpp:785
llvm::objcopy::elf::RelocationSection::removeSymbols
Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove) override
Definition: ELFObject.cpp:984
llvm::objcopy::elf::Object::SymbolTable
SymbolTableSection * SymbolTable
Definition: ELFObject.h:1057
llvm::objcopy::elf::MutableSectionVisitor::visit
virtual Error visit(Section &Sec)=0
llvm::objcopy::elf::SectionBase::OriginalData
ArrayRef< uint8_t > OriginalData
Definition: ELFObject.h:412
llvm::objcopy::elf::RelocationSectionBase
Definition: ELFObject.h:745
llvm::objcopy::elf::IHexRecord::StartAddr80x86
@ StartAddr80x86
Definition: ELFObject.h:250
llvm::pointee_iterator
An iterator type that allows iterating over the pointees via some other iterator.
Definition: iterator.h:320
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::ELF::SHN_MIPS_DATA
@ SHN_MIPS_DATA
Definition: ELF.h:571
llvm::objcopy::elf::DynamicRelocationSection::removeSectionReferences
Error removeSectionReferences(bool AllowBrokenLinks, function_ref< bool(const SectionBase *)> ToRemove) override
Definition: ELFObject.cpp:1021
llvm::objcopy::elf::BinaryWriter
Definition: ELFObject.h:358
llvm::objcopy::elf::Object::removedSections
SectionTableRef removedSections()
Definition: ELFObject.h:1078
llvm::objcopy::elf::SectionTableRef::end
iterator end() const
Definition: ELFObject.h:61
llvm::WritableMemoryBuffer
This class is an extension of MemoryBuffer, which allows copy-on-write access to the underlying conte...
Definition: MemoryBuffer.h:169
llvm::objcopy::elf::Section::initialize
Error initialize(SectionTableRef SecTable) override
Definition: ELFObject.cpp:1110
llvm::objcopy::elf::SymbolTableSection::SectionIndexTable
SectionIndexSection * SectionIndexTable
Definition: ELFObject.h:690
llvm::objcopy::elf::Object::getUpdatedSections
const auto & getUpdatedSections() const
Definition: ELFObject.h:1070
llvm::object::ELFObjectFile
Definition: ELFObjectFile.h:240
llvm::objcopy::elf::Object::SHOff
uint64_t SHOff
Definition: ELFObject.h:1048
llvm::objcopy::elf::IHexSectionWriter::IHexSectionWriter
IHexSectionWriter(WritableMemoryBuffer &Buf)
Definition: ELFObject.h:301
llvm::objcopy::elf::IHexRecord::getLine
static IHexLineData getLine(uint8_t Type, uint16_t Addr, ArrayRef< uint8_t > Data)
Definition: ELFObject.cpp:216
llvm::objcopy::elf::SymbolTableSection::accept
Error accept(SectionVisitor &Visitor) const override
Definition: ELFObject.cpp:861
llvm::objcopy::elf::BinaryELFBuilder::build
Expected< std::unique_ptr< Object > > build()
Definition: ELFObject.cpp:1304
llvm::objcopy::elf::SectionIndexSection::addIndex
void addIndex(uint32_t Index)
Definition: ELFObject.h:658
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::object::ELFFile
Definition: ELF.h:94
llvm::objcopy::elf::SectionBase::HeaderOffset
uint64_t HeaderOffset
Definition: ELFObject.h:394
llvm::objcopy::elf::OwnedDataSection::OwnedDataSection
OwnedDataSection(SectionBase &S, ArrayRef< uint8_t > Data)
Definition: ELFObject.h:525
llvm::objcopy::elf::SYMBOL_MIPS_SUNDEFINED
@ SYMBOL_MIPS_SUNDEFINED
Definition: ELFObject.h:625
llvm::objcopy::elf::SYMBOL_HEXAGON_SCOMMON_8
@ SYMBOL_HEXAGON_SCOMMON_8
Definition: ELFObject.h:620
llvm::objcopy::elf::Symbol::isCommon
bool isCommon() const
Definition: ELFObject.cpp:692
Shdr
Elf_Shdr Shdr
Definition: ELFObjHandler.cpp:77
llvm::objcopy::elf::Symbol::Referenced
bool Referenced
Definition: ELFObject.h:643
llvm::objcopy::elf::SymbolTableSection::replaceSectionReferences
void replaceSectionReferences(const DenseMap< SectionBase *, SectionBase * > &FromTo) override
Definition: ELFObject.cpp:762
llvm::objcopy::elf::IHexSectionWriterBase::visit
Error visit(const Section &Sec) final
Definition: ELFObject.cpp:384
llvm::objcopy::elf::IHexWriter::IHexWriter
IHexWriter(Object &Obj, raw_ostream &Out)
Definition: ELFObject.h:387
llvm::objcopy::elf::Segment::removeSection
void removeSection(const SectionBase *Sec)
Definition: ELFObject.h:475
llvm::objcopy::elf::ELFWriter::WriteSectionHeaders
bool WriteSectionHeaders
Definition: ELFObject.h:347