tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

EH handling and PR/39986



Hi,

Attached are diffs (minus gcc mknative re-run) to support the PT_GNU_EH_FRAME 
and dl_iterate_phdr method for finding unwind information for exception 
handling. This is described in more detail here:

        http://www.airs.com/blog/archives/166

A question was asked about removing the calls to __{de,}register_frame_info in 
crt{begin,end}. Here's what happens...

        - New binaries will work with new crt{begin,end} and new compiler (gcc)

        - Old binaries will work as they have old crt{begin,end} copied in.

        - Any compiler that requires the calls can define USE_EHREGISTER so that
          crt{begin,end} will have the calls restored. This is only a "problem"
          for i386/amd64 which uses the BSD licensed crt{begin,end}.

        - gcc crt{begin,end} will dtrt after mknative update.

Comments before I commit?

Nick

Index: gnu/dist/gcc4/gcc/crtstuff.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/gcc4/gcc/crtstuff.c,v
retrieving revision 1.1.1.1
diff -u -p -u -r1.1.1.1 crtstuff.c
--- gnu/dist/gcc4/gcc/crtstuff.c        20 Apr 2006 08:44:58 -0000      1.1.1.1
+++ gnu/dist/gcc4/gcc/crtstuff.c        24 Dec 2010 07:52:53 -0000
@@ -88,10 +88,12 @@ call_ ## FUNC (void)                                        
\
 
 #if defined(OBJECT_FORMAT_ELF) && defined(HAVE_LD_EH_FRAME_HDR) \
     && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
-    && defined(__GLIBC__) && __GLIBC__ >= 2
+    && ((defined(__GLIBC__) && __GLIBC__ >= 2) \
+       || defined(__NetBSD__))
 #include <link.h>
 # if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
-     || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
+     || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)) \
+     || defined(__NetBSD__))
 #  define USE_PT_GNU_EH_FRAME
 # endif
 #endif
Index: gnu/dist/gcc4/gcc/gcc.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/gcc4/gcc/gcc.c,v
retrieving revision 1.4
diff -u -p -u -r1.4 gcc.c
--- gnu/dist/gcc4/gcc/gcc.c     11 Jan 2007 06:59:53 -0000      1.4
+++ gnu/dist/gcc4/gcc/gcc.c     24 Dec 2010 07:52:58 -0000
@@ -1620,14 +1620,15 @@ init_gcc_specs (struct obstack *obstack,
                "%{!shared:%{!shared-libgcc:", static_name, " ",
                eh_name, "}%{shared-libgcc:", shared_name, " ",
                static_name, "}}%{shared:",
-/* XXX NH XXX */
-#if defined(LINK_EH_SPEC) || 1
-               "%{shared-libgcc:", shared_name, "} ",
-               static_name, 
+#ifdef LINK_EH_SPEC
+               "%{shared-libgcc:", shared_name,
+               "}%{!shared-libgcc:", static_name,
 #ifdef LIBGCC_PICSUFFIX
                LIBGCC_PICSUFFIX ,
 #endif
+               "}"
 #else
+NO NO NO!!!!
                shared_name,
 #endif
 #endif
Index: gnu/dist/gcc4/gcc/unwind-dw2-fde-phdr.c
===================================================================
RCS file: gnu/dist/gcc4/gcc/unwind-dw2-fde-phdr.c
diff -N gnu/dist/gcc4/gcc/unwind-dw2-fde-phdr.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/dist/gcc4/gcc/unwind-dw2-fde-phdr.c     24 Dec 2010 07:52:58 -0000
@@ -0,0 +1,3 @@
+#define __GLIBC__ 3             /* Fool unwind-dw2-fde-glibc.c.  */
+#define ElfW(type) Elf_##type
+#include "unwind-dw2-fde-glibc.c"
Index: gnu/dist/gcc4/gcc/config/netbsd-elf.h
===================================================================
RCS file: /cvsroot/src/gnu/dist/gcc4/gcc/config/netbsd-elf.h,v
retrieving revision 1.2
diff -u -p -u -r1.2 netbsd-elf.h
--- gnu/dist/gcc4/gcc/config/netbsd-elf.h       12 May 2006 00:42:13 -0000      
1.2
+++ gnu/dist/gcc4/gcc/config/netbsd-elf.h       24 Dec 2010 07:52:58 -0000
@@ -93,3 +93,7 @@ Boston, MA 02110-1301, USA.  */
        %{rdynamic:-export-dynamic} \
        %{!dynamic-linker:-dynamic-linker /usr/libexec/ld.elf_so}} \
      %{static:-static}}"
+
+#if defined(HAVE_LD_EH_FRAME_HDR)
+#define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+#endif
Index: gnu/dist/gcc4/gcc/config/t-netbsd
===================================================================
RCS file: /cvsroot/src/gnu/dist/gcc4/gcc/config/t-netbsd,v
retrieving revision 1.1.1.1
diff -u -p -u -r1.1.1.1 t-netbsd
--- gnu/dist/gcc4/gcc/config/t-netbsd   20 Apr 2006 09:39:54 -0000      1.1.1.1
+++ gnu/dist/gcc4/gcc/config/t-netbsd   24 Dec 2010 07:52:58 -0000
@@ -1,2 +1,7 @@
 # Always build crtstuff with PIC.
 CRTSTUFF_T_CFLAGS = -fPIC
+
+# Use unwind-dw2-fde-phdr
+LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/unwind-dw2-fde-phdr.c \
+  $(srcdir)/unwind-sjlj.c $(srcdir)/gthr-gnat.c $(srcdir)/unwind-c.c
+LIB2ADDEHDEP = unwind.inc unwind-dw2-fde.h unwind-dw2-fde.c
Index: lib/csu/Makefile
===================================================================
RCS file: /cvsroot/src/lib/csu/Makefile,v
retrieving revision 1.28
diff -u -p -u -r1.28 Makefile
--- lib/csu/Makefile    28 Nov 2010 18:40:56 -0000      1.28
+++ lib/csu/Makefile    24 Dec 2010 07:53:48 -0000
@@ -6,6 +6,10 @@ CSU_MACHINE_ARCH?=     ${MACHINE_ARCH}
 
 .if ${USE_COMPILERCRTSTUFF} != "yes"
 
+.if ${USE_EHREGISTER} == "yes"
+CPPFLAGS+=     -DCSU_EHFRAMEREGISTER
+.endif
+
 ARCHDIR:=      ${.PARSEDIR}/arch/${CSU_MACHINE_ARCH}
 .PATH: ${ARCHDIR}
 .  include "${ARCHDIR}/Makefile.inc"
Index: lib/csu/arch/i386/crtbegin.S
===================================================================
RCS file: /cvsroot/src/lib/csu/arch/i386/crtbegin.S,v
retrieving revision 1.1
diff -u -p -u -r1.1 crtbegin.S
--- lib/csu/arch/i386/crtbegin.S        7 Aug 2010 18:01:33 -0000       1.1
+++ lib/csu/arch/i386/crtbegin.S        24 Dec 2010 07:53:48 -0000
@@ -73,9 +73,12 @@ __finished:
 
        .text
        .weak   __cxa_finalize
+       .weak   _Jv_RegisterClasses
+
+#ifdef CSU_EHFRAMEREGSITER
        .weak   __deregister_frame_info
        .weak   __register_frame_info
-       .weak   _Jv_RegisterClasses
+#endif
 
 __get_thunk:
        movl    (%esp), %ebx
@@ -111,12 +114,15 @@ __do_global_dtors_aux:
        jmp     2b
 3:
 
+#ifdef CSU_EHFRAMEREGSITER
+
        cmpl    $0, __deregister_frame_info@GOT(%ebx)
        je      4f
        leal    __EH_FRAME_LIST__@GOTOFF(%ebx), %eax
        movl    %eax, (%esp)
        call    __deregister_frame_info@PLT
 4:
+#endif
        addl    $8, %esp
        popl    %edi
        popl    %ebx
@@ -134,6 +140,8 @@ __do_global_ctors_aux:
        jne     4f
        movb    $1, __initialized@GOTOFF(%ebx)
 
+#ifdef CSU_EHFRAMEREGSITER
+
        cmpl    $0, __register_frame_info@GOT(%ebx)
        je      1f
        leal    __dwarf_eh_object@GOTOFF(%ebx), %edi
@@ -143,6 +151,7 @@ __do_global_ctors_aux:
        call    __register_frame_info@PLT
 
 1:
+#endif
        cmpl    $0, _Jv_RegisterClasses@GOT(%ebx)
        je      2f
        leal    __JCR_LIST__@GOTOFF(%ebx), %edi
Index: lib/csu/arch/x86_64/crtbegin.S
===================================================================
RCS file: /cvsroot/src/lib/csu/arch/x86_64/crtbegin.S,v
retrieving revision 1.2
diff -u -p -u -r1.2 crtbegin.S
--- lib/csu/arch/x86_64/crtbegin.S      30 Nov 2010 18:37:59 -0000      1.2
+++ lib/csu/arch/x86_64/crtbegin.S      24 Dec 2010 07:53:48 -0000
@@ -73,9 +73,12 @@ __finished:
 
        .text
        .weak   __cxa_finalize
+       .weak   _Jv_RegisterClasses
+
+#ifdef CSU_EHFRAMEREGISTER
        .weak   __deregister_frame_info
        .weak   __register_frame_info
-       .weak   _Jv_RegisterClasses
+#endif
 
 __do_global_dtors_aux:
        cmpb    $0, __finished(%rip)
@@ -104,11 +107,13 @@ __do_global_dtors_aux:
        jmp     3b      
 4:
 
+#ifdef CSU_EHFRAMEREGISTER
        cmpq    $0, __deregister_frame_info@GOTPCREL(%rip)
        je      5f
        leaq    __EH_FRAME_LIST__(%rip), %rdi
        call    __deregister_frame_info@PLT
 5:
+#endif
        popq    %rbx
        ret
 
@@ -121,6 +126,7 @@ __do_global_ctors_aux:
        pushq   %rbx
        movb    $1, __initialized(%rip)
 
+#ifdef CSU_EHFRAMEREGISTER
        cmpq    $0, __register_frame_info@GOTPCREL(%rip)
        je      2f
        leaq    __dwarf_eh_object(%rip), %rsi
@@ -128,6 +134,7 @@ __do_global_ctors_aux:
        call    __register_frame_info@PLT
 
 2:
+#endif
        cmpq    $0, _Jv_RegisterClasses@GOTPCREL(%rip)
        je      3f
        leaq    __JCR_LIST__(%rip), %rdi
Index: share/mk/bsd.own.mk
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.own.mk,v
retrieving revision 1.646
diff -u -p -u -r1.646 bsd.own.mk
--- share/mk/bsd.own.mk 13 Dec 2010 17:22:26 -0000      1.646
+++ share/mk/bsd.own.mk 24 Dec 2010 07:54:02 -0000
@@ -57,6 +57,7 @@ HAVE_GCC=     4
 USE_COMPILERCRTSTUFF?= no
 .endif
 USE_COMPILERCRTSTUFF?= yes
+USE_EHREGISTER?=       no
 
 # default to GDB6
 HAVE_GDB?=     6


Home | Main Index | Thread Index | Old Index