【问题标题】:Creating Named sections per variable?为每个变量创建命名部分?
【发布时间】:2011-10-13 16:15:36
【问题描述】:

假设我有变量:

int global a = 1;

int banana b = 2;

int mango c = 3;

我希望 GCC 生成它们:

.global
a .long 1
.banana 
b .long 2
.mango
c .long 3

最简单的方法是什么?

更新:

得到:

 __attribute__ ((section ("mmm"))) int a = 432;`

随着

target_asm_named_section()` 

生成:

。全球的 A: .long 1

这很好,但有两个问题。

一个是,除非列表是针对不同部分排序的,否则您将获得重复部分。

所以

__attribute__ ((section ("mmm"))) int a = 432; __attribute__ ((section ("mmm"))) int b = 432; __attribute__ ((section ("global"))) int c = 432;

很好,但是

__attribute__ ((section ("mmm"))) int a = 432; __attribute__ ((section ("global"))) int c = 432; __attribute__ ((section ("mmm"))) int b = 432;

不好,因为.mmm会出现两次。

第二个问题是我已经在使用属性来做

`__attribute__((global))`

尽我所能,不能与之前的属性结合使用。

有什么简单的方法可以解决这两个问题吗?

【问题讨论】:

    标签: gcc compiler-construction


    【解决方案1】:

    解决方案: 首次使用:

    #define MMR __属性__((section ("section mmr")))

    然后,在函数内部定义

    #define TARGET_ENCODE_SECTION_INFO
    通过以下方式导航到字符串:
        #define ATTRIBUTES(decl) \
          (TYPE_P (decl)) ? TYPE_ATTRIBUTES (decl) \
                        : DECL_ATTRIBUTES (decl) \
                          ? (DECL_ATTRIBUTES (decl)) \
                  : TYPE_ATTRIBUTES (TREE_TYPE (decl))
      tree attr = ATTRIBUTES(decl);
      char* section_name = TREE_STRING_POINTER( TREE_VALUE( TREE_VALUE(attr)));
    

    中提琴,section_name 是您在 section("") 中创建的短语。然后将其与您希望它执行的操作相匹配。

    例如,我使用标志:

      if(strcmp(section_name, "apple") == 0)
      {
         flags |= SYMBOL_FLAG_APPLE;
      }
    

    设置的标志是原始_属性_的目标,现在可以使用section属性完成,两个目标都可以通过使用来实现一个属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多