From 87548867089717cbb431a617566841c3db3c6963 Mon Sep 17 00:00:00 2001 From: Huaqi Fang <578567190@qq.com> Date: Thu, 27 Jun 2024 10:46:42 +0800 Subject: [PATCH] build: add nuclei_llvm experimental support still not working for both terapines and nuclei_llvm $ make TOOLCHAIN=nuclei_llvm DOWNLOAD=sram -j run_qemu Run program helloworld.elf on qemu-system-riscv32 qemu-system-riscv32 -M nuclei_evalsoc,download=sram -cpu nuclei-n100m,ext= -icount shift=0 -nodefaults -nographic -serial stdio -kernel helloworld.elf qemu-system-riscv32: Some ROM regions are overlapping These ROM regions might have been loaded by direct user request or by default. They could be BIOS/firmware images, a guest kernel, initrd or some other file loaded into guest memory. Check whether you intended to load all this guest code, and whether it has been built to load to the correct addresses. The following two regions overlap (in the memory address space): helloworld.elf ELF program header segment 1 (addresses 0x0000000080000100 - 0x00000000a0000338) helloworld.elf ELF program header segment 0 (addresses 0x0000000080000180 - 0x00000000800001f2) when compile with terapines zcc $ make TOOLCHAIN=terapines DOWNLOAD=sram clean all see helloworld.map 80000100 80000100 80 4 .isr_vector 80000100 80000100 80 4 ../../../SoC/evalsoc/Common/Source/sy stem_evalsoc.c.o:(.mintvec) 80000100 80000100 80 1 vector_base 80000100 80000100 0 1 $d.14 a00000f2 a00000f2 aa 1 .init // FIXME this should be a0000000 a00000000 a00000f2 a00000f2 a8 1 ../../../SoC/evalsoc/Common/Source/GC C/startup_evalsoc.S.o:(.text.init) a00000f2 a00000f2 0 1 a00000f2 a00000f2 0 1 $x.0 $ make TOOLCHAIN=nuclei_llvm DOWNLOAD=flashxip clean all Linking : helloworld.elf ld.lld: error: section '.exception' will not fit in region 'flash': overflowed by 1602224620 bytes ld.lld: error: section '.isr_vector' will not fit in region 'flash': overflowed by 1602224512 bytes ld.lld: error: section '.eh_frame' will not fit in region 'flash': overflowed by 1602225328 bytes ld.lld: error: section '.init' will not fit in region 'flash': overflowed by 1602225508 bytes ld.lld: error: section '.init' will not fit in region 'flash': overflowed by 1602225508 bytes ld.lld: error: section '.text' will not fit in region 'flash': overflowed by 1602249928 bytes ld.lld: error: section '.text' will not fit in region 'flash': overflowed by 1602249928 bytes ld.lld: error: section '.data' will not fit in region 'flash': overflowed by 1602250400 bytes ld.lld: error: section '.tdata' will not fit in region 'flash': overflowed by 1602250400 bytes riscv64-unknown-elf-clang: error: ld command failed with exit code 1 (use -v to see invocation) make: *** [../../../Build/Makefile.rules:98: helloworld.elf] Error 1 $ make TOOLCHAIN=terapines DOWNLOAD=flashxip clean all Linking : helloworld.elf ld.lld: error: section '.exception' will not fit in region 'flash': overflowed by 1602224620 bytes ld.lld: error: section '.isr_vector' will not fit in region 'flash': overflowed by 1602224512 bytes ld.lld: error: section '.init' will not fit in region 'flash': overflowed by 1602224916 bytes ld.lld: error: section '.init' will not fit in region 'flash': overflowed by 1602224916 bytes ld.lld: error: section '.text' will not fit in region 'flash': overflowed by 1602243480 bytes ld.lld: error: section '.text' will not fit in region 'flash': overflowed by 1602243480 bytes ld.lld: error: section '.data' will not fit in region 'flash': overflowed by 1602243568 bytes ld.lld: error: section '.tdata' will not fit in region 'flash': overflowed by 1602243568 bytes zcc: error: ld command failed with exit code 1 (use -v to see invocation) make: *** [../../../Build/Makefile.rules:98: helloworld.elf] Error 1 Signed-off-by: Huaqi Fang <578567190@qq.com> --- Build/Makefile.conf | 4 +- Build/toolchain/nuclei_gnu.mk | 4 ++ Build/toolchain/nuclei_llvm.mk | 105 +++++++++++++++++++++++++++++++++ Build/toolchain/terapines.mk | 4 ++ 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 Build/toolchain/nuclei_llvm.mk diff --git a/Build/Makefile.conf b/Build/Makefile.conf index b7e173f1..c6e3c7a9 100644 --- a/Build/Makefile.conf +++ b/Build/Makefile.conf @@ -128,8 +128,8 @@ endif include $(NUCLEI_SDK_BUILD)/Makefile.toolchain # For N100, access must be strict alignment, unaligned access is not supported -# So we must pass -mstrict-align, see https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html -COMMON_FLAGS += -g -fno-common -mstrict-align +# So we must pass -mstrict-align gcc like option which is done in toolchain/*.mk +COMMON_FLAGS += -g -fno-common COMMON_FLAGS += $(APP_COMMON_FLAGS) $(GC_CFLAGS) \ -DDOWNLOAD_MODE=DOWNLOAD_MODE_$(DOWNLOAD_UPPER) \ -DDOWNLOAD_MODE_STRING=\"$(DOWNLOAD_UPPER)\" \ diff --git a/Build/toolchain/nuclei_gnu.mk b/Build/toolchain/nuclei_gnu.mk index dac53ffb..3861a8b4 100644 --- a/Build/toolchain/nuclei_gnu.mk +++ b/Build/toolchain/nuclei_gnu.mk @@ -118,6 +118,10 @@ COMMON_FLAGS += -DSIMULATION_MODE=$(SIMULATION_MODE) endif COMMON_FLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -mcmodel=$(RISCV_CMODEL) +# For N100, access must be strict alignment, unaligned access is not supported +# So we must pass -mstrict-align, see https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html +COMMON_FLAGS += -mstrict-align + ## Append mtune options when RISCV_TUNE is defined ## It might be defined in SoC//build.mk, and can be overwritten by make ifneq ($(RISCV_TUNE),) diff --git a/Build/toolchain/nuclei_llvm.mk b/Build/toolchain/nuclei_llvm.mk new file mode 100644 index 00000000..3bce995d --- /dev/null +++ b/Build/toolchain/nuclei_llvm.mk @@ -0,0 +1,105 @@ +CC := riscv64-unknown-elf-clang +CXX := riscv64-unknown-elf-clang++ +OBJDUMP := riscv64-unknown-elf-objdump +OBJCOPY := riscv64-unknown-elf-objcopy +# use gnu gdb to debug or upload +GDB := riscv64-unknown-elf-gdb +AR := llvm-ar +SIZE := llvm-size +OPENOCD := openocd + + +# Handle standard c library selection variable STDCLIB +ifneq ($(findstring newlib,$(STDCLIB)),) +### Handle cases when STDCLIB variable has newlib in it +ifeq ($(STDCLIB),newlib_full) +LDLIBS += -lc -lgcc +else ifeq ($(STDCLIB),newlib_fast) +LDLIBS += -lc_nano -lgcc +STDCLIB_LDFLAGS += -u _printf_float -u _scanf_float +COMMON_FLAGS += -isystem=/include/newlib-nano +else ifeq ($(STDCLIB),newlib_small) +LDLIBS += -lc_nano -lgcc +STDCLIB_LDFLAGS += -u _printf_float +COMMON_FLAGS += -isystem=/include/newlib-nano +else ifeq ($(STDCLIB),newlib_nano) +LDLIBS += -lc_nano -lgcc +# work around for relocation R_RISCV_PCREL_HI20 out of range: -524289 is not in [-524288, 524287]; references _printf_float when compile with rv64 +# so with this change below, newlib_nano = newlib_small now +STDCLIB_LDFLAGS += -u _printf_float +COMMON_FLAGS += -isystem=/include/newlib-nano +else +LDLIBS += -lc_nano -lgcc +# work around for relocation R_RISCV_PCREL_HI20 out of range: -524289 is not in [-524288, 524287]; references _printf_float when compile with rv64 +STDCLIB_LDFLAGS += -u _printf_float +COMMON_FLAGS += -isystem=/include/newlib-nano +endif +### +else ifneq ($(findstring libncrt,$(STDCLIB)),) +### Handle cases when STDCLIB variable has libncrt in it +LDLIBS += -l$(patsubst lib%,%,$(STDCLIB)) +ifneq ($(NCRTHEAP),) +LDLIBS += -lheapops_$(NCRTHEAP) +endif +### +else ifeq ($(STDCLIB),nostd) +### Handle cases when no standard system directories for header files +COMMON_FLAGS += -nostdinc +### +else ifeq ($(STDCLIB),nospec) +### Handle cases no specs configs are passed +COMMON_FLAGS += +### +else +LDLIBS += -lc_nano -lgcc +### +endif + +ifneq ($(SEMIHOST),) +ifneq ($(findstring libncrt,$(STDCLIB)),) +LDLIBS += -lfileops_semi +else +LDLIBS += -lsemihost +endif +else +ifneq ($(findstring libncrt,$(STDCLIB)),) +ifneq ($(NCRTIO),) +LDLIBS += -lfileops_$(NCRTIO) +endif +endif +endif + +## Link with standard c++ library +LDLIBS += -lstdc++ + +## Heap and stack size settings +## It will define symbols only used in linker script +## __STACK_SIZE and __HEAP_SIZE are not a c marco +## they are ld symbols used by linker +ifneq ($(STACKSZ),) +LDFLAGS += -Wl,--defsym=__STACK_SIZE=$(STACKSZ) +endif +ifneq ($(HEAPSZ),) +LDFLAGS += -Wl,--defsym=__HEAP_SIZE=$(HEAPSZ) +endif + +## SIMU=xlspike/qemu +### enable run on xlspike and qemu auto-exit if return from main +ifneq ($(SIMU),) +SIMULATION_MODE=SIMULATION_MODE_$(call uc, $(SIMU)) +COMMON_FLAGS += -DSIMULATION_MODE=$(SIMULATION_MODE) +endif + +COMMON_FLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -mcmodel=$(RISCV_CMODEL) +## Append mtune options when RISCV_TUNE is defined +## It might be defined in SoC//build.mk, and can be overwritten by make +ifneq ($(RISCV_TUNE),) +COMMON_FLAGS += +endif + +ifneq ($(findstring newlib,$(STDCLIB)),) +#LDFLAGS += -u _isatty -u _write -u _sbrk -u _read -u _close -u _fstat -u _lseek +LDFLAGS += -u __on_exit_args +endif +# -nodefaultlibs to ignore the auto added -lc -lgloss in RISCV::Linker::ConstructJob of clang/lib/Driver/ToolChains/RISCVToolchain.cpp +LDFLAGS += -fuse-ld=lld -nodefaultlibs diff --git a/Build/toolchain/terapines.mk b/Build/toolchain/terapines.mk index c6899504..95db0133 100644 --- a/Build/toolchain/terapines.mk +++ b/Build/toolchain/terapines.mk @@ -86,6 +86,10 @@ COMMON_FLAGS += -DSIMULATION_MODE=$(SIMULATION_MODE) endif COMMON_FLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -mcmodel=$(RISCV_CMODEL) +# For N100, access must be strict alignment, unaligned access is not supported +# So we must pass -mstrict-align +COMMON_FLAGS += -mstrict-align + ## Append mtune options when RISCV_TUNE is defined ## It might be defined in SoC//build.mk, and can be overwritten by make ifneq ($(RISCV_TUNE),)