From 4661f6c60b325e0c5519a1613b4021d5cba2a817 Mon Sep 17 00:00:00 2001 From: Mark Mann Date: Wed, 20 Nov 2024 12:24:59 -0800 Subject: [PATCH] [K/N] Add debugCompilationDir option akin to -fdebug-compilation-dir When using -Xdebug-prefix-map in K/N, Apple's linker (ld-prime) seems to discard the produced debug information because of the empty DW_AT_comp_dir value. To mitigate that, there should be a way to modify this value. This commit adds -Xbinary=debugCompilationDir=$dir option, similar to -fdebug-compilation-dir in Clang. The compiler propagates the specified value to DW_AT_comp_dir. ^KT-73306 Fixed --- .../src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt | 2 ++ .../src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt index 7ff5cbc0a6e6f..5438ccc9aea7f 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt @@ -96,6 +96,8 @@ object BinaryOptions : BinaryOptionRegistry() { val preCodegenInlineThreshold by uintOption() val enableDebugTransparentStepping by booleanOption() + + val debugCompilationDir by stringOption() } open class BinaryOption( diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt index 5a040d4df5403..6bd7df8495957 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt @@ -72,7 +72,7 @@ internal class DebugInfo(override val generationState: NativeGenerationState) : // we don't split path to filename and directory to provide enough level uniquely for dsymutil to avoid symbol // clashing, which happens on linking with libraries produced from intercepting sources. File = path.path(), - dir = "", + dir = config.configuration.get(BinaryOptions.debugCompilationDir) ?: "", producer = DWARF.producer, isOptimized = 0, flags = "",