Index: linkers/rtems-ld.cpp
===================================================================
--- linkers/rtems-ld.cpp	(revision b7c4753de0c17201be0ca047e2a7e320616132cb)
+++ linkers/rtems-ld.cpp	(revision 82c8788b111a4392a56414f8f421ba26ded5d0fd)
@@ -505,7 +505,7 @@
         else if (output_type == "rap")
         {
-          rld::outputter::application (output, entry, exit,
-                                       dependents, cache, symbols,
-                                       one_file);
+          rld::outputter::rap_application (output, entry, exit,
+                                           dependents, cache, symbols,
+                                           one_file);
           if (!outra.empty ())
           {
Index: linkers/rtems-ra.cpp
===================================================================
--- linkers/rtems-ra.cpp	(revision b7c4753de0c17201be0ca047e2a7e320616132cb)
+++ linkers/rtems-ra.cpp	(revision 82c8788b111a4392a56414f8f421ba26ded5d0fd)
@@ -376,7 +376,7 @@
             /* Todo: include absolute name for rap_name */
 
-            rld::outputter::application (rap_name, entry, exit,
-                                         dependents, *cache, symbols,
-                                         true);
+            rld::outputter::rap_application (rap_name, entry, exit,
+                                             dependents, *cache, symbols,
+                                             true);
           }
 
Index: rtemstoolkit/rld-files.cpp
===================================================================
--- rtemstoolkit/rld-files.cpp	(revision b7c4753de0c17201be0ca047e2a7e320616132cb)
+++ rtemstoolkit/rld-files.cpp	(revision 82c8788b111a4392a56414f8f421ba26ded5d0fd)
@@ -230,5 +230,6 @@
         fd_ (-1),
         symbol_refs (0),
-        writable (false)
+        writable (false),
+        remove (false)
     {
     }
@@ -239,5 +240,6 @@
         fd_ (-1),
         symbol_refs (0),
-        writable (false)
+        writable (false),
+        remove (false)
     {
     }
@@ -247,5 +249,6 @@
         fd_ (-1),
         symbol_refs (0),
-        writable (false)
+        writable (false),
+        remove (false)
     {
     }
@@ -256,5 +259,14 @@
 	std::cerr << "rtl:file:image: references when destructing";
       if (fd_ >= 0)
+      {
         ::close (fd_);
+        if (writable && remove)
+        {
+          if (rld::verbose () >= RLD_VERBOSE_INFO)
+            std::cout << "image::close: removing " << name ().full ()
+                        << std::endl;
+          ::unlink (name_.path ().c_str ());
+        }
+      }
     }
 
@@ -314,4 +326,12 @@
           ::close (fd_);
           fd_ = -1;
+          if (writable && remove)
+          {
+            if (rld::verbose () >= RLD_VERBOSE_INFO)
+              std::cout << "image::close: removing " << name ().full ()
+                        << std::endl;
+            ::unlink (name_.path ().c_str ());
+            remove = false;
+          }
         }
       }
Index: rtemstoolkit/rld-files.h
===================================================================
--- rtemstoolkit/rld-files.h	(revision b7c4753de0c17201be0ca047e2a7e320616132cb)
+++ rtemstoolkit/rld-files.h	(revision 82c8788b111a4392a56414f8f421ba26ded5d0fd)
@@ -389,4 +389,12 @@
       }
 
+      /**
+       * Remove a writable file on close. This flag can be set when an error
+       * happens while writing a file.
+       */
+      void remove_on_close () {
+        remove = true;
+      }
+
     private:
 
@@ -397,4 +405,5 @@
       int       symbol_refs; //< The number of symbols references made.
       bool      writable;    //< The image is writable.
+      bool      remove;      //< Remove the image on close if writable.
     };
 
Index: rtemstoolkit/rld-outputter.cpp
===================================================================
--- rtemstoolkit/rld-outputter.cpp	(revision b7c4753de0c17201be0ca047e2a7e320616132cb)
+++ rtemstoolkit/rld-outputter.cpp	(revision 82c8788b111a4392a56414f8f421ba26ded5d0fd)
@@ -333,4 +333,5 @@
       {
         out.close ();
+        ::unlink (name.c_str ());
         throw;
       }
@@ -411,4 +412,5 @@
       {
         delete [] buffer;
+        app.remove_on_close ();
         app.close ();
         throw;
@@ -428,11 +430,11 @@
 
     void
-    application (const std::string&        name,
-                 const std::string&        entry,
-                 const std::string&        exit,
-                 const files::object_list& dependents,
-                 const files::cache&       cache,
-                 const symbols::table&     symbols,
-                 bool                      one_file)
+    rap_application (const std::string&        name,
+                     const std::string&        entry,
+                     const std::string&        exit,
+                     const files::object_list& dependents,
+                     const files::cache&       cache,
+                     const symbols::table&     symbols,
+                     bool                      one_file)
     {
       if (rld::verbose () >= RLD_VERBOSE_INFO)
@@ -459,4 +461,5 @@
       catch (...)
       {
+        app.remove_on_close ();
         app.close ();
         throw;
Index: rtemstoolkit/rld-outputter.h
===================================================================
--- rtemstoolkit/rld-outputter.h	(revision b7c4753de0c17201be0ca047e2a7e320616132cb)
+++ rtemstoolkit/rld-outputter.h	(revision 82c8788b111a4392a56414f8f421ba26ded5d0fd)
@@ -112,11 +112,11 @@
      * @param symbols The symbol table used to resolve the application.
      */
-    void application (const std::string&        name,
-                      const std::string&        entry,
-                      const std::string&        exit,
-                      const files::object_list& dependents,
-                      const files::cache&       cache,
-                      const symbols::table&     symbols,
-                      bool                      one_file);
+    void rap_application (const std::string&        name,
+                          const std::string&        entry,
+                          const std::string&        exit,
+                          const files::object_list& dependents,
+                          const files::cache&       cache,
+                          const symbols::table&     symbols,
+                          bool                      one_file);
 
   }
