Repository navigation
Fix allocator compatibility with Rust 1.87 and newer - #79
Open
lkshminarayanan wants to merge 2 commits into
Open
lkshminarayanan wants to merge 2 commits into
lkshminarayanan wants to merge 2 commits into
Conversation
Verifying Rust programs compiled with rustc 1.87 or newer fails with "Tried to execute an unknown external function" errors, as the RustPrepPass no longer recognizes the allocator calls it reroutes. Since Rust 1.87, the compiler-internal allocator symbols are v0-mangled under the "__rustc" namespace, e.g., __rust_alloc is now emitted as _RNvCs<hash>_7___rustc12___rust_alloc. The calls to __rust_alloc & co. were thus no longer rerouted to genmc__rust_alloc & co. Ref: rust-lang/rust#127173 Demangle __rustc-internal symbols before matching them against the allocator function names. Unmangled symbols emitted by older rustc versions are still handled as before. This includes the __rust_no_alloc_shim_is_unstable global, which rustc 1.87 and 1.88 deliberately keep unmangled, so removeAllocShim() still finds it. Signed-off-by: Lakshmi Narayanan Sreethar <slnarayanan.tvl@gmail.com>
Since Rust 1.89, the __rust_no_alloc_shim_is_unstable global variable has been replaced by a (mangled) __rust_no_alloc_shim_is_unstable_v2 function that is called before allocating. The function is defined in the allocator shim that rustc only generates when linking the final binary, so verifying Rust programs fails with "Tried to execute an unknown external function" errors. Ref: rust-lang/rust#141061 The function is empty and only exists to cause a link error if the allocator shim is missing. As we reroute the allocator calls to genmc__rust_alloc & co. anyway, remove its calls if the global variable is not present, similar to how removeAllocShim() handles the global variable in older versions. Signed-off-by: Lakshmi Narayanan Sreethar <slnarayanan.tvl@gmail.com>
This branch has not been deployed
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.
Rust programs that allocate memory can fail verification with “Tried to execute an unknown external function” errors on recent rustc versions. This PR updates RustPrepPass to handle two changes in Rust’s allocator interface:
Rust 1.87: mangled allocator symbols. Compiler-internal allocator symbols are now v0-mangled under the
__rustcnamespace. For example,__rust_allocbecomes_RNvCs<hash>_7___rustc12___rust_alloc, so the existing name matching no longer redirects calls togenmc__rust_allocand its counterparts.Fix: Demangle these symbols before matching allocator names.
Refs Mangle rustc_std_internal_symbols functions rust-lang/rust#127173
Rust 1.89: function-based allocation shim check. The
__rust_no_alloc_shim_is_unstableglobal was replaced by a mangled__rust_no_alloc_shim_is_unstable_v2function called before allocation. Its definition is an empty function generated as part of the allocator shim when linking the final binary, so it is unavailable during verification.Fix: Remove calls to this function when the legacy global is absent. The calls only enforce the presence of the allocator shim at link time and are unnecessary because GenMC redirects the allocator calls.
Refs Change __rust_no_alloc_shim_is_unstable to be a function rust-lang/rust#141061
The changes are split into two commits, one for each compiler change. Existing handling of unmangled allocator symbols and the legacy global is preserved, including Rust 1.87 and 1.88, which deliberately leave the global unmangled.
Refs #71