Mandate optimized assembler for x86-64 __memset_chk.
Change-Id: I4d6b452f3cf850d405e8f5d7da01d432603e606b
diff --git a/libc/arch-x86_64/string/sse2-memset-slm.S b/libc/arch-x86_64/string/sse2-memset-slm.S
index bfcafae..15253da 100644
--- a/libc/arch-x86_64/string/sse2-memset-slm.S
+++ b/libc/arch-x86_64/string/sse2-memset-slm.S
@@ -28,11 +28,9 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "cache.h"
+#include <private/bionic_asm.h>
-#ifndef MEMSET
-# define MEMSET memset
-#endif
+#include "cache.h"
#ifndef L
# define L(label) .L##label
@@ -42,30 +40,19 @@
# define ALIGN(n) .p2align n
#endif
-#ifndef cfi_startproc
-# define cfi_startproc .cfi_startproc
-#endif
-#ifndef cfi_endproc
-# define cfi_endproc .cfi_endproc
-#endif
+ENTRY(__memset_chk)
+ # %rdi = dst, %rsi = byte, %rdx = n, %rcx = dst_len
+ cmp %rdx, %rcx
+ jl memset
-#ifndef ENTRY
-# define ENTRY(name) \
- .type name, @function; \
- .globl name; \
-name: \
- cfi_startproc
-#endif
+ # TODO: include __memset_chk_fail in the backtrace?
+ call PIC_PLT(__memset_chk_fail)
+END(__memset_chk)
-#ifndef END
-# define END(name) \
- cfi_endproc; \
- .size name, .-name
-#endif
.section .text.sse2,"ax",@progbits
-ENTRY (MEMSET)
+ENTRY(memset)
movq %rdi, %rax
#ifdef USE_AS_BZERO_P
mov %rsi, %rdx
@@ -170,4 +157,4 @@
sfence
ret
-END (MEMSET)
+END(memset)
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index a1db2a4..ccbdec0 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -153,7 +153,7 @@
return memrchr(s, c, n);
}
-#if !defined(__aarch64__) && !defined(__arm__) // TODO: add optimized assembler for the others too.
+#if !defined(__aarch64__) && !defined(__arm__) && !defined(__x86_64__) // TODO: add optimized assembler for the others too.
// Runtime implementation of __builtin___memset_chk (used directly by compiler, not in headers).
extern "C" void* __memset_chk(void* dst, int byte, size_t count, size_t dst_len) {
__check_count("memset", "count", count);