Merge "Mandate optimized __memset_chk for arm and arm64."

am: 5e57039c24

* commit '5e57039c24d8aa777480e33255d627ca28af7dfe':
  Mandate optimized __memset_chk for arm and arm64.
This commit is contained in:
Elliott Hughes 2016-03-03 00:42:51 +00:00 committed by android-build-merger
commit e579456a80
6 changed files with 38 additions and 58 deletions

View file

@ -232,7 +232,6 @@ libc_bionic_src_files += bionic/setjmp_cookie.cpp
libc_bionic_src_files += \
bionic/__memcpy_chk.cpp \
bionic/__memset_chk.cpp \
bionic/__strcat_chk.cpp \
bionic/__strcpy_chk.cpp \
bionic/strchr.cpp \

View file

@ -10,7 +10,6 @@ libc_bionic_src_files_arm += \
libc_bionic_src_files_exclude_arm += \
bionic/__memcpy_chk.cpp \
bionic/__memset_chk.cpp \
libc_openbsd_src_files_exclude_arm += \
upstream-openbsd/lib/libc/string/strcpy.c \

View file

@ -48,6 +48,7 @@
#define dstin x0
#define val w1
#define count x2
#define dst_count x3 /* for __memset_chk */
#define tmp1 x3
#define tmp1w w3
#define tmp2 x4
@ -63,6 +64,19 @@
#define QA_l q0
ENTRY(__memset_chk)
cmp count, dst_count
bls memset
// Preserve for accurate backtrace.
stp x29, x30, [sp, -16]!
.cfi_def_cfa_offset 16
.cfi_rel_offset x29, 0
.cfi_rel_offset x30, 8
bl __memset_chk_fail
END(__memset_chk)
ENTRY(memset)
mov dst, dstin /* Preserve return value. */

View file

@ -45,12 +45,9 @@
values rather than re-reading them each call. */
#define dstin x0
#ifdef BZERO
#define count x1
#else
#define count x2
#endif
#define val w1
#define count x2
#define dst_count x3 /* for __memset_chk */
#define tmp1 x3
#define tmp1w w3
#define tmp2 x4
@ -64,16 +61,22 @@
#define dst x8
#define tmp3w w9
#ifdef BZERO
ENTRY(bzero)
#else
ENTRY(__memset_chk)
cmp count, dst_count
bls memset
// Preserve for accurate backtrace.
stp x29, x30, [sp, -16]!
.cfi_def_cfa_offset 16
.cfi_rel_offset x29, 0
.cfi_rel_offset x30, 8
bl __memset_chk_fail
END(__memset_chk)
ENTRY(memset)
#endif
mov dst, dstin /* Preserve return value. */
#ifdef BZERO
b .Lzero_mem
#endif
ands A_lw, val, #255
b.eq .Lzero_mem
orr A_lw, A_lw, A_lw, lsl #8
@ -233,11 +236,7 @@ ENTRY(memset)
ands count, count, zva_bits_x
b.ne .Ltail_maybe_long
ret
#ifdef BZERO
END(bzero)
#else
END(memset)
#endif
#ifdef MAYBE_VIRT
.bss

View file

@ -1,40 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#undef _FORTIFY_SOURCE
#include <string.h>
#include "private/bionic_fortify.h"
// 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);
__check_buffer_access("memset", "write into", count, dst_len);
return memset(dst, byte, count);
}

View file

@ -153,6 +153,15 @@ void* __memrchr_chk(const void* s, int c, size_t n, size_t actual_size) {
return memrchr(s, c, n);
}
#if !defined(__aarch64__) && !defined(__arm__) // 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);
__check_buffer_access("memset", "write into", count, dst_len);
return memset(dst, byte, count);
}
#endif
// memset is performance-critical enough that we have assembler __memset_chk implementations.
// This function is used to give better diagnostics than we can easily do from assembler.
extern "C" void* __memset_chk_fail(void* /*dst*/, int /*byte*/, size_t count, size_t dst_len) {