1# This directory contains a large amount of C code which provides
2# generic implementations of the core runtime library along with optimized
3# architecture-specific code in various subdirectories.
4
5# TODO: Need to add a mechanism for logging errors when builtin source files are
6# added to a sub-directory and not this CMakeLists file.
7
8set(GENERIC_SOURCES
9  absvdi2.c
10  absvsi2.c
11  absvti2.c
12  adddf3.c
13  addsf3.c
14  addtf3.c
15  addvdi3.c
16  addvsi3.c
17  addvti3.c
18  apple_versioning.c
19  ashldi3.c
20  ashlti3.c
21  ashrdi3.c
22  ashrti3.c
23  # FIXME: atomic.c may only be compiled if host compiler understands _Atomic
24  # atomic.c
25  clear_cache.c
26  clzdi2.c
27  clzsi2.c
28  clzti2.c
29  cmpdi2.c
30  cmpti2.c
31  comparedf2.c
32  comparesf2.c
33  ctzdi2.c
34  ctzsi2.c
35  ctzti2.c
36  divdc3.c
37  divdf3.c
38  divdi3.c
39  divmoddi4.c
40  divmodsi4.c
41  divsc3.c
42  divsf3.c
43  divsi3.c
44  divtc3.c
45  divti3.c
46  divtf3.c
47  divxc3.c
48  enable_execute_stack.c
49  eprintf.c
50  extendsfdf2.c
51  extendhfsf2.c
52  ffsdi2.c
53  ffsti2.c
54  fixdfdi.c
55  fixdfsi.c
56  fixdfti.c
57  fixsfdi.c
58  fixsfsi.c
59  fixsfti.c
60  fixunsdfdi.c
61  fixunsdfsi.c
62  fixunsdfti.c
63  fixunssfdi.c
64  fixunssfsi.c
65  fixunssfti.c
66  fixunsxfdi.c
67  fixunsxfsi.c
68  fixunsxfti.c
69  fixxfdi.c
70  fixxfti.c
71  floatdidf.c
72  floatdisf.c
73  floatdixf.c
74  floatsidf.c
75  floatsisf.c
76  floattidf.c
77  floattisf.c
78  floattixf.c
79  floatundidf.c
80  floatundisf.c
81  floatundixf.c
82  floatunsidf.c
83  floatunsisf.c
84  floatuntidf.c
85  floatuntisf.c
86  floatuntixf.c
87  int_util.c
88  lshrdi3.c
89  lshrti3.c
90  moddi3.c
91  modsi3.c
92  modti3.c
93  muldc3.c
94  muldf3.c
95  muldi3.c
96  mulodi4.c
97  mulosi4.c
98  muloti4.c
99  mulsc3.c
100  mulsf3.c
101  multi3.c
102  multf3.c
103  mulvdi3.c
104  mulvsi3.c
105  mulvti3.c
106  mulxc3.c
107  negdf2.c
108  negdi2.c
109  negsf2.c
110  negti2.c
111  negvdi2.c
112  negvsi2.c
113  negvti2.c
114  paritydi2.c
115  paritysi2.c
116  parityti2.c
117  popcountdi2.c
118  popcountsi2.c
119  popcountti2.c
120  powidf2.c
121  powisf2.c
122  powitf2.c
123  powixf2.c
124  subdf3.c
125  subsf3.c
126  subvdi3.c
127  subvsi3.c
128  subvti3.c
129  subtf3.c
130  trampoline_setup.c
131  truncdfhf2.c
132  truncdfsf2.c
133  truncsfhf2.c
134  ucmpdi2.c
135  ucmpti2.c
136  udivdi3.c
137  udivmoddi4.c
138  udivmodsi4.c
139  udivmodti4.c
140  udivsi3.c
141  udivti3.c
142  umoddi3.c
143  umodsi3.c
144  umodti3.c)
145
146if(APPLE)
147  set(GENERIC_SOURCES
148    ${GENERIC_SOURCES}
149    atomic_flag_clear.c
150    atomic_flag_clear_explicit.c
151    atomic_flag_test_and_set.c
152    atomic_flag_test_and_set_explicit.c
153    atomic_signal_fence.c
154    atomic_thread_fence.c)
155endif()
156
157if(NOT WIN32 OR MINGW)
158  set(GENERIC_SOURCES
159      ${GENERIC_SOURCES}
160      emutls.c)
161endif()
162
163if (HAVE_UNWIND_H)
164  set(GENERIC_SOURCES
165      ${GENERIC_SOURCES}
166      gcc_personality_v0.c)
167endif ()
168
169if (NOT MSVC)
170  set(x86_64_SOURCES
171      x86_64/chkstk.S
172      x86_64/chkstk2.S
173      x86_64/floatdidf.c
174      x86_64/floatdisf.c
175      x86_64/floatdixf.c
176      x86_64/floatundidf.S
177      x86_64/floatundisf.S
178      x86_64/floatundixf.S
179      ${GENERIC_SOURCES})
180  set(x86_64h_SOURCES ${x86_64_SOURCES})
181
182  if (WIN32)
183    set(x86_64_SOURCES
184        ${x86_64_SOURCES}
185        x86_64/chkstk.S
186        x86_64/chkstk2.S)
187  endif()
188
189  set(i386_SOURCES
190      i386/ashldi3.S
191      i386/ashrdi3.S
192      i386/chkstk.S
193      i386/chkstk2.S
194      i386/divdi3.S
195      i386/floatdidf.S
196      i386/floatdisf.S
197      i386/floatdixf.S
198      i386/floatundidf.S
199      i386/floatundisf.S
200      i386/floatundixf.S
201      i386/lshrdi3.S
202      i386/moddi3.S
203      i386/muldi3.S
204      i386/udivdi3.S
205      i386/umoddi3.S
206      ${GENERIC_SOURCES})
207
208  if (WIN32)
209    set(i386_SOURCES
210        ${i386_SOURCES}
211        i386/chkstk.S
212        i386/chkstk2.S)
213  endif()
214
215  set(i686_SOURCES
216      ${i386_SOURCES})
217else () # MSVC
218  # Use C versions of functions when building on MSVC
219  # MSVC's assembler takes Intel syntax, not AT&T syntax
220  set(x86_64_SOURCES
221      x86_64/floatdidf.c
222      x86_64/floatdisf.c
223      x86_64/floatdixf.c
224      ${GENERIC_SOURCES})
225  set(x86_64h_SOURCES ${x86_64_SOURCES})
226  set(i386_SOURCES ${GENERIC_SOURCES})
227  set(i686_SOURCES ${i386_SOURCES})
228endif () # if (NOT MSVC)
229
230set(arm_SOURCES
231  arm/adddf3vfp.S
232  arm/addsf3vfp.S
233  arm/aeabi_cdcmp.S
234  arm/aeabi_cdcmpeq_check_nan.c
235  arm/aeabi_cfcmp.S
236  arm/aeabi_cfcmpeq_check_nan.c
237  arm/aeabi_dcmp.S
238  arm/aeabi_div0.c
239  arm/aeabi_drsub.c
240  arm/aeabi_fcmp.S
241  arm/aeabi_frsub.c
242  arm/aeabi_idivmod.S
243  arm/aeabi_ldivmod.S
244  arm/aeabi_memcmp.S
245  arm/aeabi_memcpy.S
246  arm/aeabi_memmove.S
247  arm/aeabi_memset.S
248  arm/aeabi_uidivmod.S
249  arm/aeabi_uldivmod.S
250  arm/bswapdi2.S
251  arm/bswapsi2.S
252  arm/clzdi2.S
253  arm/clzsi2.S
254  arm/comparesf2.S
255  arm/divdf3vfp.S
256  arm/divmodsi4.S
257  arm/divsf3vfp.S
258  arm/divsi3.S
259  arm/eqdf2vfp.S
260  arm/eqsf2vfp.S
261  arm/extendsfdf2vfp.S
262  arm/fixdfsivfp.S
263  arm/fixsfsivfp.S
264  arm/fixunsdfsivfp.S
265  arm/fixunssfsivfp.S
266  arm/floatsidfvfp.S
267  arm/floatsisfvfp.S
268  arm/floatunssidfvfp.S
269  arm/floatunssisfvfp.S
270  arm/gedf2vfp.S
271  arm/gesf2vfp.S
272  arm/gtdf2vfp.S
273  arm/gtsf2vfp.S
274  arm/ledf2vfp.S
275  arm/lesf2vfp.S
276  arm/ltdf2vfp.S
277  arm/ltsf2vfp.S
278  arm/modsi3.S
279  arm/muldf3vfp.S
280  arm/mulsf3vfp.S
281  arm/nedf2vfp.S
282  arm/negdf2vfp.S
283  arm/negsf2vfp.S
284  arm/nesf2vfp.S
285  arm/restore_vfp_d8_d15_regs.S
286  arm/save_vfp_d8_d15_regs.S
287  arm/subdf3vfp.S
288  arm/subsf3vfp.S
289  arm/switch16.S
290  arm/switch32.S
291  arm/switch8.S
292  arm/switchu8.S
293  arm/sync_fetch_and_add_4.S
294  arm/sync_fetch_and_add_8.S
295  arm/sync_fetch_and_and_4.S
296  arm/sync_fetch_and_and_8.S
297  arm/sync_fetch_and_max_4.S
298  arm/sync_fetch_and_max_8.S
299  arm/sync_fetch_and_min_4.S
300  arm/sync_fetch_and_min_8.S
301  arm/sync_fetch_and_nand_4.S
302  arm/sync_fetch_and_nand_8.S
303  arm/sync_fetch_and_or_4.S
304  arm/sync_fetch_and_or_8.S
305  arm/sync_fetch_and_sub_4.S
306  arm/sync_fetch_and_sub_8.S
307  arm/sync_fetch_and_umax_4.S
308  arm/sync_fetch_and_umax_8.S
309  arm/sync_fetch_and_umin_4.S
310  arm/sync_fetch_and_umin_8.S
311  arm/sync_fetch_and_xor_4.S
312  arm/sync_fetch_and_xor_8.S
313  arm/sync_synchronize.S
314  arm/truncdfsf2vfp.S
315  arm/udivmodsi4.S
316  arm/udivsi3.S
317  arm/umodsi3.S
318  arm/unorddf2vfp.S
319  arm/unordsf2vfp.S
320  ${GENERIC_SOURCES})
321
322set(aarch64_SOURCES
323  comparetf2.c
324  extenddftf2.c
325  extendsftf2.c
326  fixtfdi.c
327  fixtfsi.c
328  fixtfti.c
329  fixunstfdi.c
330  fixunstfsi.c
331  fixunstfti.c
332  floatditf.c
333  floatsitf.c
334  floatunditf.c
335  floatunsitf.c
336  multc3.c
337  trunctfdf2.c
338  trunctfsf2.c
339  ${GENERIC_SOURCES})
340
341set(armhf_SOURCES ${arm_SOURCES})
342set(armv7_SOURCES ${arm_SOURCES})
343set(armv7s_SOURCES ${arm_SOURCES})
344set(arm64_SOURCES ${aarch64_SOURCES})
345
346# macho_embedded archs
347set(armv6m_SOURCES ${GENERIC_SOURCES})
348set(armv7m_SOURCES ${arm_SOURCES})
349set(armv7em_SOURCES ${arm_SOURCES})
350
351set(mips_SOURCES ${GENERIC_SOURCES})
352set(mipsel_SOURCES ${mips_SOURCES})
353set(mips64_SOURCES ${mips_SOURCES})
354set(mips64el_SOURCES ${mips_SOURCES})
355
356add_custom_target(builtins)
357
358if (APPLE)
359  add_subdirectory(Darwin-excludes)
360  add_subdirectory(macho_embedded)
361  darwin_add_builtin_libraries(${BUILTIN_SUPPORTED_OS})
362elseif (NOT WIN32 OR MINGW)
363  append_string_if(COMPILER_RT_HAS_STD_C99_FLAG -std=c99 maybe_stdc99)
364
365  foreach (arch ${BUILTIN_SUPPORTED_ARCH})
366    if (CAN_TARGET_${arch})
367      # Filter out generic versions of routines that are re-implemented in
368      # architecture specific manner.  This prevents multiple definitions of the
369      # same symbols, making the symbol selection non-deterministic.
370      foreach (_file ${${arch}_SOURCES})
371        if (${_file} MATCHES ${arch}/*)
372          get_filename_component(_name ${_file} NAME)
373          string(REPLACE ".S" ".c" _cname "${_name}")
374          list(REMOVE_ITEM ${arch}_SOURCES ${_cname})
375        endif ()
376      endforeach ()
377
378      add_compiler_rt_runtime(clang_rt.builtins
379                              STATIC
380                              ARCHS ${arch}
381                              SOURCES ${${arch}_SOURCES}
382                              CFLAGS ${maybe_stdc99}
383                              PARENT_TARGET builtins)
384    endif ()
385  endforeach ()
386endif ()
387
388add_dependencies(compiler-rt builtins)
389