• attribute知识


    include/linux/init.h中有

    #define __init __section(.init.text) __cold notrace
    #define __initdata __section(.init.data)
    #define __initconst __constsection(.init.rodata)
    #define __exitdata __section(.exit.data)
    #define __exit_call __used __section(.exitcall.exit)

    其中__section(xxx)为宏定义,展开后

    # define __section(S) __attribute__ ((__section__(#S)))

    section ("SECTION-NAME")'
         Normally, the compiler places the objects it generates in sections
         like `data' and `bss'.  Sometimes, however, you need additional
         sections, or you need certain particular variables to appear in
         special sections, for example to map to special hardware.  The
         `section' attribute specifies that a variable (or function) lives
         in a particular section.  For example, this small program uses
         several specific section names:
              struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
              struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
              char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
              int init_data __attribute__ ((section ("INITDATA"))) = 0;

              main()
              {
                /* Initialize stack pointer */
                init_sp (stack + sizeof (stack));

                /* Initialize initialized data */
                memcpy (&init_data, &data, &edata - &data);

                /* Turn on the serial ports */
                init_duart (&a);
                init_duart (&b);
              }

         Use the `section' attribute with an _initialized_ definition of a
         _global_ variable, as shown in the example.  GCC issues a warning
         and otherwise ignores the `section' attribute in uninitialized
         variable declarations.

         You may only use the `section' attribute with a fully initialized
         global definition because of the way linkers work.  The linker
         requires each object be defined once, with the exception that
         uninitialized variables tentatively go in the `common' (or `bss')
         section and can be multiply "defined".  You can force a variable
         to be initialized with the `-fno-common' flag or the `nocommon'
         attribute.

         Some file formats do not support arbitrary sections so the
         `section' attribute is not available on all platforms.  If you
         need to map the entire contents of a module to a particular
         section, consider using the facilities of the linker instead.

    可以看出为将对应的函数,变量等放到指定的段中

  • 相关阅读:
    Tomcat开启Debug模式
    Tomcat多实例
    django 总结
    Django2.* + Mysql5.7开发环境整合
    网络通讯协议
    Python-警告处理
    爬虫框架-selenium
    Python-标准库(常用模块)
    ORM概念
    面向对象-高级
  • 原文地址:https://www.cnblogs.com/under/p/10448643.html
Copyright © 2020-2023  润新知