Fix prune of callback modules from AVM libs#60
Merged
UncleGrumpy merged 1 commit intoatomvm:masterfrom Feb 22, 2026
Merged
Conversation
pguyot
reviewed
Feb 18, 2026
4ca9f8a to
4ce5cb6
Compare
pguyot
reviewed
Feb 19, 2026
When using prune with modules sourced from a .avm library, modules referenced only in literals (e.g., supervisor callback modules in child specs) were incorrectly pruned. The root cause was that parse_beam (the AVM parsing path) did not extract the literals chunk, so get_atoms/1 could not find atoms that only appear in the literals table — such as a worker module name inside a supervisor child spec map. The fix extends the existing beam_lib:chunks/2 call in parse_beam to also fetch the raw "LitT" and "LitU" chunks (compressed and uncompressed literals, respectively), and extracts uncompressed_literals inline. This keeps it to a single beam_lib call and handles both OTP < 28 (compressed LitT) and OTP >= 28 (uncompressed LitT, or LitU from repackaged AVMs). Signed-off-by: Peter M <petermm@gmail.com> Amp-Thread-ID: https://ampcode.com/threads/T-019c6ff0-e8c0-746a-a012-ac0f808f8424
4ce5cb6 to
5de7197
Compare
This was referenced Feb 22, 2026
pguyot
approved these changes
Feb 22, 2026
bettio
added a commit
to atomvm/AtomVM
that referenced
this pull request
Feb 27, 2026
Use atomvm_packbeam instead of built-in C packbeam Kept the remove lines for release avm builds. Install packbeam escript as bin/packbeam Obsoletes #1429 Requires atomvm/atomvm_packbeam#47 Adding -p for runnable would be a good thing but requires atomvm/atomvm_packbeam#60 These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
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.
Fixes: #58
https://ampcode.com/threads/T-019c6de0-ba10-7688-bedb-4ce12d207c0a
When using -p (prune) with modules sourced from a .avm library, modules referenced only in literals (e.g., supervisor callback modules in child specs) were incorrectly pruned.
The root cause was that parse_beam (the AVM parsing path) did not extract uncompressed_literals, while the .beam parsing path (parse_file(beam, ...)) did. This meant get_atoms/1 could not find atoms that only appear in the literals table — such as a worker module name inside a supervisor child spec map — when the containing module came from an .avm file.
The fix adds literal extraction to the AVM parsing path, making it consistent with the .beam path.
Test modules added (test/prune_sup/):
start_mod.erl — entrypoint that calls my_sup
my_sup.erl — supervisor-like module with my_worker only in a literal child spec (not in atoms chunk or imports) my_worker.erl — callback module, never directly imported
Tests added:
packbeam_create_prune_supervisor_callback_test — verifies pruning keeps literal-only references (all .beam inputs) packbeam_create_prune_supervisor_callback_from_avm_test — same scenario with modules from a .avm lib (was failing before the fix)