Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-1345

compiler module file method does not allow BEAM to be converted to asm

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Won't Do
    • Affects Version/s: 23
    • Fix Version/s: None
    • Component/s: compiler
    • Labels:
      None

      Description

      Unfortunately the module is not set correctly in compile.erl and is set to the atom "none" and there is no workaround (no_error_module_mismatch has no effect in this context), the only thing that would work is the native option which causes the module name to be set correctly:

      c("beamfile", [from_beam,'S']).
      

      yields in all cases

      ** Module name 'none' does not match file name '"beamfile"' **
      {error,badfile}
      

      Which is not ideal as it is relatively uncertain if there is any other straight forward method to generate recompilable asm code straight from BEAM.  The BEAM asm can be fetched easily and represented in a tree-like data structure variant, or even as an AST from the beam_lib as can the original erlang if the debug info included (which could then generate a .S file of course...)  From beam_lib format, manual conversion is possible but would be very tedious.  Of course "compile:forms" would be able to recompile either of those which also can require some clunky adapter code.

      It seems from_beam is a new option and this use case scenario is simply not thought out or tried.  The native option being used to set the module name thereby seems to be a rather strange way to make some other functionality work.  The correct thing would be to always set the module name appropriately, and whatever other functionality from_beam is used for would have another variable set to indicate native.

      Here is the offending code from lib/compiler/compile.erl:

      read_beam_file(_Code, St) ->
          case file:read_file(St#compile.ifile) of {ok,Beam} ->
           Infile = St#compile.ifile,
           case no_native_compilation(Infile, St) of true ->
           {ok,none,St#compile{module=none}}; false ->
           Mod0 = filename:rootname(filename:basename(Infile)),
           Mod = list_to_atom(Mod0),
           {ok,Beam,St#compile{module=Mod,ofile=Infile}}
           end;
      

        Attachments

          Activity

            People

            Assignee:
            bjorn Björn Gustavsson
            Reporter:
            gregorymorse GregoryMorse
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: