Anyone has tried using LLVM compile Baidu Apollo7.0+ to extract bitcode? #15596
lilejin322
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
[Motivation]
Q: Why use LLVM for compilation instead of GCC?
A: LLVM provides powerful intermediate representations like bitcode (.bc) and human-readable intermediate representation (.ll) files. These representations are derived from high-level programming languages and are logically equivalent to them. Analyzing compiler intermediate representations helps in understanding the inherent logic of a program, rather than relying solely on fuzz testing (black-box testing).
Q: How to use these intermediate representations (IR) ?
A: Intermediate representations can be used to generate Control Flow Graphs (CFG), Control Dependence Graphs (CDG), and Program Dependence Graphs (PDG). These graphs are extremely useful for identifying potential logical errors within a program. One available toolkit: https://github.com/ARISTODE/program-dependence-graph
While I've tried to define the CC-toolchain using wllvm in new version of Apollo (r7.0.0), implement of my code available as follow, but it doesn't work. Can anyone can revive the LLVM compilation for Apollo 7.0+? In earlier versions of Baidu Apollo 5.5 and 3.0, BaiduXLab provided an officially supported script for compiling the Apollo core using LLVM [3].
If I use LLVM for compilation directly, I’m not sure how to modify the Bazel scripts for the entire stack. It seems that CUDA-related modules will raise Errors as long as compiler frontend is specified as Clang in Bazel config files. If you only modify the compiler priority via shell in Docker, it won’t work because Bazel will still instruct GCC to handle the entire compilation process. This can be verified by grep 'GCC' tag from the bazel-bin files.
[Update]
To further clarify the effort to introduce cc-toolchain into Apollo 7.0, I forked a public Apollo code repository and started from version r7.0.1, which has already fixed the zlib bug: https://github.com/YuqiHuai/BaiduApollo/tree/r7.0.1
Showcasing all my changes (to simplify the process, I only created a single commit): https://github.com/lilejin322/BaiduApollo/tree/r7.0.1_debug
Here is an only-one-click comparision of all code changes based on branch --r7.0.1 from a public repository YuqiHuai/BaiduApollo@r7.0.1...lilejin322:BaiduApollo:r7.0.1_debug
This attempt still has problems, this phenomenon can be directly reproduced. 👇
In host linux:
HOST$ git clone https://github.com/lilejin322/BaiduApollo.git -b r7.0.1_debug HOST$ cd apollo HOST/apollo$ bash docker/scripts/dev_start.sh HOST/apollo$ bash docker/scripts/dev_into.sh
In docker container:
INDOCKER/apollo$ pip install wllvm # install wllvm, here pip from /usr/local/lib/python3.6/dist-packages/pip (python 3.6) INDOCKER/apollo$ bash apollo.sh build
Then, you will get the reproduced error.
This is a really weird phenomenon 😂 Coz I've declared the position of /usr/bin/clang/10.0.0/include in the CROSSTOOL:
https://github.com/lilejin322/BaiduApollo/blob/d13c1999ce7d13fa2fd907365fc43739a3395db2/tools/wllvm/CROSSTOOL#L53
I can 100% confirm these head files exist. 🥺
[References] 📖
[1] https://github.com/ZiwenWan/wllvm-toolchain/tree/master
[2] https://github.com/sera-sch/apollo-clang-toolchain
[3] https://github.com/baiduxlab/apollo/tree/master/tools/clang-6.0
[4] https://github.com/h1994st/ApolloLLVMCompile
[5] https://github.com/zqzqz/AVChecker/tree/master/apollo_llvm_compile
[6] Bazel Tutorial: Configure C++ Toolchains
[7] https://github.com/vsco/bazel-toolchains
[8] Bazel Migrating to Platforms
[9] https://github.com/bazel-contrib/toolchains_llvm
[Appendix]
Bazel version comparison between Apollo 5.0 official docker image and Apollo 7.0 official docker image.
Beta Was this translation helpful? Give feedback.
All reactions