1# Build a shared libgcc library with the darwin linker. 2 3SHLIB_SOVERSION = 1.1 4SHLIB_SO_MINVERSION = 1 5SHLIB_VERSTRING = -compatibility_version $(SHLIB_SO_MINVERSION) \ 6 -current_version $(SHLIB_SOVERSION) 7SHLIB_EXT = .dylib 8SHLIB_LC = -lSystem 9SHLIB_INSTALL_DIR = $(slibdir) 10 11SHLIB_MKMAP = $(srcdir)/mkmap-flat.awk 12SHLIB_MKMAP_OPTS = -v leading_underscore=1 13 14# Shorthand expressions for the LINK below, these are substituted in the 15# link expression. 16SHLIB_INSTALL_NAME = @shlib_base_name@.$(SHLIB_SOVERSION)$(SHLIB_EXT) 17SHLIB_MAP = @shlib_map_file@ 18SHLIB_DIR = @multilib_dir@ 19SHLIB_SONAME = @shlib_base_name@$(SHLIB_EXT) 20 21# Darwin only searches in shlib_slibdir for shared libraries, not in 22# subdirectories. The link builds one architecture slice in its designated 23# subdir. The code under MULTIBUILDTOP combines these into a single FAT 24# library, that is what we eventually install. 25 26SHLIB_LINK = $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \ 27 -install_name $(SHLIB_INSTALL_DIR)/$(SHLIB_INSTALL_NAME) \ 28 -single_module -o $(SHLIB_DIR)/$(SHLIB_SONAME) \ 29 -Wl,-exported_symbols_list,$(SHLIB_MAP) \ 30 $(SHLIB_VERSTRING) \ 31 @multilib_flags@ @shlib_objs@ $(SHLIB_LC) 32 33# we do our own thing 34SHLIB_INSTALL = 35 36LGCC_FILES = libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) 37 38ifeq ($(BUILD_LIBGCCS1),YES) 39 40# We are going to build a libgcc_s.1.dylib so that distributions can 41# install it for compatibility with binaries linked against the old 42# libgcc_ext.10.x.dylib stubs. 43 44# For systems after macOS 10.7 we can forward the correct unwinder symbols 45# from libSystem. 46 47# For older systems we have to forward an entire library (since they cannot 48# selectively forward symbols, which means that we cannot forward the unwinder 49# in /usr/lib/libgcc_s.1.dylib). We also cannot forward the entire library 50# since that creates a self-referencing loop when DYLD_LIBRARY_PATH is used. 51# To provide the unwinder symbols in this case, we build the unwinder into a 52# separate shared lib (libgcc_ehs) and forward that. 53 54# These targets are local to this make fragment, which means that they do not 55# get the substitutions seen in SHLIB_LINK. 56 57ifneq ($(LIBEHSOBJS),) 58 59EHS_INSTNAME = libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) 60 61# multilib build for a shared EH lib. 62 63libgcc_ehs$(SHLIB_EXT): $(LIBEHSOBJS) $(extra-parts) 64 mkdir -p $(MULTIDIR) 65 $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \ 66 -install_name $(SHLIB_INSTALL_DIR)/$(EHS_INSTNAME) \ 67 -o $(MULTIDIR)/libgcc_ehs$(SHLIB_EXT) $(SHLIB_VERSTRING) \ 68 $(LIBEHSOBJS) $(SHLIB_LC) 69 70all: libgcc_ehs$(SHLIB_EXT) 71 72LGCC_FILES += libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) 73 74endif 75endif 76 77INSTALL_FILES=$(LGCC_FILES) 78 79ifeq ($(BUILD_LIBGCCS1),YES) 80# Provide libgcc_s.1 for backwards compatibility. 81INSTALL_FILES += libgcc_s.1.dylib 82endif 83 84# For the toplevel multilib, build FAT dylibs including all the multilibs. 85ifeq ($(MULTIBUILDTOP),) 86 87ifeq ($(enable_shared),yes) 88all: $(INSTALL_FILES) 89install-leaf: install-darwin-libgcc-stubs 90endif 91 92libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT): all-multi libgcc_s$(SHLIB_EXT) 93 MLIBS=`$(CC) --print-multi-lib | sed -e 's/;.*$$//'` ; \ 94 for mlib in $$MLIBS ; do \ 95 cp ../$${mlib}/libgcc/$${mlib}/libgcc_s$(SHLIB_EXT) \ 96 ./libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ 97 done 98 $(LIPO) -output libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) \ 99 -create libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* 100 rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* 101 102ifeq ($(BUILD_LIBGCCS1),YES) 103ifneq ($(LIBEHSOBJS),) 104 105libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT): all-multi libgcc_ehs$(SHLIB_EXT) 106 MLIBS=`$(CC) --print-multi-lib | sed -e 's/;.*$$//'` ; \ 107 for mlib in $$MLIBS ; do \ 108 cp ../$${mlib}/libgcc/$${mlib}/libgcc_ehs$(SHLIB_EXT) \ 109 ./libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ 110 done 111 $(LIPO) -output libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) \ 112 -create libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* 113 rm libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* 114 115 116libgcc_s.1.dylib: all-multi libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) \ 117 libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) 118 MLIBS=`$(CC) --print-multi-lib | sed -e 's/;.*$$//'` ; \ 119 for mlib in $$MLIBS ; do \ 120 cp ../$${mlib}/libgcc/$${mlib}/libgcc_s$(SHLIB_EXT) \ 121 ./libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ 122 cp ../$${mlib}/libgcc/$${mlib}/libgcc_ehs$(SHLIB_EXT) \ 123 ./libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ 124 arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \ 125 $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \ 126 -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \ 127 -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ 128 -Wl,-reexport_library,libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ 129 -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \ 130 -compatibility_version 1 -current_version 1 ; \ 131 done 132 $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T* 133 rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* 134 rm libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* 135 136else 137 138libgcc_s.1.dylib: all-multi libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) 139 MLIBS=`$(CC) --print-multi-lib | sed -e 's/;.*$$//'` ; \ 140 for mlib in $$MLIBS ; do \ 141 cp ../$${mlib}/libgcc/$${mlib}/libgcc_s$(SHLIB_EXT) \ 142 ./libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} || exit 1 ; \ 143 arch=`$(LIPO) -info libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} | sed -e 's/.*:\ //'` ; \ 144 $(CC) -arch $${arch} -nodefaultlibs -dynamiclib \ 145 -o libgcc_s.1$(SHLIB_EXT)_T_$${mlib} \ 146 -Wl,-reexport_library,libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T_$${mlib} \ 147 -lSystem \ 148 -Wl,-reexported_symbols_list,$(srcdir)/config/darwin-unwind.ver \ 149 -install_name $(SHLIB_INSTALL_DIR)/libgcc_s.1.dylib \ 150 -compatibility_version 1 -current_version 1 ; \ 151 done 152 $(LIPO) -output libgcc_s.1$(SHLIB_EXT) -create libgcc_s.1$(SHLIB_EXT)_T* 153 rm libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT)_T* 154 155endif 156endif 157 158# Install the shared libraries. 159 160install-darwin-libgcc-stubs : 161 $(mkinstalldirs) $(DESTDIR)$(slibdir) 162 if test x$(slibdir) = x; then \ 163 for d in $(LGCC_FILES) ; do \ 164 $(INSTALL_DATA) $$d $(DESTDIR)$(slibdir)/$$d || exit 1 ; \ 165 done; \ 166 else \ 167 for d in $(INSTALL_FILES) ; do \ 168 $(INSTALL_DATA) $$d $(DESTDIR)$(slibdir)/$$d || exit 1 ; \ 169 done; \ 170 fi 171 172else 173 174# Do not install shared libraries for multilibs. Unless we are putting them 175# in the gcc directory during a build, for compatibility with the pre-top- 176# level layout. In that case we provide symlinks to the FAT lib from the 177# multilib sub-directories. 178 179ifeq ($(enable_shared),yes) 180all: install-darwin-libgcc-links 181endif 182 183install-darwin-libgcc-links: 184 $(mkinstalldirs) $(gcc_objdir)$(MULTISUBDIR) 185 for file in $(INSTALL_FILES); do \ 186 rm -f $(gcc_objdir)$(MULTISUBDIR)/$$file; \ 187 $(LN_S) ../$$file $(gcc_objdir)$(MULTISUBDIR)/; \ 188 done 189 190endif 191