[PATCH] arm64: Change .weak to SYM_FUNC_START_WEAK_PI for arch/arm64/lib/mem*.S

39 views
Skip to first unread message

Fangrui Song

unread,
Oct 29, 2020, 2:19:59 PM10/29/20
to linux-ar...@lists.infradead.org, Catalin Marinas, Will Deacon, clang-bu...@googlegroups.com, Jian Cai, Fangrui Song, Sami Tolvanen, sta...@vger.kernel.org
Commit 39d114ddc682 ("arm64: add KASAN support") added .weak directives to
arch/arm64/lib/mem*.S instead of changing the existing SYM_FUNC_START_PI
macros. This can lead to the assembly snippet `.weak memcpy ... .globl
memcpy` which will produce a STB_WEAK memcpy with GNU as but STB_GLOBAL
memcpy with LLVM's integrated assembler before LLVM 12. LLVM 12 (since
https://reviews.llvm.org/D90108) will error on such an overridden symbol
binding.

Use the appropriate SYM_FUNC_START_WEAK_PI instead.

Fixes: 39d114ddc682 ("arm64: add KASAN support")
Reported-by: Sami Tolvanen <samito...@google.com>
Signed-off-by: Fangrui Song <mas...@google.com>
Cc: <sta...@vger.kernel.org>
---
arch/arm64/lib/memcpy.S | 3 +--
arch/arm64/lib/memmove.S | 3 +--
arch/arm64/lib/memset.S | 3 +--
3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/lib/memcpy.S b/arch/arm64/lib/memcpy.S
index e0bf83d556f2..dc8d2a216a6e 100644
--- a/arch/arm64/lib/memcpy.S
+++ b/arch/arm64/lib/memcpy.S
@@ -56,9 +56,8 @@
stp \reg1, \reg2, [\ptr], \val
.endm

- .weak memcpy
SYM_FUNC_START_ALIAS(__memcpy)
-SYM_FUNC_START_PI(memcpy)
+SYM_FUNC_START_WEAK_PI(memcpy)
#include "copy_template.S"
ret
SYM_FUNC_END_PI(memcpy)
diff --git a/arch/arm64/lib/memmove.S b/arch/arm64/lib/memmove.S
index 02cda2e33bde..1035dce4bdaf 100644
--- a/arch/arm64/lib/memmove.S
+++ b/arch/arm64/lib/memmove.S
@@ -45,9 +45,8 @@ C_h .req x12
D_l .req x13
D_h .req x14

- .weak memmove
SYM_FUNC_START_ALIAS(__memmove)
-SYM_FUNC_START_PI(memmove)
+SYM_FUNC_START_WEAK_PI(memmove)
cmp dstin, src
b.lo __memcpy
add tmp1, src, count
diff --git a/arch/arm64/lib/memset.S b/arch/arm64/lib/memset.S
index 77c3c7ba0084..a9c1c9a01ea9 100644
--- a/arch/arm64/lib/memset.S
+++ b/arch/arm64/lib/memset.S
@@ -42,9 +42,8 @@ dst .req x8
tmp3w .req w9
tmp3 .req x9

- .weak memset
SYM_FUNC_START_ALIAS(__memset)
-SYM_FUNC_START_PI(memset)
+SYM_FUNC_START_WEAK_PI(memset)
mov dst, dstin /* Preserve return value. */
and A_lw, val, #255
orr A_lw, A_lw, A_lw, lsl #8
--
2.29.1.341.ge80a0c044ae-goog

Sami Tolvanen

unread,
Oct 29, 2020, 2:53:11 PM10/29/20
to Fangrui Song, linux-arm-kernel, Catalin Marinas, Will Deacon, clang-built-linux, Jian Cai, # 3.4.x
On Thu, Oct 29, 2020 at 11:20 AM Fangrui Song <mas...@google.com> wrote:
>
> Commit 39d114ddc682 ("arm64: add KASAN support") added .weak directives to
> arch/arm64/lib/mem*.S instead of changing the existing SYM_FUNC_START_PI
> macros. This can lead to the assembly snippet `.weak memcpy ... .globl
> memcpy` which will produce a STB_WEAK memcpy with GNU as but STB_GLOBAL
> memcpy with LLVM's integrated assembler before LLVM 12. LLVM 12 (since
> https://reviews.llvm.org/D90108) will error on such an overridden symbol
> binding.
>
> Use the appropriate SYM_FUNC_START_WEAK_PI instead.
>
> Fixes: 39d114ddc682 ("arm64: add KASAN support")
> Reported-by: Sami Tolvanen <samito...@google.com>
> Signed-off-by: Fangrui Song <mas...@google.com>
> Cc: <sta...@vger.kernel.org>
> ---
> arch/arm64/lib/memcpy.S | 3 +--
> arch/arm64/lib/memmove.S | 3 +--
> arch/arm64/lib/memset.S | 3 +--
> 3 files changed, 3 insertions(+), 6 deletions(-)

Thanks for the patch! This fixes the build with Clang 12 + LLVM_IAS=1,
and also builds and boots with gcc 9.3 and Clang 12 without IAS.

Tested-by: Sami Tolvanen <samito...@google.com>

Sami

Nick Desaulniers

unread,
Oct 29, 2020, 3:15:40 PM10/29/20
to Fangrui Song, Linux ARM, Catalin Marinas, Will Deacon, clang-built-linux, Jian Cai, Sami Tolvanen, # 3.4.x
On Thu, Oct 29, 2020 at 11:20 AM 'Fangrui Song' via Clang Built Linux
<clang-bu...@googlegroups.com> wrote:
>
> Commit 39d114ddc682 ("arm64: add KASAN support") added .weak directives to
> arch/arm64/lib/mem*.S instead of changing the existing SYM_FUNC_START_PI
> macros. This can lead to the assembly snippet `.weak memcpy ... .globl
> memcpy` which will produce a STB_WEAK memcpy with GNU as but STB_GLOBAL
> memcpy with LLVM's integrated assembler before LLVM 12. LLVM 12 (since
> https://reviews.llvm.org/D90108) will error on such an overridden symbol
> binding.
>
> Use the appropriate SYM_FUNC_START_WEAK_PI instead.
>
> Fixes: 39d114ddc682 ("arm64: add KASAN support")
> Reported-by: Sami Tolvanen <samito...@google.com>
> Signed-off-by: Fangrui Song <mas...@google.com>
> Cc: <sta...@vger.kernel.org>

Before your patch, with GNU `as`:
$ llvm-readelf -s arch/arm64/lib/memcpy.o | grep memcpy
19: 0000000000000000 340 FUNC WEAK DEFAULT 1 memcpy
20: 0000000000000000 340 FUNC GLOBAL DEFAULT 1 __memcpy
21: 0000000000000000 340 FUNC GLOBAL DEFAULT 1 __pi_memcpy
$ llvm-readelf -s arch/arm64/lib/memmove.o | grep memmove
19: 0000000000000000 340 FUNC WEAK DEFAULT 1 memmove
20: 0000000000000000 340 FUNC GLOBAL DEFAULT 1 __memmove
21: 0000000000000000 340 FUNC GLOBAL DEFAULT 1 __pi_memmove
$ llvm-readelf -s arch/arm64/lib/memset.o | grep memset
19: 0000000000000000 392 FUNC WEAK DEFAULT 1 memset
20: 0000000000000000 392 FUNC GLOBAL DEFAULT 1 __memset
21: 0000000000000000 392 FUNC GLOBAL DEFAULT 1 __pi_memset
After your patch, with GNU `as`:
$ llvm-readelf -s arch/arm64/lib/memcpy.o | grep memcpy
19: 0000000000000000 340 FUNC GLOBAL DEFAULT 1 __memcpy
20: 0000000000000000 340 FUNC GLOBAL DEFAULT 1 __pi_memcpy
21: 0000000000000000 340 FUNC WEAK DEFAULT 1 memcpy
$ llvm-readelf -s arch/arm64/lib/memmove.o | grep memmove
19: 0000000000000000 340 FUNC GLOBAL DEFAULT 1 __memmove
20: 0000000000000000 340 FUNC GLOBAL DEFAULT 1 __pi_memmove
21: 0000000000000000 340 FUNC WEAK DEFAULT 1 memmove
$ llvm-readelf -s arch/arm64/lib/memset.o | grep memset
19: 0000000000000000 392 FUNC GLOBAL DEFAULT 1 __memset
20: 0000000000000000 392 FUNC GLOBAL DEFAULT 1 __pi_memset
21: 0000000000000000 392 FUNC WEAK DEFAULT 1 memset

So it didn't change any bindings (good), but it did reorder symbols.
I suspect if you flip the ordering of SYM_FUNC_START_WEAK_PI relative
to SYM_FUNC_START_ALIAS you can get the previous ordering back, but I
also suspect that the ordering of these symbols is not important.

Reviewed-by: Nick Desaulniers <ndesau...@google.com>
Tested-by: Nick Desaulniers <ndesau...@google.com>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-li...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20201029181951.1866093-1-maskray%40google.com.



--
Thanks,
~Nick Desaulniers

Will Deacon

unread,
Oct 30, 2020, 12:33:34 PM10/30/20
to Fangrui Song, Catalin Marinas, linux-ar...@lists.infradead.org, kerne...@android.com, Will Deacon, Sami Tolvanen, Jian Cai, clang-bu...@googlegroups.com, sta...@vger.kernel.org
On Thu, 29 Oct 2020 11:19:51 -0700, Fangrui Song wrote:
> Commit 39d114ddc682 ("arm64: add KASAN support") added .weak directives to
> arch/arm64/lib/mem*.S instead of changing the existing SYM_FUNC_START_PI
> macros. This can lead to the assembly snippet `.weak memcpy ... .globl
> memcpy` which will produce a STB_WEAK memcpy with GNU as but STB_GLOBAL
> memcpy with LLVM's integrated assembler before LLVM 12. LLVM 12 (since
> https://reviews.llvm.org/D90108) will error on such an overridden symbol
> binding.
>
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: Change .weak to SYM_FUNC_START_WEAK_PI for arch/arm64/lib/mem*.S
https://git.kernel.org/arm64/c/ec9d78070de9

Cheers,
--
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
Reply all
Reply to author
Forward
0 new messages