Enforce frame pointer for code with debug info on iOS and macOS
To improve call stack scanning in optimized -Xg0 binaries.
This commit is contained in:
committed by
SvyatoslavScherbina
parent
61a19e0ccf
commit
746dcfdb7a
+24
@@ -5,18 +5,25 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan.llvm
|
package org.jetbrains.kotlin.backend.konan.llvm
|
||||||
|
|
||||||
|
import llvm.LLVMAddTargetDependentFunctionAttr
|
||||||
import llvm.LLVMValueRef
|
import llvm.LLVMValueRef
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
import org.jetbrains.kotlin.backend.konan.Context
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.types.isNothing
|
import org.jetbrains.kotlin.ir.types.isNothing
|
||||||
import org.jetbrains.kotlin.ir.util.isThrowable
|
import org.jetbrains.kotlin.ir.util.isThrowable
|
||||||
|
import org.jetbrains.kotlin.konan.target.Family
|
||||||
|
|
||||||
internal fun addLlvmAttributes(context: Context, irFunction: IrFunction, llvmFunction: LLVMValueRef) {
|
internal fun addLlvmAttributes(context: Context, irFunction: IrFunction, llvmFunction: LLVMValueRef) {
|
||||||
if (irFunction.returnType.isNothing()) {
|
if (irFunction.returnType.isNothing()) {
|
||||||
setFunctionNoReturn(llvmFunction)
|
setFunctionNoReturn(llvmFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldEnforceFramePointer(context)) {
|
||||||
|
// Note: this is default for clang on at least on iOS and macOS.
|
||||||
|
enforceFramePointer(llvmFunction)
|
||||||
|
}
|
||||||
|
|
||||||
if (mustNotInline(context, irFunction)) {
|
if (mustNotInline(context, irFunction)) {
|
||||||
setFunctionNoInline(llvmFunction)
|
setFunctionNoInline(llvmFunction)
|
||||||
}
|
}
|
||||||
@@ -32,3 +39,20 @@ private fun mustNotInline(context: Context, irFunction: IrFunction): Boolean {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun shouldEnforceFramePointer(context: Context): Boolean {
|
||||||
|
// TODO: do we still need it?
|
||||||
|
if (!context.shouldOptimize()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return when (context.config.target.family) {
|
||||||
|
Family.OSX, Family.IOS -> context.shouldContainLocationDebugInfo()
|
||||||
|
Family.LINUX, Family.MINGW, Family.ANDROID, Family.WASM, Family.ZEPHYR -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun enforceFramePointer(llvmFunction: LLVMValueRef) {
|
||||||
|
LLVMAddTargetDependentFunctionAttr(llvmFunction, "no-frame-pointer-elim", "true")
|
||||||
|
LLVMAddTargetDependentFunctionAttr(llvmFunction, "no-frame-pointer-elim-non-leaf", "")
|
||||||
|
}
|
||||||
|
|||||||
-5
@@ -371,11 +371,6 @@ private class DeclarationsGeneratorVisitor(override val context: Context) :
|
|||||||
function
|
function
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: do we still need it?
|
|
||||||
if (!context.shouldOptimize()) {
|
|
||||||
LLVMAddTargetDependentFunctionAttr(llvmFunction, "no-frame-pointer-elim", "true")
|
|
||||||
}
|
|
||||||
|
|
||||||
this.functions[declaration] = FunctionLlvmDeclarations(llvmFunction)
|
this.functions[declaration] = FunctionLlvmDeclarations(llvmFunction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user