Index: include/llvm/MC/MCDisassembler/MCELFNoteDisassembler.h =================================================================== --- /dev/null +++ include/llvm/MC/MCDisassembler/MCELFNoteDisassembler.h @@ -0,0 +1,49 @@ +//===- llvm/MC/MCELFNoteDisassembler.h - MCELFNoteDisassembler class *- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains the declaration of the ELFNoteDisassembler class, which +// is used to disassemble the contents of a note from the ELF .note section. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_MC_MCDISASSEMBLER_MCELFNOTEDISASSEMBLER_H +#define LLVM_MC_MCDISASSEMBLER_MCELFNOTEDISASSEMBLER_H + +#include "llvm/ADT/StringRef.h" + +namespace llvm { + +class MCSubtargetInfo; +class MCTargetStreamer; +class Twine; + +class MCELFNoteDisassembler { +protected: + MCContext *Ctx; +public: + MCELFNoteDisassembler(MCContext &Ctx, const MCSubtargetInfo *STI) : Ctx(&Ctx) {} + + MCELFNoteDisassembler(const MCELFNoteDisassembler &) = delete; + MCELFNoteDisassembler &operator=(const MCELFNoteDisassembler &) = delete; + virtual ~MCELFNoteDisassembler() {} + + // Disassemble one note from the ELF .note section into an MCTargetStreamer, + // adding assembler directives that would assemble to the semantically + // equivalent note. + // Returns false if the note type is not recognized or disassembly fails. + // The .note record descriptor (i.e. contents) is passed as a StringRef of + // bytes as found in the ELF file, together with an indication of the + // endianness of the ELF file. + virtual bool disassembleNote(unsigned Type, StringRef Name, StringRef Desc, + support::endianness TargetEndianness, MCTargetStreamer *TS) = 0; +}; + +} // end namespace llvm + +#endif // LLVM_MC_MCDISASSEMBLER_MCELFNOTEDISASSEMBLER_H Index: include/llvm/Support/TargetRegistry.h =================================================================== --- include/llvm/Support/TargetRegistry.h +++ include/llvm/Support/TargetRegistry.h @@ -44,6 +44,7 @@ class MCCodeEmitter; class MCContext; class MCDisassembler; +class MCELFNoteDisassembler; class MCInstPrinter; class MCInstrAnalysis; class MCInstrInfo; @@ -192,6 +193,8 @@ LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr &&RelInfo); using ELFNoteDumperCtorTy = ELFNoteDumper *(*)(const Target &T); + using MCELFNoteDisassemblerCtorTy = MCELFNoteDisassembler *(*)(const Target &T, + MCContext &Ctx, const MCSubtargetInfo &STI); private: /// Next - The next registered target in the linked list, maintained by the @@ -292,6 +295,10 @@ /// ELF note dumper, if registered. ELFNoteDumperCtorTy ELFNoteDumperCtorFn = nullptr; + /// MCELFNoteDisassemblerCtorFn - Construction function for this target's + /// ELF note disassembler, if registered. + MCELFNoteDisassemblerCtorTy MCELFNoteDisassemblerCtorFn = nullptr; + public: Target() = default; @@ -594,6 +601,14 @@ return ELFNoteDumperCtorFn(*this); } + /// createMCELFNoteDisassembler - Create a target specific MCELFNoteDisassembler + MCELFNoteDisassembler *createMCELFNoteDisassembler(MCContext *Ctx, + const MCSubtargetInfo &STI) const { + if (!MCELFNoteDisassemblerCtorFn) + return nullptr; + return MCELFNoteDisassemblerCtorFn(*this, *Ctx, STI); + } + /// @} }; @@ -921,6 +936,20 @@ T.ELFNoteDumperCtorFn = Fn; } + /// RegisterMCELFNoteDisassembler - Register an MCELFNoteDisassembler + /// implementation for the given target. + /// + /// Clients are responsible for ensuring that registration doesn't occur + /// while another thread is attempting to access the registry. Typically + /// this is done by initializing all targets at program startup. + /// + /// @param T - The target being registered. + /// @param Fn - A function to construct an MCELFNoteDisassembler for the target. + static void RegisterMCELFNoteDisassembler(Target &T, + Target::MCELFNoteDisassemblerCtorTy Fn) { + T.MCELFNoteDisassemblerCtorFn = Fn; + } + /// @} };