I am trying to write a simple C program without including standard libraries and trying to compile and run with gcc. but I was getting segmentation fault( core dumped )
main.c:
int main(){}
commands executed:
- gcc main.c -c -ffreestanding
- gcc main.o -e main -nostdlib
- ./a.out
output:
Segmentation fault (core dumped)
any help would be greatly appreciated.
CodePudding user response:
Besides the problem mentioned in the comments, there is also a problem during the link time. If you run it with the flag -nostdlib
, it will ignore the symbol symbol _start
, which is part of a default library, crt0.o
.