[llvm-dev] LLVM target as loadable module

Ottet Loïc via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 18 05:57:42 PDT 2019


Hi,

I’m trying to implement a custom target for LLVM (version 6.0.1) based on the X86 target as a loadable module to use it with llc’s -load option. I have defined the module in the CMakeLists.txt file in the target folder as:

add_llvm_loadable_module(MyTarget ${sources}
  AsmParser/X86AsmInstrumentation.cpp
  AsmParser/X86AsmParser.cpp
  Disassembler/X86Disassembler.cpp
  Disassembler/X86DisassemblerDecoder.cpp
  InstPrinter/X86ATTInstPrinter.cpp
  InstPrinter/X86IntelInstPrinter.cpp
  InstPrinter/X86InstComments.cpp
  MCTargetDesc/X86AsmBackend.cpp
  MCTargetDesc/X86MCTargetDesc.cpp
  MCTargetDesc/X86MCAsmInfo.cpp
  MCTargetDesc/X86MCCodeEmitter.cpp
  MCTargetDesc/X86MachObjectWriter.cpp
  MCTargetDesc/X86ELFObjectWriter.cpp
  MCTargetDesc/X86WinCOFFObjectWriter.cpp
  MCTargetDesc/X86WinCOFFStreamer.cpp
  MCTargetDesc/X86WinCOFFTargetStreamer.cpp
  TargetInfo/X86TargetInfo.cpp
  Utils/X86ShuffleDecode.cpp
)

I also defined new versions of the LLVMInitializeMyTarget(AsmPrinter|Target|AsmParser|Disassembler|TargetMC|TargetInfo) functions. The shared module gets created, but when I load it into llc the target is not present in the list of loaded targets (from llc -version) and I cannot use it with -march=mytarget. However, when I use the llc binary that was compiled with my custom target, and load the module with it, I get errors because of duplicated options, meaning that the custom target is, in fact, loaded from the module in this case.

What am I missing here? The documentation I’ve been able to find on loadable modules seems to be targeted at previous versions of LLVM which use the LOADABLE_MODULE makefile value instead of the current cmake compilation pipeline.

Cheers,

Loïc


More information about the llvm-dev mailing list