aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2017-07-21 13:28:42 -0700
committerGeorge Burgess IV <gbiv@google.com>2017-07-24 14:20:16 -0700
commit6cb06879323cb45440ca1c7b42a2cc754b3d50c6 (patch)
tree6c57a6539009e2af358daa368f538e82da1593f2
parent248b5cb672a9eadde695edb7d73e9d1ed5cb0b7f (diff)
downloadbionic-6cb06879323cb45440ca1c7b42a2cc754b3d50c6.tar.gz
Split our FORTIFY implementation into libc_fortify
As requested in the bug. This also rips __memcpy_chk out of memcpy.S, which lets us cut down on copypasta (all of the implementations look identical). Bug: 12231437 Test: mma on aosp_{arm,arm64,mips,x86,x86_64} internal master; checkbuild on bullhead internal master; CtsBionicTestCases on bullhead. No new failures. Change-Id: I88c39ca166bacde0b692aa3063e743bb046a5d2f
-rw-r--r--libc/Android.bp188
-rw-r--r--libc/arch-arm/cortex-a15/bionic/memcpy.S11
-rw-r--r--libc/arch-arm/cortex-a53/bionic/memcpy.S11
-rw-r--r--libc/arch-arm/cortex-a7/bionic/memcpy.S11
-rw-r--r--libc/arch-arm/cortex-a9/bionic/memcpy.S12
-rw-r--r--libc/arch-arm/denver/bionic/memcpy.S12
-rw-r--r--libc/arch-arm/generic/bionic/__memcpy_chk.S43
-rw-r--r--libc/arch-arm/generic/bionic/memcpy.S12
-rw-r--r--libc/arch-arm/krait/bionic/memcpy.S12
-rw-r--r--libc/arch-arm/kryo/bionic/memcpy.S12
-rw-r--r--libc/arch-arm64/denver64/bionic/memcpy.S13
-rw-r--r--libc/arch-arm64/generic/bionic/__memcpy_chk.S42
-rw-r--r--libc/arch-arm64/generic/bionic/memcpy.S13
-rw-r--r--libc/bionic/__memcpy_chk.cpp2
-rw-r--r--libc/bionic/__strcpy_chk.cpp2
-rw-r--r--libc/bionic/fortify.cpp2
16 files changed, 226 insertions, 172 deletions
diff --git a/libc/Android.bp b/libc/Android.bp
index 7b0ac23f3..49c3899bc 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -776,6 +776,145 @@ cc_library_static {
}
// ========================================================
+// libc_fortify.a - container for our FORITFY
+// implementation details
+// ========================================================
+cc_library_static {
+ defaults: ["libc_defaults"],
+ srcs: [
+ "bionic/__memcpy_chk.cpp",
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ "bionic/fortify.cpp",
+ ],
+
+ name: "libc_fortify",
+
+ // Disable FORTIFY for the compilation of these, so we don't end up having
+ // FORTIFY silently call itself.
+ cflags: ["-U_FORTIFY_SOURCE"],
+
+ arch: {
+ arm: {
+ srcs: [
+ "arch-arm/generic/bionic/__memcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__memcpy_chk.cpp",
+ ],
+ cortex_a7: {
+ srcs: [
+ "arch-arm/cortex-a7/bionic/__strcat_chk.S",
+ "arch-arm/cortex-a7/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ cortex_a53: {
+ srcs: [
+ "arch-arm/cortex-a53/bionic/__strcat_chk.S",
+ "arch-arm/cortex-a53/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ cortex_a53_a57: {
+ srcs: [
+ "arch-arm/cortex-a15/bionic/__strcat_chk.S",
+ "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ cortex_a8: {
+ srcs: [
+ "arch-arm/cortex-a15/bionic/__strcat_chk.S",
+ "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ cortex_a9: {
+ srcs: [
+ "arch-arm/cortex-a9/bionic/__strcat_chk.S",
+ "arch-arm/cortex-a9/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ cortex_a15: {
+ srcs: [
+ "arch-arm/cortex-a15/bionic/__strcat_chk.S",
+ "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ cortex_a73: {
+ srcs: [
+ "arch-arm/denver/bionic/__strcat_chk.S",
+ "arch-arm/denver/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ denver: {
+ srcs: [
+ "arch-arm/denver/bionic/__strcat_chk.S",
+ "arch-arm/denver/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ krait: {
+ srcs: [
+ "arch-arm/krait/bionic/__strcat_chk.S",
+ "arch-arm/krait/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ kryo: {
+ srcs: [
+ "arch-arm/krait/bionic/__strcat_chk.S",
+ "arch-arm/krait/bionic/__strcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__strcat_chk.cpp",
+ "bionic/__strcpy_chk.cpp",
+ ],
+ },
+ },
+ arm64: {
+ srcs: [
+ "arch-arm64/generic/bionic/__memcpy_chk.S",
+ ],
+ exclude_srcs: [
+ "bionic/__memcpy_chk.cpp",
+ ],
+ },
+ },
+}
+
+// ========================================================
// libc_bionic.a - home-grown C library code
// ========================================================
@@ -804,9 +943,6 @@ cc_library_static {
// debuggerd will look for the abort message in libc.so's copy.
"bionic/android_set_abort_message.cpp",
- "bionic/__memcpy_chk.cpp",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
"bionic/strchr.cpp",
"bionic/strnlen.c",
"bionic/strrchr.cpp",
@@ -832,15 +968,10 @@ cc_library_static {
"arch-arm/bionic/syscall.S",
"arch-arm/bionic/vfork.S",
],
- exclude_srcs: [
- "bionic/__memcpy_chk.cpp",
- ],
cortex_a7: {
srcs: [
"arch-arm/cortex-a7/bionic/memset.S",
"arch-arm/cortex-a7/bionic/memcpy.S",
- "arch-arm/cortex-a7/bionic/__strcat_chk.S",
- "arch-arm/cortex-a7/bionic/__strcpy_chk.S",
"arch-arm/cortex-a15/bionic/stpcpy.S",
"arch-arm/cortex-a15/bionic/strcat.S",
@@ -856,15 +987,11 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
cortex_a53: {
srcs: [
"arch-arm/cortex-a53/bionic/memcpy.S",
- "arch-arm/cortex-a53/bionic/__strcat_chk.S",
- "arch-arm/cortex-a53/bionic/__strcpy_chk.S",
"arch-arm/cortex-a7/bionic/memset.S",
@@ -882,8 +1009,6 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
cortex_a53_a57: {
@@ -892,10 +1017,8 @@ cc_library_static {
"arch-arm/cortex-a15/bionic/memset.S",
"arch-arm/cortex-a15/bionic/stpcpy.S",
"arch-arm/cortex-a15/bionic/strcat.S",
- "arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/strcmp.S",
"arch-arm/cortex-a15/bionic/strcpy.S",
- "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
"arch-arm/cortex-a15/bionic/strlen.S",
"arch-arm/denver/bionic/memmove.S",
@@ -906,8 +1029,6 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
cortex_a8: {
@@ -916,10 +1037,8 @@ cc_library_static {
"arch-arm/cortex-a15/bionic/memset.S",
"arch-arm/cortex-a15/bionic/stpcpy.S",
"arch-arm/cortex-a15/bionic/strcat.S",
- "arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/strcmp.S",
"arch-arm/cortex-a15/bionic/strcpy.S",
- "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
"arch-arm/cortex-a15/bionic/strlen.S",
"arch-arm/denver/bionic/memmove.S",
@@ -930,8 +1049,6 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
cortex_a9: {
@@ -940,10 +1057,8 @@ cc_library_static {
"arch-arm/cortex-a9/bionic/memset.S",
"arch-arm/cortex-a9/bionic/stpcpy.S",
"arch-arm/cortex-a9/bionic/strcat.S",
- "arch-arm/cortex-a9/bionic/__strcat_chk.S",
"arch-arm/cortex-a9/bionic/strcmp.S",
"arch-arm/cortex-a9/bionic/strcpy.S",
- "arch-arm/cortex-a9/bionic/__strcpy_chk.S",
"arch-arm/cortex-a9/bionic/strlen.S",
"arch-arm/denver/bionic/memmove.S",
@@ -954,8 +1069,6 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
cortex_a15: {
@@ -964,10 +1077,8 @@ cc_library_static {
"arch-arm/cortex-a15/bionic/memset.S",
"arch-arm/cortex-a15/bionic/stpcpy.S",
"arch-arm/cortex-a15/bionic/strcat.S",
- "arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/strcmp.S",
"arch-arm/cortex-a15/bionic/strcpy.S",
- "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
"arch-arm/cortex-a15/bionic/strlen.S",
"arch-arm/denver/bionic/memmove.S",
@@ -978,8 +1089,6 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
cortex_a73: {
@@ -988,8 +1097,6 @@ cc_library_static {
"arch-arm/denver/bionic/memcpy.S",
"arch-arm/denver/bionic/memmove.S",
- "arch-arm/denver/bionic/__strcat_chk.S",
- "arch-arm/denver/bionic/__strcpy_chk.S",
"arch-arm/krait/bionic/strcmp.S",
@@ -1004,8 +1111,6 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
denver: {
@@ -1013,8 +1118,6 @@ cc_library_static {
"arch-arm/denver/bionic/memcpy.S",
"arch-arm/denver/bionic/memmove.S",
"arch-arm/denver/bionic/memset.S",
- "arch-arm/denver/bionic/__strcat_chk.S",
- "arch-arm/denver/bionic/__strcpy_chk.S",
// Use cortex-a15 versions of strcat/strcpy/strlen.
"arch-arm/cortex-a15/bionic/stpcpy.S",
@@ -1029,8 +1132,6 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
krait: {
@@ -1038,8 +1139,6 @@ cc_library_static {
"arch-arm/krait/bionic/memcpy.S",
"arch-arm/krait/bionic/memset.S",
"arch-arm/krait/bionic/strcmp.S",
- "arch-arm/krait/bionic/__strcat_chk.S",
- "arch-arm/krait/bionic/__strcpy_chk.S",
// Use cortex-a15 versions of strcat/strcpy/strlen.
"arch-arm/cortex-a15/bionic/stpcpy.S",
@@ -1055,8 +1154,6 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
kryo: {
@@ -1064,8 +1161,6 @@ cc_library_static {
"arch-arm/kryo/bionic/memcpy.S",
"arch-arm/cortex-a7/bionic/memset.S",
"arch-arm/krait/bionic/strcmp.S",
- "arch-arm/krait/bionic/__strcat_chk.S",
- "arch-arm/krait/bionic/__strcpy_chk.S",
// Use cortex-a15 versions of strcat/strcpy/strlen.
"arch-arm/cortex-a15/bionic/stpcpy.S",
@@ -1081,8 +1176,6 @@ cc_library_static {
"arch-arm/generic/bionic/strcmp.S",
"arch-arm/generic/bionic/strcpy.S",
"arch-arm/generic/bionic/strlen.c",
- "bionic/__strcat_chk.cpp",
- "bionic/__strcpy_chk.cpp",
],
},
},
@@ -1378,7 +1471,6 @@ cc_library_static {
"bionic/fgetxattr.cpp",
"bionic/flistxattr.cpp",
"bionic/flockfile.cpp",
- "bionic/fortify.cpp",
"bionic/fpclassify.cpp",
"bionic/fsetxattr.cpp",
"bionic/ftruncate.cpp",
@@ -1644,6 +1736,7 @@ cc_library_static {
whole_static_libs: [
"libc_bionic_ndk",
+ "libc_fortify",
"libc_freebsd",
"libc_freebsd_large_stack",
"libc_gdtoa",
@@ -1678,6 +1771,7 @@ cc_library_static {
"libc_bionic",
"libc_bionic_ndk",
"libc_dns",
+ "libc_fortify",
"libc_freebsd",
"libc_freebsd_large_stack",
"libc_gdtoa",
diff --git a/libc/arch-arm/cortex-a15/bionic/memcpy.S b/libc/arch-arm/cortex-a15/bionic/memcpy.S
index 7ad009357..4297cd6c1 100644
--- a/libc/arch-arm/cortex-a15/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a15/bionic/memcpy.S
@@ -63,17 +63,6 @@
// arch. The code generated is exactly the same.
.arch armv7-a
-ENTRY(__memcpy_chk)
- cmp r2, r3
- bls memcpy
-
- // Preserve lr for backtrace.
- push {lr}
- .cfi_def_cfa_offset 4
- .cfi_rel_offset lr, 0
- bl __memcpy_chk_fail
-END(__memcpy_chk)
-
// Prototype: void *memcpy (void *dst, const void *src, size_t count).
ENTRY(memcpy)
pld [r1, #64]
diff --git a/libc/arch-arm/cortex-a53/bionic/memcpy.S b/libc/arch-arm/cortex-a53/bionic/memcpy.S
index 7ad009357..4297cd6c1 100644
--- a/libc/arch-arm/cortex-a53/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a53/bionic/memcpy.S
@@ -63,17 +63,6 @@
// arch. The code generated is exactly the same.
.arch armv7-a
-ENTRY(__memcpy_chk)
- cmp r2, r3
- bls memcpy
-
- // Preserve lr for backtrace.
- push {lr}
- .cfi_def_cfa_offset 4
- .cfi_rel_offset lr, 0
- bl __memcpy_chk_fail
-END(__memcpy_chk)
-
// Prototype: void *memcpy (void *dst, const void *src, size_t count).
ENTRY(memcpy)
pld [r1, #64]
diff --git a/libc/arch-arm/cortex-a7/bionic/memcpy.S b/libc/arch-arm/cortex-a7/bionic/memcpy.S
index 7ad009357..4297cd6c1 100644
--- a/libc/arch-arm/cortex-a7/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a7/bionic/memcpy.S
@@ -63,17 +63,6 @@
// arch. The code generated is exactly the same.
.arch armv7-a
-ENTRY(__memcpy_chk)
- cmp r2, r3
- bls memcpy
-
- // Preserve lr for backtrace.
- push {lr}
- .cfi_def_cfa_offset 4
- .cfi_rel_offset lr, 0
- bl __memcpy_chk_fail
-END(__memcpy_chk)
-
// Prototype: void *memcpy (void *dst, const void *src, size_t count).
ENTRY(memcpy)
pld [r1, #64]
diff --git a/libc/arch-arm/cortex-a9/bionic/memcpy.S b/libc/arch-arm/cortex-a9/bionic/memcpy.S
index 93a8629bc..5a986d175 100644
--- a/libc/arch-arm/cortex-a9/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a9/bionic/memcpy.S
@@ -39,18 +39,6 @@
.thumb
.thumb_func
-ENTRY(__memcpy_chk)
- cmp r2, r3
- bls memcpy
-
- // Preserve lr for backtrace.
- push {lr}
- .cfi_def_cfa_offset 4
- .cfi_rel_offset lr, 0
-
- bl __memcpy_chk_fail
-END(__memcpy_chk)
-
ENTRY(memcpy)
pld [r1, #0]
stmfd sp!, {r0, lr}
diff --git a/libc/arch-arm/denver/bionic/memcpy.S b/libc/arch-arm/denver/bionic/memcpy.S
index 743c74b84..8528f2851 100644
--- a/libc/arch-arm/denver/bionic/memcpy.S
+++ b/libc/arch-arm/denver/bionic/memcpy.S
@@ -65,18 +65,6 @@
// arch. The code generated is exactly the same.
.arch armv7-a
-ENTRY(__memcpy_chk)
- cmp r2, r3
- bls memcpy
-
- // Preserve lr for backtrace.
- push {lr}
- .cfi_def_cfa_offset 4
- .cfi_rel_offset lr, 0
-
- bl __memcpy_chk_fail
-END(__memcpy_chk)
-
ENTRY(memcpy)
pld [r1, #64]
push {r0, lr}
diff --git a/libc/arch-arm/generic/bionic/__memcpy_chk.S b/libc/arch-arm/generic/bionic/__memcpy_chk.S
new file mode 100644
index 000000000..7044e5fa0
--- /dev/null
+++ b/libc/arch-arm/generic/bionic/__memcpy_chk.S
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include <private/bionic_asm.h>
+
+ .syntax unified
+
+ENTRY(__memcpy_chk)
+ cmp r2, r3
+ bls memcpy
+
+ // Preserve lr for backtrace.
+ push {lr}
+ .cfi_def_cfa_offset 4
+ .cfi_rel_offset lr, 0
+
+ bl __memcpy_chk_fail
+END(__memcpy_chk)
diff --git a/libc/arch-arm/generic/bionic/memcpy.S b/libc/arch-arm/generic/bionic/memcpy.S
index a3ebb95f1..d1e4372e1 100644
--- a/libc/arch-arm/generic/bionic/memcpy.S
+++ b/libc/arch-arm/generic/bionic/memcpy.S
@@ -37,18 +37,6 @@
.syntax unified
-ENTRY(__memcpy_chk)
- cmp r2, r3
- bls memcpy
-
- // Preserve lr for backtrace.
- push {lr}
- .cfi_def_cfa_offset 4
- .cfi_rel_offset lr, 0
-
- bl __memcpy_chk_fail
-END(__memcpy_chk)
-
ENTRY(memcpy)
/* The stack must always be 64-bits aligned to be compliant with the
* ARM ABI. Since we have to save R0, we might as well save R4
diff --git a/libc/arch-arm/krait/bionic/memcpy.S b/libc/arch-arm/krait/bionic/memcpy.S
index de6f432af..f22c063ba 100644
--- a/libc/arch-arm/krait/bionic/memcpy.S
+++ b/libc/arch-arm/krait/bionic/memcpy.S
@@ -42,18 +42,6 @@
.thumb
.thumb_func
-ENTRY(__memcpy_chk)
- cmp r2, r3
- bls memcpy
-
- // Preserve lr for backtrace.
- push {lr}
- .cfi_def_cfa_offset 4
- .cfi_rel_offset lr, 0
-
- bl __memcpy_chk_fail
-END(__memcpy_chk)
-
ENTRY(memcpy)
pld [r1, #64]
stmfd sp!, {r0, lr}
diff --git a/libc/arch-arm/kryo/bionic/memcpy.S b/libc/arch-arm/kryo/bionic/memcpy.S
index 7e96f7d93..e9ee2ac2f 100644
--- a/libc/arch-arm/kryo/bionic/memcpy.S
+++ b/libc/arch-arm/kryo/bionic/memcpy.S
@@ -34,18 +34,6 @@
#define PLDSIZE (128) /* L2 cache line size */
.code 32
-ENTRY(__memcpy_chk)
- cmp r2, r3
- bls memcpy
-
- // Preserve lr for backtrace.
- push {lr}
- .cfi_def_cfa_offset 4
- .cfi_rel_offset lr, 0
-
- bl __memcpy_chk_fail
-END(__memcpy_chk)
-
ENTRY(memcpy)
push {r0}
.cfi_def_cfa_offset 4
diff --git a/libc/arch-arm64/denver64/bionic/memcpy.S b/libc/arch-arm64/denver64/bionic/memcpy.S
index 0be2aac83..fc487d3a4 100644
--- a/libc/arch-arm64/denver64/bionic/memcpy.S
+++ b/libc/arch-arm64/denver64/bionic/memcpy.S
@@ -30,19 +30,6 @@
#include <private/bionic_asm.h>
-ENTRY(__memcpy_chk)
- cmp x2, x3
- bls memcpy
-
- // 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 __memcpy_chk_fail
-END(__memcpy_chk)
-
ENTRY(memcpy)
#include "memcpy_base.S"
END(memcpy)
diff --git a/libc/arch-arm64/generic/bionic/__memcpy_chk.S b/libc/arch-arm64/generic/bionic/__memcpy_chk.S
new file mode 100644
index 000000000..42177758b
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/__memcpy_chk.S
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__memcpy_chk)
+ cmp x2, x3
+ bls memcpy
+
+ // 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 __memcpy_chk_fail
+END(__memcpy_chk)
diff --git a/libc/arch-arm64/generic/bionic/memcpy.S b/libc/arch-arm64/generic/bionic/memcpy.S
index 0be2aac83..fc487d3a4 100644
--- a/libc/arch-arm64/generic/bionic/memcpy.S
+++ b/libc/arch-arm64/generic/bionic/memcpy.S
@@ -30,19 +30,6 @@
#include <private/bionic_asm.h>
-ENTRY(__memcpy_chk)
- cmp x2, x3
- bls memcpy
-
- // 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 __memcpy_chk_fail
-END(__memcpy_chk)
-
ENTRY(memcpy)
#include "memcpy_base.S"
END(memcpy)
diff --git a/libc/bionic/__memcpy_chk.cpp b/libc/bionic/__memcpy_chk.cpp
index 7b42d995c..94639544d 100644
--- a/libc/bionic/__memcpy_chk.cpp
+++ b/libc/bionic/__memcpy_chk.cpp
@@ -26,8 +26,6 @@
* SUCH DAMAGE.
*/
-#undef _FORTIFY_SOURCE
-
#include <string.h>
#include "private/bionic_fortify.h"
diff --git a/libc/bionic/__strcpy_chk.cpp b/libc/bionic/__strcpy_chk.cpp
index 116fff4a9..6fbfb8b0c 100644
--- a/libc/bionic/__strcpy_chk.cpp
+++ b/libc/bionic/__strcpy_chk.cpp
@@ -26,8 +26,6 @@
* SUCH DAMAGE.
*/
-#undef _FORTIFY_SOURCE
-
#include <string.h>
#include "private/bionic_fortify.h"
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index 144e13341..b888f09db 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -55,8 +55,6 @@
* SUCH DAMAGE.
*/
-#undef _FORTIFY_SOURCE
-
#include <poll.h>
#include <stdarg.h>
#include <stddef.h>