Skip to contentSkip to conversation

mkcompile_h: git rid of UTS_TRUNCATE from LINUX_COMPILE_{BY,HOST}

PATCH Applied Masahiro Yamada 1 participant 3 messages Dec 6, 2019 – Dec 17, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mkcompile_h: git rid of UTS_TRUNCATE from LINUX_COMPILE_{BY,HOST}

UTS_VERSION is set to struct uts_namespace, hence a too long string should be truncated so it fits in 64 characters.

On the other hand, LINUX_COMPILE_BY/HOST are not set to uts_namespace. They are just used in the banners, which do not have specific length limitation.

I dug into the git history, but I could not find the reason why these two strings must fit in 64 characters. Remove them.

Now that UTS_VERSION is the only user of UTS_TRUNCATE, I squashed it.

---

 scripts/mkcompile_h | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
scripts/mkcompile_h +4 -6
index d1d757c6edf4..3097fec1756a 100755
@@ -55,12 +55,10 @@ CONFIG_FLAGS=""
 if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
 if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
 if [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi
-UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
 
 # Truncate to maximum length
-
 UTS_LEN=64
-UTS_TRUNCATE="cut -b -$UTS_LEN"
+UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
 
 # Generate a temporary compile.h
 
@@ -69,10 +67,10 @@ UTS_TRUNCATE="cut -b -$UTS_LEN"
 
   echo \#define UTS_MACHINE \"$ARCH\"
 
-  echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\"
+  echo \#define UTS_VERSION \"$UTS_VERSION\"
 
-  echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\"
-  echo \#define LINUX_COMPILE_HOST \"`echo $LINUX_COMPILE_HOST | $UTS_TRUNCATE`\"
+  echo \#define LINUX_COMPILE_BY \"$LINUX_COMPILE_BY\"
+  echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
 
   echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\"
 } > .tmpcompile
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 mkcompile_h: use printf for LINUX_COMPILE_BY

Commit 858805b336be ("kbuild: add $(BASH) to run scripts with bash-extension") shed light on portability issues. Here is another one.

Since commit f07726048d59 ("Fix handling of backlash character in LINUX_COMPILE_BY name"), we must escape a backslash contained in LINUX_COMPILE_BY. This is not working on distros like Ubuntu.

As the POSIX spec [1] says, if any of the operands contain a backslash ( '\' ) character, the results are implementation-defined.

The actual shell of /bin/sh could be bash, dash depending on distros, and the behavior of builtin echo command is different among them.

The bash builtin echo, unless -e is given, copies the arguments to output without expanding escape sequences (BSD-like behavior).

The dash builtin echo, in contrast, adopts System V behavior, which does expand escape sequences without any option.

Even non-builtin /bin/echo behaves differently depending on the system. Due to these variations, echo is considered as a non-portable command. Using printf is the common solution to avoid the portability issue.

[1] https://pubs.opengroup.org/onlinepubs/009695399/utilities/echo.html

Fixes 858805b336be ("kbuild: add $(BASH) to run scripts with bash-extension")

---

 scripts/mkcompile_h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mkcompile_h +1 -1
index 3097fec1756a..3a5a4b210c86 100755
@@ -69,7 +69,7 @@ UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
 
   echo \#define UTS_VERSION \"$UTS_VERSION\"
 
-  echo \#define LINUX_COMPILE_BY \"$LINUX_COMPILE_BY\"
+  printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
   echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
 
   echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\"
Signature · 1 line
2.17.1
author Applied
#2 lore raw

Re: [PATCH 2/2] mkcompile_h: use printf for LINUX_COMPILE_BY

Quoted 24 lines · Masahiro Yamada

Commit 858805b336be ("kbuild: add $(BASH) to run scripts with bash-extension") shed light on portability issues. Here is another one.

Since commit f07726048d59 ("Fix handling of backlash character in LINUX_COMPILE_BY name"), we must escape a backslash contained in LINUX_COMPILE_BY. This is not working on distros like Ubuntu.

As the POSIX spec [1] says, if any of the operands contain a backslash ( '\' ) character, the results are implementation-defined.

The actual shell of /bin/sh could be bash, dash depending on distros, and the behavior of builtin echo command is different among them.

The bash builtin echo, unless -e is given, copies the arguments to output without expanding escape sequences (BSD-like behavior).

The dash builtin echo, in contrast, adopts System V behavior, which does expand escape sequences without any option.

Even non-builtin /bin/echo behaves differently depending on the system. Due to these variations, echo is considered as a non-portable command. Using printf is the common solution to avoid the portability issue.

Quoted 6 lines

[1] https://pubs.opengroup.org/onlinepubs/009695399/utilities/echo.html

Fixes 858805b336be ("kbuild: add $(BASH) to run scripts with bash-extension")

---

Applied to linux-kbuid.

Quoted 20 lines
 scripts/mkcompile_h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mkcompile_h +1 -2
index 3097fec1756a..3a5a4b210c86 100755
@@ -69,7 +69,7 @@ UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
 
   echo \#define UTS_VERSION \"$UTS_VERSION\"
 
-  echo \#define LINUX_COMPILE_BY \"$LINUX_COMPILE_BY\"
+  printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
   echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
 
   echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\"
--

2.17.1

Signature · 2 lines
Best Regards
Masahiro Yamada