Module Name: src
Committed By: christos
Date: Mon Aug 30 18:59:57 UTC 2021
Modified Files:
src/sys/arch/sun2/conf: Makefile.sun2 RAMDISK
Added Files:
src/sys/arch/sun2/conf: kern.ldscript
Log Message:
use -ffunction-sections -fdata-sections --gc-sections with an ldscript
that keeps _start. This deletes all unused code and shrinks the RAMDISK
kernel enough to be able to boot again:
-rwxr-xr-x 1 root src 2519436 Aug 30 06:38 RAMDISK.1/netbsd*
-rwxr-xr-x 1 root src 2104440 Aug 30 07:41 RAMDISK/netbsd*
text data bss dec hex filename
1525412 686252 63552 2275216 22b790 RAMDISK.1/netbsd
1098524 686400 67008 1851932 1c421c RAMDISK/netbsd
To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/sun2/conf/Makefile.sun2
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/sun2/conf/RAMDISK
cvs rdiff -u -r0 -r1.1 src/sys/arch/sun2/conf/kern.ldscript
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/sun2/conf/Makefile.sun2
diff -u src/sys/arch/sun2/conf/Makefile.sun2:1.27 src/sys/arch/sun2/conf/Makefile.sun2:1.28
--- src/sys/arch/sun2/conf/Makefile.sun2:1.27 Mon Oct 5 06:42:53 2020
+++ src/sys/arch/sun2/conf/Makefile.sun2 Mon Aug 30 14:59:57 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.sun2,v 1.27 2020/10/05 10:42:53 rin Exp $
+# $NetBSD: Makefile.sun2,v 1.28 2021/08/30 18:59:57 christos Exp $
# Makefile for NetBSD
#
@@ -34,6 +34,8 @@ GENASSYM_CONF= ${SUN2}/sun2/genassym.cf
CPPFLAGS+= -Dsun2
CFLAGS+= -msoft-float -fno-defer-pop
AFLAGS+= -x assembler-with-cpp
+KERNLDSCRIPT?= ${SUN2}/conf/kern.ldscript
+
# XXX
COPTS.promlib.c+=${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 9:? -Wno-error=array-bounds :}
Index: src/sys/arch/sun2/conf/RAMDISK
diff -u src/sys/arch/sun2/conf/RAMDISK:1.60 src/sys/arch/sun2/conf/RAMDISK:1.61
--- src/sys/arch/sun2/conf/RAMDISK:1.60 Wed Apr 3 12:30:28 2019
+++ src/sys/arch/sun2/conf/RAMDISK Mon Aug 30 14:59:57 2021
@@ -1,4 +1,4 @@
-# $NetBSD: RAMDISK,v 1.60 2019/04/03 16:30:28 christos Exp $
+# $NetBSD: RAMDISK,v 1.61 2021/08/30 18:59:57 christos Exp $
# RAMDISK: Root/swap on ramdisk
# This kernel is used to:
@@ -13,7 +13,9 @@ include "arch/sun2/conf/std.sun2"
#options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-makeoptions COPTS="-Os" # optimize for size
+makeoptions COPTS="-Os -ffunction-sections -fdata-sections" # optimize for size
+makeoptions EXTRA_LINKFLAGS="--gc-sections"
+makeoptions KERNLDSCRIPT="${SUN2}/conf/kern.ldscript"
# Machines to be supported by this kernel
#options FPU_EMULATE
Added files:
Index: src/sys/arch/sun2/conf/kern.ldscript
diff -u /dev/null src/sys/arch/sun2/conf/kern.ldscript:1.1
--- /dev/null Mon Aug 30 14:59:58 2021
+++ src/sys/arch/sun2/conf/kern.ldscript Mon Aug 30 14:59:57 2021
@@ -0,0 +1,88 @@
+/* $NetBSD: kern.ldscript,v 1.1 2021/08/30 18:59:57 christos Exp $ */
+
+#include "assym.h"
+
+__PAGE_SIZE = 0x1000 ;
+
+ENTRY(_start)
+SECTIONS
+{
+ .text : AT (ADDR(.text) & 0x0fffffff)
+ {
+ KEEP(*(.text._start));
+ . = ALIGN(__PAGE_SIZE);
+ __text_user_start = . ;
+ *(.text.user)
+ . = ALIGN(__PAGE_SIZE);
+ __text_user_end = . ;
+
+ *(.text)
+ *(.text.*)
+ *(.stub)
+ . = ALIGN(__PAGE_SIZE);
+ } =0xCC
+ _etext = . ;
+ PROVIDE (etext = .) ;
+
+ /*
+ * Push the rodata segment up to the next large page boundary so that we
+ * can map the text segment with large pages.
+ */
+ . = ALIGN(__PAGE_SIZE);
+
+ __rodata_start = . ;
+
+ .rodata :
+ {
+ *(.rodata)
+ *(.rodata.*)
+ . = ALIGN(COHERENCY_UNIT);
+ __CTOR_LIST__ = .;
+ *(.ctors)
+ __CTOR_END__ = .;
+ }
+
+ . = ALIGN(__PAGE_SIZE);
+
+ __data_start = . ;
+ .data :
+ {
+ *(.data)
+ }
+
+ . = ALIGN(COHERENCY_UNIT);
+ .data.cacheline_aligned :
+ {
+ *(.data.cacheline_aligned)
+ }
+ . = ALIGN(COHERENCY_UNIT);
+ .data.read_mostly :
+ {
+ *(.data.read_mostly)
+ }
+ . = ALIGN(COHERENCY_UNIT);
+
+ _edata = . ;
+ PROVIDE (edata = .) ;
+ __bss_start = . ;
+ .bss :
+ {
+ *(.bss)
+ *(.bss.*)
+ *(COMMON)
+ . = ALIGN(__PAGE_SIZE);
+ }
+
+ . = ALIGN(__PAGE_SIZE);
+
+ /* End of the kernel image */
+ __kernel_end = . ;
+
+ _end = . ;
+ PROVIDE (end = .) ;
+ .note.netbsd.ident :
+ {
+ KEEP(*(.note.netbsd.ident));
+ }
+}
+