Hi Sagar,
> Can you help me with how to build tcc on arm64 to cross-compile a program for riscv64?
The cross-compilers have much less testing than the native compilers. I recommend you make sure that the rv64 compiler can natively work with a musl system (try with a qemu image) first, then try messing with the cross-compiler.
> musl isn't compiled for riscv64. I tried to compile musl-1.2.3 with
>
> cd musl-1.2.3
> ./configure --target=riscv64 CC=riscv64-tcc
> make
>
> It shows an error which has asm module
>
> __asm__(....);
>
> I think current riscv64 cross compiler doesn't support asm. Is
riscv64-asm.c for physical hardware based on rv64 processor and not for
cross compilation?
>
> I have this feature request. Can you please add asm support for riscv64 cross compiler built on arm64
IIRC from working on the rv32 port, the rv64 asm support is somewhat barebones; so even if it had inline assembly support I sort of doubt it would compile correctly. I added functionality to my port as needed to compile assembly test programs (mostly bootstrap code); however, I haven't added the glue code required to get inline assembly working. If someone wants to patch my code to support inline assembly, I could make the assembly generation generic between rv32 and rv64 and patch mob (
https://github.com/sellicott/tcc-riscv32/blob/b57054f3a77fdcbeacf8102f3fca3a74983a137a/riscv32-asm.c#L1127 ). Be warned, I don't have significant amounts of free time, so it might take a while.
> I built a cross-compiler with
>
> ./configure --config-musl
> make cross-riscv64
>
> On using the built riscv64-tcc to compile, I get,
>
> tcc: error: file 'crt1.o' not found
> tcc: error: file 'crti.o' not found
> error: include file 'stdint.h' not found
>> Makefile that allows to set paths and flags for cross-compilers individually:
>>
>> ROOT-<target> = ... (translated to -DCONFIG_SYSROOT=...)
>> CRT-<target> = ... (translated to -DCONFIG_TCC_CRTPREFIX=...)
>> LIB-<target> = ... (translated to -DCONFIG_TCC_LIBPATHS=...)
>> INC-<target> = ... (translated to -DCONFIG_TCC_SYSINCLUDEPATHS=...)
>> DEF-<target> = ... (translated to -DDEFINES+=...)
I use the following definitions for using the newlib standard libraries with rv32 and rv64. You would need to change this to point to where rv64 musl gets installed on your host system.
```
CRT-riscv64 = /usr/riscv64-elf/lib
LIB-riscv64 = /usr/riscv64-elf/lib
INC-riscv64 = $(pwd)/../include:/usr/riscv64-elf/include
```
I do recommend getting a native compiler working on a virtual machine first, then working on the cross compiler.
I hope this is at least marginally helpful,
Thanks,
-Sam Ellicott
Soli Deo Gloria