Use dlopen/dlsym for CoreSymbolication (#2542)
Linking it directly seems to be inconvenient when producing static lib
This commit is contained in:
committed by
GitHub
parent
a52359fcec
commit
7e55575fbf
+1
-9
@@ -123,15 +123,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
internal val includeBinaries: List<String> =
|
||||
configuration.getList(KonanConfigKeys.INCLUDED_BINARY_FILES)
|
||||
|
||||
internal val defaultSystemLibraries: List<String> = when (target) {
|
||||
KonanTarget.MACOS_X64, KonanTarget.IOS_X64 -> if (debug) {
|
||||
listOf(File(distribution.tbdDirectory(target)).child("CoreSymbolication.tbd").absolutePath)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
else -> emptyList()
|
||||
}
|
||||
internal val defaultSystemLibraries: List<String> = emptyList()
|
||||
|
||||
internal val languageVersionSettings =
|
||||
configuration.get(CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS)!!
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
--- !tapi-tbd-v3
|
||||
archs: [ x86_64 ]
|
||||
uuids: [ 'x86_64: BA456C79-974B-499E-9013-BEDB414FE7B9' ]
|
||||
platform: ios
|
||||
install-name: /System/Library/PrivateFrameworks/CoreSymbolication.framework/CoreSymbolication
|
||||
exports:
|
||||
- archs: [ x86_64 ]
|
||||
symbols: [ _CSIsNull,
|
||||
_CSSourceInfoGetFilename,
|
||||
_CSSourceInfoGetPath,
|
||||
_CSSourceInfoGetLineNumber,
|
||||
_CSSourceInfoGetColumn,
|
||||
_CSSymbolOwnerGetSourceInfoWithAddress,
|
||||
_CSSymbolicatorCreateWithPid,
|
||||
_CSSymbolicatorGetSymbolOwnerWithAddressAtTime ]
|
||||
...
|
||||
@@ -1,16 +0,0 @@
|
||||
--- !tapi-tbd-v3
|
||||
archs: [ x86_64 ]
|
||||
uuids: [ 'x86_64: E996B8F6-929B-4111-A859-EB054C062FE8' ]
|
||||
platform: macosx
|
||||
install-name: /System/Library/PrivateFrameworks/CoreSymbolication.framework/Versions/A/CoreSymbolication
|
||||
exports:
|
||||
- archs: [ x86_64 ]
|
||||
symbols: [ _CSIsNull,
|
||||
_CSSourceInfoGetFilename,
|
||||
_CSSourceInfoGetPath,
|
||||
_CSSourceInfoGetLineNumber,
|
||||
_CSSourceInfoGetColumn,
|
||||
_CSSymbolOwnerGetSourceInfoWithAddress,
|
||||
_CSSymbolicatorCreateWithPid,
|
||||
_CSSymbolicatorGetSymbolOwnerWithAddressAtTime ]
|
||||
...
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#ifdef KONAN_CORE_SYMBOLICATION
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
@@ -41,39 +42,61 @@ typedef unsigned long long CSArchitecture;
|
||||
|
||||
#define kCSNow LONG_MAX
|
||||
|
||||
extern "C" {
|
||||
namespace {
|
||||
|
||||
CSSymbolicatorRef CSSymbolicatorCreateWithPid(pid_t pid);
|
||||
CSSymbolicatorRef (*CSSymbolicatorCreateWithPid)(pid_t pid);
|
||||
|
||||
CSSymbolOwnerRef CSSymbolicatorGetSymbolOwnerWithAddressAtTime(
|
||||
CSSymbolOwnerRef (*CSSymbolicatorGetSymbolOwnerWithAddressAtTime)(
|
||||
CSSymbolicatorRef symbolicator,
|
||||
unsigned long long address,
|
||||
long time
|
||||
);
|
||||
|
||||
CSSourceInfoRef CSSymbolOwnerGetSourceInfoWithAddress(
|
||||
CSSourceInfoRef (*CSSymbolOwnerGetSourceInfoWithAddress)(
|
||||
CSSymbolOwnerRef owner,
|
||||
unsigned long long address
|
||||
);
|
||||
|
||||
|
||||
const char* CSSourceInfoGetPath(CSSourceInfoRef info);
|
||||
const char* (*CSSourceInfoGetPath)(CSSourceInfoRef info);
|
||||
|
||||
uint32_t CSSourceInfoGetLineNumber(CSSourceInfoRef info);
|
||||
uint32_t (*CSSourceInfoGetLineNumber)(CSSourceInfoRef info);
|
||||
|
||||
uint32_t CSSourceInfoGetColumn(CSSourceInfoRef info);
|
||||
uint32_t (*CSSourceInfoGetColumn)(CSSourceInfoRef info);
|
||||
|
||||
|
||||
bool CSIsNull(CSTypeRef);
|
||||
bool (*CSIsNull)(CSTypeRef);
|
||||
|
||||
} // extern "C"
|
||||
CSSymbolicatorRef symbolicator;
|
||||
|
||||
bool TryInitializeCoreSymbolication() {
|
||||
void* cs = dlopen("/System/Library/PrivateFrameworks/CoreSymbolication.framework/CoreSymbolication", RTLD_LAZY);
|
||||
if (!cs) return false;
|
||||
|
||||
#define KONAN_CS_LOOKUP(name) name = (decltype(name)) dlsym(cs, #name); if (!name) return false;
|
||||
|
||||
KONAN_CS_LOOKUP(CSSymbolicatorCreateWithPid)
|
||||
KONAN_CS_LOOKUP(CSSymbolicatorGetSymbolOwnerWithAddressAtTime)
|
||||
KONAN_CS_LOOKUP(CSSymbolOwnerGetSourceInfoWithAddress)
|
||||
KONAN_CS_LOOKUP(CSSourceInfoGetPath)
|
||||
KONAN_CS_LOOKUP(CSSourceInfoGetLineNumber)
|
||||
KONAN_CS_LOOKUP(CSSourceInfoGetColumn)
|
||||
KONAN_CS_LOOKUP(CSIsNull)
|
||||
|
||||
#undef KONAN_CS_LOOKUP
|
||||
|
||||
symbolicator = CSSymbolicatorCreateWithPid(getpid());
|
||||
return !CSIsNull(symbolicator);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" struct SourceInfo Kotlin_getSourceInfo(void* addr) {
|
||||
SourceInfo result = { .fileName = nullptr, .lineNumber = -1, .column = -1 };
|
||||
|
||||
static CSSymbolicatorRef symbolicator = CSSymbolicatorCreateWithPid(getpid());
|
||||
static bool csIsAvailable = TryInitializeCoreSymbolication();
|
||||
|
||||
if (!CSIsNull(symbolicator)) {
|
||||
if (csIsAvailable) {
|
||||
unsigned long long address = static_cast<unsigned long long>((uintptr_t)addr);
|
||||
|
||||
CSSymbolOwnerRef symbolOwner = CSSymbolicatorGetSymbolOwnerWithAddressAtTime(symbolicator, address, kCSNow);
|
||||
|
||||
@@ -75,7 +75,6 @@ class Distribution(
|
||||
val stdlib = "$klib/common/stdlib"
|
||||
|
||||
fun defaultNatives(target: KonanTarget) = "$konanHome/konan/targets/${target.visibleName}/native"
|
||||
fun tbdDirectory(target: KonanTarget) = "$konanHome/konan/targets/${target.visibleName}/tbd"
|
||||
|
||||
fun runtime(target: KonanTarget) = runtimeFileOverride ?: "$stdlib/targets/${target.visibleName}/native/runtime.bc"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user