<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi John,</p>
<p>Thanks for the suggestion, will definitely try it out, seems like
the cleanest and least invasive way to do this.<br>
</p>
<p>Though, I feel like this should also be possible with statically
linking the ExecutionEngine into the plugin shared object.</p>
<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="moz-cite-prefix">On 4/18/19 7:38 PM, John Brawn wrote:<br>
</div>
<blockquote type="cite"
cite="mid:DB7PR08MB32735761F6381E670E6B31C38E260@DB7PR08MB3273.eurprd08.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 14 (filtered
medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]-->
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:"Arial Narrow";
panose-1:2 11 6 6 2 2 2 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;
mso-fareast-language:EN-GB;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The
fundamental problem here is that opt doesn’t use
ExecutionEngine (because it has no need to), so trying<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">to
use ExecutionEngine (or any other bit of llvm that opt
doesn’t use for that matter) in an opt plugin isn’t<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">going
to work.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The
solution I’d go with would be to build llvm with shared
libraries (use –DBUILD_SHARED_LIBS=ON on the<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">cmake
command) then link the plugin against ExecutionEngine. That
shouldn’t require any changes anywhere<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">(when
I gave it a quick try it seemed to work).<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">John<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm
0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF
1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif""
lang="EN-US">From:</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif""
lang="EN-US"> llvm-dev
[<a class="moz-txt-link-freetext" href="mailto:llvm-dev-bounces@lists.llvm.org">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<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Below is the modifications I made:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Modified Hello.cpp for testing:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> bool runOnFunction(Function
&F) override {<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> ++HelloCounter;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> std::string errStr;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> EngineBuilder eb;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> eb.setErrorStr(&errStr);<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">
eb.setEngineKind(EngineKind::Kind::JIT);<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> ExecutionEngine*
ee=eb.create();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">
errs()<<"ExecutionEngine:"<<ee<<"
Error:"<<errStr<<"\n";<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> delete ee;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> errs() << "Hello: ";<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">
errs().write_escaped(F.getName()) << '\n';<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> return false;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> }<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Modified opt's CMakeLists.txt:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">set(LLVM_LINK_COMPONENTS<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> ${LLVM_TARGETS_TO_BUILD}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> AggressiveInstCombine<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Analysis<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> BitWriter<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> CodeGen<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Core<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> MC<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> MCJIT<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Object<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> OrcJIT<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Interpreter<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> RuntimeDyld<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Coroutines<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> IPO<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> IRReader<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> InstCombine<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Instrumentation<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> MC<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> ObjCARCOpts<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> ScalarOpts<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Support<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Target<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> TransformUtils<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Vectorize<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Passes<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> ExecutionEngine<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> )<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"># Support plugins.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">set(LLVM_NO_DEAD_STRIP 1)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">add_llvm_tool(opt<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> AnalysisWrappers.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> BreakpointPrinter.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Debugify.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> GraphPrinters.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> NewPMDriver.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> PassPrinters.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> PrintSCC.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> opt.cpp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> DEPENDS<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> intrinsics_gen<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> )<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">export_executable_symbols(opt)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">if(WITH_POLLY AND
LINK_POLLY_INTO_TOOLS)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> target_link_libraries(opt PRIVATE
Polly)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">endif(WITH_POLLY AND
LINK_POLLY_INTO_TOOLS)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">target_link_libraries(opt PUBLIC
LLVMExecutionEngine)<o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Modified opt's LLVMBuild.txt:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">;===- ./tools/opt/LLVMBuild.txt
--------------------------------*- Conf -*--===;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">; The LLVM
Compiler Infrastructure<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">; This file is distributed under the
University of Illinois Open Source<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">; License. See LICENSE.TXT for
details.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;===------------------------------------------------------------------------===;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">; This is an LLVMBuild description
file for the components in this subdirectory.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">; For more information on the
LLVMBuild system, please see:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;
<a class="moz-txt-link-freetext" href="http://llvm.org/docs/LLVMBuild.html">http://llvm.org/docs/LLVMBuild.html</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">;===------------------------------------------------------------------------===;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">[component_0]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">type = Tool<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">name = opt<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">parent = Tools<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">required_libraries =<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> AsmParser<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> BitReader<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> BitWriter<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> CodeGen<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> IRReader<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> IPO<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Instrumentation<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Scalar<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> ObjCARC<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Passes<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> ExecutionEngine<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Interpreter<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> MCJIT<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> Native<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> NativeCodeGen<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> all-targets<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> if(argc==-1){<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> EngineBuilder eb;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> ExecutionEngine* ee=eb.create();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> delete ee;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> }<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">as well as force linking MCJIT and
Interpreter by including headers in opt:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">#include
"llvm/ExecutionEngine/ExecutionEngine.h"<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">#include
"llvm/ExecutionEngine/Interpreter.h"<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">#include
"llvm/ExecutionEngine/MCJIT.h"<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Moving cl::parseCommandLineOptions
doesn't seem to be related to the issue, my previous
assumption was wrong.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Those modifications works at least on
my setup with the following output:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">λ : >>> bin/opt -load
lib/LLVMHello.dylib hw.ll -hello<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">WARNING: You're attempting to print
out a bitcode file.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">This is inadvisable as it may cause
display problems. If<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">you REALLY want to taste LLVM bitcode
first-hand, you<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">can force output with the `-f'
option.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Zhang<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Arial
Narrow","sans-serif";color:black">------------------ Original ------------------<o:p></o:p></span></p>
</div>
<div>
<div id="menu_sender">
<p class="MsoNormal" style="background:#EFEFEF"><b><span
style="font-size:9.0pt;color:black">From:
</span></b><span
style="font-size:9.0pt;color:black"> "Zhang via
llvm-dev"<a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org"><llvm-dev@lists.llvm.org></a>;<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:#EFEFEF"><b><span
style="font-size:9.0pt;color:black">Date:
</span></b><span
style="font-size:9.0pt;color:black"> Wed, Apr 17,
2019 04:35 AM<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:#EFEFEF"><b><span
style="font-size:9.0pt;color:black">To:
</span></b><span
style="font-size:9.0pt;color:black"> "Viktor Was
BSc"<a class="moz-txt-link-rfc2396E" href="mailto:gs15m015@technikum-wien.at"><gs15m015@technikum-wien.at></a>;
"llvm-dev"<a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org"><llvm-dev@lists.llvm.org></a>;
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:#EFEFEF"><b><span
style="font-size:9.0pt;color:black">Subject:
</span></b><span
style="font-size:9.0pt;color:black"> Re:
[llvm-dev] Opt plugin linkage<o:p></o:p></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="color:black">Hey:<o:p></o:p></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,<o:p></o:p></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<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Zhang<o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Arial
Narrow","sans-serif";color:black">------------------
Original ------------------<o:p></o:p></span></p>
</div>
<div>
<div id="menu_sender">
<p class="MsoNormal" style="background:#EFEFEF"><b><span
style="font-size:9.0pt;color:black">From:
</span></b><span
style="font-size:9.0pt;color:black"> "Viktor
Was BSc via
llvm-dev"<a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org"><llvm-dev@lists.llvm.org></a>;<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:#EFEFEF"><b><span
style="font-size:9.0pt;color:black">Date:
</span></b><span
style="font-size:9.0pt;color:black"> Wed,
Apr 17, 2019 03:09 AM<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:#EFEFEF"><b><span
style="font-size:9.0pt;color:black">To:
</span></b><span
style="font-size:9.0pt;color:black"> "llvm-dev"<a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org"><llvm-dev@lists.llvm.org></a>;
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:#EFEFEF"><b><span
style="font-size:9.0pt;color:black">Subject:
</span></b><span
style="font-size:9.0pt;color:black"> Re:
[llvm-dev] Opt plugin linkage<o:p></o:p></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></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.
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"
style="margin-bottom:12.0pt"><span
style="color:black">Also there is basically
no documentation for the custom cmake
commands.
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"
style="margin-bottom:12.0pt"><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?
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Thanks
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Viktor
<o:p></o:p></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" moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
wrote:<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="color:black">Hi,<o:p></o:p></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).<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">It
uses the ExecutionEngine.<o:p></o:p></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'."
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"
style="margin-bottom:12.0pt"><span
style="color:black">For a minimal example
add set(LLVM_LINK_COMPONENTS Core) to the
CMakeLists.txt of the Hello llvm pass.
<o:p></o:p></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.
<o:p></o:p></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?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"
style="margin-bottom:12.0pt"><span
style="color:black">How can I use the
EngineBuilder in my plugin with proper
symbol resolution?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">For
reproductivity:<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"
style="margin-bottom:12.0pt"><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<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Hope
someone can help me out.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Viktor<o:p></o:p></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="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" moz-do-not-send="true">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></span></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</body>
</html>