[llvm-dev] How to port symcc to clang/llvm-13?

Min-Yih Hsu via llvm-dev llvm-dev at lists.llvm.org
Fri Dec 17 17:06:19 PST 2021



> On Dec 18, 2021, at 12:19 AM, DouglasChen[陳鍵源] <dougpuob at gmail.com> wrote:
> 
> Hi Min:
> 
> 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).

A Clang plugin, which works on AST, custom pragma or attribute, is different from a LLVM pass plugin (works on LLVM IR). This flag is designated for LLVM pass plugin. 

> There is a comment around the keyword, -fpass-plugin, "Forward -fpass-plugin=name.so to -cc1". Did I understand it correctly?
> 

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: https://github.com/llvm/llvm-project/blob/713ee230f884651afd17ab7b910e85a992ce406b/clang/lib/CodeGen/BackendUtil.cpp#L1321 <https://github.com/llvm/llvm-project/blob/713ee230f884651afd17ab7b910e85a992ce406b/clang/lib/CodeGen/BackendUtil.cpp#L1321> 
Which uses `llvm::PassPlugin::Load` to load your custom pass plugin into the LLVM pass pipeline.

Best,
-Min
> -- Douglas Chen [陳鍵源]
> 
> 
> On Fri, Dec 17, 2021 at 2:56 PM Alberto Barbaro via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
> Hi Min-Yih,
> 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 :)
> 
> 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:
> 
> ➜  build git:(main) ✗ make                                   
> Scanning dependencies of target HelloWorld
> [ 50%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o
> [100%] Linking CXX shared library libHelloWorld.so
> [100%] Built target HelloWorld
> ➜  build git:(main) ✗ clang-13 -cc1 -load ./libHelloWorld.so -plugin hello-world $CLANG_TUTOR_DIR/test/HelloWorld-basic.cpp
> ➜  build git:(main) ✗ $Clang_DIR/bin/clang -cc1 -load ./libHelloWorld.so -plugin hello-world $CLANG_TUTOR_DIR/test/HelloWorld-basic.cpp 
> (clang-tutor)  file: /home/alberto/Desktop/projects/llvm/clang-tutor//test/HelloWorld-basic.cpp
> (clang-tutor)  count: 3
> ➜  build git:(main) ✗ cd ..    
> ➜  HelloWorld git:(main) ✗ wget https://raw.githubusercontent.com/llvm/llvm-project/main/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp <https://raw.githubusercontent.com/llvm/llvm-project/main/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp>
> --2021-12-17 06:45:54--  https://raw.githubusercontent.com/llvm/llvm-project/main/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp <https://raw.githubusercontent.com/llvm/llvm-project/main/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp>
> Resolving raw.githubusercontent.com <http://raw.githubusercontent.com/> (raw.githubusercontent.com <http://raw.githubusercontent.com/>)... 185.199.110.133, 185.199.109.133, 185.199.108.133, ...
> Connecting to raw.githubusercontent.com <http://raw.githubusercontent.com/> (raw.githubusercontent.com <http://raw.githubusercontent.com/>)|185.199.110.133|:443... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 4504 (4.4K) [text/plain]
> Saving to: ‘PrintFunctionNames.cpp’
> 
> PrintFunctionNames.cp 100%[========================>]   4.40K  --.-KB/s    in 0s      
> 
> 2021-12-17 06:45:54 (11.3 MB/s) - ‘PrintFunctionNames.cpp’ saved [4504/4504]
> 
> ➜  HelloWorld git:(main) ✗ mv HelloWorld.cpp HelloWorld.cpp.backup
> ➜  HelloWorld git:(main) ✗ mv PrintFunctionNames.cpp HelloWorld.cpp        
> ➜  HelloWorld git:(main) ✗ rm -rf build 
> ➜  HelloWorld git:(main) ✗ take build
> ➜  build git:(main) ✗ cmake ../                               
> -- The C compiler identification is GNU 10.2.1
> -- The CXX compiler identification is GNU 10.2.1
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Check for working C compiler: /usr/bin/cc - skipped
> -- Detecting C compile features
> -- Detecting C compile features - done
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Check for working CXX compiler: /usr/bin/c++ - skipped
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> -- Performing Test Terminfo_LINKABLE
> -- Performing Test Terminfo_LINKABLE - Success
> -- Found Terminfo: /usr/lib/x86_64-linux-gnu/libtinfo.so  
> -- Found ZLIB: /usr/local/lib/libz.so (found version "1.2.11") 
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /home/alberto/Desktop/progetti/llvm/clang-tutor/HelloWorld/build
> ➜  build git:(main) ✗ make                                    
> Scanning dependencies of target HelloWorld
> [ 50%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o
> [100%] Linking CXX shared library libHelloWorld.so
> [100%] Built target HelloWorld
> ➜  build git:(main) ✗ $Clang_DIR/bin/clang -cc1 -load ./libHelloWorld.so -plugin hello-world $CLANG_TUTOR_DIR/test/HelloWorld-basic.cpp
> error: unable to find plugin 'hello-world'
> ➜  build git:(main) ✗
> 
> 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.
> 
> Thanks a lot for all
> Alberto
> 
> [1] https://clang.llvm.org/docs/ClangPlugins.html <https://clang.llvm.org/docs/ClangPlugins.html>
> [2] https://github.com/banach-space/clang-tutor <https://github.com/banach-space/clang-tutor>
> Il giorno ven 17 dic 2021 alle ore 01:11 Min-Yih Hsu <minyihh at uci.edu <mailto:minyihh at uci.edu>> ha scritto:
> It’s a lot easier to load custom pass plugins into clang with the new PassManager actually:
> ```
> clang -fpass-plugin=<path to plugin> ...
> ```
> Note that <path to plugin> needs to be an absolute path.
> 
> -Min
> 
>> On Dec 17, 2021, at 6:38 AM, Alberto Barbaro via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
>> 
>> Hi all,
>> 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. 
>> 
>> 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?
>> 
>> How would you fix this situation in symcc?
>> 
>> If someone could tell me how to load a ModulePass in clang-13 would be great.
>> 
>> Thanks a lot
>> Alberto
>> 
>> [1] https://github.com/eurecom-s3/symcc <https://github.com/eurecom-s3/symcc>
>> 
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211218/1c907941/attachment.html>


More information about the llvm-dev mailing list