如何编写这个 ld 脚本? [英] How to write this ld script ?

查看:37
本文介绍了如何编写这个 ld 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想链接除 z.o 之外的所有 .o 文件,所有 .o(无 z.o)都重定位在 0xC0000000 而 z.o 位于 0xFFFF0000 但 z.o 位于文件偏移量 0x8000.

If I want to link all .o files except z.o .All .o (no z.o) is relocated at 0xC0000000 while z.o is at 0xFFFF0000 but z.o is located at file offset 0x8000.

那么.如何编写这个ld脚本?

So.how to write this ld script ?

这是我的 loader.lds

Here is my loader.lds

SECTIONS { 
    loader      0x00000000 : { start.o loader.o }
    kloader     0x30100000 : AT(4096) { loaderk.o ../lib/klib.a }
    vect        0xFFFF0000 : AT(0x4000) { high_vect.o }
} 

这是对的吗????

推荐答案

如果你使用 输入部分.仅使用文件名不是执行此操作的正常方法.问题是,在某些时候,源模块会相互作用,您将在同一模块中使用来自多个位置的代码和/或数据.因此,制作部分 loaderkloadervect 并使用 gcc attributespragmas 将代码/数据放在部分中.

It is much easier if you use input sections. Just using filename is not the normal way to do this. The issue is that at some point the source modules will inter-act and you will have code and/or data from multiple location used in the same module. So, make sections loader, kloader and vect and use gcc attributes or pragmas to place code/data in sections.

您的问题在 Gnu ld's 中得到了回答 输入部分示例.输出节列表不必按内存顺序排列.将通配符 { *.o(.text*) } 放在最后,不匹配的输入对象将放置在此部分.

Your question is answered in Gnu ld's Input section example. The output section list does not have to be in memory order. Place the wildcard { *.o(.text*) } last and input objects that aren't matched will be placed in this section.

一个带注释的函数示例可能看起来像,

An example annotated function might look like,

 void data_abort(unsigned int fsr, void* fault) __attribute__ ((section ("vector)))

通常不同部分中的函数/数据必须协作,因此能够将它们混合在同一个源文件中允许编译器对 static 项目执行优化,并将功能相似的项目组合在一起,即使它们可能位于不同的部分.

Often functions/data in different sections must co-operate, so being able to mix them in the same source file allows the compiler to perform optimizations on static items and keeps functionally similar items grouped together, even though they might reside in different sections.

我认为这通常会遵循您的要求.

I think this might generally follow what you requested.

 SECTIONS { 
     loader      0x00000000 : { start.o loader.o }
     kloader     0x30100000 : AT(4096) { loaderk.o ../lib/klib.a }
     vect        0xFFFF0000 : AT(0x4000) { high_vect.o }
     vect2       0xFFFF0000 : AT(0x8000) { z.o } /* overlay? */
     text        0xC0000000 : { *.o }
 } 

我不确定您是否打算叠加矢量.你可以用一些数据表覆盖 init 代码.通常你希望至少将 .text.data.bss 分开.

I am not sure if you intend to over-lay the vectors or not. You can overlay init code with some data tables. Usually you want to separate at a minimum .text, .data and .bss.

总是生成一个地图文件并仔细检查那里的地址.这比加载和检测代码以确定某些内容已放置在错误地址要快得多.

Always generate a map file and double check the addresses there. This is much quicker than loading and instrumenting the code to determine that something has been placed at the wrong address.

参见:从 RAM 运行代码Gnu Linker 给出意外地址,以及相关的 指向此问题的链接.

See: Running code from RAM, Gnu Linker giving unexpected address, and the related links to this question.

这篇关于如何编写这个 ld 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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