解决llvm-9.0开启JIT EVENT后的编译错误'undefined reference to llvm::createLowerSwitchPass()'
程序员文章站
2022-06-22 16:16:48
...
解决llvm-9.0开启JIT EVENT后的编译错误’undefined reference to llvm::createLowerSwitchPass()’
开启JIT EVENT需要在cmake命令中增加-DLLVM_USE_OPROFILE=ON
,-DLLVM_USE_INTEL_JITEVENTS=ON
,-DLLVM_USE_PERF=ON
三个选项,但是不幸的是,在llvm-9.0版本,会在编译时报错,错误信息如下图:
根据编译器报错信息提示,找到文件’llvm/lib/ExecutionEngine/OProfileJIT/OProfileJITEventListener.cpp’, 然后如下修改:
104 uint64_t Addr = *AddrOrErr;
105 +++
106 +++
107 +++ //---------------FIX COMPILE ERROR
108 +++ auto SecOrErr = Sym.getSection();
109 +++ if (!SecOrErr) {
110 +++ // TODO: Actually report errors helpfully.
111 +++ consumeError(SecOrErr.takeError());
112 +++ continue;
113 +++ }
114 +++ object::section_iterator Sec = *SecOrErr;
115 +++ if (Sec == Obj.section_end())
116 +++ continue;
117 +++ uint64_t Index = Sec->getIndex();
118 +++ //---------------FIX COMPILE ERROR
119 +++
120 +++
121 uint64_t Size = P.second;
122
123 if (Wrapper->op_write_native_code(Name.data(), Addr, (void *)Addr, Size)
124 -1) {
125 LLVM_DEBUG(dbgs() << "Failed to tell OProfile about native function "
126 << Name << " at [" << (void *)Addr << "-"
127 << ((char *)Addr + Size) << "]\n");
128 continue;
129 }
130
131 +++ DILineInfoTable Lines = Context->getLineInfoForAddressRange({Addr,Index}, Size);
115 --- DILineInfoTable Lines = Context->getLineInfoForAddressRange(Addr, Size);
重新编译,即可解决编译的报错的问题