[K/N] Fix building mimalloc with TSAN
This commit is contained in:
+14
-4
@@ -102,6 +102,9 @@ abstract class CompileToBitcode @Inject constructor(
|
|||||||
@Input @Optional
|
@Input @Optional
|
||||||
var sanitizer: SanitizerKind? = null
|
var sanitizer: SanitizerKind? = null
|
||||||
|
|
||||||
|
@Input @Optional
|
||||||
|
val extraSanitizerArgs = mutableMapOf<SanitizerKind, List<String>>()
|
||||||
|
|
||||||
private val targetDir: File
|
private val targetDir: File
|
||||||
get() {
|
get() {
|
||||||
val sanitizerSuffix = when (sanitizer) {
|
val sanitizerSuffix = when (sanitizer) {
|
||||||
@@ -136,11 +139,18 @@ abstract class CompileToBitcode @Inject constructor(
|
|||||||
null -> listOf()
|
null -> listOf()
|
||||||
SanitizerKind.ADDRESS -> listOf("-fsanitize=address")
|
SanitizerKind.ADDRESS -> listOf("-fsanitize=address")
|
||||||
SanitizerKind.THREAD -> listOf("-fsanitize=thread")
|
SanitizerKind.THREAD -> listOf("-fsanitize=thread")
|
||||||
}
|
} + (extraSanitizerArgs[sanitizer] ?: emptyList())
|
||||||
val languageFlags = when (language) {
|
val languageFlags = when (language) {
|
||||||
Language.C ->
|
Language.C -> {
|
||||||
// Used flags provided by original build of allocator C code.
|
listOf("-std=gnu11", "-Wall", "-Wextra", "-Werror") +
|
||||||
listOf("-std=gnu11", "-O3", "-Wall", "-Wextra", "-Werror")
|
if (sanitizer != SanitizerKind.THREAD) {
|
||||||
|
// Used flags provided by original build of allocator C code.
|
||||||
|
listOf("-O3")
|
||||||
|
} else {
|
||||||
|
// Building with TSAN needs turning off extra optimizations.
|
||||||
|
listOf("-O1")
|
||||||
|
}
|
||||||
|
}
|
||||||
Language.CPP ->
|
Language.CPP ->
|
||||||
listOfNotNull("-std=c++17", "-Werror", "-O2",
|
listOfNotNull("-std=c++17", "-Werror", "-O2",
|
||||||
"-fno-aligned-allocation", // TODO: Remove when all targets support aligned allocation in C++ runtime.
|
"-fno-aligned-allocation", // TODO: Remove when all targets support aligned allocation in C++ runtime.
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ bitcode {
|
|||||||
compilerArgs.addAll(listOf("-DKONAN_MI_MALLOC=1", "-Wno-unknown-pragmas", "-ftls-model=initial-exec",
|
compilerArgs.addAll(listOf("-DKONAN_MI_MALLOC=1", "-Wno-unknown-pragmas", "-ftls-model=initial-exec",
|
||||||
"-Wno-unused-function", "-Wno-error=atomic-alignment",
|
"-Wno-unused-function", "-Wno-error=atomic-alignment",
|
||||||
"-Wno-unused-parameter" /* for windows 32*/))
|
"-Wno-unused-parameter" /* for windows 32*/))
|
||||||
|
extraSanitizerArgs[SanitizerKind.THREAD] = listOf("-DMI_TSAN=1")
|
||||||
headersDirs = files("$srcRoot/c/include")
|
headersDirs = files("$srcRoot/c/include")
|
||||||
|
|
||||||
onlyIf { targetSupportsMimallocAllocator(target) }
|
onlyIf { targetSupportsMimallocAllocator(target) }
|
||||||
|
|||||||
Reference in New Issue
Block a user