Skip to contentSkip to conversation

kbuild: replace BASH-specific ${@:2} with shift and ${@}

PATCH Applied Andrii Nakryiko 4 participants 5 messages Sep 5, 2019 – Sep 6, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: replace BASH-specific ${@:2} with shift and ${@}

${@:2} is BASH-specific extension, which makes link-vmlinux.sh rely on BASH. Use shift and ${@} instead to fix this issue.

Fixes 341dfcf8d78e ("btf: expose BTF info through sysfs")
Cc Stephen Rothwell <[email protected]>
Cc Masahiro Yamada <[email protected]>
---
 scripts/link-vmlinux.sh | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
scripts/link-vmlinux.sh +11 -5
index 0d8f41db8cd6..8c59970a09dc 100755
@@ -57,12 +57,16 @@ modpost_link()
 
 # Link of vmlinux
 # ${1} - output file
-# ${@:2} - optional extra .o files
+# ${2}, ${3}, ... - optional extra .o files
 vmlinux_link()
 {
 	local lds="${objtree}/${KBUILD_LDS}"
+	local output=${1}
 	local objects
 
+	# skip output file argument
+	shift
+
 	if [ "${SRCARCH}" != "um" ]; then
 		objects="--whole-archive			\
 			${KBUILD_VMLINUX_OBJS}			\
@@ -70,9 +74,10 @@ vmlinux_link()
 			--start-group				\
 			${KBUILD_VMLINUX_LIBS}			\
 			--end-group				\
-			${@:2}"
+			${@}"
 
-		${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} -o ${1}	\
+		${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux}	\
+			-o ${output}				\
 			-T ${lds} ${objects}
 	else
 		objects="-Wl,--whole-archive			\
@@ -81,9 +86,10 @@ vmlinux_link()
 			-Wl,--start-group			\
 			${KBUILD_VMLINUX_LIBS}			\
 			-Wl,--end-group				\
-			${@:2}"
+			${@}"
 
-		${CC} ${CFLAGS_vmlinux} -o ${1}			\
+		${CC} ${CFLAGS_vmlinux}				\
+			-o ${output}				\
 			-Wl,-T,${lds}				\
 			${objects}				\
 			-lutil -lrt -lpthread
Signature · 1 line
2.21.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andrii Nakryiko

${@:2} is BASH-specific extension, which makes link-vmlinux.sh rely on BASH. Use shift and ${@} instead to fix this issue.

Fixes 341dfcf8d78e ("btf: expose BTF info through sysfs")
Cc Stephen Rothwell <[email protected]>
Cc Masahiro Yamada <[email protected]>

Tested with bash/sh/csh, all works.

Quoted 53 lines
---
  scripts/link-vmlinux.sh | 16 +++++++++++-----
  1 file changed, 11 insertions(+), 5 deletions(-)
scripts/link-vmlinux.sh +11 -5
index 0d8f41db8cd6..8c59970a09dc 100755
@@ -57,12 +57,16 @@ modpost_link()
 
  # Link of vmlinux
  # ${1} - output file
-# ${@:2} - optional extra .o files
+# ${2}, ${3}, ... - optional extra .o files
  vmlinux_link()
  {
  	local lds="${objtree}/${KBUILD_LDS}"
+	local output=${1}
  	local objects
 
+	# skip output file argument
+	shift
+
  	if [ "${SRCARCH}" != "um" ]; then
  		objects="--whole-archive			\
  			${KBUILD_VMLINUX_OBJS}			\
@@ -70,9 +74,10 @@ vmlinux_link()
  			--start-group				\
  			${KBUILD_VMLINUX_LIBS}			\
  			--end-group				\
-			${@:2}"
+			${@}"
 
-		${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} -o ${1}	\
+		${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux}	\
+			-o ${output}				\
  			-T ${lds} ${objects}
  	else
  		objects="-Wl,--whole-archive			\
@@ -81,9 +86,10 @@ vmlinux_link()
  			-Wl,--start-group			\
  			${KBUILD_VMLINUX_LIBS}			\
  			-Wl,--end-group				\
-			${@:2}"
+			${@}"
 
-		${CC} ${CFLAGS_vmlinux} -o ${1}			\
+		${CC} ${CFLAGS_vmlinux}				\
+			-o ${output}				\
  			-Wl,-T,${lds}				\
  			${objects}				\
  			-lutil -lrt -lpthread
#2 lore raw
Quoted 6 lines · Yonghong Song
Quoted 3 lines · Andrii Nakryiko

${@:2} is BASH-specific extension, which makes link-vmlinux.sh rely on BASH. Use shift and ${@} instead to fix this issue.

Quoted 7 lines
Quoted 5 lines
Fixes 341dfcf8d78e ("btf: expose BTF info through sysfs")
Cc Stephen Rothwell <[email protected]>
Cc Masahiro Yamada <[email protected]>

Tested with bash/sh/csh, all works.

Thanks for testing, Yonghong! In my system sh is an alias to bash, so it still behaved like bash and didn't fail even with existing code. I didn't have an opportunity to install csh at that time and try it, so thanks a lot for confirming. I basically relied on documentation to verify shift and $@ is not BASH'ism.

Quoted 55 lines
Quoted 53 lines
---
   scripts/link-vmlinux.sh | 16 +++++++++++-----
   1 file changed, 11 insertions(+), 5 deletions(-)
scripts/link-vmlinux.sh +11 -5
index 0d8f41db8cd6..8c59970a09dc 100755
@@ -57,12 +57,16 @@ modpost_link()
 
   # Link of vmlinux
   # ${1} - output file
-# ${@:2} - optional extra .o files
+# ${2}, ${3}, ... - optional extra .o files
   vmlinux_link()
   {
   	local lds="${objtree}/${KBUILD_LDS}"
+	local output=${1}
   	local objects
 
+	# skip output file argument
+	shift
+
   	if [ "${SRCARCH}" != "um" ]; then
   		objects="--whole-archive			\
   			${KBUILD_VMLINUX_OBJS}			\
@@ -70,9 +74,10 @@ vmlinux_link()
   			--start-group				\
   			${KBUILD_VMLINUX_LIBS}			\
   			--end-group				\
-			${@:2}"
+			${@}"
 
-		${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} -o ${1}	\
+		${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux}	\
+			-o ${output}				\
   			-T ${lds} ${objects}
   	else
   		objects="-Wl,--whole-archive			\
@@ -81,9 +86,10 @@ vmlinux_link()
   			-Wl,--start-group			\
   			${KBUILD_VMLINUX_LIBS}			\
   			-Wl,--end-group				\
-			${@:2}"
+			${@}"
 
-		${CC} ${CFLAGS_vmlinux} -o ${1}			\
+		${CC} ${CFLAGS_vmlinux}				\
+			-o ${output}				\
   			-Wl,-T,${lds}				\
   			${objects}				\
   			-lutil -lrt -lpthread
Reviewed-by on v1 1/1
#3 lore raw
In reply to Andrii Nakryiko
Quoted 13 lines

-----Original Message-----
From: Andrii Nakryiko <[email protected]>
Sent: Friday, September 06, 2019 3:00 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Andrii Nakryiko <[email protected]>; Stephen Rothwell <[email protected]>; Yamada, Masahiro/山田 真弘 <[email protected]>
Subject: [PATCH bpf-next] kbuild: replace BASH-specific ${@:2} with shift and ${@}

Quoted 8 lines

${@:2} is BASH-specific extension, which makes link-vmlinux.sh rely on BASH. Use shift and ${@} instead to fix this issue.

Fixes 341dfcf8d78e ("btf: expose BTF info through sysfs")
Cc Stephen Rothwell <[email protected]>
Cc Masahiro Yamada <[email protected]>
#4 lore raw
Quoted 17 lines · On Fri, Sep 6, 2019 at 3:34 AM <[email protected]> wrote:
Quoted 17 lines

-----Original Message-----
From: Andrii Nakryiko <[email protected]>
Sent: Friday, September 06, 2019 3:00 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Andrii Nakryiko <[email protected]>; Stephen Rothwell <[email protected]>; Yamada, Masahiro/山田 真弘 <[email protected]>
Subject: [PATCH bpf-next] kbuild: replace BASH-specific ${@:2} with shift and ${@}

${@:2} is BASH-specific extension, which makes link-vmlinux.sh rely on BASH. Use shift and ${@} instead to fix this issue.

Quoted 7 lines
Quoted 5 lines
Fixes 341dfcf8d78e ("btf: expose BTF info through sysfs")
Cc Stephen Rothwell <[email protected]>
Cc Masahiro Yamada <[email protected]>

Applied. Thanks