Skip to content

Commit

Permalink
Name anonymous symbols to make it easier to attribute binary size blo…
Browse files Browse the repository at this point in the history
…at to specific structures
  • Loading branch information
MarkCMann committed Aug 22, 2024
1 parent b693071 commit 970a7c0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import llvm.*
import org.jetbrains.kotlin.backend.konan.NativeGenerationState
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.util.*

private fun ConstPointer.addBits(llvm: CodegenLlvmHelpers, type: LLVMTypeRef, bits: Int): ConstPointer {
val rawPtr = LLVMConstBitCast(this.llvm, llvm.int8PtrType)
Expand Down Expand Up @@ -59,7 +60,7 @@ internal class KotlinStaticData(override val generationState: NativeGenerationSt

val compositeType = llvm.structType(runtime.arrayHeaderType, arrayBody.llvmType)

val global = this.createGlobal(compositeType, "")
val global = this.createGlobal(compositeType, "kconstarray:${arrayClass.fqNameForIrSerialization}")

val objHeaderPtr = global.pointer.getElementPtr(llvm, compositeType, 0)
val arrayHeader = arrayHeader(typeInfo, elements.size)
Expand All @@ -72,7 +73,7 @@ internal class KotlinStaticData(override val generationState: NativeGenerationSt
}

fun createConstKotlinObject(type: IrClass, vararg fields: ConstValue): ConstPointer {
val global = this.placeGlobal("", createConstKotlinObjectBody(type, *fields))
val global = this.placeGlobal("kconstobj:${type.fqNameForIrSerialization}", createConstKotlinObjectBody(type, *fields))
global.setUnnamedAddr(true)
global.setConstant(true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private class DeclarationsGeneratorVisitor(override val generationState: NativeG
it.setLinkage(LLVMLinkage.LLVMCommonLinkage) // Allows to be replaced by other bitcode module.
}
} else {
staticData.createGlobal(writableTypeInfoType, "")
staticData.createGlobal(writableTypeInfoType, "ktypew:${declaration.fqNameForIrSerialization}#internal")
}.also {
it.setZeroInitializer()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ internal class RTTIGenerator(
debugOperationsSize, debugOperations)
}

val result = staticData.placeGlobal("", value)
val result = staticData.placeGlobal("kextendedtypeinfo:$className", value)
result.setConstant(true)
return result.pointer
}
Expand Down Expand Up @@ -503,26 +503,26 @@ internal class RTTIGenerator(

assert(superClass.implementedInterfaces.isEmpty())
val interfaces = (listOf(irClass) + irClass.implementedInterfaces)
val interfacesPtr = staticData.placeGlobalConstArray("",
val interfacesPtr = staticData.placeGlobalConstArray("kinterfacesptr:${irClass.fqNameForIrSerialization}",
pointerType(runtime.typeInfoType), interfaces.map { it.typeInfoPtr })

assert(superClass.declarations.all { it !is IrProperty && it !is IrField })

val objOffsets = getObjOffsets(bodyType)
val objOffsetsPtr = staticData.placeGlobalConstArray("", llvm.int32Type, objOffsets)
val objOffsetsPtr = staticData.placeGlobalConstArray("kobjoffsetsptrs:${irClass.fqNameForIrSerialization}", llvm.int32Type, objOffsets)
val objOffsetsCount = objOffsets.size

val writableTypeInfoType = runtime.writableTypeInfoType
val writableTypeInfo = if (writableTypeInfoType == null) {
null
} else {
staticData.createGlobal(writableTypeInfoType, "")
staticData.createGlobal(writableTypeInfoType, "ktypewsynth:${irClass.fqNameForIrSerialization}")
.also { it.setZeroInitializer() }
.pointer
}
val vtable = vtable(superClass)
val typeInfoWithVtableType = llvm.structType(runtime.typeInfoType, vtable.llvmType)
val typeInfoWithVtableGlobal = staticData.createGlobal(typeInfoWithVtableType, "", isExported = false)
val typeInfoWithVtableGlobal = staticData.createGlobal(typeInfoWithVtableType, "ktypeinfowvtable:${irClass.fqNameForIrSerialization}", isExported = false)
val result = typeInfoWithVtableGlobal.pointer.getElementPtr(llvm, typeInfoWithVtableType, 0)
val typeHierarchyInfo = if (!context.ghaEnabled())
ClassGlobalHierarchyInfo.DUMMY
Expand All @@ -537,7 +537,7 @@ internal class RTTIGenerator(
InterfaceTableRecord(llvm.constInt32(0), llvm.constInt32(0), null)
} else {
val vtableEntries = layoutBuilder.interfaceVTableEntries.map { methodImpls[it]!!.bitcast(llvm.int8PtrType) }
val interfaceVTable = staticData.placeGlobalArray("", llvm.int8PtrType, vtableEntries)
val interfaceVTable = staticData.placeGlobalArray("kitableentries:${irClass.fqNameForIrSerialization}", llvm.int8PtrType, vtableEntries)
val interfaceVTableType = LLVMArrayType(llvm.int8PtrType, vtableEntries.size)!!
InterfaceTableRecord(
llvm.constInt32(layoutBuilder.classId),
Expand All @@ -546,7 +546,7 @@ internal class RTTIGenerator(
)
}
}
val interfaceTablePtr = staticData.placeGlobalConstArray("", runtime.interfaceTableRecordType, interfaceTable)
val interfaceTablePtr = staticData.placeGlobalConstArray("kitablerecs:${irClass.fqNameForIrSerialization}", runtime.interfaceTableRecordType, interfaceTable)

val typeInfoWithVtable = llvm.struct(TypeInfo(
selfPtr = result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,10 @@ internal class ObjCExportCodeGenerator(
val placedInterfaceAdapters = mutableMapOf<String, ConstPointer>()

objCTypeAdapters.forEach { adapter ->
val typeAdapter = staticData.placeGlobal("", adapter).pointer
val typeAdapter = staticData.placeGlobal(
adapter.irClass?.fqNameForIrSerialization.let { "kobjctypeadapter:$it" } ?: "",
adapter
).pointer
val irClass = adapter.irClass

val descriptorToAdapter = if (irClass?.isInterface == true) {
Expand Down Expand Up @@ -606,34 +609,38 @@ internal class ObjCExportCodeGenerator(
vtable,
llvm.constInt32(vtableSize),

staticData.placeGlobalConstArray("", runtime.interfaceTableRecordType, itable),
staticData.placeGlobalConstArray(
irClass?.let {"kitablerecs:${it.fqNameForIrSerialization}" } ?: "",
runtime.interfaceTableRecordType,
itable
),
llvm.constInt32(itableSize),

staticData.cStringLiteral(objCName),

staticData.placeGlobalConstArray(
"",
irClass?.let { "kdirectadapters:${it.fqNameForIrSerialization}" } ?: "",
runtime.objCToKotlinMethodAdapter,
directAdapters
),
llvm.constInt32(directAdapters.size),

staticData.placeGlobalConstArray(
"",
irClass?.let {"kclassadapters:${it.fqNameForIrSerialization}" } ?: "",
runtime.objCToKotlinMethodAdapter,
classAdapters
),
llvm.constInt32(classAdapters.size),

staticData.placeGlobalConstArray(
"",
irClass?.let { "kvirtualadapter:${it.fqNameForIrSerialization}" } ?: "",
runtime.objCToKotlinMethodAdapter,
virtualAdapters
),
llvm.constInt32(virtualAdapters.size),

staticData.placeGlobalConstArray(
"",
irClass?.let { "kreverseadapters:${it.fqNameForIrSerialization}" } ?: "",
runtime.kotlinToObjCMethodAdapter,
reverseAdapters
),
Expand Down

0 comments on commit 970a7c0

Please sign in to comment.