Home | History | Annotate | Download | only in platform
      1 # These are the functions which clang needs when it is targetting 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 
      7 Description := Static runtime libraries for 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.
     11 CheckArches = \
     12   $(shell \
     13     result=""; \
     14     for arch in $(1); do \
     15       if $(CC) -arch $$arch -c \
     16 	  -integrated-as \
     17 	  $(ProjSrcRoot)/make/platform/clang_darwin_test_input.c \
     18 	  -isysroot $(ProjSrcRoot)/SDKs/darwin \
     19 	  -o /dev/null > /dev/null 2> /dev/null; then \
     20         result="$$result$$arch "; \
     21       else \
     22 	printf 1>&2 \
     23 	  "warning: clang_darwin.mk: dropping arch '$$arch' from lib '$(2)'\n"; \
     24       fi; \
     25     done; \
     26     echo $$result)
     27 
     28 ###
     29 
     30 CC := clang
     31 
     32 Configs :=
     33 UniversalArchs :=
     34 
     35 # Configuration solely for providing access to an eprintf symbol, which may
     36 # still be referenced from Darwin system headers. This symbol is only ever
     37 # needed on i386.
     38 Configs += eprintf
     39 UniversalArchs.eprintf := $(call CheckArches,i386,eprintf)
     40 
     41 # Configuration for targetting 10.4. We need a few functions missing from
     42 # libgcc_s.10.4.dylib. We only build x86 slices since clang doesn't really
     43 # support targetting PowerPC.
     44 Configs += 10.4
     45 UniversalArchs.10.4 := $(call CheckArches,i386 x86_64,10.4)
     46 
     47 # Configuration for targetting iOS for a couple of functions that didn't
     48 # make it into libSystem.
     49 Configs += ios
     50 UniversalArchs.ios := $(call CheckArches,i386 x86_64 armv7,ios)
     51 
     52 # Configuration for targetting OSX. These functions may not be in libSystem
     53 # so we should provide our own.
     54 Configs += osx
     55 UniversalArchs.osx := $(call CheckArches,i386 x86_64,osx)
     56 
     57 # Configuration for use with kernel/kexts.
     58 Configs += cc_kext
     59 UniversalArchs.cc_kext := $(call CheckArches,armv7 i386 x86_64,cc_kext)
     60 
     61 # Configuration for use with kernel/kexts for iOS 5.0 and earlier (which used 
     62 # a different code generation strategy).
     63 Configs += cc_kext_ios5
     64 UniversalArchs.cc_kext_ios5 := $(call CheckArches,x86_64 armv7,cc_kext_ios5)
     65 
     66 # Configurations which define the profiling support functions.
     67 Configs += profile_osx
     68 UniversalArchs.profile_osx := $(call CheckArches,i386 x86_64,profile_osx)
     69 Configs += profile_ios
     70 UniversalArchs.profile_ios := $(call CheckArches,i386 x86_64 armv7,profile_ios)
     71 
     72 # Configurations which define the ASAN support functions.
     73 Configs += asan_osx_dynamic
     74 UniversalArchs.asan_osx_dynamic := $(call CheckArches,i386 x86_64,asan_osx_dynamic)
     75 
     76 Configs += ubsan_osx
     77 UniversalArchs.ubsan_osx := $(call CheckArches,i386 x86_64,ubsan_osx)
     78 
     79 # Darwin 10.6 has a bug in cctools that makes it unable to use ranlib on our ARM
     80 # object files. If we are on that platform, strip out all ARM archs. We still
     81 # build the libraries themselves so that Clang can find them where it expects
     82 # them, even though they might not have an expected slice.
     83 ifneq ($(shell test -x /usr/bin/sw_vers && sw_vers -productVersion | grep 10.6),)
     84 UniversalArchs.ios := $(filter-out armv7, $(UniversalArchs.ios))
     85 UniversalArchs.cc_kext := $(filter-out armv7, $(UniversalArchs.cc_kext))
     86 UniversalArchs.cc_kext_ios5 := $(filter-out armv7, $(UniversalArchs.cc_kext_ios5))
     87 UniversalArchs.profile_ios := $(filter-out armv7, $(UniversalArchs.profile_ios))
     88 endif
     89 
     90 # If RC_SUPPORTED_ARCHS is defined, treat it as a list of the architectures we
     91 # are intended to support and limit what we try to build to that.
     92 #
     93 # We make sure to remove empty configs if we end up dropping all the requested
     94 # archs for a particular config.
     95 ifneq ($(RC_SUPPORTED_ARCHS),)
     96 $(foreach config,$(Configs),\
     97   $(call Set,UniversalArchs.$(config),\
     98 	$(filter $(RC_SUPPORTED_ARCHS),$(UniversalArchs.$(config))))\
     99   $(if $(UniversalArchs.$(config)),,\
    100 	$(call Set,Configs,$(filter-out $(config),$(Configs)))))
    101 endif
    102 
    103 ###
    104 
    105 # Forcibly strip off any -arch, as that totally breaks our universal support.
    106 override CC := $(subst -arch ,-arch_,$(CC))
    107 override CC := $(patsubst -arch_%,,$(CC))
    108 
    109 CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer
    110 
    111 # Always set deployment target arguments for every build, these libraries should
    112 # never depend on the environmental overrides. We simply set them to minimum
    113 # supported deployment target -- nothing in the compiler-rt libraries should
    114 # actually depend on the deployment target.
    115 OSX_DEPLOYMENT_ARGS := -mmacosx-version-min=10.4
    116 IOS_DEPLOYMENT_ARGS := -mios-version-min=1.0
    117 IOS6_DEPLOYMENT_ARGS := -mios-version-min=6.0
    118 IOSSIM_DEPLOYMENT_ARGS := -mios-simulator-version-min=1.0
    119 
    120 # Use our stub SDK as the sysroot to support more portable building.
    121 OSX_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
    122 IOS_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
    123 IOS6_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
    124 IOSSIM_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
    125 
    126 CFLAGS.eprintf		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
    127 CFLAGS.10.4		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
    128 # FIXME: We can't build ASAN with our stub SDK yet.
    129 CFLAGS.asan_osx_dynamic := \
    130 	$(CFLAGS) -mmacosx-version-min=10.6 -fno-builtin \
    131 	-gline-tables-only \
    132 	-DMAC_INTERPOSE_FUNCTIONS=1 \
    133   -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
    134 
    135 CFLAGS.ubsan_osx	:= $(CFLAGS) -mmacosx-version-min=10.6 -fno-builtin
    136 
    137 CFLAGS.ios.i386		:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
    138 CFLAGS.ios.x86_64	:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
    139 CFLAGS.ios.armv7	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    140 CFLAGS.ios.armv7f	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    141 CFLAGS.ios.armv7k	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    142 CFLAGS.ios.armv7s	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    143 CFLAGS.osx.i386		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
    144 CFLAGS.osx.x86_64	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
    145 CFLAGS.cc_kext.i386	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
    146 CFLAGS.cc_kext.x86_64	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
    147 CFLAGS.cc_kext.armv7	:= $(CFLAGS) $(IOS6_DEPLOYMENT_ARGS)
    148 CFLAGS.cc_kext.armv7f	:= $(CFLAGS) $(IOS6_DEPLOYMENT_ARGS)
    149 CFLAGS.cc_kext.armv7k	:= $(CFLAGS) $(IOS6_DEPLOYMENT_ARGS)
    150 CFLAGS.cc_kext.armv7s	:= $(CFLAGS) $(IOS6_DEPLOYMENT_ARGS)
    151 CFLAGS.cc_kext_ios5.armv7  := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    152 CFLAGS.cc_kext_ios5.armv7f := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    153 CFLAGS.cc_kext_ios5.armv7k := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    154 CFLAGS.cc_kext_ios5.armv7s := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    155 CFLAGS.profile_osx.i386   := $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
    156 CFLAGS.profile_osx.x86_64 := $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
    157 CFLAGS.profile_ios.i386   := $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
    158 CFLAGS.profile_ios.x86_64 := $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
    159 CFLAGS.profile_ios.armv7  := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    160 CFLAGS.profile_ios.armv7f := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    161 CFLAGS.profile_ios.armv7k := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    162 CFLAGS.profile_ios.armv7s := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
    163 
    164 # Configure the asan_osx_dynamic library to be built shared.
    165 SHARED_LIBRARY.asan_osx_dynamic := 1
    166 LDFLAGS.asan_osx_dynamic := -framework Foundation -lstdc++ -undefined dynamic_lookup
    167 
    168 FUNCTIONS.eprintf := eprintf
    169 FUNCTIONS.10.4 := eprintf floatundidf floatundisf floatundixf
    170 
    171 FUNCTIONS.ios	    := divmodsi4 udivmodsi4 mulosi4 mulodi4 muloti4
    172 # On x86, the divmod functions reference divsi.
    173 FUNCTIONS.ios.i386   := $(FUNCTIONS.ios) \
    174                         divsi3 udivsi3
    175 FUNCTIONS.ios.x86_64 := $(FUNCTIONS.ios) \
    176                         divsi3 udivsi3
    177 
    178 FUNCTIONS.osx	:= mulosi4 mulodi4 muloti4
    179 
    180 FUNCTIONS.profile_osx := GCDAProfiling
    181 FUNCTIONS.profile_ios := GCDAProfiling
    182 
    183 FUNCTIONS.asan_osx_dynamic := $(AsanFunctions) $(InterceptionFunctions) \
    184                               $(SanitizerCommonFunctions) \
    185 	                      $(AsanDynamicFunctions)
    186 
    187 FUNCTIONS.ubsan_osx := $(UbsanFunctions) $(UbsanCXXFunctions) \
    188                        $(SanitizerCommonFunctions)
    189 
    190 CCKEXT_COMMON_FUNCTIONS := \
    191 	absvdi2 \
    192 	absvsi2 \
    193 	addvdi3 \
    194 	addvsi3 \
    195 	ashldi3 \
    196 	ashrdi3 \
    197 	bswapdi2 \
    198 	bswapsi2 \
    199 	clzdi2 \
    200 	clzsi2 \
    201 	cmpdi2 \
    202 	ctzdi2 \
    203 	ctzsi2 \
    204 	divdc3 \
    205 	divdi3 \
    206 	divsc3 \
    207 	divmodsi4 \
    208 	udivmodsi4 \
    209 	do_global_dtors \
    210 	eprintf \
    211 	ffsdi2 \
    212 	fixdfdi \
    213 	fixsfdi \
    214 	fixunsdfdi \
    215 	fixunsdfsi \
    216 	fixunssfdi \
    217 	fixunssfsi \
    218 	floatdidf \
    219 	floatdisf \
    220 	floatundidf \
    221 	floatundisf \
    222 	gcc_bcmp \
    223 	lshrdi3 \
    224 	moddi3 \
    225 	muldc3 \
    226 	muldi3 \
    227 	mulsc3 \
    228 	mulvdi3 \
    229 	mulvsi3 \
    230 	negdi2 \
    231 	negvdi2 \
    232 	negvsi2 \
    233 	paritydi2 \
    234 	paritysi2 \
    235 	popcountdi2 \
    236 	popcountsi2 \
    237 	powidf2 \
    238 	powisf2 \
    239 	subvdi3 \
    240 	subvsi3 \
    241 	ucmpdi2 \
    242 	udiv_w_sdiv \
    243 	udivdi3 \
    244 	udivmoddi4 \
    245 	umoddi3
    246 
    247 CCKEXT_ARM_FUNCTIONS := $(CCKEXT_COMMON_FUNCTIONS) \
    248 	adddf3 \
    249 	addsf3 \
    250 	aeabi_cdcmpeq \
    251 	aeabi_cdrcmple \
    252 	aeabi_cfcmpeq \
    253 	aeabi_cfrcmple \
    254 	aeabi_dcmpeq \
    255 	aeabi_dcmpge \
    256 	aeabi_dcmpgt \
    257 	aeabi_dcmple \
    258 	aeabi_dcmplt \
    259 	aeabi_drsub \
    260 	aeabi_fcmpeq \
    261 	aeabi_fcmpge \
    262 	aeabi_fcmpgt \
    263 	aeabi_fcmple \
    264 	aeabi_fcmplt \
    265 	aeabi_frsub \
    266 	aeabi_idivmod \
    267 	aeabi_uidivmod \
    268 	cmpdf2 \
    269 	cmpsf2 \
    270 	div0 \
    271 	divdf3 \
    272 	divsf3 \
    273 	divsi3 \
    274 	extendsfdf2 \
    275 	ffssi2 \
    276 	fixdfsi \
    277 	fixsfsi \
    278 	floatsidf \
    279 	floatsisf \
    280 	floatunsidf \
    281 	floatunsisf \
    282 	comparedf2 \
    283 	comparesf2 \
    284 	modsi3 \
    285 	muldf3 \
    286 	mulsf3 \
    287 	negdf2 \
    288 	negsf2 \
    289 	subdf3 \
    290 	subsf3 \
    291 	switch16 \
    292 	switch32 \
    293 	switch8 \
    294 	switchu8 \
    295 	truncdfsf2 \
    296 	udivsi3 \
    297 	umodsi3 \
    298 	unorddf2 \
    299 	unordsf2
    300 
    301 CCKEXT_ARMVFP_FUNCTIONS := $(CCKEXT_ARM_FUNCTIONS) \
    302 	adddf3vfp \
    303 	addsf3vfp \
    304 	divdf3vfp \
    305 	divsf3vfp \
    306 	eqdf2vfp \
    307 	eqsf2vfp \
    308 	extendsfdf2vfp \
    309 	fixdfsivfp \
    310 	fixsfsivfp \
    311 	fixunsdfsivfp \
    312 	fixunssfsivfp \
    313 	floatsidfvfp \
    314 	floatsisfvfp \
    315 	floatunssidfvfp \
    316 	floatunssisfvfp \
    317 	gedf2vfp \
    318 	gesf2vfp \
    319 	gtdf2vfp \
    320 	gtsf2vfp \
    321 	ledf2vfp \
    322 	lesf2vfp \
    323 	ltdf2vfp \
    324 	ltsf2vfp \
    325 	muldf3vfp \
    326 	mulsf3vfp \
    327 	nedf2vfp \
    328 	nesf2vfp \
    329 	subdf3vfp \
    330 	subsf3vfp \
    331 	truncdfsf2vfp \
    332 	unorddf2vfp \
    333 	unordsf2vfp
    334 
    335 FUNCTIONS.cc_kext.armv7 := $(CCKEXT_ARMVFP_FUNCTIONS)
    336 FUNCTIONS.cc_kext.armv7f := $(CCKEXT_ARMVFP_FUNCTIONS)
    337 FUNCTIONS.cc_kext.armv7k := $(CCKEXT_ARMVFP_FUNCTIONS)
    338 FUNCTIONS.cc_kext.armv7s := $(CCKEXT_ARMVFP_FUNCTIONS)
    339 FUNCTIONS.cc_kext_ios5.armv7 := $(CCKEXT_ARMVFP_FUNCTIONS)
    340 FUNCTIONS.cc_kext_ios5.armv7f := $(CCKEXT_ARMVFP_FUNCTIONS)
    341 FUNCTIONS.cc_kext_ios5.armv7k := $(CCKEXT_ARMVFP_FUNCTIONS)
    342 FUNCTIONS.cc_kext_ios5.armv7s := $(CCKEXT_ARMVFP_FUNCTIONS)
    343 
    344 CCKEXT_X86_FUNCTIONS := $(CCKEXT_COMMON_FUNCTIONS) \
    345 	divxc3 \
    346 	fixunsxfdi \
    347 	fixunsxfsi \
    348 	fixxfdi \
    349 	floatdixf \
    350 	floatundixf \
    351 	mulxc3 \
    352 	powixf2
    353 
    354 FUNCTIONS.cc_kext.i386 := $(CCKEXT_X86_FUNCTIONS) \
    355 	ffssi2 \
    356 	i686.get_pc_thunk.eax \
    357 	i686.get_pc_thunk.ebp \
    358 	i686.get_pc_thunk.ebx \
    359 	i686.get_pc_thunk.ecx \
    360 	i686.get_pc_thunk.edi \
    361 	i686.get_pc_thunk.edx \
    362 	i686.get_pc_thunk.esi
    363 
    364 FUNCTIONS.cc_kext.x86_64 := $(CCKEXT_X86_FUNCTIONS) \
    365 	absvti2 \
    366 	addvti3 \
    367 	ashlti3 \
    368 	ashrti3 \
    369 	clzti2 \
    370 	cmpti2 \
    371 	ctzti2 \
    372 	divti3 \
    373 	ffsti2 \
    374 	fixdfti \
    375 	fixsfti \
    376 	fixunsdfti \
    377 	fixunssfti \
    378 	fixunsxfti \
    379 	fixxfti \
    380 	floattidf \
    381 	floattisf \
    382 	floattixf \
    383 	floatuntidf \
    384 	floatuntisf \
    385 	floatuntixf \
    386 	lshrti3 \
    387 	modti3 \
    388 	multi3 \
    389 	mulvti3 \
    390 	negti2 \
    391 	negvti2 \
    392 	parityti2 \
    393 	popcountti2 \
    394 	subvti3 \
    395 	ucmpti2 \
    396 	udivmodti4 \
    397 	udivti3 \
    398 	umodti3
    399 
    400 # FIXME: Currently, compiler-rt is missing implementations for a number of the
    401 # functions that need to go into libcc_kext.a. Filter them out for now.
    402 CCKEXT_MISSING_FUNCTIONS := \
    403 	cmpdf2 cmpsf2 div0 \
    404 	ffssi2 \
    405 	udiv_w_sdiv unorddf2 unordsf2 bswapdi2 \
    406 	bswapsi2 \
    407 	gcc_bcmp \
    408 	do_global_dtors \
    409 	i686.get_pc_thunk.eax i686.get_pc_thunk.ebp i686.get_pc_thunk.ebx \
    410 	i686.get_pc_thunk.ecx i686.get_pc_thunk.edi i686.get_pc_thunk.edx \
    411 	i686.get_pc_thunk.esi \
    412 	aeabi_cdcmpeq aeabi_cdrcmple aeabi_cfcmpeq aeabi_cfrcmple aeabi_dcmpeq \
    413 	aeabi_dcmpge aeabi_dcmpgt aeabi_dcmple aeabi_dcmplt aeabi_drsub aeabi_fcmpeq \
    414 	aeabi_fcmpge aeabi_fcmpgt aeabi_fcmple aeabi_fcmplt aeabi_frsub aeabi_idivmod \
    415 	aeabi_uidivmod
    416 
    417 FUNCTIONS.cc_kext.armv7 := \
    418 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv7))
    419 FUNCTIONS.cc_kext.armv7f := \
    420 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv7f))
    421 FUNCTIONS.cc_kext.armv7k := \
    422 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv7k))
    423 FUNCTIONS.cc_kext.armv7s := \
    424 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv7s))
    425 FUNCTIONS.cc_kext_ios5.armv7 := \
    426 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext_ios5.armv7))
    427 FUNCTIONS.cc_kext_ios5.armv7f := \
    428 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext_ios5.armv7f))
    429 FUNCTIONS.cc_kext_ios5.armv7k := \
    430 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext_ios5.armv7k))
    431 FUNCTIONS.cc_kext_ios5.armv7s := \
    432 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext_ios5.armv7s))
    433 FUNCTIONS.cc_kext.i386 := \
    434 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.i386))
    435 FUNCTIONS.cc_kext.x86_64 := \
    436 	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.x86_64))
    437 
    438 KERNEL_USE.cc_kext := 1
    439 KERNEL_USE.cc_kext_ios5 := 1
    440 
    441 VISIBILITY_HIDDEN := 1
    442 
    443 SHARED_LIBRARY_SUFFIX := dylib
    444