Skip to content

Commit

Permalink
build: add nuclei_llvm experimental support
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
fanghuaqi committed Jun 27, 2024
1 parent 4eaef31 commit 8754886
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Build/Makefile.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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)\" \
Expand Down
4 changes: 4 additions & 0 deletions Build/toolchain/nuclei_gnu.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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/<SOC>/build.mk, and can be overwritten by make
ifneq ($(RISCV_TUNE),)
Expand Down
105 changes: 105 additions & 0 deletions Build/toolchain/nuclei_llvm.mk
Original file line number Diff line number Diff line change
@@ -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/<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
4 changes: 4 additions & 0 deletions Build/toolchain/terapines.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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/<SOC>/build.mk, and can be overwritten by make
ifneq ($(RISCV_TUNE),)
Expand Down

0 comments on commit 8754886

Please sign in to comment.