zoukankan      html  css  js  c++  java
  • 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.

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

  • 相关阅读:
    前端 JavaScript&Dom
    前端 css续
    前端 初级篇(CSS)
    前端 初级篇(HTML)
    堡垒机
    Python操作RabbitMQ
    常用到代码片段
    关于文件上传功能的思考
    JS正则表达式将url转成json格式
    一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
  • 原文地址:https://www.cnblogs.com/under/p/10448643.html
Copyright © 2011-2022 走看看