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

NativeAOT descriptor file doesnt generate warnings #73952

Closed
tlakollo opened this issue Aug 15, 2022 · 1 comment
Closed

NativeAOT descriptor file doesnt generate warnings #73952

tlakollo opened this issue Aug 15, 2022 · 1 comment

Comments

@tlakollo
Copy link
Contributor

Description

Descriptor files allow keeping members that otherwise the ilc compiler would have stripped. During this process it inserts nodes (reflectable fields, reflectable methods, etc.) this will indeed keep the members in the final assembly. What the ilc compiler is missing is the generation of warnings when the keep members produce dangerous code.

Reproduction Steps

C# code: Assume the RequiresOnFieldOnlyViaDescriptor class is not going to be kept by the compiler since is never called

[RequiresUnreferencedCode ("Message for --RequiresOnFieldOnlyViaDescriptor--")]
class RequiresOnFieldOnlyViaDescriptor
{
	public static int Field;
}

XML descriptor keeps the type and the field

<linker>
  <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
    <type fullname="RequiresOnFieldOnlyViaDescriptor">
      <field name="Field" />
    </type>
  </assembly>
</linker>

Expected behavior

The ilc compiler should keep the type, the field and warn about the Requires Attribute since the field is static and the class is annotated with RequiresUnreferencedCode

Actual behavior

The type is kept, the field is kept but no warning is produced

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@tlakollo
Copy link
Contributor Author

Given the discussion in dotnet/linker#2103 this scenario should not generate a warning

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

No branches or pull requests

1 participant