public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] Build libgcc_s on Windows
@ 2008-08-18 21:30 Charles Wilson
  2008-08-19 16:42 ` Charles Wilson
  0 siblings, 1 reply; 36+ messages in thread
From: Charles Wilson @ 2008-08-18 21:30 UTC (permalink / raw)
  To: gcc-patches

I'm a little concerned about this part:

+  if (pe_dll) {
+    # This matches SHLIB_SONAME in config/i386/t-cygming.
+    print "LIBRARY libgcc_s_1.dll";
+    print "EXPORTS";
+  }

when it comes to interoperability on the Windows platform.  Suppose you
have an application compiled by mingw-gcc and one compiled by
cygwin-gcc. For these two apps to work properly, the libgcc dll must be
(a) in the PATH, or (b) in the same directory as the executable (there
are a few other possibilities as well, but let's ignore those for now).

It's the first -- and most common -- case that concerns me. I'll have
two identically named DLLs in the PATH: one which is intended for use by
"native" windows programs, and the other which is intended for use by
cygwin programs.  Presumably the code in these two different DLLs will
be different, since the behavior and capabilities of the two "platforms"
differ.   Assuming case (a) above, then whichever one is found first in
the PATH will always be used by any application that claims to need
"libgcc_s_1".  This is a guaranteed recipe for runtime conflicts.

It is also why (almost all) DLLs shipped with cygwin are named
"cygfoo.dll", not "libfoo.dll" -- this naming scheme is also built in to
libtool, and is supported by ld since about 2000, which is why if you
try to build libstdc++ shared in current gcc on cygwin, you'll get
cygstdc++-VER.dll.

So, IMO, both SHLIB_SONAME and the snippet above should be sensitive to
the actual platform (cygwin, or mingw).

Also, there is another interoperability issue: IIRC the cygwin gcc
maintainer intends to provide (or hopes to one day provide) both dw2 and
sjlj versions of the compiler.  This also might be useful -- one day --
on the mingw platform. [1]  But, in that case, you'll again have two
different runtime DLLs; one for dw2 and one for sjlj.  Perhaps
SHLIB_SONAME and the snippet above should /also/ be sensitive to that
setting?

I realize you could continue this down this rabbithole indefinitely,
with
cyggcc_s_sjlj_nothread_ipcsupport_other_random_configure_option_1.dll,
and that would be very silly.  However, the mingw-vs-cygwin issue and
the dw2-vs-sjlj issues probably do need to be resolved in a way that
applications compiled with compilers of those four flavors can coexist
on the same machine.

from t-cygming:

+SHLIB_IMPLIB = @shlib_base_name@.a
+SHLIB_SOVERSION = 1
+SHLIB_SONAME = @shlib_base_name@_$(SHLIB_SOVERSION)$(SHLIB_EXT)

Here, SHLIB_IMPLIB *could* be named @shlib_base_name@.dll.a to make
clear that it is an import library (gnu ld understands this since about
2000) -- and for parallelism to the import libraries created by libtool
for the other runtime libs.  Also, in reference to the disambiguation
above, all "four" implibs could have the same name, since they will live
in the compiler's private area; only the _SONAMEs need to be explicitly
disambiguated.


--
Chuck

[1] even if not provided officially by the mingw team, a private entity
might want an sjlj compiler if they run into issues with your upcoming
foreign frame support.  And they might assume that any application
products they ship built using that compiler will actually work on a
client's machine, even if that client has ALSO installed applications
built using the official mingw-dw2 compiler.

^ permalink raw reply	[flat|nested] 36+ messages in thread
[parent not found: <1221035558.13510.ezmlm@gcc.gnu.org>]
* Re: [PATCH] Build libgcc_s on Windows
@ 2008-08-28 12:56 Charles Wilson
  0 siblings, 0 replies; 36+ messages in thread
From: Charles Wilson @ 2008-08-28 12:56 UTC (permalink / raw)
  To: GCC Patches

Brian Dessent wrote:
> Danny Smith wrote:
> 
>> The "downside" of this is that  we  force user to always add
>> "-shared-libgcc" to gcc command line rather than allow the clever user
>> to rely on a libgcc.dll.a vs libgcc.a  link order diff.
> 
> I'm not sure that will work in the case of Cygwin then, since the plan
> as I understand it is to behave like Linux: shared libgcc is the default
> if not specified, and must be overridden with -static-libgcc.

IIRC, this is one of the differences between mingw and cygwin with
regards to shared libgcc: for the former, they decided that static
runtimes should be the default, given the strong desire of most mingw
users for so-called 'monolithic' executables.  On cygwin, of course, the
more like unix the better, so shared libgcc should be the default.

--
Chuck

^ permalink raw reply	[flat|nested] 36+ messages in thread
* [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; 36+ 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] 36+ messages in thread

end of thread, other threads:[~2008-09-10  9:54 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-18 21:30 [PATCH] Build libgcc_s on Windows Charles Wilson
2008-08-19 16:42 ` Charles Wilson
2008-08-19 20:34   ` Paolo Bonzini
2008-08-25  7:40     ` Charles Wilson
2008-08-26 12:44       ` Dave Korn
2008-08-28  3:21   ` Dave Korn
2008-08-28  8:51     ` Charles Wilson
2008-08-28 13:04       ` Dave Korn
     [not found] <1221035558.13510.ezmlm@gcc.gnu.org>
2008-09-10  9:09 ` Jay
2008-09-10  9:43   ` lkcl
  -- strict thread matches above, loose matches on Subject: below --
2008-08-28 12:56 Charles Wilson
2008-08-18 19:08 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  8:31           ` 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

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).