# Role of syscalls.c

What is the role of syscalls.c file in GNU ARM(STM32 for instance) based projects? I found 2 ways of successfully building the project

1. Delete syscalls.c and include -specs=nosys.specs in the linker flags

2. Simply include syscalls.c

What is the fundamental difference between these two methods? What is the importance of system calls in a non-os environment like microcontroller? If it is used for implementing system-level functions used by printf, scanf, etc. then who is calling these function(because I am not using any of these functions in my code)?

Edit:- As an experimental step, I deleted syscalls.c and added -specs=nosys.specs to make the linker happy then I wrote a simple malloc program to check whether it is working or not. To my surprise, it is giving the expected output. How did the malloc function work without the _sbrk definition in syscalls.c? I checked the startup file but it has only a few functions like copying data from flash to SRAM during startup, zeroing out .bss section, etc. Can I assume that it has to do something with C Runtime Library? If so where is it located?

P.S - I am using System Workbench for STM32 & STM32F4Nucleo board for this particular example

1. printf uses _write and _read. You can write your own ones for example if you want to redirect output to SWO
2. malloc & friends use _sbrk. Bur I would rather avoid dynamic allocation in the limited resources implementations. This version of _sbrk is very poor (it assumes that the stack is at the largest addresses and heap is just before etc etc).
• @Supreeth You use (in the second case) the libraries as defined in the specs file. Google about the specs gcc files. – P__J__ Sep 25 '19 at 9:52