-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Switch mono to use cmake-detected objcopy #83903
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
Conversation
0ff0fa2
to
0913ff2
Compare
@directhex could you take a look - particularly with an eye toward monoaotcross |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-community |
Azure Pipelines successfully started running 1 pipeline(s). |
Have we validated that binaries are indeed still stripped? We aren't failing the build, at least |
@directhex, I have validated that it is stripping the symbols. It shows up in build logs like this:
(similar to other subsets' builds like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments but looks good otherwise
<ItemGroup> | ||
<_MonoCMakeArgs Include="-DMONO_COMPONENTS_RID=$(TargetOS)-$(TargetArchitecture)" /> | ||
<_MonoCMakeArgs Condition="'$(TargetArchitecture)' == 'wasm'" Include="-DCLR_CMAKE_HOST_ARCH=$(BuildArchitecture)" /> | ||
<_MonoCMakeArgs Condition="'$(TargetArchitecture)' != 'wasm'" Include="-DCLR_CMAKE_HOST_ARCH=$(TargetArchitecture)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment explaining why we have this difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment. It is the case until we completely switch mono to use the common infra.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but it is still not really clear to me why this is different on wasm vs. non-wasm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this existing condition from this same file. There is no comment on line 769 either. Without this, wasm builds fail. So the comment I've added is based on my understanding of the situation. I'm sure there is a better way to elaborate it, but depending on the audience, I guess it will still fall short until we explain everything. 😅
Wasm is always cross-compiled; meaning host
is always different than target
. But when we add build
dimension; i.e. we are in our other cross-compiling environment (e.g. linux-x64
(the system running build.sh
) -> linux-arm64
(for which the cross/aot tools are compiled in stage0) -> wasm (the target emitted by those cross/aot tools in stage 1)) then host
!= target
!= build
holds and it fails wasm builds without this flip.
In coreclr, tools like crossgen2 are built for multi-tagets, so we can do things like crossgen2 --targetarch arm64
on x64 machine. That cuts off the requirement of dealing with the third dimension in build infra. I suppose mono cross/aot tools are not on such multi-target plan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry I didn't realize this was existing code. Looks like this was added in 81724f1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey 81724f1 is some of my best work!
<ItemGroup> | ||
<_MonoCMakeArgs Include="-DMONO_COMPONENTS_RID=$(TargetOS)-$(TargetArchitecture)" /> | ||
<_MonoCMakeArgs Condition="'$(TargetArchitecture)' == 'wasm'" Include="-DCLR_CMAKE_HOST_ARCH=$(BuildArchitecture)" /> | ||
<_MonoCMakeArgs Condition="'$(TargetArchitecture)' != 'wasm'" Include="-DCLR_CMAKE_HOST_ARCH=$(TargetArchitecture)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but it is still not really clear to me why this is different on wasm vs. non-wasm?
SkipUnchangedFiles="true" | ||
Condition="'$(BuildMonoAOTCrossCompilerOnly)' != 'true'" /> | ||
|
||
<Exec Condition="'$(BuildMonoAOTCrossCompilerOnly)' != 'true' and '$(MonoGenerateOffsetsOSGroups)' == '' and ('$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true')" Command="install_name_tool -id @rpath/$(MonoFileName) $(RuntimeBinDir)$(MonoFileName)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you verify that the rpath is correct after this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed this works because we pass -DMONO_SHARED_LIB_NAME=$(MonoSharedLibName)
into cmake now so the filename is correct from the beginning (and thus the rpath).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I mainly relied upon the CI for this one. We switched cmake install
with our wrapper install_with_stripped_symbols
, which is used for all binaries for coreclr, libs and corehost.
Now that you have mentioned it, I tested it on osx-arm64 and otool
gives me the same output before (main) and after (PR):
$ ./build.sh mono -c Release
$ otool -l artifacts/bin/mono/osx.arm64.Release/libcoreclr.dylib
[...]
Load command 4
cmd LC_ID_DYLIB
cmdsize 48
name @rpath/libcoreclr.dylib (offset 24)
time stamp 1 Thu Jan 1 02:00:01 1970
current version 2.0.0
[...]
If the passing CI legs do not indicate that iOS / other targets are in the clear and this testing (on osx-arm64) is not enough, I can try to build for those platforms as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked through the failures on runtime-extra-platforms and none of them seem to be related :)
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
Thank you! |
This got broken by dotnet#83903 and wasn't noticed on the PR because we don't build .frameworks unless you pass `/p:BuildDarwinFrameworks=true`. For .frameworks we need to use a different install command and we also don't need to codesign them, it actually causes an error trying to do so: > /Users/alexander/dev/runtime/artifacts/obj/mono/maccatalyst.x64.Release/mono/mini/Mono.release.framework/Versions/C/Mono.release: code object is not signed at all > In subcomponent: /Users/alexander/dev/runtime/artifacts/obj/mono/maccatalyst.x64.Release/mono/mini/Mono.release.framework/Versions/C/Mono.release.dwarf
This got broken by #83903 and wasn't noticed on the PR because we don't build .frameworks unless you pass `/p:BuildDarwinFrameworks=true`. For .frameworks we need to use a different install command and we also don't need to codesign them, it actually causes an error trying to do so (only on Catalyst though, not on iOS/tvOS for some reason): > /Users/alexander/dev/runtime/artifacts/obj/mono/maccatalyst.x64.Release/mono/mini/Mono.release.framework/Versions/C/Mono.release: code object is not signed at all > In subcomponent: /Users/alexander/dev/runtime/artifacts/obj/mono/maccatalyst.x64.Release/mono/mini/Mono.release.framework/Versions/C/Mono.release.dwarf
This caused mono runtime builds to be stripped at build time, i.e. running ninja causes a stripped mono-sgen to be generated even in debug configuration. |
@vargaz, in |
The problem is that the stripping is done during the build, not the install/publish etc. step, so even the local binaries under 'obj/mono/' are stripped, which shouldn't happen. |
Is there any benefit in having unstripped binary under My point was that this is how the other native binaries built from this repo are treated. Granted it is different than what we had for mono before, but consistent with rest of the repo. |
Building directly under artifacts/obj using ninja avoids the time overhead of running build.sh. |
We use
configuretools.cmake
incoreclr
, nativelibs
(for both runtimes),corehost
andtests
to locate tools most suitable for the selected toolchain. However formono
, we manually specify a hardcoded list ofobjcopy
names which require extra step in each cross Dockerfile (e.g. when distro package provides cross arch binutils and when distro package doesn't provide one). This manual work is redundant and adds complexity for someone working on porting runtime to a new platform or creating a docker image with runtime build prereqs.This PR brings mono to the same plan as rest of the native subsets by re-using
configuretools.cmake
in mono forobjcopy
detection andinstall_with_stripped_symbols
function out offunctions.cmake
, which takes care of stripping the binaries without dealing with platform differences at call-sites.ps - moving mono to fully utilize
configurecompiler.cmake
as rest of the native subsets is ultimate goal, but it is non-trivial to accomplish in a single PR.