Skip to content

Commit

Permalink
fe310: Support the LLVM toolchain (i.e. compilation with clang)
Browse files Browse the repository at this point in the history
This requires -nostartfiles to be only passed to the linker, not the
compiler, as it is a linker flag and passing it to the compiler causes a
clang warning to be emitted.

Additionally, clang does not seem to support `-mcmodel=medlow` and
`-msmall-data-limit=8` but these options do not seem strictly necessary
to me anyhow thus they are deactivated conditionally when using clang.
  • Loading branch information
nmeum committed Oct 7, 2020
1 parent 3a9f8d5 commit 125e4b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cpu/riscv_common/Makefile.include
@@ -1,6 +1,8 @@
CFLAGS += -Wno-pedantic
INCLUDES += -I$(RIOTCPU)/riscv_common/include

TOOLCHAINS_SUPPORTED = gnu llvm

# All variables must be defined in the CPU configuration when using the common
# `ldscripts/riscv.ld`
ifneq (,$(ROM_START_ADDR)$(RAM_START_ADDR)$(ROM_LEN)$(RAM_LEN))
Expand Down
13 changes: 10 additions & 3 deletions makefiles/arch/riscv.inc.mk
Expand Up @@ -30,8 +30,15 @@ TARGET_ARCH_RISCV ?= \
TARGET_ARCH ?= $(TARGET_ARCH_RISCV)

# define build specific options
CFLAGS_CPU = -march=rv32imac -mabi=ilp32 -mcmodel=medlow -msmall-data-limit=8
CFLAGS_LINK = -nostartfiles -ffunction-sections -fdata-sections
CFLAGS_CPU = -march=rv32imac -mabi=ilp32
ifeq ($(TOOLCHAIN),llvm)
# Always use riscv32-none-elf as target triple for clang, as some
# autodetected gcc target triples are incompatible with clang
TARGET_ARCH_LLVM := riscv32-none-elf
else
CFLAGS_CPU += -mcmodel=medlow -msmall-data-limit=8
endif
CFLAGS_LINK = -ffunction-sections -fdata-sections
CFLAGS_DBG ?= -g3
CFLAGS_OPT ?= -Os

Expand All @@ -42,4 +49,4 @@ LINKFLAGS += -T$(LINKER_SCRIPT)
CFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) $(CFLAGS_LINK)
ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG)
# export linker flags
LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) -Wl,--gc-sections -static -lgcc
LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) -nostartfiles -Wl,--gc-sections -static -lgcc

0 comments on commit 125e4b5

Please sign in to comment.