Avatar
omochimetaru 1/7/2020 7:37 AM
// c3.swift public protocol P { func foo() -> Int }
7:37 AM
; c3.ll ... @"$s2c31PMp" = constant <{ i32, i32, i32, i32, i32, i32, %swift.protocol_requirement }> <{ i32 65603, ... (edited)
7:38 AM
// c4.cpp #include <stdio.h> #include <stdlib.h> #include <dlfcn.h> int main() { void *handle = dlopen(nullptr, RTLD_LAZY); if (!handle) { printf("dlopen failed: %s\n", dlerror()); return 0; } void *symbol = dlsym(handle, "$s2c31PMp"); if (!symbol) { printf("symbol not found: %s\n", dlerror()); return 0; } int32_t flags = ((int32_t *)symbol)[0]; printf("flags=%d\n", flags); if (dlclose(handle)) { printf("dlclose failed: %s\n", dlerror()); return 0; } return 0; }
7:39 AM
$ clang++ -std=c++14 c4.cpp -c -S -emit-llvm $ ./c4.out flags=65603
7:39 AM
protocol descriptor、直接取れた (edited)