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

class ELFObjectWriter : 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:

// llvm/lib/MC/ELFObjectWriter.cpp

class ELFObjectWriter : public MCObjectWriter {
  // ...
private:

  bool hasRelocationAddend() const;

  bool shouldRelocateWithSymbol(const MCAssembler &Asm,
                                const MCSymbolRefExpr *RefA,
                                const MCSymbolELF *Sym, uint64_t C,
                                unsigned Type) const;

public:
  void reset() override;

  bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
                                              const MCSymbol &SymA,
                                              const MCFragment &FB, bool InSet,
                                              bool IsPCRel) const override;

  virtual bool checkRelocation(MCContext &Ctx, SMLoc Loc,
                               const MCSectionELF *From,
                               const MCSectionELF *To) {
    return true;
  }

  void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
                        const MCFragment *Fragment, const MCFixup &Fixup,
                        MCValue Target, uint64_t &FixedValue) override;


};

More

Created Aug 15, 2020 // Last Updated Aug 15, 2020

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

... what would you change?