From 89fdb49884da8d7d55f7661d21b1f336a1b7f4a5 Mon Sep 17 00:00:00 2001 From: xhe Date: Tue, 19 Apr 2022 14:07:37 +0800 Subject: [PATCH] patches for custom toolchain Signed-off-by: xhe --- litex/soc/cores/cpu/__init__.py | 1 + litex/soc/integration/export.py | 8 +++++++- litex/soc/software/common.mak | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/litex/soc/cores/cpu/__init__.py b/litex/soc/cores/cpu/__init__.py index 8f07c655f..e59426784 100644 --- a/litex/soc/cores/cpu/__init__.py +++ b/litex/soc/cores/cpu/__init__.py @@ -50,6 +50,7 @@ class CPUNone(CPU): } CPU_GCC_TRIPLE_RISCV64 = ( + "riscv64-pc-linux-musl", "riscv64-unknown-elf", "riscv64-unknown-linux-gnu", "riscv64-elf", diff --git a/litex/soc/integration/export.py b/litex/soc/integration/export.py index 1e9ab58a6..daa2a551a 100644 --- a/litex/soc/integration/export.py +++ b/litex/soc/integration/export.py @@ -89,9 +89,15 @@ def get_cpu_mak(cpu, compile_software): raise OSError(msg) return r + selected_triple = select_triple(triple) + if not clang: + binutils_version = re.match("GNU ar \(GNU Binutils\) (.+)\.(.+)", os.popen(selected_triple + "-ar -V").read()) + if int(binutils_version.group(1)) >= 2 and int(binutils_version.group(2)) >= 37 and (not re.search("zicsr", flags)): + flags = re.compile("-march=([^ ]+)").sub("-march=\\1_zicsr", flags) + # Return informations. return [ - ("TRIPLE", select_triple(triple)), + ("TRIPLE", selected_triple), ("CPU", cpu.name), ("CPUFAMILY", cpu.family), ("CPUFLAGS", flags), diff --git a/litex/soc/software/common.mak b/litex/soc/software/common.mak index e7ffe9b28..4951c5516 100644 --- a/litex/soc/software/common.mak +++ b/litex/soc/software/common.mak @@ -14,6 +14,7 @@ CX_normal := $(CCACHE) clang++ -target $(TRIPLE) -integrated-as else CC_normal := $(CCACHE) $(TARGET_PREFIX)gcc -std=gnu99 CX_normal := $(CCACHE) $(TARGET_PREFIX)g++ +GCC_INSTALLATION_PATH := $(patsubst %/libgcc.a,%,$(shell $(CC) -print-libgcc-file-name)) endif AR_normal := $(TARGET_PREFIX)gcc-ar LD_normal := $(TARGET_PREFIX)ld @@ -54,7 +55,13 @@ INCLUDES = -I$(PICOLIBC_DIRECTORY)/newlib/libc/tinystdio \ -I$(BUILDINC_DIRECTORY) \ -I$(BUILDINC_DIRECTORY)/../libc \ -I$(CPU_DIRECTORY) -COMMONFLAGS = $(DEPFLAGS) -Os $(CPUFLAGS) -g3 -fomit-frame-pointer -Wall -fno-builtin -fno-stack-protector -flto $(INCLUDES) +COMMONFLAGS = $(DEPFLAGS) -Os $(CPUFLAGS) -g3 -fomit-frame-pointer -Wall -fno-builtin -fno-stack-protector $(INCLUDES) +ifneq (,$(GCC_INSTALLATION_PATH)) +COMMONFLAGS += -nostdinc -I$(GCC_INSTALLATION_PATH)/include -I$(GCC_INSTALLATION_PATH)/include-fixed +endif +ifeq (,$(findstring musl,$(TRIPLE))) +COMMONFLAGS += -flto +endif ifneq ($(CPUFAMILY), arm) COMMONFLAGS += -fexceptions endif