Do garbage collection of unused sections.
Implement -ffunction-sections and -fdata-sections in both 32bit and
16bit code.
Make sure all sections have unique names (even asm and discarded
sections).
Enhance tools/layoutrom.py script to find all sections reachable from
exported 16bit code - prune all other sections.
Mark sections with "export" if they can be visible outside of code -
these sections wont be dropped when pruning unused sections.
diff --git a/Makefile b/Makefile
index bd5c184..ff594e7 100644
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,7 @@
-mpreferred-stack-boundary=2 -mrtd -freg-struct-return \
-ffreestanding -fwhole-program -fomit-frame-pointer \
-fno-delete-null-pointer-checks -Wno-strict-aliasing \
+ -ffunction-sections -fdata-sections \
-minline-all-stringops
COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
@@ -33,7 +34,6 @@
CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \
$(call cc-option,$(CC),-fno-tree-switch-conversion,) \
$(call cc-option,$(CC),--param large-stack-frame=4,)
-CFLAGS16INC += -ffunction-sections -fdata-sections
CFLAGS16 = $(CFLAGS16INC) -g
all: $(OUT) $(OUT)bios.bin
@@ -107,11 +107,14 @@
@echo " Linking (no relocs) $@"
$(Q)$(LD) -r -T $(OUT)rombios32.lds $< -o $@
-$(OUT)romlayout.lds: $(OUT)romlayout16.o
+$(OUT)romlayout16.lds $(OUT)romlayout32.lds: $(OUT)ccode32.o $(OUT)romlayout16.o
@echo " Building layout information $@"
- $(Q)$(OBJDUMP) -h $< | ./tools/layoutrom.py $@
+ $(Q)$(OBJDUMP) -thr $(OUT)ccode32.o > $(OUT)ccode32.o.objdump
+ $(Q)$(OBJDUMP) -thr $(OUT)romlayout16.o > $(OUT)romlayout16.o.objdump
+ $(Q)./tools/layoutrom.py $(OUT)romlayout16.o.objdump $(OUT)ccode32.o.objdump $(OUT)romlayout16.lds $(OUT)romlayout32.lds
-$(OUT)layout16.lds: $(OUT)romlayout.lds
+$(OUT)layout16.lds: $(OUT)romlayout16.lds
+$(OUT)rombios32.lds: $(OUT)romlayout32.lds
$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)layout16.lds
@echo " Linking (no relocs) $@"
@@ -148,7 +151,7 @@
$(OUT)vgarom.o: $(OUT)vgalayout16.o $(OUT)vgalayout.lds
@echo " Linking $@"
- $(Q)$(LD) -T $(OUT)vgalayout.lds $(OUT)vgalayout16.o -o $@
+ $(Q)$(LD) --gc-sections -T $(OUT)vgalayout.lds $(OUT)vgalayout16.o -o $@
$(OUT)vgabios.bin.raw: $(OUT)vgarom.o
@echo " Extracting binary $@"