This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Avoid unnecessary references to the EH personality routine


I noticed that this program:

  struct S {
    virtual void f();
  };
  void S::f() {}
  int main () {}

pulled in all of the EH machinery -- even when compiled with
-fno-exceptions.  The reason is that this program (when not compiled
with -fno-rtti) contains a reference to the __class_type_info vtable,
which pulls in all of the virtual functions for __class_type_info,
which pull in the EH routines.  But, there's no reason those virtual
functions should pull in the EH routines; none of them throw or catch
exceptions.

In fact, the compiler recognizes that, and elides the EH tables.  But,
it still referenced the personality routine, thanks to this snippet in
output_function_except_table which emits a reference to the
personality routine before determining whether or not a table is
needed.  

This patch, eliminates the references from __class_type_info to the
personality routine, and, from there, to the rest of the EH machinery.
When compiling for Thumb EABI (with static linking), this change
reduces the size of the above program from about 40K to about 16K.
Obviously, -fno-rtti will make the program even smaller, and, if
you're really concerned about size, you may want that -- but it's
still a good idea to make the default compilation mode generate
smaller binaries, where doing so has no harm.

I suspect that others parts of libsupc++ could additionally benefit
from the use of "throw ()" specifications, as there may still be
routines which look like they can throw exceptions to the compiler,
but cannot in actual practice.

Tested on ARM EABI and x86_64-unknown-linux-gnu, committed to mainline.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2007-03-19  Mark Mitchell  <mark@codesourcery.com>

	* except.c (output_function_exception_table): Do not reference the
	EH personality routine for functions that do not require an
	exception table.

Index: except.c
===================================================================
--- except.c	(revision 123041)
+++ except.c	(working copy)
@@ -3633,13 +3633,13 @@ output_function_exception_table (const c
   int have_tt_data;
   int tt_format_size = 0;
 
-  if (eh_personality_libfunc)
-    assemble_external_libcall (eh_personality_libfunc);
-
   /* Not all functions need anything.  */
   if (! cfun->uses_eh_lsda)
     return;
 
+  if (eh_personality_libfunc)
+    assemble_external_libcall (eh_personality_libfunc);
+
 #ifdef TARGET_UNWIND_INFO
   /* TODO: Move this into target file.  */
   fputs ("\t.personality\t", asm_out_file);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]