Elf Writer

References:

  • reference

    // class .member
    struct ELFWriter{
    ELFObjectWriter &OWriter;
    }
    
    // parent --> child
    MCObjectWriter
    -> ELFObjectWriter
    

States:

  • ELFObjectWriter &OWriter
  • support::endian::Writer W. An adapter to write values to a stream in a particular byte order.
  • unsigned LastLocalSymbolIndex. This holds the symbol table index of the last local symbol.
  • unsigned StringTableIndex. This holds the .strtab section index.
  • unsigned SymbolTableIndex. This holds the .symtabl section index.
  • std::vector<const MCSectionELF *> SectionTable. All the sections in order. They are to be output in the section table.

Interfaces:

// llvm/lib/MC/ELFObjectWriter.cpp

  void writeHeader(const MCAssembler &Asm);

  void writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
                   ELFSymbolData &MSD, const MCAsmLayout &Layout);

  /// Compute the symbol table data
  ///
  /// \param Asm - The assembler.
  /// \param SectionIndexMap - Maps a section to its index.
  /// \param RevGroupMap - Maps a signature symbol to the group section.
  void computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
                          const SectionIndexMapTy &SectionIndexMap,
                          const RevGroupMapTy &RevGroupMap,
                          SectionOffsetsTy &SectionOffsets);

  MCSectionELF *createRelocationSection(MCContext &Ctx,
                                        const MCSectionELF &Sec);

  const MCSectionELF *createStringTable(MCContext &Ctx);

  void writeSectionHeader(const MCAsmLayout &Layout,
                          const SectionIndexMapTy &SectionIndexMap,
                          const SectionOffsetsTy &SectionOffsets);

  void writeSectionData(const MCAssembler &Asm, MCSection &Sec,
                        const MCAsmLayout &Layout);

  void WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
                        uint64_t Address, uint64_t Offset, uint64_t Size,
                        uint32_t Link, uint32_t Info, uint64_t Alignment,
                        uint64_t EntrySize);

  void writeRelocations(const MCAssembler &Asm, const MCSectionELF &Sec);

  uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout);
  void writeSection(const SectionIndexMapTy &SectionIndexMap,
                    uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size,
                    const MCSectionELF &Section);

More

  • Elf Object Writer
  • References: [LLVM source code (version 11)] Inheritance/Member relation // parent --> child MCObjectWriter -> ELFObjectWriter // class .member struct ELFWriter{ ELFObjectWriter &OWriter; } States: // llvm/lib/MC/ELFObjectWriter.cpp classELFObjectWriter : public MCObjectWriter { /// The target specific ELF writer instance. std::unique_ptr<MCELFObjectTargetWriter> TargetObjectWriter; DenseMap<const MCSectionELF *, std::vector<ELFRelocationEntry>> Relocations; DenseMap<const MCSymbolELF *, const MCSymbolELF *> Renames; bool EmitAddrsigSection = false; std::vector<const MCSymbol *> AddrsigSyms; // ... friend struct ELFWriter; }; Interfaces:

Created Aug 15, 2020 // Last Updated May 18, 2021

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?