Sdk: macOS library validation fails for FFI

Created on 4 Nov 2019  路  4Comments  路  Source: dart-lang/sdk

It looks like https://github.com/dart-lang/sdk/issues/38288 has started happening again.

  1. Clone https://github.com/dart-lang/samples
  2. open the ffi/hello_world sample
  3. run cd c && make dylib
  4. run cd .. && dart hello.dart
  5. observe "Failed to load dynamic library" exception
dart hello.dart 
Unhandled exception:
Invalid argument(s): Failed to load dynamic library (dlopen(hello_world.dylib, 1): no suitable image found.  Did find:
    hello_world.dylib: code signature in (hello_world.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)
#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:10:55)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:17:12)
#2      main (file:///Users/ryjohn/code/github/dart-lang/samples/ffi/hello_world/hello.dart:17:36)
#3      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

cc: @mit-mit @mjohnsullivan

Most helpful comment

I have a slightly different error:

Failed to load dynamic library (dlopen(./hello_library/libhello.dylib, 1): no suitable image found. Did find:
file system relative paths not allowed in hardened programs)

Update:
Fixed with executing
codesign --remove-signature /usr/local/bin/dart

All 4 comments

I've tried using Apple's codesign tool to ad-hoc sign the library, but it's still not working:

codesign -f -s - hello_world.dylib
dart hello.dart 
Unhandled exception:
Invalid argument(s): Failed to load dynamic library (dlopen(hello_world.dylib, 1): no suitable image found.  Did find:
    hello_world.dylib: code signature in (hello_world.dylib) not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?))
#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:10:55)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:17:12)
#2      main (file:///Users/ryjohn/code/github/dart-lang/samples/ffi/hello_world/hello.dart:17:36)
#3      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

cc @dcharkes I think this isn't #38288 , but rather #38314 ?

Yeah, this is a duplicate of #38314, please add more details there.

I have a slightly different error:

Failed to load dynamic library (dlopen(./hello_library/libhello.dylib, 1): no suitable image found. Did find:
file system relative paths not allowed in hardened programs)

Update:
Fixed with executing
codesign --remove-signature /usr/local/bin/dart

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmesserly picture jmesserly  路  3Comments

matanlurey picture matanlurey  路  3Comments

xster picture xster  路  3Comments

DartBot picture DartBot  路  3Comments

DartBot picture DartBot  路  3Comments