diff --git a/litex/soc/cores/cpu/__init__.py b/litex/soc/cores/cpu/__init__.py index 63b935541..3b39aa2f0 100644 --- a/litex/soc/cores/cpu/__init__.py +++ b/litex/soc/cores/cpu/__init__.py @@ -52,6 +52,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..6176f4b5b 100644 --- a/litex/soc/integration/export.py +++ b/litex/soc/integration/export.py @@ -18,6 +18,7 @@ # SPDX-License-Identifier: BSD-2-Clause import os +import re import json import time import datetime @@ -89,9 +90,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()).group(1).split(".") + if int(binutils_version[1]) >= 2 and int(binutils_version[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