Skip to contentSkip to conversation

Fix ld-version.sh script if LLD was built with LLD_VENDOR

PATCH In review Bernhard Rosenkränzer 3 participants 7 messages Mar 2, 2021 – Mar 9, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

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
index a463273509b5..4c042a306e22 100755
@@ -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
#1 lore raw

Hi 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. Since LLD_VENDOR can 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.

---
 scripts/ld-version.sh | 12 ++++++++++++
 1 file changed, 12 insertions(+)
scripts/ld-version.sh +12 -0
index a463273509b5..4c042a306e22 100755
@@ -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

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
index a463273509b5..84f9fc741f09 100755
@@ -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
#2 lore raw
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.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. Since LLD_VENDOR can 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.

---
 scripts/ld-version.sh | 12 ++++++++++++
 1 file changed, 12 insertions(+)
scripts/ld-version.sh +12 -1
index a463273509b5..4c042a306e22 100755
@@ -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_VENDOR defined.

scripts/ld-version.sh +0 -0
index a463273509b5..84f9fc741f09 100755
@@ -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 -1
        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

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
        fi

fi

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw
Quoted 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.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. Since LLD_VENDOR can 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.

---
 scripts/ld-version.sh | 12 ++++++++++++
 1 file changed, 12 insertions(+)
scripts/ld-version.sh +12 -1
index a463273509b5..4c042a306e22 100755
@@ -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_VENDOR defined.

scripts/ld-version.sh +0 -0
index a463273509b5..84f9fc741f09 100755
@@ -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 -1
        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

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
        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
index a463273509b5..30debf78aa09 100755
@@ -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
#4 lore raw
In reply to Bernhard Rosenkränzer
Quoted 9 lines · Bernhard Rosenkränzer

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.

---

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
index a463273509b5..4c042a306e22 100755
@@ -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
#5 lore raw
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. 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.

---

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
index a463273509b5..30debf78aa09 100755
@@ -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

maintainer Reviewed-by Tested-by
#6 lore raw
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. 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.

---

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.

Quoted 5 lines

Adjust the version checker to handle such versions of lld.

If it is not too late:

Quoted 42 lines
scripts/ld-version.sh +0 -0
index a463273509b5..30debf78aa09 100755
@@ -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

scripts/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