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.
7 Description
:= Static runtime libraries for clang
/Darwin.
9 # A function that ensures we don't try to build for architectures and SDKs
10 # that we don't have working toolchains for. Arguments:
11 # (1): List of architectures
14 # The result is a possibly empty subset of the architectures from argument 1.
18 if
[ "X$(3)" != X
]; then \
19 for arch in
$(1); do \
20 if
$(LD
) -v
2>&1 | grep
"configured to support" \
21 | tr
' ' '\n' | grep
"^$$arch$$" >/dev
/null
2>/dev
/null
; then \
22 if
$(CC
) -arch
$$arch \
24 $(ProjSrcRoot
)/make
/platform
/clang_darwin_test_input.c \
26 -o
/dev
/null
> /dev
/null
2> /dev
/null
; then \
27 result
="$$result$$arch "; \
30 "warning: clang_darwin.mk: dropping arch '$$arch' from lib '$(2)'"; \
31 printf
1>&2 " (clang or system libraries do not support it)\n"; \
35 "warning: clang_darwin.mk: dropping arch '$$arch' from lib '$(2)'";\
36 printf
1>&2 " (ld does not support it)\n"; \
44 result
=`xcrun -find $(1) 2> /dev/null`; \
45 if
[ "$$?" != "0" ]; then result
=$(1); fi
; \
47 # Prefer building with the internal SDKs.
50 result
=`xcrun --sdk $(1).internal --show-sdk-path 2> /dev/null`; \
51 if
[ "$$?" != "0" ]; then \
52 result
=`xcrun --sdk $(1) --show-sdk-path 2> /dev/null`; \
53 if
[ "$$?" != "0" ]; then result
=""; fi
; \
58 CC
:= $(call XCRun
,clang
)
59 LD
:= $(shell $(CC
) -print-prog-name
=ld)
60 AR
:= $(call XCRun
,ar)
61 RANLIB
:= $(call XCRun
,ranlib
)
62 STRIP
:= $(call XCRun
,strip)
63 LIPO
:= $(call XCRun
,lipo
)
64 DSYMUTIL
:= $(call XCRun
,dsymutil
)
66 OSX_SDK
:= $(call XCRunSdkPath
,macosx
)
67 IOS_SDK
:= $(call XCRunSdkPath
,iphoneos
)
68 IOSSIM_SDK
:= $(call XCRunSdkPath
,iphonesimulator
)
73 # Configuration solely for providing access to an eprintf symbol, which may
74 # still be referenced from Darwin system headers. This symbol is only ever
77 UniversalArchs.eprintf
:= $(call CheckArches
,i386
,eprintf
,$(OSX_SDK
))
79 # Configuration for targeting 10.4. We need a few functions missing from
80 # libgcc_s.10.4.dylib. We only build x86 slices since clang doesn't really
81 # support targeting PowerPC.
83 UniversalArchs
.10.4 := $(call CheckArches
,i386 x86_64
,10.4,$(OSX_SDK
))
85 # Configuration for targeting iOS for a couple of functions that didn't
86 # make it into libSystem.
88 UniversalArchs.ios
:= $(call CheckArches
,i386 x86_64
,ios
,$(IOSSIM_SDK
))
89 UniversalArchs.ios
+= $(call CheckArches
,armv7 arm64
,ios
,$(IOS_SDK
))
91 # Configuration for targeting OSX. These functions may not be in libSystem
92 # so we should provide our own.
94 UniversalArchs.osx
:= $(call CheckArches
,i386 x86_64 x86_64h
,osx
,$(OSX_SDK
))
96 # Configuration for use with kernel/kexts.
98 UniversalArchs.cc_kext
:= $(call CheckArches
,i386 x86_64 x86_64h
,cc_kext
,$(OSX_SDK
))
100 # Configuration for use with iOS kernel/kexts
101 Configs
+= cc_kext_ios
102 UniversalArchs.cc_kext_ios
+= $(call CheckArches
,armv7
,cc_kext_ios
,$(IOS_SDK
))
104 # Darwin 10.6 has a bug in cctools that makes it unable to use ranlib on our ARM
105 # object files. If we are on that platform, strip out all ARM archs. We still
106 # build the libraries themselves so that Clang can find them where it expects
107 # them, even though they might not have an expected slice.
108 ifneq ($(shell test -x
/usr
/bin
/sw_vers
&& sw_vers
-productVersion | grep
10.6),)
109 UniversalArchs.ios
:= $(filter-out armv7
, $(UniversalArchs.ios
))
110 UniversalArchs.cc_kext_ios
:= $(filter-out armv7
, $(UniversalArchs.cc_kext_ios
))
113 # If RC_SUPPORTED_ARCHS is defined, treat it as a list of the architectures we
114 # are intended to support and limit what we try to build to that.
115 ifneq ($(RC_SUPPORTED_ARCHS
),)
116 $(foreach config
,$(Configs
),\
117 $(call Set
,UniversalArchs.
$(config
),\
118 $(filter $(RC_SUPPORTED_ARCHS
),$(UniversalArchs.
$(config
)))))
121 # Remove empty configs if we end up dropping all the requested
122 # archs for a particular config.
123 $(foreach config
,$(Configs
),\
124 $(if
$(strip $(UniversalArchs.
$(config
))),,\
125 $(call Set
,Configs
,$(filter-out $(config
),$(Configs
)))))
129 # Forcibly strip off any -arch, as that totally breaks our universal support.
130 override CC
:= $(subst -arch
,-arch_
,$(CC
))
131 override CC
:= $(patsubst -arch_
%,,$(CC
))
133 CFLAGS
:= -Wall
-Werror
-O3
-fomit-frame-pointer
135 # Always set deployment target arguments for every build, these libraries should
136 # never depend on the environmental overrides. We simply set them to minimum
137 # supported deployment target -- nothing in the compiler-rt libraries should
138 # actually depend on the deployment target.
139 OSX_DEPLOYMENT_ARGS
:= -mmacosx-version-min
=10.4
140 IOS_DEPLOYMENT_ARGS
:= -mios-version-min
=1.0
141 IOS6_DEPLOYMENT_ARGS
:= -mios-version-min
=6.0
142 IOSSIM_DEPLOYMENT_ARGS
:= -mios-simulator-version-min
=1.0
144 OSX_DEPLOYMENT_ARGS
+= -isysroot
$(OSX_SDK
)
145 IOS_DEPLOYMENT_ARGS
+= -isysroot
$(IOS_SDK
)
146 IOS6_DEPLOYMENT_ARGS
+= -isysroot
$(IOS_SDK
)
147 IOSSIM_DEPLOYMENT_ARGS
+= -isysroot
$(IOSSIM_SDK
)
149 CFLAGS.eprintf
:= $(CFLAGS
) $(OSX_DEPLOYMENT_ARGS
)
150 CFLAGS
.10.4 := $(CFLAGS
) $(OSX_DEPLOYMENT_ARGS
)
152 SANITIZER_MACOSX_DEPLOYMENT_ARGS
:= -mmacosx-version-min
=10.7
153 SANITIZER_IOSSIM_DEPLOYMENT_ARGS
:= -mios-simulator-version-min
=7.0 \
154 -isysroot
$(IOSSIM_SDK
)
155 SANITIZER_CFLAGS
:= -fno-builtin
-gline-tables-only
-stdlib
=libc
++
158 CFLAGS.ios.i386
:= $(CFLAGS
) $(IOSSIM_DEPLOYMENT_ARGS
)
159 CFLAGS.ios.x86_64
:= $(CFLAGS
) $(IOSSIM_DEPLOYMENT_ARGS
)
160 CFLAGS.ios.armv7
:= $(CFLAGS
) $(IOS_DEPLOYMENT_ARGS
)
161 CFLAGS.ios.armv7k
:= $(CFLAGS
) $(IOS_DEPLOYMENT_ARGS
)
162 CFLAGS.ios.armv7s
:= $(CFLAGS
) $(IOS_DEPLOYMENT_ARGS
)
163 CFLAGS.ios.arm64
:= $(CFLAGS
) $(IOS6_DEPLOYMENT_ARGS
)
164 CFLAGS.osx.i386
:= $(CFLAGS
) $(OSX_DEPLOYMENT_ARGS
)
165 CFLAGS.osx.x86_64
:= $(CFLAGS
) $(OSX_DEPLOYMENT_ARGS
)
166 CFLAGS.osx.x86_64h
:= $(CFLAGS
) $(OSX_DEPLOYMENT_ARGS
)
167 CFLAGS.cc_kext.i386
:= $(CFLAGS
) $(OSX_DEPLOYMENT_ARGS
)
168 CFLAGS.cc_kext.x86_64
:= $(CFLAGS
) $(OSX_DEPLOYMENT_ARGS
)
169 CFLAGS.cc_kext.x86_64h
:= $(CFLAGS
) $(OSX_DEPLOYMENT_ARGS
)
170 CFLAGS.cc_kext_ios.armv7
:= $(CFLAGS
) $(IOS6_DEPLOYMENT_ARGS
)
171 CFLAGS.cc_kext_ios.armv7k
:= $(CFLAGS
) $(IOS6_DEPLOYMENT_ARGS
)
172 CFLAGS.cc_kext_ios.armv7s
:= $(CFLAGS
) $(IOS6_DEPLOYMENT_ARGS
)
173 CFLAGS.cc_kext_ios.arm64
:= $(CFLAGS
) $(IOS6_DEPLOYMENT_ARGS
)
175 SANITIZER_LDFLAGS
:= -stdlib
=libc
++ -lc
++ -lc
++abi
177 ATOMIC_FUNCTIONS
:= \
179 atomic_flag_clear_explicit \
180 atomic_flag_test_and_set \
181 atomic_flag_test_and_set_explicit \
182 atomic_signal_fence \
190 FUNCTIONS.eprintf
:= eprintf
191 FUNCTIONS
.10.4 := eprintf floatundidf floatundisf floatundixf
193 FUNCTIONS.ios
:= divmodsi4 udivmodsi4 mulosi4 mulodi4 muloti4 \
194 $(ATOMIC_FUNCTIONS
) $(FP16_FUNCTIONS
)
195 # On x86, the divmod functions reference divsi.
196 FUNCTIONS.ios.i386
:= $(FUNCTIONS.ios
) \
198 FUNCTIONS.ios.x86_64
:= $(FUNCTIONS.ios.i386
)
199 FUNCTIONS.ios.arm64
:= mulsc3 muldc3 divsc3 divdc3 udivti3 umodti3 \
202 FUNCTIONS.osx
:= mulosi4 mulodi4 muloti4
$(ATOMIC_FUNCTIONS
) $(FP16_FUNCTIONS
)
204 CCKEXT_PROFILE_FUNCTIONS
:= \
206 InstrProfilingBuffer \
207 InstrProfilingPlatformDarwin
209 CCKEXT_COMMON_FUNCTIONS
:= \
210 $(CCKEXT_PROFILE_FUNCTIONS
) \
270 CCKEXT_ARM_FUNCTIONS
:= $(CCKEXT_COMMON_FUNCTIONS
) \
325 CCKEXT_ARMVFP_FUNCTIONS
:= $(CCKEXT_ARM_FUNCTIONS
) \
359 CCKEXT_ARM64_FUNCTIONS
:= \
360 $(CCKEXT_PROFILE_FUNCTIONS
) \
368 FUNCTIONS.cc_kext_ios.armv7
:= $(CCKEXT_ARMVFP_FUNCTIONS
)
369 FUNCTIONS.cc_kext_ios.armv7k
:= $(CCKEXT_ARMVFP_FUNCTIONS
)
370 FUNCTIONS.cc_kext_ios.armv7s
:= $(CCKEXT_ARMVFP_FUNCTIONS
)
371 FUNCTIONS.cc_kext_ios.arm64
:= $(CCKEXT_ARM64_FUNCTIONS
)
373 CCKEXT_X86_FUNCTIONS
:= $(CCKEXT_COMMON_FUNCTIONS
) \
383 FUNCTIONS.cc_kext.i386
:= $(CCKEXT_X86_FUNCTIONS
) \
385 i686.get_pc_thunk.eax \
386 i686.get_pc_thunk.ebp \
387 i686.get_pc_thunk.ebx \
388 i686.get_pc_thunk.ecx \
389 i686.get_pc_thunk.edi \
390 i686.get_pc_thunk.edx \
391 i686.get_pc_thunk.esi
393 FUNCTIONS.cc_kext.x86_64
:= $(CCKEXT_X86_FUNCTIONS
) \
429 FUNCTIONS.cc_kext.x86_64h
:= $(FUNCTIONS.cc_kext.x86_64
)
431 # FIXME: Currently, compiler-rt is missing implementations for a number of the
432 # functions that need to go into libcc_kext.a. Filter them out for now.
433 CCKEXT_MISSING_FUNCTIONS
:= \
436 udiv_w_sdiv unorddf2 unordsf2 bswapdi2 \
440 i686.get_pc_thunk.eax i686.get_pc_thunk.ebp i686.get_pc_thunk.ebx \
441 i686.get_pc_thunk.ecx i686.get_pc_thunk.edi i686.get_pc_thunk.edx \
442 i686.get_pc_thunk.esi \
443 aeabi_cdcmpeq aeabi_cdrcmple aeabi_cfcmpeq aeabi_cfrcmple aeabi_dcmpeq \
444 aeabi_dcmpge aeabi_dcmpgt aeabi_dcmple aeabi_dcmplt aeabi_drsub aeabi_fcmpeq \
445 aeabi_fcmpge aeabi_fcmpgt aeabi_fcmple aeabi_fcmplt aeabi_frsub aeabi_idivmod \
448 FUNCTIONS.cc_kext_ios.armv7
:= \
449 $(filter-out $(CCKEXT_MISSING_FUNCTIONS
),$(FUNCTIONS.cc_kext_ios.armv7
))
450 FUNCTIONS.cc_kext_ios.armv7k
:= \
451 $(filter-out $(CCKEXT_MISSING_FUNCTIONS
),$(FUNCTIONS.cc_kext_ios.armv7k
))
452 FUNCTIONS.cc_kext_ios.armv7s
:= \
453 $(filter-out $(CCKEXT_MISSING_FUNCTIONS
),$(FUNCTIONS.cc_kext_ios.armv7s
))
454 FUNCTIONS.cc_kext_ios.arm64
:= \
455 $(filter-out $(CCKEXT_MISSING_FUNCTIONS
),$(FUNCTIONS.cc_kext_ios.arm64
))
456 FUNCTIONS.cc_kext.i386
:= \
457 $(filter-out $(CCKEXT_MISSING_FUNCTIONS
),$(FUNCTIONS.cc_kext.i386
))
458 FUNCTIONS.cc_kext.x86_64
:= \
459 $(filter-out $(CCKEXT_MISSING_FUNCTIONS
),$(FUNCTIONS.cc_kext.x86_64
))
460 FUNCTIONS.cc_kext.x86_64h
:= \
461 $(filter-out $(CCKEXT_MISSING_FUNCTIONS
),$(FUNCTIONS.cc_kext.x86_64h
))
463 KERNEL_USE.cc_kext
:= 1
464 KERNEL_USE.cc_kext_ios
:= 1
466 VISIBILITY_HIDDEN
:= 1
468 SHARED_LIBRARY_SUFFIX
:= dylib