I am trying to build an application statically for RISC-V without standard includes and without a standard lib, and instead am trying to link in a statically built musl-libc using its libc.a and crt1.o files (Note, I built crt1.o into a static library libcrt1.a).
The following is my program:
#include <stdio.h>
int main()
{
printf("Hello world!");
return 0;
}
And here is my Makefile:
CC=/home/john/deps/install/opt/riscv/bin/riscv64-unknown-elf-gcc
CFLAGS=-Wall -g --static -static-libgcc -nostdinc -nostdlib -I/home/john/musl-1.1.23/install/include
LDFLAGS=-L/home/john/deps/install/opt/riscv/lib/gcc/riscv64-unknown-elf/8.1.0 -L/home/john/musl-1.1.23/install/lib -lc -lgcc -lcrt1
hello.elf: hello.c
${CC} ${CFLAGS} -o $@ $^ ${LDFLAGS}
clean:
rm -f hello.elf
When I try to make this, I get the following error:
/home/john/musl-1.1.23/install/lib/libcrt1_weak.a(crt1.o): In function `_start_c':
/home/john/musl-1.1.23/crt/crt1.c:18: undefined reference to `__libc_start_main'
collect2: error: ld returned 1 exit status
Makefile:6: recipe for target 'hello.elf' failed
However, when I inspect the symbols of libc and libcrt1, I find that __libc_start_main is a GLOBAL symbol defined in libc:
File: libc.a(__libc_start_main.o)
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS __libc_start_main.c
323: 0000000000000000 112 FUNC GLOBAL DEFAULT 14 __libc_start_main
(Here is the printout of the symbol in libcrt1 for clarity):
88: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND __libc_start_main
Any help understanding why this global symbol is not being resolved would be greatly appreciated.