【问题标题】:using the same linker ld script file target for two files对两个文件使用相同的链接器 ld 脚本文件目标
【发布时间】:2021-03-10 08:30:43
【问题描述】:

假设我的内存分配如下所示:

MEMORY
{
    firstfile  : ORIGIN = 0x00000000, LENGTH = 0x2000 
    secondfile : ORIGIN = 0x00002000, LENGTH = 0x6000
}

现在我想对两个不同的文件使用相同的 ld 脚本。 “firstfile.c”和“secondfile.c” 如何使第一个文件整个分配进入“firstfile”部分,第二个文件位于“secondfile”部分?

目前 .text 都在 secondfile 部分。 在 firstfile.c 中的每个函数上使用特殊属性部分没有帮助

【问题讨论】:

    标签: linker embedded ld


    【解决方案1】:

    在您的链接器脚本片段中,firstfilesecondfileMEMORY 区域而不是 SECTIONS,因此(我猜)部分属性将被忽略,因为这些部分不存在。

    您必须创建MEMORY 区域,在其中放置SECTIONS,然后将目标代码中定义的部分分配给链接描述文件中声明的部分。请注意,定位的是 目标代码,而不是源文件 - 链接器对源文件一无所知:

    类似:

    MEMORY
    {
        FIRST_MEMORY  : ORIGIN = 0x00000000, LENGTH = 0x2000 
        SECOND_MEMORY : ORIGIN = 0x00002000, LENGTH = 0x6000
    }
    
    SECTIONS
    {
      .firstsection :
      {
        . = ALIGN(4);
    
        *firstfile.o (.text .text*)   /* Locate firstfile text sections here */
    
      } > FIRST_MEMORY
    
      .secondsection :
      {
        . = ALIGN(4);
    
        *secondfile.o (.text .text*)  /* Locate secondfile text sections here */
    
      } > SECOND_MEMORY
    }
    

    然后,您可以明确地为每个部分定位任意数量的模块。

    您可能需要一个默认位置来放置未明确定位的模块。在这种情况下,您应该添加:

    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    

    到其中一个部分(或创建一个单独的默认 .text 部分)。

    如果你添加:

    *(.firstsection*)  /* Locate anything with firstsection attribute here */
    

    *(.secondsection*) /* Locate anything with secondsection attribute here */
    

    对于各个部分,您可以使用代码中的__section__ 属性将特定函数(或数据)定位到这些部分,就像您之前尝试的那样。但是最好定位整个模块,因为它不需要修改和维护代码。

    【讨论】:

      猜你喜欢
      • 2015-11-03
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 2012-12-19
      • 2013-03-02
      • 2010-11-20
      相关资源
      最近更新 更多