简体   繁体   English

GCC-ARM:在 C 中跳转到 linker 部分而不是绝对地址

[英]GCC-ARM: Make a jump in C to a linker section instead to a absolute address

I have a SW that is divided into two binaries (loaded in different memories).我有一个软件,它分为两个二进制文件(加载在不同的内存中)。

Therefore I have two linker files.因此我有两个 linker 文件。

A binary runs and loads the second binary in the other memory, and this second runs.一个二进制文件运行并在另一个 memory 中加载第二个二进制文件,第二个运行。

There is a function that both codes use, and it is loaded in RAM by the first one, so in the second I make the call to this function really a JUMP to the address where it is loaded in RAM (in the linker file of the first SW I have defined a specific section where I force this function to be loaded).有一个 function 两个代码都使用,它由第一个代码加载到 RAM 中,所以在第二个代码中我调用这个 function 实际上是跳转到它在 RAM 中加载的地址(在 Z3175B42736043407 的 Z3175B423736043407 文件中第一个 SW 我已经定义了一个特定的部分,我强制加载这个 function)。

Currently, this mechanism works for me correctly.目前,这种机制对我来说是正确的。

My question is, is it possible to jump to a tag or symbol instead of the specific address?我的问题是,是否可以跳转到标签或符号而不是特定地址?

Ideally, in my linker file I would define the address with a tag, and in the code I would refer to that tag.理想情况下,在我的 linker 文件中,我将使用标签定义地址,并在代码中引用该标签。

That is, both the compiler and the linker would understand that tag and translate it to the address.也就是说,编译器和 linker 都会理解该标签并将其转换为地址。

So if I change the address in the linker I would not have to change also in the JUMP instruction.因此,如果我更改 linker 中的地址,我也不必更改 JUMP 指令。

Many thanks非常感谢

NOTE: gcc-arm-none-eabi-4_9-2015q3注意:gcc-arm-none-eabi-4_9-2015q3

Accessing Linker Sections directly from C code 直接从 C 代码访问 Linker 部分

NOLOAD directive NOLOAD 指令

Splitting linker files in two and using both for linking (the question's answer has an example of that) 将 linker 文件一分为二并使用两者进行链接(问题的答案有一个例子)

You can use NOLOAD in App2 (while loading it normally in App1) to know about the function, but not load it, and then access it as mentioned in the first link.您可以在 App2 中使用 NOLOAD(在 App1 中正常加载时)了解function,但不加载它,然后按照第一个链接中所述访问它。

If you wanted to play around with preprocessor macros and compilation/linking options, you could have an additional linker file that is shared between both apps, but conditionally loads sections based on the switches.如果您想使用预处理器宏和编译/链接选项,您可以有一个额外的 linker 文件在两个应用程序之间共享,但有条件地根据开关加载部分。 This would help you avoid repeating the address in both linker files (eg App1 would be linked using ld1 + ldshared , App2 using ld1 + ldshared with different switches ).这将帮助您避免在 linker 文件中重复地址(例如 App1 将使用ld1 + ldshared链接,App2 使用ld1 + ldshared 与不同的开关链接)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM