Skip to content

Remove Unix SystemString iconv dependency - #612

Open
Noam Hershtig (noamher) wants to merge 6 commits into
microsoft:mainfrom
noamher:nohersht-microsoft-remove-systemstring-iconv
Open

Noam Hershtig (noamher) wants to merge 6 commits into
microsoft:mainfrom
noamher:nohersht-microsoft-remove-systemstring-iconv

Conversation

@noamher

Copy link
Copy Markdown

Motivation

CLRIE currently uses iconv in the Unix SystemString implementation to convert between UTF-8 and UTF-16 during profiler initialization.

Although the iconv API is provided by glibc, many character-set converters are loaded dynamically from glibc's gconv modules. Minimal Linux distributions and container images do not always include those modules. In particular, minimal Azure Linux 3 images package them separately in glibc-iconv.

When the UTF-16 converter is unavailable, iconv_open("UTF-16LE", "UTF-8") fails and SystemString::Convert cannot process CLRIE configuration and path strings. This can prevent the instrumentation engine from initializing unless the host image is modified to install or stage the missing gconv modules.

CLRIE is commonly injected into existing application containers, where changing the base image or installing an additional OS package may be undesirable or impossible. Making this core conversion self-contained allows CLRIE to initialize on minimal Linux images such as Azure Linux 3 without requiring host gconv modules for SystemString conversion.

Summary

  • Replace the Unix SystemString iconv implementation with strict, self-contained UTF-8/UTF-16 conversion.
  • Preserve the existing null, bounds, HRESULT, and destination-state behavior.
  • Add coverage for Unicode boundaries, malformed input, surrogate handling, NUL termination, and length limits.
  • Document the conversion helper contracts and encoding branches.

Scope

  • The Windows implementation is unchanged.
  • Existing macOS iconv linker entries are unchanged.
  • libxml2[iconv] remains unchanged because it serves libxml2's support for non-UTF-8 XML encodings and is separate from SystemString.
  • This change removes CLRIE's direct SystemString dependency on iconv/gconv; it does not claim to remove every iconv symbol contributed by libxml2 from the final engine binary.

Validation

  • Ubuntu Debug: 14/14 CTest tests passed.
  • Ubuntu Release: 14/14 CTest tests passed.
  • Alpine Debug: 14/14 CTest tests passed.
  • Alpine Release: 14/14 CTest tests passed.
  • StringConversionTests: 9/9 passed in targeted validation.
  • XmlTests: 2/2 passed in targeted validation.
  • systemstring.cpp.o and libCommon.Lib.a contain no iconv references.

nohersht and others added 3 commits September 29, 2026 15:49
Replace the Unix conversion internals with strict self-contained UTF-8 and UTF-16 handling while preserving existing bounds and destination-state behavior. Add comprehensive conversion and malformed-input coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Extract strict UTF-8 and UTF-16 decoding and encoding helpers, use bounded strnlen with an overflow-proof limit check, and preserve existing conversion behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Clarify UTF-8 and UTF-16 helper contracts, malformed-sequence cases, and canonical encoding ranges without changing behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@noamher
Noam Hershtig (noamher) requested a review from a team as a code owner September 30, 2026 08:23
@plnelson

Copy link
Copy Markdown
Member

Wiktor Kopec (@wiktork) for his input as well.

I have some concerns about the custom Unicode conversion routines. Though this was written by an LLM, do we know the code provenance? My concern is that it may be derived from, or very close to, an implementation that licensed under a license incompatible with MIT. I also don't want to have to maintain a custom Unicode conversion implementation.

Since we use vcpkg to pull in other dependencies such as libxml2, why not pull in an existing package? One suggestion is to use UTF8-CPP (Boost licensed) to do the actual conversion.

@noamher

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Microsoft"

@noamher

Copy link
Copy Markdown
Author

Wiktor Kopec (Wiktor Kopec (@wiktork)) for his input as well.

I have some concerns about the custom Unicode conversion routines. Though this was written by an LLM, do we know the code provenance? My concern is that it may be derived from, or very close to, an implementation that licensed under a license incompatible with MIT. I also don't want to have to maintain a custom Unicode conversion implementation.

Since we use vcpkg to pull in other dependencies such as libxml2, why not pull in an existing package? One suggestion is to use UTF8-CPP (Boost licensed) to do the actual conversion.

Let me check about using UTF8-CPP.
Re provenance - I will check as well.

@noamher

Copy link
Copy Markdown
Author

Noam Hershtig (Noam Hershtig (@noamher)) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

Replace the custom Unix Unicode conversion helpers with checked UTF8-CPP adapters while preserving existing bounds, error, and destination-state behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@noamher

Copy link
Copy Markdown
Author

Wiktor Kopec (Wiktor Kopec (@wiktork)) for his input as well.

I have some concerns about the custom Unicode conversion routines. Though this was written by an LLM, do we know the code provenance? My concern is that it may be derived from, or very close to, an implementation that licensed under a license incompatible with MIT. I also don't want to have to maintain a custom Unicode conversion implementation.

Since we use vcpkg to pull in other dependencies such as libxml2, why not pull in an existing package? One suggestion is to use UTF8-CPP (Boost licensed) to do the actual conversion.

good catch. I've updated the pr to use UTF8-CPP. WDYT?

@plnelson

Copy link
Copy Markdown
Member

Please also update THIRD-PARTY-NOTICES.txt

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@noamher

Copy link
Copy Markdown
Author

Patrick Nelson (@plnelson) Added the UTF8-CPP attribution and complete Boost Software License 1.0 text to THIRD-PARTY-NOTICES.txt in d8d722c. Thanks for catching this.

Comment thread src/Common.Lib/systemstring.cpp
Comment thread src/Tests/CommonLibTests/StringConversionTests.cpp Outdated
Restore platform-specific vcpkg dependencies on Linux and macOS, keep libxml2 vcpkg usage Linux-only, and focus conversion tests on CLRIE adapter behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@plnelson

Copy link
Copy Markdown
Member

/azp run ClrInstrumentationEngine-PR-Yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants