Repository navigation
Fix Linux HarfBuzz symbol preemption - #5352
Conversation
📦 Try the packages from this PRWarning Do not run these scripts without first reviewing the code in this PR. Step 1 — Download the packages bash / macOS / Linux: curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 5352PowerShell / Windows: iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 5352"Step 2 — Add the local NuGet source dotnet nuget add source ~/.skiasharp/hives/pr-5352/packages --name skiasharp-pr-5352More options
Or download manually from Azure Pipelines — look for the Remove the source when you're done: dotnet nuget remove source skiasharp-pr-5352 |
|
Hey there @@VirgilMing! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
8048a1f to
f1e82f7
Compare
|
@dotnet-policy-service agree |
A visible canvas can still be empty while the raster interop module loads. Wait for the sample's first opaque pixel before capturing the existing golden image, and exercise delayed module initialization as a regression. The delayed case fails with the old condition and passes with pixel readiness. Normal initialization, infrastructure/discovery tests, and the unfiltered Console solution pass locally. Related to mono#5312; observed while validating mono#5352. The earliest introduction of the readiness gap is not established by the current refactored-file blame.
A visible canvas can still be empty while the raster interop module loads. Wait for the sample's first opaque pixel before capturing the existing golden image, and exercise delayed module initialization as a regression. The delayed case fails with the old condition and passes with pixel readiness. Normal initialization, infrastructure/discovery tests, and the unfiltered Console solution pass locally. Related to #5312; observed while validating #5352. The earliest introduction of the readiness gap is not established by the current refactored-file blame.
A globally loaded system HarfBuzz can preempt calls inside libHarfBuzzSharp.so and receive incompatible private objects. Bind internal function references locally with -Bsymbolic-functions. All 565 public hb_* exports in the tested library are functions. Both symbolic options eliminate the same 67 preemptible hb_* relocations, so function-only binding covers the conflict without changing data-symbol binding. Add a standalone native regression that loads conflicting functions globally before creating a bundled font and initializing OpenType functions. Validated Linux x64 source builds with libstdc++ and libc++/libc++abi, native load-order probes, Avalonia font initialization, and the unfiltered net10.0 Console solution: 6450 passed, 0 failed, and 38 existing skips. Other architectures, musl, nodeps/Bionic/Tizen variants, and release cross-images using static libc++ with GCC ABI remain unverified. LLD was tested only in the earlier libstdc++ comparison. The original complete GtkSharp reproduction, actual SourceGit GUI, and published packages were not tested.
f1e82f7 to
0999cd7
Compare
|
The latest build, 1637759, failed in two Samples Host jobs:
Could someone with Azure Pipelines permissions rerun the failed Samples Host jobs? I don't have permission to rerun them. |
Add native artifact inspection tests and dedicated Linux CI (#5366) Context: #3038 Context: #5352 Context: https://dev.azure.com/dnceng/internal/_build/results?buildId=3106805 Context: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1638964 Separate native artifact validation from artifact production. Inspect the merged outputs with ordinary xUnit/TRX reporting instead of keeping those assertions in native build jobs. Keep Package build-only, and report compatibility and symbol failures through the test pipelines. ~~ Add a case without extending the runner ~~ Add SkiaSharp.Tests.Native and its dedicated solution. One xUnit theory discovers Cases/Name.ps1 or Cases/Name/test.ps1, so a scenario can include supporting files without C# registration or another test framework. Share artifact layouts and inspection helpers through Helpers.psm1. Supply the checkout root through the NativeTest.RepositoryDirectory MSBuild runtime configuration value rather than walking parent folders. Clear stale copied cases before building, then copy the current scripts to the output directory so deleted tests cannot remain discoverable. Run each case in a separate pwsh process, capture stdout/stderr, and kill its process tree after five minutes. Missing entry points and unexpected exit codes fail. Exit 77 requires an explicit SKIP reason; exceptions do not become skips. ~~ Make uninspected additions to the native collection fail ~~ Fixed lists alone can silently omit newly added libraries or targets. Compare the required inventory with files detected by suffix and binary signature in output/native and output/msvc/native. Reject missing files, duplicate claims, unclaimed binaries and entries without an inspection case, including extensionless framework/DWARF files and newly bundled binaries inside the Dawn package. Consume native_msvc separately because its desktop MSVC outputs are not included in the merged native artifact. Compare versioned ELF files and retained libHarfBuzzSharp.wasm.a aliases with their normalized originals by hash. Require the published Windows ARM64 paths directly rather than searching alternate directory spellings. ~~ Preserve Linux dependency and minimum-runtime contracts ~~ Require fontconfig in normal glibc/musl Skia builds and exclude it from nodeps and Bionic outputs. Inspect both libraries across the declared architecture and variant combinations without loading target code. Keep GLIBC ceilings directly in the compatibility test: 2.27 for x86, x64 and arm64; 2.35 for arm; 2.39 for riscv64; and 2.42 for loongarch64. Require libc.so.6, reject musl substitutions, and fail on empty or unrecognized version requirements. An empty parse is not compatibility evidence. Use llvm-readobj --elf-output-style=GNU as the explicit ELF inspection API. Missing tools, APIs and required artifacts fail without automatic installation, alternate-tool selection or fallback path searches. ~~ Verify Android ABI and 16 KB page compatibility ~~ Check ELF class, machine, little-endian encoding and shared-object type against x86, x86_64, armeabi-v7a and arm64-v8a directories. A library and matching debug file copied into the wrong ABI directory must not pass merely because their alignment and identities agree. Require loadable segments with power-of-two alignment of at least 16 KB and congruent file offsets and virtual addresses. Accept larger compatible alignments rather than requiring the previous exact align 2**14 output. ~~ Keep debug files tied to their shipped modules ~~ Require matching nonempty GNU build IDs and the exact case-sensitive .gnu_debuglink filename for Android split symbols. Compare Windows native MSF and projection portable-PDB GUID/age identities with their DLL CodeView records. Require readable CLI metadata in WinUI projection and WinMD artifacts. Match Apple dSYM UUIDs to archived slices and require DWARF debug information. Retain the objr_spectre/objd_spectre runtime-marker policy for native Windows PDBs, excluding the managed projection. Scan bounded chunks with overlap so a marker crossing a chunk boundary is recognized. Marker presence does not prove compiler mitigation, CFG or complete Spectre protection. ~~ Preserve static CRT and optional Direct3D import policies ~~ Reject hard VCRUNTIME/MSVCP imports while retaining the previous allowance for delay-only CRT imports. Inspect desktop Clang/MSVC, Nano Server, WinUI, ANGLE and projection artifacts on the Linux host. Require desktop Skia DLLs to delay-load D3D12 and D3DCompiler, with neither present as a hard import. Exclude Nano Server from that requirement because its native build disables Direct3D. ~~ Validate Apple slices and packaged framework contents ~~ Check expected Mach-O slices, dynamic-library type and selected public entry points in macOS, iOS, tvOS and Mac Catalyst outputs. Compare each Mac Catalyst framework zip's binary with the inspected framework and reject additional native entries. Claim framework-root and Versions/Current aliases explicitly, including directories materialized when pipeline artifacts dereference symlinks. Compare their binaries with Versions/A rather than excluding alias directories and hiding extra native files. ~~ Check the Tizen ABI without executing Tizen code ~~ Require x86_64/aarch64 ELF64 shared libraries and selected public SkiaSharp or HarfBuzz exports. These checks catch incorrect architecture and missing entry points without requiring a Tizen runtime; they do not establish runtime behavior. ~~ Inspect every listed WebAssembly archive member ~~ Inspect both libraries for Emscripten 3.1.34, 3.1.56 and 6.0.2 across the declared single-threaded, multithreaded and SIMD combinations. Require nonempty archives, wasm32 WebAssembly headers for the listed members, and selected defined public symbols. A valid archive container must not hide an accidentally bundled host object. ~~ Separate build-only packaging from artifact test results ~~ Remove CheckLinuxDependencies, CheckWindowsDependencies, CheckAlignment and Android build-ID/debuglink assertions from Cake, including callers and obsolete verification arguments. Their responsibilities now live in the inspection cases. Keep compilation, copying, stripping, symbol extraction, debuglink creation and build-input/toolchain validation in the producers. Expose tests-native through Cake. Add a Linux native_tests leaf stage to Test and Complete: Test depends on prepare and downloads source-build artifacts; Complete depends on native artifact merging. Packaging does not wait for native_tests, and Package does not include it. Keep tests on standard templates without forwarding native-build 1ES settings. Use a dedicated Azure Linux .NET SDK image with LLVM, leaving native build images and minimal managed-runtime images unchanged. Publish TRX and logs on failure; failed tests or missing result files fail the job. The twelve current cases inspect target files without executing target libraries or requiring a C compiler. Internal run 3106805 passed twelve cases on each Linux/Windows host against production Package build 3104558. Public Windows used a different image whose LLVM tools were not on PATH. Keep that host invocation out rather than hiding missing tools or restoring a defensive installer; Windows DLL/PDB inspection still runs on Linux. After rebasing onto main d29d6e6, public run 1638964 passed all twelve native cases with no failures or skips against fresh artifacts, publishing TRX run 45519180. The full build failed separately on the Windows Host sample's four-second HTTP request timeout; this change does not modify sample code or claim to fix that failure. The motivating HarfBuzz symbol-preemption fix and runtime regression belong to #5352, not this infrastructure change. These static inspections do not resolve #3038 or substitute for target-platform runtime tests. Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Virgil Ming <[email protected]> Co-authored-by: Copilot App <[email protected]> Copilot-Session: e108ef36-df39-44b3-8fa7-6ec8272316a5
|
Thanks for the fix and the native regression script! Your script inspired me to add the new I pushed one commit to move your regression into that project, splitting the C code into separate loader, interposer, and negative-control files. Your linker fix is unchanged. I verified the before/after behavior with production-built libraries: the test catches the incorrect symbol binding without the fix, and all 13 native tests pass with it. Thanks again for helping improve both HarfBuzz and our native testing infrastructure! |
Replace the standalone Python probe with a folder-discovered PowerShell case and separate loader, interposer and negative-control C sources. Declare the compiler, C headers and binutils in the Linux test image, and remove the redundant linker comment. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a6d3ab7a-bdc2-4092-b3e1-07f912ae9c77
fd6f57d to
2f11447
Compare
|
FWIW, I hit this same issue when working on an Avalonia Linux build for .NET 11. So looking forward to this fix being released soon. |
Description
If system HarfBuzz is loaded globally first, internal
hb_*calls fromlibHarfBuzzSharp.somay currently resolve to that other implementation.Mixing private objects from different versions then causes
SIGSEGVorfree(): invalid pointer, matching the symbol-preemption problem reported in #3038.This PR adds
-Wl,-Bsymbolic-functionsto the HarfBuzzSharp Linux link flags, and add a standalone native regression that loads conflicting functions globally before loading the library and exercising font creation and OpenType initialization.The GNU ld option definitions distinguish function-only binding
-Bsymbolic-functionsfrom-Bsymbolic, which also binds global data references.All 565 public
hb_*exports in the tested binary are functions. Both options eliminate the same 67 preemptiblehb_*relocations and pass the same crash probes, so function-only binding covers the observed conflict, without extending the change to data-symbol binding.The nodeps and clang-cross recipes delegate to the common Linux recipe and inherit the flag, but those variants were not executed locally.
Related issues
Fixes #3038
Required skia PR
None. The change is in the parent repository's Linux link recipe and native regression script.
Areas affected
binding/)externals/skia/src/c,include/c)Changes
Public API
None. The 565 exported
hb_*function names, symbol versions, and symbol types are identical across the three Linux x64 link variants.Behavior
On Linux, internal HarfBuzzSharp function calls stay within the bundled implementation even when system HarfBuzz was loaded globally first, preventing the resulting font-initialization crash.
Testing
Local validation used Gentoo/glibc Linux x64, Clang 23.1.3, .NET 10, system HarfBuzz 12.3.2, source-built Skia m156, and bundled HarfBuzz 14.4.0. A libstdc++ build was tested first; both native libraries were then rebuilt from source with the original Clang compiler and libc++/libc++abi 23.1.3. The latter binaries directly depend on
libc++.so.1andlibc++abi.so.1.The libc++ comparison relinks identical HarfBuzz objects, changing only the symbolic link option:
-Bsymbolic-functions-Bsymbolichb_*function exportshb_*dynamic relocationshb_*bindings to system HarfBuzzThe standalone native regression fails without the flag and passes with either symbolic option. It needs a C compiler, but no system HarfBuzz, font files, or .NET runtime, and removes
LD_PRELOADfrom its fresh probe processes. Bundled-only, system-global-first, and FreeType-initialized-first probes each pass 3/3 for both fixed variants.The Avalonia 11.3.22 probe keeps its existing managed dependencies and replaces only the native HarfBuzz library. It exercises font initialization, rather than a complete GUI application. The unfiltered Console solution passes 6450 tests, with 0 failures and 38 existing skips. DejaVu Sans regular/bold fixtures were supplied through isolated Fontconfig configuration; no skips were added or broadened, and copied native-library hashes match the source-built artifacts. An earlier intermediate full run hit the existing color-space weak-reference count assertion (expected 4, actual 3); its focused diagnostic and final full runs passed. That test is not changed here.
Commands used for the source build, standalone regression, and final solution gate:
dotnet cake --target=externals-linux --arch=x64 --cc=clang --cxx=clang++ python3 scripts/infra/native/linux/test-harfbuzz-symbol-binding.py output/native/linux/x64/libHarfBuzzSharp.so dotnet test tests/SkiaSharp.Tests.Console.slnx -p:TargetFramework=net10.0 -p:TargetFrameworks=net10.0Rebase validation (2026-10-16)
Rebased the unchanged patch onto upstream
633b37a865829bbfb904b11e8f65ebc108a7fe1bas0999cd77cf8a5cd03dccda3aad8467be9fe8765a. The PR still contains one commit and the same two files;git range-diffand the stable patch ID confirm that the fix itself is unchanged. The new base includes merged #5353; #5361 is still a separate open PR.Rebuilt both Linux x64 native libraries from source with Clang 23.1.3 and libc++/libc++abi 23.1.3 against the new base's Skia submodule (
7f0c3d39be96525be511614c28742e709a496dd9). Both library SHA-256 hashes are identical to the earlier libc++ validation artifacts. The standalone symbol-binding regression passes, all 565 publichb_*function exports are unchanged, and there are no preemptiblehb_*dynamic relocations. The unfiltered Console solution passes 6450 tests, with 0 failures and 38 existing skips on this exact rebased commit; native copies in all test hosts match the source-built artifacts. The isolated Fontconfig fixtures were reused, with no skip-policy changes.The earlier three-option/Avalonia comparison above was not repeated because the freshly rebuilt Linux x64 binaries are byte-identical. Other architectures, libc variants, release cross-images, GUI applications, and published packages were not rerun locally. New-head remote CI is pending.
Unverified: other CPU architectures, musl, nodeps/Bionic/Tizen variants, and the release cross-images. Gentoo's shared libc++/libc++abi build is different from the release images' static libc++ with GCC ABI. LLD was exercised only in the earlier libstdc++ comparison; the libc++ comparison uses GNU ld. The original complete GtkSharp reproduction, actual SourceGit GUI, and published packages were not tested.
Checklist
Changesabove lists all public API and behavioral changes///documentation and regenerated bindings when applicable — N/A: no API changemono/skiaPR linked above and bindings regenerated — N/A: parent link recipe only; no C API or submodule change