New Section

Reference reference

To emit a new section, e.g. .newsection, to an object (ELF) file:

  1. add an option to clang to enable options.

    • need to pass option from clang frontend to backend.
    • Option finally goes to TargetOptions::EmitNewSection
    • Option access in different classes:
      • via TargetMachine instance: TM.Options.EmitNewSection
        • Can be used in AsmPrinter, etc.
      • via MachineFunction instance: MF.getTarget().Options.EmitNewSection
  2. update AsmPrinter class in LLVM CodeGen to emit the new section. e.g. AsmPrinter::emitNewSection()

    • implement in llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  3. add target dependent interface in AsmPrinter for each target to implement the actual emission for the section. e.g. virtual void EmitNewSectionEntry();

    • impl for mips in llvm/lib/Target/Mips/MipsAsmPrinter.cpp
  4. add a new MCSection member, say MCSection *NewSection;, to MCObjectFileInfo class.

    • Also add the corresponding get methods: e.g. MCSection *getNewSection(){...}
  5. Update initialization code of MCObjectFileInfo to create the new section instance.

    • in MCObjectFileInfo::initELFMCObjectFileInfo():
      code: initELFMCObjectFileInfo()
  6. Register the section to the MCAssembler in MipsTargetELFStreamer::finish():

    register section

  7. Update DumpStyle class with new interface to print the new section; and implement it in the children class, such as GNUStyle, LLVMStyle, etc. // currently not used.

AsmPrinter::emitNewSection

Switch current section to the new section and emit the section entries one by one:

emitNewSection()
Created Jul 26, 2020 // Last Updated May 18, 2021

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

... what would you change?