diff --git a/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp b/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp
index 380f2e98..dbfe8ce6 100644
--- a/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp
+++ b/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp
@@ -11,6 +11,21 @@
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
 
+
+#ifdef __APPLE__
+#include <Availability.h>
+#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+static size_t strnlen(const char *s, size_t maxlen) {
+  size_t l = 0;
+  while (l < maxlen && *s) {
+    l++;
+    s++;
+  }
+  return l;
+}
+#endif
+#endif
+
 namespace llvm {
 namespace objcopy {
 namespace macho {
diff --git a/tools/llvm-objcopy/MachO/Object.cpp b/tools/llvm-objcopy/MachO/Object.cpp
index d3b4fdc2..3f88377b 100644
--- a/tools/llvm-objcopy/MachO/Object.cpp
+++ b/tools/llvm-objcopy/MachO/Object.cpp
@@ -1,6 +1,20 @@
 #include "Object.h"
 #include "../llvm-objcopy.h"
 
+#ifdef __APPLE__
+#include <Availability.h>
+#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+static size_t strnlen(const char *s, size_t maxlen) {
+  size_t l = 0;
+  while (l < maxlen && *s) {
+    l++;
+    s++;
+  }
+  return l;
+}
+#endif
+#endif
+
 namespace llvm {
 namespace objcopy {
 namespace macho {
