|
|||||||||||
|
Technical Support Support Resources
Product Information |
ARMCLANG: Support for global named register variablesInformation in this knowledgebase article applies to:
QUESTIONI'm migrating my program from using ARMCC v5.x to ARMCLANG v6.x compiler, and in my program I have the following source code:
register unsigned __reg_lr __asm("lr");
unsigned getLR() { return __reg_lr; }
This works fine with ARMCC v5.x But when I compile the same code with ARMCLANG, I get the following error: fatal error: error in backend: Invalid register name "lr". ArmClang.exe: error: clang frontend command failed with exit code 70 (use -v to see invocation) How can I solve this issue using ARMCLANG? ANSWERUsing the __asm keyword to allocate a global variable to a register is not supported by ARMCLANG compiler. Instead, you can use the following inline assembly in your code to retrieve the value stored in the LR register, for example:
__attribute__((always_inline)) static inline unsigned getLR() {
unsigned lr;
__asm__ __volatile("mov %0, lr" : "=r"(lr));
return lr;
}
Similarly you can retrieve general-purpose register's value, such as R11:
__attribute__((always_inline)) static inline unsigned getR11() {
unsigned r11;
__asm__ __volatile("mov %0, r11" : "=r"(r11));
return r11;
}
Support for global named register variables may be added to ARMCLANG in a future release. MORE INFORMATION
Last Reviewed: Thursday, November 26, 2020 | ||||||||||
|
|||||||||||
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.