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

Add support for C++/CLI assemblies #676

Closed
sbomer opened this issue Jul 26, 2019 · 4 comments
Closed

Add support for C++/CLI assemblies #676

sbomer opened this issue Jul 26, 2019 · 4 comments
Labels
Milestone

Comments

@sbomer
Copy link
Member

sbomer commented Jul 26, 2019

Currently the linker skips C++/CLI assemblies (see #658), because

  1. it's not aware of native code in mixed-mode assemblies
  2. even for /clr:pure assemblies, cecil may reorder IL data that C++/CLI expects to be preserved (see Wpf applications can't be published as a trimmed single exe #651 (comment)).

As a result, dependencies of the C++/CLI assemblies aren't analyzed, requiring workarounds like dotnet/wpf#1387.

This issue tracks improving the linker's support for C++/CLI assemblies. There are a number of routes we could take:

  • making the linker aware of native code (probably expensive)
  • preserving the ordering of IL data (which would work for /clr:pure assemblies, and probably involves a cecil fix)
  • letting the linker analyze assemblies without modifying them (see Linker removes data from "copy" assemblies #639)
@wli3
Copy link

wli3 commented Sep 12, 2019

Is there any ETA for fixing this error? If it won't make 3.1 we might need to prepare a known issue post

@MichalStrehovsky
Copy link
Member

/clr:pure is now deprecated so there's little point in adding support for that.

The only way how illink would be able to process C++/CLI is if illink was an actual, real, linker (accepting obj files as input).

The produced EXE/DLL doesn't have enough information for illink to safely touch anything in it (the real linker already computed various relative offsets and threw away the relocation information for them). The .NET metadata is in the middle of the executable (in the .rdata section). The .text section precedes it and .data section follows. If illink resizes the .NET metadata in any way, it's going to invalidate all relative offsets within the image that follow the .NET metadata blobs.

I don't see a path to success with this, unless we accept that the file cannot be touched and just append data to it (i.e. we would bloat the file, keeping a dead copy of the old .NET metadata, with the hope that it will allow us to make non-C++ assemblies smaller).

@sbomer
Copy link
Member Author

sbomer commented May 10, 2021

I don't see a path to success with this, unless we accept that the file cannot be touched and just append data to it

Agreed, I think the current plan is to never touch them for the reasons you pointed out, but still analyze them for dependencies (and I don't think we should try to append a metadata copy either). @mateoatr

@vitek-karas
Copy link
Member

Linker now scans C++/CLI assemblies, but it will never modify them. C++/CLI assembly is either removed as a whole, or kept untouched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants
@marek-safar @agocke @sbomer @wli3 @vitek-karas @MichalStrehovsky and others