arm-none-eabi-gcc 编译器的链接问题 - 警告:找不到条目符号_vectors;默认为 0000000010260000

Linking issue with arm-none-eabi-gcc compiler - warning: cannot find entry symbol _vectors; defaulting to 0000000010260000

提问人:kowshik 提问时间:5/28/2023 最后编辑:Brian Tompsett - 汤莱恩kowshik 更新时间:5/29/2023 访问量:277

问:

我正在尝试做一个非常简单的练习,如下所示

  1. 使用 arm-none-eabi-gcc 编译器编译 Cortex-R5 MCU 目标的简单 C 程序。
  2. 将其与相应的链接器文件链接并创建一个可执行文件,以便我可以加载它并进行调试。

我试过什么?

  1. 我能够使用下面提到的命令成功编译以下 C 代码
#include<stdio.h>

int main()
{
    int a = 1;
    for(int i=0;i<10;i++)
    {
        a++;
    }
    return 0;
}

使用的 gcc 命令 -arm-none-eabi-gcc -mcpu=cortex-r5 -mthumb -mfloat-abi=hard -mfpu=vfpv3-d16 --specs=nosys.specs -ffunction-sections -fdata-sections -c main.c -o hi.o

这已正确创建了一个对象文件。

我被卡在哪里?

当我尝试使用下面的链接器和链接命令时,我收到一个警告,其中向量表不正确地放置在内存中(它被放置在0x10260000 (RAM) 中,而不是0x0它必须放在的位置)

使用的链接器命令 -arm-none-eabi-gcc -mcpu=cortex-r5 -mthumb -mfloat-abi=hard -mfpu=vfpv3-d16 -Wl,-Map=output.map -Wl,-I/home/kowshik/ti/mcu_plus_sdk_am273x_08_05_00_24/source/kernel/nortos/lib/ -Wl,-Lnortos.am273x.r5f.ti-arm-clang.debug.lib -nostdlib -nostartfiles --specs=nosys.specs -T linker.ld hi.o -o hi.elf

使用的链接器文件

/* This is the stack that is used by code running within main()
 * In case of NORTOS,
 * - This means all the code outside of ISR uses this stack
 * In case of FreeRTOS
 * - This means all the code until vTaskStartScheduler() is called in main()
 *   uses this stack.
 * - After vTaskStartScheduler() each task created in FreeRTOS has its own stack
 */
__stack_size = 16384;
/* This is the heap size for malloc() API in NORTOS and FreeRTOS
 * This is also the heap used by pvPortMalloc in FreeRTOS
 */
__heap_size = 32768;
ENTRY(_vectors)/* This is the entry of the application, _vector MUST be placed at starting address 0x0 */

/* This is the size of stack when R5 is in IRQ mode
 * In NORTOS,
 * - Here interrupt nesting is enabled
 * - This is the stack used by ISRs registered as type IRQ
 * In FreeRTOS,
 * - Here interrupt nesting is disabled
 * - This is stack that is used initially when an IRQ is received
 * - But then the mode is switched to SVC mode and SVC stack is used for all user ISR callbacks
 * - Hence in FreeRTOS, IRQ stack size is less and SVC stack size is more
 */
__IRQ_STACK_SIZE = 256;
/* This is the size of stack when R5 is in IRQ mode
 * - In both NORTOS and FreeRTOS, nesting is disabled for FIQ
 */
__FIQ_STACK_SIZE = 256;
__SVC_STACK_SIZE = 4096; /* This is the size of stack when R5 is in SVC mode */
__ABORT_STACK_SIZE = 256;  /* This is the size of stack when R5 is in ABORT mode */
__UNDEFINED_STACK_SIZE = 256;  /* This is the size of stack when R5 is in UNDEF mode */

MEMORY
{
    R5F_VECS : ORIGIN = 0x00000000, LENGTH = 0x00000040
    R5F_TCMA : ORIGIN = 0x00000040, LENGTH = 0x00003FC0
    R5F_TCMB : ORIGIN = 0x00080000, LENGTH = 0x00004000

    /* when using multi-core application's i.e more than one R5F active, make sure
     * this memory does not overlap with other R5F's
     */
    MSS_L2 : ORIGIN = 0x10260000, LENGTH = 0x40000

    /* This is typically used to hold data IO buffers from accelerators like CSI, HWA, DSP */
    DSS_L3 : ORIGIN = 0x88000000, LENGTH = 0x00390000

    /* shared memories that are used by RTOS/NORTOS cores */
    /* On R5F,
     * - make sure there are MPU entries which map below regions as non-cache
     */
    USER_SHM_MEM : ORIGIN = 0x102E8000, LENGTH = 0x00004000
    LOG_SHM_MEM : ORIGIN = 0x102EC000, LENGTH = 0x00004000
    /* MSS mailbox memory is used as shared memory, we dont use bottom 32*6 bytes, since its used as SW queue by ipc_notify */
    RTOS_NORTOS_IPC_SHM_MEM : ORIGIN = 0xC5000000, LENGTH = 0x1F40
    MAILBOX_HSM : ORIGIN = 0x44000000, LENGTH = 0x000003CE
    MAILBOX_R5F : ORIGIN = 0x44000400, LENGTH = 0x000003CE
}


SECTIONS
{
    /* This has the R5F entry point and vector table, this MUST be at 0x0 */
    
    .vectors :
    {
        KEEP(*(.vectors)) /* Keep the vectors section */
    } > R5F_VECS

    /* This is rest of code. This can be placed in MSS_L2 */
    .text :
    {
        *(.text) /* Code resides here */
    } > MSS_L2

    /* This is rest of initialized data. This can be placed in MSS_L2 */
    .rodata :
    {
        *(.rodata) /* Consts go here */
    } > MSS_L2

    /* This is rest of uninitialized data. This can be placed in MSS_L2 */
    .data :
    {
        *(.data) /* Initialized globals and statics go here */
    } > MSS_L2

    /* This is where the uninitialized data goes */
    .bss :
    {
        *(.bss) /* Uninitialized globals go here */
        __bss_start__ = .; /* Symbol for BSS start address */
        *(.sysmem) /* Malloc heap goes here */
        *(.stack) /* Main stack goes here */
        __bss_end__ = .; /* Symbol for BSS end address */
    } > MSS_L2

    /* This is where the stacks for different R5F modes go */
    .irqstack :
    {
        . = ALIGN(8);
        __IRQ_STACK_START = .;
        BYTE(0); /* Reserve space for IRQ stack */
        __IRQ_STACK_END = .; /* Symbol for IRQ stack end address */
    }

    .fiqstack :
    {
        . = ALIGN(8);
        __FIQ_STACK_START = .;
        BYTE(0); /* Reserve space for FIQ stack */
        __FIQ_STACK_END = .; /* Symbol for FIQ stack end address */
    }

    .svcstack :
    {
        . = ALIGN(8);
        __SVC_STACK_START = .;
        BYTE(0); /* Reserve space for SVC stack */
        __SVC_STACK_END = .; /* Symbol for SVC stack end address */
    }

    .abortstack :
    {
        . = ALIGN(8);
        __ABORT_STACK_START = .;
        BYTE(0); /* Reserve space for ABORT stack */
        __ABORT_STACK_END = .; /* Symbol for ABORT stack end address */
    }

    .undefinedstack :
    {
        . = ALIGN(8);
        __UNDEFINED_STACK_START = .;
        BYTE(0); /* Reserve space for UNDEFINED stack */
        __UNDEFINED_STACK_END = .; /* Symbol for UNDEFINED stack end address */
    }

    /* Sections needed for C++ projects */
    .ARM.exidx :
    {
        *(.ARM.exidx) /* Needed for C++ exception handling */
    } > MSS_L2

    .init_array :
    {
        KEEP(*(SORT(.init_array.*))) /* Contains function pointers called before main */
    } > MSS_L2

    .fini_array :
    {
        KEEP(*(SORT(.fini_array.*))) /* Contains function pointers called after main */
    } > MSS_L2

    /* any data buffer needed to be put in L3 can be assigned this section name */
    .bss.dss_l3 :
    {
        *(.bss.dss_l3)
    } > DSS_L3

    /* General purpose user shared memory, used in some examples */
    .bss.user_shared_mem (NOLOAD) :
    {
        *(.bss.user_shared_mem)
    } > USER_SHM_MEM

    /* this is used when Debug log's to shared memory are enabled, else this is not used */
    .bss.log_shared_mem  (NOLOAD) :
    {
        *(.bss.log_shared_mem)
    } > LOG_SHM_MEM

    /* this is used only when IPC RPMessage is enabled, else this is not used */
    .bss.ipc_vring_mem   (NOLOAD) :
    {
        *(.bss.ipc_vring_mem)
    } > RTOS_NORTOS_IPC_SHM_MEM

    /* this is used only when Secure IPC is enabled */
    .bss.sipc_hsm_queue_mem   (NOLOAD) :
    {
        *(.bss.sipc_hsm_queue_mem)
    } > MAILBOX_HSM

    .bss.sipc_r5f_queue_mem   (NOLOAD) :
    {
        *(.bss.sipc_r5f_queue_mem)
    } > MAILBOX_R5F
}

我收到的警告 -warning: cannot find entry symbol _vectors; defaulting to 0000000010260000

我正在使用德州仪器 (TI) 的 AM273x MCU,这是 Technial 参考手册 (TRM) 的链接

我还打开了此命令生成的映射文件,我仍然看到没有部分单独分配给向量。

我可以肯定地确保在静态库中已经存在的文件中正确定义了符号。如果您需要,我可以提供有关此的更多详细信息。_vectorsnortos.am273x.r5f.ti-arm-clang.debug.lib

请在这里帮助我正确定位二进制文件中的向量表,以便我可以正确运行我的应用程序。

嵌入式 交叉编译 链接器错误 arm-none-eabi-gcc

评论


答:

0赞 Clifford 5/29/2023 #1

向量表通常是特定于应用程序的(在启动文件中,但您已经定义了)。将向量表包含在 .lib 文件中似乎很奇怪。-nostartfiles

链接器将仅链接静态库对象中的符号,前提是这些符号在任何前面的对象文件中被显式引用。您通常不会在 Cortex-M 上引用 0x0 处的默认向量表,因为硬件期望它在那里。

要强制向量表链接,它要么需要是一个独立的对象文件(通常是启动文件),要么需要显式引用它,例如,将向量表地址显式设置为即使它在任何情况下都是默认值。_vectors

评论

0赞 kowshik 5/29/2023
感谢克利福德的回答。你能告诉我如何做到这一点吗“你需要显式引用它,例如,通过显式地将向量表地址设置为_vectors,即使它在任何情况下都是默认值。
0赞 Clifford 5/29/2023
通过将其写入 VTOR 寄存器:developer.arm.com/documentation/dui0662/b/...,但我认为任何引用都会强制链接它。
0赞 kowshik 5/29/2023
我的 MCU 中没有这样的 VTOR 寄存器。
0赞 kowshik 5/29/2023
请注意,我的 MCU 不是 cortex-M。它是 cortex-r5,我们没有任何 vtor 寄存器。我通过链接器手动将其放置在0x0处。
0赞 Clifford 5/29/2023
@kowshik。道歉 - 我的疏忽。更有理由不把向量表放在库中 - 你打算如何实现特定于应用程序的中断?或者该库是否包含您将使用的所有设备驱动程序?