From c84105f39900cac700bdf7f735d9ac2504504d70 Mon Sep 17 00:00:00 2001 From: Michal Sieron Date: Thu, 19 Aug 2021 11:52:34 +0200 Subject: [PATCH] Disable LTO for picolibc and use picolibc.specs Use picolibc.specs to specify integer only printf/scanf. To do that, we need to pass specs file with options to the linker. With LTO enabled, name mapping was failing, so LTO is now disabled for picolibc compilation only. This also means, that exchange.c and arc4random.c no longer need to be recompiled and added back. --- litex/soc/software/common.mak | 3 ++- litex/soc/software/libc/Makefile | 14 +++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/litex/soc/software/common.mak b/litex/soc/software/common.mak index a2d90b96d..6d8486b5a 100644 --- a/litex/soc/software/common.mak +++ b/litex/soc/software/common.mak @@ -52,10 +52,11 @@ INCLUDES = -I$(PICOLIBC_DIRECTORY)/newlib/libc/tinystdio \ -I$(BUILDINC_DIRECTORY) \ -I$(BUILDINC_DIRECTORY)/../libc \ -I$(CPU_DIRECTORY) +PICOLIBC_SPECS = --specs=$(BUILDINC_DIRECTORY)/../libc/picolibc.specs -DPICOLIBC_INTEGER_PRINTF_SCANF COMMONFLAGS = $(DEPFLAGS) -Os $(CPUFLAGS) -g3 -fomit-frame-pointer -Wall -fno-builtin -fno-stack-protector -flto $(INCLUDES) CFLAGS = $(COMMONFLAGS) -fexceptions -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes CXXFLAGS = $(COMMONFLAGS) -std=c++11 -I$(SOC_DIRECTORY)/software/include/basec++ -fexceptions -fno-rtti -ffreestanding -LDFLAGS = -nostdlib -nodefaultlibs -Wl,--no-dynamic-linker -Wl,--build-id=none $(CFLAGS) -L$(BUILDINC_DIRECTORY) +LDFLAGS = -nostdlib -nodefaultlibs -Wl,--no-dynamic-linker -Wl,--build-id=none $(CFLAGS) -L$(BUILDINC_DIRECTORY) $(PICOLIBC_SPECS) define compilexx $(CX) -c $(CXXFLAGS) $(1) $< -o $@ diff --git a/litex/soc/software/libc/Makefile b/litex/soc/software/libc/Makefile index ab55e33c8..d57587649 100644 --- a/litex/soc/software/libc/Makefile +++ b/litex/soc/software/libc/Makefile @@ -1,7 +1,7 @@ include ../include/generated/variables.mak include $(SOC_DIRECTORY)/software/common.mak -all: libc.a iob.c.o missing.c.o exchange.c.o arc4random.c.o +all: libc.a iob.c.o missing.c.o CPUFAMILY= @@ -35,8 +35,8 @@ cpu = '$(CPU)' endian = '$(CPUENDIANNESS)' [built-in options] -c_args = [ '-DPRINTF_LEVEL=1', $(foreach flag,$(filter-out $(DEPFLAGS),$(CFLAGS)),'$(flag)',) ] -c_link_args = [ '-DPRINTF_LEVEL=1', $(foreach flag,$(LDFLAGS),'$(flag)',) ] +c_args = [ $(foreach flag,$(filter-out $(DEPFLAGS) -flto,$(CFLAGS)),'$(flag)',) ] +c_link_args = [ $(foreach flag,$(filter-out -flto,$(LDFLAGS)),'$(flag)',) ] endef export CROSSFILE @@ -68,11 +68,3 @@ missing.c.o: $(LIBC_DIRECTORY)/missing.c $(compile) $(AR) csr libc.a $@ -exchange.c.o: $(PICOLIBC_DIRECTORY)/newlib/libc/tinystdio/exchange.c - $(call compile,-fno-lto) - $(AR) csr libc.a $@ - -arc4random.c.o: $(PICOLIBC_DIRECTORY)/newlib/libc/stdlib/arc4random.c - $(call compile,-fno-lto) - $(AR) csr libc.a $@ -