<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 18, 2021, at 12:19 AM, DouglasChen[陳鍵源] <<a href="mailto:dougpuob@gmail.com" class="">dougpuob@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Min:<div class=""><br class=""></div><div class="">I am interested in your discussion, so I had it a try. Seem the option `-fpass-plugin=<path to plugin>` to clang brings the plugin to Clang Plugins(frontend). </div></div></div></blockquote><div><br class=""></div><div>A Clang plugin, <span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">which works on AST, custom pragma or attribute, is different from a LLVM pass plugin (works on LLVM IR). </span>This flag is designated for LLVM pass plugin. </div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">There is a comment around the keyword, -fpass-plugin, "Forward -fpass-plugin=name.so to -cc1". Did I understand it correctly?<div class=""><div class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><br class=""></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br class=""></div><div><font color="#000000" class="">The code you referenced is part of the clang driver, who simply relays `-fpass-plugin` flag to the frontend. The flag is eventually consumed by clang CodeGen at this palce: <span style="caret-color: rgb(0, 0, 0);" class=""><a href="https://github.com/llvm/llvm-project/blob/713ee230f884651afd17ab7b910e85a992ce406b/clang/lib/CodeGen/BackendUtil.cpp#L1321" class="">https://github.com/llvm/llvm-project/blob/713ee230f884651afd17ab7b910e85a992ce406b/clang/lib/CodeGen/BackendUtil.cpp#L1321</a> </span></font></div><div><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class="">Which uses `llvm::PassPlugin::Load` to load your custom pass plugin into the LLVM pass pipeline.</span></font></div><div><br class=""></div>Best,</div><div>-Min<br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><font face="arial, sans-serif" class="">-- Douglas Chen [陳鍵源]</font><br class=""></div></div></div></div></div></div></div><br class=""></div></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 17, 2021 at 2:56 PM Alberto Barbaro via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class=""><div class="">Hi Min-Yih,</div><div class="">thanks for your email. I have searched online on how to build clang plugins and I found [1]. I wanted to use the example that prints all the function names but, despite the fact that I followed the instructions, I could not compile it :)</div><div class=""><br class=""></div><div class="">I searched again and I found [2] and hopefully In this case I could build and run the basic hello-world example. I then tried to just replace the HelloWorld.cpp with the example that print the functions names but no luck. I compile but I have an error message. The following paragraph shows the entire test:</div><div class=""><br class=""></div><div class="">➜  build git:(main) ✗ make                                   <br class="">Scanning dependencies of target HelloWorld<br class="">[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o<br class="">[100%] Linking CXX shared library libHelloWorld.so<br class="">[100%] Built target HelloWorld<br class="">➜  build git:(main) ✗ clang-13 -cc1 -load ./libHelloWorld.so -plugin hello-world $CLANG_TUTOR_DIR/test/HelloWorld-basic.cpp<br class="">➜  build git:(main) ✗ $Clang_DIR/bin/clang -cc1 -load ./libHelloWorld.so -plugin hello-world $CLANG_TUTOR_DIR/test/HelloWorld-basic.cpp <br class="">(clang-tutor)  file: /home/alberto/Desktop/projects/llvm/clang-tutor//test/HelloWorld-basic.cpp<br class="">(clang-tutor)  count: 3<br class="">➜  build git:(main) ✗ cd ..    <br class="">➜  HelloWorld git:(main) ✗ wget <a href="https://raw.githubusercontent.com/llvm/llvm-project/main/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp" target="_blank" class="">https://raw.githubusercontent.com/llvm/llvm-project/main/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp</a><br class="">--2021-12-17 06:45:54--  <a href="https://raw.githubusercontent.com/llvm/llvm-project/main/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp" target="_blank" class="">https://raw.githubusercontent.com/llvm/llvm-project/main/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp</a><br class="">Resolving <a href="http://raw.githubusercontent.com/" target="_blank" class="">raw.githubusercontent.com</a> (<a href="http://raw.githubusercontent.com/" target="_blank" class="">raw.githubusercontent.com</a>)... 185.199.110.133, 185.199.109.133, 185.199.108.133, ...<br class="">Connecting to <a href="http://raw.githubusercontent.com/" target="_blank" class="">raw.githubusercontent.com</a> (<a href="http://raw.githubusercontent.com/" target="_blank" class="">raw.githubusercontent.com</a>)|185.199.110.133|:443... connected.<br class="">HTTP request sent, awaiting response... 200 OK<br class="">Length: 4504 (4.4K) [text/plain]<br class="">Saving to: ‘PrintFunctionNames.cpp’<br class=""><br class="">PrintFunctionNames.cp 100%[========================>]   4.40K  --.-KB/s    in 0s      <br class=""><br class="">2021-12-17 06:45:54 (11.3 MB/s) - ‘PrintFunctionNames.cpp’ saved [4504/4504]<br class=""><br class="">➜  HelloWorld git:(main) ✗ mv HelloWorld.cpp HelloWorld.cpp.backup<br class="">➜  HelloWorld git:(main) ✗ mv PrintFunctionNames.cpp HelloWorld.cpp        <br class="">➜  HelloWorld git:(main) ✗ rm -rf build <br class="">➜  HelloWorld git:(main) ✗ take build<br class="">➜  build git:(main) ✗ cmake ../                               <br class="">-- The C compiler identification is GNU 10.2.1<br class="">-- The CXX compiler identification is GNU 10.2.1<br class="">-- Detecting C compiler ABI info<br class="">-- Detecting C compiler ABI info - done<br class="">-- Check for working C compiler: /usr/bin/cc - skipped<br class="">-- Detecting C compile features<br class="">-- Detecting C compile features - done<br class="">-- Detecting CXX compiler ABI info<br class="">-- Detecting CXX compiler ABI info - done<br class="">-- Check for working CXX compiler: /usr/bin/c++ - skipped<br class="">-- Detecting CXX compile features<br class="">-- Detecting CXX compile features - done<br class="">-- Performing Test Terminfo_LINKABLE<br class="">-- Performing Test Terminfo_LINKABLE - Success<br class="">-- Found Terminfo: /usr/lib/x86_64-linux-gnu/libtinfo.so  <br class="">-- Found ZLIB: /usr/local/lib/libz.so (found version "1.2.11") <br class="">-- Configuring done<br class="">-- Generating done<br class="">-- Build files have been written to: /home/alberto/Desktop/progetti/llvm/clang-tutor/HelloWorld/build<br class="">➜  build git:(main) ✗ make                                    <br class="">Scanning dependencies of target HelloWorld<br class="">[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o<br class="">[100%] Linking CXX shared library libHelloWorld.so<br class="">[100%] Built target HelloWorld<br class="">➜  build git:(main) ✗ $Clang_DIR/bin/clang -cc1 -load ./libHelloWorld.so -plugin hello-world $CLANG_TUTOR_DIR/test/HelloWorld-basic.cpp<br class="">error: unable to find plugin 'hello-world'<br class="">➜  build git:(main) ✗</div><div class=""><br class=""></div><div class="">Any idea on how to solve it? I think a little github repo with an example on how to do it as standalone project would be beneficial to others as well.</div><div class=""><br class=""></div><div class="">Thanks a lot for all</div><div class="">Alberto<br class=""></div><div class=""><br class=""></div><div class="">[1] <a href="https://clang.llvm.org/docs/ClangPlugins.html" target="_blank" class="">https://clang.llvm.org/docs/ClangPlugins.html</a><br class=""></div><div class="">[2] <a href="https://github.com/banach-space/clang-tutor" target="_blank" class="">https://github.com/banach-space/clang-tutor</a></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno ven 17 dic 2021 alle ore 01:11 Min-Yih Hsu <<a href="mailto:minyihh@uci.edu" target="_blank" class="">minyihh@uci.edu</a>> ha scritto:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="">It’s a lot easier to load custom pass plugins into clang with the new PassManager actually:<div class="">```</div><div class="">clang -fpass-plugin=<path to plugin> ...</div><div class="">```</div><div class="">Note that <path to plugin> needs to be an absolute path.</div><div class=""><br class=""></div><div class="">-Min<br class=""><div class=""><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Dec 17, 2021, at 6:38 AM, Alberto Barbaro via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class=""><div class=""><div dir="auto" class="">Hi all,<div dir="auto" class="">Few days ago I have discovered the symcc[1] project. This project, via an llvm pass, is able to modify the IR code and to inject calls to a backend which allows symbolic execution. I can use it with clang/llvm 11 but not with the version 13. </div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">I was wondering if maybe the new pass manager uses llvm passes in a different way .. so I have created a small pass which injects a call to printf in each function and I'm able to use it via opt. Now my question is: is it possible to run the same pass via clang and just obtain the modified IR code? I'd like to avoid to use opt if not mandatory. Is it possible to do it or the new pass manager forces me to use opt?</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">How would you fix this situation in symcc?</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">If someone could tell me how to load a ModulePass in clang-13 would be great.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Thanks a lot</div><div dir="auto" class="">Alberto</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">[1] <a href="https://github.com/eurecom-s3/symcc" rel="noreferrer" target="_blank" class="">https://github.com/eurecom-s3/symcc</a><br class=""><div dir="auto" class=""><br class=""></div></div></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></blockquote></div>
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></body></html>