dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.23k stars 1.58k forks source link

Clang from Xcode may crash on Assembly snapshots #38526

Open sjindel-google opened 5 years ago

sjindel-google commented 5 years ago

Crash report from @truongsinh:

 Running Xcode build...                                                  
 ├─Building Dart code...                                    30.8s
 ├─Assembling Flutter resources...                           1.8s
 └─Compiling, linking and signing...                         0.3s
Xcode build done.                                           34.5s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **

Xcode's output:
↳
    === BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Profile ===
    Building AOT snapshot in profile mode (ios-profile)...          
    Building App.framework for arm64...
    ProcessException: Process exited abnormally:
    clang: error: unable to execute command: Segmentation fault: 11
    clang: error: linker command failed due to signal (use -v to see invocation)
      Command: xcrun clang -arch arm64 -miphoneos-version-min=8.0 -dynamiclib -Xlinker -rpath -Xlinker @executable_path/Frameworks
      -Xlinker -rpath -Xlinker @loader_path/Frameworks -install_name @rpath/App.framework/App -o build/aot/arm64/App.framework/App
      build/aot/arm64/snapshot_assembly.o
    cp: build/aot/App.framework: No such file or directory
    cp: /Users/truongsinh/Dev/ml/flutter_realtime_detection/ios/Flutter/App.framework/Info.plist: No such file or directory
    Project /Users/truongsinh/Dev/ml/flutter_realtime_detection built and packaged successfully.
    Command /bin/sh emitted errors but did not return a nonzero exit code to indicate failure
    === BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Profile ===
    ld: framework not found App
    clang: error: linker command failed with exit code 1 (use -v to see invocation).

/cc @mraleph @mkustermann

mraleph commented 5 years ago

As I mentioned I think this is a bug in clang which is triggered by the symbols which we declare in our .S file, e.g. consider removing all the symbols - leaving only only necessary ones.

sjindel-google commented 5 years ago

@truongsinh, please run flutter build profile --verbose >logs 2>&logs and upload the logs, and in addition the .S files which may be discovered via:

find build -name *.S
sjindel-google commented 5 years ago

If you run find build -name *.S in the root directory of your Flutter project, it will list all the files we need.

truongsinh commented 5 years ago

FYI, I have to adjust the command a little bit: flutter build ios --profile --verbose >logs 2>logs

Please find the zipped file, which contains logs file and build/aot/arm64/snapshot_assembly.S in the attachment

Archive.zip

sjindel-google commented 5 years ago

@truongsinh I can reproduce the crash from your archive.

It appears that the error is actually when the compiled static library snapshot_assembly.o is linked into the App. There are 32776 symbols in snapshot_assembly.o, but if I strip it (strip -x), the crash disappears.

Perhaps the linker assumes there are fewer than 2**15 symbols, e.g. by representing symbols with an int16_t.

sjindel-google commented 5 years ago

I don't think the problem is with the number of symbols. Flutter gallery has over 65K, and LD still crashes if I remove just the the Precompiled_* symbols, reducing the symbol count by 31%.

sachaarbonel commented 5 years ago

Hi guys, I have a similar issue (I think) when trying to vendor a static library as mylibrary.a with mylibrary.h (generated with rust cargo-lipo). My bindings work on Android but not ios ( the library has bean loaded) and the error message is Invalid arguments : failed to lookup symbol dlsym(0x10b538ba8,search). My repo