Fix prune of callback modules from AVM libs#60
Open
petermm wants to merge 1 commit intoatomvm:masterfrom
Open
Conversation
pguyot
reviewed
Feb 18, 2026
src/packbeam_api.erl
Outdated
| StrippedData = strip_padding(Data), | ||
| {ok, {Module, ChunkRefs}} = beam_lib:chunks(StrippedData, [imports, exports, atoms]), | ||
| [{module, Module}, {chunk_refs, ChunkRefs}, {data, StrippedData} | Accum]; | ||
| {ok, _, AllChunks} = beam_lib:all_chunks(StrippedData), |
Collaborator
There was a problem hiding this comment.
We do chunks and then all_chunks?
e314a31 to
4ca9f8a
Compare
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>
4ca9f8a to
4ce5cb6
Compare
pguyot
reviewed
Feb 19, 2026
| @@ -0,0 +1,14 @@ | |||
| %% | |||
| %% Copyright (c) 2026 AtomVM | |||
Collaborator
There was a problem hiding this comment.
We have a tradition of identifying authors with names or pseudos, even for very small files.
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)