Merge "Use ifunc for ARM32 fortify functions"

This commit is contained in:
Haibo Huang 2018-11-29 00:47:35 +00:00 committed by Gerrit Code Review
commit 7260329093
16 changed files with 119 additions and 149 deletions

View file

@ -691,120 +691,32 @@ cc_library_static {
arch: {
arm: {
cflags: ["-DNO___MEMCPY_CHK"],
cflags: [
"-DNO___MEMCPY_CHK",
"-DRENAME___STRCAT_CHK",
"-DRENAME___STRCPY_CHK",
],
srcs: [
"arch-arm/generic/bionic/__memcpy_chk.S",
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
"arch-arm/cortex-a7/bionic/__strcat_chk.S",
"arch-arm/cortex-a7/bionic/__strcpy_chk.S",
"arch-arm/cortex-a9/bionic/__strcat_chk.S",
"arch-arm/cortex-a9/bionic/__strcpy_chk.S",
"arch-arm/krait/bionic/__strcat_chk.S",
"arch-arm/krait/bionic/__strcpy_chk.S",
"arch-arm/cortex-a53/bionic/__strcat_chk.S",
"arch-arm/cortex-a53/bionic/__strcpy_chk.S",
"arch-arm/denver/bionic/__strcat_chk.S",
"arch-arm/denver/bionic/__strcpy_chk.S",
],
neon: {
cflags: [
"-DNO___STRCAT_CHK",
"-DNO___STRCPY_CHK",
],
srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
cortex_a7: {
srcs: [
"arch-arm/cortex-a7/bionic/__strcat_chk.S",
"arch-arm/cortex-a7/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
cortex_a9: {
srcs: [
"arch-arm/cortex-a9/bionic/__strcat_chk.S",
"arch-arm/cortex-a9/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
krait: {
srcs: [
"arch-arm/krait/bionic/__strcat_chk.S",
"arch-arm/krait/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
cortex_a53: {
srcs: [
"arch-arm/cortex-a53/bionic/__strcat_chk.S",
"arch-arm/cortex-a53/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
cortex_a55: {
srcs: [
"arch-arm/denver/bionic/__strcat_chk.S",
"arch-arm/denver/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
cortex_a73: {
srcs: [
"arch-arm/denver/bionic/__strcat_chk.S",
"arch-arm/denver/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
cortex_a75: {
srcs: [
"arch-arm/denver/bionic/__strcat_chk.S",
"arch-arm/denver/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
cortex_a76: {
srcs: [
"arch-arm/denver/bionic/__strcat_chk.S",
"arch-arm/denver/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
denver: {
srcs: [
"arch-arm/denver/bionic/__strcat_chk.S",
"arch-arm/denver/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
kryo: {
srcs: [
"arch-arm/krait/bionic/__strcat_chk.S",
"arch-arm/krait/bionic/__strcpy_chk.S",
],
exclude_srcs: [
"arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/__strcpy_chk.S",
],
},
},
arm64: {
cflags: ["-DNO___MEMCPY_CHK"],

View file

@ -40,7 +40,7 @@
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
ENTRY(__strcat_chk)
ENTRY(__strcat_chk_a15)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -200,4 +200,4 @@ ENTRY(__strcat_chk)
.cfi_adjust_cfa_offset 8
.cfi_rel_offset r4, 0
.cfi_rel_offset r5, 4
END(__strcat_chk)
END(__strcat_chk_a15)

View file

@ -39,7 +39,7 @@
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
ENTRY(__strcpy_chk_a15)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -162,4 +162,4 @@ ENTRY(__strcpy_chk)
#include "memcpy_base.S"
END(__strcpy_chk)
END(__strcpy_chk_a15)

View file

@ -40,7 +40,7 @@
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
ENTRY(__strcat_chk)
ENTRY(__strcat_chk_a53)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -200,4 +200,4 @@ ENTRY(__strcat_chk)
.cfi_adjust_cfa_offset 8
.cfi_rel_offset r4, 0
.cfi_rel_offset r5, 4
END(__strcat_chk)
END(__strcat_chk_a53)

View file

@ -39,7 +39,7 @@
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
ENTRY(__strcpy_chk_a53)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -162,4 +162,4 @@ ENTRY(__strcpy_chk)
#include "memcpy_base.S"
END(__strcpy_chk)
END(__strcpy_chk_a53)

View file

@ -40,7 +40,7 @@
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
ENTRY(__strcat_chk)
ENTRY(__strcat_chk_a7)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -200,4 +200,4 @@ ENTRY(__strcat_chk)
.cfi_adjust_cfa_offset 8
.cfi_rel_offset r4, 0
.cfi_rel_offset r5, 4
END(__strcat_chk)
END(__strcat_chk_a7)

View file

@ -39,7 +39,7 @@
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
ENTRY(__strcpy_chk_a7)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -162,4 +162,4 @@ ENTRY(__strcpy_chk)
#include "memcpy_base.S"
END(__strcpy_chk)
END(__strcpy_chk_a7)

View file

@ -33,10 +33,14 @@
.thumb
.thumb_func
// To avoid warning about deprecated instructions, add an explicit
// arch. The code generated is exactly the same.
.arch armv7-a
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
ENTRY(__strcat_chk)
ENTRY(__strcat_chk_a9)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -191,8 +195,8 @@ ENTRY(__strcat_chk)
pop {r4, r5}
// Fall through into the memcpy_base function.
END(__strcat_chk)
END(__strcat_chk_a9)
#define MEMCPY_BASE __strcat_chk_memcpy_base
#define MEMCPY_BASE_ALIGNED __strcat_chk_memcpy_base_aligned
#define MEMCPY_BASE __strcat_chk_a9_memcpy_base
#define MEMCPY_BASE_ALIGNED __strcat_chk_a9_memcpy_base_aligned
#include "memcpy_base.S"

View file

@ -33,9 +33,13 @@
.thumb
.thumb_func
// To avoid warning about deprecated instructions, add an explicit
// arch. The code generated is exactly the same.
.arch armv7-a
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
ENTRY(__strcpy_chk_a9)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -159,8 +163,8 @@ ENTRY(__strcpy_chk)
bhi __strcpy_chk_fail
// Fall through into the memcpy_base function.
END(__strcpy_chk)
END(__strcpy_chk_a9)
#define MEMCPY_BASE __strcpy_chk_memcpy_base
#define MEMCPY_BASE_ALIGNED __strcpy_chk_memcpy_base_aligned
#define MEMCPY_BASE __strcpy_chk_a9_memcpy_base
#define MEMCPY_BASE_ALIGNED __strcpy_chk_a9_memcpy_base_aligned
#include "memcpy_base.S"

View file

@ -40,7 +40,7 @@
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
ENTRY(__strcat_chk)
ENTRY(__strcat_chk_denver)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -190,9 +190,9 @@ ENTRY(__strcat_chk)
mov r2, r4
add r0, r0, r3
pop {r4, r5}
END(__strcat_chk)
END(__strcat_chk_denver)
#define MEMCPY_BASE __strcat_chk_memcpy_base
#define MEMCPY_BASE_ALIGNED __strcat_chk_memcpy_base_aligned
#define MEMCPY_BASE __strcat_chk_denver_memcpy_base
#define MEMCPY_BASE_ALIGNED __strcat_chk_denver_memcpy_base_aligned
#include "memcpy_base.S"

View file

@ -39,7 +39,7 @@
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
ENTRY(__strcpy_chk_denver)
pld [r0, #0]
push {r0, lr}
.cfi_def_cfa_offset 8
@ -161,8 +161,8 @@ ENTRY(__strcpy_chk)
bhi __strcpy_chk_fail
// Fall through into the memcpy_base function.
END(__strcpy_chk)
END(__strcpy_chk_denver)
#define MEMCPY_BASE __strcpy_chk_memcpy_base
#define MEMCPY_BASE_ALIGNED __strcpy_chk_memcpy_base_aligned
#define MEMCPY_BASE __strcpy_chk_denver_memcpy_base
#define MEMCPY_BASE_ALIGNED __strcpy_chk_denver_memcpy_base_aligned
#include "memcpy_base.S"

View file

@ -220,6 +220,26 @@ DEFINE_IFUNC(strcpy) {
}
}
typedef char* __strcpy_chk_func(char* dst, const char* src, size_t dst_len);
DEFINE_IFUNC(__strcpy_chk) {
switch(get_cpu_variant()) {
case kCortexA7:
RETURN_FUNC(__strcpy_chk_func, __strcpy_chk_a7);
case kCortexA9:
RETURN_FUNC(__strcpy_chk_func, __strcpy_chk_a9);
case kKrait:
case kKryo:
RETURN_FUNC(__strcpy_chk_func, __strcpy_chk_krait);
case kCortexA53:
RETURN_FUNC(__strcpy_chk_func, __strcpy_chk_a53);
case kCortexA55:
case kDenver:
RETURN_FUNC(__strcpy_chk_func, __strcpy_chk_denver);
default:
RETURN_FUNC(__strcpy_chk_func, __strcpy_chk_a15);
}
}
typedef char* stpcpy_func(char* __dst, const char* __src);
DEFINE_IFUNC(stpcpy) {
switch(get_cpu_variant()) {
@ -240,6 +260,26 @@ DEFINE_IFUNC(strcat) {
}
}
typedef char* __strcat_chk_func(char* dst, const char* src, size_t dst_buf_size);
DEFINE_IFUNC(__strcat_chk) {
switch(get_cpu_variant()) {
case kCortexA7:
RETURN_FUNC(__strcat_chk_func, __strcat_chk_a7);
case kCortexA9:
RETURN_FUNC(__strcat_chk_func, __strcat_chk_a9);
case kKrait:
case kKryo:
RETURN_FUNC(__strcat_chk_func, __strcat_chk_krait);
case kCortexA53:
RETURN_FUNC(__strcat_chk_func, __strcat_chk_a53);
case kCortexA55:
case kDenver:
RETURN_FUNC(__strcat_chk_func, __strcat_chk_denver);
default:
RETURN_FUNC(__strcat_chk_func, __strcat_chk_a15);
}
}
typedef int strcmp_func(const char* __lhs, const char* __rhs);
DEFINE_IFUNC(strcmp) {
switch(get_cpu_variant()) {

View file

@ -40,7 +40,7 @@
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
ENTRY(__strcat_chk)
ENTRY(__strcat_chk_krait)
pld [r0, #0]
push {r0, lr}
.cfi_adjust_cfa_offset 8
@ -200,4 +200,4 @@ ENTRY(__strcat_chk)
.cfi_adjust_cfa_offset 8
.cfi_rel_offset r4, 0
.cfi_rel_offset r5, 4
END(__strcat_chk)
END(__strcat_chk_krait)

View file

@ -39,7 +39,7 @@
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
ENTRY(__strcpy_chk_krait)
pld [r0, #0]
push {r0, lr}
.cfi_adjust_cfa_offset 8
@ -162,4 +162,4 @@ ENTRY(__strcpy_chk)
#include "memcpy_base.S"
END(__strcpy_chk)
END(__strcpy_chk_krait)

View file

@ -38,7 +38,9 @@ FUNCTION_DELEGATE(memcpy, memmove_generic)
FUNCTION_DELEGATE(memset, memset_generic)
FUNCTION_DELEGATE(__memset_chk, __memset_chk_generic)
FUNCTION_DELEGATE(strcpy, strcpy_generic)
FUNCTION_DELEGATE(__strcpy_chk, __strcpy_chk_generic)
FUNCTION_DELEGATE(stpcpy, stpcpy_generic)
FUNCTION_DELEGATE(strcat, strcat_generic)
FUNCTION_DELEGATE(__strcat_chk, __strcat_chk_generic)
FUNCTION_DELEGATE(strcmp, strcmp_generic)
FUNCTION_DELEGATE(strlen, strlen_generic)

View file

@ -454,9 +454,14 @@ ssize_t __write_chk(int fd, const void* buf, size_t count, size_t buf_size) {
return write(fd, buf, count);
}
#if !defined(NO___STRCAT_CHK)
#if defined(RENAME___STRCAT_CHK)
#define __STRCAT_CHK __strcat_chk_generic
#else
#define __STRCAT_CHK __strcat_chk
#endif // RENAME___STRCAT_CHK
// Runtime implementation of __builtin____strcat_chk (used directly by compiler, not in headers).
extern "C" char* __strcat_chk(char* dst, const char* src, size_t dst_buf_size) {
extern "C" char* __STRCAT_CHK(char* dst, const char* src, size_t dst_buf_size) {
char* save = dst;
size_t dst_len = __strlen_chk(dst, dst_buf_size);
@ -472,17 +477,20 @@ extern "C" char* __strcat_chk(char* dst, const char* src, size_t dst_buf_size) {
return save;
}
#endif // NO___STRCAT_CHK
#if !defined(NO___STRCPY_CHK)
#if defined(RENAME___STRCPY_CHK)
#define __STRCPY_CHK __strcpy_chk_generic
#else
#define __STRCPY_CHK __strcpy_chk
#endif // RENAME___STRCPY_CHK
// Runtime implementation of __builtin____strcpy_chk (used directly by compiler, not in headers).
extern "C" char* __strcpy_chk(char* dst, const char* src, size_t dst_len) {
extern "C" char* __STRCPY_CHK(char* dst, const char* src, size_t dst_len) {
// TODO: optimize so we don't scan src twice.
size_t src_len = strlen(src) + 1;
__check_buffer_access("strcpy", "write into", src_len, dst_len);
return strcpy(dst, src);
}
#endif // NO___STRCPY_CHK
#if !defined(NO___MEMCPY_CHK)
// Runtime implementation of __memcpy_chk (used directly by compiler, not in headers).