[erlang-bugs] R15B02 HiPE can't compile modules with on_load attribute

Sverker Eriksson <>
Tue Nov 27 15:08:59 CET 2012


Kostis Sagonas wrote:
> On 11/25/2012 08:16 PM, José Valim wrote:
>> HiPE can't compile a module with on_load attribute. This sample module
>> fails:
>>
>>     -module(foo).
>>     -on_load(do_nothing/0).
>>
>>     %% Exporting the function doesn't affect the outcome
>>     %% -exports([do_nothing/0]).
>>
>>     do_nothing() -> ok.
>>
>>
>> When compiled via command line or via compile:forms.
>> A snippet of the error message is:
>>
>> =ERROR REPORT==== 25-Nov-2012::18:48:29 ===
>> Error in process <0.88.0> with exit value:
>> {{badmatch,{'EXIT',{{hipe_beam_to_icode,1103,{'trans_fun/2',on_load}},[{hipe_beam_to_icode,trans_fun,2,[{file,"hipe_beam_to_icode.erl"},{line,1103}]},{hipe_beam_to_icode,trans_fun,2,[{file,"hipe_beam_to_icode.erl"},{line,253}]},{hipe_beam_to_icode... 
>>
>
> I can easily provide a patch that makes the HiPE compiler not crash 
> when it finds an "on_load" BEAM instruction, but the real fix involves 
> changing the HiPE loader to trigger execution of functions specified 
> as part of the on_load attribute declaration.
>
> Perhaps somebody at OTP who is more familiar with the magic that the 
> BEAM loader does when it finds BEAM code with on_load instructions can 
> do this -- or at least help here.
>
> Kostis

Supporting "on_load" for Hipe is not trivial to do and it is not a 
prioritized job for us right now.

If on_load is used to call erlang:load_nif/2, that's yet another thing 
that would need to be fixed. Right now you can not mix Hipe and NIFs in 
the same module.


/Sverker, Erlang/OTP




More information about the erlang-bugs mailing list