__init__.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. from devtools.yamaker.modules import Linkable, Switch, Recursable
  2. from devtools.yamaker.platform_macros import LLVM_VERSION
  3. from devtools.yamaker.project import CMakeNinjaNixProject
  4. CLANG_RT_LIBS = {
  5. "asan",
  6. "asan-preinit",
  7. "asan_cxx",
  8. "asan_static",
  9. "cfi",
  10. "cfi_diag",
  11. "dd",
  12. "dfsan",
  13. "gwp_asan",
  14. "hwasan",
  15. "hwasan_cxx",
  16. "hwasan_aliases",
  17. "hwasan_aliases_cxx",
  18. "lsan",
  19. "memprof",
  20. "memprof-preinit",
  21. "memprof_cxx",
  22. "msan",
  23. "msan_cxx",
  24. "profile",
  25. "safestack",
  26. "scudo_standalone",
  27. "scudo_standalone_cxx",
  28. "stats",
  29. "stats_client",
  30. "tsan",
  31. "tsan_cxx",
  32. "ubsan_minimal",
  33. "ubsan_standalone",
  34. "ubsan_standalone_cxx",
  35. }
  36. CLANG_RT_LINUX_ONLY_LIBS = {
  37. "lib/" + lib
  38. for lib in CLANG_RT_LIBS
  39. if lib.startswith(
  40. (
  41. "dd",
  42. "dfsan",
  43. "cfi",
  44. "gwp_asan",
  45. "hwasan",
  46. "msan",
  47. "memprof",
  48. "memprof-preinit",
  49. "memprof_cxx",
  50. "safestack",
  51. "scudo",
  52. )
  53. )
  54. }
  55. MAPSMOBI_SPECIFIC = """
  56. IF(MAPSMOBI_BUILD_TARGET == "yes")
  57. NO_OPTIMIZE()
  58. ENDIF()
  59. """
  60. def post_install(self):
  61. # Original build system uses a copy of profile/InstrProfData.inc in build dir.
  62. self.yamakes["lib/profile"].ADDINCL.add(self.arcdir + "/include")
  63. # Override -fexceptions that we force on C code; fixes combined LTO+PGO builds.
  64. self.yamakes["lib/profile"].CFLAGS.append("-fno-exceptions")
  65. self.yamakes["lib/memprof"].ADDINCL.add(self.arcdir + "/include")
  66. for s in CLANG_RT_LIBS:
  67. with self.yamakes["lib/" + s] as m:
  68. m.NO_SANITIZE = True
  69. # We need specific library names for use in pkg.json.
  70. m.before("DLL", "INCLUDE(${ARCADIA_ROOT}/build/platform/clang/arch.cmake)\n")
  71. m.LIBRARY = ["clang_rt." + s + "${CLANG_RT_SUFFIX}"]
  72. # Remove Linux-only libraries from other platforms.
  73. self.yamakes["."].RECURSE -= CLANG_RT_LINUX_ONLY_LIBS
  74. self.yamakes["."].after(
  75. "RECURSE",
  76. Switch(
  77. OS_LINUX=Recursable(RECURSE=CLANG_RT_LINUX_ONLY_LIBS),
  78. ),
  79. )
  80. # Support all needed arches and OSes.
  81. with self.yamakes["lib/tsan"] as m:
  82. linux_srcs = {"tsan/rtl/tsan_platform_linux.cpp"}
  83. darwin_srcs = {
  84. "tsan/rtl/tsan_platform_mac.cpp",
  85. "tsan/rtl/tsan_interceptors_mac.cpp",
  86. "tsan/rtl/tsan_interceptors_mach_vm.cpp",
  87. }
  88. m.SRCS -= linux_srcs
  89. m.SRCS.add("tsan/rtl/tsan_rtl_aarch64.S")
  90. m.after(
  91. "SRCS",
  92. Switch(
  93. ARCH_PPC64LE=Linkable(SRCS=["tsan/rtl/tsan_rtl_ppc64.S"]),
  94. ),
  95. )
  96. m.after(
  97. "SRCS",
  98. Switch(
  99. OS_LINUX=Linkable(SRCS=linux_srcs),
  100. OS_DARWIN=Linkable(SRCS=darwin_srcs),
  101. ),
  102. )
  103. with self.yamakes["lib/asan_static"] as m:
  104. linux_srcs = {"asan_rtl_x86_64.S"}
  105. m.SRCS -= linux_srcs
  106. supported_platforms = "ARCH_X86_64 AND NOT OS_DARWIN"
  107. m.after(
  108. "SRCS",
  109. Switch({supported_platforms: Linkable(SRCS=linux_srcs)}),
  110. )
  111. with self.yamakes["lib/msan"] as m:
  112. m.before("CFLAGS", MAPSMOBI_SPECIFIC)
  113. # Remove SCUDO_DEFAULT_OPTIONS.
  114. for ym in self.yamakes:
  115. if hasattr(self.yamakes[ym], "CFLAGS"):
  116. self.yamakes[ym].CFLAGS.remove("-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0")
  117. llvm_clang_rt = CMakeNinjaNixProject(
  118. nixattr=f"llvmPackages_{LLVM_VERSION}.compiler-rt",
  119. arcdir=f"contrib/libs/clang{LLVM_VERSION}-rt",
  120. # fmt: off
  121. install_targets=[
  122. f"clang_rt.{lib}-x86_64"
  123. for lib in CLANG_RT_LIBS
  124. ],
  125. # fmt: on
  126. ignore_targets=[
  127. "libclang_rt.*.so",
  128. ],
  129. copy_sources=[
  130. "include/sanitizer/*.h",
  131. "lib/asan/*.h",
  132. "lib/interception/*.h",
  133. "lib/lsan/*.h",
  134. "lib/profile/WindowsMMap.h",
  135. "lib/sanitizer_common/*.inc",
  136. "lib/sanitizer_common/*.h",
  137. "lib/tsan/rtl/tsan_interceptors_*.cpp",
  138. "lib/tsan/rtl/tsan_platform_*.cpp",
  139. "lib/tsan/rtl/tsan_rtl_*.S",
  140. "lib/tsan/rtl/tsan_spinlock_defs_mac.h",
  141. ],
  142. flags=[
  143. "-DCOMPILER_RT_BUILD_BUILTINS=OFF", # Split into cxxsupp/builtins.
  144. "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF", # Split into libfuzzer.
  145. ],
  146. put={f"clang_rt.{lib}-x86_64": f"lib/{lib}" for lib in CLANG_RT_LIBS},
  147. args=["--add-foptions", "--keep-cflag=PIC"],
  148. post_install=post_install,
  149. disable_includes=[
  150. "GWP_ASAN_PLATFORM_TLS_HEADER",
  151. "altq/",
  152. "asm/reg.h",
  153. "backtrace.h",
  154. "backtrace-supported.h",
  155. "bionic/",
  156. "demangle.h",
  157. "dev/",
  158. "fs/",
  159. "lib/",
  160. "link_elf.h",
  161. "machine/reg.h",
  162. "md5.h",
  163. "net/if_ether.h",
  164. "net/if_gre.h",
  165. "net/if_pppoe.h",
  166. "net/if_sppp.h",
  167. "net/if_srt.h",
  168. "net/if_tap.h",
  169. "net/if_tun.h",
  170. "net/npf.h",
  171. "net/ppp_defs.h",
  172. "net/slip.h",
  173. "netbt/hci.h",
  174. "netinet/ip_compat.h",
  175. "netinet/ip_fil.h",
  176. "netinet/ip_mroute.h",
  177. "netinet/ip_nat.h",
  178. "netinet/ip_proxy.h",
  179. "netinet6/in6_var.h",
  180. "netinet6/nd6.h",
  181. "netsmb/smb_dev.h",
  182. "nvmm.h",
  183. "ptrauth.h",
  184. "rmd160.h",
  185. "rpc/xdr.h",
  186. "sanitizer_intercept_overriders.h",
  187. "scudo_platform_tls_slot.h",
  188. "sha224.h",
  189. "sha256.h",
  190. "sha384.h",
  191. "sha512.h",
  192. "stringlist.h",
  193. "sys/agpio.h",
  194. "sys/ataio.h",
  195. "sys/audioio.h",
  196. "sys/capsicum.h",
  197. "sys/cdbr.h",
  198. "sys/cdio.h",
  199. "sys/chio.h",
  200. "sys/clockctl.h",
  201. "sys/consio.h",
  202. "sys/cpuio.h",
  203. "sys/dkbad.h",
  204. "sys/dkio.h",
  205. "sys/drvctlio.h",
  206. "sys/dvdio.h",
  207. "sys/envsys.h",
  208. "sys/fdio.h",
  209. "sys/futex.h",
  210. "sys/gpio.h",
  211. "sys/ioctl_compat.h",
  212. "sys/ipmi.h",
  213. "sys/joystick.h",
  214. "sys/kbio.h",
  215. "sys/kcov.h",
  216. "sys/ksyms.h",
  217. "sys/link_elf.h",
  218. "sys/lua.h",
  219. "sys/midiio.h",
  220. "sys/mqueue.h",
  221. "sys/power.h",
  222. "sys/procctl.h",
  223. "sys/ptyvar.h",
  224. "sys/radioio.h",
  225. "sys/rndio.h",
  226. "sys/scanio.h",
  227. "sys/scsiio.h",
  228. "sys/sha1.h",
  229. "sys/sha2.h",
  230. "sys/timepps.h",
  231. "sys/tls.h",
  232. "sys/verified_exec.h",
  233. "sys/wdog.h",
  234. "traceloggingprovider.h",
  235. "zircon/",
  236. # ifdef __sun
  237. "procfs.h",
  238. "synch.h",
  239. # if defined(_AIX)
  240. "sys/ldr.h",
  241. "xcoff.h",
  242. # ifdef SCUDO_USE_CUSTOM_CONFIG
  243. "custom_scudo_config.h",
  244. ],
  245. )