【问题标题】:Why doesn't arm-none-eabi-gcc search for my custom _start symbol?为什么 arm-none-eabi-gcc 不搜索我的自定义 _start 符号?
【发布时间】:2016-01-21 12:39:49
【问题描述】:

我正在用“-nostdlib”编译下面的代码。我的理解是 arm-none-eabi-gcc 不会使用“crt0.o”中的_start,但会使用用户定义的_start。为此,我希望创建一个 start.S 文件并放置 _start 符号。

但是,如果我编译下面显示的代码而没有从我这边定义 _start 符号,我不会收到任何警告。我期待“警告:找不到条目符号_start;”

问题:

1) 为什么我没有收到警告? GCC 是从哪里得到 _start 符号的?

2) 如果 gcc 从某个地方的文件中获取了 _start 符号,您能告诉我如何让 GCC 使用我的 start.S 文件中的 _start 吗?

$ cat test.c

int main()
{
    volatile int i=0;
    i = i+1;

    return 0;
}

$ cat linker.ld

MEMORY
{
    ram : ORIGIN = 0x8000, LENGTH = 20K
}

SECTIONS
{
    .text : { *(.text*) } > ram
    .bss : { *(.bss*) } > ram
}

$ arm-none-eabi-gcc -Wall -Werror -O2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostdlib -T linker.ld 测试。 c -o test.o

$ arm-none-eabi-gcc --version

arm-none-eabi-gcc(用于 ARM 嵌入式处理器的 GNU 工具)4.9.3 20150529 >(发布)[ARM/embedded-4_9-branch 修订版 224288]

【问题讨论】:

    标签: c gcc arm


    【解决方案1】:

    编译并链接arm-none-eabi-gcc -v -Wall -Werror -O2....了解编译器在做什么(以及它正在使用哪个crt0crt0可能有一个_start调用你的main_start 也可能是链接器的默认入口点)

    注意-nostdlib 与(缺少)C standard library 相关;也许你想在一个独立的环境中编译(见this),然后use -ffreestanding(在那种情况下main没有特别的意义,你需要定义你的起始函数[s],并且没有标准的C函数像mallocprintf 可用,除了 setjmp)。

    阅读 C99 标准 n1256 草案。它解释了 §5.1.2.1 中的独立式含义

    【讨论】:

    • -v GCC 中的选项没有给我任何关于使用哪个 crt0 的信息。我搜索了 crt0、crt1、*.S 文件以及 _start。同样使用 -ffreestanding,我没有收到警告。
    • 链接arm-none-eabi-gcc -v -Wall -Werror -O2了吗?
    • 是的,我链接了。因为最后我定义了链接器文件,并且 test.o 是我的最终输出。在独立模式下,这就是“启动功能”?
    • 您应该阅读该标准。独立式 C 没有标准启动函数的概念,它是特定于实现的(并且可能是用户特定的)
    • 好的。但是如果我不想要独立模式,你知道编译器从哪里得到 _start 吗?我无法从 -v 中找到任何信息
    猜你喜欢
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    相关资源
    最近更新 更多