为每个变量创建命名部分?

问题描述 投票:0回答:1

假设我有变量:

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()` 

生成:

    。全球的
    一个: 
       .长1

这很好,但有两个问题。

其中之一是,除非列表是按不同部分排序的,否则您将得到重复的部分。

所以

     __attribute__ ((节("mmm"))) int a = 432;
     __attribute__ ((节("mmm"))) int b = 432;
     __attribute__ ((节(“全局”))) int c = 432;

很好,但是

     __attribute__ ((节("mmm"))) int a = 432;
     __attribute__ ((节(“全局”))) int c = 432;
     __attribute__ ((节("mmm"))) int b = 432;

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

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

`__attribute__((全局))`

尽我所能,它不能与之前的属性组合。

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

gcc
1个回答
0
投票

解决方案: 首次使用:

#定义 MMR __属性__((section ("section mmr")))

然后,在函数内部定义

#定义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属性来完成,两个目标都可以通过使用一个属性来实现

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.