__attribute__((section(“name”))) usage?

后端 未结 2 548
生来不讨喜
生来不讨喜 2021-02-09 08:35

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 cre

2条回答
  •  佛祖请我去吃肉
    2021-02-09 09:19

    From a usecase point of view, there are lots of different types of .data, like:

    • data local to a specific CPU and/or NUMA node
    • data shared between contexts (like user/kernelspace, as are the .vdso or vsyscall pages. Or, another example, bootloader and kernel)
    • readonly data or other data with specific access mode/type restrictions (say, cacheability or cache residency - the latter can be specificed on some ARM SoCs)
    • data that persists "state transitions" (such as hibernation image loads, or crash kernel / fast reboot reinitializations)
    • data with specific lifetimes/lifecycles (only used in specific stages during boot or during operation, write-once data)
    • data specific to a particular kernel subsystem or particular kernel module
    • "code colocated" data (addressing offsets in x64 are plus/minus 2GB so if you want RIP-relative addressing, the data must be within that range of your currently executing code)
    • data mapped to some specific hardware register space VA range

    So in the end it's often about attributes (the word here used in a more generic sense than what __attribute__(...) allows you to state from within gcc sourcecode. Whether another section is needed and/or useful is ... in the eye of the beholder - the system designer, that is.

    The availabiltiy of the section attribute, therefore, allows for flexibility and that is, IMHO, a good thing.

提交回复
热议问题