optimize LTO

This commit is contained in:
Kizarm 2024-10-13 15:29:09 +02:00
parent b4f5dd0670
commit c1cf18d047
5 changed files with 33 additions and 37 deletions

View file

@ -1,25 +1,25 @@
TARGET?= ch32v203
TOOL ?= gcc TOOL ?= gcc
#TOOL ?= clang #TOOL ?= clang
TARGET = ch32v203
PRJ = example PRJ = example
VPATH += ./ch32v203
VPATH = . ./$(TARGET)
BLD = ./build/ BLD = ./build/
DFLAGS = -d DFLAGS = -d
LFLAGS = -g LFLAGS = -g
LDLIBS = LDLIBS =
BFLAGS = --strip-unneeded BFLAGS = --strip-unneeded
CFLAGS = -MMD -Wall -Wno-format -Wno-parentheses -ggdb -fno-exceptions -ffunction-sections -fdata-sections CFLAGS = -MMD -Wall -Wno-parentheses -ggdb -fno-exceptions -ffunction-sections -fdata-sections
CFLAGS+= -I. -I./ch32v203 CFLAGS+= -I. -I./$(TARGET)
DEL = rm -f DEL = rm -f
# zdrojaky # zdrojaky
OBJS = main.o hack.o print.o OBJS = main.o hack.o print.o
OBJS += startup.o system.o usb_desc.o OBJS += usb_desc.o cdc_class.o
OBJS += cdc_class.o
include $(TOOL).mk include $(TARGET)/$(TOOL).mk
BOBJS = $(addprefix $(BLD),$(OBJS)) BOBJS = $(addprefix $(BLD),$(OBJS))
all: $(BLD) $(PRJ).elf all: $(BLD) $(PRJ).elf
@ -36,9 +36,6 @@ $(PRJ).elf: $(BOBJS)
-@echo "OK." -@echo "OK."
$(COPY) $(BFLAGS) -O binary $(PRJ).elf $(PRJ).bin $(COPY) $(BFLAGS) -O binary $(PRJ).elf $(PRJ).bin
# preloz co je potreba # preloz co je potreba
$(BLD)%.o: %.S
-@echo [AS $(TOOL),$(TARGET)] $@
$(AS) -$(CCPU) $< -o $@
$(BLD)%.o: %.c $(BLD)%.o: %.c
-@echo [CC $(TOOL),$(TARGET)] $@ -@echo [CC $(TOOL),$(TARGET)] $@
@$(CC) -std=gnu99 -c $(CFLAGS) $< -o $@ @$(CC) -std=gnu99 -c $(CFLAGS) $< -o $@
@ -51,5 +48,5 @@ flash: $(PRJ).elf
minichlink -w $(PRJ).bin flash -b minichlink -w $(PRJ).bin flash -b
# vycisti # vycisti
clean: clean:
$(DEL) $(BLD)* *.lst *.bin *.elf *.map *~ mystrings.inc $(DEL) $(BLD)* *.lst *.bin *.elf *.map *~
.PHONY: all clean flash run .PHONY: all clean flash run

View file

@ -6,13 +6,13 @@ LD = ld.lld
SIZE = llvm-size SIZE = llvm-size
DUMP = riscv64-unknown-elf-objdump DUMP = riscv64-unknown-elf-objdump
COPY = riscv64-unknown-elf-objcopy COPY = riscv64-unknown-elf-objcopy
AS = riscv64-unknown-elf-as
#OBJS += startup.o system.o OBJS += startup.o system.o
CCPU = -march=rv32imac -mabi=ilp32 CCPU = -march=rv32imac -mabi=ilp32
MCPU = $(CCPU) MCPU = $(CCPU)
TRIP = riscv32-unknown-none-elf TRIP = riscv32-unknown-none-elf
CFLAGS+= -Oz CFLAGS+= -Oz
CFLAGS+= -flto
CFLAGS+= -fmessage-length=0 -fsigned-char -I/usr/include/newlib CFLAGS+= -fmessage-length=0 -fsigned-char -I/usr/include/newlib
#CFLAGS+= -fconstexpr-steps=2097152 #CFLAGS+= -fconstexpr-steps=2097152
CFLAGS+= --target=$(TRIP) $(MCPU) CFLAGS+= --target=$(TRIP) $(MCPU)
@ -20,6 +20,6 @@ LFLAGS+= --Map=$(@:%.elf=%.map) --gc-sections
# 16-bit instrukce se do toho asi dostanou až na úrovni LLVM linkeru. # 16-bit instrukce se do toho asi dostanou až na úrovni LLVM linkeru.
# Bohužel to není nikde pořádně popsáno. # Bohužel to není nikde pořádně popsáno.
LFLAGS+= -mllvm -mattr=+c LFLAGS+= -mllvm -mattr=+c
LFLAGS+= -lto-O3
LFLAGS+= -nostdlib LFLAGS+= -nostdlib
#LDLIBS+= -L$(SRCDIR)/Ld -T Link.ld LDLIBS+= -L./$(TARGET) -T script.ld
LDLIBS+= -L./ch32v203 -T script.ld

View file

@ -0,0 +1,20 @@
# Use gcc / binutils toolchain
PREFIX = riscv64-unknown-elf-
CC = $(PREFIX)gcc
CXX = $(PREFIX)g++
LD = $(PREFIX)gcc
SIZE = $(PREFIX)size
DUMP = $(PREFIX)objdump
COPY = $(PREFIX)objcopy
OBJS += startup.o system.o
CFLAGS+= -Os
CFLAGS+= -flto
CCPU = -march=rv32imac -mabi=ilp32
MCPU = $(CCPU)
CFLAGS+= $(MCPU) -msmall-data-limit=8 -mno-save-restore -fmessage-length=0 -fsigned-char -I/usr/include/newlib
LFLAGS+= -Wl,--Map=$(@:%.elf=%.map),--gc-sections
#LFLAGS+= -Wl,--print-sysroot -- chyba ld ?
LFLAGS+= -flto
LFLAGS+= -Os $(MCPU) -nostartfiles -nostdlib
LDLIBS+= -lgcc -L./$(TARGET) -T script.ld

View file

@ -1,4 +1,4 @@
ENTRY( Init ) ENTRY( InterruptVector )
MEMORY MEMORY
{ {
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K

View file

@ -1,21 +0,0 @@
# Use gcc / binutils toolchain
PREFIX = riscv64-unknown-elf-
CC = $(PREFIX)gcc
CXX = $(PREFIX)g++
LD = $(PREFIX)gcc
AS = $(PREFIX)as
SIZE = $(PREFIX)size
DUMP = $(PREFIX)objdump
COPY = $(PREFIX)objcopy
#OBJS += startup.o system.o
CFLAGS+= -Os
CCPU = -march=rv32imac -mabi=ilp32
MCPU = $(CCPU)
CFLAGS+= $(MCPU) -fmessage-length=0 -I/usr/include/newlib
LFLAGS+= -Wl,--Map=$(@:%.elf=%.map),--gc-sections
#LFLAGS+= -Wl,--print-sysroot -- chyba ld ?
LFLAGS+= -O3 $(MCPU) -nostartfiles -nostdlib
#LFLAGS+= -L${HOME}/Downloads/MRS_Toolchain_Linux_x64_V1.91/RISC-V_Embedded_GCC/riscv-none-embed/lib/rv32imac/ilp32 -lprintf -lc
#LDLIBS+= -L$(SRCDIR)/Ld -T Link.ld
LDLIBS+= -L./ch32v203 -T script.ld