English 中文(简体)
确切地说,一个C工具链预计会与光金属发展有什么联系?
原标题:What, exactly, does a C toolchain expect to be linked with for bare-metal development?

我曾做过一个牢固的C发展轨道,但总是来自供应商内部的 garden园。 由于这是一次毫不含糊的可怕经验,因为我最近提出的一个项目是让海合会、开放式海委会、非洲开发银行和埃恩茨在我通常的含水层环境中玩.。 我已经对项目进行了测试,并做了很好的工作,但我对无法查获的Im链接错误进行了研究,我想知道,除了具体错误外,这几类事情还有debuggingmeth

我的实际问题: 我有一个通过其“发射台”的跳板“TI tm4c123”。 I m 编辑从32个轨道档案。 缩略语 没有任何问题;它完全是汇编、闪电和清醒。 直到我需要<代码>。 然后,从研究无数其他问题来看,“未明确提及......sbrk:”似乎与在提供<条码>libc所用扫描定义的图书馆之间没有联系。 罚款。 通过链式图书馆搜索途径,我发现libnosys.a,但与这一条相联系似乎只是将问题推向一步,并产生了“未明确提及” 此时此刻,我担心linker script上的ug。 I m 使用或其他类似低级别问题。

While I d welcome a quick resolution to my particular problem ("add option foo to compile step bar" or something), I d actually prefer if, in addition, anyone could point me to resources that would help me understand how MCUs, embedded ABIs, linkers, and libraries all interact―what, exactly, are the assumptions that the arm-none-eabi-gcc toolchain is making about the execution environment and the code that ll eventually get linked in? How does one modify or satisfy those assumptions, in order to actually get an .elf that flashes and runs correctly on an MCU? There seem to be a great many questions related to similarly-named errors, and they range over a large variety of actual underlying bugs. Understanding exactly what the tools are doing and why would help greatly in sorting out the differences.

Here s a minimum non-working example, for discussion:

// ./main.c
#include <stdlib.h>
#include <stdint.h>

int main() {
  uint8_t *ptr = malloc(3);
  ptr[0] = 0xb0;
  ptr[1] = 0x0b;
  
}
# ./Makefile
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld


CFLAGS = -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections 
    -fdata-sections -MD  -std=c2x -Wall -Wextra -Werror -DPART_${MCU} -c -O0 -Dgcc -ggdb


LIBGCC := ${shell ${CC} ${CFLAGS} -print-libgcc-file-name}
LIBC := ${shell ${CC} ${CFLAGS} -print-file-name=libc.a}
LIBM := ${shell ${CC} ${CFLAGS} -print-file-name=libm.a}
LIBSTUB := ${shell ${CC} ${CFLAGS} -print-file-name=libnosys.a}
LDFLAGS = -T linkerscript.ld -e Reset_Handler --gc-sections   ${LIBM}    ${LIBGCC}   ${LIBC}   ${LIBSTUB} 



all: mwe.elf

startup.o: startup.c
    $(CC) -o $@ $^ $(CFLAGS)

main.o: main.c
    $(CC) -o $@ $^ $(CFLAGS)

mwe.elf: main.o startup.o
    $(LD) -o $@ $^ $(LDFLAGS)


.PHONY: all

Include also the ./startup.h, ./startup.c, and ./linkerscript.ld files from the project guide linked above; I omitted them for brevity. Putting all mentioned files in a single directory and running make (with an ARM gcc toolchain installed: arm-none-eabi-gcc, arm-none-eabi-newlib, and arm-none-eabi-binutils for me on Arch) has reproduced the exact error, along with some extra warnings.

问题回答

首先,序言:嵌入式系统一般设计为小型和针对具体目标。 典型的嵌入式应用doesn t need 该图书馆的全权,以及doesn tech<>m>,要么因为记忆的大小确实是嵌入式系统的事项。 因此,专门标准图书馆,如<代码>newlib,的设计是为了认真满足这些应用的要求。

For a brief but detailed explanation of the general compilation and linking process you can refer to this link. This process clearly applies to microprocessors as well as MCU like Cortex-M4. Compilers like arm-none-eabi include in their release the newlib library compiled with a specific configuration (see this and this to understand what it means) and this library can be linked as you did in your makefile or can be totally ignored with the nostdlib compilation option for applications that don t need it and/or want to implement the functions by themselves.

<代码>newlib提供标准图书馆功能的履行情况,例如<编码>memcpy和strcat,以及低水平的具体目标,如_aeabi_uldivmod(关于未签署64 bit integers的划分)。 该系统还提供最低程度的安装系统电话:here,包括。 直接使用<条码>。 由于这些职能与监督厅密切相关,因为该办公室无法存在于一个嵌入式系统之中,因此,它要由用户来决定是否使用从图书馆进行的扫描或自行实施。

您能把申请联系起来的原因是,没有提及文号end,该编号为sbrk<>。 让我们考虑从新的平衡网站:

caddr_t
_sbrk (int incr)
{
  extern char end asm ("end"); /* Defined by the linker.  */
  static char * heap_end;
  char * prev_heap_end;

  if (heap_end == NULL)
    heap_end = & end;
  
  prev_heap_end = heap_end;
  
  if (heap_end + incr > stack_ptr)
    {
      /* Some of the libstdc++-v3 tests rely upon detecting
     out of memory errors, so do not abort here.  */
#if 0
      extern void abort (void);

      _write (1, "_sbrk: Heap and stack collision
", 32);
      
      abort ();
#else
      errno = ENOMEM;
      return (caddr_t) -1;
#endif
    }
  
  heap_end += incr;

  return (caddr_t) prev_heap_end;
}

基本上,这项职能按照所要求的记忆规模更新了目前的头盔,并恢复了以往的价值。 最初,标题指符号end的地址,正如该代码本身指出的那样,这些地址必须由联系人通过链接稿加以界定。

从对<代码>sbrk功能的ack碰撞检查中查阅。 我们可以假设,蒸.必须从<条码>末/条码>开始,并呈上升趋势,而脚步必须从<条码>末/条码>开始,并呈下降趋势。 因此,将<条码>末<>>>> 代码/代码>符号列入链接文字的假设方法是:

MEMORY
{
    FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K /* FLASH size 256KB */
    RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K/* RAM size 32KB */
}

SECTIONS
{
    PROVIDE( _stack_ptr = ORIGIN(RAM) + LENGTH(RAM));

    /* .text, .data, .bss, .rodata */

    . = ALIGN(4);
    end = . ;   /* Heap start */
}

这样一来,分站开始于区域援助团的末端,向下发展,而分机则在编码各节之后开始在<代码>end上,并呈下降趋势。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...