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

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