[llvm-commits] [llvm-gcc-4.2] r47684 - in /llvm-gcc-4.2/trunk/gcc: config.gcc config/i386/cygming-crtbegin.c config/i386/cygming-crtend.c config/i386/cygming.h config/i386/cygwin.h config/i386/mingw32.h config/i386/t-cygming libgcc2.c

Anton Korobeynikov asl at math.spbu.ru
Wed Feb 27 11:25:16 PST 2008


Author: asl
Date: Wed Feb 27 13:25:16 2008
New Revision: 47684

URL: http://llvm.org/viewvc/llvm-project?rev=47684&view=rev
Log:
Provide necessary bits for Dwarf2 EH on mingw32

Added:
    llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtbegin.c
    llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtend.c
Modified:
    llvm-gcc-4.2/trunk/gcc/config.gcc
    llvm-gcc-4.2/trunk/gcc/config/i386/cygming.h
    llvm-gcc-4.2/trunk/gcc/config/i386/cygwin.h
    llvm-gcc-4.2/trunk/gcc/config/i386/mingw32.h
    llvm-gcc-4.2/trunk/gcc/config/i386/t-cygming
    llvm-gcc-4.2/trunk/gcc/libgcc2.c

Modified: llvm-gcc-4.2/trunk/gcc/config.gcc
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config.gcc?rev=47684&r1=47683&r2=47684&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config.gcc (original)
+++ llvm-gcc-4.2/trunk/gcc/config.gcc Wed Feb 27 13:25:16 2008
@@ -1321,6 +1321,7 @@
 	c_target_objs=cygwin2.o
 	cxx_target_objs="cygwin2.o winnt-cxx.o"
 	extra_gcc_objs=cygwin1.o
+	extra_parts="crtbegin.o crtend.o"
 	if test x$enable_threads = xyes; then
 		thread_file='posix'
 	fi
@@ -1333,6 +1334,7 @@
 	extra_options="${extra_options} i386/cygming.opt"
 	extra_objs="winnt.o winnt-stubs.o"
 	cxx_target_objs=winnt-cxx.o
+	extra_parts="crtbegin.o crtend.o"
 	case ${enable_threads} in
 	  "" | yes | win32)
 	  thread_file='win32'

Added: llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtbegin.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtbegin.c?rev=47684&view=auto

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtbegin.c (added)
+++ llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtbegin.c Wed Feb 27 13:25:16 2008
@@ -0,0 +1,140 @@
+/* crtbegin object for windows32 targets.
+   Copyright (C) 2007  Free Software Foundation, Inc.
+
+   Contributed by Danny Smith <dannysmith at users.sourceforge.net>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file.  (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+/* Target machine header files require this define. */
+#define IN_LIBGCC2
+
+#include "auto-host.h"
+#include "tconfig.h"
+#include "tsystem.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "unwind-dw2-fde.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#ifndef LIBGCC_SONAME
+#define LIBGCC_SONAME "libgcc_s.dll"
+#endif
+
+#ifndef LIBGCJ_SONAME
+#define LIBGCJ_SONAME "libgcj_s.dll"
+#endif
+
+
+/* Make the declarations weak.  This is critical for
+   _Jv_RegisterClasses because it lives in libgcj.a  */
+extern void __register_frame_info (const void *, struct object *)
+				   TARGET_ATTRIBUTE_WEAK;
+extern void *__deregister_frame_info (const void *)
+				      TARGET_ATTRIBUTE_WEAK;
+extern void _Jv_RegisterClasses (const void *) TARGET_ATTRIBUTE_WEAK;
+
+#if defined(HAVE_LD_RO_RW_SECTION_MIXING)
+# define EH_FRAME_SECTION_CONST const
+#else
+# define EH_FRAME_SECTION_CONST
+#endif
+
+/* Stick a label at the beginning of the frame unwind info so we can
+   register/deregister it with the exception handling library code.  */
+#if DWARF2_UNWIND_INFO
+static EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
+  __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4)))
+  = { };
+
+static struct object obj;
+#endif
+
+#if TARGET_USE_JCR_SECTION
+static void *__JCR_LIST__[]
+  __attribute__ ((unused, section(JCR_SECTION_NAME), aligned(4)))
+  = { };
+#endif
+
+/* Pull in references from libgcc.a(unwind-dw2-fde.o) in the
+   startfile. These are referenced by a ctor and dtor in crtend.o.  */
+extern void __gcc_register_frame (void);
+extern void __gcc_deregister_frame (void);
+
+void
+__gcc_register_frame (void)
+{
+#if DWARF2_UNWIND_INFO
+/* Weak undefined symbols won't be pulled in from dlls; hence
+   we first test if the dll is already loaded and, if so,
+   get the symbol's address at run-time.  If the dll is not loaded,
+   fallback to weak linkage to static archive.  */
+
+  void (*register_frame_fn) (const void *, struct object *);
+  HANDLE h = GetModuleHandle (LIBGCC_SONAME);
+  if (h)
+    register_frame_fn = (void (*) (const void *, struct object *))
+			GetProcAddress (h, "__register_frame_info");
+  else 
+    register_frame_fn = __register_frame_info;
+  if (register_frame_fn)
+     register_frame_fn (__EH_FRAME_BEGIN__, &obj);
+#endif
+
+#if TARGET_USE_JCR_SECTION 
+  if (__JCR_LIST__[0])
+    {
+      void (*register_class_fn) (const void *);
+      HANDLE h = GetModuleHandle (LIBGCJ_SONAME);
+      if (h)
+	register_class_fn = (void (*) (const void *))
+			     GetProcAddress (h, "_Jv_RegisterClasses");
+      else
+	register_class_fn = _Jv_RegisterClasses;
+
+      if (register_class_fn)
+	register_class_fn (__JCR_LIST__);
+    }
+#endif
+}
+
+void
+__gcc_deregister_frame (void)
+{
+#if DWARF2_UNWIND_INFO
+  void *  (*deregister_frame_fn) (const void *);
+  HANDLE h = GetModuleHandle (LIBGCC_SONAME);
+  if (h)
+    deregister_frame_fn = (void* (*) (const void *))
+			  GetProcAddress (h, "__deregister_frame_info");
+  else 
+    deregister_frame_fn = __deregister_frame_info;
+  if (deregister_frame_fn)
+     deregister_frame_fn (__EH_FRAME_BEGIN__);
+#endif
+}

Added: llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtend.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtend.c?rev=47684&view=auto

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtend.c (added)
+++ llvm-gcc-4.2/trunk/gcc/config/i386/cygming-crtend.c Wed Feb 27 13:25:16 2008
@@ -0,0 +1,92 @@
+/* crtend object for windows32 targets.
+   Copyright (C) 2007  Free Software Foundation, Inc.
+
+   Contributed by Danny Smith <dannysmith at users.sourceforge.net>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file.  (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+/* Target machine header files require this define. */
+#define IN_LIBGCC2
+
+/* auto-host.h is needed by cygming.h for HAVE_GAS_WEAK and here
+   for HAVE_LD_RO_RW_SECTION_MIXING.  */  
+#include "auto-host.h"
+#include "tconfig.h"
+#include "tsystem.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "unwind-dw2-fde.h"
+
+#if defined(HAVE_LD_RO_RW_SECTION_MIXING)
+# define EH_FRAME_SECTION_CONST const
+#else
+# define EH_FRAME_SECTION_CONST
+#endif
+
+#if DWARF2_UNWIND_INFO
+/* Terminate the frame unwind info section with a 0 as a sentinel;
+   this would be the 'length' field in a real FDE.  */
+
+static EH_FRAME_SECTION_CONST int __FRAME_END__[]
+  __attribute__ ((unused,  section(EH_FRAME_SECTION_NAME),
+		  aligned(4)))
+  = { 0 };
+#endif
+
+#if TARGET_USE_JCR_SECTION
+/* Null terminate the .jcr section array.  */
+static void *__JCR_END__[1] 
+   __attribute__ ((unused, section(JCR_SECTION_NAME),
+		   aligned(sizeof(void *))))
+   = { 0 };
+#endif
+
+
+/*
+extern void __gcco_register_frame (void); 
+extern void __gcco_deregister_frame (void);
+*/
+
+
+/* Register the eh_frame. This has to be the first .ctor to  be invoked
+   so we put its address in the .ctor section of the last object and
+   give it a high priority (ld uses strcmp to sort sections by name).
+   The definition is in crtbegin.c since we need to pull in.
+   libgcc.a __register_frame_info. 
+   Likewise for frame deregistration on exit from app or dll.  */
+
+/* FIXME: Port constructor(N) here */
+
+__asm__(
+  ".section\t.ctors.zzzzz ,\"w\"\n\t"
+  ".align 4\n\t"
+   ".long\t___gcc_register_frame");
+
+__asm__(
+  ".section\t.dtors.zzzzz ,\"w\"\n\t"
+  ".align 4\n\t"
+   ".long\t___gcc_deregister_frame ");

Modified: llvm-gcc-4.2/trunk/gcc/config/i386/cygming.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/i386/cygming.h?rev=47684&r1=47683&r2=47684&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/i386/cygming.h (original)
+++ llvm-gcc-4.2/trunk/gcc/config/i386/cygming.h Wed Feb 27 13:25:16 2008
@@ -29,11 +29,24 @@
 #ifdef HAVE_GAS_PE_SECREL32_RELOC
 #define DWARF2_DEBUGGING_INFO 1
 
+/* LLVM LOCAL begin mainline 125696 */
+/* Map gcc register number to DBX register number. Maintain
+   compatibility with old -gstabs compiled code.  */
+/* LLVM LOCAL end mainline 125696 */
 #undef DBX_REGISTER_NUMBER
 #define DBX_REGISTER_NUMBER(n) (write_symbols == DWARF2_DEBUG   \
                                 ? svr4_dbx_register_map[n]      \
                                 : dbx_register_map[n])
 
+/* LLVM LOCAL begin mainline 125696 */
+/* Map gcc register number to DWARF 2 CFA column number.  Always
+   use the svr4_dbx_register_map for DWARF .eh_frame even if we
+   don't use DWARF .debug_frame.  */
+#undef DWARF_FRAME_REGNUM
+#define DWARF_FRAME_REGNUM(n) svr4_dbx_register_map[(n)]
+/* LLVM LOCAL end mainline 125696 */
+
+
 /* Use section relative relocations for debugging offsets.  Unlike
    other targets that fake this by putting the section VMA at 0, PE
    won't allow it.  */
@@ -262,10 +275,17 @@
 #undef ASM_COMMENT_START
 #define ASM_COMMENT_START " #"
 
-/* DWARF2 Unwinding doesn't work with exception handling yet.  To make
-   it work, we need to build a libgcc_s.dll, and dcrt0.o should be
-   changed to call __register_frame_info/__deregister_frame_info.  */
+/* LLVM LOCAL begin mainline 125696 */
+#ifndef DWARF2_UNWIND_INFO
+/* If configured with --disable-sjlj-exceptions, use DWARF2, else
+   default to SJLJ  */
+#if defined (CONFIG_SJLJ_EXCEPTIONS) && !CONFIG_SJLJ_EXCEPTIONS
+#define DWARF2_UNWIND_INFO 1
+#else
 #define DWARF2_UNWIND_INFO 0
+#endif
+#endif
+/* LLVM LOCAL end mainline 125696 */
 
 /* Don't assume anything about the header files.  */
 #define NO_IMPLICIT_EXTERN_C

Modified: llvm-gcc-4.2/trunk/gcc/config/i386/cygwin.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/i386/cygwin.h?rev=47684&r1=47683&r2=47684&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/i386/cygwin.h (original)
+++ llvm-gcc-4.2/trunk/gcc/config/i386/cygwin.h Wed Feb 27 13:25:16 2008
@@ -33,12 +33,17 @@
   %{!nostdinc:%{!mno-win32|mno-cygwin:-idirafter ../include/w32api%s -idirafter ../../include/w32api%s}}\
 "
 
+/* LLVM LOCAL begin mainline 125696 */
 #undef STARTFILE_SPEC
 #define STARTFILE_SPEC "\
   %{shared|mdll: %{mno-cygwin:dllcrt2%O%s}}\
   %{!shared: %{!mdll: %{!mno-cygwin:crt0%O%s} %{mno-cygwin:crt2%O%s}\
   %{pg:gcrt0%O%s}}}\
-"
+  crtbegin%O%s"
+
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "crtend%O%s"
+/* LLVM LOCAL end mainline 125696 */
 
 /* Normally, -lgcc is not needed since everything in it is in the DLL, but we
    want to allow things to be added to it when installing new versions of

Modified: llvm-gcc-4.2/trunk/gcc/config/i386/mingw32.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/i386/mingw32.h?rev=47684&r1=47683&r2=47684&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/i386/mingw32.h (original)
+++ llvm-gcc-4.2/trunk/gcc/config/i386/mingw32.h Wed Feb 27 13:25:16 2008
@@ -65,9 +65,16 @@
 #define LIBGCC_SPEC \
   "%{mthreads:-lmingwthrd} -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt"
 
+/* LLVM LOCAL begin mainline 125696 */
 #undef STARTFILE_SPEC
 #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
-  %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s}"
+  %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s}  \
+  crtbegin%O%s"
+
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "crtend%O%s"
+/* LLVM LOCAL end mainline 125696 */
+
 
 /* Override startfile prefix defaults.  */
 #ifndef STANDARD_STARTFILE_PREFIX_1
@@ -112,3 +119,10 @@
 /* mingw32 uses the  -mthreads option to enable thread support.  */
 #undef GOMP_SELF_SPECS
 #define GOMP_SELF_SPECS "%{fopenmp: -mthreads}"
+
+
+/* LLVM LOCAL begin mainline 125696 */
+/* This works on mingw32.  */
+#undef TARGET_USE_JCR_SECTION
+#define TARGET_USE_JCR_SECTION 1
+/* LLVM LOCAL end mainline 125696 */

Modified: llvm-gcc-4.2/trunk/gcc/config/i386/t-cygming
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/i386/t-cygming?rev=47684&r1=47683&r2=47684&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/i386/t-cygming (original)
+++ llvm-gcc-4.2/trunk/gcc/config/i386/t-cygming Wed Feb 27 13:25:16 2008
@@ -30,3 +30,18 @@
 	$(srcdir)/config/i386/winnt-stubs.c
 
 STMP_FIXINC=stmp-fixinc
+
+# LLVM LOCAL begin mainline 125696
+# Effectively disable the crtbegin/end rules using crtstuff.c
+T = disable
+
+CRTSTUFF_T_CFLAGS = -fno-omit-frame-pointer
+
+crtbegin.o: $(srcdir)/config/i386/cygming-crtbegin.c $(GCC_PASSES)
+	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) -c -o crtbegin.o \
+	$(srcdir)/config/i386/cygming-crtbegin.c
+
+crtend.o: $(srcdir)/config/i386/cygming-crtend.c $(GCC_PASSES)
+	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) -c -o crtend.o  \
+	$(srcdir)/config/i386/cygming-crtend.c
+# LLVM LOCAL end mainline 125696

Modified: llvm-gcc-4.2/trunk/gcc/libgcc2.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/libgcc2.c?rev=47684&r1=47683&r2=47684&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/libgcc2.c (original)
+++ llvm-gcc-4.2/trunk/gcc/libgcc2.c Wed Feb 27 13:25:16 2008
@@ -2126,7 +2126,7 @@
 #endif
 #endif /* L_trampoline */
 
-#ifndef __CYGWIN__
+#if !defined (__CYGWIN__) && !defined(__MINGW32__)
 #ifdef L__main
 
 #include "gbl-ctors.h"





More information about the llvm-commits mailing list