Cheng Shao pushed to branch wip/terrorjack/asan at Glasgow Haskell Compiler / GHC

Commits:

18 changed files:

Changes:

  • .gitlab/generate-ci/gen_ci.hs
    ... ... @@ -162,6 +162,7 @@ data BuildConfig
    162 162
                     , tablesNextToCode :: Bool
    
    163 163
                     , threadSanitiser :: Bool
    
    164 164
                     , ubsan :: Bool
    
    165
    +                , asan :: Bool
    
    165 166
                     , noSplitSections :: Bool
    
    166 167
                     , validateNonmovingGc :: Bool
    
    167 168
                     , textWithSIMDUTF :: Bool
    
    ... ... @@ -173,7 +174,7 @@ configureArgsStr :: BuildConfig -> String
    173 174
     configureArgsStr bc = unwords $
    
    174 175
          ["--enable-unregisterised"| unregisterised bc ]
    
    175 176
       ++ ["--disable-tables-next-to-code" | not (tablesNextToCode bc) ]
    
    176
    -  ++ ["--with-intree-gmp" | Just _ <- pure (crossTarget bc) ]
    
    177
    +  ++ ["--with-intree-gmp" | isJust (crossTarget bc) || ubsan bc || asan bc ]
    
    177 178
       ++ ["--with-system-libffi" | crossTarget bc == Just "wasm32-wasi" ]
    
    178 179
       ++ ["--enable-ipe-data-compression" | withZstd bc ]
    
    179 180
       ++ ["--enable-strict-ghc-toolchain-check"]
    
    ... ... @@ -188,6 +189,7 @@ mkJobFlavour BuildConfig{..} = Flavour buildFlavour opts
    188 189
                [HostFullyStatic | hostFullyStatic] ++
    
    189 190
                [ThreadSanitiser | threadSanitiser] ++
    
    190 191
                [UBSan | ubsan] ++
    
    192
    +           [ASan | asan] ++
    
    191 193
                [NoSplitSections | noSplitSections, buildFlavour == Release ] ++
    
    192 194
                [BootNonmovingGc | validateNonmovingGc ] ++
    
    193 195
                [TextWithSIMDUTF | textWithSIMDUTF]
    
    ... ... @@ -201,11 +203,12 @@ data FlavourTrans =
    201 203
         | HostFullyStatic
    
    202 204
         | ThreadSanitiser
    
    203 205
         | UBSan
    
    206
    +    | ASan
    
    204 207
         | NoSplitSections
    
    205 208
         | BootNonmovingGc
    
    206 209
         | TextWithSIMDUTF
    
    207 210
     
    
    208
    -data BaseFlavour = Release | Validate | SlowValidate deriving Eq
    
    211
    +data BaseFlavour = Release | QuickValidate | Validate | SlowValidate deriving Eq
    
    209 212
     
    
    210 213
     -----------------------------------------------------------------------------
    
    211 214
     -- Build Configurations
    
    ... ... @@ -230,6 +233,7 @@ vanilla = BuildConfig
    230 233
       , tablesNextToCode = True
    
    231 234
       , threadSanitiser = False
    
    232 235
       , ubsan = False
    
    236
    +  , asan = False
    
    233 237
       , noSplitSections = False
    
    234 238
       , validateNonmovingGc = False
    
    235 239
       , textWithSIMDUTF = False
    
    ... ... @@ -283,8 +287,14 @@ llvm = vanilla { llvmBootstrap = True }
    283 287
     tsan :: BuildConfig
    
    284 288
     tsan = vanilla { threadSanitiser = True }
    
    285 289
     
    
    286
    -enableUBSan :: BuildConfig
    
    287
    -enableUBSan = vanilla { withDwarf = True, ubsan = True }
    
    290
    +enableUBSanASan :: BuildConfig
    
    291
    +enableUBSanASan =
    
    292
    +  vanilla
    
    293
    +    { buildFlavour = QuickValidate,
    
    294
    +      withDwarf = True,
    
    295
    +      ubsan = True,
    
    296
    +      asan = True
    
    297
    +    }
    
    288 298
     
    
    289 299
     noTntc :: BuildConfig
    
    290 300
     noTntc = vanilla { tablesNextToCode = False }
    
    ... ... @@ -372,6 +382,7 @@ flavourString :: Flavour -> String
    372 382
     flavourString (Flavour base trans) = base_string base ++ concatMap (("+" ++) . flavour_string) trans
    
    373 383
       where
    
    374 384
         base_string Release = "release"
    
    385
    +    base_string QuickValidate = "quick-validate"
    
    375 386
         base_string Validate = "validate"
    
    376 387
         base_string SlowValidate = "slow-validate"
    
    377 388
     
    
    ... ... @@ -381,6 +392,7 @@ flavourString (Flavour base trans) = base_string base ++ concatMap (("+" ++) . f
    381 392
         flavour_string HostFullyStatic = "host_fully_static"
    
    382 393
         flavour_string ThreadSanitiser = "thread_sanitizer_cmm"
    
    383 394
         flavour_string UBSan = "ubsan"
    
    395
    +    flavour_string ASan = "asan"
    
    384 396
         flavour_string NoSplitSections = "no_split_sections"
    
    385 397
         flavour_string BootNonmovingGc = "boot_nonmoving_gc"
    
    386 398
         flavour_string TextWithSIMDUTF = "text_simdutf"
    
    ... ... @@ -1213,15 +1225,24 @@ fedora_x86 =
    1213 1225
       , hackage_doc_job (disableValidate (standardBuildsWithConfig Amd64 (Linux Fedora43) releaseConfig))
    
    1214 1226
       , disableValidate (standardBuildsWithConfig Amd64 (Linux Fedora43) dwarf)
    
    1215 1227
       , disableValidate (standardBuilds Amd64 (Linux Fedora43))
    
    1216
    -    -- For UBSan jobs, only enable for validate/nightly pipelines.
    
    1217
    -    -- Also disable docs since it's not the point for UBSan jobs.
    
    1228
    +    -- For UBSan/ASan jobs, only enable for validate/nightly
    
    1229
    +    -- pipelines. Also disable docs since it's not the point for
    
    1230
    +    -- UBSan/ASan jobs.
    
    1231
    +    --
    
    1232
    +    -- See
    
    1233
    +    -- https://github.com/llvm/llvm-project/blob/llvmorg-21.1.8/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
    
    1234
    +    -- for ASAN options help, for now these are required to pass the
    
    1235
    +    -- testsuite
    
    1218 1236
       , modifyJobs
    
    1219 1237
           ( setVariable "HADRIAN_ARGS" "--docs=none"
    
    1220 1238
               . addVariable
    
    1221 1239
                 "UBSAN_OPTIONS"
    
    1222 1240
                 "suppressions=$CI_PROJECT_DIR/rts/.ubsan-suppressions"
    
    1241
    +          . addVariable
    
    1242
    +            "ASAN_OPTIONS"
    
    1243
    +            "detect_leaks=false:handle_segv=0:handle_sigfpe=0:verify_asan_link_order=false"
    
    1223 1244
           )
    
    1224
    -      $ validateBuilds Amd64 (Linux Fedora43) enableUBSan
    
    1245
    +      $ validateBuilds Amd64 (Linux Fedora43) enableUBSanASan
    
    1225 1246
       ]
    
    1226 1247
       where
    
    1227 1248
         hackage_doc_job = rename (<> "-hackage") . modifyJobs (addVariable "HADRIAN_ARGS" "--haddock-for-hackage")
    

  • .gitlab/jobs.yaml
    ... ... @@ -2942,7 +2942,7 @@
    2942 2942
           "XZ_OPT": "-9"
    
    2943 2943
         }
    
    2944 2944
       },
    
    2945
    -  "nightly-x86_64-linux-fedora43-release": {
    
    2945
    +  "nightly-x86_64-linux-fedora43-quick-validate+debug_info+ubsan+asan": {
    
    2946 2946
         "after_script": [
    
    2947 2947
           ".gitlab/ci.sh save_cache",
    
    2948 2948
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -2953,7 +2953,7 @@
    2953 2953
         "artifacts": {
    
    2954 2954
           "expire_in": "8 weeks",
    
    2955 2955
           "paths": [
    
    2956
    -        "ghc-x86_64-linux-fedora43-release.tar.xz",
    
    2956
    +        "ghc-x86_64-linux-fedora43-quick-validate+debug_info+ubsan+asan.tar.xz",
    
    2957 2957
             "junit.xml",
    
    2958 2958
             "unexpected-test-output.tar.gz"
    
    2959 2959
           ],
    
    ... ... @@ -2995,17 +2995,20 @@
    2995 2995
           "x86_64-linux"
    
    2996 2996
         ],
    
    2997 2997
         "variables": {
    
    2998
    +      "ASAN_OPTIONS": "detect_leaks=false:handle_segv=0:handle_sigfpe=0:verify_asan_link_order=false",
    
    2998 2999
           "BIGNUM_BACKEND": "gmp",
    
    2999
    -      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-release",
    
    3000
    -      "BUILD_FLAVOUR": "release",
    
    3001
    -      "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3000
    +      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-quick-validate+debug_info+ubsan+asan",
    
    3001
    +      "BUILD_FLAVOUR": "quick-validate+debug_info+ubsan+asan",
    
    3002
    +      "CONFIGURE_ARGS": "--with-intree-gmp --enable-strict-ghc-toolchain-check",
    
    3003
    +      "HADRIAN_ARGS": "--docs=none",
    
    3002 3004
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3003 3005
           "RUNTEST_ARGS": "",
    
    3004
    -      "TEST_ENV": "x86_64-linux-fedora43-release",
    
    3006
    +      "TEST_ENV": "x86_64-linux-fedora43-quick-validate+debug_info+ubsan+asan",
    
    3007
    +      "UBSAN_OPTIONS": "suppressions=$CI_PROJECT_DIR/rts/.ubsan-suppressions",
    
    3005 3008
           "XZ_OPT": "-9"
    
    3006 3009
         }
    
    3007 3010
       },
    
    3008
    -  "nightly-x86_64-linux-fedora43-release-hackage": {
    
    3011
    +  "nightly-x86_64-linux-fedora43-release": {
    
    3009 3012
         "after_script": [
    
    3010 3013
           ".gitlab/ci.sh save_cache",
    
    3011 3014
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -3062,14 +3065,13 @@
    3062 3065
           "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-release",
    
    3063 3066
           "BUILD_FLAVOUR": "release",
    
    3064 3067
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3065
    -      "HADRIAN_ARGS": "--haddock-for-hackage",
    
    3066 3068
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3067 3069
           "RUNTEST_ARGS": "",
    
    3068 3070
           "TEST_ENV": "x86_64-linux-fedora43-release",
    
    3069 3071
           "XZ_OPT": "-9"
    
    3070 3072
         }
    
    3071 3073
       },
    
    3072
    -  "nightly-x86_64-linux-fedora43-validate": {
    
    3074
    +  "nightly-x86_64-linux-fedora43-release-hackage": {
    
    3073 3075
         "after_script": [
    
    3074 3076
           ".gitlab/ci.sh save_cache",
    
    3075 3077
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -3080,7 +3082,7 @@
    3080 3082
         "artifacts": {
    
    3081 3083
           "expire_in": "8 weeks",
    
    3082 3084
           "paths": [
    
    3083
    -        "ghc-x86_64-linux-fedora43-validate.tar.xz",
    
    3085
    +        "ghc-x86_64-linux-fedora43-release.tar.xz",
    
    3084 3086
             "junit.xml",
    
    3085 3087
             "unexpected-test-output.tar.gz"
    
    3086 3088
           ],
    
    ... ... @@ -3123,16 +3125,17 @@
    3123 3125
         ],
    
    3124 3126
         "variables": {
    
    3125 3127
           "BIGNUM_BACKEND": "gmp",
    
    3126
    -      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate",
    
    3127
    -      "BUILD_FLAVOUR": "validate",
    
    3128
    +      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-release",
    
    3129
    +      "BUILD_FLAVOUR": "release",
    
    3128 3130
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3131
    +      "HADRIAN_ARGS": "--haddock-for-hackage",
    
    3129 3132
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3130 3133
           "RUNTEST_ARGS": "",
    
    3131
    -      "TEST_ENV": "x86_64-linux-fedora43-validate",
    
    3134
    +      "TEST_ENV": "x86_64-linux-fedora43-release",
    
    3132 3135
           "XZ_OPT": "-9"
    
    3133 3136
         }
    
    3134 3137
       },
    
    3135
    -  "nightly-x86_64-linux-fedora43-validate+debug_info": {
    
    3138
    +  "nightly-x86_64-linux-fedora43-validate": {
    
    3136 3139
         "after_script": [
    
    3137 3140
           ".gitlab/ci.sh save_cache",
    
    3138 3141
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -3143,7 +3146,7 @@
    3143 3146
         "artifacts": {
    
    3144 3147
           "expire_in": "8 weeks",
    
    3145 3148
           "paths": [
    
    3146
    -        "ghc-x86_64-linux-fedora43-validate+debug_info.tar.xz",
    
    3149
    +        "ghc-x86_64-linux-fedora43-validate.tar.xz",
    
    3147 3150
             "junit.xml",
    
    3148 3151
             "unexpected-test-output.tar.gz"
    
    3149 3152
           ],
    
    ... ... @@ -3186,16 +3189,16 @@
    3186 3189
         ],
    
    3187 3190
         "variables": {
    
    3188 3191
           "BIGNUM_BACKEND": "gmp",
    
    3189
    -      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate+debug_info",
    
    3190
    -      "BUILD_FLAVOUR": "validate+debug_info",
    
    3192
    +      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate",
    
    3193
    +      "BUILD_FLAVOUR": "validate",
    
    3191 3194
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3192 3195
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3193 3196
           "RUNTEST_ARGS": "",
    
    3194
    -      "TEST_ENV": "x86_64-linux-fedora43-validate+debug_info",
    
    3197
    +      "TEST_ENV": "x86_64-linux-fedora43-validate",
    
    3195 3198
           "XZ_OPT": "-9"
    
    3196 3199
         }
    
    3197 3200
       },
    
    3198
    -  "nightly-x86_64-linux-fedora43-validate+debug_info+ubsan": {
    
    3201
    +  "nightly-x86_64-linux-fedora43-validate+debug_info": {
    
    3199 3202
         "after_script": [
    
    3200 3203
           ".gitlab/ci.sh save_cache",
    
    3201 3204
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -3206,7 +3209,7 @@
    3206 3209
         "artifacts": {
    
    3207 3210
           "expire_in": "8 weeks",
    
    3208 3211
           "paths": [
    
    3209
    -        "ghc-x86_64-linux-fedora43-validate+debug_info+ubsan.tar.xz",
    
    3212
    +        "ghc-x86_64-linux-fedora43-validate+debug_info.tar.xz",
    
    3210 3213
             "junit.xml",
    
    3211 3214
             "unexpected-test-output.tar.gz"
    
    3212 3215
           ],
    
    ... ... @@ -3249,14 +3252,12 @@
    3249 3252
         ],
    
    3250 3253
         "variables": {
    
    3251 3254
           "BIGNUM_BACKEND": "gmp",
    
    3252
    -      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate+debug_info+ubsan",
    
    3253
    -      "BUILD_FLAVOUR": "validate+debug_info+ubsan",
    
    3255
    +      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate+debug_info",
    
    3256
    +      "BUILD_FLAVOUR": "validate+debug_info",
    
    3254 3257
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3255
    -      "HADRIAN_ARGS": "--docs=none",
    
    3256 3258
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3257 3259
           "RUNTEST_ARGS": "",
    
    3258
    -      "TEST_ENV": "x86_64-linux-fedora43-validate+debug_info+ubsan",
    
    3259
    -      "UBSAN_OPTIONS": "suppressions=$CI_PROJECT_DIR/rts/.ubsan-suppressions",
    
    3260
    +      "TEST_ENV": "x86_64-linux-fedora43-validate+debug_info",
    
    3260 3261
           "XZ_OPT": "-9"
    
    3261 3262
         }
    
    3262 3263
       },
    
    ... ... @@ -7097,7 +7098,7 @@
    7097 7098
           "TEST_ENV": "x86_64-linux-deb9-validate"
    
    7098 7099
         }
    
    7099 7100
       },
    
    7100
    -  "x86_64-linux-fedora43-release": {
    
    7101
    +  "x86_64-linux-fedora43-quick-validate+debug_info+ubsan+asan": {
    
    7101 7102
         "after_script": [
    
    7102 7103
           ".gitlab/ci.sh save_cache",
    
    7103 7104
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -7108,7 +7109,7 @@
    7108 7109
         "artifacts": {
    
    7109 7110
           "expire_in": "2 weeks",
    
    7110 7111
           "paths": [
    
    7111
    -        "ghc-x86_64-linux-fedora43-release.tar.xz",
    
    7112
    +        "ghc-x86_64-linux-fedora43-quick-validate+debug_info+ubsan+asan.tar.xz",
    
    7112 7113
             "junit.xml",
    
    7113 7114
             "unexpected-test-output.tar.gz"
    
    7114 7115
           ],
    
    ... ... @@ -7134,7 +7135,7 @@
    7134 7135
         ],
    
    7135 7136
         "rules": [
    
    7136 7137
           {
    
    7137
    -        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-release(\\s|$).*/)) || (($ONLY_JOBS == null) && ((\"true\" == \"true\")))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7138
    +        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-quick-validate\\+debug_info\\+ubsan\\+asan(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7138 7139
             "when": "on_success"
    
    7139 7140
           }
    
    7140 7141
         ],
    
    ... ... @@ -7150,16 +7151,19 @@
    7150 7151
           "x86_64-linux"
    
    7151 7152
         ],
    
    7152 7153
         "variables": {
    
    7154
    +      "ASAN_OPTIONS": "detect_leaks=false:handle_segv=0:handle_sigfpe=0:verify_asan_link_order=false",
    
    7153 7155
           "BIGNUM_BACKEND": "gmp",
    
    7154
    -      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-release",
    
    7155
    -      "BUILD_FLAVOUR": "release",
    
    7156
    -      "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7156
    +      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-quick-validate+debug_info+ubsan+asan",
    
    7157
    +      "BUILD_FLAVOUR": "quick-validate+debug_info+ubsan+asan",
    
    7158
    +      "CONFIGURE_ARGS": "--with-intree-gmp --enable-strict-ghc-toolchain-check",
    
    7159
    +      "HADRIAN_ARGS": "--docs=none",
    
    7157 7160
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7158 7161
           "RUNTEST_ARGS": "",
    
    7159
    -      "TEST_ENV": "x86_64-linux-fedora43-release"
    
    7162
    +      "TEST_ENV": "x86_64-linux-fedora43-quick-validate+debug_info+ubsan+asan",
    
    7163
    +      "UBSAN_OPTIONS": "suppressions=$CI_PROJECT_DIR/rts/.ubsan-suppressions"
    
    7160 7164
         }
    
    7161 7165
       },
    
    7162
    -  "x86_64-linux-fedora43-release-hackage": {
    
    7166
    +  "x86_64-linux-fedora43-release": {
    
    7163 7167
         "after_script": [
    
    7164 7168
           ".gitlab/ci.sh save_cache",
    
    7165 7169
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -7196,7 +7200,7 @@
    7196 7200
         ],
    
    7197 7201
         "rules": [
    
    7198 7202
           {
    
    7199
    -        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-release(\\s|$).*/)) || (($ONLY_JOBS == null) && (\"disabled\" != \"disabled\"))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7203
    +        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-release(\\s|$).*/)) || (($ONLY_JOBS == null) && ((\"true\" == \"true\")))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7200 7204
             "when": "on_success"
    
    7201 7205
           }
    
    7202 7206
         ],
    
    ... ... @@ -7216,13 +7220,12 @@
    7216 7220
           "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-release",
    
    7217 7221
           "BUILD_FLAVOUR": "release",
    
    7218 7222
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7219
    -      "HADRIAN_ARGS": "--haddock-for-hackage",
    
    7220 7223
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7221 7224
           "RUNTEST_ARGS": "",
    
    7222 7225
           "TEST_ENV": "x86_64-linux-fedora43-release"
    
    7223 7226
         }
    
    7224 7227
       },
    
    7225
    -  "x86_64-linux-fedora43-validate": {
    
    7228
    +  "x86_64-linux-fedora43-release-hackage": {
    
    7226 7229
         "after_script": [
    
    7227 7230
           ".gitlab/ci.sh save_cache",
    
    7228 7231
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -7233,7 +7236,7 @@
    7233 7236
         "artifacts": {
    
    7234 7237
           "expire_in": "2 weeks",
    
    7235 7238
           "paths": [
    
    7236
    -        "ghc-x86_64-linux-fedora43-validate.tar.xz",
    
    7239
    +        "ghc-x86_64-linux-fedora43-release.tar.xz",
    
    7237 7240
             "junit.xml",
    
    7238 7241
             "unexpected-test-output.tar.gz"
    
    7239 7242
           ],
    
    ... ... @@ -7259,7 +7262,7 @@
    7259 7262
         ],
    
    7260 7263
         "rules": [
    
    7261 7264
           {
    
    7262
    -        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && (\"disabled\" != \"disabled\"))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7265
    +        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-release(\\s|$).*/)) || (($ONLY_JOBS == null) && (\"disabled\" != \"disabled\"))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7263 7266
             "when": "on_success"
    
    7264 7267
           }
    
    7265 7268
         ],
    
    ... ... @@ -7276,15 +7279,16 @@
    7276 7279
         ],
    
    7277 7280
         "variables": {
    
    7278 7281
           "BIGNUM_BACKEND": "gmp",
    
    7279
    -      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate",
    
    7280
    -      "BUILD_FLAVOUR": "validate",
    
    7282
    +      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-release",
    
    7283
    +      "BUILD_FLAVOUR": "release",
    
    7281 7284
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7285
    +      "HADRIAN_ARGS": "--haddock-for-hackage",
    
    7282 7286
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7283 7287
           "RUNTEST_ARGS": "",
    
    7284
    -      "TEST_ENV": "x86_64-linux-fedora43-validate"
    
    7288
    +      "TEST_ENV": "x86_64-linux-fedora43-release"
    
    7285 7289
         }
    
    7286 7290
       },
    
    7287
    -  "x86_64-linux-fedora43-validate+debug_info": {
    
    7291
    +  "x86_64-linux-fedora43-validate": {
    
    7288 7292
         "after_script": [
    
    7289 7293
           ".gitlab/ci.sh save_cache",
    
    7290 7294
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -7295,7 +7299,7 @@
    7295 7299
         "artifacts": {
    
    7296 7300
           "expire_in": "2 weeks",
    
    7297 7301
           "paths": [
    
    7298
    -        "ghc-x86_64-linux-fedora43-validate+debug_info.tar.xz",
    
    7302
    +        "ghc-x86_64-linux-fedora43-validate.tar.xz",
    
    7299 7303
             "junit.xml",
    
    7300 7304
             "unexpected-test-output.tar.gz"
    
    7301 7305
           ],
    
    ... ... @@ -7321,7 +7325,7 @@
    7321 7325
         ],
    
    7322 7326
         "rules": [
    
    7323 7327
           {
    
    7324
    -        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-validate\\+debug_info(\\s|$).*/)) || (($ONLY_JOBS == null) && (\"disabled\" != \"disabled\"))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7328
    +        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && (\"disabled\" != \"disabled\"))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7325 7329
             "when": "on_success"
    
    7326 7330
           }
    
    7327 7331
         ],
    
    ... ... @@ -7338,15 +7342,15 @@
    7338 7342
         ],
    
    7339 7343
         "variables": {
    
    7340 7344
           "BIGNUM_BACKEND": "gmp",
    
    7341
    -      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate+debug_info",
    
    7342
    -      "BUILD_FLAVOUR": "validate+debug_info",
    
    7345
    +      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate",
    
    7346
    +      "BUILD_FLAVOUR": "validate",
    
    7343 7347
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7344 7348
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7345 7349
           "RUNTEST_ARGS": "",
    
    7346
    -      "TEST_ENV": "x86_64-linux-fedora43-validate+debug_info"
    
    7350
    +      "TEST_ENV": "x86_64-linux-fedora43-validate"
    
    7347 7351
         }
    
    7348 7352
       },
    
    7349
    -  "x86_64-linux-fedora43-validate+debug_info+ubsan": {
    
    7353
    +  "x86_64-linux-fedora43-validate+debug_info": {
    
    7350 7354
         "after_script": [
    
    7351 7355
           ".gitlab/ci.sh save_cache",
    
    7352 7356
           ".gitlab/ci.sh save_test_output",
    
    ... ... @@ -7357,7 +7361,7 @@
    7357 7361
         "artifacts": {
    
    7358 7362
           "expire_in": "2 weeks",
    
    7359 7363
           "paths": [
    
    7360
    -        "ghc-x86_64-linux-fedora43-validate+debug_info+ubsan.tar.xz",
    
    7364
    +        "ghc-x86_64-linux-fedora43-validate+debug_info.tar.xz",
    
    7361 7365
             "junit.xml",
    
    7362 7366
             "unexpected-test-output.tar.gz"
    
    7363 7367
           ],
    
    ... ... @@ -7383,7 +7387,7 @@
    7383 7387
         ],
    
    7384 7388
         "rules": [
    
    7385 7389
           {
    
    7386
    -        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-validate\\+debug_info\\+ubsan(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7390
    +        "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-validate\\+debug_info(\\s|$).*/)) || (($ONLY_JOBS == null) && (\"disabled\" != \"disabled\"))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
    
    7387 7391
             "when": "on_success"
    
    7388 7392
           }
    
    7389 7393
         ],
    
    ... ... @@ -7400,14 +7404,12 @@
    7400 7404
         ],
    
    7401 7405
         "variables": {
    
    7402 7406
           "BIGNUM_BACKEND": "gmp",
    
    7403
    -      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate+debug_info+ubsan",
    
    7404
    -      "BUILD_FLAVOUR": "validate+debug_info+ubsan",
    
    7407
    +      "BIN_DIST_NAME": "ghc-x86_64-linux-fedora43-validate+debug_info",
    
    7408
    +      "BUILD_FLAVOUR": "validate+debug_info",
    
    7405 7409
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7406
    -      "HADRIAN_ARGS": "--docs=none",
    
    7407 7410
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7408 7411
           "RUNTEST_ARGS": "",
    
    7409
    -      "TEST_ENV": "x86_64-linux-fedora43-validate+debug_info+ubsan",
    
    7410
    -      "UBSAN_OPTIONS": "suppressions=$CI_PROJECT_DIR/rts/.ubsan-suppressions"
    
    7412
    +      "TEST_ENV": "x86_64-linux-fedora43-validate+debug_info"
    
    7411 7413
         }
    
    7412 7414
       },
    
    7413 7415
       "x86_64-linux-rocky8-validate": {
    

  • hadrian/doc/flavours.md
    ... ... @@ -242,6 +242,10 @@ The supported transformers are listed below:
    242 242
             <td><code>ubsan</code></td>
    
    243 243
             <td>Build all stage1+ C/C++ code with UndefinedBehaviorSanitizer support</td>
    
    244 244
         </tr>
    
    245
    +    <tr>
    
    246
    +        <td><code>asan</code></td>
    
    247
    +        <td>Build all stage1+ C/C++ code with AddressSanitizer support</td>
    
    248
    +    </tr>
    
    245 249
         <tr>
    
    246 250
             <td><code>llvm</code></td>
    
    247 251
             <td>Use GHC's LLVM backend (`-fllvm`) for all stage1+ compilation.</td>
    

  • hadrian/src/Flavour.hs
    ... ... @@ -8,6 +8,7 @@ module Flavour
    8 8
       , splitSections
    
    9 9
       , enableThreadSanitizer
    
    10 10
       , enableUBSan
    
    11
    +  , enableASan
    
    11 12
       , enableLateCCS
    
    12 13
       , enableHashUnitIds
    
    13 14
       , enableDebugInfo, enableTickyGhc
    
    ... ... @@ -57,6 +58,7 @@ flavourTransformers = M.fromList
    57 58
         , "thread_sanitizer" =: enableThreadSanitizer False
    
    58 59
         , "thread_sanitizer_cmm" =: enableThreadSanitizer True
    
    59 60
         , "ubsan"            =: enableUBSan
    
    61
    +    , "asan"             =: enableASan
    
    60 62
         , "llvm"             =: viaLlvmBackend
    
    61 63
         , "profiled_ghc"     =: enableProfiledGhc
    
    62 64
         , "no_dynamic_ghc"   =: disableDynamicGhcPrograms
    
    ... ... @@ -306,6 +308,37 @@ enableUBSan =
    306 308
               builder Testsuite ? arg "--config=have_ubsan=True"
    
    307 309
             ]
    
    308 310
     
    
    311
    +-- | Build all stage1+ C/C++ code with AddressSanitizer support:
    
    312
    +-- https://clang.llvm.org/docs/AddressSanitizer.html
    
    313
    +enableASan :: Flavour -> Flavour
    
    314
    +enableASan =
    
    315
    +  addArgs $
    
    316
    +    notStage0
    
    317
    +      ? mconcat
    
    318
    +        [ package rts
    
    319
    +            ? builder (Cabal Flags)
    
    320
    +            ? arg "+asan"
    
    321
    +            <> (needSharedLibSAN ? arg "+shared-libsan"),
    
    322
    +          builder (Ghc CompileHs) ? arg "-optc-fno-omit-frame-pointer"
    
    323
    +            <> arg
    
    324
    +              "-optc-fsanitize=address",
    
    325
    +          builder (Ghc CompileCWithGhc) ? arg "-optc-fno-omit-frame-pointer"
    
    326
    +            <> arg
    
    327
    +              "-optc-fsanitize=address",
    
    328
    +          builder (Ghc CompileCppWithGhc)
    
    329
    +            ? arg "-optcxx-fno-omit-frame-pointer"
    
    330
    +            <> arg "-optcxx-fsanitize=address",
    
    331
    +          builder (Ghc LinkHs)
    
    332
    +            ? arg "-optc-fno-omit-frame-pointer"
    
    333
    +            <> arg "-optc-fsanitize=address"
    
    334
    +            <> arg "-optl-fsanitize=address"
    
    335
    +            <> (needSharedLibSAN ? arg "-optl-shared-libsan"),
    
    336
    +          builder (Cc CompileC) ? arg "-fno-omit-frame-pointer"
    
    337
    +            <> arg
    
    338
    +              "-fsanitize=address",
    
    339
    +          builder Testsuite ? arg "--config=have_asan=True"
    
    340
    +        ]
    
    341
    +
    
    309 342
     -- | Use the LLVM backend in stages 1 and later.
    
    310 343
     viaLlvmBackend :: Flavour -> Flavour
    
    311 344
     viaLlvmBackend = addArgs $ notStage0 ? builder Ghc ? arg "-fllvm"
    

  • rts/Hash.c
    ... ... @@ -283,6 +283,7 @@ allocHashList (HashTable *table)
    283 283
         if (table->freeList != NULL) {
    
    284 284
             HashList *hl = table->freeList;
    
    285 285
             table->freeList = hl->next;
    
    286
    +        __ghc_asan_unpoison_memory_region(hl, offsetof(HashList, next));
    
    286 287
             return hl;
    
    287 288
         } else {
    
    288 289
             /* We allocate one block of memory which contains:
    
    ... ... @@ -302,8 +303,11 @@ allocHashList (HashTable *table)
    302 303
     
    
    303 304
             table->freeList = hl + 1;
    
    304 305
             HashList *p = table->freeList;
    
    305
    -        for (; p < hl + HCHUNK - 1; p++)
    
    306
    +        for (; p < hl + HCHUNK - 1; p++) {
    
    307
    +            __ghc_asan_poison_memory_region(p, offsetof(HashList, next));
    
    306 308
                 p->next = p + 1;
    
    309
    +        }
    
    310
    +        __ghc_asan_poison_memory_region(p, offsetof(HashList, next));
    
    307 311
             p->next = NULL;
    
    308 312
             return hl;
    
    309 313
         }
    
    ... ... @@ -318,6 +322,7 @@ freeHashList (HashTable *table, HashList *hl)
    318 322
         // HashListChunks.
    
    319 323
         hl->next = table->freeList;
    
    320 324
         table->freeList = hl;
    
    325
    +    __ghc_asan_poison_memory_region(hl, offsetof(HashList, next));
    
    321 326
     }
    
    322 327
     
    
    323 328
     STATIC_INLINE void
    
    ... ... @@ -388,9 +393,10 @@ removeHashTable_inlined(HashTable *table, StgWord key, const void *data,
    388 393
                     table->dir[segment][index] = hl->next;
    
    389 394
                 else
    
    390 395
                     prev->next = hl->next;
    
    396
    +            void *hl_data = (void*)hl->data;
    
    391 397
                 freeHashList(table,hl);
    
    392 398
                 table->kcount--;
    
    393
    -            return (void *) hl->data;
    
    399
    +            return hl_data;
    
    394 400
             }
    
    395 401
             prev = hl;
    
    396 402
         }
    

  • rts/Task.c
    ... ... @@ -183,6 +183,7 @@ freeTask (Task *task)
    183 183
             stgFree(incall);
    
    184 184
         }
    
    185 185
         for (incall = task->spare_incalls; incall != NULL; incall = next) {
    
    186
    +        __ghc_asan_unpoison_memory_region(incall, sizeof(InCall));
    
    186 187
             next = incall->next;
    
    187 188
             stgFree(incall);
    
    188 189
         }
    
    ... ... @@ -252,6 +253,7 @@ newInCall (Task *task)
    252 253
     
    
    253 254
         if (task->spare_incalls != NULL) {
    
    254 255
             incall = task->spare_incalls;
    
    256
    +        __ghc_asan_unpoison_memory_region(incall, sizeof(InCall));
    
    255 257
             task->spare_incalls = incall->next;
    
    256 258
             task->n_spare_incalls--;
    
    257 259
         } else {
    
    ... ... @@ -283,6 +285,7 @@ endInCall (Task *task)
    283 285
             stgFree(incall);
    
    284 286
         } else {
    
    285 287
             incall->next = task->spare_incalls;
    
    288
    +        __ghc_asan_poison_memory_region(incall, sizeof(InCall));
    
    286 289
             task->spare_incalls = incall;
    
    287 290
             task->n_spare_incalls++;
    
    288 291
         }
    

  • rts/include/Stg.h
    ... ... @@ -335,6 +335,7 @@ external prototype return neither of these types to workaround #11395.
    335 335
     #include "stg/MachRegsForHost.h"
    
    336 336
     #include "stg/Regs.h"
    
    337 337
     #include "stg/Ticky.h"
    
    338
    +#include "rts/ASANUtils.h"
    
    338 339
     #include "rts/TSANUtils.h"
    
    339 340
     
    
    340 341
     #if IN_STG_CODE
    

  • rts/include/rts/ASANUtils.h
    1
    +#pragma once
    
    2
    +
    
    3
    +#if defined(__SANITIZE_ADDRESS__)
    
    4
    +#define ASAN_ENABLED
    
    5
    +#elif defined(__has_feature)
    
    6
    +#if __has_feature(address_sanitizer)
    
    7
    +#define ASAN_ENABLED
    
    8
    +#endif
    
    9
    +#endif
    
    10
    +
    
    11
    +#if defined(ASAN_ENABLED)
    
    12
    +#include <sanitizer/asan_interface.h>
    
    13
    +#define USED_IF_ASAN
    
    14
    +#else
    
    15
    +#include <stdlib.h>
    
    16
    +#define USED_IF_ASAN __attribute__((unused))
    
    17
    +#endif
    
    18
    +
    
    19
    +static inline void
    
    20
    +__ghc_asan_poison_memory_region(void const volatile *addr USED_IF_ASAN,
    
    21
    +                                size_t size USED_IF_ASAN) {
    
    22
    +#if defined(ASAN_ENABLED)
    
    23
    +  __asan_poison_memory_region(addr, size);
    
    24
    +#endif
    
    25
    +}
    
    26
    +
    
    27
    +static inline void
    
    28
    +__ghc_asan_unpoison_memory_region(void const volatile *addr USED_IF_ASAN,
    
    29
    +                                  size_t size USED_IF_ASAN) {
    
    30
    +#if defined(ASAN_ENABLED)
    
    31
    +  __asan_unpoison_memory_region(addr, size);
    
    32
    +#endif
    
    33
    +}

  • rts/rts.cabal
    ... ... @@ -97,6 +97,12 @@ flag ubsan
    97 97
         UndefinedBehaviorSanitizer.
    
    98 98
       default: False
    
    99 99
       manual: True
    
    100
    +flag asan
    
    101
    +  description:
    
    102
    +    Link with -fsanitize=address, to be enabled when building with
    
    103
    +    AddressSanitizer.
    
    104
    +  default: False
    
    105
    +  manual: True
    
    100 106
     flag shared-libsan
    
    101 107
       description:
    
    102 108
         Link with -shared-libsan, to guarantee only one copy of the
    
    ... ... @@ -216,6 +222,9 @@ library
    216 222
           if flag(ubsan)
    
    217 223
             ld-options: -fsanitize=undefined
    
    218 224
     
    
    225
    +      if flag(asan)
    
    226
    +        ld-options: -fsanitize=address
    
    227
    +
    
    219 228
           if flag(shared-libsan)
    
    220 229
             ld-options: -shared-libsan
    
    221 230
     
    
    ... ... @@ -280,6 +289,7 @@ library
    280 289
                             -- ^ generated
    
    281 290
                             rts/ghc_ffi.h
    
    282 291
                             rts/Adjustor.h
    
    292
    +                        rts/ASANUtils.h
    
    283 293
                             rts/ExecPage.h
    
    284 294
                             rts/BlockSignals.h
    
    285 295
                             rts/Bytecodes.h
    

  • rts/sm/BlockAlloc.c
    ... ... @@ -261,6 +261,8 @@ initGroup(bdescr *head)
    261 261
           head[i].flags = 0;
    
    262 262
       }
    
    263 263
     #endif
    
    264
    +
    
    265
    +  __ghc_asan_unpoison_memory_region(head->start, (W_)head->blocks * BLOCK_SIZE);
    
    264 266
     }
    
    265 267
     
    
    266 268
     #if SIZEOF_VOID_P == SIZEOF_LONG
    
    ... ... @@ -474,6 +476,7 @@ alloc_mega_group (uint32_t node, StgWord mblocks)
    474 476
             bd = alloc_mega_group_from_free_list(&deferred_free_mblock_list[node], n, &best);
    
    475 477
             if(bd)
    
    476 478
             {
    
    479
    +            __ghc_asan_unpoison_memory_region(bd->start, (W_)bd->blocks * BLOCK_SIZE);
    
    477 480
                 return bd;
    
    478 481
             }
    
    479 482
             else if(!best)
    
    ... ... @@ -490,6 +493,7 @@ alloc_mega_group (uint32_t node, StgWord mblocks)
    490 493
     
    
    491 494
         if (bd)
    
    492 495
         {
    
    496
    +        __ghc_asan_unpoison_memory_region(bd->start, (W_)bd->blocks * BLOCK_SIZE);
    
    493 497
             return bd;
    
    494 498
         }
    
    495 499
         else if (best)
    
    ... ... @@ -500,6 +504,7 @@ alloc_mega_group (uint32_t node, StgWord mblocks)
    500 504
                               (best_mblocks-mblocks)*MBLOCK_SIZE);
    
    501 505
     
    
    502 506
             best->blocks = MBLOCK_GROUP_BLOCKS(best_mblocks - mblocks);
    
    507
    +        __ghc_asan_unpoison_memory_region(MBLOCK_ROUND_DOWN(bd), mblocks * MBLOCK_SIZE);
    
    503 508
             initMBlock(MBLOCK_ROUND_DOWN(bd), node);
    
    504 509
         }
    
    505 510
         else
    
    ... ... @@ -878,6 +883,8 @@ free_mega_group (bdescr *mg)
    878 883
     
    
    879 884
             IF_DEBUG(sanity, checkFreeListSanity());
    
    880 885
         }
    
    886
    +
    
    887
    +    __ghc_asan_poison_memory_region(mg->start, (W_)mg->blocks * BLOCK_SIZE);
    
    881 888
     }
    
    882 889
     
    
    883 890
     static void
    
    ... ... @@ -925,6 +932,8 @@ free_deferred_mega_groups (uint32_t node)
    925 932
             // coalesce forwards
    
    926 933
             coalesce_mblocks(mg);
    
    927 934
     
    
    935
    +        __ghc_asan_poison_memory_region(mg->start, (W_)mg->blocks * BLOCK_SIZE);
    
    936
    +
    
    928 937
             // initialize search for next round
    
    929 938
             prev = mg;
    
    930 939
             bd = prev->link;
    
    ... ... @@ -1045,6 +1054,8 @@ freeGroup(bdescr *p)
    1045 1054
       setup_tail(p);
    
    1046 1055
       free_list_insert(node,p);
    
    1047 1056
     
    
    1057
    +  __ghc_asan_poison_memory_region(p->start, (W_)p->blocks * BLOCK_SIZE);
    
    1058
    +
    
    1048 1059
       IF_DEBUG(sanity, checkFreeListSanity());
    
    1049 1060
     }
    
    1050 1061
     
    

  • rts/sm/GCUtils.c
    ... ... @@ -348,6 +348,7 @@ alloc_todo_block (gen_workspace *ws, uint32_t size)
    348 348
             } else {
    
    349 349
                 if (gct->free_blocks) {
    
    350 350
                     bd = gct->free_blocks;
    
    351
    +                __ghc_asan_unpoison_memory_region(bd->start, (W_)bd->blocks * BLOCK_SIZE);
    
    351 352
                     gct->free_blocks = bd->link;
    
    352 353
                 } else {
    
    353 354
                     // We allocate in chunks of at most 16 blocks, use one
    
    ... ... @@ -357,6 +358,9 @@ alloc_todo_block (gen_workspace *ws, uint32_t size)
    357 358
                     StgWord n_blocks = stg_min(chunk_size, 1 << (MBLOCK_SHIFT - BLOCK_SHIFT - 1));
    
    358 359
                     allocBlocks_sync(n_blocks, &bd);
    
    359 360
                     gct->free_blocks = bd->link;
    
    361
    +                for (bdescr *bd = gct->free_blocks; bd; bd = bd->link) {
    
    362
    +                    __ghc_asan_poison_memory_region(bd->start, (W_)bd->blocks * BLOCK_SIZE);
    
    363
    +                }
    
    360 364
                 }
    
    361 365
             }
    
    362 366
             initBdescr(bd, ws->gen, ws->gen->to);
    

  • rts/sm/MBlock.c
    ... ... @@ -579,6 +579,8 @@ getMBlocks(uint32_t n)
    579 579
     
    
    580 580
         ret = getCommittedMBlocks(n);
    
    581 581
     
    
    582
    +    __ghc_asan_unpoison_memory_region(ret, (W_)n * MBLOCK_SIZE);
    
    583
    +
    
    582 584
         debugTrace(DEBUG_gc, "allocated %d megablock(s) at %p",n,ret);
    
    583 585
     
    
    584 586
         mblocks_allocated += n;
    
    ... ... @@ -611,6 +613,8 @@ freeMBlocks(void *addr, uint32_t n)
    611 613
     
    
    612 614
         mblocks_allocated -= n;
    
    613 615
     
    
    616
    +    __ghc_asan_poison_memory_region(addr, (W_)n * MBLOCK_SIZE);
    
    617
    +
    
    614 618
         decommitMBlocks(addr, n);
    
    615 619
     }
    
    616 620
     
    

  • rts/sm/Storage.c
    ... ... @@ -1242,6 +1242,10 @@ start_new_pinned_block(Capability *cap)
    1242 1242
             ACQUIRE_SM_LOCK;
    
    1243 1243
             bd = allocNursery(cap->node, NULL, PINNED_EMPTY_SIZE);
    
    1244 1244
             RELEASE_SM_LOCK;
    
    1245
    +
    
    1246
    +        for (bdescr *pbd = bd; pbd; pbd = pbd->link) {
    
    1247
    +            __ghc_asan_poison_memory_region(pbd->start, (W_)pbd->blocks * BLOCK_SIZE);
    
    1248
    +        }
    
    1245 1249
         }
    
    1246 1250
     
    
    1247 1251
         // Bump up the nursery pointer to avoid the pathological situation
    
    ... ... @@ -1267,6 +1271,7 @@ start_new_pinned_block(Capability *cap)
    1267 1271
         }
    
    1268 1272
     
    
    1269 1273
         cap->pinned_object_empty = bd->link;
    
    1274
    +    __ghc_asan_unpoison_memory_region(bd->start, (W_)bd->blocks * BLOCK_SIZE);
    
    1270 1275
         newNurseryBlock(bd);
    
    1271 1276
         if (bd->link != NULL) {
    
    1272 1277
           bd->link->u.back = cap->pinned_object_empty;
    

  • testsuite/driver/testglobals.py
    ... ... @@ -189,6 +189,9 @@ class TestConfig:
    189 189
             # Are we running with UndefinedBehaviorSanitizer enabled?
    
    190 190
             self.have_ubsan = False
    
    191 191
     
    
    192
    +        # Are we running with AddressSanitizer enabled?
    
    193
    +        self.have_asan = False
    
    194
    +
    
    192 195
             # Do symbols use leading underscores?
    
    193 196
             self.leading_underscore = False
    
    194 197
     
    

  • testsuite/driver/testlib.py
    ... ... @@ -1093,6 +1093,9 @@ def have_thread_sanitizer( ) -> bool:
    1093 1093
     def have_ubsan( ) -> bool:
    
    1094 1094
         return config.have_ubsan
    
    1095 1095
     
    
    1096
    +def have_asan( ) -> bool:
    
    1097
    +    return config.have_asan
    
    1098
    +
    
    1096 1099
     def gcc_as_cmmp() -> bool:
    
    1097 1100
         return config.cmm_cpp_is_gcc
    
    1098 1101
     
    

  • testsuite/tests/ffi/should_run/all.T
    ... ... @@ -192,6 +192,9 @@ test('rts_clearMemory', [
    192 192
          extra_ways(['g1', 'nursery_chunks', 'nonmoving', 'compacting_gc', 'sanity']),
    
    193 193
          # On windows, nonmoving way fails with bad exit code (2816)
    
    194 194
          when(opsys('mingw32'), fragile(23091)),
    
    195
    +     # For simplicity, ASAN poisoning/unpoisoning logic is omitted
    
    196
    +     # from rts_clearMemory implementation
    
    197
    +     when(have_asan(), skip),
    
    195 198
          req_c,
    
    196 199
          pre_cmd('$MAKE -s --no-print-directory rts_clearMemory_setup') ],
    
    197 200
          # Same hack as ffi023
    

  • testsuite/tests/rts/T18623/all.T
    ... ... @@ -8,6 +8,8 @@ test('T18623',
    8 8
          # Recent versions of osx report an error when running `ulimit -v`
    
    9 9
          when(opsys('darwin'), skip),
    
    10 10
          when(arch('powerpc64le'), skip),
    
    11
    +     # ASan can't allocate shadow memory
    
    12
    +     when(have_asan(), skip),
    
    11 13
          cmd_prefix('ulimit -v ' + str(8 * 1024 ** 2) + ' && '),
    
    12 14
          ignore_stdout],
    
    13 15
         run_command,
    

  • testsuite/tests/rts/all.T
    ... ... @@ -105,6 +105,8 @@ def remove_parenthesis(s):
    105 105
         return re.sub(r'\s+\([^)]*\)', '', s)
    
    106 106
     
    
    107 107
     test('outofmem', [ when(opsys('darwin'), skip),
    
    108
    +                   # ASan shadow memory allocation blows up
    
    109
    +                   when(have_asan(), skip),
    
    108 110
                        # this is believed to cause other processes to die
    
    109 111
                        # that happen concurrently while the outofmem test
    
    110 112
                        # runs in CI. As such we'll need to disable it on