memset_chk into assembly file
Writing an assembly file can reduce several
assembly instructions, and compare it through
the disassembly of this file
Test: make libc
Change-Id: Ifdcc9c76742cc95b2ad9e3c14fac4796c36e12e6
Signed-off-by: caowencheng <caowencheng@eswincomputing.com>
diff --git a/libc/Android.bp b/libc/Android.bp
index 1e65fea..23b381d 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -672,7 +672,6 @@
},
riscv64: {
srcs: [
- "arch-riscv64/string/memset_chk.c",
"upstream-freebsd/lib/libc/string/memcmp.c",
"upstream-freebsd/lib/libc/string/memcpy.c",
"upstream-freebsd/lib/libc/string/memmove.c",
@@ -825,6 +824,11 @@
"arch-arm64/string/__memset_chk.S",
],
},
+ riscv64: {
+ srcs: [
+ "arch-riscv64/string/__memset_chk.S",
+ ],
+ },
},
}
diff --git a/libc/arch-riscv64/string/__memset_chk.S b/libc/arch-riscv64/string/__memset_chk.S
new file mode 100644
index 0000000..a5562cb
--- /dev/null
+++ b/libc/arch-riscv64/string/__memset_chk.S
@@ -0,0 +1,10 @@
+#include <private/bionic_asm.h>
+
+ENTRY(__memset_chk)
+ bleu a2, a3, 1f
+ call __memset_chk_fail
+
+1:
+ tail memset
+END(__memset_chk)
+
diff --git a/libc/arch-riscv64/string/memset_chk.c b/libc/arch-riscv64/string/memset_chk.c
deleted file mode 100644
index bdd15a5..0000000
--- a/libc/arch-riscv64/string/memset_chk.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <stdint.h>
-
-extern void* memset(void*, int, size_t);
-extern void* __memset_chk_fail(void*, int, size_t, size_t);
-
-void* __memset_chk(void* dst, int c, size_t n, size_t dst_len) {
- if (dst_len < n) __memset_chk_fail(dst, c, n, dst_len);
- return memset(dst, c, n);
-}