Repository navigation
Add RTLD_DEEPBIND flag to dlopen mode - #2247
Merged
Merged
Conversation
mattleibow
approved these changes
Sep 10, 2022
Contributor
|
Thanks for this PR! Always great to see SkiaSharp getting better! |
mattleibow
added a commit
that referenced
this pull request
Oct 17, 2026
Bind bundled HarfBuzz functions locally on Linux (#5352) Fixes: #3038 Context: #2247 Context: #5366 Context: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1637759 Context: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1637595 Keep internal HarfBuzz calls within the bundled implementation and add a native regression that demonstrates the failure without depending on GTK, system HarfBuzz versions, fonts, or a managed-process crash. ~~ Prevent ELF preemption from mixing private HarfBuzz objects ~~ Using HarfBuzzSharp after GTK initialization can cause SIGSEGV or invalid pointer errors. GTK can load system HarfBuzz into the global symbol scope; ELF lookup can then redirect internal calls from libHarfBuzzSharp.so to that implementation, passing private objects between incompatible builds. Resolving the initial managed import from the intended library does not control the native calls made inside it. The earlier RTLD_DEEPBIND workaround lived in the custom library loader, so it did not protect the .NET import path reported in this regression. Apply -Wl,-Bsymbolic-functions in the common Linux HarfBuzz link recipe instead, following the native-binding diagnosis in the issue discussion. Choose function-only binding rather than -Bsymbolic: the observed conflict is in function references, and the narrower option avoids extending the change to global data binding. Keep the exported hb_* entry points and managed signatures unchanged rather than introducing prefixed wrappers. The nodeps and clang-cross recipes delegate to this common recipe and inherit the option; other native recipes are not changed. ~~ Make load-order regression failures observable in native CI ~~ Add HarfBuzzSymbolBinding as a folder-discovered PowerShell case in the SkiaSharp.Tests.Native project introduced by #5366. Separate the loader, conflicting exports, and intentionally preemptible control into probe.c, interposer.c, and control.c. The loader obtains entry points from the explicit library handle and exercises font creation and OpenType function initialization. Each probe runs in a fresh native process, optionally loading the interposer with RTLD_GLOBAL first. This keeps load-order state separate between probes and prevents a native failure from terminating the xUnit host. Have the interposer report the unexpectedly called function and exit 86, rather than relying on incompatible object layouts to produce a segfault. Require the fake control to pass alone and fail with that diagnostic and exit code before trusting the produced-library checks. This rejects a false pass caused by an inactive conflict. Validate the exact linux and linuxnodeps artifact paths, ELF class, endianness, machine, shared-library type, and glibc dependency before execution. Exercise both variants alone and with the conflicting exports. Declare a non-Linux runtime skip; unsupported Linux hosts, missing tools, missing artifacts, and failed native commands remain failures. Remove LD_PRELOAD and LD_AUDIT from the probe environment. Use the existing xUnit execution, timeout, and TRX reporting rather than adding another runner. Install gcc, glibc-devel, and binutils explicitly in the Linux test image alongside LLVM; GCC also needs the assembler and linker to compile these probes. A Linux ARM64 before/after run used identical test sources and image, substituting the standard HarfBuzz binary and its versioned alias. The unfixed production binary from build 1637595 passed alone but called the global hb_font_set_funcs_using with the interposer, producing exit 86: 12 native cases passed and this case failed. Restoring the fixed binary from contributor build 1637759 produced 13 passes with no skips; its nodeps HarfBuzz binary also passed both load orders. Those runtime checks used production-built HarfBuzz libraries; the other artifact inspections in that local run used retained fixtures. They do not establish a full GTK application run or runtime coverage of musl, Bionic, Tizen, or every cross-built architecture. Co-authored-by: vgm <[email protected]> Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Nikita Tsukanov <[email protected]> Co-authored-by: Copilot App <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
By default, internal dependences of a library loaded with
dlopenare resolved using the global lookup scope first. If there are already matched symbols in the global scope, internal calls in the library that are supposed to use its local functions, will be linked to some external code, which is usually results in segmentation faults when the library is used. This is particularly true for thelibharfbuzz.so.0, that is often present in the system, exports the same symbols aslibHarfBuzzSharp.soand is implicitly used by some dependencies ofmonoordotnet. To avoid such conflicts, there is a flag RTLD_DEEPBIND inglibcsince version 2.3.4. Earlier versions do not check the mode argument for unknown flags, andmusldoes not check it either. So just adding this flag to the mode appears to be quite harmless.Bugs Fixed
API Changes
None.
Behavioral Changes
None.
Required skia PR
None.
PR Checklist