Skip to content

[mono] Initialize module's image ALC for dynamic objects #90731

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

Merged
merged 5 commits into from
Aug 21, 2023

Conversation

kotlarmilos
Copy link
Member

@kotlarmilos kotlarmilos commented Aug 17, 2023

This PR initializes module's image ALC for dynamic objects created during the runtime.

Fixes #90164

@vargaz
Copy link
Contributor

vargaz commented Aug 17, 2023

Maybe we should set the alc of the dynamic images instead ?

@kotlarmilos
Copy link
Member Author

kotlarmilos commented Aug 17, 2023

During initialization, the ALC is set in mono_reflection_dynimage_basic_init to default mono_alc_get_default:

image->image.alc = alc;

When retrieving custom attributes in mono_reflection_get_custom_attrs_by_type_handle, parameter MonoObjectHandle obj seems to be a MonoClass containing an image without ALC. Should the MonoObjectHandle's image contain the ALC?

@lambdageek
Copy link
Member

During initialization, the ALC is set in mono_reflection_dynimage_basic_init to default mono_alc_get_default:

image->image.alc = alc;

When retrieving custom attributes in mono_reflection_get_custom_attrs_by_type_handle, parameter MonoObjectHandle obj seems to be a MonoClass containing an image without ALC. Should the MonoObjectHandle's image contain the ALC?

I wonder if this is because dynamic assemblies have two images - one for the assembly, and one for the image. (this is some old legacy stuff from how the SRE api works). Maybe only the assembly image has an ALC set, but the module image does not? I think the emitted class gets assigned to the module image.

@kotlarmilos kotlarmilos changed the title [mono] Use the image's ALC instead of the default one only if exists [mono] Initialize module's image ALC for dynamic objects Aug 18, 2023
@kotlarmilos
Copy link
Member Author

I wonder if this is because dynamic assemblies have two images - one for the assembly, and one for the image. (this is some old legacy stuff from how the SRE api works). Maybe only the assembly image has an ALC set, but the module image does not? I think the emitted class gets assigned to the module image.

Thanks for pointing out, the module's image ALC wasn't set.

Is there anything we can do to retrieve the image from the assembly, instead of creating a new one for the module?
https://github.com/dotnet/runtime/blob/64243bbf5e9ee53c0c4c5678f2cd8c7f1c9b4f6f/src/mono/mono/metadata/sre.c#L1286C4-L1291

@lambdageek
Copy link
Member

Is there anything we can do to retrieve the image from the assembly, instead of creating a new one for the module?

I haven't thought about it on a while, but I think I convinced myself that it's a consequence of how the SRE public API works and there's no way to avoid it without a bunch of hacks. But maybe it's with another look

@kotlarmilos kotlarmilos merged commit 3c3f499 into dotnet:main Aug 21, 2023
@srxqds
Copy link
Contributor

srxqds commented Aug 22, 2023

why this pr not merged to release/8.0?

@kotlarmilos
Copy link
Member Author

/backport to release/8.0

@github-actions
Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/5935192228

@ghost ghost locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get attributes from objects created on runtime
4 participants