diff --git a/fixincludes/ChangeLog b/fixincludes/ChangeLog
index c50e4d7e1dc99574c47e41d769c12d15fce2e92c..defdb6517e03ea61c2a49df610153b5e46cdc5eb 100644
--- a/fixincludes/ChangeLog
+++ b/fixincludes/ChangeLog
@@ -1,3 +1,8 @@
+2004-10-27  Geoffrey Keating  <geoffk@apple.com>
+
+	* inclhack.def (darwin_gcc4_breakage): New.
+	* fixincl.x: Regenerate.
+
 2004-10-27  Aaron W. LaFramboise  <aaronavay62@aaronwl.com>
 
 	PR bootstrap/17832
diff --git a/fixincludes/fixincl.x b/fixincludes/fixincl.x
index f6d1300aa58e5eabc0d934cc66e6ad3625cef4c6..69098aefa90ffb32ed29295a501b4c27b05169b3 100644
--- a/fixincludes/fixincl.x
+++ b/fixincludes/fixincl.x
@@ -2,11 +2,11 @@
  * 
  * DO NOT EDIT THIS FILE   (fixincl.x)
  * 
- * It has been AutoGen-ed  Saturday September 18, 2004 at 10:59:03 AM MDT
+ * It has been AutoGen-ed  Tuesday October 26, 2004 at 01:55:22 PM PDT
  * From the definitions    inclhack.def
  * and the template file   fixincl
  */
-/* DO NOT CVS-MERGE THIS FILE, EITHER Sat Sep 18 10:59:03 MDT 2004
+/* DO NOT CVS-MERGE THIS FILE, EITHER Tue Oct 26 13:55:22 PDT 2004
  *
  * You must regenerate it.  Use the ./genfixes script.
  *
@@ -15,7 +15,7 @@
  * certain ANSI-incompatible system header files which are fixed to work
  * correctly with ANSI C and placed in a directory that GNU C will search.
  *
- * This file contains 179 fixup descriptions.
+ * This file contains 180 fixup descriptions.
  *
  * See README for more information.
  *
@@ -1640,6 +1640,43 @@ extern \"C\" {\n\
 #endif\n",
     (char*)NULL };
 
+/* * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
+ *  Description of Darwin_Gcc4_Breakage fix
+ */
+tSCC zDarwin_Gcc4_BreakageName[] =
+     "darwin_gcc4_breakage";
+
+/*
+ *  File name selection pattern
+ */
+tSCC zDarwin_Gcc4_BreakageList[] =
+  "|AvailabilityMacros.h|";
+/*
+ *  Machine/OS name selection pattern
+ */
+tSCC* apzDarwin_Gcc4_BreakageMachs[] = {
+        "*-*-darwin*",
+        (const char*)NULL };
+
+/*
+ *  content selection pattern - do fix if pattern found
+ */
+tSCC zDarwin_Gcc4_BreakageSelect0[] =
+       "\\(__GNUC__ >= 3\\) && \\(__GNUC_MINOR__ >= 1\\)";
+
+#define    DARWIN_GCC4_BREAKAGE_TEST_CT  1
+static tTestDesc aDarwin_Gcc4_BreakageTests[] = {
+  { TT_EGREP,    zDarwin_Gcc4_BreakageSelect0, (regex_t*)NULL }, };
+
+/*
+ *  Fix Command Arguments for Darwin_Gcc4_Breakage
+ */
+static const char* apzDarwin_Gcc4_BreakagePatch[] = {
+    "format",
+    "((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))",
+    (char*)NULL };
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
  *
  *  Description of Darwin_Private_Extern fix
@@ -7102,9 +7139,9 @@ static const char* apzX11_SprintfPatch[] = {
  *
  *  List of all fixes
  */
-#define REGEX_COUNT          202
+#define REGEX_COUNT          203
 #define MACH_LIST_SIZE_LIMIT 261
-#define FIX_COUNT            179
+#define FIX_COUNT            180
 
 /*
  *  Enumerate the fixes
@@ -7148,6 +7185,7 @@ typedef enum {
     CTRL_QUOTES_DEF_FIXIDX,
     CTRL_QUOTES_USE_FIXIDX,
     CXX_UNREADY_FIXIDX,
+    DARWIN_GCC4_BREAKAGE_FIXIDX,
     DARWIN_PRIVATE_EXTERN_FIXIDX,
     DEC_INTERN_ASM_FIXIDX,
     DJGPP_WCHAR_H_FIXIDX,
@@ -7482,6 +7520,11 @@ tFixDesc fixDescList[ FIX_COUNT ] = {
      CXX_UNREADY_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
      aCxx_UnreadyTests,   apzCxx_UnreadyPatch, 0 },
 
+  {  zDarwin_Gcc4_BreakageName,    zDarwin_Gcc4_BreakageList,
+     apzDarwin_Gcc4_BreakageMachs,
+     DARWIN_GCC4_BREAKAGE_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
+     aDarwin_Gcc4_BreakageTests,   apzDarwin_Gcc4_BreakagePatch, 0 },
+
   {  zDarwin_Private_ExternName,    zDarwin_Private_ExternList,
      apzDarwin_Private_ExternMachs,
      DARWIN_PRIVATE_EXTERN_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def
index 38021c33957ccd6c95d41bdff8cc5eef2890a9de..00c5ae6aba357ae6c6f394b44d4a64054b3bff50 100644
--- a/fixincludes/inclhack.def
+++ b/fixincludes/inclhack.def
@@ -977,6 +977,23 @@ fix = {
 };
 
 
+/*
+ * AvailabilityMacros.h on Darwin breaks with GCC 4.0, because of
+ * bad __GNUC__ tests.
+ */
+
+fix = {
+  hackname  = darwin_gcc4_breakage;
+  mach      = "*-*-darwin*";
+  files     = AvailabilityMacros.h;
+  select    = "\\(__GNUC__ >= 3\\) && \\(__GNUC_MINOR__ >= 1\\)";
+  c_fix     = format;
+  c_fix_arg = "((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))";
+  test_text = "#if defined(__GNUC__) && (__GNUC__ >= 3) && "
+  	      "(__GNUC_MINOR__ >= 1)\n";
+};
+
+
 /*
  *  __private_extern__ doesn't exist in FSF GCC.  Even if it did,
  *  why would you ever put it in a system header file?
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6f7587ad7bb1bac62ecfb3ae425ef1770a8a2a01..8199b2a3e927828ae5012ed2a55d1eaf9dbde492 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -8,6 +8,16 @@
 
 2004-10-27  Geoffrey Keating  <geoffk@apple.com>
 
+	* config/rs6000/rs6000.c (rs6000_attribute_table): Add
+	SUBTARGET_ATTRIBUTE_TABLE.
+	* config/darwin.h (ASM_WEAKEN_DECL): Handle weak_import.
+	(SUBTARGET_ATTRIBUTE_TABLE): Define.
+	* config/darwin.c (darwin_handle_weak_import_attribute): New.
+	(HAVE_DEAD_STRIP): Delete.
+	(no_dead_strip): Don't test HAVE_DEAD_STRIP.
+	* config/darwin-protos.h (darwin_handle_weak_import_attribute):
+	Prototype.
+
 	* doc/tm.texi (USE_SELECT_SECTION_FOR_FUNCTIONS): Document.
 
 	* config/darwin.h (GTHREAD_USE_WEAK): Define.
diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h
index 9a915a2b16f7a375af36c444e19d31fd67aa0ea6..43ea4cd3363196420e7a5241bbb915f2de2a2df8 100644
--- a/gcc/config/darwin-protos.h
+++ b/gcc/config/darwin-protos.h
@@ -82,6 +82,10 @@ extern void darwin_file_end (void);
 
 extern void darwin_mark_decl_preserved (const char *);
 
+extern tree darwin_handle_weak_import_attribute (tree *node, tree name,
+						 tree args, int flags,
+						 bool * no_add_attrs);
+
 /* Expanded by EXTRA_SECTION_FUNCTIONS into varasm.o.  */
 extern void text_coal_section (void);
 extern void text_unlikely_section (void);
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 0c39fd80c650eef0ab8ad4df30261e597ab50e9f..73581f7346ac8b5b95b47b3fabfc49e69b834cd1 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -1209,13 +1209,30 @@ darwin_unique_section (tree decl ATTRIBUTE_UNUSED, int reloc ATTRIBUTE_UNUSED)
   /* Darwin does not use unique sections.  */
 }
 
-#define HAVE_DEAD_STRIP 0
+/* Handle a "weak_import" attribute; arguments as in
+   struct attribute_spec.handler.  */
+
+tree
+darwin_handle_weak_import_attribute (tree *node, tree name,
+				     tree ARG_UNUSED (args),
+				     int ARG_UNUSED (flags),
+				     bool * no_add_attrs)
+{
+  if (TREE_CODE (*node) != FUNCTION_DECL)
+    {
+      warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
+      *no_add_attrs = true;
+    }
+  else
+    declare_weak (*node);
+
+  return NULL_TREE;
+}
 
 static void
 no_dead_strip (FILE *file, const char *lab)
 {
-  if (HAVE_DEAD_STRIP)
-    fprintf (file, ".no_dead_strip %s\n", lab);
+  fprintf (file, ".no_dead_strip %s\n", lab);
 }
 
 /* Emit a label for an FDE, making it global and/or weak if appropriate. 
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 917f4a945398c521c09d7a9afb8fba4c4f2e0aa9..098caa2d76de960946724c5248e68877828efdbf 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -385,6 +385,9 @@ extern const char *darwin_fix_and_continue_switch;
       targetm.asm_out.globalize_label (FILE, NAME);			\
     if (DECL_EXTERNAL (DECL))						\
       fputs ("\t.weak_reference ", FILE);				\
+    else if (! lookup_attribute ("weak", DECL_ATTRIBUTES (DECL))	\
+	&& lookup_attribute ("weak_import", DECL_ATTRIBUTES (DECL)))	\
+      break;								\
     else if (TREE_PUBLIC (DECL))					\
       fputs ("\t.weak_definition ", FILE);				\
     else								\
@@ -862,6 +865,11 @@ objc_section_init (void)			\
 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
 #define TARGET_ASM_ASSEMBLE_VISIBILITY darwin_assemble_visibility
 
+/* Extra attributes for Darwin.  */
+#define SUBTARGET_ATTRIBUTE_TABLE					     \
+  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ \
+  { "weak_import", 0, 0, true, false, false,				     \
+    darwin_handle_weak_import_attribute }
 
 #undef ASM_GENERATE_INTERNAL_LABEL
 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)	\
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index bfea35379a2714256270e294adb33b41509ed0fd..e2f97d7742cfd8a4c01b64fe883b3235b67b089f 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -16659,6 +16659,9 @@ const struct attribute_spec rs6000_attribute_table[] =
   { "altivec",   1, 1, false, true,  false, rs6000_handle_altivec_attribute },
   { "longcall",  0, 0, false, true,  true,  rs6000_handle_longcall_attribute },
   { "shortcall", 0, 0, false, true,  true,  rs6000_handle_longcall_attribute },
+#ifdef SUBTARGET_ATTRIBUTE_TABLE
+  SUBTARGET_ATTRIBUTE_TABLE,
+#endif
   { NULL,        0, 0, false, false, false, NULL }
 };
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8d984cc8c3438b3367af1239ed5a487c25b58335..647ab555ddae86e057e9eef69e7aea66fdc6e6d4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2004-10-27  Geoffrey Keating  <geoffk@apple.com>
+
+	* gcc.dg/darwin-weakimport-1.c: New.
+
 2004-10-28  Ben Elliston  <bje@au.ibm.com>
 
 	* gcc.dg/tree-ssa/sra-1.c: Pass --param sra-max-structure-size.
diff --git a/gcc/testsuite/gcc.dg/darwin-weakimport-1.c b/gcc/testsuite/gcc.dg/darwin-weakimport-1.c
new file mode 100644
index 0000000000000000000000000000000000000000..c797720e4e2400a418af29951c1170aa482e9c81
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/darwin-weakimport-1.c
@@ -0,0 +1,16 @@
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-require-weak "" } */
+/* { dg-options "-fno-common" } */
+
+/* { dg-final { scan-assembler "weak_reference _a" } } */
+/* { dg-final { scan-assembler-not "weak_\[a-z \t\]*_b" } } */
+
+extern void a (void) __attribute__((weak_import));
+extern void b (void) __attribute__((weak_import));
+
+void b(void)
+{
+  a();
+}
+
+extern int c __attribute__((weak_import)); /* { dg-warning "ignored" } */