elixir-lang/elixir

Unable to compile from source

Closed this issue · 6 comments

Elixir and Erlang/OTP versions

The Elixir version is commit 64e4b8905317f21a31ca3c78789580f2aff15e53 and Erlang is commit 800613cca84970750658b294ddd7977843b3bc5d.

Operating system

Ubuntu

Current behavior

I cloned the repo on a VM with Erlang 27 (installed with ./configure, make and make install from branch maint-27). However, when i do make on the freshly cloned Elixir repo, after compiling some files, fails with:

==> mix (compile)

=ERROR REPORT==== 6-Dec-2024::19:31:31.873685 ===

Error in process <0.452.0> with exit value:

{#{message =>

       <<"found error while checking types for Mix.Release.strip_beam/2:\n\n** (MatchError) no match of right hand side value: {:EXIT, {:badarg, [{:erlang, :binary_to_atom, [<<122, 108, 105, 98, 112, 111, 110, 95, 108, 111, 97, 100, 96, 101, 114, 108, 97, 110, 103, 128, 108, 111, 97, 100, 95, 110, 105, 102, 32, 111, 107, 64, 111, 112, 101, 110, 128, 111, 112, 101, 110, ...>>, :utf8], [error_info: %{module: :erl_erts_errors}]}, {:beam_lib, :extract_atom, 2, [file: ~c\"beam_lib.erl\", line: 1217]}, {:beam_lib, :get_atom_data, 8, [file: ~c\"beam_lib.erl\", line: 981]}, {:beam_lib, :scan_beam1, 2, [file: ~c\"beam_lib.erl\", line: 942]}, {:beam_lib, :scan_beam, 4, [file: ~c\"beam_lib.erl\", line: 927]}, {:beam_lib, :read_chunk_data, 3, [file: ~c\"beam_lib.erl\", line: 899]}, {:beam_lib, :read_chunk_data, 2, [file: ~c\"beam_lib.erl\", line: 890]}, {Module.ParallelChecker, :cache_module, 2, [file: ~c\"lib/module/parallel_checker.ex\", line: 379]}]}}\nThe exception happened while checking this code:\n\ndef strip_beam(binary, options) when :erlang.is_list(options) do\n  chunks_to_keep = Enum.map(List.wrap(options[:keep]), &String.to_charlist/1)\n\n  all_chunks =\n    Enum.uniq(:erlang.++([~c\"Attr\"], :erlang.++(:beam_lib.significant_chunks(), chunks_to_keep)))\n\n  compress? = Keyword.get(options, :compress, false)\n\n  case :beam_lib.chunks(binary, all_chunks, [:allow_missing_chunks]) do\n    {:ok, {_, chunks}} ->\n      chunks =\n        for {name, chunk} <- chunks, :erlang.is_binary(chunk) do\n          {name, chunk}\n        into\n          []\n        end\n\n      {:ok, binary} = :beam_lib.build_module(chunks)\n\n      case compress? do\n        x when :erlang.orelse(:erlang.\"=:=\"(x, false), :erlang.\"=:=\"(x, nil)) -> {:ok, binary}\n        _ -> {:ok, :zlib.gzip(binary)}\n      end\n\n    {:error, _, _} = error ->\n      error\n  end\nend\n\nPlease report this bug at: https://github.com/elixir-lang/elixir/issues\n">>,

   '__struct__' => 'Elixir.RuntimeError','__exception__' => true},

 [{beam_lib,read_chunk_data,3,[{file,"beam_lib.erl"},{line,899}]},

  {beam_lib,read_chunk_data,2,[{file,"beam_lib.erl"},{line,890}]},

  {'Elixir.Module.ParallelChecker',cache_module,2,

                                   [{file,"lib/module/parallel_checker.ex"},

                                    {line,379}]},

  {'Elixir.Module.ParallelChecker',fetch_export,4,

                                   [{file,"lib/module/parallel_checker.ex"},

                                    {line,207}]},

  {'Elixir.Module.Types.Apply',export,6,

                               [{file,"lib/module/types/apply.ex"},

                                {line,493}]},

  {'Elixir.Module.Types.Apply',remote,6,

                               [{file,"lib/module/types/apply.ex"},

                                {line,416}]},

  {'Elixir.Module.Types.Expr',of_expr,3,

                              [{file,"lib/module/types/expr.ex"},{line,92}]},

  {'Elixir.Module.Types.Expr','-of_clauses/5-fun-0-',7,

                              [{file,"lib/module/types/expr.ex"},

                               {line,574}]}]}



** (EXIT from #PID<0.88.0>) an exception was raised:

    ** (RuntimeError) found error while checking types for Mix.Release.strip_beam/2:



** (MatchError) no match of right hand side value: {:EXIT, {:badarg, [{:erlang, :binary_to_atom, [<<122, 108, 105, 98, 112, 111, 110, 95, 108, 111, 97, 100, 96, 101, 114, 108, 97, 110, 103, 128, 108, 111, 97, 100, 95, 110, 105, 102, 32, 111, 107, 64, 111, 112, 101, 110, 128, 111, 112, 101, 110, ...>>, :utf8], [error_info: %{module: :erl_erts_errors}]}, {:beam_lib, :extract_atom, 2, [file: ~c"beam_lib.erl", line: 1217]}, {:beam_lib, :get_atom_data, 8, [file: ~c"beam_lib.erl", line: 981]}, {:beam_lib, :scan_beam1, 2, [file: ~c"beam_lib.erl", line: 942]}, {:beam_lib, :scan_beam, 4, [file: ~c"beam_lib.erl", line: 927]}, {:beam_lib, :read_chunk_data, 3, [file: ~c"beam_lib.erl", line: 899]}, {:beam_lib, :read_chunk_data, 2, [file: ~c"beam_lib.erl", line: 890]}, {Module.ParallelChecker, :cache_module, 2, [file: ~c"lib/module/parallel_checker.ex", line: 379]}]}}

The exception happened while checking this code:



def strip_beam(binary, options) when :erlang.is_list(options) do

  chunks_to_keep = Enum.map(List.wrap(options[:keep]), &String.to_charlist/1)



  all_chunks =

    Enum.uniq(:erlang.++([~c"Attr"], :erlang.++(:beam_lib.significant_chunks(), chunks_to_keep)))



  compress? = Keyword.get(options, :compress, false)



  case :beam_lib.chunks(binary, all_chunks, [:allow_missing_chunks]) do

    {:ok, {_, chunks}} ->

      chunks =

        for {name, chunk} <- chunks, :erlang.is_binary(chunk) do

          {name, chunk}

        into

          []

        end



      {:ok, binary} = :beam_lib.build_module(chunks)



      case compress? do

        x when :erlang.orelse(:erlang."=:="(x, false), :erlang."=:="(x, nil)) -> {:ok, binary}

        _ -> {:ok, :zlib.gzip(binary)}

      end



    {:error, _, _} = error ->

      error

  end

end



Please report this bug at: https://github.com/elixir-lang/elixir/issues



        (stdlib 6.1.2) beam_lib.erl:899: :beam_lib.read_chunk_data/3

        (stdlib 6.1.2) beam_lib.erl:890: :beam_lib.read_chunk_data/2

        (elixir 1.18.0-dev) lib/module/parallel_checker.ex:379: Module.ParallelChecker.cache_module/2

        (elixir 1.18.0-dev) lib/module/parallel_checker.ex:207: Module.ParallelChecker.fetch_export/4

        (elixir 1.18.0-dev) lib/module/types/apply.ex:493: Module.Types.Apply.export/6

        (elixir 1.18.0-dev) lib/module/types/apply.ex:416: Module.Types.Apply.remote/6

        (elixir 1.18.0-dev) lib/module/types/expr.ex:92: Module.Types.Expr.of_expr/3

        (elixir 1.18.0-dev) lib/module/types/expr.ex:574: anonymous fn/7 in Module.Types.Expr.of_clauses/5



make: *** [Makefile:117: lib/mix/ebin/Elixir.Mix.beam] Error 1

I tried figuring out what <<122, 108, 105, 98, 112, 111, 110, 95, 108, 111, 97, 100, 96, 101, 114, 108, 97, 110, 103, 128, 108, 111, 97, 100, 95, 110, 105, 102, 32, 111, 107, 64, 111, 112, 101, 110, 128, 111, 112, 101, 110, ...>> is, and it starts as zlibpon_load`erlang and then the ascii character 128 which is nonsense. If I ignore both occurrences of that byte, it seems that the string is zlibpon_load`erlangload_nif ok@openopen before it cuts off.

Expected behavior

It should compile.

I'm trying to figure out what that binary is and what it should be, but since the error said "Please report this bug at: https://github.com/elixir-lang/elixir/issues". I decided to open the issue here just in case.

I wonder if this an issue with your actual Erlang installation? Can you please try running it with a released Erlang (and not maint)?

Built Erlang from master (this would be Erlang 28) and Elixir indeed compiled fine*.

However, using the tag OTP-27.1.3 tag` fails with the same error (even the same string).

I can't try the prebuilt Erlang packages because ESL stopped making them, but I tried kerl, installed the release 27.1.3 and that worked too.

We can close this issue if you want. But I still wonder what that strange string is and where it's coming from. I spent some time trying to look at the Elixir code, but I need more time to figure it out. It does looks like the result of a nif reading the wrong bytes from memory, but that doesn't explain 128 since that's not even a value from Erlang's ETF and specially why it's always the exact same binary if it's reading random bytes.

* When I said it compiled fine, that's true, but it has a problem installing archives. Should I open another issue for that or is using random OTP commits not actually meant to be supported?

@HernanRivasAcosta correct, we don't support Erlang master. We focus on compatibility as soon as the first release candidate is out.

Btw, if you are on Ubuntu, there are install scripts you can use that rely on precompiled Erlang, which should be much faster to install: https://elixir-lang.org/install.html#install-scripts

You could also try reproducing it in Docker. FWIW, I tried 27.1.3 on macOS and it worked fine. :)

I was unnable to reproduce on Docker, so clearly there's something wrong with my configuration, though I can't figure out what.

FROM ubuntu:20.04
RUN apt update && apt install -y git gcc libncurses5-dev libssl-dev make
RUN git clone -b maint-27 https://github.com/erlang/otp.git
RUN cd otp && ./configure && make && make install
RUN git clone https://github.com/elixir-lang/elixir.git
RUN cd elixir && make && make install

Either way, this seems to be entierly on me, so I'm closing the issue.

@HernanRivasAcosta try using the precompiled ones, unless you really want to use Erlang's maint for a reason?