forked from erlang/otp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix hang when calling functions in a module with an on_load attribute
from a native module The fix consists in adding a new opcode for hipe stub calls that is used to replace the call to error_handler:undefined_function/3. This stub directly calls the function: there is no need to go through error_handler:undefined_function/3 once we know the module is loaded, and, more importantly, when error_handler module itself was natively compiled (with native code loaded), the emulator did loop infinitely. The fix also comes with a non-regression test that will prevent this bug to reappear again.
- Loading branch information
Showing
8 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-module(hipe_SUITE). | ||
|
||
-include("test_server.hrl"). | ||
|
||
-export([all/1,call_beam_module_with_on_load/1]). | ||
|
||
all(suite) -> | ||
[call_beam_module_with_on_load]. | ||
|
||
call_beam_module_with_on_load(suite) -> | ||
[]; | ||
call_beam_module_with_on_load(doc) -> | ||
["Test that we can call a non-native module with a on_load from a native module"]; | ||
call_beam_module_with_on_load(Config) when is_list(Config) -> | ||
?line DataDir = ?config(data_dir, Config), | ||
?line CallerModule = filename:join(DataDir, "native_caller.erl"), | ||
?line CalleeModule = filename:join(DataDir, "beam_callee.erl"), | ||
?line PrivDir = ?config(priv_dir, Config), | ||
test_call_with_on_load(PrivDir, CallerModule, CalleeModule). | ||
|
||
test_call_with_on_load(PrivDir, CallerModule, CalleeModule) -> | ||
% Compile both modules. | ||
?line {ok, CallerModuleName} = compile:file(CallerModule, [{outdir, PrivDir}]), | ||
?line {ok, CalleeModuleName} = compile:file(CalleeModule, [{outdir, PrivDir}]), | ||
% Add PrivDir to the path so we can load modules interactively. | ||
AbsPrivDir = filename:absname(PrivDir), | ||
?line true = code:add_patha(AbsPrivDir), | ||
% Call the function in caller module. | ||
?line ok = CallerModuleName:call(CalleeModuleName), | ||
% Purge both modules now. | ||
?line true = code:soft_purge(CallerModuleName), | ||
?line true = code:soft_purge(CalleeModuleName), | ||
% Remove PrivDir from the path. | ||
?line true = code:del_path(AbsPrivDir), | ||
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-module(beam_callee). | ||
-on_load(on_load/0). | ||
-export([f/0]). | ||
|
||
on_load() -> | ||
ok. | ||
|
||
f() -> | ||
false = code:is_module_native(?MODULE), | ||
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-module(native_caller). | ||
-compile([native]). | ||
-export([call/1]). | ||
|
||
call(CalleeModuleName) -> | ||
true = code:is_module_native(?MODULE), | ||
ok = CalleeModuleName:f(), | ||
ok = CalleeModuleName:f(), | ||
ok. |