Fix ld-version.sh script if LLD was built with LLD_VENDOR
PATCH 1/1 Fix ld-version.sh script if LLD was built with LLD_VENDOR
If LLD was built with -DLLD_VENDOR="xyz", ld.lld --version output will prefix LLD_VENDOR. Since LLD_VENDOR can contain spaces, the LLD identifier isn't guaranteed to be $2 either.
Adjust the version checker to handle such versions of lld.
--- scripts/ld-version.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+)
scripts/ld-version.sh +12 -0
@@ -49,6 +49,18 @@ elif [ "$1" = LLD ]; then min_version=$lld_min_version name=LLD disp_name=LLD +elif echo "$@" |grep -q ' LLD '; then + # if LLD was built with -DLLD_VENDOR="xyz", it ld.lld --version + # says "xyz LLD [...]". Since LLD_VENDOR may contain spaces, we + # don't know the exact position of "LLD" and the version info + # at this point + while [ "$1" != "LLD" ]; do + shift + done + version=$2 + min_version=$lld_min_version + name=LLD + disp_name=LLD else echo "$orig_args: unknown linker" >&2 exit 1
Signature · 1 line
2.30.1
Nathan Chancellor
maintainerHi Bernhard,
I have added the ClangBuiltLinux mailing list, kbuild mailing list, and Masahiro and Nick to CC. Maybe ld-version.sh and cc-version.sh should be added to a MAINTAINERS entry to make sure we get CC'd (I can send one along tomorrow).
Quoted 3 lines · Bernhard Rosenkränzer
If LLD was built with -DLLD_VENDOR="xyz", ld.lld --version output will prefix
LLD_VENDOR. SinceLLD_VENDORcan contain spaces, the LLD identifier isn't guaranteed to be $2 either.
TIL about LLD_VENDOR...
Quoted 33 lines
Adjust the version checker to handle such versions of lld.
Signed-off-by Bernhard Rosenkränzer <[email protected]>--- scripts/ld-version.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+)scripts/ld-version.sh +12
-0@@ -49,6 +49,18 @@ elif [ "$1" = LLD ]; then min_version=$lld_min_version name=LLD disp_name=LLD +elif echo "$@" |grep -q ' LLD '; then + # if LLD was built with -DLLD_VENDOR="xyz", it ld.lld --version + # says "xyz LLD [...]". Since LLD_VENDOR may contain spaces, we + # don't know the exact position of "LLD" and the version info + # at this point + while [ "$1" != "LLD" ]; do + shift + done + version=$2 + min_version=$lld_min_version + name=LLD + disp_name=LLD else echo "$orig_args: unknown linker" >&2 exit 1Signature · 1 line
2.30.1
I am not sure what a better fix would be of the top of my head but wouldn't it be better to avoid the duplication? This diff below works for me with or without LLD_VENDOR defined.
scripts/ld-version.sh +4 -1
@@ -44,7 +44,10 @@ if [ "$1" = GNU -a "$2" = ld ]; then elif [ "$1" = GNU -a "$2" = gold ]; then echo "gold linker is not supported as it is not capable of linking the kernel proper." >&2 exit 1 -elif [ "$1" = LLD ]; then +elif echo "$*" | grep -q LLD; then + while [ "$1" != "LLD" ]; do + shift + done version=$2 min_version=$lld_min_version name=LLD
Quoted 59 lines · Nathan Chancellor
Hi Bernhard,
I have added the ClangBuiltLinux mailing list, kbuild mailing list, and Masahiro and Nick to CC. Maybe
ld-version.shandcc-version.shshould be added to aMAINTAINERSentry to make sure we get CC'd (I can send one along tomorrow).Quoted 3 lines · Bernhard Rosenkränzer
If LLD was built with -DLLD_VENDOR="xyz", ld.lld --version output will prefix
LLD_VENDOR. SinceLLD_VENDORcan contain spaces, the LLD identifier isn't guaranteed to be $2 either.TIL about
LLD_VENDOR...Quoted 31 lines
Adjust the version checker to handle such versions of lld.
Signed-off-by Bernhard Rosenkränzer <[email protected]>--- scripts/ld-version.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+)scripts/ld-version.sh +12
-1@@ -49,6 +49,18 @@ elif [ "$1" = LLD ]; then min_version=$lld_min_version name=LLD disp_name=LLD +elif echo "$@" |grep -q ' LLD '; then + # if LLD was built with -DLLD_VENDOR="xyz", it ld.lld --version + # says "xyz LLD [...]". Since LLD_VENDOR may contain spaces, we + # don't know the exact position of "LLD" and the version info + # at this point + while [ "$1" != "LLD" ]; do + shift + done + version=$2 + min_version=$lld_min_version + name=LLD + disp_name=LLD else echo "$orig_args: unknown linker" >&2 exit 1 --Quoted 2 lines
2.30.1
I am not sure what a better fix would be of the top of my head but wouldn't it be better to avoid the duplication? This diff below works for me with or without
LLD_VENDORdefined.scripts/ld-version.sh +0
-0@@ -44,7 +44,10 @@ if [ "$1" = GNU -a "$2" = ld ]; then elif [ "$1" = GNU -a "$2" = gold ]; then
scripts/ld-version.sh if [ "$1" = GNU -a "$2" = ld ]; then · line 53
Quoted 10 lines
scripts/ld-version.sh +4
-1echo "gold linker is not supported as it is not capable of linking the kernel proper." >&2 exit 1 -elif [ "$1" = LLD ]; then +elif echo "$*" | grep -q LLD; then + while [ "$1" != "LLD" ]; do + shift + done version=$2 min_version=$lld_min_version name=LLD
You do not need to use grep.
How about this?
...
else
while [ $# -gt 1 -a "$1" != "LLD" ]; do
shift
done
if [ "$1" = LLD ]; then
version=$2
min_version=$lld_min_version
name=LLD
disp_name=LLD
else
echo "$orig_args: unknown linker" >&2
exit 1
fifi
Signature · 2 lines
Best Regards Masahiro Yamada
Nathan Chancellor
maintainerQuoted 94 lines · Masahiro Yamada
Quoted 59 lines · Nathan Chancellor
Hi Bernhard,
I have added the ClangBuiltLinux mailing list, kbuild mailing list, and Masahiro and Nick to CC. Maybe
ld-version.shandcc-version.shshould be added to aMAINTAINERSentry to make sure we get CC'd (I can send one along tomorrow).Quoted 3 lines · Bernhard Rosenkränzer
If LLD was built with -DLLD_VENDOR="xyz", ld.lld --version output will prefix
LLD_VENDOR. SinceLLD_VENDORcan contain spaces, the LLD identifier isn't guaranteed to be $2 either.TIL about
LLD_VENDOR...Quoted 31 lines
Adjust the version checker to handle such versions of lld.
Signed-off-by Bernhard Rosenkränzer <[email protected]>--- scripts/ld-version.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+)scripts/ld-version.sh +12
-1@@ -49,6 +49,18 @@ elif [ "$1" = LLD ]; then min_version=$lld_min_version name=LLD disp_name=LLD +elif echo "$@" |grep -q ' LLD '; then + # if LLD was built with -DLLD_VENDOR="xyz", it ld.lld --version + # says "xyz LLD [...]". Since LLD_VENDOR may contain spaces, we + # don't know the exact position of "LLD" and the version info + # at this point + while [ "$1" != "LLD" ]; do + shift + done + version=$2 + min_version=$lld_min_version + name=LLD + disp_name=LLD else echo "$orig_args: unknown linker" >&2 exit 1 --Quoted 2 lines
2.30.1
I am not sure what a better fix would be of the top of my head but wouldn't it be better to avoid the duplication? This diff below works for me with or without
LLD_VENDORdefined.scripts/ld-version.sh +0
-0@@ -44,7 +44,10 @@ if [ "$1" = GNU -a "$2" = ld ]; then elif [ "$1" = GNU -a "$2" = gold ]; thenscripts/ld-version.sh if [ "$1" = GNU -a "$2" = ld ]; then · line 53
Quoted 10 lines
scripts/ld-version.sh +4
-1echo "gold linker is not supported as it is not capable of linking the kernel proper." >&2 exit 1 -elif [ "$1" = LLD ]; then +elif echo "$*" | grep -q LLD; then + while [ "$1" != "LLD" ]; do + shift + done version=$2 min_version=$lld_min_version name=LLDYou do not need to use grep.
How about this?... else while [ $# -gt 1 -a "$1" != "LLD" ]; do shift done if [ "$1" = LLD ]; then version=$2 min_version=$lld_min_version name=LLD disp_name=LLD else echo "$orig_args: unknown linker" >&2 exit 1 fi
Quoted 8 lines
fi
Signature · 2 lines
Best Regards Masahiro Yamada
Yes, that as the following diff works for me.
scripts/ld-version.sh +13 -7
@@ -44,14 +44,20 @@ if [ "$1" = GNU -a "$2" = ld ]; then elif [ "$1" = GNU -a "$2" = gold ]; then echo "gold linker is not supported as it is not capable of linking the kernel proper." >&2 exit 1 -elif [ "$1" = LLD ]; then - version=$2 - min_version=$lld_min_version - name=LLD - disp_name=LLD else - echo "$orig_args: unknown linker" >&2 - exit 1 + while [ $# -gt 1 -a "$1" != "LLD" ]; do + shift + done + + if [ "$1" = LLD ]; then + version=$2 + min_version=$lld_min_version + name=LLD + disp_name=LLD + else + echo "$orig_args: unknown linker" >&2 + exit 1 + fi fi # Some distributions append a package release number, as in 2.34-4.fc32
Quoted 9 lines · Bernhard Rosenkränzer
If LLD was built with -DLLD_VENDOR="xyz", ld.lld --version output will prefix
LLD_VENDOR. SinceLLD_VENDORcan contain spaces, the LLD identifier isn't guaranteed to be $2 either.Adjust the version checker to handle such versions of lld.
Signed-off-by Bernhard Rosenkränzer <[email protected]>---
Bernhard,
Could you senv v2
with the suggested code change?
Please make sure to add
[email protected]
in the To:
Quoted 29 lines
scripts/ld-version.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+)scripts/ld-version.sh +12
-1@@ -49,6 +49,18 @@ elif [ "$1" = LLD ]; then min_version=$lld_min_version name=LLD disp_name=LLD +elif echo "$@" |grep -q ' LLD '; then + # if LLD was built with -DLLD_VENDOR="xyz", it ld.lld --version + # says "xyz LLD [...]". Since LLD_VENDOR may contain spaces, we + # don't know the exact position of "LLD" and the version info + # at this point + while [ "$1" != "LLD" ]; do + shift + done + version=$2 + min_version=$lld_min_version + name=LLD + disp_name=LLD else echo "$orig_args: unknown linker" >&2 exit 1 --2.30.1
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 13 lines · Masahiro Yamada
Quoted 9 lines · Bernhard Rosenkränzer
If LLD was built with -DLLD_VENDOR="xyz", ld.lld --version output will prefix
LLD_VENDOR. SinceLLD_VENDORcan contain spaces, the LLD identifier isn't guaranteed to be $2 either.Adjust the version checker to handle such versions of lld.
Signed-off-by Bernhard Rosenkränzer <[email protected]>---
Quoted 8 lines
Bernhard,
Could you senv v2
with the suggested code change?Please make sure to add
[email protected]
in the To:
I did not get v2, but never mind.
I locally modified the code and applied.
I added Link: to your original patch
just in case I make some mistake in the
code refactoring.
The final one looks as follows:
commit 0b2813ba7b0f0a9ff273177e85cbc93d92e76212
Author: Bernhard Rosenkränzer <[email protected]> Date: Tue Mar 2 23:12:11 2021 +0100
kbuild: Fix ld-version.sh script if LLD was built with LLD_VENDOR
If LLD was built with -DLLD_VENDOR="xyz", ld.lld --version output will prefix LLD_VENDOR. Since LLD_VENDOR can contain spaces, the LLD identifier isn't guaranteed to be $2 either.
Adjust the version checker to handle such versions of lld.
scripts/ld-version.sh +0 -0
@@ -44,14 +44,20 @@ if [ "$1" = GNU -a "$2" = ld ]; then elif [ "$1" = GNU -a "$2" = gold ]; then echo "gold linker is not supported as it is not capable of
linking the kernel proper." >&2
exit 1
-elif [ "$1" = LLD ]; then
- version=$2 - min_version=$lld_min_version - name=LLD - disp_name=LLD else - echo "$orig_args: unknown linker" >&2 - exit 1 + while [ $# -gt 1 -a "$1" != "LLD" ]; do
+ shift
+ done
+
+ if [ "$1" = LLD ]; then
+ version=$2 + min_version=$lld_min_version + name=LLD + disp_name=LLD
+ else
+ echo "$orig_args: unknown linker" >&2
+ exit 1
+ fi
fi
# Some distributions append a package release number, as in 2.34-4.fc32
--
Best Regards
Masahiro Yamada
Quoted 48 lines · Masahiro Yamada
Quoted 13 lines · Masahiro Yamada
Quoted 9 lines · Bernhard Rosenkränzer
If LLD was built with -DLLD_VENDOR="xyz", ld.lld --version output will prefix
LLD_VENDOR. SinceLLD_VENDORcan contain spaces, the LLD identifier isn't guaranteed to be $2 either.Adjust the version checker to handle such versions of lld.
Signed-off-by Bernhard Rosenkränzer <[email protected]>---
Quoted 8 lines
Bernhard,
Could you senv v2
with the suggested code change?Please make sure to add
[email protected]
in the To:I did not get v2, but never mind.
I locally modified the code and applied.I added Link: to your original patch
just in case I make some mistake in the
code refactoring.The final one looks as follows:
commit
0b2813ba7b0f0a9ff273177e85cbc93d92e76212Author: Bernhard Rosenkränzer <[email protected]> Date: Tue Mar 2 23:12:11 2021 +0100kbuild: Fix
ld-version.shscript if LLD was built withLLD_VENDORIf LLD was built with -DLLD_VENDOR="xyz", ld.lld --version output will prefix
LLD_VENDOR. SinceLLD_VENDORcan contain spaces, the LLD identifier isn't guaranteed to be $2 either.
Quoted 5 lines
Adjust the version checker to handle such versions of lld.
Signed-off-by Bernhard Rosenkränzer <[email protected]>[masahiro yamada: refactor the code]
If it is not too late:
Quoted 42 lines
Signed-off-by Masahiro Yamada <[email protected]>scripts/ld-version.sh +0
-0@@ -44,14 +44,20 @@ if [ "$1" = GNU -a "$2" = ld ]; then elif [ "$1" = GNU -a "$2" = gold ]; then echo "gold linker is not supported as it is not capable oflinking the kernel proper." >&2
exit 1scripts/ld-version.sh +13
-8-elif [ "$1" = LLD ]; then - version=$2 - min_version=$lld_min_version - name=LLD - disp_name=LLD else - echo "$orig_args: unknown linker" >&2 - exit 1 + while [ $# -gt 1 -a "$1" != "LLD" ]; do + shift + done + + if [ "$1" = LLD ]; then + version=$2 + min_version=$lld_min_version + name=LLD + disp_name=LLD + else + echo "$orig_args: unknown linker" >&2 + exit 1 + fi fi # Some distributions append a package release number, as in 2.34-4.fc32 --Best Regards
Masahiro Yamada