【问题标题】:Linker Script: Put a particular file at a later position链接描述文件:将特定文件放在后面的位置
【发布时间】:2014-01-28 22:49:09
【问题描述】:

我想编写一个如下所示的链接描述文件:

SECTIONS {
  . = 0x0;
  .startup . : { startup.o(.text) }
  .text : { *(.text) }
  .data : { *(.data) }
  .bss : { *(.bss COMMON) }
  . = 0x4000;
  other.text : { other.o(.text) }
  other.data : { other.o(.data) }
  other.bss : { other.o(.bss) }
}

我的意图是按以下顺序:

  • 带有.text 的部分来自startup.o
  • .text.data.bss 包含所有其他输入文件中的这些部分除了other.o
  • 来自other.o.text.data.bss 部分

当然,我给出的脚本有问题:other.o 包含在之前使用的* 通配符中,因此它不会被放入输出部分other

除了手动列出所有输入目标文件栏other.o 代替*s,还有什么方法可以在这里实现我想要的吗?

【问题讨论】:

    标签: c linker embedded ld bare-metal


    【解决方案1】:

    您可以使用部分属性来解决这个问题。假设您在该文件(或任何其他文件)中声明函数时添加以下属性:

    void foo() __attribute__ ((section(".specialmem")));
    

    在您的链接器脚本中也有类似的部分定义:

    .specialmem:
    {
        *(.specialmem)
    }
    

    您也可以对 data/bss(全局变量)做同样的事情。 假设您希望某些文件/函数最终位于特定的内存位置,最好在链接器文件中定义这些内存块,然后将它们放在那里:

    .specialmem:
    {
        *(.specialmem)
    } >specialMemBlock
    

    【讨论】:

      【解决方案2】:

      您可能想尝试 EXCLUDE_FILE

      类似这样的: *(EXCLUDE_FILE (other.o) .text .text. )

      【讨论】:

        【解决方案3】:

        部分解决方案:* 通配符是成熟的文件通配符。如果你足够幸运 other.o 与其他输入文件位于不同的目录中,这将起作用:

        SECTIONS {
          . = 0x0;
          .startup . : { foo/startup.o(.text) }
          .text : { foo/*(.text) }
          .data : { foo/*(.data) }
          .bss : { foo/*(.bss COMMON) }
          . = 0x4000;
          other.text : { bar/other.o(.text) }
          other.data : { bar/other.o(.data) }
          other.bss : { bar/other.o(.bss) }
        }
        

        【讨论】:

          猜你喜欢
          • 2018-11-09
          • 2012-11-29
          • 2014-07-02
          • 2014-04-22
          • 2019-12-13
          • 2016-11-09
          • 1970-01-01
          • 2013-06-03
          • 1970-01-01
          相关资源
          最近更新 更多