SHLIB_SOVERSION = 1.1
SHLIB_SO_MINVERSION = 1
-SHLIB_VERSTRING = -compatibility_version $(SHLIB_SO_MINVERSION) -current_version $(SHLIB_SOVERSION)
+SHLIB_VERSTRING = -compatibility_version $(SHLIB_SO_MINVERSION) \
+ -current_version $(SHLIB_SOVERSION)
SHLIB_EXT = .dylib
SHLIB_LC = -lSystem
+SHLIB_INSTALL_DIR = $(slibdir)
-# Shorthand expressions for the LINK below.
+SHLIB_MKMAP = $(srcdir)/mkmap-flat.awk
+SHLIB_MKMAP_OPTS = -v leading_underscore=1
+
+# Shorthand expressions for the LINK below, these are substituted in the
+# link expression.
SHLIB_INSTALL_NAME = @shlib_base_name@.$(SHLIB_SOVERSION)$(SHLIB_EXT)
SHLIB_MAP = @shlib_map_file@
SHLIB_DIR = @multilib_dir@
# library, that is what we eventually install.
SHLIB_LINK = $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \
- -install_name @shlib_slibdir@/$(SHLIB_INSTALL_NAME) \
+ -install_name $(SHLIB_INSTALL_DIR)/$(SHLIB_INSTALL_NAME) \
-single_module -o $(SHLIB_DIR)/$(SHLIB_SONAME) \
-Wl,-exported_symbols_list,$(SHLIB_MAP) \
$(SHLIB_VERSTRING) \
@multilib_flags@ @shlib_objs@ $(SHLIB_LC)
-SHLIB_MKMAP = $(srcdir)/mkmap-flat.awk
-SHLIB_MKMAP_OPTS = -v leading_underscore=1
+# we do our own thing
+SHLIB_INSTALL =
LGCC_FILES = libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)
-INSTALL_FILES=$(LGCC_FILES)
+ifeq ($(BUILD_LIBGCCS1),YES)
-# we do our own thing
-SHLIB_INSTALL =
+# We are going to build a libgcc_s.1.dylib so that distributions can
+# install it for compatibility with binaries linked against the old
+# libgcc_ext.10.x.dylib stubs.
+
+# For systems after macOS 10.7 we can forward the correct unwinder symbols
+# from libSystem.
+
+# For older systems we have to forward an entire library (since they cannot
+# selectively forward symbols, which means that we cannot forward the unwinder
+# in /usr/lib/libgcc_s.1.dylib). We also cannot forward the entire library
+# since that creates a self-referencing loop when DYLD_LIBRARY_PATH is used.
+# To provide the unwinder symbols in this case, we build the unwinder into a
+# separate shared lib (libgcc_ehs) and forward that.
+
+# These targets are local to this make fragment, which means that they do not
+# get the substitutions seen in SHLIB_LINK.
+
+ifneq ($(LIBEHSOBJS),)
+
+EHS_INSTNAME = libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)
+
+# multilib build for a shared EH lib.
+$(LIBEHSOBJS): libgcc_tm.h
+
+libgcc_ehs$(SHLIB_EXT): $(LIBEHSOBJS)
+ mkdir -p $(MULTIDIR)
+ $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \
+ -install_name $(SHLIB_INSTALL_DIR)/$(EHS_INSTNAME) \
+ -o $(MULTIDIR)/libgcc_ehs$(SHLIB_EXT) $(SHLIB_VERSTRING) \
+ $(LIBEHSOBJS) $(SHLIB_LC)
+
+all: libgcc_ehs$(SHLIB_EXT)
+
+LGCC_FILES += libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)
+
+endif
+
+# Provide libgcc_s.1 for backwards compatibility.
+LGCC_FILES += libgcc_s.1.dylib
+
+endif
+
+INSTALL_FILES=$(LGCC_FILES)
-# For the toplevel multilib, build a fat archive including all the multilibs.
+# For the toplevel multilib, build FAT dylibs including all the multilibs.
ifeq ($(MULTIBUILDTOP),)
ifeq ($(enable_shared),yes)
-create libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T*
rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T*
-# Install the shared library.
+ifeq ($(BUILD_LIBGCCS1),YES)
+ifneq ($(LIBEHSOBJS),)
+
+libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT): all-multi libgcc_ehs$(SHLIB_EXT)
+ MLIBS=`$(CC) --print-multi-lib | sed -e 's/;.*$$//'` ; \
+ for mlib in $$MLIBS ; do \
+ cp ../$${mlib}/libgcc/$${mlib}/libgcc_ehs$(SHLIB_EXT) \
+ ./libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \
+ done
+ $(LIPO) -output libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) \
+ -create libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T*
+ rm libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T*
+
+
+libgcc_s.1.dylib: libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)
+ MLIBS=`$(CC) --print-multi-lib | sed -e 's/;.*$$//'` ; \
+ for mlib in $$MLIBS ; do \
+ cp ../$${mlib}/libgcc/$${mlib}/libgcc_s$(SHLIB_EXT) \
+ ./libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \
+ cp ../$${mlib}/libgcc/$${mlib}/libgcc_ehs$(SHLIB_EXT) \
+ ./libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \
+ arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \
+ $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \
+ -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \
+ -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \
+ -Wl,-reexport_library,libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \
+ -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \
+ -compatibility_version 1 -current_version 1 ; \
+ done
+ $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T*
+ rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T*
+ rm libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T*
+
+else
+
+libgcc_s.1.dylib: libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)
+ MLIBS=`$(CC) --print-multi-lib | sed -e 's/;.*$$//'` ; \
+ for mlib in $$MLIBS ; do \
+ cp ../$${mlib}/libgcc/$${mlib}/libgcc_s$(SHLIB_EXT) \
+ ./libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \
+ arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \
+ $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \
+ -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \
+ -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \
+ -lSystem \
+ -Wl,-reexported_symbols_list,$(srcdir)/config/darwin-unwind.ver \
+ -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \
+ -compatibility_version 1 -current_version 1 ; \
+ done
+ $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T*
+ rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T*
+
+endif
+endif
+
+# Install the shared libraries.
install-darwin-libgcc-stubs :
$(mkinstalldirs) $(DESTDIR)$(slibdir)
else
-# Do not install shared libraries for any other multilibs. Unless we are
-# putting them in the gcc directory during a build, for compatibility with
-# the pre-top-level layout. In that case we provide symlinks to the FAT lib
-# from the sub-directories.
+# Do not install shared libraries for multilibs. Unless we are putting them
+# in the gcc directory during a build, for compatibility with the pre-top-
+# level layout. In that case we provide symlinks to the FAT lib from the
+# multilib sub-directories.
ifeq ($(enable_shared),yes)
all: install-darwin-libgcc-links