Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/sun2/conf use -ffunction-sections -fdata-sections -...



details:   https://anonhg.NetBSD.org/src/rev/602918971211
branches:  trunk
changeset: 985566:602918971211
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Aug 30 18:59:57 2021 +0000

description:
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

diffstat:

 sys/arch/sun2/conf/Makefile.sun2 |   4 +-
 sys/arch/sun2/conf/RAMDISK       |   6 +-
 sys/arch/sun2/conf/kern.ldscript |  88 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 3 deletions(-)

diffs (130 lines):

diff -r 6dc9bbf6de12 -r 602918971211 sys/arch/sun2/conf/Makefile.sun2
--- a/sys/arch/sun2/conf/Makefile.sun2  Mon Aug 30 18:33:37 2021 +0000
+++ b/sys/arch/sun2/conf/Makefile.sun2  Mon Aug 30 18:59:57 2021 +0000
@@ -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 @@
 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 :}
diff -r 6dc9bbf6de12 -r 602918971211 sys/arch/sun2/conf/RAMDISK
--- a/sys/arch/sun2/conf/RAMDISK        Mon Aug 30 18:33:37 2021 +0000
+++ b/sys/arch/sun2/conf/RAMDISK        Mon Aug 30 18:59:57 2021 +0000
@@ -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 @@
 
 #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
diff -r 6dc9bbf6de12 -r 602918971211 sys/arch/sun2/conf/kern.ldscript
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sun2/conf/kern.ldscript  Mon Aug 30 18:59:57 2021 +0000
@@ -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));
+       }
+}
+



Home | Main Index | Thread Index | Old Index