Reduce binary sizes for the kernel and userspace apps

This commit is contained in:
2025-11-15 23:56:16 +01:00
parent e66fe4030d
commit 0a43ba36cd
7 changed files with 24 additions and 7 deletions

View File

@ -4,7 +4,8 @@ include $(ROOT)/mk/grabsrc.mk
PUTCHAR_ ?= fb
CFLAGS := -ffreestanding -Wall -Wextra -g -fcommon -nostdinc
CFLAGS := -ffreestanding -Wall -Wextra -fcommon -nostdinc \
-fdata-sections -ffunction-sections
CFLAGS += -I. \
-I$(ROOT)/limine \
@ -24,7 +25,8 @@ CFLAGS += -I. \
include arch/$(ARCH)/$(ARCH).mk
LDFLAGS += -nostdlib -static -T arch/$(ARCH)/link.ld $(shell $(CC) -print-libgcc-file-name)
LDFLAGS += -nostdlib -static -T arch/$(ARCH)/link.ld $(shell $(CC) -print-libgcc-file-name) \
--gc-sections --strip-all
SRCFILES :=

View File

@ -2,4 +2,4 @@ PREFIX := $(ROOT)/toolchain/root/bin
CC := $(PREFIX)/x86_64-elf-gcc
LD := $(PREFIX)/x86_64-elf-ld
AR := $(PREFIX)/x86_64-elf-ar
AR := $(PREFIX)/x86_64-elf-gcc-ar

View File

@ -13,4 +13,8 @@ CFLAGS += -m64 \
-fno-strict-aliasing \
-O0 \
-mno-tls-direct-seg-refs \
# -fsanitize=undefined
-fdata-sections \
-ffunction-sections \
LDFLAGS += --gc-sections \
--strip-all

View File

@ -7,6 +7,7 @@ cd build-bintuils-gdb
../binutils-gdb/configure --prefix="$PREFIX" \
--disable-nls \
--disable-werror \
--enable-gold=yes \
--target=x86_64-elf
make -j$(nproc)
make install

View File

@ -10,6 +10,7 @@ cd build-gcc
../gcc/configure --prefix="$PREFIX" \
--disable-nls \
--enable-languages=c \
--enable-lto \
--target=x86_64-elf \
--disable-bootstrap \
--without-headers \

View File

@ -6,4 +6,5 @@ CURRENT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
include $(CURRENT_DIR)/arch/$(ARCH)/$(ARCH).mk
LDFLAGS += -nostdlib -static $(shell $(CC) -print-libgcc-file-name) -T $(CURRENT_DIR)/arch/$(ARCH)/link.ld
LDFLAGS += -nostdlib -static $(shell $(CC) -print-libgcc-file-name) \
-T $(CURRENT_DIR)/arch/$(ARCH)/link.ld

View File

@ -25,4 +25,12 @@ SECTIONS {
. = ALIGN(4K);
_bss_end = .;
}
/DISCARD/ : {
*(.eh_frame)
*(.eh_frame_hdr)
*(.gcc_except_table*)
*(.note*)
*(.comment)
}
}