Skip to content

Fix prune of callback modules from AVM libs#60

Merged
UncleGrumpy merged 1 commit intoatomvm:masterfrom
petermm:fix-prune-callbacks
Feb 22, 2026
Merged

Fix prune of callback modules from AVM libs#60
UncleGrumpy merged 1 commit intoatomvm:masterfrom
petermm:fix-prune-callbacks

Conversation

@petermm
Copy link
Contributor

@petermm petermm commented Feb 18, 2026

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)

@petermm petermm force-pushed the fix-prune-callbacks branch 2 times, most recently from 4ca9f8a to 4ce5cb6 Compare February 18, 2026 13:09
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
@UncleGrumpy UncleGrumpy merged commit 748f776 into atomvm:master Feb 22, 2026
10 checks passed
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
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.

-p prunes callbacks

3 participants