Skip to content

loader: support Thumbv7-M dynamic applications and DSOs - #475

Open
shihange-vivo wants to merge 4 commits into
vivoblueos:mainfrom
shihange-vivo:thumbv7_loader_and_linker
Open

shihange-vivo wants to merge 4 commits into
vivoblueos:mainfrom
shihange-vivo:thumbv7_loader_and_linker

Conversation

@shihange-vivo

Copy link
Copy Markdown

Summary

Add support for dynamically linked applications and shared libraries on the Thumbv7-M soft-float profile.

The initial supported profile is:

  • ELF32, little-endian, EM_ARM
  • ARM EABI5, Thumb-only, soft-float
  • ET_DYN PIE applications and shared objects
  • eager binding with R_ARM_RELATIVE, R_ARM_ABS32, R_ARM_GLOB_DAT, and R_ARM_JUMP_SLOT
  • qemu_mps2_an385 as the first validated board

This change covers the complete path from artifact generation and ELF validation to dependency loading, relocation, execution, and application resource reclamation.

Motivation

BlueOS previously had an ELF image loader, but it did not provide a complete dynamic application runtime. In particular, it lacked:

  • DT_NEEDED dependency closure loading
  • cross-image symbol resolution
  • DSO constructor/destructor ordering
  • application-scoped image ownership
  • dynamic libc startup and shutdown
  • pthread and emutls lifetime integration
  • build-time validation of the supported ELF contract

This made it impossible to reliably run C, C++, Rust no_std, and Rust std applications linked against shared libraries.

Implementation

Loader and dynamic linker

  • Add a fail-closed Thumbv7-M ELF profile.
  • Load ET_DYN applications and their DT_NEEDED dependency closure.
  • Support application-private and system shared libraries.
  • Resolve global, weak, hidden, and protected symbols.
  • Handle diamond-shaped and cyclic DSO dependency graphs.
  • Apply ARM32 REL and PLT relocations using eager binding.
  • Validate relocation ownership, target ranges, permissions, and Thumb function addresses.
  • Build dependency-ordered init and reverse-ordered fini plans.
  • Publish linked images atomically and roll back failed link sessions.

Application lifecycle

  • Add ApplicationManager, ApplicationService, and ThreadGroup.
  • Keep application membership and resource ownership outside the generic Thread type.
  • Wait for application child threads before running fini and reclaiming images.
  • Keep shared system DSOs alive through counted leases.
  • Support repeated and concurrent application loading without leaking private images.

Runtime integration

  • Add the Thumb dynamic startup object and libc DSO runtime.
  • Pass argc, argv, envp, and auxv to dynamic applications.
  • Integrate constructors, main, atexit, destructors, pthread cleanup, and application exit.
  • Support Rust std applications and emulated TLS.
  • Transfer dynamically allocated pthread stack ownership to the kernel so the stack is released only after the scheduler switches away from it.

Build integration

  • Build dynamic artifacts with the board's configured arm-none-eabi-gcc toolchain.
  • Use the GNU linker long Thumb PLT form required by the current relocation contract.
  • Add reusable GN templates for dynamic applications, DSOs, and application bundles.
  • Add an ELF contract gate that validates the target ABI, PIE/DSO format, relocation allowlist, NOW binding, non-executable stack, and absence of text relocations.
  • Register all dynamic application checks through a single //kernel/tests:check_dynamic target.

Validation

The following scenarios are covered by QEMU integration tests:

  • basic dynamic application startup and exit
  • C and C++ PIE applications
  • Rust no_std and Rust std applications
  • private and shared DSOs
  • diamond-shaped and cyclic dependency graphs
  • weak, hidden, and protected symbol resolution
  • constructor and destructor ordering
  • rejected unresolved symbol rollback
  • repeated application loading
  • multiple applications loaded sequentially
  • concurrent instances with isolated private DSOs
  • pthread creation and application ThreadGroup inheritance
  • per-thread emutls isolation
  • application and DSO resource reclamation

Current scope and limitations

This PR establishes the first supported Thumbv7-M dynamic ELF profile. It is not intended to implement every feature of a general-purpose ELF dynamic linker.

The current profile deliberately:

  • supports Thumbv7-M soft-float only
  • supports four ARM runtime relocation types
  • uses eager binding only
  • uses emutls instead of native PT_TLS
  • does not provide dlopen, dlsym, or dlclose
  • rejects symbol versioning, RPATH, RUNPATH, text relocations, and executable stacks
  • treats PT_GNU_RELRO as optional because the selected bare-metal GNU linker does not emit it
  • records segment permissions logically on the current flat-memory backend; hardware-enforced W^X/RELRO requires a future MPU-capable backend
  • is currently enabled and runtime-tested on qemu_mps2_an385

Unsupported ELF features are rejected during admission rather than being silently ignored.

Related PRs

@shihange-vivo
shihange-vivo force-pushed the thumbv7_loader_and_linker branch from 56f5d9c to 93ddd2e Compare September 18, 2026 10:12
@shihange-vivo

Copy link
Copy Markdown
Author

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: check_format (failure), build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/35333635066.

@shihange-vivo

Copy link
Copy Markdown
Author

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: apply_prs (cancelled), check_format (cancelled), check_license (cancelled), build_host (cancelled), build_and_check_boards (cancelled), see https://github.com/vivoblueos/kernel/actions/runs/35335060668.

@github-actions

Copy link
Copy Markdown

@shihange-vivo

Copy link
Copy Markdown
Author

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: check_license (failure), build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/35335270126.

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/35336114515.

@shihange-vivo

Copy link
Copy Markdown
Author

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/35337820529.

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.

1 participant