每个变量创建命名部分?

时间:2011-07-26 18:44:31

标签: gcc compiler-construction

假设我有变量:

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

最简单的方法是什么?

更新

GOT:

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

一起
target_asm_named_section()` 

生成:


    .global
    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))`

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

有没有简单的方法来解决这两个问题?

1 个答案:

答案 0 :(得分:0)

解决方案: 首次使用:     

#define MMR __attribute__((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是您在部分(“”)中创建的短语。然后将它与你想要它做的匹配。

我使用标志例如:

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

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