Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Native] Name previously unnamed symbols #5347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
@@ -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)

Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -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
}
@@ -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
@@ -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),
@@ -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,
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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
),