From 1fdb86d51736e07fdd433bdcdacc76cc02c12de4 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Thu, 17 Feb 2022 11:07:26 +0000 Subject: [PATCH] Native: fix loading libllvmstubs.dylib on macOS 12.3 Beta Link libllvmstubs.dylib to `$sysroot/usr/lib/libc++.1.dylib` instead of `$llvm/lib/libc++.1.dylib`. The latter has `@rpath/libc++.1.dylib` as install name, so the dynamic linker was unable to find it when loading libllvmstubs.dylib on macOS 12.3. ^KT-51359 Fixed --- kotlin-native/backend.native/build.gradle | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kotlin-native/backend.native/build.gradle b/kotlin-native/backend.native/build.gradle index 91edbd36f24..07fe73bedd2 100644 --- a/kotlin-native/backend.native/build.gradle +++ b/kotlin-native/backend.native/build.gradle @@ -50,6 +50,17 @@ kotlinNativeInterop { dependsOn ":kotlin-native:llvmCoverageMappingC:${NativePluginKt.lib("coverageMapping")}" defFile 'llvm.def' compilerOpts "-I$llvmDir/include", "-I${rootProject.project(':kotlin-native:llvmDebugInfoC').projectDir}/src/main/include", "-I${rootProject.project(':kotlin-native:llvmCoverageMappingC').projectDir}/src/main/include" + if (isMac()) { + // $llvmDir/lib contains libc++.1.dylib too, and it seems to be preferred by the linker + // over the sysroot-provided one. + // As a result, libllvmstubs.dylib gets linked with $llvmDir/lib/libc++.1.dylib. + // It has install_name = @rpath/libc++.1.dylib, which won't work for us, because + // dynamic loader won't be able to find libc++ when loading libllvmstubs. + // For some reason, this worked fine before macOS 12.3. + // + // To enforce linking with proper libc++, pass the default path explicitly: + linkerOpts "-L${platformManager.hostPlatform.absoluteTargetSysRoot}/usr/lib" + } linkerOpts "-L$llvmDir/lib", "-L${rootProject.project(':kotlin-native:llvmDebugInfoC').buildDir}", "-L${rootProject.project(':kotlin-native:llvmCoverageMappingC').buildDir}" }