Repository navigation
Remove metadata token deletion (HAS_DELETE) support - #137789
Conversation
The HAS_DELETE / _Deleted token concept was only reachable through MDUpdateIncremental mode plus IMetaDataEmit::DeleteToken, which nothing in the runtime uses. The read/write importer's filtering of deleted fields was also incorrect when a FieldPtr table reordered fields. - Remove deleted-record filtering from the RW internal importer and the public RegMeta enumerators. - IMetaDataEmit::DeleteToken now returns E_NOTIMPL. - Stop setting HAS_DELETE in incremental update mode. - Reject metadata with HAS_DELETE set unless it is an EnC delta (System.Reflection.Metadata sets the bit on all deltas). Co-authored-by: Copilot <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke |
There was a problem hiding this comment.
🟡 Changes recommended
Normal assemblies can bypass deleted-metadata rejection by setting both HAS_DELETE and DELTA_ONLY, exposing deleted fields; compatibility and test coverage also remain unresolved.
4 open issues
What changed in this PR
Removes legacy HAS_DELETE support from CoreCLR’s metadata engine, superseding the earlier FieldPtr filtering fix.
Changes:
- Removes deleted-record filtering and incremental-mode deletion bookkeeping.
- Makes
IMetaDataEmit::DeleteTokenreturnE_NOTIMPLwhile preserving its interface slot. - Rejects non-delta metadata carrying
HAS_DELETEand adds an image-loading regression test.
| File | Description |
|---|---|
src/tests/reflection/DeletedMetadata/DeletedMetadataRejected.csproj |
Configures the CoreCLR-specific regression test. |
src/tests/reflection/DeletedMetadata/DeletedMetadataRejected.cs |
Builds a raw metadata image and checks load rejection. |
src/coreclr/tools/metainfo/mdinfo.cpp |
Removes the incremental-mode retry. |
src/coreclr/md/runtime/metamodel.cpp |
Adds shared schema rejection with a delta-flag exemption. |
src/coreclr/md/inc/metamodelrw.h |
Removes the HasDelete helper. |
src/coreclr/md/inc/metamodel.h |
Updates the HAS_DELETE comment to describe EnC-only support. |
src/coreclr/md/enc/metamodelrw.cpp |
Removes deletion-related update-mode checks and flag setting. |
src/coreclr/md/enc/mdinternalrw.cpp |
Removes internal deleted-record filtering. |
src/coreclr/md/compiler/regmeta_import.cpp |
Simplifies type-definition enumeration. |
src/coreclr/md/compiler/regmeta_emit.cpp |
Removes deleted-name filtering from global-method marking. |
src/coreclr/md/compiler/import.cpp |
Removes deletion-aware member and permission enumeration. |
src/coreclr/md/compiler/emit.cpp |
Replaces token deletion with E_NOTIMPL. |
src/coreclr/md/compiler/assemblymd.cpp |
Simplifies exported-type enumeration. |
Review effort: Balanced
jkoritzinsky
left a comment
There was a problem hiding this comment.
I believe the _Deleted convention is still used by EnC scenarios, so we might need to keep it for enumerators. We can definitely delete the DeleteToken operation from within the native metadata compiler though.
It should not be #118903 (it never actually worked well). |
|
Missed that. Nice! Happy to be done with this convention! |
GetMDInternalInterface now accepts only the compressed (#~) table stream and returns CLDB_E_FILE_CORRUPT for #-. The read/write metadata model is still used for EnC/Hot Reload: deltas are opened directly with GetInternalWithRWFormat, and EnC modules are converted from #~ via ConvertMDInternalImport. The DAC opens Reflection.Emit module metadata, which the runtime captures in the #- format, through GetInternalWithRWFormat directly. Also remove the obsolete #Schema (ICR) stream handling. Extend the DeletedMetadataRejected test to cover a successful #~ load, #~ with HAS_DELETE, and #- with and without HAS_DELETE. Co-authored-by: Copilot <[email protected]>
Undo the local #- image rejection change. Keep the existing metadata token delection removal change unchanged. Co-authored-by: Copilot <[email protected]>
Reject HAS_DELETE and DELTA_ONLY metadata during ordinary loads. Mark the two EnC delta parsing paths explicitly so delta metadata remains accepted only while an update is being applied. Expand metadata loader tests to cover valid compressed and uncompressed images, rejection of the flags in both formats, and exposure of live and _Deleted-named fields when HAS_DELETE is absent. Isolate the CoreCLR-only test from merged runners and NativeAOT. Co-authored-by: Copilot <[email protected]>
The runtime doesn't use declarative security (the `DeclSecurity` table / permission sets). Only ILASM, which emits `.permissionset`, and ILDASM, which disassembles it, need to read or write them. Both link the `*_ppdb` builds of the metadata engine. This PR gates the PermissionSet implementation behind a new `FEATURE_METADATA_PERMISSION_SETS` define, set only on `mdcompiler_ppdb`, `mdruntime_ppdb` and `mdruntimerw_ppdb`. Every other variant gets the stubs: the runtime (`_wks`), the DAC (`_dac`) and the DBI (`-dbi`). Without the feature: - `IMetaDataImport::EnumPermissionSets` returns an empty enumeration (`S_FALSE`, count 0, null enum handle). - These return `E_NOTIMPL`: - `IMetaDataImport::GetPermissionSetProps` - `IMetaDataEmit::DefinePermissionSet` and `SetPermissionSetProps`, plus the internal `_DefinePermissionSet` and `_SetPermissionSetProps` `GetPermissionSetProps` is removed from the internal `IMDInternalImport` interface. It had no callers, because ILDASM and ILASM use the public `IMetaDataImport`/`IMetaDataEmit` APIs. The `MDInternalRO` and `MDInternalRW` implementations are removed along with it. The cDAC's `IMetaDataImport` already returns `E_NOTIMPL` for the PermissionSet APIs, so it is unaffected. Nothing in `src/coreclr/vm` or `src/coreclr/debug` calls these APIs. ## Behavior change Profilers and debuggers using the public metadata interfaces from the runtime or DBI can no longer see or define permission sets. This needs breaking-change documentation. ## Validation On linux-x64 Checked: - `./build.sh clr.runtime+clr.iltools+clr.corelib -c checked` succeeded. - `build.ninja` sets `FEATURE_METADATA_PERMISSION_SETS` only for the `mdcompiler_ppdb`, `mdruntime_ppdb` and `mdruntimerw_ppdb` objects. - Assembled IL containing `.permissionset` on the assembly, a type and a method with the new `ilasm`. Then ran the new `ildasm` on the output: all three permission sets round-tripped with their blobs intact. I repeated this after removing the internal method. - Ran the same assembly with `corerun`: it executed normally and exited with code 100. The permission-set enumeration in `RegMeta::EnumPermissionSets` also touches code that #137789 modifies, so whichever merges second may need a trivial rebase. > [!NOTE] > This PR description and the code changes were generated with GitHub Copilot. --------- Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The change introduces public metadata API and header compatibility regressions, blocks edit-and-continue delta loading, and inconsistently filters deleted security rows.
4 open issues
4 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The changed metadata enumeration behavior lacks tests for live and historically marked _Deleted records across import options, including reordered FieldPtr entries.
1 open issue
4 resolved since last review
Review effort: Balanced



CoreCLR's metadata engine had a legacy "deleted token" convention: incremental emitters set
HAS_DELETE(0x80),IMetaDataEmit::DeleteTokenrenamed records to_Deleted*or cleared their parent, and importers filtered those records out.The runtime has no callers of
DeleteTokenand does not open scopes inMDUpdateIncrementalmode. Modern EnC does not require the deleted-name convention; see #118903. The filtering also contained aFieldPtrindexing bug addressed separately by #137787. This PR removes the obsolete deletion machinery rather than retaining that special case.Changes
IMetaDataEmit::DeleteTokenreturnE_NOTIMPL, preserving its vtable slot.HAS_DELETEin incremental update mode and remove the associated update-mode rejection andmetainforetry.HAS_DELETEas a reserved, ignored bit. Existing incremental-mode images remain loadable even if they carry this bit.DELTA_ONLY(0x20) outside the internal delta-application path, for both compressed (#~) and uncompressed (#-) metadata. A normal image withHAS_DELETE | DELTA_ONLY(0xA0) is rejected because ofDELTA_ONLY, not because ofHAS_DELETE.COR_DELETED_NAME_*andIsDeletedNamefrom the native headers. These headers are not maintained as stable, backward-compatible public headers.DeletedMetadataFlags, covering successful loads with and withoutHAS_DELETEand rejection withDELTA_ONLY, in both metadata formats.IMetaDataEmit::ApplyEditAndContinuereturnE_NOTIMPL, preserving its vtable slot. There are no in-repository callers of this public API.MetaDataImportOptionGUID andCorImportOptionsdeclarations with their original values, includingMDImportOptionAll = 0xFFFFFFFF.IMetaDataDispenserEx::SetOptionaccepts the option as a validatedVT_UI4no-op, allowing existing callers to requestMDImportOptionAllbefore opening ordinary metadata.Behavior Change
Deleted-record names and markers no longer hide metadata records, and
DeleteTokenreturnsE_NOTIMPL.HAS_DELETEalone does not prevent an image from loading. Ordinary loads rejectDELTA_ONLY.The public
IMetaDataEmit::ApplyEditAndContinueAPI is retired. This is separate from the internalIMDInternalImport::ApplyEditAndContinueAPI used by debugger EnC andMetadataUpdater.ApplyUpdate. Both internal delta readers passfIsDelta = true, so those paths continue accepting EnC deltas, including the 0xA0 flags emitted by System.Reflection.Metadata.Validation
Validated locally on linux-x64 with a Checked runtime:
./build.sh clr.native+clr.iltools -c checked- passed../build.sh clr.corelib+clr.nativecorelib+libs.pretest -rc checked- passed; refreshed stale baseline CoreLib artifacts.src/tests/build.sh -Test profiler/unittest/metadatagetdispenser.csproj x64 checked- passed.src/tests/build.sh -GenerateLayoutOnly x64 checked- passed.corerunfrom its output directory, failed against the pre-change runtime (ApplyEditAndContinuereturnedE_NOINTERFACEinstead ofE_NOTIMPL) and passed against the updated runtime, including settingMDImportOptionDefaultandMDImportOptionAllbefore opening scopes.src/tests/build.sh -Test reflection/DeletedMetadata/DeletedMetadataFlags.csproj x64 checked- passed; the generated test executable passed with exit code 100../build.sh libs.pretest -c Release -rc checked- passed../dotnet.sh build src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj -c Release /t:Test /p:RuntimeConfiguration=Checked '/p:XUnitOptions=-class System.Reflection.Metadata.ApplyUpdateTest'- passed all 24 tests, with no failures or skips.Supersedes #137787.
Note
This PR description and the code changes were generated with GitHub Copilot.