aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2021-05-06 19:05:09 +0000
committerWarner Losh <imp@FreeBSD.org>2021-07-30 23:00:17 +0000
commit631cf89fd4c869d3688a63402199e0500b1a65a8 (patch)
tree05982149676b45036c48cd12637cbb7d8577f703
parentefe3bf0fb092ebf79c04c760b8b6d703817c37c0 (diff)
downloadsrc-631cf89fd4c869d3688a63402199e0500b1a65a8.tar.gz
src-631cf89fd4c869d3688a63402199e0500b1a65a8.zip
boot: fix OBJS to not include BTX's crt0.o
According to comments in the Makefile, to make pxeboot work we need to have crt0.o first. This is needed because the simplified loader in pxeboot assumes that the startup code is at offset 0 in this binary. In normal booting, the start address can be obtained from headers of the binary, but since pxeboot encodes this as a pure binary, it has no way of knowing where that is and assumes 0. Added comments to that effect in the Makefile. We've done this by adding it to OBJS before all the other .o's are added. However, there's a problem. This also adds it to the CLEANFILES variable, which causes it to be removed from multiple places. The dependencies may also cause it to be re-built at a time that's after boot2 is built. This causes installs to fail because at install time boot2 is considered to be out of date and the programs to rebuild it are no longer in the path. Cope with this problem by just adding it to LDFLAGS instead. Glanced at by: kevans ("I thought that went in ages ago") Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D28876 (cherry picked from commit e713d3a013882893fceb84dd14569052271497a9)
-rw-r--r--stand/i386/loader/Makefile14
1 files changed, 12 insertions, 2 deletions
diff --git a/stand/i386/loader/Makefile b/stand/i386/loader/Makefile
index ad95948ec50a..dcae7bd67a14 100644
--- a/stand/i386/loader/Makefile
+++ b/stand/i386/loader/Makefile
@@ -89,8 +89,18 @@ LINKS+= ${BINDIR}/${LOADER} ${BINDIR}/loader
FILES+= ${LOADER}
FILESMODE_${LOADER}= ${BINMODE} -b
-# XXX crt0.o needs to be first for pxeboot(8) to work
-OBJS= ${BTXCRT}
+# 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.
+#
+# We must add it to the LDFLAGS instead of the OBJS becauce the former won't try
+# to clean it. When it is in OBJS, this cleaning can lead to races where
+# btxcrt.o is rebuilt, but boot2 isn't, leading to errors at installation time.
+# LDFLAGS does not have this baggage and will be included first in the list of
+# files.
+LDFLAGS+= ${BTXCRT}
DPADD= ${LDR_INTERP32} ${LIBFIREWIRE} ${LIBI386} ${LIBSA32}
LDADD= ${LDR_INTERP32} ${LIBFIREWIRE} ${LIBI386} ${LIBSA32}