<div dir="ltr"><div class="gmail_quote"><div>Hi Viktor, </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><p>Though, I feel like this should also be possible with statically
linking the ExecutionEngine into the plugin shared object.</p></div></blockquote><div>Unfortunately it won't. In general, you don't link any LLVM libraries into opt plugins because opt already has all the symbols you need. If you were to link in the libraries, all sorts of problems arise, most of them because we have lot's of global state everywhere. With dynamic linking, most of the problems can be avoided because the dependencies won't be loaded twice.</div><div><br></div><div>Cheers,</div><div>Philip</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF">
<p>I don't quite understand how the concrete Interpreter/MCJIT
linking via llvm/ExecutionEngine/Interpreter.h and
llvm/ExecutionEngine/MCJIT.h works. So far I was only using
ExecutionEngine.h without Interpreter or MCJIT, so that could have
been the problem why static linking didn't work.<br>
</p>
<p>After playing around with Zhangs solution I've found out that I
get the same undefined symbol to llvm::EngineBuilder error when
omitting the MCJIT header and lib (since I actually only need an
interpreter), my guess is that this is due to Interpreter.h
missing the getenv trick used in MCJIT.h to prevent it being
optimized away by the compiler? I might take a closer look at this
at some point, right now I'm just happy to finally be able to work
on my opt pass.<br>
</p>
<p><br>
</p>
<p>Thanks,</p>
<p>Viktor<br>
</p>
<p><br>
</p>
<div class="gmail-m_6517503528706480469moz-cite-prefix">On 4/18/19 7:38 PM, John Brawn wrote:<br>
</div>
<blockquote type="cite">
<div class="gmail-m_6517503528706480469WordSection1">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The
fundamental problem here is that opt doesn’t use
ExecutionEngine (because it has no need to), so trying<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">to
use ExecutionEngine (or any other bit of llvm that opt
doesn’t use for that matter) in an opt plugin isn’t<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">going
to work.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The
solution I’d go with would be to build llvm with shared
libraries (use –DBUILD_SHARED_LIBS=ON on the<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">cmake
command) then link the plugin against ExecutionEngine. That
shouldn’t require any changes anywhere<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">(when
I gave it a quick try it seemed to work).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">John<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10pt;font-family:Tahoma,sans-serif" lang="EN-US">From:</span></b><span style="font-size:10pt;font-family:Tahoma,sans-serif" lang="EN-US"> llvm-dev
[<a class="gmail-m_6517503528706480469moz-txt-link-freetext" href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">mailto:llvm-dev-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>Zhang via llvm-dev<br>
<b>Sent:</b> 16 April 2019 22:04<br>
<b>To:</b> Viktor Was BSc; llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] Opt plugin linkage<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Just another follow-up, seems like
ExecutionEngine is still not usable without editing
CMakeLists, on my setup I had to edit CMakeLists.txt as
well to get the example working.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Below is the modifications I made:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Modified Hello.cpp for testing:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> bool runOnFunction(Function
&F) override {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ++HelloCounter;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> std::string errStr;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> EngineBuilder eb;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> eb.setErrorStr(&errStr);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">
eb.setEngineKind(EngineKind::Kind::JIT);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ExecutionEngine*
ee=eb.create();<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">
errs()<<"ExecutionEngine:"<<ee<<"
Error:"<<errStr<<"\n";<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> delete ee;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> errs() << "Hello: ";<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">
errs().write_escaped(F.getName()) << '\n';<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> return false;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> }<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Modified opt's CMakeLists.txt:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">set(LLVM_LINK_COMPONENTS<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ${LLVM_TARGETS_TO_BUILD}<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> AggressiveInstCombine<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Analysis<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> BitWriter<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> CodeGen<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Core<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> MC<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> MCJIT<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Object<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> OrcJIT<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Interpreter<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> RuntimeDyld<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Coroutines<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> IPO<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> IRReader<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> InstCombine<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Instrumentation<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> MC<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ObjCARCOpts<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ScalarOpts<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Support<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Target<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> TransformUtils<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Vectorize<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Passes<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ExecutionEngine<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> )<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Support plugins.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">set(LLVM_NO_DEAD_STRIP 1)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">add_llvm_tool(opt<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> AnalysisWrappers.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> BreakpointPrinter.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Debugify.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> GraphPrinters.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> NewPMDriver.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> PassPrinters.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> PrintSCC.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> opt.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> DEPENDS<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> intrinsics_gen<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> )<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">export_executable_symbols(opt)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">if(WITH_POLLY AND
LINK_POLLY_INTO_TOOLS)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> target_link_libraries(opt PRIVATE
Polly)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">endif(WITH_POLLY AND
LINK_POLLY_INTO_TOOLS)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">target_link_libraries(opt PUBLIC
LLVMExecutionEngine)<u></u><u></u></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Modified opt's LLVMBuild.txt:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">;===- ./tools/opt/LLVMBuild.txt
--------------------------------*- Conf -*--===;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">; The LLVM
Compiler Infrastructure<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">; This file is distributed under the
University of Illinois Open Source<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">; License. See LICENSE.TXT for
details.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;===------------------------------------------------------------------------===;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">; This is an LLVMBuild description
file for the components in this subdirectory.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">; For more information on the
LLVMBuild system, please see:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;
<a class="gmail-m_6517503528706480469moz-txt-link-freetext" href="http://llvm.org/docs/LLVMBuild.html" target="_blank">http://llvm.org/docs/LLVMBuild.html</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">;===------------------------------------------------------------------------===;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">[component_0]<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">type = Tool<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">name = opt<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">parent = Tools<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">required_libraries =<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> AsmParser<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> BitReader<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> BitWriter<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> CodeGen<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> IRReader<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> IPO<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Instrumentation<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Scalar<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ObjCARC<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Passes<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ExecutionEngine<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Interpreter<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> MCJIT<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Native<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> NativeCodeGen<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> all-targets<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">On top of that I also added these lines
to the beginning of main function in opt.cpp to force
linking ExecutionEngine:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> if(argc==-1){<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> EngineBuilder eb;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ExecutionEngine* ee=eb.create();<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> delete ee;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> }<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">as well as force linking MCJIT and
Interpreter by including headers in opt:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">#include
"llvm/ExecutionEngine/ExecutionEngine.h"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">#include
"llvm/ExecutionEngine/Interpreter.h"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">#include
"llvm/ExecutionEngine/MCJIT.h"<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Moving cl::parseCommandLineOptions
doesn't seem to be related to the issue, my previous
assumption was wrong.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Those modifications works at least on
my setup with the following output:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">λ : >>> bin/opt -load
lib/LLVMHello.dylib hw.ll -hello<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">WARNING: You're attempting to print
out a bitcode file.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">This is inadvisable as it may cause
display problems. If<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">you REALLY want to taste LLVM bitcode
first-hand, you<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">can force output with the `-f'
option.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Assertion failed: (M &&
"Module is null?"), function Init, file
/Users/naville/Development/Hikari/lib/ExecutionEngine/ExecutionEngine.cpp,
line 80.<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Which is due to i didn't initialize the
EEBuilder properly, but at least the pass now loads and
executes properly<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Zhang<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"><span>------------------ Original ------------------<u></u><u></u></span></p>
</div>
<div>
<div id="gmail-m_6517503528706480469menu_sender">
<p class="MsoNormal" style="background:rgb(239,239,239)"><b><span style="font-size:9pt;color:black">From:
</span></b><span style="font-size:9pt;color:black"> "Zhang via
llvm-dev"<a class="gmail-m_6517503528706480469moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org" target="_blank"><llvm-dev@lists.llvm.org></a>;<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="background:rgb(239,239,239)"><b><span style="font-size:9pt;color:black">Date:
</span></b><span style="font-size:9pt;color:black"> Wed, Apr 17,
2019 04:35 AM<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="background:rgb(239,239,239)"><b><span style="font-size:9pt;color:black">To:
</span></b><span style="font-size:9pt;color:black"> "Viktor Was
BSc"<a class="gmail-m_6517503528706480469moz-txt-link-rfc2396E" href="mailto:gs15m015@technikum-wien.at" target="_blank"><gs15m015@technikum-wien.at></a>;
"llvm-dev"<a class="gmail-m_6517503528706480469moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org" target="_blank"><llvm-dev@lists.llvm.org></a>;
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="background:rgb(239,239,239)"><b><span style="font-size:9pt;color:black">Subject:
</span></b><span style="font-size:9pt;color:black"> Re:
[llvm-dev] Opt plugin linkage<u></u><u></u></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="color:black">Hey:<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">I spent
sometime debugging this, it seems like editing
``llvm/tools/opt.cpp`` and move
``cl::ParseCommandLineOptions(argc, argv,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">
"llvm .bc -> .bc modular optimizer and analysis
printer\n");`` to the beginning of main() solved
it for me. I'm not sure if this is a bug on LLVM
side<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Zhang<u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span>------------------
Original ------------------<u></u><u></u></span></p>
</div>
<div>
<div id="gmail-m_6517503528706480469menu_sender">
<p class="MsoNormal" style="background:rgb(239,239,239)"><b><span style="font-size:9pt;color:black">From:
</span></b><span style="font-size:9pt;color:black"> "Viktor
Was BSc via
llvm-dev"<a class="gmail-m_6517503528706480469moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org" target="_blank"><llvm-dev@lists.llvm.org></a>;<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="background:rgb(239,239,239)"><b><span style="font-size:9pt;color:black">Date:
</span></b><span style="font-size:9pt;color:black"> Wed,
Apr 17, 2019 03:09 AM<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="background:rgb(239,239,239)"><b><span style="font-size:9pt;color:black">To:
</span></b><span style="font-size:9pt;color:black"> "llvm-dev"<a class="gmail-m_6517503528706480469moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org" target="_blank"><llvm-dev@lists.llvm.org></a>;
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="background:rgb(239,239,239)"><b><span style="font-size:9pt;color:black">Subject:
</span></b><span style="font-size:9pt;color:black"> Re:
[llvm-dev] Opt plugin linkage<u></u><u></u></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="color:black">How
come the hello pass example is so totally
useless as a starting point? Why is this not
using any library/compontent which could
conflict with opt or clang and showing how
to handle this? I have no clue as to how I
have to setup llvm to get this to work or
why it doesn't work in the first place with
the setup described in "Getting started" and
"writing an llvm pass" pages etc.
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="color:black">Also there is basically
no documentation for the custom cmake
commands.
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="color:black">Can please somebody help
me with this issue? How do I get dynamically
loaded llvm pass plugins to work? Am I the
only one ever having this issue?
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Thanks
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Viktor
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">On
Apr 16, 2019, at 05:38, Viktor Was BSc via
llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>
wrote:<u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="color:black">Hi,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">I
have a dynamically loaded llvm pass built
in-tree with ninja (generated with cmake,
basically a copy of the hallo pass plugin,
linux, llvm/clang version 6.0.1).<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">It
uses the ExecutionEngine.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Building
it without linking against
LLVMExecutionEngine library results in an
undefined symbol to the vtable of the
EngineBuilder when loaded to opt. Linking
the plugin with LLVMExecutionEngine
results in the pass simply not being
executable with giving "opt: Unkown
command line argument '-passArg'."
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="color:black">For a minimal example
add set(LLVM_LINK_COMPONENTS Core) to the
CMakeLists.txt of the Hello llvm pass.
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">There
is no error or warning at any point when
linking or loading a plugin linked against
some libs.
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">How
do I find out which llvm libs I can't link
with a dynamically loaded plugin?<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="color:black">How can I use the
EngineBuilder in my plugin with proper
symbol resolution?<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">For
reproductivity:<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="color:black">cmake -G "Sublime Text
2 - Ninja"
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON
-DLLVM_BUILD_TESTS=ON
-DLLVM_BUILD_EXAMPLES=ON
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"
-DLLVM_TOOL_CLANG_BUILD=ON
-DLLVM_TOOL_CLANG_TOOLS_EXTRA=ON
-DLLVM_OPTIMIZED_TABLEGEN=ON
-DCLANG_BUILD_EXAMPLES=ON
-DCLANG_PLUGIN_SUPPORT=ON<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Hope
someone can help me out.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Viktor<u></u><u></u></span></p>
</div>
<pre style="text-align:center"><span style="color:black"><hr width="100%" size="2" align="center"></span></pre>
<pre><span style="color:black">
LLVM Developers mailing list
<a class="gmail-m_6517503528706480469moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></span></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>