diff --git a/kernel/Makefile b/kernel/Makefile index a31dc64..f65ffc8 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -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 := diff --git a/mk/arch/toolchain-x86_64.mk b/mk/arch/toolchain-x86_64.mk index 4f4ab31..f0af23a 100644 --- a/mk/arch/toolchain-x86_64.mk +++ b/mk/arch/toolchain-x86_64.mk @@ -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 diff --git a/mk/user/x86_64.mk b/mk/user/x86_64.mk index 3f33f02..2e741ed 100644 --- a/mk/user/x86_64.mk +++ b/mk/user/x86_64.mk @@ -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 diff --git a/scripts/build-binutils-gdb.sh b/scripts/build-binutils-gdb.sh index c1fc3b0..f5bc70e 100755 --- a/scripts/build-binutils-gdb.sh +++ b/scripts/build-binutils-gdb.sh @@ -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 diff --git a/scripts/build-gcc.sh b/scripts/build-gcc.sh index 1e28a7c..2bc2c52 100755 --- a/scripts/build-gcc.sh +++ b/scripts/build-gcc.sh @@ -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 \ diff --git a/user/Makefile.inc b/user/Makefile.inc index c9f7b4a..5f8afc5 100644 --- a/user/Makefile.inc +++ b/user/Makefile.inc @@ -1,9 +1,10 @@ CFLAGS := -ffreestanding -Wall -Wextra -g -fcommon -nostdinc \ - -isystem $(ROOT)/std/include -isystem $(ROOT)/ulib -isystem $(ROOT)/share \ - -isystem $(ROOT)/ulib/std + -isystem $(ROOT)/std/include -isystem $(ROOT)/ulib -isystem $(ROOT)/share \ + -isystem $(ROOT)/ulib/std 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 diff --git a/user/arch/x86_64/link.ld b/user/arch/x86_64/link.ld index dd60644..ccd15fa 100644 --- a/user/arch/x86_64/link.ld +++ b/user/arch/x86_64/link.ld @@ -25,4 +25,12 @@ SECTIONS { . = ALIGN(4K); _bss_end = .; } + + /DISCARD/ : { + *(.eh_frame) + *(.eh_frame_hdr) + *(.gcc_except_table*) + *(.note*) + *(.comment) + } }