Skip to content

Add RTLD_DEEPBIND flag to dlopen mode - #2247

Merged
mattleibow merged 1 commit into
mono:mainfrom
snnz:main
Sep 11, 2022
Merged

mattleibow merged 1 commit into
mono:mainfrom
snnz:main

Conversation

@snnz

@snnz snnz commented Sep 9, 2022 •

Copy link
Copy Markdown
Contributor

Description of Change

By default, internal dependences of a library loaded with dlopen are 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 the libharfbuzz.so.0, that is often present in the system, exports the same symbols as libHarfBuzzSharp.so and is implicitly used by some dependencies of mono or dotnet. To avoid such conflicts, there is a flag RTLD_DEEPBIND in glibc since version 2.3.4. Earlier versions do not check the mode argument for unknown flags, and musl does 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

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Merged related skia PRs
  • Changes adhere to coding standard
  • Updated documentation

@mattleibow

Copy link
Copy Markdown
Contributor

@mattleibow mattleibow added this to the v2.88.3 milestone Sep 11, 2022
@mattleibow
mattleibow merged commit 482e6ee into mono:main Sep 11, 2022
@mattleibow

Copy link
Copy Markdown
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]>
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.

[BUG] SkiaSharp crash as it uses system provided Harfbuzz on Linux

2 participants