Ensure Lazy has stable behaviour with afl-instrument.

When AFL instrumentation is enabled, the inlining of Lazy.force
is disabled, so that the GC optimisation of removing Forward_tag
blocks is no longer visible in the instrumentation output.
master
Stephen Dolan 2018-05-02 15:11:54 +01:00
parent 5c449dd3d8
commit 8095e5a10f
2 changed files with 21 additions and 7 deletions

View File

@ -1478,6 +1478,8 @@ let get_mod_field modname field =
let code_force_lazy_block =
get_mod_field "CamlinternalLazy" "force_lazy_block"
let code_force_lazy =
get_mod_field "CamlinternalLazy" "force"
;;
(* inline_lazy_force inlines the beginning of the code of Lazy.force. When
@ -1540,13 +1542,24 @@ let inline_lazy_force_switch arg loc =
sw_failaction = Some varg }, loc ))))
let inline_lazy_force arg loc =
if !Clflags.native_code then
(* Lswitch generates compact and efficient native code *)
inline_lazy_force_switch arg loc
if !Clflags.afl_instrument then
(* Disable inlining optimisation if AFL instrumentation active,
so that the GC forwarding optimisation is not visible in the
instrumentation output. (PR#???) *)
Lapply{ap_should_be_tailcall = false;
ap_loc=loc;
ap_func=Lazy.force code_force_lazy;
ap_args=[arg];
ap_inlined=Default_inline;
ap_specialised=Default_specialise}
else
(* generating bytecode: Lswitch would generate too many rather big
tables (~ 250 elts); conditionals are better *)
inline_lazy_force_cond arg loc
if !Clflags.native_code then
(* Lswitch generates compact and efficient native code *)
inline_lazy_force_switch arg loc
else
(* generating bytecode: Lswitch would generate too many rather big
tables (~ 250 elts); conditionals are better *)
inline_lazy_force_cond arg loc
let make_lazy_matching def = function
[] -> fatal_error "Matching.make_lazy_matching"

View File

@ -20,7 +20,8 @@ case $1 in
' -pp "$AWK -f expand_module_aliases.awk"';;
stdlib__pervasives.cm[iox]|stdlib__pervasives.p.cmx) echo ' -nopervasives';;
camlinternalOO.cmx|camlinternalOO.p.cmx) echo ' -inline 0 -afl-inst-ratio 0';;
# never instrument camlinternalOO (PR#7725)
camlinternalLazy.cmx|camlinternalLazy.p.cmx) echo ' -afl-inst-ratio 0';;
# never instrument camlinternalOO or camlinternalLazy (PR#7725)
stdlib__buffer.cmx|stdlib__buffer.p.cmx) echo ' -inline 3';;
# make sure add_char is inlined (PR#5872)
stdlib__buffer.cm[io]) echo ' -w A';;