Introduce property for relocation mode
This commit is contained in:
committed by
Stanislav Erokhin
parent
3068c230f9
commit
e8e705bf68
+7
-3
@@ -74,9 +74,7 @@ internal class BitcodeCompiler(val context: Context) {
|
||||
else -> configurables.clangNooptFlags
|
||||
})
|
||||
addNonEmpty(BitcodeEmbedding.getClangOptions(context.config))
|
||||
if (determineLinkerOutput(context) == LinkerOutputKind.DYNAMIC_LIBRARY) {
|
||||
addNonEmpty(configurables.clangDynamicFlags)
|
||||
}
|
||||
addNonEmpty(configurables.currentRelocationMode(context).translateToClangCc1Flag())
|
||||
addNonEmpty(profilingFlags)
|
||||
}
|
||||
if (configurables is AppleConfigurables) {
|
||||
@@ -87,6 +85,12 @@ internal class BitcodeCompiler(val context: Context) {
|
||||
return objectFile
|
||||
}
|
||||
|
||||
private fun RelocationModeFlags.Mode.translateToClangCc1Flag() = when (this) {
|
||||
RelocationModeFlags.Mode.PIC -> listOf("-mrelocation-model", "pic")
|
||||
RelocationModeFlags.Mode.STATIC -> listOf("-mrelocation-model", "static")
|
||||
RelocationModeFlags.Mode.DEFAULT -> emptyList()
|
||||
}
|
||||
|
||||
private fun llvmProfilingFlags(): List<String> {
|
||||
val flags = mutableListOf<String>()
|
||||
if (context.shouldProfilePhases()) {
|
||||
|
||||
+16
-5
@@ -6,9 +6,7 @@ import kotlinx.cinterop.ptr
|
||||
import kotlinx.cinterop.value
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.makeVisibilityHiddenLikeLlvmInternalizePass
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.Configurables
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
|
||||
private fun initializeLlvmGlobalPassRegistry() {
|
||||
val passRegistry = LLVMGetGlobalPassRegistry()
|
||||
@@ -90,7 +88,13 @@ private class LlvmPipelineConfiguration(context: Context) {
|
||||
else -> LLVMCodeGenOptLevel.LLVMCodeGenLevelDefault
|
||||
}
|
||||
|
||||
val relocMode: LLVMRelocMode = LLVMRelocMode.LLVMRelocDefault
|
||||
val relocMode: LLVMRelocMode = configurables.currentRelocationMode(context).translateToLlvmRelocMode()
|
||||
|
||||
private fun RelocationModeFlags.Mode.translateToLlvmRelocMode() = when (this) {
|
||||
RelocationModeFlags.Mode.PIC -> LLVMRelocMode.LLVMRelocPIC
|
||||
RelocationModeFlags.Mode.STATIC -> LLVMRelocMode.LLVMRelocStatic
|
||||
RelocationModeFlags.Mode.DEFAULT -> LLVMRelocMode.LLVMRelocDefault
|
||||
}
|
||||
|
||||
val codeModel: LLVMCodeModel = LLVMCodeModel.LLVMCodeModelDefault
|
||||
|
||||
@@ -175,4 +179,11 @@ internal fun runLlvmOptimizationPipeline(context: Context) {
|
||||
if (shouldRunLateBitcodePasses(context)) {
|
||||
runLateBitcodePasses(context, llvmModule)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun RelocationModeFlags.currentRelocationMode(context: Context): RelocationModeFlags.Mode =
|
||||
when (determineLinkerOutput(context)) {
|
||||
LinkerOutputKind.DYNAMIC_LIBRARY -> dynamicLibraryRelocationMode
|
||||
LinkerOutputKind.STATIC_LIBRARY -> staticLibraryRelocationMode
|
||||
LinkerOutputKind.EXECUTABLE -> executableRelocationMode
|
||||
}
|
||||
@@ -87,7 +87,6 @@ clangFlags.macos_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir
|
||||
clangNooptFlags.macos_x64 = -O1
|
||||
clangOptFlags.macos_x64 = -O3
|
||||
clangDebugFlags.macos_x64 = -O0
|
||||
clangDynamicFlags.macos_x64 =
|
||||
|
||||
linkerKonanFlags.macos_x64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 10.15.6
|
||||
linkerOptimizationFlags.macos_x64 = -dead_strip
|
||||
@@ -129,7 +128,6 @@ clangFlags.ios_arm32 = -cc1 -emit-obj -disable-llvm-optzns -x ir
|
||||
clangNooptFlags.ios_arm32 = -O1
|
||||
clangOptFlags.ios_arm32 = -O3
|
||||
clangDebugFlags.ios_arm32 = -O0
|
||||
clangDynamicFlags.ios_arm32 =
|
||||
linkerNoDebugFlags.ios_arm32 = -S
|
||||
linkerDynamicFlags.ios_arm32 = -dylib
|
||||
linkerKonanFlags.ios_arm32 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 14.0
|
||||
@@ -164,7 +162,6 @@ clangOptFlags.ios_arm64 = -O3
|
||||
# Related:
|
||||
# https://github.com/JetBrains/kotlin-native/issues/3290
|
||||
clangDebugFlags.ios_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false
|
||||
clangDynamicFlags.ios_arm64 =
|
||||
|
||||
linkerNoDebugFlags.ios_arm64 = -S
|
||||
linkerDynamicFlags.ios_arm64 = -dylib
|
||||
@@ -192,7 +189,6 @@ clangFlags.ios_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir
|
||||
clangNooptFlags.ios_x64 = -O1
|
||||
clangOptFlags.ios_x64 = -O3
|
||||
clangDebugFlags.ios_x64 = -O0
|
||||
clangDynamicFlags.ios_x64 =
|
||||
|
||||
linkerKonanFlags.ios_x64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 14.0
|
||||
linkerOptimizationFlags.ios_x64 = -dead_strip
|
||||
@@ -219,7 +215,6 @@ clangFlags.tvos_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir
|
||||
clangNooptFlags.tvos_x64 = -O1
|
||||
clangOptFlags.tvos_x64 = -O3
|
||||
clangDebugFlags.tvos_x64 = -O0
|
||||
clangDynamicFlags.tvos_x64 =
|
||||
|
||||
linkerKonanFlags.tvos_x64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 14.0
|
||||
linkerOptimizationFlags.tvos_x64 = -dead_strip
|
||||
@@ -246,7 +241,6 @@ clangFlags.tvos_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir
|
||||
clangNooptFlags.tvos_arm64 = -O1
|
||||
clangOptFlags.tvos_arm64 = -O3
|
||||
clangDebugFlags.tvos_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false
|
||||
clangDynamicFlags.tvos_arm64 =
|
||||
|
||||
linkerNoDebugFlags.tvos_arm64 = -S
|
||||
linkerDynamicFlags.tvos_arm64 = -dylib
|
||||
@@ -273,7 +267,6 @@ clangFlags.watchos_arm32 = -cc1 -emit-obj -disable-llvm-passes -x ir
|
||||
clangNooptFlags.watchos_arm32 = -O1
|
||||
clangOptFlags.watchos_arm32 = -O3
|
||||
clangDebugFlags.watchos_arm32 = -O0
|
||||
clangDynamicFlags.watchos_arm32 =
|
||||
|
||||
linkerKonanFlags.watchos_arm32 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 7.0
|
||||
linkerOptimizationFlags.watchos_arm32 = -dead_strip
|
||||
@@ -303,7 +296,6 @@ clangFlags.watchos_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -mllvm -aar
|
||||
clangNooptFlags.watchos_arm64 = -O1
|
||||
clangOptFlags.watchos_arm64 = -O3
|
||||
clangDebugFlags.watchos_arm64 = -O0
|
||||
clangDynamicFlags.watchos_arm64 =
|
||||
|
||||
linkerKonanFlags.watchos_arm64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 7.0
|
||||
linkerOptimizationFlags.watchos_arm64 = -dead_strip
|
||||
@@ -336,7 +328,6 @@ clangFlags.watchos_x86 = -cc1 -emit-obj -disable-llvm-passes -x ir -target-cpu $
|
||||
clangNooptFlags.watchos_x86 = -O1
|
||||
clangOptFlags.watchos_x86 = -O3
|
||||
clangDebugFlags.watchos_x86 = -O0
|
||||
clangDynamicFlags.watchos_x86 =
|
||||
|
||||
linkerKonanFlags.watchos_x86 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 7.0
|
||||
linkerOptimizationFlags.watchos_x86 = -dead_strip
|
||||
@@ -363,7 +354,6 @@ clangFlags.watchos_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir -target-cpu $
|
||||
clangNooptFlags.watchos_x64 = -O1
|
||||
clangOptFlags.watchos_x64 = -O3
|
||||
clangDebugFlags.watchos_x64 = -O0
|
||||
clangDynamicFlags.watchos_x64 =
|
||||
|
||||
linkerKonanFlags.watchos_x64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 7.0
|
||||
linkerOptimizationFlags.watchos_x64 = -dead_strip
|
||||
@@ -406,7 +396,8 @@ clangFlags.linux_x64 = -cc1 -target-cpu $targetCpu.linux_x64 -emit-obj -disable-
|
||||
clangNooptFlags.linux_x64 = -O1
|
||||
clangOptFlags.linux_x64 = -O3
|
||||
clangDebugFlags.linux_x64 = -O0
|
||||
clangDynamicFlags.linux_x64 = -mrelocation-model pic
|
||||
dynamicLibraryRelocationMode.linux_x64 = pic
|
||||
staticLibraryRelocationMode.linux_x64 = pic
|
||||
linkerKonanFlags.linux_x64 = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread \
|
||||
--defsym __cxa_demangle=Konan_cxa_demangle --gc-sections
|
||||
linkerOptimizationFlags.linux_x64 =
|
||||
@@ -457,7 +448,8 @@ clangFlags.linux_arm32_hfp = -cc1 -target-cpu $targetCpu.linux_arm32_hfp -mfloat
|
||||
clangNooptFlags.linux_arm32_hfp = -O1
|
||||
clangOptFlags.linux_arm32_hfp = -O3 -ffunction-sections
|
||||
clangDebugFlags.linux_arm32_hfp = -O0
|
||||
clangDynamicFlags.linux_arm32_hfp = -mrelocation-model pic
|
||||
dynamicLibraryRelocationMode.linux_arm32_hfp = pic
|
||||
staticLibraryRelocationMode.linux_arm32_hfp = pic
|
||||
dynamicLinker.linux_arm32_hfp = /lib/ld-linux-armhf.so.3
|
||||
# targetSysRoot relative
|
||||
abiSpecificLibraries.linux_arm32_hfp = lib usr/lib
|
||||
@@ -501,7 +493,8 @@ clangFlags.linux_arm64 = -cc1 -target-cpu cortex-a57 -emit-obj -disable-llvm-opt
|
||||
clangNooptFlags.linux_arm64 = -O1
|
||||
clangOptFlags.linux_arm64 = -O3 -ffunction-sections
|
||||
clangDebugFlags.linux_arm64 = -O0
|
||||
clangDynamicFlags.linux_arm64 = -mrelocation-model pic
|
||||
dynamicLibraryRelocationMode.linux_arm64 = pic
|
||||
staticLibraryRelocationMode.linux_arm64 = pic
|
||||
dynamicLinker.linux_arm64 = /lib/ld-linux-aarch64.so.1
|
||||
# targetSysRoot relative
|
||||
abiSpecificLibraries.linux_arm64 = lib usr/lib
|
||||
@@ -535,7 +528,8 @@ clangFlags.linux_mips32 = -cc1 -emit-obj -disable-llvm-optzns -x ir -target-cpu
|
||||
clangNooptFlags.linux_mips32 = -O1
|
||||
clangOptFlags.linux_mips32 = -O3 -ffunction-sections
|
||||
clangDebugFlags.linux_mips32 = -O0
|
||||
clangDynamicFlags.linux_mips32 = -mrelocation-model pic
|
||||
dynamicLibraryRelocationMode.linux_mips32 = pic
|
||||
staticLibraryRelocationMode.linux_mips32 = pic
|
||||
dynamicLinker.linux_mips32 = /lib/ld.so.1
|
||||
# targetSysRoot relative
|
||||
abiSpecificLibraries.linux_mips32 = lib usr/lib
|
||||
@@ -570,7 +564,8 @@ clangFlags.linux_mipsel32 = -cc1 -emit-obj -disable-llvm-optzns -x ir -target-cp
|
||||
clangNooptFlags.linux_mipsel32 = -O1
|
||||
clangOptFlags.linux_mipsel32 = -O3 -ffunction-sections
|
||||
clangDebugFlags.linux_mipsel32 = -O0
|
||||
clangDynamicFlags.linux_mipsel32 = -mrelocation-model pic
|
||||
dynamicLibraryRelocationMode.linux_mipsel32 = pic
|
||||
staticLibraryRelocationMode.linux_mipsel32 = pic
|
||||
dynamicLinker.linux_mipsel32 = /lib/ld.so.1
|
||||
# targetSysRoot relative
|
||||
abiSpecificLibraries.linux_mipsel32 = lib usr/lib
|
||||
|
||||
+21
-3
@@ -18,19 +18,37 @@ package org.jetbrains.kotlin.konan.target
|
||||
|
||||
import org.jetbrains.kotlin.konan.properties.*
|
||||
|
||||
interface ClangFlags : TargetableExternalStorage {
|
||||
interface RelocationModeFlags : TargetableExternalStorage {
|
||||
val dynamicLibraryRelocationMode get() = targetString("dynamicLibraryRelocationMode").mode()
|
||||
val staticLibraryRelocationMode get() = targetString("staticLibraryRelocationMode").mode()
|
||||
val executableRelocationMode get() = targetString("executableRelocationMode").mode()
|
||||
|
||||
private fun String?.mode(): Mode = when (this?.toLowerCase()) {
|
||||
null -> Mode.DEFAULT
|
||||
"pic" -> Mode.PIC
|
||||
"static" -> Mode.STATIC
|
||||
else -> error("Unknown relocation mode: $this")
|
||||
}
|
||||
|
||||
enum class Mode {
|
||||
PIC,
|
||||
STATIC,
|
||||
DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
interface ClangFlags : TargetableExternalStorage, RelocationModeFlags {
|
||||
val clangFlags get() = targetList("clangFlags")
|
||||
val clangNooptFlags get() = targetList("clangNooptFlags")
|
||||
val clangOptFlags get() = targetList("clangOptFlags")
|
||||
val clangDebugFlags get() = targetList("clangDebugFlags")
|
||||
val clangDynamicFlags get() = targetList("clangDynamicFlags")
|
||||
}
|
||||
|
||||
interface LldFlags : TargetableExternalStorage {
|
||||
val lldFlags get() = targetList("lld")
|
||||
}
|
||||
|
||||
interface Configurables : TargetableExternalStorage {
|
||||
interface Configurables : TargetableExternalStorage, RelocationModeFlags {
|
||||
|
||||
val target: KonanTarget
|
||||
|
||||
|
||||
Reference in New Issue
Block a user