尽管LMA属于不同的存储区,但RISC-V链接器抛出段LMA重叠错误

时间:2019-06-09 20:13:34

标签: c embedded ld riscv linker-scripts

我在链接器文件中关注了内存区域描述:

/*=============================
 * Memory region descriptions
 *=============================*/

MEMORY
{
  /*-------------------------------------
   * Virtual Memory Address (VMA) regions
   *-------------------------------------*/

  /* Local memory VMA */
  DMEM_VMA (rw) : ORIGIN = 0x1000, LENGTH = 4K

  /* DRAM text VMA */
  DRAM_T_VMA (rx) : ORIGIN = 0x0, LENGTH = 16M

  /* DRAM data VMA */
  DRAM_D_VMA (rw) : ORIGIN = 0x81000000, LENGTH = 2032M /* 2048M - 16M */


  /*----------------------------------
   * Load Memory Address (LMA) regions
   *----------------------------------*/

  /* Local memory LMA */
  DMEM_LMA (rw) : ORIGIN = 0x1000, LENGTH = 4K

  /* DRAM text LMA */
  DRAM_T_LMA (rx) : ORIGIN = 0x0, LENGTH = 16M

  /* DRAM data LMA */
  DRAM_D_LMA (rw) : ORIGIN = 0x01000000, LENGTH = 2032M
}



/*=============================
 * Output section descriptions
 *=============================*/

SECTIONS
{

  /*----------------------------------
   * DMEM output sections
   *----------------------------------*/

  /* data segment */
  .data.dmem : { 
    *(.data) 
  } >DMEM_VMA AT>DMEM_LMA

  .sdata.dmem : {
    _gp = . + 0x800;
    *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*)
    *(.sdata .sdata.* .gnu.linkonce.s.*)
  } >DMEM_VMA AT>DMEM_LMA


  /* bss segment */
  .sbss.dmem : {
    *(.sbss .sbss.* .gnu.linkonce.sb.*)
    *(.scommon)
  } >DMEM_VMA AT>DMEM_LMA

  .bss.dmem : { 
    *(.bss) 
  } >DMEM_VMA AT>DMEM_LMA


  /* thread-local data segment */
  .tdata.dmem : {
    _tls_data = .;
    *(.tdata)
    *(.tdata*)
  } >DMEM_VMA AT>DMEM_LMA

  .tbss.dmem : {
    *(.tbss)
    *(.tbss*)
  } >DMEM_VMA AT>DMEM_LMA


  /* read-only data */
  .rodata.dmem : { 
    *(.rodata) 
    *(.rodata*) 
  } >DMEM_VMA AT>DMEM_LMA


  .eh_frame.dmem : { 
    *(.eh_frame) 
    *(.eh_frame*) 
  } >DMEM_VMA AT>DMEM_LMA


  /* striped data */
  /* RISC-V 32 has a 4 byte word size */
  .striped.data.dmem ALIGN(bsg_group_size * 4): {
    _bsg_striped_data_start = . ;
    *(.striped.data)
  } >DMEM_VMA AT>DMEM_LMA


  /*----------------------------------
   * DRAM output sections
   *----------------------------------*/

  .text.dram : {
     *crt.o(.text)
     *(.text)
     *(.text.startup)
  } >DRAM_T_VMA AT>DRAM_T_LMA

  .data.dram : {
    *(.dram)
  } >DRAM_D_VMA AT>DRAM_D_LMA
}

我们有两个不同的区域,分别称为DMEM和DRAM,它们在我们的体系结构中是物理上不同的存储器。但是,我尝试使用此链接脚本链接的某些程序遇到以下错误:

riscv32-unknown-elf/bin/ld: section .data.dmem LMA [0000000000001000,000000000000100f] overlaps section .text.dram LMA [0000000000000000,0000000000001e4f]
collect2: error: ld returned 1 exit status

我很困惑,为什么链接器抱怨两个不同的LMA区域之间的重叠!任何调试提示都将非常有帮助...

0 个答案:

没有答案