sifive / freedom-tools

Tools for SiFive's Freedom Platform
217 stars 52 forks source link

Symbols undefined for rv64 on Darwin #69

Closed suculent closed 3 years ago

suculent commented 3 years ago

Any idea why this happens? I have no clue, where to find the error...

<-censored->/bl_iot_sdk/toolchain/riscv/Darwin/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: <-censored->/Repositories/bl_iot_sdk-ubuntu/bl_iot_sdk/toolchain/riscv/Darwin/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/lib/rv64imafdc/lp64d/crt0.o: in function `.L0 ':
(.text+0x2e): undefined reference to `main'

Then at the crt.o file:

bl_iot_sdk/toolchain/riscv/Darwin/riscv64-unknown-elf/lib/rv64imafdc/lp64d$ nm -C ./crt0.o 
0000000000000008 t .L0 
0000000000000010 t .L0 
0000000000000024 t .L0 
0000000000000000 t .L11
                 U __global_pointer$
                 U __libc_fini_array
                 U __libc_init_array
                 U _edata
                 U _end
0000000000000000 T _start
                 U atexit
                 U exit
                 U main
                 U memset

Also in objdump those symbols seem to be undefined indeed.

$ objdump -t ./crt0.o 

./crt0.o:   file format ELF64-riscv

SYMBOL TABLE:
0000000000000000 l    d  .text  00000000 .text
0000000000000000 l    d  .data  00000000 .data
0000000000000000 l    d  .bss   00000000 .bss
0000000000000000         .text  00000000 .L11
0000000000000008         .text  00000000 .L0 
0000000000000010         .text  00000000 .L0 
0000000000000024         .text  00000000 .L0 
0000000000000000 l    d  .riscv.attributes  00000000 .riscv.attributes
0000000000000000 g     F .text  00000052 _start
0000000000000000         *UND*  00000000 __global_pointer$
0000000000000000         *UND*  00000000 _edata
0000000000000000         *UND*  00000000 _end
0000000000000000         *UND*  00000000 memset
0000000000000000         *UND*  00000000 __libc_fini_array
0000000000000000         *UND*  00000000 atexit
0000000000000000         *UND*  00000000 __libc_init_array
0000000000000000         *UND*  00000000 main
0000000000000000         *UND*  00000000 exit

When trying to run the same command in ubuntu-20 docker container, this does not fail.

Failed when using to build for pine64. https://github.com/pine64/bl_iot_sdk/issues/59?_pjax=%23js-repo-pjax-container

jim-wilson commented 3 years ago

C programs are expected to have a main function. It appears to be missing. That doens't look like a toolchain problem. The default crt0.o has a _start function that calls main. It isn't clear why you are asking about the other symbols used in crt0.o since you aren't having problems with them.

suculent commented 3 years ago

Anyway, this problem is related to something local. It does not fail this way on my other machine (with maybe older gcc but i'm not sure if that matters) and it does not fail on linux.