aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2020-05-27 16:34:47 +0000
committerKyle Evans <kevans@FreeBSD.org>2020-05-27 16:34:47 +0000
commitb50ff2261bea0c0418f8b2b31cf82158e957a130 (patch)
treeac186e67a9424b4a5e290001b372f9509cf44453
parent48d7e753a7b42e782f7578914f383cd9bf2df28f (diff)
downloadsrc-b50ff2261bea0c0418f8b2b31cf82158e957a130.tar.gz
src-b50ff2261bea0c0418f8b2b31cf82158e957a130.zip
MFS r361538: 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. Note that this doesn't affect the stock build of 11.4's loaders, which do not have whatever set of optimizations leads to bootprog_interp getting removed; this is being merged as a low-risk change that will prevent accidents in case I've missed some non-default option combination that can lead to the same situation. Approved by: re (gjb)
Notes
Notes: svn path=/releng/11.4/; revision=361554
-rw-r--r--stand/common/interp.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/stand/common/interp.c b/stand/common/interp.c
index 8941101f6479..a0a6bd486614 100644
--- a/stand/common/interp.c
+++ b/stand/common/interp.c
@@ -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");