vxWorks6.9动态加载程序时出现“ Relocation value does not fit in 24/26 bits “错误的处理方法

时间:2024-04-14 11:55:17

在vxworks中动态加载可执行程序,有时候会出现类似  Relocation value does not fit in 26 bits (offset: 0x10, type: 1)  的错误提示,从而导致程序加载失败。

出错原因:

Some architectures have instructions that use less than 32 bits to reference a nearby position in memory. Using these instructions can be more efficient than always using 32 bits to refer to nearby places in memory.
The problem arises when the compiler has produced such a reference to something that lies farther away in memory than the range that can be accessed with the reduced number of bits. For instance, if a call to printf( ) is encoded with one of these instructions, the load may succeed if the object code is loaded near the kernel code, but fail if the object code is loaded farther away from the kernel image.

以上是官方文档解释,概述来说就是:有些架构的处理器使用少于32bit的指令来引用临近的内存,比如例子中使用26bit来访问,这样可以使访问更快、更有效率。但是万事万物的利和弊都是并存的,如果引用的内容位于内存中比26bit所能表示的地址更远时,就会出错了。
直白打比方,这个错误就好比:以北京为核心,你买的车票只能到郑州,但是你要访问的内容在南京,所以就出错了。

解决方案:

Recompile the object file using -Xcode-absolute-far for the Wind River compilers, and for GNU compilers, the appropriate long call option, -mlongcall (for PPC architecture).

官方给出的方案简单明了:对于diab编译器,添加 -Xcode-absolute-far 配置; 对于GNU编译器,添加 -mlongcall 配置即可。

如下图:

vxWorks6.9动态加载程序时出现“ Relocation value does not fit in 24/26 bits “错误的处理方法

diab编译器处理类似。

了解详细信息,可在workbench帮助文档中搜索  mlongcall 即可查阅相关手册说明。

结束