1 # Build a shared libgcc library with the darwin linker. 2 3 SHLIB_SOVERSION = 1.1 4 SHLIB_SO_MINVERSION = 1 5 SHLIB_VERSTRING = -compatibility_version $(SHLIB_SO_MINVERSION) \ 6 -current_version $(SHLIB_SOVERSION) 7 SHLIB_EXT = .dylib 8 SHLIB_LC = -lSystem 9 SHLIB_INSTALL_DIR = $(slibdir) 10 11 SHLIB_MKMAP = $(srcdir)/mkmap-flat.awk 12 SHLIB_MKMAP_OPTS = -v leading_underscore=1 13 14 # Shorthand expressions for the LINK below, these are substituted in the 15 # link expression. 16 SHLIB_INSTALL_NAME = @shlib_base_name@.$(SHLIB_SOVERSION)$(SHLIB_EXT) 17 SHLIB_MAP = @shlib_map_file@ 18 SHLIB_DIR = @multilib_dir@ 19 SHLIB_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 26 SHLIB_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 34 SHLIB_INSTALL = 35 36 LGCC_FILES = libgcc_s.$(SHLIB_SOVERSION)$(SHLIB_EXT) 37 38 ifeq ($(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 57 ifneq ($(LIBEHSOBJS),) 58 59 EHS_INSTNAME = libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) 60 61 # multilib build for a shared EH lib. 62 63 libgcc_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 70 all: libgcc_ehs$(SHLIB_EXT) 71 72 LGCC_FILES += libgcc_ehs.$(SHLIB_SOVERSION)$(SHLIB_EXT) 73 74 endif 75 endif 76 77 INSTALL_FILES=$(LGCC_FILES) 78 79 ifeq ($(BUILD_LIBGCCS1),YES) 80 # Provide libgcc_s.1 for backwards compatibility. 81 INSTALL_FILES += libgcc_s.1.dylib 82 endif 83 84 # For the toplevel multilib, build FAT dylibs including all the multilibs. 85 ifeq ($(MULTIBUILDTOP),) 86 87 ifeq ($(enable_shared),yes) 88 all: $(INSTALL_FILES) 89 install-leaf: install-darwin-libgcc-stubs 90 endif 91 92 libgcc_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 102 ifeq ($(BUILD_LIBGCCS1),YES) 103 ifneq ($(LIBEHSOBJS),) 104 105 libgcc_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 116 libgcc_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 136 else 137 138 libgcc_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 155 endif 156 endif 157 158 # Install the shared libraries. 159 160 install-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 172 else 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 179 ifeq ($(enable_shared),yes) 180 all: install-darwin-libgcc-links 181 endif 182 183 install-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 190 endif 191