Skip to content

BEGIN_ILLINK_FEATURE_SWITCH mechanism for corelib.h does not work with checked/debug runtime and a trimmed app #55950

Closed
@elinor-fung

Description

@elinor-fung

BEGIN_ILLINK_FEATURE_SWITCH/END_ILLINK_FEATURE_SWITCH were added to corelib.h to allow trimming of classes that are only used by the runtime when a specific feature switch is enabled/disabled.

// BEGIN_ILLINK_FEATURE_SWITCH and END_ILLINK_FEATURE_SWITCH allow IL linker to guard types behind a feature switch.
// Current support is only around class scope and not for standalone members of classes.
// See usage in this file itself and on the link (the assembly name for feature switch in this file will be System.Private.CoreLib),
// https://github.com/dotnet/designs/blob/main/accepted/2020/feature-switch.md#generate-the-right-input-for-the-linker-in-sdk
//
#ifndef BEGIN_ILLINK_FEATURE_SWITCH
#define BEGIN_ILLINK_FEATURE_SWITCH(featureName, featureValue, featureDefault)
#endif
#ifndef END_ILLINK_FEATURE_SWITCH
#define END_ILLINK_FEATURE_SWITCH()
#endif

In checked/debug, the runtime does a consistency check between corelib and the runtime based on what was defined in corelib.h

#if defined(_DEBUG) && !defined(CROSSGEN_COMPILE)
if (!NingenEnabled())
{
g_CoreLib.Check();
}
#endif

With the usage of *_ILLINK_FEATURE_SWITCH, some of these items can now be trimmed away, but the consistency check doesn't handle that possibility. As a result, running a trimmed app on on checked/debug runtime fails.

Currently, System.Runtime.InteropServices.BuiltInComInterop.IsSupported is the only switch that uses this mechanism. One way to repro is to build/run one of the TrimmingTests in libraries (with that feature switch disabled) against a checked/debug coreclr, which results in something like:

Assert failure(PID 324 [0x00000144], Thread: 22480 [0x57d0]): pFD != NULL

CORECLR! CoreLibBinder::Check + 0x4D1 (0x00007ff9`5fcff9a1)
CORECLR! SystemDomain::LoadBaseSystemClasses + 0x5B8 (0x00007ff9`5fcb3748)
CORECLR! SystemDomain::Init + 0x3FE (0x00007ff9`5fcad48e)
CORECLR! EEStartupHelper + 0xCA3 (0x00007ff9`60a74f43)
CORECLR! `EEStartup'::`9'::__Body::Run + 0x59 (0x00007ff9`60a77fb9)
CORECLR! EEStartup + 0x85 (0x00007ff9`60a74215)
CORECLR! EnsureEEStarted + 0x221 (0x00007ff9`60a753a1)
CORECLR! CorHost2::Start + 0x1D0 (0x00007ff9`5fe008b0)
CORECLR! coreclr_initialize + 0x341 (0x00007ff9`60a82a11)
HOSTPOLICY! <no symbol> + 0x0 (0x00007ff9`c3363c57)
    File: C:\repos\runtime\src\coreclr\vm\binder.cpp Line: 573
    Image: C:\repos\runtime\artifacts\bin\trimmingTests\projects\System.Runtime.TrimmingTests\TypeBuilderComDisabled\win-x64\bin\Release\net6.0\win-x64\publish\project.exe

cc @LakshanF

Metadata

Metadata

Assignees

Labels

area-AssemblyLoader-coreclrin-prThere is an active PR which will close this issue when it is mergedlinkable-frameworkIssues associated with delivering a linker friendly framework

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions