git: 37ddf393f85b - stable/13 - stand: Compile out the extensive superblock diagnostic messages for BIOS loader

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Fri, 18 Nov 2022 01:21:47 UTC
The branch stable/13 has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=37ddf393f85b2d70d34bb85f8ffad3cc2882d50a

commit 37ddf393f85b2d70d34bb85f8ffad3cc2882d50a
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-08-12 17:08:36 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2022-11-18 01:19:41 +0000

    stand: Compile out the extensive superblock diagnostic messages for BIOS loader
    
    The BIOS loader operates in a very constrained environment. The messages
    for the super block integrity tests take up about 12k of space. Compile
    them out for the BIOS loader, while leaving it intact for all other
    loaders that aren't space constrained. These aren't used in the 'super
    tiny' *boot* programs, so no adjustment is needed there.
    
    We reply on the fact that (a) i386 doesn't support 32-bit UEFI booting
    and (b) LIBSA_CPUARCH is "i386" when building on both i386 and when
    we're building the 32-bit libsa32 library.
    
    This saves about 12k of space for this constrained envrionment and will
    take a bit of the pressure off some machines where the loader has grown
    too big for their BIOS (see comments in i386/loader/Makefile for
    details).
    
    Sponsored by:           Netflix
    Reviewed by:            mckusick
    Differential Revision:  https://reviews.freebsd.org/D36175
    
    (cherry picked from commit 148211300870b3bd558bf70dc3bf7d7f78c657aa)
---
 stand/libsa/Makefile   | 11 +++++++++++
 sys/ufs/ffs/ffs_subr.c |  6 +++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/stand/libsa/Makefile b/stand/libsa/Makefile
index 781194d0a28d..284aa5452fca 100644
--- a/stand/libsa/Makefile
+++ b/stand/libsa/Makefile
@@ -167,6 +167,17 @@ SRCS+=	time.c
 .PATH: ${SRCTOP}/sys/ufs/ffs
 SRCS+=ffs_subr.c ffs_tables.c
 
+#
+# i386 has a constrained space for its /boot/loader, so compile out the
+# extensive messages diagnosing bad superblocks. i386 doesn't support UEFI
+# booting, so doing it always makes sense natively there. When we compile
+# for 32-bit on amd64, LIBSA_CPUARCH is also i386 and we use libsa32 only
+# for the BIOS /boot/loader which has the same constraints.
+#
+.if ${LIBSA_CPUARCH} == "i386"
+CFLAGS.ffs_subr.c+= -DSTANDALONE_SMALL
+.endif
+
 CFLAGS.dosfs.c+= -I${LDRSRC}
 CFLAGS.tftp.c+= -I${LDRSRC}
 CFLAGS.ufs.c+= -I${LDRSRC}
diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c
index 6b2bbf41c91b..01981c782499 100644
--- a/sys/ufs/ffs/ffs_subr.c
+++ b/sys/ufs/ffs/ffs_subr.c
@@ -323,7 +323,11 @@ readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk,
  * Verify the filesystem values.
  */
 #define ILOG2(num)	(fls(num) - 1)
-#define MPRINT		if (prtmsg) printf
+#ifdef STANDALONE_SMALL
+#define MPRINT(...)	do { } while (0)
+#else
+#define MPRINT(...)	if (prtmsg) printf(__VA_ARGS__)
+#endif
 /*
  * Print error messages when bad superblock values are found.
  */