stand: Go back to a.out format for /boot/loader

Turns out there's two hidden a.out dependencies. pxeldr.S assumes it has
access to the a.out header from /boot/loader and cdboot.S assumes that
/boot/loader is also a.out and doesn't use boot2.

So, go back to making a.out files for these and adjust the size checks
to use ls, but we only need to check loader.bin. Trim the size we check
against by 2,000. The difference in size between loader and loader.bin
is about 3000 bytes, but clang15 produces binaries that are a smidge
bigger so we need to relax the check just a little and accept some
additional risk for the moment.

Add some comments to loader's Makefile about this.

Sponsored by:		Netflix
Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D36142
This commit is contained in:
Warner Losh 2022-08-11 17:29:10 -06:00
parent ac175bd33a
commit 4c8ea3efe7
2 changed files with 9 additions and 10 deletions

View file

@ -19,7 +19,7 @@ PROG= ${LOADER}.sym
INTERNALPROG=
NEWVERSWHAT?= "bootstrap loader" x86
VERSION_FILE= ${.CURDIR}/../loader/version
LOADERSIZE?= 510000 # Largest known safe size
LOADERSIZE?= 508000 # Largest known safe size for loader.bin
.PATH: ${BOOTSRC}/i386/loader
@ -83,13 +83,13 @@ CFLAGS+= -I${BOOTSRC}/i386
${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}
btxld -v -f elf -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
btxld -v -f aout -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
-b ${BTXKERN} ${LOADER}.bin
@set -- `${SIZE} ${.TARGET} | tail -1` ; x=$$((${LOADERSIZE}-$$4)); \
echo "$$x bytes available"; test $$x -ge 0
${LOADER}.bin: ${LOADER}.sym
${STRIPBIN} -R .comment -R .note -o ${.TARGET} ${.ALLSRC}
@set -- `ls -l ${.TARGET}` ; x=$$((${LOADERSIZE}-$$5)); \
echo "$$x bytes available"; test $$x -ge 0
.if ${MK_LOADER_ZFS} == "yes" && ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP}
LINKS+= ${BINDIR}/${LOADER} ${BINDIR}/zfsloader
@ -103,8 +103,8 @@ FILESMODE_${LOADER}= ${BINMODE} -b
# Note: crt0.o needs to be first for pxeboot(8) to work. It assumes that the
# startup code is located at the start of the loader and will jump
# there. Although btx is more flexible than this, the emulated boot2 environment
# that pxeloader provides has none of that flexibility because it lacks access
# to the a.out/elf headers and assumes an entry point of 0.
# that pxeldr provides has none of that flexibility assumes an entry point of
# 0. In addition, pxeldr and cdboot assume that it is loading an a.out file.
#
# We must add it to the LDFLAGS instead of the OBJS because the former won't try
# to clean it. When it is in OBJS, this cleaning can lead to races where

View file

@ -13,7 +13,6 @@ BOOT= pxeboot
LDR= pxeldr
ORG= 0x7c00
LOADER= loader
PXELDRSIZE?= 510000 # Largest known safe size
.if defined(BOOT_PXELDR_PROBE_KEYBOARD)
CFLAGS+=-DPROBE_KEYBOARD
@ -39,10 +38,10 @@ LDFLAGS+=${LDFLAGS_BIN}
CLEANFILES+= ${LOADER}
# Note: pxeldr.S assumes a.out and will require changes for ELF if the output
# format is changed to ELF.
${LOADER}: ${LOADERBIN} ${BTXLDR} ${BTXKERN}
btxld -v -f elf -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
btxld -v -f aout -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
-b ${BTXKERN} ${LOADERBIN}
@set -- `${SIZE} ${.TARGET} | tail -1` ; x=$$((${PXELDRSIZE}-$$4)); \
echo "$$x bytes available"; test $$x -ge 0
.include <bsd.prog.mk>