svn commit: r361295 - head/stand/common

Kyle Evans kevans at FreeBSD.org
Wed May 20 21:02:09 UTC 2020


Author: kevans
Date: Wed May 20 21:02:08 2020
New Revision: 361295
URL: https://svnweb.freebsd.org/changeset/base/361295

Log:
  loader: fix userboot's ability to detect a guest's interpreter
  
  Some time after r338418, I believe with -Os/-Oz -ffunction-sections
  -fdata-sections, the bootprog_interp variable that held our "$Interpreter:"
  marker started getting strip from all loaders, with exception to userboot
  since it used bootprog_interp to determine what flavor of userboot it was.
  
  At some point, it had been brought to my attention that this was no longer
  working and I had worked up some potential solutions to use the variable
  that involved printing it out. My vague recollection is that this was
  rejected, and I forgot to explore the alternatives; I cannot find records of
  this discussion anymore.
  
  Fast forward to present day, Andrew reported that it was non-functional and
  offered (effectively) this patch (sans comment) to stop the compiler from
  optimizing it out by assigning it to a volatile variable. This removes
  concerns about user-facing change while retaining the interpreter marker.
  Furthermore, it could certainly be uglier.
  
  Reported and tested by:	Andrew Gierth <andrew_tao173.riddles.org.uk>
  MFC after:	3 days

Modified:
  head/stand/common/interp.c

Modified: head/stand/common/interp.c
==============================================================================
--- head/stand/common/interp.c	Wed May 20 20:58:48 2020	(r361294)
+++ head/stand/common/interp.c	Wed May 20 21:02:08 2020	(r361295)
@@ -45,8 +45,17 @@ __FBSDID("$FreeBSD$");
 void
 interact(void)
 {
-	static char	input[256];			/* big enough? */
+	static char		input[256];		/* big enough? */
+	const char * volatile	interp_identifier;
 
+	/*
+	 * Because interp_identifier is volatile, it cannot be optimized out by
+	 * the compiler as it's considered an externally observable event.  This
+	 * prevents the compiler from optimizing out our carefully placed
+	 * $Interpreter:4th string that userboot may use to determine that
+	 * we need to switch interpreters.
+	 */
+	interp_identifier = bootprog_interp;
 	interp_init();
 
 	printf("\n");


More information about the svn-src-all mailing list