1# These are the functions which clang needs when it is targeting a previous 2# version of the OS. The issue is that the backend may use functions which were 3# not present in the libgcc that shipped on the platform. In such cases, we link 4# with a version of the library which contains private_extern definitions of all 5# the extra functions which might be referenced. 6 7Description := Static runtime libraries for embedded clang/Darwin 8 9# A function that ensures we don't try to build for architectures that we 10# don't have working toolchains for. 11CheckArches = \ 12 $(shell \ 13 result=""; \ 14 for arch in $(1); do \ 15 if $(CC) -arch $$arch -c \ 16 -integrated-as \ 17 $(ProjSrcRoot)/make/platform/clang_macho_embedded_test_input.c \ 18 -o /dev/null > /dev/null 2> /dev/null; then \ 19 result="$$result$$arch "; \ 20 else \ 21 printf 1>&2 \ 22 "warning: clang_macho_embedded.mk: dropping arch '$$arch' from lib '$(2)'\n"; \ 23 fi; \ 24 done; \ 25 echo $$result) 26 27XCRun = \ 28 $(shell \ 29 result=`xcrun -find $(1) 2> /dev/null`; \ 30 if [ "$$?" != "0" ]; then result=$(1); fi; \ 31 echo $$result) 32 33### 34 35CC := $(call XCRun,clang) 36AR := $(call XCRun,ar) 37RANLIB := $(call XCRun,ranlib) 38STRIP := $(call XCRun,strip) 39LIPO := $(call XCRun,lipo) 40DSYMUTIL := $(call XCRun,dsymutil) 41 42Configs := 43UniversalArchs := 44 45# Soft-float version of the runtime. No floating-point instructions will be used 46# and the ABI (out of necessity) passes floating values in normal registers: 47# non-VFP variant of the AAPCS. 48UniversalArchs.soft_static := $(call CheckArches,armv6m armv7m armv7em armv7,soft_static) 49Configs += $(if $(UniversalArchs.soft_static),soft_static) 50 51# Hard-float version of the runtime. On ARM VFP instructions and registers are 52# allowed, and floating point values get passed in them. VFP variant of the 53# AAPCS. 54UniversalArchs.hard_static := $(call CheckArches,armv7em armv7 i386 x86_64,hard_static) 55Configs += $(if $(UniversalArchs.hard_static),hard_static) 56 57UniversalArchs.soft_pic := $(call CheckArches,armv6m armv7m armv7em armv7,soft_pic) 58Configs += $(if $(UniversalArchs.soft_pic),soft_pic) 59 60UniversalArchs.hard_pic := $(call CheckArches,armv7em armv7 i386 x86_64,hard_pic) 61Configs += $(if $(UniversalArchs.hard_pic),hard_pic) 62 63CFLAGS := -Wall -Werror -Oz -fomit-frame-pointer -ffreestanding 64 65PIC_CFLAGS := -fPIC 66STATIC_CFLAGS := -static 67 68CFLAGS_SOFT := -mfloat-abi=soft 69CFLAGS_HARD := -mfloat-abi=hard 70 71CFLAGS_ARMV7 := -target thumbv7-apple-darwin-eabi 72CFLAGS_I386 := -march=pentium 73 74CFLAGS.soft_static := $(CFLAGS) $(STATIC_CFLAGS) $(CFLAGS_SOFT) 75CFLAGS.hard_static := $(CFLAGS) $(STATIC_CFLAGS) $(CFLAGS_HARD) 76CFLAGS.soft_pic := $(CFLAGS) $(PIC_CFLAGS) $(CFLAGS_SOFT) 77CFLAGS.hard_pic := $(CFLAGS) $(PIC_CFLAGS) $(CFLAGS_HARD) 78 79CFLAGS.soft_static.armv7 := $(CFLAGS.soft_static) $(CFLAGS_ARMV7) 80CFLAGS.hard_static.armv7 := $(CFLAGS.hard_static) $(CFLAGS_ARMV7) 81CFLAGS.soft_pic.armv7 := $(CFLAGS.soft_pic) $(CFLAGS_ARMV7) 82CFLAGS.hard_pic.armv7 := $(CFLAGS.hard_pic) $(CFLAGS_ARMV7) 83 84# x86 platforms ignore -mfloat-abi options and complain about doing so. Despite 85# this they're hard-float. 86CFLAGS.hard_static.i386 := $(CFLAGS) $(STATIC_CFLAGS) $(CFLAGS_I386) 87CFLAGS.hard_pic.i386 := $(CFLAGS) $(PIC_CFLAGS) $(CFLAGS_I386) 88CFLAGS.hard_static.x86_64 := $(CFLAGS) $(STATIC_CFLAGS) 89CFLAGS.hard_pic.x86_64 := $(CFLAGS) $(PIC_CFLAGS) 90 91# Functions not wanted: 92# + eprintf is obsolete anyway 93# + *vfp: designed for Thumb1 CPUs with VFPv2 94 95COMMON_FUNCTIONS := \ 96 absvdi2 \ 97 absvsi2 \ 98 addvdi3 \ 99 addvsi3 \ 100 ashldi3 \ 101 ashrdi3 \ 102 bswapdi2 \ 103 bswapsi2 \ 104 clzdi2 \ 105 clzsi2 \ 106 cmpdi2 \ 107 ctzdi2 \ 108 ctzsi2 \ 109 divdc3 \ 110 divdi3 \ 111 divsc3 \ 112 divmodsi4 \ 113 udivmodsi4 \ 114 do_global_dtors \ 115 ffsdi2 \ 116 fixdfdi \ 117 fixsfdi \ 118 fixunsdfdi \ 119 fixunsdfsi \ 120 fixunssfdi \ 121 fixunssfsi \ 122 floatdidf \ 123 floatdisf \ 124 floatundidf \ 125 floatundisf \ 126 gcc_bcmp \ 127 lshrdi3 \ 128 moddi3 \ 129 muldc3 \ 130 muldi3 \ 131 mulsc3 \ 132 mulvdi3 \ 133 mulvsi3 \ 134 negdi2 \ 135 negvdi2 \ 136 negvsi2 \ 137 paritydi2 \ 138 paritysi2 \ 139 popcountdi2 \ 140 popcountsi2 \ 141 powidf2 \ 142 powisf2 \ 143 subvdi3 \ 144 subvsi3 \ 145 ucmpdi2 \ 146 udiv_w_sdiv \ 147 udivdi3 \ 148 udivmoddi4 \ 149 umoddi3 \ 150 adddf3 \ 151 addsf3 \ 152 cmpdf2 \ 153 cmpsf2 \ 154 div0 \ 155 divdf3 \ 156 divsf3 \ 157 divsi3 \ 158 extendsfdf2 \ 159 extendhfsf2 \ 160 ffssi2 \ 161 fixdfsi \ 162 fixsfsi \ 163 floatsidf \ 164 floatsisf \ 165 floatunsidf \ 166 floatunsisf \ 167 comparedf2 \ 168 comparesf2 \ 169 modsi3 \ 170 muldf3 \ 171 mulsf3 \ 172 negdf2 \ 173 negsf2 \ 174 subdf3 \ 175 subsf3 \ 176 truncdfhf2 \ 177 truncdfsf2 \ 178 truncsfhf2 \ 179 udivsi3 \ 180 umodsi3 \ 181 unorddf2 \ 182 unordsf2 \ 183 atomic_flag_clear \ 184 atomic_flag_clear_explicit \ 185 atomic_flag_test_and_set \ 186 atomic_flag_test_and_set_explicit \ 187 atomic_signal_fence \ 188 atomic_thread_fence 189 190ARM_FUNCTIONS := \ 191 aeabi_cdcmpeq \ 192 aeabi_cdrcmple \ 193 aeabi_cfcmpeq \ 194 aeabi_cfrcmple \ 195 aeabi_dcmpeq \ 196 aeabi_dcmpge \ 197 aeabi_dcmpgt \ 198 aeabi_dcmple \ 199 aeabi_dcmplt \ 200 aeabi_drsub \ 201 aeabi_fcmpeq \ 202 aeabi_fcmpge \ 203 aeabi_fcmpgt \ 204 aeabi_fcmple \ 205 aeabi_fcmplt \ 206 aeabi_frsub \ 207 aeabi_idivmod \ 208 aeabi_uidivmod \ 209 210# ARM Assembly implementation which requires Thumb2 (i.e. won't work on v6M). 211THUMB2_FUNCTIONS := \ 212 switch16 \ 213 switch32 \ 214 switch8 \ 215 switchu8 \ 216 sync_fetch_and_add_4 \ 217 sync_fetch_and_sub_4 \ 218 sync_fetch_and_and_4 \ 219 sync_fetch_and_or_4 \ 220 sync_fetch_and_xor_4 \ 221 sync_fetch_and_nand_4 \ 222 sync_fetch_and_max_4 \ 223 sync_fetch_and_umax_4 \ 224 sync_fetch_and_min_4 \ 225 sync_fetch_and_umin_4 \ 226 sync_fetch_and_add_8 \ 227 sync_fetch_and_sub_8 \ 228 sync_fetch_and_and_8 \ 229 sync_fetch_and_or_8 \ 230 sync_fetch_and_xor_8 \ 231 sync_fetch_and_nand_8 \ 232 sync_fetch_and_max_8 \ 233 sync_fetch_and_umax_8 \ 234 sync_fetch_and_min_8 \ 235 sync_fetch_and_umin_8 236 237I386_FUNCTIONS := \ 238 i686.get_pc_thunk.eax \ 239 i686.get_pc_thunk.ebp \ 240 i686.get_pc_thunk.ebx \ 241 i686.get_pc_thunk.ecx \ 242 i686.get_pc_thunk.edi \ 243 i686.get_pc_thunk.edx \ 244 i686.get_pc_thunk.esi 245 246# FIXME: Currently, compiler-rt is missing implementations for a number of the 247# functions. Filter them out for now. 248MISSING_FUNCTIONS := \ 249 cmpdf2 cmpsf2 div0 \ 250 ffssi2 \ 251 udiv_w_sdiv unorddf2 unordsf2 bswapdi2 \ 252 bswapsi2 \ 253 gcc_bcmp \ 254 do_global_dtors \ 255 i686.get_pc_thunk.eax i686.get_pc_thunk.ebp i686.get_pc_thunk.ebx \ 256 i686.get_pc_thunk.ecx i686.get_pc_thunk.edi i686.get_pc_thunk.edx \ 257 i686.get_pc_thunk.esi \ 258 aeabi_cdcmpeq aeabi_cdrcmple aeabi_cfcmpeq aeabi_cfrcmple aeabi_dcmpeq \ 259 aeabi_dcmpge aeabi_dcmpgt aeabi_dcmple aeabi_dcmplt aeabi_drsub \ 260 aeabi_fcmpeq \ aeabi_fcmpge aeabi_fcmpgt aeabi_fcmple aeabi_fcmplt \ 261 aeabi_frsub aeabi_idivmod aeabi_uidivmod 262 263FUNCTIONS_ARMV6M := $(COMMON_FUNCTIONS) $(ARM_FUNCTIONS) 264FUNCTIONS_ARM_ALL := $(COMMON_FUNCTIONS) $(ARM_FUNCTIONS) $(THUMB2_FUNCTIONS) 265FUNCTIONS_I386 := $(COMMON_FUNCTIONS) $(I386_FUNCTIONS) 266FUNCTIONS_X86_64 := $(COMMON_FUNCTIONS) 267 268FUNCTIONS_ARMV6M := \ 269 $(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_ARMV6M)) 270FUNCTIONS_ARM_ALL := \ 271 $(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_ARM_ALL)) 272FUNCTIONS_I386 := \ 273 $(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_I386)) 274FUNCTIONS_X86_64 := \ 275 $(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_X86_64)) 276 277FUNCTIONS.soft_static.armv6m := $(FUNCTIONS_ARMV6M) 278FUNCTIONS.soft_pic.armv6m := $(FUNCTIONS_ARMV6M) 279 280FUNCTIONS.soft_static.armv7m := $(FUNCTIONS_ARM_ALL) 281FUNCTIONS.soft_pic.armv7m := $(FUNCTIONS_ARM_ALL) 282 283FUNCTIONS.soft_static.armv7em := $(FUNCTIONS_ARM_ALL) 284FUNCTIONS.hard_static.armv7em := $(FUNCTIONS_ARM_ALL) 285FUNCTIONS.soft_pic.armv7em := $(FUNCTIONS_ARM_ALL) 286FUNCTIONS.hard_pic.armv7em := $(FUNCTIONS_ARM_ALL) 287 288FUNCTIONS.soft_static.armv7 := $(FUNCTIONS_ARM_ALL) 289FUNCTIONS.hard_static.armv7 := $(FUNCTIONS_ARM_ALL) 290FUNCTIONS.soft_pic.armv7 := $(FUNCTIONS_ARM_ALL) 291FUNCTIONS.hard_pic.armv7 := $(FUNCTIONS_ARM_ALL) 292 293FUNCTIONS.hard_static.i386 := $(FUNCTIONS_I386) 294FUNCTIONS.hard_pic.i386 := $(FUNCTIONS_I386) 295 296FUNCTIONS.hard_static.x86_64 := $(FUNCTIONS_X86_64) 297FUNCTIONS.hard_pic.x86_64 := $(FUNCTIONS_X86_64) 298