  
  #define DARWIN_NOPIE_SPEC \
  "%{no-pie|fno-pie|fno-PIE: \
-@@ -298,6 +305,13 @@ extern GTY(()) int darwin_ms_struct;
+@@ -298,6 +297,31 @@ extern GTY(()) int darwin_ms_struct;
  #define DARWIN_CC1_SPEC							\
    "%<dynamic %<dynamiclib %<force_cpusubtype_ALL "
  
++/* When we are using embedded runpaths DARWIN_AT_RPATH is set. */
 +#if DARWIN_AT_RPATH
-+#define DARWIN_RPATH_LINK \
++# define DARWIN_RPATH_LINK \
 +"%{!r:%{!nostdlib:%{!nodefaultrpaths:%(darwin_rpaths)}}}"
++# define DARWIN_SHARED_LIBGCC "-lgcc_s.1.1"
 +#else
-+#define DARWIN_RPATH_LINK ""
++# define DARWIN_RPATH_LINK ""
++# define DARWIN_SHARED_LIBGCC \
++"%:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \
++ %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) "
++#endif
++
++/* We might elect to add a path even when this compiler does not use embedded
++   run paths, so that we can use libraries from an alternate compiler that is
++   using embedded runpaths.  */
++#if DARWIN_DO_EXTRA_RPATH
++# define DARWIN_EXTRA_RPATH \
++"%{!r:%{!nostdlib:%{!nodefaultrpaths:\
++    %:version-compare(>= 10.5 mmacosx-version-min= -rpath) \
++    %:version-compare(>= 10.5 mmacosx-version-min= " DARWIN_ADD_RPATH ") \
++  }}}"
++#else
++# define DARWIN_EXTRA_RPATH ""
 +#endif
 +
  #define SUBSUBTARGET_OVERRIDE_OPTIONS					\
    do {									\
      darwin_override_options ();						\
-@@ -389,7 +403,8 @@ extern GTY(()) int darwin_ms_struct;
+@@ -389,7 +413,9 @@ extern GTY(()) int darwin_ms_struct;
      DARWIN_NOPIE_SPEC \
      DARWIN_RDYNAMIC \
      DARWIN_NOCOMPACT_UNWIND \
 -    "}}}}}}} %<pie %<no-pie %<rdynamic %<X "
++    DARWIN_EXTRA_RPATH \
 +    DARWIN_RPATH_LINK \
 +    "}}}}}}} %<pie %<no-pie %<rdynamic %<X %<rpath %<nodefaultrpaths "
  
  /* Spec that controls whether the debug linker is run automatically for
     a link step.  This needs to be done if there is a source file on the
-@@ -445,6 +460,7 @@ extern GTY(()) int darwin_ms_struct;
+@@ -445,12 +471,16 @@ extern GTY(()) int darwin_ms_struct;
                       %:replace-outfile(-lobjc libobjc-gnu.a%s); \
                      :%:replace-outfile(-lobjc -lobjc-gnu )}}\
     %{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran libgfortran.a%s)}\

 (define_predicate "aarch64_valid_symref"
   (match_code "const, symbol_ref, label_ref")
 {
diff --git a/gcc/config/aarch64/t-aarch64-darwin b/gcc/config/aarch64/t-aarch64-darwin
new file mode 100644
index 00000000000..a8bfcffad78

 	   (int) osversion_len, osversion);
   return NULL;
 }
@@ -229,7 +222,7 @@ darwin_default_min_version (void)
       const char *checked = validate_macosx_version_min (new_flag);
       if (checked == NULL)
 	{
