Skip to contentSkip to conversation

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

PATCH Applied Fangrui Song 4 participants 4 messages Oct 29, 2020 – Oct 30, 2020

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

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

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")
---
 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(-)
arch/arm64/lib/memcpy.S +1 -2
index e0bf83d556f2..dc8d2a216a6e 100644
@@ -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)
arch/arm64/lib/memmove.S +1 -2
index 02cda2e33bde..1035dce4bdaf 100644
@@ -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
arch/arm64/lib/memset.S +1 -2
index 77c3c7ba0084..a9c1c9a01ea9 100644
@@ -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
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
Tested-by on v1 1/1
#1 lore raw
Quoted 15 lines · Fangrui Song

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")
Quoted 5 lines
---
 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.

Sami

Reviewed-by Tested-by on v1 1/1
#2 lore raw
In reply to Fangrui Song
Quoted 9 lines · Fangrui Song' via Clang Built Linux

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.

Quoted 6 lines

Use the appropriate SYM_FUNC_START_WEAK_PI instead.

Fixes 39d114ddc682 ("arm64: add KASAN support")

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.

Quoted 58 lines
---
 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(-)
arch/arm64/lib/memcpy.S +1 -2
index e0bf83d556f2..dc8d2a216a6e 100644
@@ -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)
arch/arm64/lib/memmove.S +1 -2
index 02cda2e33bde..1035dce4bdaf 100644
@@ -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
arch/arm64/lib/memset.S +1 -3
index 77c3c7ba0084..a9c1c9a01ea9 100644
@@ -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

--
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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20201029181951.1866093-1-maskray%40google.com.

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer Applied
#3 lore raw
In reply to Fangrui Song
Quoted 9 lines · Fangrui Song

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,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev