简体   繁体   English

如何使用MinGW创建固定大小的内存段,将数据放置在段内的固定位置

[英]How to create memory segment with fixed size, place data in fixed position inside the segment, using MinGW

I am using MinGW to create a win32 exe.我正在使用 MinGW 创建一个 win32 exe。 I would like to create a memory segment with a fixed size, and after that place variable inside this segment at a fixed address relative to the start of the segment.我想创建一个固定大小的内存段,然后在该段内相对于段开头的固定地址处放置变量。 Has anyone an idea of how to do this?有没有人知道如何做到这一点?

I was able to declare my own segment with:我能够声明我自己的段:

  .codeflash BLOCK(__section_alignment__) :
  {
    __codeflash_start__ = . ;
    *(.codeflash)
    __codeflash_end__ = . ;    
  }

And place variables inside this segment using:并使用以下方法将变量放置在该段内:

__attribute__((section(".codeflash"))) 

I am using the default linker script.我正在使用默认的链接器脚本。

Thanks.谢谢。

Lets say 0x100 bytes from the start of the segment假设从段的开头开始 0x100 个字节

  .codeflash BLOCK(__section_alignment__) :
  {
    . += 0x100;
    __codeflash_start__ = . ;
    KEEP(*(.codeflash))
    KEEP(*(.codeflash*))
    __codeflash_end__ = . ;    
  }

我使用上面的建议来解决问题:将所有内容添加到结构中并将此结构放在部分中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM