__attribute __(((section("name")))))的用法? [英] __attribute__((section("name"))) usage?

查看:156
本文介绍了__attribute __(((section("name")))))的用法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遍历了使用_ 属性 _((section("name")))的代码.我了解,对于gcc编译器,这使您可以告诉链接程序将创建的对象放在特定部分名称"(在链接器文件中声明了名称"绝对地址).

I have ran through code that use _ attribute _((section("name")). I understand that for gcc compiler this allows you to tell the linker to put the object created at a specific section "name" (with "name" absolute address declared in a linker file).

这样做而不是仅使用.data节有什么意义?

What is the point of doing this instead of just using the .data section?

推荐答案

有很多可能的用途.

例如,Linux内核将一些代码和数据段标记为仅在内核引导过程中使用.这些可以在内核运行后抛弃,从而回收空间以供其他用途.

The Linux kernel, for instance, marks some code and data sections as used only during kernel bootstrap. These can be jettisoned after the kernel is running, reclaiming the space for other uses.

您可以使用它来标记需要在特定处理器变体上打补丁的代码或数据值,例如在有或没有协处理器的情况下.

You can use this to mark code or data values that need patching on a particular processor variant, e.g., with or without a coprocessor.

您可以使用它使事物存在于特殊"地址空间中,这些地址空间将被刻录到PROM或保存在EEPROM中,而不是普通存储器中.

You can use it to make things live in "special" address spaces that will be burned to PROM or saved on an EEPROM, rather than in ordinary memory.

您可以使用它来收集代码或数据区域,以用于初始化和清除之类的目的,例如在程序开始之前和结束时运行的C ++构造函数和析构函数,或使用较短的寻址模式(我不知道我自己没有编写任何ARM代码,这对ARM有多少影响.

You can use it to collect together code or data areas for purposes like initialization and cleanup, as with C++ constructors and destructors that run before the program starts and when it ends, or for using shorter addressing modes (I don't know how much that would apply on ARM as I have not written any ARM code myself).

实际使用情况取决于链接描述文件.

The actual use depends on the linker script(s).

这篇关于__attribute __(((section("name")))))的用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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