Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
[codegen][debug info] use single compile unit for compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
vvlevchenko authored Mar 4, 2020
1 parent 7e9f8b5 commit 682d56d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.*
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.util.OperatorNameConventions

internal val contextLLVMSetupPhase = makeKonanModuleOpPhase(
Expand All @@ -33,6 +34,19 @@ internal val contextLLVMSetupPhase = makeKonanModuleOpPhase(
val llvmModule = LLVMModuleCreateWithNameInContext("out", llvmContext)!!
context.llvmModule = llvmModule
context.debugInfo.builder = LLVMCreateDIBuilder(llvmModule)

// 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.
context.debugInfo.compilationUnit = if (context.shouldContainLocationDebugInfo()) DICreateCompilationUnit(
builder = context.debugInfo.builder,
lang = DWARF.language(context.config),
File = File(context.config.outputFile).absolutePath,
dir = "-",
producer = DWARF.producer,
isOptimized = 0,
flags = "",
rv = DWARF.runtimeVersion(context.config)) as DIScopeOpaqueRef?
else null
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ internal class DebugInfo internal constructor(override val context: Context):Con
val inlinedSubprograms = mutableMapOf<IrFunction, DISubprogramRef>()
var builder: DIBuilderRef? = null
var module: DIModuleRef? = null
var compilationUnit: DIScopeOpaqueRef? = null
var objHeaderPointerType: DITypeOpaqueRef? = null
var types = mutableMapOf<IrType, DITypeOpaqueRef>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,20 +504,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
context.llvm.objects.clear()
context.llvm.sharedObjects.clear()

val compilationUnit = if (context.shouldContainLocationDebugInfo()) {
val path = declaration.fileEntry.name.toFileAndFolder()
DICreateCompilationUnit(
builder = context.debugInfo.builder,
lang = DWARF.language(context.config),
File = path.file,
dir = path.folder,
producer = DWARF.producer,
isOptimized = 0,
flags = "",
rv = DWARF.runtimeVersion(context.config))
} else null
@Suppress("UNCHECKED_CAST")
using(FileScope(declaration, compilationUnit as DIScopeOpaqueRef?)) {
using(FileScope(declaration)) {
declaration.acceptChildrenVoid(this)

if (context.llvm.fileInitializers.isEmpty() && context.llvm.objects.isEmpty() && context.llvm.sharedObjects.isEmpty())
Expand Down Expand Up @@ -1768,7 +1756,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE

//-------------------------------------------------------------------------//

private open inner class FileScope(val file: IrFile, private val compilationUnit: DIScopeOpaqueRef? = null) : InnerScopeImpl() {
private open inner class FileScope(val file: IrFile) : InnerScopeImpl() {
override fun fileScope(): CodeContext? = this

override fun location(line: Int, column: Int) = scope()?.let { LocationInfo(it, line, column) }
Expand All @@ -1781,10 +1769,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
}

override fun scope() = scope
fun diCompilationUnit(): DIScopeOpaqueRef? = compilationUnit ?:
(this.outerContext.fileScope() as? FileScope)?.diCompilationUnit() ?:
error("no compilation unit found")

}

//-------------------------------------------------------------------------//
Expand Down Expand Up @@ -1988,7 +1972,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
@Suppress("UNCHECKED_CAST")
private fun diFunctionScope(name: String, linkageName: String, startLine: Int, subroutineType: DISubroutineTypeRef) = DICreateFunction(
builder = context.debugInfo.builder,
scope = (currentCodeContext.fileScope() as FileScope).diCompilationUnit(),
scope = context.debugInfo.compilationUnit,
name = name,
linkageName = linkageName,
file = file().file(),
Expand Down

0 comments on commit 682d56d

Please sign in to comment.