public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Build libgcc_s on Windows
@ 2008-08-18 19:08 Aaron W. LaFramboise
  2008-08-19  5:16 ` Danny Smith
                   ` (2 more replies)
  0 siblings, 3 replies; 56+ messages in thread
From: Aaron W. LaFramboise @ 2008-08-18 19:08 UTC (permalink / raw)
  To: gcc-patches; +Cc: Danny Smith, libstdc++

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

This patch enables building libgcc_s as a DLL on MinGW and Cygwin.  This 
allows throwing exceptions across DLL boundaries when using a shared 
libgcc_s.

It needs approval from toplevel configure, gcc/mkmap, Windows and 
libstdc++ maintainers.

It was tested by a bootstrap and testsuite run on i386-pc-mingw32, as 
well as manually to make sure it works.

The mkmap machinery is re-used to generate a .def file, which is PECOFF 
equivalent of a flat map file.  This should help control the ABI a little.

OK to commit?

[-- Attachment #2: gcc-4.4.0-20080817-libgcc_s.patch --]
[-- Type: text/plain, Size: 9441 bytes --]

2008-08-17  Aaron W. LaFramboise  <aaronavay62@aaronwl.com>

	<toplevel>
	* configure.ac (RPATH_ENVVAR): Use PATH on Windows.
	(GCC_SHLIB_SUBDIR): New.
	* Makefile.tpl (HOST_LIB_PATH_gcc): Use GCC_SHLIB_SUBDIR.
	* configure: Regenerate.
	* Makefile.in: Regenerate.

	<gcc>
	* mkmap-flat.awk: Add option pe_dll.
	* config/i386/t-cygming (SHLIB_LINK): Support building libgcc_s.
	* gcc/config/i386/t-cygwin (SHLIB_LC): Add.
	* gcc/config/i386/t-mingw32 (SHLIB_LC): Add.
	* config/i386/mingw32.h (SHARED_LIBGCC_UNDEFS_SPEC): New.
	(SUBTARGET_EXTRA_SPECS): Use SHARED_LIBGCC_UNDEFS_SPEC.
	(LINK_SPEC): Support libgcc_s.
	(LIBGCC_SPEC): Support libgcc_s.
	(LIBGCC_SONAME): New.

	<libstdc++-v3>
	* acinclude.m4 <enable_symvers>: Don't use symvers on Windows.
	* configure: Regenerated.
	* Makefile.in: Regenerated.
	* src/Makefile.in: Regenerated.
	* doc/makefile.in: Regenerated.
	* po/Makefile.in: Regenerated.
	* libmath/Makefile.in: Regenerated.
	* include/Makefile.in: Regenerated.
	* libsupc++/Makefile.in: Regenerated.
	* testsuite/makefile.in: Regenerated.

Index: gcc/mkmap-flat.awk
===================================================================
--- gcc/mkmap-flat.awk	(revision 139148)
+++ gcc/mkmap-flat.awk	(working copy)
@@ -18,6 +18,11 @@
 # along with GCC; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.
 
+# Options:
+#   "-v leading_underscore=1" : Symbols in map need leading underscore.
+#   "-v pe_dll=1"             : Create .DEF file for Windows PECOFF
+#                               DLL link instead of map file.
+
 BEGIN {
   state = "nm";
   excluding = 0;
@@ -86,7 +91,14 @@ $1 == "}" {
 }
 
 END {
+
+  if (pe_dll) {
+    # This matches SHLIB_SONAME in config/i386/t-cygming.
+    print "LIBRARY libgcc_s_1.dll";
+    print "EXPORTS";
+  }
+
   for (sym in export)
-    if (def[sym])
+    if (def[sym] || (pe_dll && def["_" sym]))
       print sym;
 }
Index: gcc/config/i386/t-cygming
===================================================================
--- gcc/config/i386/t-cygming	(revision 139148)
+++ gcc/config/i386/t-cygming	(working copy)
@@ -36,3 +36,51 @@ msformat-c.o: $(srcdir)/config/i386/msfo
 	$(srcdir)/config/i386/msformat-c.c
 
 STMP_FIXINC=stmp-fixinc
+
+# Build a shared libgcc library for PECOFF with a DEF file
+# with the GNU linker.
+#
+# mkmap-flat.awk is used with the pe_dll option to produce a DEF instead
+# of an ELF map file.
+#
+# Warning: If SHLIB_SOVERSION or SHLIB_SONAME is updated, LIBGCC_SONAME
+# in mingw32.h must be updated also.
+
+SHLIB_EXT = .dll
+SHLIB_IMPLIB = @shlib_base_name@.a
+SHLIB_SOVERSION = 1
+SHLIB_SONAME = @shlib_base_name@_$(SHLIB_SOVERSION)$(SHLIB_EXT)
+SHLIB_MAP = @shlib_map_file@
+SHLIB_OBJS = @shlib_objs@
+SHLIB_DIR = @multilib_dir@/shlib
+SHLIB_SLIBDIR_QUAL = @shlib_slibdir_qual@
+SHLIB_LC = -luser32 -lkernel32 -ladvapi32 -lshell32
+
+SHLIB_LINK = $(LN_S) $(SHLIB_MAP) $(SHLIB_MAP).def && \
+	if [ ! -d $(SHLIB_DIR) ]; then \
+		mkdir $(SHLIB_DIR) \
+	else true; fi && \
+	$(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -shared -nodefaultlibs \
+	$(SHLIB_MAP).def \
+	-Wl,--out-implib,$(SHLIB_DIR)/$(SHLIB_IMPLIB).tmp \
+	-o $(SHLIB_DIR)/$(SHLIB_SONAME).tmp @multilib_flags@ \
+	$(SHLIB_OBJS) $(SHLIB_LC) && \
+	$(AR_FOR_TARGET) -r $(SHLIB_DIR)/$(SHLIB_IMPLIB).tmp \
+		_chkstk.o _ctors.o && \
+	if [ -f $(SHLIB_DIR)/$(SHLIB_SONAME) ]; then \
+	  mv -f $(SHLIB_DIR)/$(SHLIB_SONAME) \
+		$(SHLIB_DIR)/$(SHLIB_SONAME).backup; \
+	else true; fi && \
+	mv $(SHLIB_DIR)/$(SHLIB_SONAME).tmp $(SHLIB_DIR)/$(SHLIB_SONAME) && \
+	mv $(SHLIB_DIR)/$(SHLIB_IMPLIB).tmp $(SHLIB_DIR)/$(SHLIB_IMPLIB)
+# $(slibdir) double quoted to protect it from expansion while building
+# libgcc.mk.  We want this delayed until actual install time.
+SHLIB_INSTALL = \
+	$$(mkinstalldirs) $$(DESTDIR)$$(slibdir)$(SHLIB_SLIBDIR_QUAL); \
+	$(INSTALL_PROGRAM) $(SHLIB_DIR)/$(SHLIB_SONAME) \
+	  $$(DESTDIR)$$(bindir)/$(SHLIB_SONAME); \
+	$(INSTALL_DATA) $(SHLIB_DIR)/$(SHLIB_IMPLIB) \
+	  $$(DESTDIR)$$(slibdir)$(SHLIB_SLIBDIR_QUAL)/$(SHLIB_IMPLIB)
+SHLIB_MKMAP = $(srcdir)/mkmap-flat.awk
+SHLIB_MKMAP_OPTS = -v pe_dll=1
+SHLIB_MAPFILES = $(srcdir)/libgcc-std.ver
Index: gcc/config/i386/t-cygwin
===================================================================
--- gcc/config/i386/t-cygwin	(revision 139148)
+++ gcc/config/i386/t-cygwin	(working copy)
@@ -14,3 +14,5 @@ cygwin2.o: $(srcdir)/config/i386/cygwin2
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 	$(srcdir)/config/i386/cygwin2.c
 
+# Cygwin-specific parts of LIB_SPEC
+SHLIB_LC += -lcygwin
Index: gcc/config/i386/t-mingw32
===================================================================
--- gcc/config/i386/t-mingw32	(revision 139148)
+++ gcc/config/i386/t-mingw32	(working copy)
@@ -1,2 +1,5 @@
 # Match SYSTEM_INCLUDE_DIR
 NATIVE_SYSTEM_HEADER_DIR = /mingw/include
+
+# MinGW-specific parts of LIB_SPEC
+SHLIB_LC += -lmingw32 -lmingwex -lmoldname -lmsvcrt
Index: gcc/config/i386/mingw32.h
===================================================================
--- gcc/config/i386/mingw32.h	(revision 139148)
+++ gcc/config/i386/mingw32.h	(working copy)
@@ -67,19 +67,33 @@ along with GCC; see the file COPYING3.  
 #define LIB_SPEC "%{pg:-lgmon} %{mwindows:-lgdi32 -lcomdlg32} \
                   -luser32 -lkernel32 -ladvapi32 -lshell32"
 
-/* Include in the mingw32 libraries with libgcc */
-#undef LINK_SPEC
+/* Weak symbols do not get resolved if using a Windows dll import lib.
+   Make the unwind registration references strong undefs.  */
+#if DWARF2_UNWIND_INFO
+#define SHARED_LIBGCC_UNDEFS_SPEC \
+ "%{shared-libgcc: -u ___register_frame_info -u ___deregister_frame_info}"
+#else
+#define SHARED_LIBGCC_UNDEFS_SPEC ""
+#endif
+
+#undef  SUBTARGET_EXTRA_SPECS
+#define SUBTARGET_EXTRA_SPECS						\
+  { "shared_libgcc_undefs", SHARED_LIBGCC_UNDEFS_SPEC }
+
 #define LINK_SPEC "%{mwindows:--subsystem windows} \
   %{mconsole:--subsystem console} \
   %{shared: %{mdll: %eshared and mdll are not compatible}} \
   %{shared: --shared} %{mdll:--dll} \
   %{static:-Bstatic} %{!static:-Bdynamic} \
-  %{shared|mdll: -e _DllMainCRTStartup@12}"
+  %{shared|mdll: -e _DllMainCRTStartup@12 --enable-auto-image-base} \
+  %(shared_libgcc_undefs)"
 
 /* Include in the mingw32 libraries with libgcc */
 #undef LIBGCC_SPEC
 #define LIBGCC_SPEC \
-  "%{mthreads:-lmingwthrd} -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt"
+  "%{mthreads:-lmingwthrd} -lmingw32 \
+   %{shared-libgcc:-lgcc_s} -lgcc \
+   -lmoldname -lmingwex -lmsvcrt"
 
 #undef STARTFILE_SPEC
 #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
@@ -186,3 +200,6 @@ __enable_execute_stack (void *addr)					
 #if !TARGET_64BIT
 #define MD_UNWIND_SUPPORT "config/i386/w32-unwind.h"
 #endif
+
+/* This matches SHLIB_SONAME and SHLIB_SOVERSION in t-cygming. */
+#define LIBGCC_SONAME "libgcc_s_1.dll"
Index: libstdc++-v3/acinclude.m4
===================================================================
--- libstdc++-v3/acinclude.m4	(revision 139148)
+++ libstdc++-v3/acinclude.m4	(working copy)
@@ -2527,7 +2527,12 @@ if test x$enable_symvers = xyes ; then
     enable_symvers=no
   else
     if test $with_gnu_ld = yes ; then
-      enable_symvers=gnu
+      case ${target_os} in
+        cygwin* | pe | mingw32*)
+          enable_symvers=no ;;
+        *)
+          enable_symvers=gnu ;;
+      esac
     else
       case ${target_os} in
         darwin*)
Index: configure.ac
===================================================================
--- configure.ac	(revision 139148)
+++ configure.ac	(working copy)
@@ -2050,12 +2050,21 @@ case "${host}" in
   ;;
 esac
 
+# Decide which environment variable is used to find dynamic libraries.
 case "${host}" in
   *-*-hpux*) RPATH_ENVVAR=SHLIB_PATH ;;
   *-*-darwin* | *-*-rhapsody* ) RPATH_ENVVAR=DYLD_LIBRARY_PATH ;;
+  *-*-mingw* | *-*-cygwin ) RPATH_ENVVAR=PATH ;;
   *) RPATH_ENVVAR=LD_LIBRARY_PATH ;;
 esac
 
+# On systems where the dynamic library environment variable is PATH,
+if test "$RPATH_ENVVAR" = PATH; then
+  GCC_SHLIB_SUBDIR=/shlib
+else
+  GCC_SHLIB_SUBDIR=
+fi
+
 # Record target_configdirs and the configure arguments for target and
 # build configuration in Makefile.
 target_configdirs=`echo "${target_configdirs}" | sed -e 's/target-//g'`
@@ -2513,6 +2522,7 @@ AC_SUBST_FILE(ospace_frag)
 
 # Miscellanea: directories, flags, etc.
 AC_SUBST(RPATH_ENVVAR)
+AC_SUBST(GCC_SHLIB_SUBDIR)
 AC_SUBST(tooldir)
 AC_SUBST(build_tooldir)
 AC_SUBST(CONFIGURE_GDB_TK)
Index: Makefile.tpl
===================================================================
--- Makefile.tpl	(revision 139148)
+++ Makefile.tpl	(working copy)
@@ -108,6 +108,11 @@ GDB_NLM_DEPS = 
 # the libraries.
 RPATH_ENVVAR = @RPATH_ENVVAR@
 
+# On targets where RPATH_ENVVAR is PATH, a subdirectory of the GCC build path
+# is used instead of the directory itself to avoid including built
+# executables in PATH.
+GCC_SHLIB_SUBDIR = @GCC_SHLIB_SUBDIR@
+
 # Build programs are put under this directory.
 BUILD_SUBDIR = @build_subdir@
 # This is set by the configure script to the arguments to use when configuring
@@ -439,7 +444,7 @@ HOST_LIB_PATH = [+ FOR host_modules +][+
 
 # Define HOST_LIB_PATH_gcc here, for the sake of TARGET_LIB_PATH, ouch
 @if gcc
-HOST_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/gcc:$$r/$(HOST_SUBDIR)/prev-gcc:
+HOST_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/gcc$(GCC_SHLIB_SUBDIR):$$r/$(HOST_SUBDIR)/prev-gcc$(GCC_SHLIB_SUBDIR):
 @endif gcc
 
 [+ FOR host_modules +][+ IF lib_path +]

^ permalink raw reply	[flat|nested] 56+ messages in thread
[parent not found: <1221035558.13510.ezmlm@gcc.gnu.org>]
[parent not found: <OFB5BC0CC2.0ADC574F-ONC12574E1.0039EBC2-C12574E1.0039FBF6@LocalDomain>]

end of thread, other threads:[~2008-11-21 13:58 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-18 19:08 [PATCH] Build libgcc_s on Windows Aaron W. LaFramboise
2008-08-19  5:16 ` Danny Smith
2008-08-20 14:30   ` Aaron W. LaFramboise
2008-08-21  5:15     ` Danny Smith
2008-08-28  4:15       ` Dave Korn
2008-08-28  9:15         ` Danny Smith
2008-08-28  9:35           ` Brian Dessent
2008-08-19  8:05 ` Paolo Bonzini
2008-08-19 13:20   ` Aaron W. LaFramboise
2008-08-19 16:17     ` Paolo Bonzini
2008-09-02  6:40 ` NightStrike
2008-09-02 12:03   ` Kai Tietz
2008-09-02 16:30     ` NightStrike
2008-09-03  9:51       ` Kai Tietz
2008-09-03 18:03         ` NightStrike
2008-09-04  3:52         ` Danny Smith
2008-09-04  6:25           ` NightStrike
2008-09-04  8:00             ` Danny Smith
2008-09-04 10:48               ` [patch i386]: Adjust DWARF_OFFSET_SIZE for w64 Kai Tietz
2008-09-04 16:30                 ` NightStrike
2008-09-09 21:18                 ` Richard Henderson
2008-09-10  8:20                   ` Kai Tietz
2008-09-05 11:21               ` [patch]: Fix bootstrap/PR 25502: I64d format Werror problem in build Kai Tietz
2008-09-05 13:57                 ` Joseph S. Myers
2008-09-05 14:02                   ` Kai Tietz
2008-09-05 14:07                     ` Joseph S. Myers
2008-09-05 16:28                       ` Kai Tietz
2008-09-05 20:18                         ` Joseph S. Myers
2008-09-08 10:54                           ` Kai Tietz
2008-09-08 12:28                             ` Joseph S. Myers
2008-09-08 12:42                               ` Kai Tietz
2008-09-08 15:44                                 ` Joseph S. Myers
2008-09-09  0:12                                   ` Aaron W. LaFramboise
2008-09-09  5:42                                     ` Danny Smith
2008-09-09  6:01                                       ` Kai Tietz
2008-09-12 15:33                                       ` Kai Tietz
2008-09-12 15:40                                       ` Aaron W. LaFramboise
2008-09-12 16:04                                         ` NightStrike
2008-09-12 16:38                                       ` NightStrike
2008-09-12 21:42                                         ` Danny Smith
2008-10-10 12:14                                       ` Kai Tietz
2008-10-11 10:27                                         ` Danny Smith
2008-10-11 15:34                                           ` Kai Tietz
2008-10-12  9:48                                         ` Danny Smith
2008-10-13 11:36                                           ` Kai Tietz
2008-09-15  8:18                                 ` Aaron W. LaFramboise
2008-09-04  8:31           ` [PATCH] Build libgcc_s on Windows Kai Tietz
2008-09-09 19:57           ` lkcl
2008-09-10  8:49             ` lkcl
2008-09-10  9:11               ` Brian Dessent
2008-09-10  9:26                 ` lkcl
2008-09-10 12:32                   ` lkcl
2008-09-10  9:19               ` lkcl
     [not found] <1221035558.13510.ezmlm@gcc.gnu.org>
2008-09-10  9:09 ` Jay
2008-09-10  9:43   ` lkcl
     [not found] <OFB5BC0CC2.0ADC574F-ONC12574E1.0039EBC2-C12574E1.0039FBF6@LocalDomain>
2008-11-21 14:09 ` [patch]: Fix bootstrap/PR 25502: I64d format Werror problem in build Kai Tietz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).