0002-compiler-rt-support-a-new-embedded-linux-target.patch 8.8 KB

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