2019-11-12 13:47:40

by Ilie Halip

[permalink] [raw]
Subject: [PATCH] scripts/tools-support-relr.sh: un-quote variables

When the CC variable contains quotes, e.g. when using
ccache (make CC="ccache <compiler>"), this script always
fails, so CONFIG_RELR is never enabled, even when the
toolchain supports this feature. Removing the /dev/null
redirect and invoking the script manually shows the issue:

$ CC='/usr/bin/ccache clang' ./scripts/tools-support-relr.sh
./scripts/tools-support-relr.sh: 7: ./scripts/tools-support-relr.sh: /usr/bin/ccache clang: not found

Fix this by un-quoting the variables.

Before:
$ make ARCH=arm64 CC='/usr/bin/ccache clang' LD=ld.lld \
NM=llvm-nm OBJCOPY=llvm-objcopy defconfig
$ grep RELR .config
CONFIG_ARCH_HAS_RELR=y

With this change:
$ make ARCH=arm64 CC='/usr/bin/ccache clang' LD=ld.lld \
NM=llvm-nm OBJCOPY=llvm-objcopy defconfig
$ grep RELR .config
CONFIG_TOOLS_SUPPORT_RELR=y
CONFIG_ARCH_HAS_RELR=y
CONFIG_RELR=y

Fixes: 5cf896fb6be3 ("arm64: Add support for relocating the kernel with RELR relocations")
Reported-by: Dmitry Golovin <[email protected]>
Link: https://github.com/ClangBuiltLinux/linux/issues/769
Cc: Peter Collingbourne <[email protected]>
Signed-off-by: Ilie Halip <[email protected]>
---
scripts/tools-support-relr.sh | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/tools-support-relr.sh b/scripts/tools-support-relr.sh
index 97a2c844a95e..45e8aa360b45 100755
--- a/scripts/tools-support-relr.sh
+++ b/scripts/tools-support-relr.sh
@@ -4,13 +4,13 @@
tmp_file=$(mktemp)
trap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT

-cat << "END" | "$CC" -c -x c - -o $tmp_file.o >/dev/null 2>&1
+cat << "END" | $CC -c -x c - -o $tmp_file.o >/dev/null 2>&1
void *p = &p;
END
-"$LD" $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr -o $tmp_file
+$LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr -o $tmp_file

# Despite printing an error message, GNU nm still exits with exit code 0 if it
# sees a relr section. So we need to check that nothing is printed to stderr.
-test -z "$("$NM" $tmp_file 2>&1 >/dev/null)"
+test -z "$($NM $tmp_file 2>&1 >/dev/null)"

-"$OBJCOPY" -O binary $tmp_file $tmp_file.bin
+$OBJCOPY -O binary $tmp_file $tmp_file.bin
--
2.17.1


2019-11-13 05:45:10

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] scripts/tools-support-relr.sh: un-quote variables

On Tue, Nov 12, 2019 at 03:45:20PM +0200, Ilie Halip wrote:
> When the CC variable contains quotes, e.g. when using
> ccache (make CC="ccache <compiler>"), this script always
> fails, so CONFIG_RELR is never enabled, even when the
> toolchain supports this feature. Removing the /dev/null
> redirect and invoking the script manually shows the issue:
>
> $ CC='/usr/bin/ccache clang' ./scripts/tools-support-relr.sh
> ./scripts/tools-support-relr.sh: 7: ./scripts/tools-support-relr.sh: /usr/bin/ccache clang: not found
>
> Fix this by un-quoting the variables.
>
> Before:
> $ make ARCH=arm64 CC='/usr/bin/ccache clang' LD=ld.lld \
> NM=llvm-nm OBJCOPY=llvm-objcopy defconfig
> $ grep RELR .config
> CONFIG_ARCH_HAS_RELR=y
>
> With this change:
> $ make ARCH=arm64 CC='/usr/bin/ccache clang' LD=ld.lld \
> NM=llvm-nm OBJCOPY=llvm-objcopy defconfig
> $ grep RELR .config
> CONFIG_TOOLS_SUPPORT_RELR=y
> CONFIG_ARCH_HAS_RELR=y
> CONFIG_RELR=y
>
> Fixes: 5cf896fb6be3 ("arm64: Add support for relocating the kernel with RELR relocations")
> Reported-by: Dmitry Golovin <[email protected]>
> Link: https://github.com/ClangBuiltLinux/linux/issues/769
> Cc: Peter Collingbourne <[email protected]>
> Signed-off-by: Ilie Halip <[email protected]>

Reviewed-by: Nathan Chancellor <[email protected]>

2019-11-13 10:32:33

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH] scripts/tools-support-relr.sh: un-quote variables

On Tue, Nov 12, 2019 at 03:45:20PM +0200, Ilie Halip wrote:
> When the CC variable contains quotes, e.g. when using
> ccache (make CC="ccache <compiler>"), this script always
> fails, so CONFIG_RELR is never enabled, even when the
> toolchain supports this feature. Removing the /dev/null
> redirect and invoking the script manually shows the issue:
>
> $ CC='/usr/bin/ccache clang' ./scripts/tools-support-relr.sh
> ./scripts/tools-support-relr.sh: 7: ./scripts/tools-support-relr.sh: /usr/bin/ccache clang: not found
>
> Fix this by un-quoting the variables.
>
> Before:
> $ make ARCH=arm64 CC='/usr/bin/ccache clang' LD=ld.lld \
> NM=llvm-nm OBJCOPY=llvm-objcopy defconfig
> $ grep RELR .config
> CONFIG_ARCH_HAS_RELR=y
>
> With this change:
> $ make ARCH=arm64 CC='/usr/bin/ccache clang' LD=ld.lld \
> NM=llvm-nm OBJCOPY=llvm-objcopy defconfig
> $ grep RELR .config
> CONFIG_TOOLS_SUPPORT_RELR=y
> CONFIG_ARCH_HAS_RELR=y
> CONFIG_RELR=y
>
> Fixes: 5cf896fb6be3 ("arm64: Add support for relocating the kernel with RELR relocations")
> Reported-by: Dmitry Golovin <[email protected]>
> Link: https://github.com/ClangBuiltLinux/linux/issues/769
> Cc: Peter Collingbourne <[email protected]>
> Signed-off-by: Ilie Halip <[email protected]>
> ---
> scripts/tools-support-relr.sh | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)

Thanks, I'll queue this as a fix.

Will

2019-11-13 10:39:41

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] scripts/tools-support-relr.sh: un-quote variables

On Wed, Nov 13, 2019 at 7:31 PM Will Deacon <[email protected]> wrote:
>
> On Tue, Nov 12, 2019 at 03:45:20PM +0200, Ilie Halip wrote:
> > When the CC variable contains quotes, e.g. when using
> > ccache (make CC="ccache <compiler>"), this script always
> > fails, so CONFIG_RELR is never enabled, even when the
> > toolchain supports this feature. Removing the /dev/null
> > redirect and invoking the script manually shows the issue:
> >
> > $ CC='/usr/bin/ccache clang' ./scripts/tools-support-relr.sh
> > ./scripts/tools-support-relr.sh: 7: ./scripts/tools-support-relr.sh: /usr/bin/ccache clang: not found
> >
> > Fix this by un-quoting the variables.
> >
> > Before:
> > $ make ARCH=arm64 CC='/usr/bin/ccache clang' LD=ld.lld \
> > NM=llvm-nm OBJCOPY=llvm-objcopy defconfig
> > $ grep RELR .config
> > CONFIG_ARCH_HAS_RELR=y
> >
> > With this change:
> > $ make ARCH=arm64 CC='/usr/bin/ccache clang' LD=ld.lld \
> > NM=llvm-nm OBJCOPY=llvm-objcopy defconfig
> > $ grep RELR .config
> > CONFIG_TOOLS_SUPPORT_RELR=y
> > CONFIG_ARCH_HAS_RELR=y
> > CONFIG_RELR=y
> >
> > Fixes: 5cf896fb6be3 ("arm64: Add support for relocating the kernel with RELR relocations")
> > Reported-by: Dmitry Golovin <[email protected]>
> > Link: https://github.com/ClangBuiltLinux/linux/issues/769
> > Cc: Peter Collingbourne <[email protected]>
> > Signed-off-by: Ilie Halip <[email protected]>
> > ---
> > scripts/tools-support-relr.sh | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
>
> Thanks, I'll queue this as a fix.
>
> Will

Reviewed-by: Masahiro Yamada <[email protected]>


--
Best Regards
Masahiro Yamada