Index: linkers/rtems-exeinfo.cpp
===================================================================
--- linkers/rtems-exeinfo.cpp	(revision b73f905e3aa0e9ac16eb19f956ff3297d92fe48f)
+++ linkers/rtems-exeinfo.cpp	(revision 1e21ea76b743f29b7c17952f5f19d15b53dc5afd)
@@ -44,4 +44,5 @@
 #include <rld.h>
 #include <rld-buffer.h>
+#include <rld-dwarf.h>
 #include <rld-files.h>
 #include <rld-process.h>
@@ -132,4 +133,5 @@
     {
       files::object    exe;         //< The object file that is the executable.
+      dwarf::file      debug;       //< The executable's DWARF details.
       symbols::table   symbols;     //< The synbols for a map.
       symbols::addrtab addresses;   //< The symbols keyed by address.
@@ -148,4 +150,9 @@
        */
       ~image ();
+
+      /*
+       * Check the compiler and flags match.
+       */
+      void output_compilation_unit (bool objects);
 
       /*
@@ -261,4 +268,5 @@
       exe.open ();
       exe.begin ();
+      debug.begin (exe.elf ());
 
       if (!exe.valid ())
@@ -285,4 +293,5 @@
        */
       exe.load_symbols (symbols, true);
+      debug.load_debug ();
       symbols.globals (addresses);
       symbols.weaks (addresses);
@@ -293,5 +302,184 @@
     image::~image ()
     {
-      exe.close ();
+    }
+
+    void
+    image::output_compilation_unit (bool objects)
+    {
+      dwarf::compilation_units& cus = debug.get_cus ();
+
+      std::cout << "Compilation: " << std::endl;
+
+      rld::strings flag_exceptions = { "-O",
+                                       "-g",
+                                       "-mtune=",
+                                       "-fno-builtin",
+                                       "-fno-inline",
+                                       "-fexceptions",
+                                       "-fnon-call-exceptions",
+                                       "-fvisibility=",
+                                       "-fno-stack-protector",
+                                       "-fbuilding-libgcc",
+                                       "-fno-implicit-templates",
+                                       "-ffunction-sections",
+                                       "-fdata-sections",
+                                       "-frandom-seed=",
+                                       "-fno-common",
+                                       "-fno-keep-inline-functions" };
+
+      dwarf::producer_sources producers;
+
+      debug.get_producer_sources (producers);
+
+      /*
+       * Find which flags are common to the building of all source. We are only
+       * interested in files that have any flags. This filters out things like
+       * the assembler which does not have flags.
+       */
+
+      rld::strings all_flags;
+
+      size_t source_max = 0;
+
+      for (auto& p : producers)
+      {
+        dwarf::source_flags_compare compare;
+        std::sort (p.sources.begin (), p.sources.end (), compare);
+
+        for (auto& s : p.sources)
+        {
+          size_t len = rld::path::basename (s.source).length ();
+          if (len > source_max)
+            source_max = len;
+
+          if (!s.flags.empty ())
+          {
+            for (auto& f : s.flags)
+            {
+              bool add = true;
+              for (auto& ef : flag_exceptions)
+              {
+                if (rld::starts_with (f, ef))
+                {
+                  add = false;
+                  break;
+                }
+              }
+              if (add)
+              {
+                for (auto& af : all_flags)
+                {
+                  if (f == af)
+                  {
+                    add = false;
+                    break;
+                  }
+                }
+                if (add)
+                  all_flags.push_back (f);
+              }
+            }
+          }
+        }
+      }
+
+      rld::strings common_flags;
+
+      for (auto& flag : all_flags)
+      {
+        bool found_in_all = true;
+        for (auto& p : producers)
+        {
+          for (auto& s : p.sources)
+          {
+            if (!s.flags.empty ())
+            {
+              bool flag_found = false;
+              for (auto& f : s.flags)
+              {
+                if (flag == f)
+                {
+                  flag_found = true;
+                  break;
+                }
+              }
+              if (!flag_found)
+              {
+                found_in_all = false;
+                break;
+              }
+            }
+            if (!found_in_all)
+              break;
+          }
+        }
+        if (found_in_all)
+          common_flags.push_back (flag);
+      }
+
+      std::cout << " Producers: " << producers.size () << std::endl;
+
+      for (auto& p : producers)
+      {
+        std::cout << "  | " << p.producer
+                  << ": " << p.sources.size () << " objects" << std::endl;
+      }
+
+      std::cout << " Common flags: " << common_flags.size () << std::endl
+                << "  |";
+
+      for (auto& f : common_flags)
+        std::cout << ' ' << f;
+      std::cout << std::endl;
+
+      if (objects)
+      {
+        std::cout << " Object files: " << cus.size () << std::endl;
+
+        rld::strings filter_flags = common_flags;
+        filter_flags.insert (filter_flags.end (),
+                             flag_exceptions.begin (),
+                             flag_exceptions.end());
+
+        for (auto& p : producers)
+        {
+          std::cout << ' ' << p.producer
+                    << ": " << p.sources.size () << " objects" << std::endl;
+          for (auto& s : p.sources)
+          {
+            std::cout << "   | "
+                      << std::setw (source_max + 1) << std::left
+                      << rld::path::basename (s.source);
+            if (!s.flags.empty ())
+            {
+              bool first = true;
+              for (auto& f : s.flags)
+              {
+                bool present = false;
+                for (auto& ff : filter_flags)
+                {
+                  if (rld::starts_with(f, ff))
+                  {
+                    present = true;
+                    break;
+                  }
+                }
+                if (!present)
+                {
+                  if (first)
+                  {
+                    std::cout << ':';
+                    first = false;
+                  }
+                  std::cout << ' ' << f;
+                }
+              }
+            }
+            std::cout << std::endl;
+          }
+        }
+      }
+
+      std::cout << std::endl;
     }
 
@@ -443,5 +631,6 @@
             << " -S        : show all section (also --sections)" << std::endl
             << " -I        : show init section tables (also --init)" << std::endl
-            << " -F        : show fini section tables (also --fini)" << std::endl;
+            << " -F        : show fini section tables (also --fini)" << std::endl
+            << " -O        : show object files (also --objects)" << std::endl;
   ::exit (exit_code);
 }
@@ -481,4 +670,11 @@
 }
 
+void
+unhandled_exception (void)
+{
+  std::cerr << "error: exception handling error, please report" << std::endl;
+  exit (1);
+}
+
 int
 main (int argc, char* argv[])
@@ -487,4 +683,6 @@
 
   setup_signals ();
+
+  std::set_terminate(unhandled_exception);
 
   try
@@ -496,4 +694,5 @@
     bool        init = false;
     bool        fini = false;
+    bool        objects = false;
 
     rld::set_cmdline (argc, argv);
@@ -538,4 +737,8 @@
           break;
 
+        case 'O':
+          objects = true;
+          break;
+
         case '?':
           usage (3);
@@ -567,4 +770,5 @@
       init = true;
       fini = true;
+      objects = true;
     }
 
@@ -590,9 +794,11 @@
     rld::exeinfo::image exe (exe_name);
 
-    std::cout << "exe: " << exe.exe.name ().full () << std::endl;
+    std::cout << "exe: " << exe.exe.name ().full () << std::endl
+              << std::endl;
 
     /*
      * Generate the output.
      */
+    exe.output_compilation_unit (objects);
     if (sections)
       exe.output_sections ();
Index: linkers/wscript
===================================================================
--- linkers/wscript	(revision b73f905e3aa0e9ac16eb19f956ff3297d92fe48f)
+++ linkers/wscript	(revision 1e21ea76b743f29b7c17952f5f19d15b53dc5afd)
@@ -71,5 +71,5 @@
     # The list of modules.
     #
-    modules = ['rld', 'elf', 'iberty']
+    modules = ['rld', 'dwarf', 'elf', 'iberty']
 
     #
