RISC-V IDE MRS Usage Notes (IV): Link-time Optimization
[Copy link]
Link-time optimization, or LTO (Link Time Optimization), is partially introduced as follows (for details, please refer to the GCC document on FLTO): When called with source code, it generates GIMPLE (one of GCC's internal representations) and writes it to a special ELF section in the object file. When object files are linked together, all function bodies are read from these ELF sections and instantiated as if they were part of the same translation unit. Multiple intermediate files are merged together by the linker and combined into a program to reduce the code size, so link-time optimization is an analysis of the entire program and cross-module optimization. At the same time, this requires that all parts involved in the link must have this parameter when compiling, otherwise errors may occur during linking.
The optimized entry when opening the link in the project properties page in MRS is as follows:
If you use this option in some projects in MRS and find that the code runs incorrectly, the possible reasons are as follows:
- The flto option has no effect on assembly files
- In order to prevent the problem of chip failure caused by enabling interrupts in the MCU code but not writing interrupt service functions, an interrupt service routine with in-place jump is declared in the assembly file. As a result, when this option is turned on, some programs use the in-place jump routine in the assembly instead of the interrupt service subroutine.
- The code itself is written incorrectly
Solution: Check the code writing method, ensure that the interrupts enabled in the program have C code level handlers, and delete the interrupt in-place jump program in the startup file (as shown in the figure below).
|