Skip to content

Rewrite packbeam.c #1429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Rewrite packbeam.c #1429

wants to merge 19 commits into from

Conversation

jgonet
Copy link
Contributor

@jgonet jgonet commented Dec 27, 2024

I went and implemented my suggestion from #1394.
I didn't do any thorough checks yet since I want to get feedback first (make -j in build/ doesn't crash on my machine).
Worked on original file, slowly refactoring to what I had in mind. Do we have tests for packbeam or we only check it by usage?

Leaving all commits for now, will squash after acceptance.

  1. Added TRY macro that checks bool output from expression and if false, stops the execution of current function.
  2. Various functions have additional bool output to check for errors.
  3. Refactored error output, printing usage when it makes sense (maybe should've used perror for internals?).
  4. Added TODOs for things that would change the structure stronger that I wanted for now.

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

@jgonet jgonet changed the title Rewrite packbeam Rewrite packbeam.c Dec 27, 2024
@jgonet
Copy link
Contributor Author

jgonet commented Dec 27, 2024

I did expect some CI to fail but not pretty much everything. How can I test it locally? I was doing make clean && make -j inside build/ for local testing (using MacOS).

In any case, I'll try to pin down the issue. You don't need to do full review, just let me know if approach is sane.

@UncleGrumpy
Copy link
Collaborator

See draft PR #1510 as a partial solution to your CI problems... But after pulling your branch and cherry-picking the changes for #1510 it appears that your implementation is not recognizing that when -a is used the first name should be the output name and the remaining parameters are the input files to pack into the named archive...

For example when I try the build the esp32boot target I get an internal error from PackBeam:

$ make esp32boot
[  0%] Built target esp32devmode_beams
[  0%] Built target generated-nifs-hash
[  0%] Built target generated
[ 30%] Built target libAtomVM
[ 46%] Built target libAtomVMLinux-x86_64
[ 46%] Built target PackBEAM
[ 46%] Packing archive esp32devmode.avm
PackBeam: Cannot open file 'esp32devmode.avm'.
make[3]: *** [libs/esp32devmode/src/CMakeFiles/esp32devmode.dir/build.make:71: libs/esp32devmode/src/CMakeFiles/esp32devmode] Error 1
make[2]: *** [CMakeFiles/Makefile2:2248: libs/esp32devmode/src/CMakeFiles/esp32devmode.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:2202: libs/esp32boot/CMakeFiles/esp32boot.dir/rule] Error 2
make: *** [Makefile:793: esp32boot] Error 2

PackBeam should be creating the file esp32devmode.avm not trying to load it. ;-)

@UncleGrumpy
Copy link
Collaborator

I don't think #1510 should be necessary, but the help in the current PackBEAM is slightly ambiguous about the name of the archive directly following the -a flag, or just being the first input parameter after the switches.

@UncleGrumpy
Copy link
Collaborator

Also, one feature missing from the C implementation that the pure erlang module has is a -s option to explicitly specify the start module. This would probably be good to add.

free(file_data.data);
return ret;
}
TRY(safe_read_file(output_file, &file_data));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a problem. Trying to read and verify that the not yet created avm archive is valid... this check should be done after the files have been packed into the output archive.

Copy link
Collaborator

@UncleGrumpy UncleGrumpy Feb 4, 2025

Choose a reason for hiding this comment

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

I can successfully create an archive with lines 209-214 commented out.

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.

2 participants