链接器脚本:将函数的绝对地址插入到生成的代码中 [英] Linker script: insert absolute address of the function to the generated code

查看:390
本文介绍了链接器脚本:将函数的绝对地址插入到生成的代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用嵌入式工具(PIC32),但PIC32的编译器和链接器都基于gcc,因此,主要的东西应该是普通的gcc链接器和PIC32链接器。



为了节省闪存空间(在微控制器上通常不够用),我需要将几个大的函数只能通过指针调用这些函数。

所以,我需要在生成的代码中创建向量表。



我试图获得函数的绝对地址并将其写入生成的代码,但仍然出现错误。



在下面的示例中,我试图获取函数 _formatted_write 的地址。



代码:

  .user_addr_table _USER_ADDR_TABLE_ADDR:
{
KEEP( *(。user_addr_table))
LONG((ABSOLUTE(_formatted_write))); / * _formatted_write是我的函数的名称* /
}> user_addr_table

链接器返回错误:表达式中引用的无法解析的符号'_formatted_write' / code>。



我注意到如果我写一些垃圾而不是 _formatted_write ,那么它会返回错误未定义符号..... ,所以, _formatted_write 被链接器所知。



这让我觉得我应该执行一些额外的步骤来使其可以解析。但是仍然不知道如何去做。

解决方案

对于有人有同样问题的案例(比如几个小时前的我) ,还有一个更好的解决方案:

让bootloader.out成为bootloader-binary。然后我们可以使用 $ b

  nm -g bootloader.out | grep'^ [0-9,a-e] \ {8 \} T'| awk'{printf'PROVIDE(%s = 0x%s); \\\
,$ 3,$ 1}'> bootloader.inc

我们可以在应用程序的链接描述文件中包含一个文件

  INCLUDE bootloader.inc 

链接器现在知道所有引导加载程序函数的地址,我们可以链接它,而不必在应用程序中具有实际的功能代码。我们需要的所有内容都是针对我们要执行的每个引导加载程序函数的声明。

I have a question related to gcc's linker.

I'm working with embedded stuff (PIC32), but PIC32's compiler and linker are based on gcc, so, main things should be common for "regular" gcc linker and PIC32 linker.

In order to save flash space (which is often insufficient on microcontrollers) I need to put several large functions in the bootloader, and application should call these functions just by pointers.

So, I need to create vector table in the generated code.

I'm trying to get absolute address of the function and write it to the generated code, but still getting errors.

In the example below I'm trying to get address of the function _formatted_write.

Code:

.user_addr_table _USER_ADDR_TABLE_ADDR :
{
   KEEP(*(.user_addr_table))
   LONG((ABSOLUTE(_formatted_write))); /* _formatted_write is a name of my function */
} > user_addr_table

Linker returns error: "unresolvable symbol '_formatted_write' referenced in expression".

I have noticed that if I write some garbage instead of _formatted_write, then it returns error "undefined symbol .....", so, _formatted_write is known by linker.

It makes me think I should perform some additional steps to make it "resolvable". But still no idea how to do that.

解决方案

For the case that someone has the same problem (like me some hours ago), there is a still better solution:

Let "bootloader.out" be the bootloader-binary. Then we can generate with

nm -g bootloader.out | grep '^[0-9,a-e]\{8\} T' | awk '{printf "PROVIDE(%s = 0x%s);\n",$3,$1}' > bootloader.inc

a file that we can include in the linker script of the application with

INCLUDE bootloader.inc

The linker knows now the addresses of all bootloader-functions and we can link against it without to have the actual function code in the application. All what we need there is a declaration for every bootloader-function which we want to execute.

这篇关于链接器脚本:将函数的绝对地址插入到生成的代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆