FS#52867 - [erlang] 19.2-1 beam_lib reports invalid_chunk "Abst"

Attached to Project: Community Packages
Opened by Incomplete Ness (incomplete) - Monday, 06 February 2017, 09:08 GMT
Last edited by Alexander F. Rødseth (xyproto) - Monday, 06 March 2017, 21:13 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Alexander F. Rødseth (xyproto)
Architecture x86_64
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:

beam_lib:chunks("/usr/lib/erlang/lib/mnesia-4.13.4/ebin/mnesia.beam", [abstract_code]).

would return:

{error,beam_lib,
{invalid_chunk,"/usr/lib/erlang/lib/mnesia-4.13.4/ebin/mnesia.beam",
"Abst"}}

while I was expecting an ok tuple, which looks like "{ok, {module(), [chunkdata()]}}".

This makes dialyzer unusable, for it depends on abstract code.

I don't think this is an upstream problem, because I haven't upgraded erlang in a long time, (I am using erlang 18.3.3-1, but the bug is reproducible in the latest 19.2-1 version), and I remember dialyzer working fine some times ago while I was using 18.3.3-1.


Additional info:
* package version(s)
erlang 19.2-1
* config and/or log files etc.


Steps to reproduce:

1) install erlang 19.2-1 with `pacman -S erlang` or download this version from archive.archlinux.org
2) type `erl` in bash to open an erlang shell
3) type `beam_lib:chunks("/usr/lib/erlang/lib/mnesia-4.13.4/ebin/mnesia.beam", [abstract_code]).`
4) the reported error message should appear in the shell
This task depends upon

Closed by  Alexander F. Rødseth (xyproto)
Monday, 06 March 2017, 21:13 GMT
Reason for closing:  Fixed
Comment by Incomplete Ness (incomplete) - Monday, 06 February 2017, 11:06 GMT
Just downloaded erlang source code from http://www.erlang.org/downloads, manually compiled it, didn't work either, same source code works on an Ubuntu machine.

Also, if you create a simple .erl file, and compile with +debug_info, then call beam_lib:chunnks/2 on it, it works ok.
Comment by Incomplete Ness (incomplete) - Monday, 06 February 2017, 12:23 GMT
Turns out, binary_to_term/1 cannot handle the binary (attachment) in the "Abst" section of beam_lib:all_chunks("/usr/lib/erlang/lib/mnesia-4.13.4/ebin/mnesia.beam"), but if you copy the binary to an Ubuntu box, then binary_to_term works fine.
Comment by Incomplete Ness (incomplete) - Tuesday, 07 February 2017, 12:07 GMT
Let B = binary_to_term(<<"insert contents of attachment here">>), do this on a good machine, e.g. an Ubuntu distribution,

then on Arch, open an erlang shell, type:

binary_to_term(term_to_binary(B, [compressed])).

you would get an error, however, this works fine:

binary_to_term(term_to_binary(a_simple_atom, [compressed])).

If you do all the above procedures on an Ubuntu machine, everything works.
Comment by Incomplete Ness (incomplete) - Thursday, 09 February 2017, 03:42 GMT
Reason found, erlang requires zlib 1.2.8 (as specified in erts/emulator/zlib/zlib.h), but Arch has zlib 1.2.11-1.

Downgraded zlib to 1.2.8-7, beam_lib:chunks works fine now.

Sitting here waiting for other packages to be broken.

Comment by Incomplete Ness (incomplete) - Thursday, 09 February 2017, 04:12 GMT
For those who have the same problem, you can also try --enable-builtin-zlib when configuring erlang, which means you need to build erlang manually though.
Comment by Alexander F. Rødseth (xyproto) - Wednesday, 01 March 2017, 15:04 GMT
Will update the erlang package with --enable-builtin-zlib.
Comment by Alexander F. Rødseth (xyproto) - Monday, 06 March 2017, 14:13 GMT
The updated package should appear in [community] shortly. It is built with --enable-builtin-zlib.

However, I still get an error when running `beam_lib:chunks("/usr/lib/erlang/lib/mnesia-4.13.4/ebin/mnesia.beam", [abstract_code]).` in erl. However, I never got "Abst" as part of the error message when following the steps to reproduce the issue, I got this instead:

{error,beam_lib,
{file_error,"/usr/lib/erlang/lib/mnesia-4.13.4/ebin/mnesia.beam",
enoent}}


Does the updated package work for you?
Comment by Incomplete Ness (incomplete) - Monday, 06 March 2017, 14:34 GMT
Probably because you have installed erlang to a different location, or mnesia's version has changed, try this:

`beam_lib:chunks(code:which(mnesia), [abstract_code]).`

It should be OK.
Comment by Alexander F. Rødseth (xyproto) - Monday, 06 March 2017, 21:13 GMT
Yes, that works. Fixed erlang-nox as well.

Please re-open if there should be further issues with this.

Thanks everyone for reproducible test cases, good suggestions and testing.

Loading...