huawei/bisheng⚓︎
Repository address⚓︎
https://repo.oepkgs.net/bisheng/
Repository positioning⚓︎
The repository for Kunpeng development kit - Bisheng compiler.
Overview⚓︎
Bisheng compiler is a high-performance, highly reliable, and easily scalable compiler toolchain developed by Huawei Compiler Lab for general processor architecture scenarios such as Kunpeng. It enhances and introduces various compilation optimization techniques, supporting programming languages such as C, C++, and Fortran.
In addition to the general LLVM functions and optimizations, the toolchain of Bisheng compiler has deeply optimized the key technology points of the middle-end and back-end, and integrates the Auto-tuner feature to support compiler automatic tuning.
For general information, please refer to the user guide of LLVM https://llvm.org/docs/UserGuides.html. The custom options newly added in Bisheng compiler can be found in the section of custom optimization options.
LLVM is a compiler that covers multiple programming languages and target processors, and Bisheng compiler focuses on the support for C, C++, and Fortran languages, using Clang, the LLVM front-end for C and C++ compilation and driver, as well as Flang, the LLVM front-end for Fortran compilation and driver.
- C and C++ programs
- Clang not only compiles C and C++ programs into LLVM intermediate representation (IR), but it also serves as a driver program that calls all LLVM optimization passes with code generation as a target, until the final binary file is generated. Bisheng compiler provides all the tools and libraries required for end-to-end compilation of programs.
- Fortran programs
- Flang is a Fortran frontend designed specifically for LLVM integration, consisting of two components flang1 and flang2. It is also a driver program that converts source code to LLVM IR. The frontend driver program transfers the IR downward for optimization and target code generation.
Installation and usage⚓︎
Environment dependencies⚓︎
- Memory: 8GB or more
- Operating system: openEuler21.03, openEuler 20.03 (LTS), CentOS 7.6, Ubuntu 18.04, Ubuntu 20, Kylin V10, UOS 20
- Architecture: AArch64
- GCC version: 4.8.5 or above
- glibc version: 2.17 or above
- libatomic version: 1.2 or above
- libstdc++ version: 6 or above
Installing Bisheng compiler⚓︎
Info
All the following operations should be performed as a root user.
The Bisheng compiler is now included in the openEuler source. For openEuler operating systems, you can install the Bisheng compiler using the yum source method. For non-openEuler operating systems, you can install it using the package management system.
- Create a configuration file named "bisheng-compiler.repo" under the directory "/etc/yum.repos.d/".
cat > /etc/yum.repos.d/bisheng-compiler.repo << EOF
[bisheng-compiler]
name=bisheng-compiler
baseurl=https://repo.oepkgs.net/bisheng/aarch64/
enabled=1
gpgcheck=0
priority=100
EOF
- To download and install the Bisheng compiler rpm package from the yum repository, you can follow these steps:
yum update
yum install bisheng-compiler
- (Optional) Clear the hash cache table of the current window. If there are other versions of LLVM compilers on the system, please run the following command immediately after installing the Mosheng compiler.
hash -r
- To verify if the installation is successful
clang -v
Using the Mosheng compiler⚓︎
- Compiling and running C/C++ programs
clang [command line flags] hello.c -o hello.o
./hello.o
clang++ [command line flags] hello.cpp -o hello.o
./hello.o
- Compiling and running Fortran programs
flang [command line flags] hello.f90 -o hello.o
./hello.o
- Specifying the linker. The linker specified by the Mosheng compiler is LLVM's lld. If it is not specified, the default ld will be used.
clang [command line flags] -fuse-ld=lld hello.c -o hello.o
./hello.o
Security Hardening⚓︎
- Purpose
- Buffer overflow attack is an attack action carried out using buffer overflow vulnerabilities. Buffer overflow is a very common and dangerous vulnerability that exists widely in various operating systems and applications. By exploiting buffer overflow attacks, program crashes, system shutdowns, reboots, and other consequences can be caused.
- In current network and distributed system security, more than 50% of the widely utilized vulnerabilities are attributed to buffer overflow, and the most dangerous of them are stack overflow, since intruders can use stack overflow to change the return address when the function returns, so that it jumps to any address, bringing harm such as program crash that can lead to denial of service, or jump and execute malicious code, such as jumping to the shell to execute malicious code.
- Solution
- Provide stack protection compilation options to enhance the security of software and prevent stack overflow attacks. You can use the command clang --help | grep stack-protector to check for stack protection options.