diff options
author | Greta Yorsh <gyorsh@janestreet.com> | 2019-02-20 18:46:43 +0000 |
---|---|---|
committer | Greta Yorsh <gyorsh@janestreet.com> | 2019-07-15 10:25:26 +0100 |
commit | 27a92a94455b8ace604292ea1c5e09fd6a76048e (patch) | |
tree | d4977d2529d20abb449896e1d02bc7c862c01688 /asmcomp/i386 | |
parent | 658233568930c9b1c291f78d8ac2177e67aa9981 (diff) | |
download | ocaml-27a92a94455b8ace604292ea1c5e09fd6a76048e.tar.gz |
Emit each function in a separate section (amd64,i386,arm,arm64)
Add --enable-function-sections option to configure. With this option,
the compiler will emit each function in a separate named text section,
on supported targets. This enables function reordering using a linker
script. With this option, the compiler also emits caml_hot__code_begin
and caml_hot__code_end sections. This allows a linker script to
move function sections outside of the segments they belong to,
without breaking caml_code_segments.
Diffstat (limited to 'asmcomp/i386')
-rw-r--r-- | asmcomp/i386/emit.mlp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/asmcomp/i386/emit.mlp b/asmcomp/i386/emit.mlp index b1d9ab4010..3e26e2f071 100644 --- a/asmcomp/i386/emit.mlp +++ b/asmcomp/i386/emit.mlp @@ -461,6 +461,16 @@ let emit_global_label s = D.global lbl; _label lbl +(* Output .text section directive, or named .text.<name> if enabled. *) + +let emit_named_text_section func_name = + if Config.function_sections then + begin match system with + | S_macosx | S_mingw | S_cygwin | S_win32 -> D.text () + | _ -> D.section [ ".text."^(emit_symbol func_name) ] (Some "ax") ["@progbits"] + end + else D.text () + (* Output the assembly code for an instruction *) (* Name of current function *) @@ -843,7 +853,7 @@ let emit_instr fallthrough i = for i = 0 to Array.length jumptbl - 1 do D.long (ConstLabel (emit_label jumptbl.(i))) done; - D.text () + emit_named_text_section !function_name | Lentertrap -> () | Ladjust_trap_depth { delta_traps } -> @@ -896,7 +906,7 @@ let fundecl fundecl = call_gc_sites := []; bound_error_sites := []; bound_error_call := 0; - D.text (); + emit_named_text_section !function_name; add_def_symbol fundecl.fun_name; D.align (if system = S_win32 then 4 else 16); D.global (emit_symbol fundecl.fun_name); @@ -963,8 +973,7 @@ let begin_assembly() = D.data (); emit_global_label "data_begin"; - - D.text (); + emit_named_text_section (Compilenv.make_symbol (Some "code_begin")); emit_global_label "code_begin" let end_assembly() = @@ -973,8 +982,7 @@ let end_assembly() = List.iter (fun (cst,lbl) -> emit_float_constant cst lbl) !float_constants end; - D.text (); - + emit_named_text_section (Compilenv.make_symbol (Some "code_end")); emit_global_label "code_end"; D.data (); |