Repository navigation
Delete coreclr PAL's unicode wrapper layer - #136973
Conversation
Port everything the PAL MultiByteToWideChar and WideCharToMultiByte tests cover to direct minipal_* calls, so they can replace those tests: valid and ill-formed input with and without the terminator, embedded in ASCII runs, embedded NULs, size queries, exactly sized and too small destinations, errno, MINIPAL_MB_NO_REPLACE_INVALID_CHARS, and MINIPAL_TREAT_AS_LITTLE_ENDIAN parity on big- and little-endian platforms. Add long runs around the UTF-16 lane count flush, and random input checked against a simple reference model.
…WideCharToMultiByte Call minipal_get_length_* and minipal_convert_* directly for every conversion in CoreCLR, on Windows as well as Unix, including the PAL, the PAL test helpers and the generated LTTng provider. Native code now treats narrow strings as UTF-8 everywhere instead of using the ANSI or console code page on Windows: console output of ilasm, ildasm and PrintToStdErrW, metadata, ETW and config names, the ildasm input file name, the dbghelp symbol path, GC config strings, the mcs command line and the assembly name hashed into the typelib GUID. ilasm opens resource files by their UTF-16 name instead of converting it. Callers that pass a destination size of 0 now ask for the length explicitly, which fixes GetVersionString writing past the caller's buffer on Unix. Also pass EventStaticEntry::WriteEntry a size in characters rather than bytes, and keep the terminator inside the buffer in the GDB JIT file names.
Nothing calls them anymore, so remove unicode.cpp along with GetConsoleOutputCP, which only ever returned CP_UTF8 on Unix, and the UNICODE debug channel. Remove their declarations and the code page structures and flags that only they used from pal.h, the DAC exports, and the PAL locale tests, which the native minipal tests in src/tests replace.
|
Azure Pipelines: Successfully started running 8 pipeline(s). 7 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved null-pointer handling, Windows encoding mismatches, and event-buffer sizing regressions can cause crashes, corrupted paths and output, and lost event data.
8 open issues
Convert ilasm diagnostics to the Windows console code page · New Preserve code-page-aware Windows output conversion · New Treat null metadata name buffers as size queries · New Reject null CreateDirectoryW paths before UTF-16 conversion · New Reject null CreateFileW filenames before UTF-16 conversion · New Decode Windows command-line arguments using the ANSI code page · New Keep ANSI encoding for SymInitialize search paths · New Increase bulk static event buffer capacity for long field names · New
What changed in this PR
This PR removes CoreCLR PAL’s Unicode conversion wrappers and moves callers to the shared minipal UTF-8/UTF-16 APIs.
Changes:
- Replaces wrapper calls across the runtime, metadata code, diagnostics, and tools.
- Removes obsolete PAL declarations, implementation, debug channel, and tests.
- Adds minipal test-driver integration and clarifies conversion API documentation.
| File | Description |
|---|---|
| src/tests/minipal/NativeMinipalTests.csproj | Adds the managed test project and native driver reference. |
| src/tests/minipal/NativeMinipalTests.cs | Runs the native UTF conversion suite. |
| src/tests/minipal/native-minipal-tests-driver.c | Registers the UTF conversion test group. |
| src/tests/minipal/Directory.Build.targets | Reuses native test-driver targets. |
| src/tests/minipal/Directory.Build.props | Reuses native test-driver properties. |
| src/tests/minipal/CMakeLists.txt | Builds and installs the minipal test driver. |
| src/tests/CMakeLists.txt | Avoids a minipal build-directory collision. |
| src/native/minipal/utf8.h | Clarifies sizing, destination, and error contracts. |
| src/coreclr/vm/util.cpp | Uses minipal for Unix stderr conversion. |
| src/coreclr/vm/object.cpp | Converts native UTF-8 strings through minipal. |
| src/coreclr/vm/interoputil.cpp | Migrates Unix assembly-name conversion, preserving Windows behavior. |
| src/coreclr/vm/gdbjit.cpp | Migrates debugger names and source paths. |
| src/coreclr/vm/gctoclreventsink.cpp | Converts dynamic event names through minipal. |
| src/coreclr/vm/gcenv.ee.cpp | Migrates configuration conversions and handles missing strings. |
| src/coreclr/vm/eventtracepriv.h | Migrates field-name conversion and corrects capacity units. |
| src/coreclr/vm/dwbucketmanager.hpp | Migrates crash-bucket assembly-name conversion. |
| src/coreclr/vm/dllimport.cpp | Migrates entry-point diagnostic conversion. |
| src/coreclr/vm/commtmemberinfomap.cpp | Migrates COM property-name conversion. |
| src/coreclr/vm/cdacstress.cpp | Migrates diagnostic method-name conversion. |
| src/coreclr/vm/assemblyspec.cpp | Migrates locale conversion and error handling. |
| src/coreclr/utilcode/util.cpp | Migrates quick-buffer UTF conversion. |
| src/coreclr/utilcode/stacktrace.cpp | Changes symbol-search-path conversion to UTF-8. |
| src/coreclr/utilcode/sstring.cpp | Migrates SString Unicode conversions. |
| src/coreclr/utilcode/fstring.cpp | Migrates string sizing and conversion helpers. |
| src/coreclr/tools/superpmi/superpmi/jithost.cpp | Migrates environment configuration conversion. |
| src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp | Migrates shared UTF-8 conversion. |
| src/coreclr/tools/superpmi/mcs/verbmerge.h | Renames conversion helper declarations. |
| src/coreclr/tools/superpmi/mcs/verbmerge.cpp | Migrates merge-path conversion helpers and callers. |
| src/coreclr/tools/metainfo/mdobj.cpp | Migrates archive-member-name conversion. |
| src/coreclr/tools/metainfo/mdinfo.cpp | Migrates metadata display conversions. |
| src/coreclr/scripts/genLttngProvider.py | Generates direct minipal conversion calls. |
| src/coreclr/pal/tests/palsuite/paltestlist.txt | Removes obsolete wrapper test registrations. |
| src/coreclr/pal/tests/palsuite/paltestlist_to_be_reviewed.txt | Removes the legacy best-fit test listing. |
| src/coreclr/pal/tests/palsuite/locale_info/WideCharToMultiByte/test5/test5.cpp | Removes the PAL UTF-16-to-UTF-8 suite. |
| src/coreclr/pal/tests/palsuite/locale_info/WideCharToMultiByte/test4/test4.cpp | Removes legacy code-page best-fit tests. |
| src/coreclr/pal/tests/palsuite/locale_info/WideCharToMultiByte/test3/test3.cpp | Removes wrapper error-condition tests. |
| src/coreclr/pal/tests/palsuite/locale_info/WideCharToMultiByte/test2/test2.cpp | Removes wrapper explicit-length tests. |
| src/coreclr/pal/tests/palsuite/locale_info/WideCharToMultiByte/test1/test1.cpp | Removes wrapper ASCII and sizing tests. |
| src/coreclr/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.cpp | Removes the PAL UTF-8-to-UTF-16 suite. |
| src/coreclr/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.cpp | Removes wrapper error-condition tests. |
| src/coreclr/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.cpp | Removes wrapper explicit-length tests. |
| src/coreclr/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.cpp | Removes wrapper ASCII and sizing tests. |
| src/coreclr/pal/tests/palsuite/compilableTests.txt | Removes obsolete test build listings. |
| src/coreclr/pal/tests/palsuite/common/palsuite.cpp | Migrates shared PAL test conversion helpers. |
| src/coreclr/pal/tests/palsuite/CMakeLists.txt | Removes deleted wrapper test sources. |
| src/coreclr/pal/src/thread/thread.cpp | Migrates thread-description conversion. |
| src/coreclr/pal/src/misc/utils.cpp | Migrates allocating conversion helpers. |
| src/coreclr/pal/src/misc/fmtmessage.cpp | Migrates format-message numeric conversion. |
| src/coreclr/pal/src/misc/environ.cpp | Migrates environment name and value conversions. |
| src/coreclr/pal/src/misc/dbgmsg.cpp | Removes the Unicode debug-channel name. |
| src/coreclr/pal/src/locale/unicode.cpp | Deletes the Unicode wrapper implementation. |
| src/coreclr/pal/src/loader/module.cpp | Migrates module and library path conversions. |
| src/coreclr/pal/src/init/pal.cpp | Migrates executable-path conversion. |
| src/coreclr/pal/src/include/pal/utils.h | Updates conversion comments to specify UTF-8. |
| src/coreclr/pal/src/include/pal/dbgmsg.h | Removes the Unicode debug-channel declaration. |
| src/coreclr/pal/src/file/path.cpp | Migrates full-path and search-path conversions. |
| src/coreclr/pal/src/file/file.cpp | Migrates file-creation path conversion. |
| src/coreclr/pal/src/file/directory.cpp | Migrates directory path conversions. |
| src/coreclr/pal/src/debug/debug.cpp | Migrates debug-output conversion. |
| src/coreclr/pal/src/cruntime/wchar.cpp | Migrates wide-string numeric parsing conversions. |
| src/coreclr/pal/src/CMakeLists.txt | Removes the deleted wrapper source. |
| src/coreclr/pal/inc/pal.h | Removes wrapper APIs and supporting definitions. |
| src/coreclr/nativeresources/resourcestring.cpp | Migrates resource-string conversion. |
| src/coreclr/nativeaot/Runtime/windows/PalMinWin.cpp | Migrates NativeAOT Windows string conversions. |
| src/coreclr/nativeaot/Runtime/windows/PalCommon.cpp | Migrates PDB-path conversion. |
| src/coreclr/md/runtime/stgpool.cpp | Migrates metadata string-pool conversion. |
| src/coreclr/md/runtime/metamodelro.cpp | Separates metadata sizing from conversion. |
| src/coreclr/md/enc/stgtiggerstorage.cpp | Migrates metadata stream-name conversions. |
| src/coreclr/md/enc/rwutil.cpp | Migrates metadata UTF-8 conversion. |
| src/coreclr/md/enc/metamodelrw.cpp | Separates writable metadata sizing from conversion. |
| src/coreclr/md/compiler/import.cpp | Migrates version-string sizing and conversion. |
| src/coreclr/md/compiler/disp.cpp | Migrates runtime-version option conversion. |
| src/coreclr/md/compiler/custattr_import.cpp | Migrates custom-attribute-name conversion. |
| src/coreclr/jit/utils.cpp | Migrates the JIT UTF-16 string helper. |
| src/coreclr/inc/utilcode.h | Migrates shared conversion macros. |
| src/coreclr/inc/mdfileformat.h | Migrates stream-header name conversion. |
| src/coreclr/ildasm/windasm.cpp | Migrates arguments and changes encoding selection. |
| src/coreclr/ildasm/dman.cpp | Migrates manifest display conversions. |
| src/coreclr/ildasm/dis.cpp | Migrates disassembly and output conversion helpers. |
| src/coreclr/ildasm/dasm.cpp | Migrates resource, name, and filename conversions. |
| src/coreclr/ilasm/writer.cpp | Migrates conversions and opens resources by wide path. |
| src/coreclr/ilasm/typar.hpp | Migrates generic-parameter-name conversions. |
| src/coreclr/ilasm/method.hpp | Migrates method generic-parameter lookup conversion. |
| src/coreclr/ilasm/main.cpp | Migrates argument and path conversions. |
| src/coreclr/ilasm/grammar_before.cpp | Removes the console-code-page declaration. |
| src/coreclr/ilasm/grammar_after.cpp | Migrates token conversion and removes diagnostic transcoding. |
| src/coreclr/ilasm/class.hpp | Migrates class generic-parameter lookup conversion. |
| src/coreclr/ilasm/assembler.cpp | Migrates assembler names and string literals. |
| src/coreclr/ilasm/assem.cpp | Migrates metadata emission conversions. |
| src/coreclr/ilasm/asmparse.h | Migrates source-filename conversion. |
| src/coreclr/ilasm/asmman.cpp | Migrates assembly manifest conversions. |
| src/coreclr/hosts/corerun/corerun.hpp | Migrates Windows host conversion helpers. |
| src/coreclr/dlls/mscoree/exports.cpp | Migrates hosting string conversion. |
| src/coreclr/dlls/mscordac/mscordac_unixexports.src | Removes commented-out wrapper export entries. |
| src/coreclr/debug/ee/debugger.cpp | Migrates debug-event configuration conversion. |
| src/coreclr/debug/di/rsmain.cpp | Migrates application-group identifier conversion. |
| src/coreclr/debug/daccess/daccess.cpp | Migrates diagnostic conversion helpers and validation. |
Review effort: Balanced
- Report truncation for a null metadata string buffer with a nonzero size instead of writing through it. - Reject null paths in PAL CreateDirectoryW and CreateFileW before converting. - Keep the ANSI code page for the dbghelp SymInitialize search path. - Reserve room for a 255 character field name in bulk statics events. Co-authored-by: Cursor <cursoragent@cursor.com>
|
This was blocked in my mind by the API design discussions of the minipal functions related to #100451, but seems that you have the context here. |
This is a straightforward replacement of inlining existing minipal API and adapting caller code which was earlier adapting to win32 PAL shape anyway that for the call through the wrapper. On Windows, it is slightly faster: #136915 (comment) |
minipal utf8 converters are same or faster compared to the Win32 methods after #136915, so the concern about perf regressions discussed in #100451 no longer applies. We should get rid of the FString wrapper too (follow up PR). |
There was a problem hiding this comment.
🟡 Changes recommended
The change introduces Windows GC log-path encoding mismatches that can fail or misdirect logging, and directory-scan allocations that leak because the renamed member shadows the shared UTF-8 helper.
2 open issues
8 resolved since last review
Increase bulk static event buffer capacity for long field names Keep ANSI encoding for SymInitialize search paths Decode Windows command-line arguments using the ANSI code page Reject null CreateFileW filenames before UTF-16 conversion Reject null CreateDirectoryW paths before UTF-16 conversion Treat null metadata name buffers as size queries Preserve code-page-aware Windows output conversion Convert ilasm diagnostics to the Windows console code page
Review effort: Balanced
Drop palsuite coverage for APIs that no longer exist (IsBad*, Sleep, CompareString*, GetLocaleInfoW, LoadLibraryA, PAL_RegisterLibraryW) and for plain C-runtime functions that do not go through the PAL. Co-authored-by: Cursor <cursoragent@cursor.com>
471b139 to
d6fe8c4
Compare
Keep conversion lengths as size_t to match the minipal APIs. Co-authored-by: Cursor <cursoragent@cursor.com>
1b09ec2 to
9939ca6
Compare
minipal_convert_utf16_to_utf8 cannot exceed the destination size; keep the assert instead of a redundant upper-bound check. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Could you please resolve the conflicts? |
…place-pal Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # src/coreclr/vm/gcenv.ee.cpp # src/coreclr/vm/gdbjit.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
/ba-g opened #137160 on the unrelated test failure |
|
/ba-g opened #137160 on the unrelated test failure |
This should be unblocked now |
|
Follow-up to #136973. * Replace the FString wrapper with direct minipal UTF-8 conversions in SString, CQuickBytes and JitHost. * Delete pal/src/cruntime/wchar.cpp. Its users within the PAL are inlined; the u16_strtoul, u16_strtoui64 and u16_strtod implementations move to coreclr minipal (dn-u16). * Add u16_stricmp and u16_strnicmp to dn-u16 and use them in place of _wcsicmp/_wcsnicmp. * Delete the corresponding PAL tests. --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>


Uh oh!
There was an error while loading. Please reload this page.