将二进制与存储器中特定位置的功能/数据链接 [英] Linking binary against functions/data in specific location in memory

查看:238
本文介绍了将二进制与存储器中特定位置的功能/数据链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为ATMega编写一个中间内存引导程序。



我想放置一些常用的功能和数据在内存中的特定位置,以便:




  • 引导加载程序部分的有限大小无法克服

  • 库函数,驱动程序等不会被应用程序部分复制,从而浪费空间



为了说明的目的,所需的内存布局如下:



这个线程在avrfreaks,我到了我能够移动所有代码(在我的bootloader +库开发环境 - 应用程序w不能在单独的项目中开发),而不是通过自定义链接描述文件,通过成功地将 __ attribute__((section(。boot)))标记到共享库部分。 / p>

在avrfreaks线程中建议我可以使用 avr-objcopy --strip-all --keep-symbol = fred链接我的应用程序--keep-symbol = greg ... boot.elf dummy.elf 创建一个我在共享库中具有的符号引用,然后将我的应用程序与这个内存布局与 avr-gcc -o app.elf -Wl, - just-symbols = dummy.elf app1.o app2.o ...



我在这里遇到的问题是我需要指定我要保存在我的dumy.elf中的每个符号。我可以使用 keep-symbols =< file> 指令来指定要保留的符号的文本文件列表,但我仍然必须生成此列表。



我注意到有一堆符号,我不要想要包含(像名称中常见的C环境设置代码但是对于引导加载程序和应用程序而言,功能不同)似乎以前缀'_'开头(但是当然,有一些有用的和大的库函数具有相同的前缀,例如* printf和数学例程)。如果我的应用程序与应用程序/引导加载程序中的现有运行时代码链接,也不会有冲突?



如何为我的库部分生成一个符号列表其中包含了我编写的代码(可能有一些sed魔术和扫描头文件)/排除可能在链接应用程序时冲突的任何符号?



该项目可以在当前状态下查看此github资源库



编辑:我想澄清一点,我可以用 __ attribute__((section(。library))标记共享库部分中的所有内容) ,但是因为我也想在引导程序和应用程序之间分享一些相当大的libc东西(vsprintf等),所以这很麻烦。因此,我已经选择通过链接描述将没有标记为启动的所有东西放在库内存区域中。



也许我只需要关于我的链接描述文件的一些建议,因为我不是很确定我在做什么。

解决方案

考虑使用 -R< file> 作为链接器选项( gcc -Wl,-R -Wl,< file>



这将在< file> 中生成对(全局)符号的引用,就像它们正常链接,但不包括引用的代码。


I'm currently in the process of writing an intermediate-memory bootloader for an ATMega.

I'd like to place a section of commonly used functions and data in a specific location in memory, such that:

  • limited size of the bootloader section is not overcome
  • library functions, drivers, etc, are not reproduced by the application section and thus wasting space

For illustrative purposes, a map of the desired memory layout is below:

Following some help in this thread on avrfreaks, I'm to the point where I've been able to move all code (in my bootloader + library development environment - applications will be developed in separate projects) not tagged with __attribute__ ((section(".boot"))) to the shared library section successfully via means of a custom linker script.

It was suggested in the avrfreaks thread that I can link my applications by using avr-objcopy --strip-all --keep-symbol=fred --keep-symbol=greg ... boot.elf dummy.elf to create a symbol reference of what I have in my shared library, and then linking my applications against this memory layout with avr-gcc -o app.elf -Wl,--just-symbols=dummy.elf app1.o app2.o ....

The problem I face here is that I need to specify each symbol I want to keep in my dumy.elf. I can use the keep-symbols=<file> directive to specify a text file list of symbols to keep, but I still must generate this list.

I've noticed that there is a bunch of symbols that I don't want to include (stuff like C environment set-up code that is common in name, but different in functionality, for both the bootloader and application) that seems to start with the prefix '_' (but of course, there are some useful and large library functions with the same prefix, e.g. *printf and math routines). Perhaps there won't be conflicts if I link my application against the existing runtime code in the application/bootloader?

How can I generate a list of symbols for my library section that contains the code that I've written (maybe some sed magic and scanning header files)/excludes any symbols that may conflict in linking the application?

The project can be viewed in its current state at this github repository.

Edit: I want to make clear that I could tag everything I want to be in the shared library section with __attribute__ ((section(".library"))), but as I also want to share some rather large libc stuff (vsprintf, etc) between the bootloader and application, this becomes cumbersome very quickly. As such, I've elected to put everything not tagged as boot in the library memory region via a linker script.

Perhaps I just need some advice on my linker script, as I'm not super sure what I'm doing there.

解决方案

Consider using -R <file> as linker option (gcc -Wl,-R -Wl,<file>).

This will generate references to (global) symbols in <file> just as if they were linked normally, but not include the referenced code.

这篇关于将二进制与存储器中特定位置的功能/数据链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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