diff --git a/gcc/config/avr/avr.h b/gcc/config/avr/avr.h
index 5eb90b5..f69ed22 100644
--- a/gcc/config/avr/avr.h
+++ b/gcc/config/avr/avr.h
@@ -508,9 +508,11 @@ typedef struct avr_args
 #define ADJUST_INSN_LENGTH(INSN, LENGTH)                \
     (LENGTH = avr_adjust_insn_length (INSN, LENGTH))
 
+extern const char *avr_mmcu_to_devicespecs (int, const char**);
 extern const char *avr_devicespecs_file (int, const char**);
 
 #define EXTRA_SPEC_FUNCTIONS                                   \
+  { "mmcu-to-device-specs", avr_mmcu_to_devicespecs }, \
   { "device-specs-file", avr_devicespecs_file },
 
 /* Driver self specs has lmited functionality w.r.t. '%s' for dynamic specs.
@@ -519,7 +521,7 @@ extern const char *avr_devicespecs_file (int, const char**);
 
 #undef  DRIVER_SELF_SPECS
 #define DRIVER_SELF_SPECS                       \
-  " %:device-specs-file(device-specs%s %{mmcu=*:%*})"
+  " %:mmcu-to-device-specs(device-specs%s %{mmcu=*:%*})"
 
 /* No libstdc++ for now.  Empty string doesn't work.  */
 #define LIBSTDCXX "gcc"
diff --git a/gcc/config/avr/driver-avr.c b/gcc/config/avr/driver-avr.c
index 83ca373..1d75c01 100644
--- a/gcc/config/avr/driver-avr.c
+++ b/gcc/config/avr/driver-avr.c
@@ -32,12 +32,42 @@ static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
 static const char specfiles_doc_url[] =
   "http://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html";
 
+/* Implement spec function 'device-specs-file'.
 
-static const char*
-avr_diagnose_devicespecs_error (const char *mcu, const char *filename)
+   Compose -specs=<spec file name>. Issue error if the spec file is not
+   accessible.
+*/
+const char*
+avr_devicespecs_file (int argc, const char **argv)
 {
-  error ("cannot access device-specs for %qs expected at %qs",
-         mcu, filename);
+  const char *specfile_name = NULL;
+  const char *mcu = NULL;
+
+  switch (argc)
+    {
+    case 2:
+      specfile_name = argv[0];
+      mcu = argv[1];
+      break;
+
+    default:
+      fatal_error (input_location,
+                   "bad usage of spec function %qs", "device-specs-file");
+      return "";
+    }
+
+  if (!access (specfile_name, R_OK))
+    {
+#ifdef DEBUG_SPECS
+  if (verbose_flag)
+    fnotice (stderr, "'%s': mmcu='%s'\n'%s': specfile='%s'\n\n",
+             __FUNCTION__, mcu, __FUNCTION__, specfile_name);
+#endif
+      return concat ("-specs=", specfile_name, NULL);
+    }
+
+  error ("cannot access device-specs for %qs expected at GCC-SEARCH-DIRS/device-specs.",
+         mcu);
 
   // Inform about natively supported devices and cores.
 
@@ -49,21 +79,21 @@ avr_diagnose_devicespecs_error (const char *mcu, const char *filename)
   inform (input_location, "you can provide your own specs files, "
           "see <%s> for details", specfiles_doc_url);
 
-  return X_NODEVLIB;
+  return "";
 }
 
 
-/* Implement spec function `device-specs-file´.
+/* Implement spec function `mmcu-to-device-specs'.
 
-   Compose -specs=<specs-file-name>%s.  If everything went well then argv[0]
-   is the inflated (absolute) specs directory and argv[1] is a device or
-   core name as supplied by -mmcu=*.  When building GCC the path might
-   be relative.  */
+   Validate mcu name given with -mmcu option. Use spec function
+   device-specs-file to get -specs=<specs-file-name>. If everything went
+   well then argv[0] is the inflated (absolute) first specs directory and
+   argv[1] is a device or core name as supplied by -mmcu=*.  When building
+   GCC the path might be relative.  */
 
 const char*
-avr_devicespecs_file (int argc, const char **argv)
+avr_mmcu_to_devicespecs (int argc, const char **argv)
 {
-  char *specfile_name;
   const char *mmcu = NULL;
 
 #ifdef DEBUG_SPECS
@@ -76,7 +106,7 @@ avr_devicespecs_file (int argc, const char **argv)
     {
     case 0:
       fatal_error (input_location,
-                   "bad usage of spec function %qs", "device-specs-file");
+                   "bad usage of spec function %qs", "mmcu-to-device-specs");
       return X_NODEVLIB;
 
     case 1:
@@ -111,12 +141,10 @@ avr_devicespecs_file (int argc, const char **argv)
       break;
     }
 
-  specfile_name = concat (argv[0], dir_separator_str, "specs-", mmcu, NULL);
-
 #ifdef DEBUG_SPECS
   if (verbose_flag)
-    fnotice (stderr, "'%s': mmcu='%s'\n'%s': specfile='%s'\n\n",
-             __FUNCTION__, mmcu, __FUNCTION__, specfile_name);
+    fnotice (stderr, "'%s': mmcu='%s'\n\n",
+             __FUNCTION__, mmcu);
 #endif
 
   // Filter out silly -mmcu= arguments like "foo bar".
@@ -131,26 +159,14 @@ avr_devicespecs_file (int argc, const char **argv)
         return X_NODEVLIB;
       }
 
-  if (/* When building / configuring the compiler we might get a relative path
-         as supplied by "-B.".  Assume that the specs file exists and MCU is
-         a core, not a proper device then, i.e. we have "-mmcu=avr*".  */
-      (0 == strncmp (mmcu, "avr", strlen ("avr"))
-       && specfile_name[0] == '.')
-      /* vanilla */
-      || (IS_ABSOLUTE_PATH (specfile_name)
-          && !access (specfile_name, R_OK)))
-    {
-      return concat ("-specs=device-specs", dir_separator_str, "specs-", mmcu,
-                     // Use '%s' instead of the expanded specfile_name.  This
-                     // is the easiest way to handle pathes containing spaces.
-                     "%s",
+  /* Use spec function 'device-specs-file' to handle device-specs file.
+  */
+  return concat ("%:device-specs-file(device-specs", dir_separator_str, "specs-",
+                 mmcu, "%s ", mmcu, ")",
 #if defined (WITH_AVRLIBC)
-                     " %{mmcu=avr*:" X_NODEVLIB "} %{!mmcu=*:" X_NODEVLIB "}",
+                 " %{mmcu=avr*:" X_NODEVLIB "} %{!mmcu=*:" X_NODEVLIB "}",
 #else
-                     " " X_NODEVLIB,
+                 " " X_NODEVLIB,
 #endif
-                     NULL);
-    }
-
-  return avr_diagnose_devicespecs_error (mmcu, specfile_name);
+                 NULL);
 }
