[erlang-bugs] Crash when using -on_load() directive.
Mikael Pettersson
mikpelinux@REDACTED
Thu Feb 19 13:01:05 CET 2015
Rich Neswold writes:
> Hello,
>
> I'm trying to use the -on_load() directive on NetBSD/amd64, but I'm having
> problems. Even this simple test file (test.erl) fails:
>
> -module(test).
> -on_load(load_my_nifs/0).
>
> load_my_nifs() ->
> io:format("Loaded module.~n"),
> ok.
>
> Try to compile as byte-code and then native:
>
> $ erl
> Erlang/OTP 17 (erts-6.3) [source] [64-bit] [smp:8:8] [async-threads:10]
> [hipe] [kernel-poll:false]
>
> Eshell V6.3 (abort with ^G)
> 1> c(test).
> Loaded module.
> {ok,test}
> 2> c(test, [native]).
> <HiPE (v 3.11.2)> EXITED with reason {'trans_fun/2',on_load}
> @hipe_beam_to_icode:1174
>
> =ERROR REPORT==== 18-Feb-2015::13:42:46 ===
> Error in process <0.37.0> with exit value:
> {{badmatch,{'EXIT',{{hipe_beam_to_icode,1174,{'trans_fun/2',on_load}},[{hipe_beam_to_icode,trans_fun,2,[]},{hipe_beam_to_icode,trans_fun,2,[]},{hipe_beam_to_icode,trans_mfa_code,5,[]},{hipe_beam_to_icode,trans_beam_function_chunk...
>
> test.erl: internal error in native_compile;
> crash
> reason: {badmatch,{'EXIT',{{hipe_beam_to_icode,1174,{'trans_fun/2',on_load}},
> [{hipe_beam_to_icode,trans_fun,2,[]},
> {hipe_beam_to_icode,trans_fun,2,[]},
> {hipe_beam_to_icode,trans_mfa_code,5,[]},
> {hipe_beam_to_icode,trans_beam_function_chunk,2,[]},
> {hipe_beam_to_icode,'-module/2-lc$^1/1-1-',2,[]},
> {hipe,get_beam_icode,4,[]},
> {hipe,'-run_compiler_1/3-fun-0-',4,[]},
> {hipe_icode_callgraph,get_called_modules,1,[]}]}}}
>
> in function hipe:get_beam_icode/4
> in call from hipe:'-run_compiler_1/3-fun-0-'/4
> in call from hipe_icode_callgraph:get_called_modules/1
> error
> 3>
>
>
> This also happens on an R16B03-1 installation. The documentation doesn't
> mention the directive is limited to byte-code compiles. But even if it was,
> the native compiler should print an error instead of crashing.
>
> Are other platforms having this problem?
It's a generic problem affecting all platforms.
Code loading is complex, adding native code to the mix makes it more so,
and then on_load adds yet another dimension of complex interactions.
Yes, the compiler should reject the code gracefully instead.
More information about the erlang-bugs
mailing list