Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple Silicon official runtime build unsigned binaries #46369

Closed
sdmaclea opened this issue Dec 23, 2020 · 6 comments · Fixed by #46435
Closed

Apple Silicon official runtime build unsigned binaries #46369

sdmaclea opened this issue Dec 23, 2020 · 6 comments · Fixed by #46435

Comments

@sdmaclea
Copy link
Contributor

sdmaclea commented Dec 23, 2020

Looking at installer build dotnet-sdk-6.0.100-alpha.1.20623.4-osx-arm64.tar.gz

Runtime Apple Silicon official build has issues.

  • libclrjit.dylib is not built for arm64. This looks like a regression.
  • libhostfxr.dylib signature is corrupt
  • libhostpolicy.dylib signature is corrupt
  • libnethost.dylib signature is corrupt
% for i in $(find . -name \*.dylib)  ./dotnet ./shared/Microsoft.NETCore.App/6.0.0-alpha.1.20622.11//createdump
do 
  file $i
  codesign -v $i
done
                     
./host/fxr/6.0.0-alpha.1.20622.11/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
./host/fxr/6.0.0-alpha.1.20622.11/libhostfxr.dylib: invalid signature (code or signature have been modified)
In architecture: arm64
...
./shared/Microsoft.NETCore.App/6.0.0-alpha.1.20622.11/libhostpolicy.dylib: Mach-O 64-bit dynamically linked shared library arm64
./shared/Microsoft.NETCore.App/6.0.0-alpha.1.20622.11/libhostpolicy.dylib: invalid signature (code or signature have been modified)
In architecture: arm64
...
./shared/Microsoft.NETCore.App/6.0.0-alpha.1.20622.11/libclrjit.dylib: Mach-O 64-bit dynamically linked shared library x86_64
./packs/Microsoft.NETCore.App.Host.osx-arm64/6.0.0-alpha.1.20622.11/runtimes/osx-arm64/native/libnethost.dylib: Mach-O 64-bit dynamically linked shared library arm64
./packs/Microsoft.NETCore.App.Host.osx-arm64/6.0.0-alpha.1.20622.11/runtimes/osx-arm64/native/libnethost.dylib: invalid signature (code or signature have been modified)
In architecture: arm64
...

/cc @mangod9 @janvorli @sandreenko

@ghost
Copy link

ghost commented Dec 23, 2020

Tagging subscribers to this area: @ViktorHofer
See info in area-owners.md if you want to be subscribed.

Issue Details

Looking at installer build dotnet-sdk-6.0.100-alpha.1.20623.4-osx-arm64.tar.gz

Runtime Apple Silicon official build has issues.

  • libclrjit.dylib is not built for arm64. This looks like a regression.
  • libhostfxr.dylib signature is corrupt
  • libhostpolicy.dylib signature is corrupt
  • libnethost.dylib signature is corrupt
% for i in $(find . -name \*.dylib)  ./dotnet ./shared/Microsoft.NETCore.App/6.0.0-alpha.1.20622.11//createdump
do 
  file $i
  codesign -v $i
done
                     
./host/fxr/6.0.0-alpha.1.20622.11/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
./host/fxr/6.0.0-alpha.1.20622.11/libhostfxr.dylib: invalid signature (code or signature have been modified)
In architecture: arm64
...
./shared/Microsoft.NETCore.App/6.0.0-alpha.1.20622.11/libhostpolicy.dylib: Mach-O 64-bit dynamically linked shared library arm64
./shared/Microsoft.NETCore.App/6.0.0-alpha.1.20622.11/libhostpolicy.dylib: invalid signature (code or signature have been modified)
In architecture: arm64
...
./shared/Microsoft.NETCore.App/6.0.0-alpha.1.20622.11/libclrjit.dylib: Mach-O 64-bit dynamically linked shared library x86_64
./packs/Microsoft.NETCore.App.Host.osx-arm64/6.0.0-alpha.1.20622.11/runtimes/osx-arm64/native/libnethost.dylib: Mach-O 64-bit dynamically linked shared library arm64
./packs/Microsoft.NETCore.App.Host.osx-arm64/6.0.0-alpha.1.20622.11/runtimes/osx-arm64/native/libnethost.dylib: invalid signature (code or signature have been modified)
In architecture: arm64
...

/cc @mangod9 @janvorli @sandreenko

Author: sdmaclea
Assignees: sdmaclea
Labels:

arch-arm64, area-Infrastructure, os-mac-os-x-big-sur

Milestone: 6.0.0

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Dec 23, 2020
@sdmaclea
Copy link
Contributor Author

For reference runtime 6.0.0-alpha.1.20622.11 is a545d13

@mangod9 mangod9 removed the untriaged New issue has not been triaged by the area owner label Dec 23, 2020
@sdmaclea
Copy link
Contributor Author

@jkoritzinsky Looks like the incorrect libclrjit.dylib was introduced by #38457.

./build.sh packs -arch arm64 -c release -cross /v:detailed 2>&1 | tee detailed.log
...
  24973    6:3>Target "PublishToDisk" in file "/Users/stmaclea/.nuget/packages/microsoft.dotnet.sharedframework.sdk/6.0.0-beta.20621.12/targets/sharedfx.targets" from 
  24973 project "/Users/stmaclea/git/runtime/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj" (entry point):
  24974        Task "Error" skipped, due to false condition; ('$(OutputPath)' == '') was evaluated as ('/Users/stmaclea/git/runtime/artifacts/obj/Microsoft.NETCore.App
  24974 .Runtime/Release/net6.0/osx-arm64/output/' == '').
  24975        Task "Copy"
  24976          Creating directory 
...
  24983          Copying file from "/Users/stmaclea/git/runtime/artifacts/bin/coreclr/OSX.arm64.Release/sharedFramework/libclrjit.dylib" to "/Users/stmaclea/git/runtim  24983 e/artifacts/obj/Microsoft.NETCore.App.Runtime/Release/net6.0/osx-arm64/output/shared/Microsoft.NETCore.App/6.0.0-dev/libclrjit.dylib".
...
  24993          Copying file from "/Users/stmaclea/git/runtime/artifacts/bin/coreclr/OSX.arm64.Release/x64/sharedFramework/libclrjit.dylib" to "/Users/stmaclea/git/ru  24993 ntime/artifacts/obj/Microsoft.NETCore.App.Runtime/Release/net6.0/osx-arm64/output/shared/Microsoft.NETCore.App/6.0.0-dev/libclrjit.dylib".
...

So it looks like ./src/installer/pkg/sfx/bundle/Microsoft.NETCore.App.Bundle.bundleproj

  <Target Name="PublishToDisk">
    <Error Condition="'$(OutputPath)' == ''" Text="Publishing to disk requires the OutputPath to be set to the root of the path to write to." />

    <MSBuild Projects="@(BundleComponentReference)"
             Targets="PublishToDisk"
             Properties="OutputPath=$(OutputPath)" />
  </Target>

is doing a recursive copy but failing to setup the output directory structure. So it is overwriting the arm64 version of libclrjit.dylib with the cross component version.

This probably affects other runtimes with cross components too.

@sdmaclea
Copy link
Contributor Author

#46434 has fixed the incorrect architecture on libclrjit.dylib

@sdmaclea sdmaclea changed the title Apple Silicon official runtime build has incorrect & unsigned binaries Apple Silicon official runtime build unsigned binaries Dec 26, 2020
@sdmaclea
Copy link
Contributor Author

The signature of a few files are being corrupted during the cmake install of a few dylibs

I was able to work around the issue and get a usable SDK with this command.

for i in $(find ../dotnet-sdk-6.0.100-alpha.1.20625.2-osx-arm64 -name \*.dylib)
do
    # Check the existing signature, if it is not valid force replace the signature with an adhoc signature
    # Note: Requires XCode command line tools 
    codesign -v $i || codesign -f -s - $i
done

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Dec 28, 2020
@sdmaclea
Copy link
Contributor Author

The corrupt signature also affects 6 test libraries.

For these 9 libraries, cmake install() generates a cmake_install.cmake file which includes the code below. (I don't really understand why this only affects 9 libraries).

if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
  file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/corehost" TYPE SHARED_LIBRARY FILES "/Users/stmaclea/git/runtime/artifacts/obj/osx-arm64.Release/cli/hostpolicy/standalone/libhostpolicy.dylib")
  if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/corehost/libhostpolicy.dylib" AND
     NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/corehost/libhostpolicy.dylib")
    execute_process(COMMAND "/usr/bin/install_name_tool"
      -id "libhostpolicy.dylib"
      "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/corehost/libhostpolicy.dylib")
    if(CMAKE_INSTALL_DO_STRIP)
      execute_process(COMMAND "/Applications/Xcode_12_beta_6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip" -x "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/corehost/libhostpolicy.dylib")
    endif()
  endif()
endif()

I believe the changing the id of the library is corrupting the signature. (It could be the strip command, but most of the libraries/programs have this code. Only these nine libraries have the install_name_tool -id command).

I have a draft workaround in #46435.

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Dec 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.