You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Trimming locals from a method doesn't remove the locals from the pdb #1260
With change dotnet/runtime#37615, we are introducing some ILLink.Substitutions.xml files that direct the linker to trim branches in IL that will never be called. For example, when building for x64, any if (AdvSimd.IsSupported) branches can be trimmed away, since ARM intrinsics will never be true for x64.
However, Pdb2Pdb is failing in this PR:
System.Private.CoreLib -> F:\workspace\_work\1\s\artifacts\bin\coreclr\Windows_NT.x64.Checked\IL\System.Private.CoreLib.dll
PDB0004: token 0x06001C30: Method containing local variables has no local signature
PDB0004: token 0x06001C30: Method containing local variables has no local signature
PDB0004: token 0x06001C31: Method containing local variables has no local signature
PDB0004: token 0x06001C31: Method containing local variables has no local signature
Error HRESULT E_FAIL has been returned from a call to a COM component.
F:\workspace\_work\1\s\.packages\microsoft.dotnet.arcade.sdk\5.0.0-beta.20280.1\tools\SymStore.targets(70,5): error MSB3073: The command ""F:\workspace\_work\1\s\.packages\microsoft.diasymreader.pdb2pdb\1.1.0-beta2-19575-01\tools\Pdb2Pdb.exe" "F:\workspace\_work\1\s\artifacts\bin\coreclr\Windows_NT.x64.Checked\IL\System.Private.CoreLib.dll" /out "F:\workspace\_work\1\s\artifacts\SymStore\Checked\System.Private.CoreLib\netcoreapp2.1\x64\System.Private.CoreLib.pdb" /srcsvrvar SRC_INDEX=public" exited with code 2. [F:\workspace\_work\1\s\src\coreclr\src\System.Private.CoreLib\System.Private.CoreLib.csproj]
##[error].packages\microsoft.dotnet.arcade.sdk\5.0.0-beta.20280.1\tools\SymStore.targets(70,5): error MSB3073: (NETCORE_ENGINEERING_TELEMETRY=Build) The command ""F:\workspace\_work\1\s\.packages\microsoft.diasymreader.pdb2pdb\1.1.0-beta2-19575-01\tools\Pdb2Pdb.exe" "F:\workspace\_work\1\s\artifacts\bin\coreclr\Windows_NT.x64.Checked\IL\System.Private.CoreLib.dll" /out "F:\workspace\_work\1\s\artifacts\SymStore\Checked\System.Private.CoreLib\netcoreapp2.1\x64\System.Private.CoreLib.pdb" /srcsvrvar SRC_INDEX=public" exited with code 2.
Debugging into Pdb2Pdb.exe, I see the first problem is that we are trimming away locals from this method:
The if (AdvSimd.Arm64.IsSupported) branch is getting trimmed, but it looks like the local variables are not getting removed from the portable .pdb. Here is the code after trimming:
PDB0004: token 0x06001C30: Method containing local variables has no local signature
Is being emitted because Pdb2Pdb is finding local variables in the pdb, but the method doesn't have a "local signature" (since there are no locals in the resulting method).
The ILLinker needs to be removing the locals from the pdbs as well, so tools like Pdb2Pdb still work.
This issue will be about the local variable debug information.
The problem is in CleanRemovedVariables. Linker will remove the local variables from the method body definition, but it will not remove them from debug information. Some tools consuming the PDB will then get confused when reading it as the information in PDB doesn't match the method body.
Fix is to walk all local scopes (even nested ones) and remove variables which are also removed from the body (not replaced with System.Object ones). Since the debug info for local variables only stores name and some special flags, rewriting the variable to be System.Object doesn't change the debug info for it.
Cleaner way to fix this would be in Cecil itself. VariableDefinitionCollection.OnRemove is the right place to go and cleanup debug info for the variable being removed. There's no real counterpart for OnAdd as VariableDefinition doesn't carry any debug info (name), so there's nothing to add to the debug info.
@vitek-karas - I see the underlying Cecil fixes have been merged. Is this issue now fixed? Or do we need to take the latest Cecil in mono/linker in order to get the changes?
Activity
vitek-karas commentedon Jun 11, 2020
There are actually two issues here
This issue will be about the local variable debug information.
The problem is in
CleanRemovedVariables. Linker will remove the local variables from the method body definition, but it will not remove them from debug information. Some tools consuming the PDB will then get confused when reading it as the information in PDB doesn't match the method body.Fix is to walk all local scopes (even nested ones) and remove variables which are also removed from the body (not replaced with
System.Objectones). Since the debug info for local variables only stores name and some special flags, rewriting the variable to beSystem.Objectdoesn't change the debug info for it.vitek-karas commentedon Jun 11, 2020
Candidate fix: https://github.com/vitek-karas/linker/tree/CleanLocalVariableDebugInfo
(no tests yet)
vitek-karas commentedon Jun 15, 2020
Cleaner way to fix this would be in Cecil itself.
VariableDefinitionCollection.OnRemoveis the right place to go and cleanup debug info for the variable being removed. There's no real counterpart forOnAddasVariableDefinitiondoesn't carry any debug info (name), so there's nothing to add to the debug info.eerhardt commentedon Jul 30, 2020
@vitek-karas - I see the underlying Cecil fixes have been merged. Is this issue now fixed? Or do we need to take the latest Cecil in
mono/linkerin order to get the changes?Once this is fixed, we can fix dotnet/runtime#31785.
vitek-karas commentedon Jul 30, 2020
We need to get a new build of https://github.com/jbevain/cecil published. It should be in the works.. so hopefully soon.
marek-safar commentedon Sep 22, 2020
Fixed in master and 5.0 release