Skip to content

[native] Construct DSO names and directory paths without local strings - #12515

Merged
simonrozsival merged 20 commits into
mainfrom
dev/simonrozsival/simplify-dso-name
Sep 1, 2026
Merged

simonrozsival merged 20 commits into
mainfrom
dev/simonrozsival/simplify-dso-name

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Remove the CLR/NativeAOT local-string dependencies from DSO-name, path and directory construction, without introducing libc++ ownership or fixed-size limits. This removes the last strings.hh includes from the CLR/NativeAOT code.

Part of #12533. This PR is the combination of what were previously two stacked PRs — the DSO-name work and the directory-creation work — which sat directly on top of each other and modified the same files (android-system.hh/cc, util.hh/cc). They are reviewed together here.

DSO names and paths

  • centralize conditional lib prefix and .so suffix construction
  • make DSO-name and full-path formatters return the negative required capacity including NUL
  • retry through non-template helpers with explicit stack-buffer capacities
  • return either the caller's stack buffer or exact-size malloc() storage, with no heap out-parameters
  • free returned storage only when it differs from the caller-owned stack buffer
  • preserve the original separator insertion and P/Invoke name-normalization behavior

Directory creation

Preserves dynamically sized directory paths:

  • calculate strlen(pathname) + 1 once for mutable directory-path storage
  • use the stack buffer when it fits and exact-size malloc() storage otherwise
  • represent ownership through pointer identity and free the path only when it differs from the stack buffer
  • temporarily terminate each component in place before calling mkdir()
  • preserve filesystem errno across conditional heap cleanup
  • remove the final CLR/NativeAOT strings.hh includes

Both halves use the same ownership convention — a returned pointer is freed only when it differs from the caller's stack buffer — which is the main reason they are easier to review as one change.

Validation

  • CoreCLR, MonoVM and NativeAOT all build clean

Copilot AI lite review requested due to automatic review settings August 25, 2026 13:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR factors out repeated DSO name normalization (optional lib prefix + mandatory .so suffix) into a shared helper and uses it in both CoreCLR DSO path construction and P/Invoke override loading to reduce duplicated string manipulation.

Changes:

  • Added Util::append_dso_name() helper to normalize DSO names (prefix/suffix).
  • Updated AndroidSystem::get_full_dso_path() to use the shared helper.
  • Updated P/Invoke override loading to use the shared helper when rewriting short library names.
Show a summary per file
File Description
src/native/clr/runtime-base/android-system.cc Uses shared helper for full DSO path construction while preserving rooted/path-qualified handling.
src/native/clr/include/runtime-base/util.hh Introduces shared helper for DSO name normalization.
src/native/clr/include/host/pinvoke-override-impl.hh Uses shared helper when rewriting [DllImport] names like log/liblog.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/native/clr/include/runtime-base/util.hh Outdated
@simonrozsival simonrozsival added the drop-libcpp Work to remove the libc++ dependency from Android NativeAOT label Aug 25, 2026
@simonrozsival simonrozsival changed the title Share DSO name construction Use fixed buffers for DSO name construction Aug 25, 2026
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/simplify-dso-name branch from 67f7f33 to 51ef76a Compare August 25, 2026 15:09
@simonrozsival
simonrozsival changed the base branch from main to dev/simonrozsival/replace-simple-local-strings August 25, 2026 15:10
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/simplify-dso-name branch 2 times, most recently from 355d3d7 to 4c9090e Compare August 25, 2026 15:35
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/simplify-dso-name branch from 4c9090e to 390be0f Compare August 25, 2026 15:42
@simonrozsival simonrozsival changed the title Use fixed buffers for DSO name construction Construct DSO names without local strings Aug 25, 2026
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/simplify-dso-name branch from 390be0f to 2a53b4d Compare August 25, 2026 15:54
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/simplify-dso-name branch 2 times, most recently from 2ea7b1e to 19e08dc Compare August 25, 2026 18:53
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/simplify-dso-name branch from 19e08dc to 821de28 Compare August 25, 2026 21:27
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/simplify-dso-name branch from 821de28 to 0c6fa97 Compare August 25, 2026 21:32
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/simplify-dso-name branch from 0c6fa97 to cc5e351 Compare August 25, 2026 21:41
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/simplify-dso-name branch from cc5e351 to 7dc6df9 Compare August 25, 2026 21:51
@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Aug 31, 2026
Base automatically changed from dev/simonrozsival/replace-simple-local-strings to main August 31, 2026 13:39
simonrozsival and others added 19 commits August 31, 2026 08:39
Use one helper to conditionally add the lib prefix and .so suffix for runtime DSO lookup and P/Invoke override loading.

Co-authored-by: Copilot <[email protected]>
Return formatted DSO and lookup-path lengths through caller-owned buffers, removing the remaining local strings from both normalization paths.

Co-authored-by: Copilot <[email protected]>
Preserve the unbounded behavior of dynamic local strings without introducing libc++ ownership.

Co-authored-by: Copilot <[email protected]>
Return the malloc-allocated joined path directly after releasing the temporary DSO name.

Co-authored-by: Copilot <[email protected]>
Calculate complete DSO sizes first, use the sensible local buffer when possible, and allocate only larger names and paths.

Co-authored-by: Copilot <[email protected]>
Return the selected stack or heap buffer from DSO formatters and report the exact required capacity when local storage is too small.

Co-authored-by: Copilot <[email protected]>
Rely on free(nullptr) and name stack-backed DSO storage explicitly.

Co-authored-by: Copilot <[email protected]>
Use non-template DSO helpers and make callers provide each stack buffer capacity.

Co-authored-by: Copilot <[email protected]>
Remove heap-buffer out parameters and free returned DSO strings only when they differ from their stack buffers.

Co-authored-by: Copilot <[email protected]>
`get_full_dso_path` gained a second overload whose parameter list is
identical to the existing one and differs only in its return type, which is
not a valid overload.

Rename the raw `ssize_t` variant to `format_full_dso_path` and leave the
`char*` wrapper as the only `get_full_dso_path`.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 0a35a0db-502d-48c0-8468-e73b5dd0ab2e
Replace the resizable local string in Util::create_directory with a checked mutable path buffer and report ENAMETOOLONG when it cannot fit.

Co-authored-by: Copilot <[email protected]>
Stop scanning once the fixed create-directory buffer capacity is reached.

Co-authored-by: Copilot <[email protected]>
The stacked fixed-buffer migrations remove every remaining CLR and NativeAOT consumer of strings.hh, so drop the final includes.

Co-authored-by: Copilot <[email protected]>
Preserve the former dynamic local string behavior with malloc/free instead of imposing SENSIBLE_PATH_MAX as a path limit.

Co-authored-by: Copilot <[email protected]>
Use the sensible local buffer for common paths and allocate only when the complete path exceeds it.

Co-authored-by: Copilot <[email protected]>
Keep typical paths in local storage, use malloc only when needed, and clean up through Util::free_if_used.

Co-authored-by: Copilot <[email protected]>
Rely on free(nullptr) and name stack-backed directory storage explicitly.

Co-authored-by: Copilot <[email protected]>
Eliminate the separate heap pointer and free directory storage only when it differs from the stack buffer.

Co-authored-by: Copilot <[email protected]>
create_directory no longer uses dynamic_local_string, so the header is
no longer needed here.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 0a35a0db-502d-48c0-8468-e73b5dd0ab2e
@jonathanpeppers
jonathanpeppers force-pushed the dev/simonrozsival/simplify-dso-name branch from 48ac89b to 057798b Compare August 31, 2026 13:39
Keep fast local failure detection while allowing slower CI hosts up to two minutes to complete apkdiff. Report the selected timeout in failure diagnostics.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival
simonrozsival merged commit 141aa6f into main Sep 1, 2026
44 checks passed
@simonrozsival
simonrozsival deleted the dev/simonrozsival/simplify-dso-name branch September 1, 2026 10:14
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

drop-libcpp Work to remove the libc++ dependency from Android NativeAOT ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants