fuzzybinary / dart_shared_library

An attempt to package Dart into a usable shared library (.dll / .so)
Other
77 stars 10 forks source link

dart_dll.h symbols mangled in the exported dylib. #3

Closed modulovalue closed 1 year ago

modulovalue commented 1 year ago

I'm trying to invoke the functions declared in dart_dll.h from a dylib.

It looks like the names are mangled and therefore not visible under the name that the header defines.

modulovalue@MacBook-Air-von-Modestas bin % nm libdart_dll.dylib | grep 'DartDll'
000000000000461c T __Z15DartDll_RunMainP12_Dart_Handle
00000000000048d4 T __Z16DartDll_Shutdownv
000000000000406c T __Z18DartDll_Initializev
00000000000045c0 T __Z18DartDll_LoadScriptPKcS0_
0000000000004790 T __Z27DartDll_DrainMicrotaskQueuev

// Other symbols are not mangled as expected

...
0000000000041d28 T _Dart_LoadLibrary
0000000000041994 T _Dart_LoadLibraryFromKernel
000000000003f0b4 T _Dart_LoadScriptFromKernel
0000000000043d0c T _Dart_LoadingUnitLibraryUris
0000000000041338 T _Dart_LookupLibrary
0000000000036b7c T _Dart_MapContainsKey
0000000000036834 T _Dart_MapGetAt
...

I can invoke the functions under the mangled name (without one leading underscore e.g. _Z18DartDll_Initializev)

I've tried extending the macro in dart_dll.h to make these symbols 'visible' under macos:

#ifdef _WIN
  #ifdef DART_DLL_EXPORTING
    #define DART_DLL_EXPORT __declspec(dllexport)
  #else
    #define DART_DLL_EXPORT __declspec(dllimport)
  #endif
#elif defined(__APPLE__) // <-
  #define DART_DLL_EXPORT __attribute__((visibility("default"))) // <-
#else
  #define DART_DLL_EXPORT
#endif

But that doesn't seem to have any effect i.e. the symbols are still mangled.

I feel like I'm missing something simple here, do you know what it would take to export the actual identifiers that can be found in dart_dll.h?

fuzzybinary commented 1 year ago

This is just C++ name mangling over C. Since all of my examples were C++ they used C++ name mangling and worked properly, but you're right they should be exported with C name mangling.

New updates should now export as C instead of C++.

modulovalue commented 1 year ago

I can confirm that the symbols aren't mangled anymore, thank you again!