build.ym 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. {% extends '//builtin/bag.ym' %}
  2. {% block current_version %}19.1.7{% endblock %}
  3. {% block current_url %}
  4. https://github.com/llvm/llvm-project/releases/download/llvmorg-{{self.version().strip()}}/compiler-rt-{{self.version().strip()}}.src.tar.xz
  5. {% endblock %}
  6. {% block patch_source %}
  7. (
  8. rm CMakeLists.txt
  9. cd lib/builtins
  10. rm CMakeLists.txt
  11. rm aarch64/lse.S
  12. sed -e 's|.*#include.*sys/byteorder.h.*||' -i int_endianness.h
  13. sed -e 's|.*#include.*zircon/features.h.*||' -i cpu_model/aarch64/fmv/fuchsia.inc
  14. sed -e 's|.*#include.*zircon/features.h.*||' -i cpu_model/aarch64/lse_atomics/fuchsia.inc
  15. )
  16. {% endblock %}
  17. {% block ya_make %}
  18. SUBSCRIBER(
  19. g:contrib
  20. g:cpp-contrib
  21. )
  22. # Check MUSL before NO_PLATFORM() disables it.
  23. IF (MUSL)
  24. # We use C headers despite NO_PLATFORM, but we do not propagate
  25. # them with ADDINCL GLOBAL because we do not have an API, and we
  26. # can not propagate them because libcxx has to put its own
  27. # includes before musl includes for its include_next to work.
  28. IF (ARCH_X86_64)
  29. ADDINCL(
  30. contrib/libs/musl/arch/x86_64
  31. )
  32. ENDIF()
  33. IF (ARCH_AARCH64)
  34. ADDINCL(
  35. contrib/libs/musl/arch/aarch64
  36. )
  37. ENDIF()
  38. ADDINCL(
  39. contrib/libs/musl/arch/generic
  40. contrib/libs/musl/include
  41. contrib/libs/musl/extra
  42. )
  43. ENDIF()
  44. NO_UTIL()
  45. NO_RUNTIME()
  46. NO_PLATFORM()
  47. NO_COMPILER_WARNINGS()
  48. IF (GCC OR CLANG)
  49. # Clang (maybe GCC too) LTO code generator leaves the builtin calls unresolved
  50. # even if they are available. After the code generation pass is done
  51. # a linker is forced to select original object files from this library again
  52. # as they contain unresolved symbols. But code generation is already done,
  53. # object files actually are not ELFs but an LLVM bytecode and we get
  54. # "member at xxxxx is not an ELF object" errors from the linker.
  55. # Just generate native code from the beginning.
  56. NO_LTO()
  57. ENDIF()
  58. {% endblock %}
  59. {% block gen_ya_make %}
  60. (
  61. cd lib/builtins
  62. cat << EOF > join.py
  63. import os
  64. import sys
  65. common = open(sys.argv[1]).read().strip().split('\n')
  66. special = open(sys.argv[2]).read().strip().split('\n')
  67. arch = sys.argv[3]
  68. def name(n):
  69. return os.path.basename(n).split('.')[0]
  70. sset = frozenset([name(x) for x in special])
  71. scrt = frozenset(['crtbegin', 'crtend'])
  72. # x86_80_BIT_SOURCES
  73. x86_not_win = frozenset(['divxc3', 'extendxftf2', 'fixxfdi', 'fixxfti', 'fixunsxfdi', 'fixunsxfsi', 'fixunsxfti', 'floatdixf', 'floattixf', 'floatundixf', 'floatuntixf', 'mulxc3', 'powixf2', 'trunctfxf2'])
  74. other_not_emscripten = frozenset([
  75. 'clear_cache',
  76. 'emutls',
  77. 'enable_execute_stack',
  78. 'eprintf',
  79. ])
  80. def it_srcs():
  81. for x in common:
  82. n = name(x)
  83. if n.startswith("atomic_") or n.endswith("bf2") or n == "extendbfsf2":
  84. # these are handled explicitly below
  85. continue
  86. if n in scrt:
  87. continue
  88. if arch != 'x86_64_not_win' and n in x86_not_win:
  89. continue
  90. if arch == 'x86_64_not_win' and (not n in x86_not_win or n in ['floatdixf', 'floatundixf']):
  91. continue
  92. if arch == 'other' and n in other_not_emscripten:
  93. continue
  94. if arch == 'other_not_emscripten' and (n not in other_not_emscripten):
  95. continue
  96. if n not in sset:
  97. yield x
  98. yield from set(special) - {'x86_64/floatdixf.c', 'aarch64/sme-libc-routines.c'}
  99. print('\n'.join(sorted(list(it_srcs()))).strip())
  100. EOF
  101. ls *.c > common
  102. cat << EOF
  103. IF (OS_DARWIN OR OS_IOS)
  104. SRCS(
  105. atomic_flag_clear.c
  106. atomic_flag_clear_explicit.c
  107. atomic_flag_test_and_set.c
  108. atomic_flag_test_and_set_explicit.c
  109. atomic_signal_fence.c
  110. atomic_thread_fence.c
  111. )
  112. ENDIF()
  113. IF (ARCH_ARM64 OR ARCH_X86_64)
  114. # As of r25b, clang-for-android does not have bf16 support.
  115. # These can be built using r27 and above.
  116. IF (NOT OS_ANDROID)
  117. SRCS(
  118. # NB: sources that were commented out were added in llvm-20
  119. extendbfsf2.c
  120. truncdfbf2.c
  121. # truncxfbf2.c
  122. truncsfbf2.c
  123. # trunctfbf2.c
  124. )
  125. ENDIF()
  126. ENDIF()
  127. EOF
  128. echo 'IF (ARCH_AARCH64)'
  129. echo 'SRCS('
  130. ls aarch64/*.c cpu_model/aarch64.*c aarch64/*.S > special
  131. python3 join.py common special aarch
  132. echo ')'
  133. echo 'IF(NOT OS_DARWIN) SRCS(aarch64/sme-libc-routines.c) ENDIF()'
  134. echo 'ELSEIF (ARCH_X86_64)'
  135. echo 'SRCS('
  136. ls x86_64/*.c cpu_model/x86.*c x86_64/*.S > special
  137. python3 join.py common special x86_64
  138. echo ')'
  139. # As llvm/compiler-rt/lib/builtins says:
  140. # Implement extended-precision builtins, assuming long double is 80 bits.
  141. # long double is not 80 bits on Android or MSVC.
  142. echo 'IF(NOT OS_WINDOWS AND NOT OS_ANDROID) SRCS(x86_64/floatdixf.c'
  143. echo '' > special
  144. python3 join.py common special x86_64_not_win
  145. echo ') ENDIF()'
  146. echo 'ELSE()'
  147. echo 'SRCS('
  148. echo '' > special
  149. python3 join.py common special other
  150. echo ')'
  151. echo 'IF (NOT OS_EMSCRIPTEN)'
  152. echo 'SRCS('
  153. python3 join.py common special other_not_emscripten
  154. echo ')'
  155. echo 'ENDIF()'
  156. echo 'ENDIF()'
  157. echo 'IF(OS_LINUX AND NOT WITH_MAPKIT)'
  158. echo 'SRCS(crtbegin.c crtend.c)'
  159. echo 'ENDIF()'
  160. rm join.py common special
  161. ) >> ya.make
  162. {% endblock %}
  163. {% block move_to_output %}
  164. {{super()}}
  165. cp -R lib/builtins/* ${OUTPUT}/
  166. {% endblock %}
  167. {% block run_license_analyzer %}
  168. {{super()}}
  169. sed -e 's|.* LLVM.*||' -i ${OUTPUT}/ya.make
  170. {% endblock %}