数组变量在我给出section属性时没有分配到数据部分,为什么?

huangapple go评论78阅读模式
英文:

Array variables didn't get allocated in a data section when I gave section attribute, why?

问题

我已经添加了一个属性,用于指定某些数据的部分(位于任何函数之外,因此它位于一种数据部分中),如下所示。

char __attribute__(( aligned(256), __section__(".axpudata") )) mem_local  [N_AXEMIS_PER_AXPU][LOCAL_SEGMENT_SIZE];
char __attribute__(( aligned(256), __section__(".axpudata") )) mem_private[N_AXEMIS_PER_AXPU][N_AXEC_PER_AXEMIS*N_THREAD_PER_AXEC][PRIVATE_SEGMENT_SIZE];
uint64_t  __attribute__(( aligned(256), __section__(".axpudata") )) mem_knlargs[KNLARGS_SEGMENT_SIZE/8];
struct __attribute__(( aligned(256), __section__(".axpudata") )) es_t      axpu_es   [N_AXEMIS_PER_AXPU];
struct __attribute__(( aligned(256), __section__(".axpudata") )) reg_csr_t axpu_regs [N_AXEMIS_PER_AXPU];

但是当我检查映射文件时,我发现mem_local、mem_private和mem_knlargs都分配在'.axpudata'部分,但axpu_es和axpu_regs分配在'.bss'部分。然后我发现axpu_es和axpu_regs不必在'.axpudata'部分,如果它们位于'.bss'部分也不会引起任何问题。但我好奇为什么它们没有分配在'.axpudata'部分。在什么情况下会发生这种情况?
以下是关于此的链接器脚本的部分。

.axpudata : {
    . = ALIGN(65536);
    *(.axpudata)
}

/* 未初始化数据 */
. = ALIGN(0x10000);
.bss :
{
    __bss_start = .;
    __bss_start__ = .;
    *(.bss*)
    __bss_end = .;
    __bss_end__ = .;
}

附加信息:我刚刚发现属性是在结构体和es_t之间给出的,例如struct __attribute__(..) es_t axpu_es[..],但应该是struct es_t __attribute__(..) axpu_es[...]

英文:

I have added attribute specifying the section for some data (outside any function, so it's in a kind of data section) as below.

char __attribute__(( aligned(256), __section__(".axpudata") )) mem_local  [N_AXEMIS_PER_AXPU][LOCAL_SEGMENT_SIZE];
char __attribute__(( aligned(256), __section__(".axpudata") )) mem_private[N_AXEMIS_PER_AXPU][N_AXEC_PER_AXEMIS*N_THREAD_PER_AXEC][PRIVATE_SEGMENT_SIZE];
uint64_t  __attribute__(( aligned(256), __section__(".axpudata") )) mem_knlargs[KNLARGS_SEGMENT_SIZE/8];
struct __attribute__(( aligned(256), __section__(".axpudata") )) es_t      axpu_es   [N_AXEMIS_PER_AXPU];
struct __attribute__(( aligned(256), __section__(".axpudata") )) reg_csr_t axpu_regs [N_AXEMIS_PER_AXPU];

But when I examine the map file, I found mem_local, mem_private, mem_knlargs were all allocated at '.axpudata' section but axpu_es and axpu_regs were allocated at '.bss' section. I then found axpu_es and axpu_regs didn't have to be at the '.axpudata' section and it doesn't cause any problem if they are in '.bss' section. Buy I'm curious why they didn't get allocated in the '.axpudata' section. In what cases does this kind of thing happen?
Here is the part of the linker script about this.

  .axpudata : {
    . = ALIGN(65536);
    *(.axpudata)
  }

  /* Uninitialized data */
  . = ALIGN(0x10000);
  .bss :
  {
    __bss_start = .;
    __bss_start__ = .;
    *(.bss*)
    __bss_end = .;
    __bss_end__ = .;
  }

ADD :
I just found the attribute was given between struct and es_t like struct __attribute__(..) es_t axpu_es[..] but it should be struct es_t __attribute__(..) axpu_es[...].

答案1

得分: 0

第一部分指定了变量属性

第二部分指定了类型属性,其中不包括__section__选项。

因此,显然你可以指定特定变量应该位于某个节(section)中,但不能指定所有该类型的变量都应该这样做。

英文:

The first part specifies attributes for variables.

The second part specifies attributes for types, which doesn't include a __section__ option.

So, apparently you can specify that a specific variable should reside in a section, but not that all variables of a type should do that.

答案2

得分: 0

我后来发现属性是在结构体和es_t之间给出的,像struct __attribute__(..) es_t axpu_es[..],但应该是struct es_t __attribute__(..) axpu_es[...]。当我修复了这个问题后,'axpu_es' 和 'axpu_regs' 数组被分配到了 '.axpudata' 部分。

英文:

I later found the attribute was given between struct and es_t like struct __attribute__(..) es_t axpu_es[..] but it should be struct es_t __attribute__(..) axpu_es[...]. When I fixed this, 'axpu_es' and 'axpu_regs' array got allocated in '.axpudata' section.

huangapple
  • 本文由 发表于 2023年7月3日 10:26:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定