Index: linkers/rld-path.cpp
===================================================================
--- linkers/rld-path.cpp	(revision 3f5e31f86df56008fe3f45e56116a44df24f2c48)
+++ linkers/rld-path.cpp	(revision 32cd4fcc17bbd969410f5f8d165cb7793cce972c)
@@ -20,4 +20,5 @@
 
 #include <sys/stat.h>
+#include <unistd.h>
 
 #include <rld.h>
@@ -84,5 +85,6 @@
     }
 
-    void path_join (const std::string& base, const paths& parts, std::string& joined)
+    void
+    path_join (const std::string& base, const paths& parts, std::string& joined)
     {
       joined = base;
@@ -129,4 +131,28 @@
     }
 
+    void
+    unlink (const std::string& path, bool not_present_error)
+    {
+      struct stat sb;
+      if (::stat (path.c_str (), &sb) >= 0)
+      {
+        if (!S_ISREG (sb.st_mode))
+            throw rld::error ("Not a regular file", "unlinking: " + path);
+
+        int r;
+#if _WIN32
+        r = ::remove(path.c_str ());
+#else
+        r = ::unlink (path.c_str ());
+#endif
+        if (r < 0)
+          throw rld::error (::strerror (errno), "unlinking: " + path);
+      }
+      else
+      {
+        if (not_present_error)
+          throw rld::error ("Not found", "unlinking: " + path);
+      }
+    }
   }
 }
Index: linkers/rld-path.h
===================================================================
--- linkers/rld-path.h	(revision 3f5e31f86df56008fe3f45e56116a44df24f2c48)
+++ linkers/rld-path.h	(revision 32cd4fcc17bbd969410f5f8d165cb7793cce972c)
@@ -129,4 +129,11 @@
                     paths&             search_paths);
 
+    /**
+     * Unlink the file.
+     *
+     * @param path The path of the file to unlink.
+     */
+    void unlink (const std::string& path, bool not_present_error = false);
+
   }
 }
Index: linkers/rld-process.cpp
===================================================================
--- linkers/rld-process.cpp	(revision 3f5e31f86df56008fe3f45e56116a44df24f2c48)
+++ linkers/rld-process.cpp	(revision 32cd4fcc17bbd969410f5f8d165cb7793cce972c)
@@ -61,5 +61,5 @@
   {
     /**
-     * Keep the temporary files if true. Used to help debug a system.
+     * Global keep of temporary files if true. Used to help debug a system.
      */
     bool keep_temporary_files = false;
@@ -80,5 +80,5 @@
 
     const std::string
-    temporary_files::get (const std::string& suffix)
+    temporary_files::get (const std::string& suffix, bool keep)
     {
       char* temp = ::make_temp_file (suffix.c_str ());
@@ -87,36 +87,17 @@
         throw rld::error ("bad temp name", "temp-file");
 
-      std::string name = temp;
-
-      name = rld::find_replace (name,
-                                RLD_PATH_SEPARATOR_STR RLD_PATH_SEPARATOR_STR,
-                                RLD_PATH_SEPARATOR_STR);
-
-      tempfiles.push_back (name);
-
+      const std::string name = rld::find_replace (temp,
+                                                  RLD_PATH_SEPARATOR_STR RLD_PATH_SEPARATOR_STR,
+                                                  RLD_PATH_SEPARATOR_STR);
+      tempfile_ref ref (name, keep);
+      tempfiles.push_back (ref);
       return name;
     }
 
     void
-    temporary_files::unlink (const std::string& name)
-    {
-      if (!keep_temporary_files)
-      {
-        struct stat sb;
-        if ((::stat (name.c_str (), &sb) >= 0) && S_ISREG (sb.st_mode))
-        {
-          int r;
-#if _WIN32
-          r = ::remove(name.c_str ());
-#else
-          r = ::unlink (name.c_str ());
-#endif
-          if (r < 0)
-          {
-            std::cerr << "error: unlinking temp file: " << name << std::endl;
-            ::exit (100);
-          }
-        }
-      }
+    temporary_files::unlink (const tempfile_ref& ref)
+    {
+      if (!keep_temporary_files && !ref.keep)
+        rld::path::unlink (ref.name);
     }
 
@@ -128,7 +109,7 @@
            ++tfi)
       {
-        if (*tfi == name)
-        {
-          unlink (name);
+        if ((*tfi).name == name)
+        {
+          unlink (*tfi);
           tempfiles.erase (tfi);
           break;
@@ -138,5 +119,5 @@
 
     void
-    temporary_files::clean_up ()
+    temporary_files::keep (const std::string& name)
     {
       for (tempfile_container::iterator tfi = tempfiles.begin ();
@@ -144,14 +125,30 @@
            ++tfi)
       {
+        if ((*tfi).name == name)
+        {
+          (*tfi).keep = true;
+          break;
+        }
+      }
+    }
+
+    void
+    temporary_files::clean_up ()
+    {
+      for (tempfile_container::iterator tfi = tempfiles.begin ();
+           tfi != tempfiles.end ();
+           ++tfi)
+      {
         unlink (*tfi);
       }
     }
 
-    tempfile::tempfile (const std::string& suffix)
+    tempfile::tempfile (const std::string& suffix, bool _keep)
       : suffix (suffix),
+        overridden (false),
         fd (-1),
         level (0)
     {
-      _name = temporaries.get (suffix);
+      _name = temporaries.get (suffix, _keep);
     }
 
@@ -165,8 +162,21 @@
     tempfile::open (bool writable)
     {
-      if ((fd < 0) && rld::path::check_file (_name))
-      {
+      if (fd < 0)
+      {
+        bool ok = rld::path::check_file (_name);
+        int  flags = writable ? O_RDWR : O_RDONLY;
+
+        if (overridden)
+        {
+          flags |= O_CREAT | O_TRUNC;
+        }
+        else
+        {
+          if (!ok)
+            throw rld::error ("Not found.", "tempfile open:" + _name);
+        }
+
         level = 0;
-        fd = ::open (_name.c_str (), writable ? O_RDWR : O_RDONLY);
+        fd = ::open (_name.c_str (), flags);
         if (fd < 0)
           throw rld::error (::strerror (errno), "tempfile open:" + _name);
@@ -183,4 +193,20 @@
         level = 0;
       }
+    }
+
+    void
+    tempfile::override (const std::string& name_)
+    {
+      if (fd >= 0)
+        throw rld::error ("Already open", "tempfile override");
+      rld::path::unlink (_name);
+      overridden = true;
+      _name = name_ + suffix;
+    }
+
+    void
+    tempfile::keep ()
+    {
+      temporaries.keep (_name);
     }
 
Index: linkers/rld-process.h
===================================================================
--- linkers/rld-process.h	(revision 3f5e31f86df56008fe3f45e56116a44df24f2c48)
+++ linkers/rld-process.h	(revision 32cd4fcc17bbd969410f5f8d165cb7793cce972c)
@@ -35,4 +35,18 @@
   {
     /**
+     * Temporary file is a name and keep state.
+     */
+    struct tempfile_ref
+    {
+      const std::string name; //< The name of the tempfile.
+      bool              keep; //< If true do not delete this file.
+
+      tempfile_ref (const std::string& name, bool keep = false)
+        : name (name),
+          keep (keep) {
+      }
+    };
+
+    /**
      * Manage temporary files. We keep these so we can delete them when
      * we exit.
@@ -44,5 +58,5 @@
        * Container of temporary file names.
        */
-      typedef std::list < std::string > tempfile_container;
+      typedef std::list < tempfile_ref > tempfile_container;
 
       /**
@@ -59,5 +73,6 @@
        * Get a new temporary file name.
        */
-      const std::string get (const std::string& suffix = ".rldxx");
+      const std::string get (const std::string& suffix = ".rldxx",
+                             bool               keep = false);
 
       /**
@@ -67,4 +82,9 @@
 
       /**
+       * Set the tempfile reference keep state to true.
+       */
+      void keep (const std::string& name);
+
+      /**
        * Remove all temporary files.
        */
@@ -74,7 +94,7 @@
 
       /*
-       * Delete the file.
-       */
-      void unlink (const std::string& name);
+       * Delete the tempfile given the reference if not keeping.
+       */
+      void unlink (const tempfile_ref& ref);
 
       tempfile_container tempfiles; //< The temporary files.
@@ -90,7 +110,7 @@
 
       /**
-       * Get a temporary file name.
-       */
-      tempfile (const std::string& suffix = ".rldxx");
+       * Get a temporary file name given a suffix.
+       */
+      tempfile (const std::string& suffix = ".rldxx", bool keep = false);
 
       /**
@@ -108,4 +128,15 @@
        */
       void close ();
+
+      /**
+       * Override the temp file name automatically assigned with this name. The
+       * suffix is appended.
+       */
+      void override (const std::string& name);
+
+      /**
+       * Set the temp file keep state to true so it is not deleted.
+       */
+      void keep ();
 
       /**
@@ -158,9 +189,10 @@
     private:
 
-      std::string       _name;    //< The name of the file.
-      const std::string suffix;   //< The temp file's suffix.
-      int               fd;       //< The file descriptor
-      char              buf[256]; //< The read buffer.
-      int               level;    //< The level of data in the buffer.
+      std::string       _name;      //< The name of the file.
+      const std::string suffix;     //< The temp file's suffix.
+      bool              overridden; //< The name is overridden; may no exist.
+      int               fd;         //< The file descriptor
+      char              buf[256];   //< The read buffer.
+      int               level;      //< The level of data in the buffer.
     };
 
Index: linkers/rld.h
===================================================================
--- linkers/rld.h	(revision 3f5e31f86df56008fe3f45e56116a44df24f2c48)
+++ linkers/rld.h	(revision 32cd4fcc17bbd969410f5f8d165cb7793cce972c)
@@ -273,5 +273,5 @@
 
   /**
-   * The RTEMS version string.
+   * The RTEMS version string. @todo move to rld-rtems.
    */
   const std::string rtems_version ();
Index: linkers/rtems-tld.cpp
===================================================================
--- linkers/rtems-tld.cpp	(revision 3f5e31f86df56008fe3f45e56116a44df24f2c48)
+++ linkers/rtems-tld.cpp	(revision 32cd4fcc17bbd969410f5f8d165cb7793cce972c)
@@ -728,6 +728,8 @@
       rld::cc::append_flags (rld::cc::ft_cflags, args);
 
+      args.push_back ("-O2");
+      args.push_back ("-g");
       args.push_back ("-c");
-      args.push_back ("-o ");
+      args.push_back ("-o");
       args.push_back (o.name ());
       args.push_back (c.name ());
@@ -783,4 +785,5 @@
   { "rtems-bsp",   required_argument,      NULL,           'B' },
   { "config",      required_argument,      NULL,           'C' },
+  { "wrapper",     required_argument,      NULL,           'W' },
   { NULL,          0,                      NULL,            0 }
 };
@@ -791,15 +794,16 @@
   std::cout << "rtems-trace-ld [options] objects" << std::endl
             << "Options and arguments:" << std::endl
-            << " -h        : help (also --help)" << std::endl
-            << " -V        : print linker version number and exit (also --version)" << std::endl
-            << " -v        : verbose (trace import parts), can supply multiple times" << std::endl
-            << "             to increase verbosity (also --verbose)" << std::endl
-            << " -w        : generate warnings (also --warn)" << std::endl
-            << " -k        : keep temporary files (also --keep)" << std::endl
-            << " -E prefix : the RTEMS tool prefix (also --exec-prefix)" << std::endl
-            << " -c cflags : C compiler flags (also --cflags)" << std::endl
-            << " -r path   : RTEMS path (also --rtems)" << std::endl
-            << " -B bsp    : RTEMS arch/bsp (also --rtems-bsp)" << std::endl
-            << " -C ini    : user configuration INI file (also --config)" << std::endl;
+            << " -h         : help (also --help)" << std::endl
+            << " -V         : print linker version number and exit (also --version)" << std::endl
+            << " -v         : verbose (trace import parts), can supply multiple times" << std::endl
+            << "              to increase verbosity (also --verbose)" << std::endl
+            << " -w         : generate warnings (also --warn)" << std::endl
+            << " -k         : keep temporary files (also --keep)" << std::endl
+            << " -E prefix  : the RTEMS tool prefix (also --exec-prefix)" << std::endl
+            << " -c cflags  : C compiler flags (also --cflags)" << std::endl
+            << " -r path    : RTEMS path (also --rtems)" << std::endl
+            << " -B bsp     : RTEMS arch/bsp (also --rtems-bsp)" << std::endl
+            << " -W wrapper : Wrapper file name without ext (also --wrapper)" << std::endl
+            << " -C ini     : user configuration INI file (also --config)" << std::endl;
   ::exit (exit_code);
 }
@@ -852,9 +856,10 @@
     std::string        configuration;
     std::string        trace = "tracer";
+    std::string        wrapper;
     bool               arch_bsp_load = false;
 
     while (true)
     {
-      int opt = ::getopt_long (argc, argv, "hvwkVE:c:C:r:B:", rld_opts, NULL);
+      int opt = ::getopt_long (argc, argv, "hvwkVE:c:C:r:B:W:", rld_opts, NULL);
       if (opt < 0)
         break;
@@ -903,4 +908,8 @@
           break;
 
+        case 'W':
+          wrapper = optarg;
+          break;
+
         case '?':
           usage (3);
@@ -946,8 +955,17 @@
     try
     {
+      linker.load_config (configuration, trace);
+
       rld::process::tempfile c (".c");
       rld::process::tempfile o (".o");
 
-      linker.load_config (configuration, trace);
+      if (!wrapper.empty ())
+      {
+        c.override (wrapper);
+        c.keep ();
+        o.override (wrapper);
+        o.keep ();
+      }
+
       linker.generate_wrapper (c);
       linker.compile_wrapper (c, o);
