svn commit: r245384 - stable/9/contrib/gcc

Dimitry Andric dim at FreeBSD.org
Sun Jan 13 20:35:09 UTC 2013


Author: dim
Date: Sun Jan 13 20:35:08 2013
New Revision: 245384
URL: http://svnweb.freebsd.org/changeset/base/245384

Log:
  MFC r245272:
  
  Add an ugly hack to libgcc's unwind code, to make it behave properly at
  runtime on amd64, when it is compiled by clang.  Some versions of clang
  don't save and restore all callee registers, if a __builtin_eh_return()
  intrinsic is used in a function.  This is particularly bad on amd64.
  
  Until the problem gets fixed by upstream, use an asm statement to force
  clang to assume the registers in question are clobbered, when invoking
  __builtin_eh_return(), so it will emit code to save and restore them.
  
  This should fix the crashes reported on -current with some C++ programs,
  particularly those that throw exceptions over multiple function
  boundaries.
  
  Reported by:	stefanf

Modified:
  stable/9/contrib/gcc/unwind-dw2.c
Directory Properties:
  stable/9/contrib/gcc/   (props changed)

Modified: stable/9/contrib/gcc/unwind-dw2.c
==============================================================================
--- stable/9/contrib/gcc/unwind-dw2.c	Sun Jan 13 19:39:13 2013	(r245383)
+++ stable/9/contrib/gcc/unwind-dw2.c	Sun Jan 13 20:35:08 2013	(r245384)
@@ -1438,6 +1438,17 @@ uw_init_context_1 (struct _Unwind_Contex
   context->ra = __builtin_extract_return_addr (outer_ra);
 }
 
+#if defined(__clang__) && defined(__amd64__)
+/* Some versions of clang don't save and restore all callee registers, if a
+   __builtin_eh_return() intrinsic is used in a function.  This is particularly
+   bad on amd64.  For now, use the following ugly hack to force it to assume
+   those registers are clobbered, when invoking __builtin_eh_return(), so it
+   will emit code to save and restore them.  */
+#define CLOBBER_REGS_HACK \
+  __asm __volatile(" " : : : "r15", "r14", "r13", "r12", "rbx", "rdx", "rax");
+#else
+#define CLOBBER_REGS_HACK
+#endif /* __clang__ */
 
 /* Install TARGET into CURRENT so that we can return to it.  This is a
    macro because __builtin_eh_return must be invoked in the context of
@@ -1448,6 +1459,7 @@ uw_init_context_1 (struct _Unwind_Contex
     {									 \
       long offset = uw_install_context_1 ((CURRENT), (TARGET));		 \
       void *handler = __builtin_frob_return_addr ((TARGET)->ra);	 \
+      CLOBBER_REGS_HACK							 \
       __builtin_eh_return (offset, handler);				 \
     }									 \
   while (0)


More information about the svn-src-all mailing list