[Git][ghc/ghc][wip/ubsan] hadrian/rts: add support for building with UndefinedBehaviorSanitizer
Cheng Shao (@TerrorJack)
gitlab at gitlab.haskell.org
Tue Oct 15 22:46:08 UTC 2024
Cheng Shao pushed to branch wip/ubsan at Glasgow Haskell Compiler / GHC
Commits:
0ff36bbb by Cheng Shao at 2024-10-16T00:44:23+02:00
hadrian/rts: add support for building with UndefinedBehaviorSanitizer
- - - - -
2 changed files:
- hadrian/src/Flavour.hs
- rts/rts.cabal
Changes:
=====================================
hadrian/src/Flavour.hs
=====================================
@@ -8,6 +8,7 @@ module Flavour
, splitSections
, enableThreadSanitizer
, enableLateCCS
+ , enableUBSan
, enableDebugInfo, enableTickyGhc
, viaLlvmBackend
, enableProfiledGhc
@@ -50,6 +51,7 @@ flavourTransformers = M.fromList
, "no_split_sections" =: noSplitSections
, "thread_sanitizer" =: enableThreadSanitizer False
, "thread_sanitizer_cmm" =: enableThreadSanitizer True
+ , "ubsan" =: enableUBSan
, "llvm" =: viaLlvmBackend
, "profiled_ghc" =: enableProfiledGhc
, "no_dynamic_ghc" =: disableDynamicGhcPrograms
@@ -239,6 +241,23 @@ enableThreadSanitizer instrumentCmm = addArgs $ notStage0 ? mconcat
]
]
+enableUBSan :: Flavour -> Flavour
+enableUBSan =
+ addArgs $
+ notStage0
+ ? mconcat
+ [ package rts ? builder (Cabal Flags) ? arg "ubsan",
+ builder (Ghc CompileHs) ? arg "-optc-fsanitize=undefined",
+ builder (Ghc CompileCWithGhc) ? arg "-optc-fsanitize=undefined",
+ builder (Ghc CompileCppWithGhc) ? arg "optcxx-fsanitize=undefined",
+ builder (Ghc LinkHs) ? arg "-optc-fsanitize=undefined"
+ <> arg "-optl-fsanitize=undefined"
+ <> arg "-optl-shared-libsan"
+ <> arg "-optl-Wl,-rpath,/usr/lib/llvm-19/lib/clang/19/lib/linux"
+ <> arg "-optl--rtlib=compiler-rt",
+ builder (Cc CompileC) ? arg "-fsanitize=undefined"
+ ]
+
-- | Use the LLVM backend in stages 1 and later.
viaLlvmBackend :: Flavour -> Flavour
viaLlvmBackend = addArgs $ notStage0 ? builder Ghc ? arg "-fllvm"
=====================================
rts/rts.cabal
=====================================
@@ -81,6 +81,8 @@ flag thread-sanitizer
mechanism supported by GCC and Clang. See Note [ThreadSanitizer]
in @rts/include/rts/TSANUtils.h at .
default: False
+flag ubsan
+ default: False
library
-- rts is a wired in package and
@@ -190,6 +192,9 @@ library
cc-options: -fsanitize=thread
ld-options: -fsanitize=thread
+ if flag(ubsan)
+ ld-options: -fsanitize=undefined -shared-libsan -Wl,-rpath,/usr/lib/llvm-19/lib/clang/19/lib/linux --rtlib=compiler-rt
+
if os(linux)
-- the RTS depends upon libc. while this dependency is generally
-- implicitly added by `cc`, we must explicitly add it here to ensure
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0ff36bbbbefb7e1184fb0a453cd4e38bdb8b61ec
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0ff36bbbbefb7e1184fb0a453cd4e38bdb8b61ec
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241015/64d2ed3f/attachment-0001.html>
More information about the ghc-commits
mailing list