Skip to contentSkip to conversation

kbuild: compile_h: fix compiler version detection with clang

PATCH In review Yuxuan Shui 3 participants 3 messages May 14, 2020 – May 15, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: compile_h: fix compiler version detection with clang

In some setup clang will print a line about CUDA version it detects, like this:

Found CUDA installation: /opt/cuda, version 10.1

So grepping ' version ' matches 2 lines, and results in a broken string in compiler.h, which doesn't compile.

This commit adds a "head -n1" to fix this problem.

---
 scripts/mkcompile_h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mkcompile_h +1 -1
index 5b80a4699740..8e6b4fc6fdd9 100755
@@ -62,7 +62,7 @@ UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
   printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
   echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
 
-  CC_VERSION=$($CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//')
+  CC_VERSION=$($CC -v 2>&1 | grep ' version ' | head -n1 | sed 's/[[:space:]]*$//')
   LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
 		      | sed 's/[[:space:]]*$//')
   printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION"

--
2.26.2

Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Yuxuan Shui

In some setup clang will print a line about CUDA version it detects, like this:

Quoted 8 lines

Found CUDA installation: /opt/cuda, version 10.1

So grepping ' version ' matches 2 lines, and results in a broken string in compiler.h, which doesn't compile.

This commit adds a "head -n1" to fix this problem.

Hi Yuxuan, thanks for the patch!

Might be worthwhile for Masahiro to add

if/when picked up?

Quoted 19 lines
---
 scripts/mkcompile_h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mkcompile_h +1 -2
index 5b80a4699740..8e6b4fc6fdd9 100755
@@ -62,7 +62,7 @@ UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
   printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
   echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
 
-  CC_VERSION=$($CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//')
+  CC_VERSION=$($CC -v 2>&1 | grep ' version ' | head -n1 | sed 's/[[:space:]]*$//')
   LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
                      | sed 's/[[:space:]]*$//')
   printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION"
--

2.26.2

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
In reply to Yuxuan Shui
Quoted 5 lines · Yuxuan Shui

In some setup clang will print a line about CUDA version it detects, like this:

Quoted 8 lines

Found CUDA installation: /opt/cuda, version 10.1

So grepping ' version ' matches 2 lines, and results in a broken string in compiler.h, which doesn't compile.

This commit adds a "head -n1" to fix this problem.

I do not know what to do about this.

This problem had already been fixed by a different patch, which is queued up in linux-next.

9a950154668729a472d17b8e307d92e7c60f45f7

This patch
https://patchwork.kernel.org/patch/11505803/

So, the future releases will be OK.

For back-porting to the stable kernel,
your one-liner fixup is simpler.

Quoted 18 lines
---
 scripts/mkcompile_h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mkcompile_h +1 -2
index 5b80a4699740..8e6b4fc6fdd9 100755
@@ -62,7 +62,7 @@ UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
   printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
   echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
 
-  CC_VERSION=$($CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//')
+  CC_VERSION=$($CC -v 2>&1 | grep ' version ' | head -n1 | sed 's/[[:space:]]*$//')
   LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
                      | sed 's/[[:space:]]*$//')
   printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION"
--
Quoted 1 line

2.26.2

--
Best Regards
Masahiro Yamada