Skip to content

LATX: Add an embedded liblat runtime and native callback support - #481

Draft
LaurenIsACoder wants to merge 9 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/liblat-public-candidate
Draft

LATX: Add an embedded liblat runtime and native callback support#481
LaurenIsACoder wants to merge 9 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/liblat-public-candidate

Conversation

@LaurenIsACoder

Copy link
Copy Markdown
Contributor

Depends on #470. This branch rebases its five prerequisite commits onto master at 2c2a169b16a1, followed by four additional commits. Once #470 merges, the prerequisite commits can be dropped from this PR.

This adds an embedded x86-64 liblat runtime for LoongArch applications. Native threads can call Guest functions and receive callbacks with independent Guest thread state and dynamically sized libc boundary records.

The four additional commits cover:

  1. Missing GLib filesystem declarations in two AOT tests.
  2. Common native callback entry points and dynamically growing boundary records.
  3. The shared runtime, initialization checks, ordered/reentrant exit callbacks, and Guest mapping ownership. Partial SysV detach preserves mappings that replaced part of the original attachment. Shared-only PIC and libc registrations remain scoped to the shared build.
  4. LAT-owned integration fixtures and the documented runtime lifetime. Tests use the existing domain registration interface.

The runtime has one process lifetime: finalization drains callbacks but does not destroy or reset it. Loader or Guest fatal errors may terminate the embedding process. The API and build contract are documented in docs/devel/liblat.md.

Validation on LoongArch64 with 16 KiB pages, GCC 8.3 and glibc 2.28:

  • Shared build: meson test -C build64 --suite lat-pr-fast --print-errorlogs — 26 passed.
  • Executable build: meson test -C build-executable --suite lat-pr-fast --print-errorlogs — 27 passed.
  • Shared-runtime integration: meson test -C build64 --suite latx-integration --print-errorlogs — 12 passed, using matching x86-64 fixtures.
  • Workflow helper tests: python3 tests/ci/test_lat_ci_workflows.py — 10 passed.
  • The partial SysV replacement regression fails with the previous runtime and passes with the fix, covering private/shared anonymous replacements at either end of an attachment.

Draft: the four additional commits await author-confirmed DCO sign-offs.

LaurenIsACoder and others added 9 commits September 10, 2026 15:08
Extract CPU clone initialization without changing existing callers or thread policy.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Preserve the existing callback ABI, including float results and Host floating-point register preservation. Add explicit helper-call entry points for subsequent TLS initialization.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Keep common runtime options available in release builds and propagate an explicit -L selection through LAT_LD_PREFIX. A re-executed Guest must use the same loader and libc as its parent.

Add test-runtime-prefix-exec to check the exported selection and mapped Guest libc before and after exec. Reverting the runtime-root fix makes the fixture fail; the fixed build passes on LoongArch ABI1.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Keep Guest TLS management disabled unless LATX_KZT_GUEST_TLS=1 and KZT is effective. Attach native-created threads from an immutable template, initialize Guest TLS from live loader state, and coordinate generation refresh, callback execution, fork and thread exit. Keep existing library registration and disabled-mode loader behavior. Add policy, loader and native-thread callback tests.

Initialize the attached TCB thread ID and robust-list fields before calling the Guest loader allocation helper. The debugger regression reaches that helper with TID 0 before the fix and with the real thread ID after it. Opt-in off/on, robust owner death and 64-cycle dynamic loading regressions pass on LoongArch ABI1.

Supply the new runtime-gate variables in the standalone TB-flush test fixture so the complete KZT-enabled lat-pr-fast suite links and runs.

Co-authored-by: sunguoyun <sunguoyun@loongson.cn>

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
…ries

Provide an initially inactive libc boundary broker for errno, h_errno and locale names. Keep Guest thread destruction in the TLS runtime. Consumers explicitly initialize and activate the broker; enabling Guest TLS alone does not enable semantic propagation. Keep private libc pointers within their owning domain.

Own locale projections per Guest context, document borrowed handles, and release each projection in its owning libc during context teardown. The two-thread regression fails with the old shared cache and passes with separate contexts, including mutation and release of an owned duplicate.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
The AOT cache reader and publication tests use g_remove and g_rmdir.
Include their declaring header so the tests build with older GLib headers
and warnings treated as errors.
Provide common native-to-Guest callback entry points and per-thread attach
support for embedded clients. Grow nested libc boundary records dynamically
so deep callbacks preserve errno and locale state without a fixed limit.

Keep the bridge independent of JVM registration and signal adapters.
Add the shared-library build and NBL loader ABI. Validate bootstrap inputs,
keep bootstrap completion local to its CPU, and reject repeated runtime
initialization. Drain Guest cleanup callbacks once in reverse registration
order, including reentrant registrations and null DSO handles.

Reserve only owned Guest mappings in the shared process and reject fixed
operations against Native mappings. Preserve partial SysV attachments.
Scope PIC and shared-only libc registrations to the shared build so ordinary
translator executables retain their existing code generation and bindings.

Based on the liblat implementation by sunguoyun, zhaixiang and panxuefeng,
with integration, lifecycle, mapping and build corrections.

Co-authored-by: zhaixiang <zhaixiang@loongson.cn>
Co-authored-by: panxuefeng <panxuefeng@loongson.cn>
Co-authored-by: Hanlu Li <heuleehanlu@gmail.com>
Exercise calls, Host thread TLS, deep callbacks, reentrant cleanup, invalid
initialization, bootstrap collisions and Native mapping preservation on
LoongArch. Include SysV full and partial unmap lifetimes and mixed page sizes.
Document the single process-lifetime runtime, bootstrap and error contract.
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.

2 participants