Add compile-time option -function-sections
parent
63f62123df
commit
351edb49bb
7
Makefile
7
Makefile
|
@ -55,6 +55,11 @@ INCLUDES=-I utils -I parsing -I typing -I bytecomp -I file_formats \
|
|||
COMPFLAGS=-strict-sequence -principal -absname -w +a-4-9-40-41-42-44-45-48-66 \
|
||||
-warn-error A \
|
||||
-bin-annot -safe-string -strict-formats $(INCLUDES)
|
||||
ifeq "$(FUNCTION_SECTIONS)" "true"
|
||||
OPTCOMPFLAGS= -function-sections
|
||||
else
|
||||
OPTCOMPFLAGS=
|
||||
endif
|
||||
LINKFLAGS=
|
||||
|
||||
ifeq "$(strip $(NATDYNLINKOPTS))" ""
|
||||
|
@ -1285,7 +1290,7 @@ endif
|
|||
$(CAMLC) $(COMPFLAGS) -c $<
|
||||
|
||||
.ml.cmx:
|
||||
$(CAMLOPT) $(COMPFLAGS) -c $<
|
||||
$(CAMLOPT) $(COMPFLAGS) $(OPTCOMPFLAGS) -c $<
|
||||
|
||||
partialclean::
|
||||
for d in utils parsing typing bytecomp asmcomp middle_end file_formats \
|
||||
|
|
|
@ -482,7 +482,7 @@ let emit_global_label s =
|
|||
supported on the target system. *)
|
||||
|
||||
let emit_named_text_section func_name =
|
||||
if Config.function_sections then
|
||||
if !Clflags.function_sections then
|
||||
begin match system with
|
||||
| S_macosx
|
||||
(* Names of section segments in macosx are restricted to 16 characters,
|
||||
|
|
|
@ -439,7 +439,7 @@ let emit_load_handler_address handler =
|
|||
(* Output .text section directive, or named .text.<name> if enabled. *)
|
||||
|
||||
let emit_named_text_section func_name =
|
||||
if Config.function_sections then begin
|
||||
if !Clflags.function_sections then begin
|
||||
` .text.{emit_symbol func_name},{emit_string_literal "ax"},{emit_string_literal "%progbits"}\n`
|
||||
end
|
||||
else
|
||||
|
|
|
@ -566,7 +566,7 @@ let assembly_code_for_allocation ?label_after_call_gc i ~n ~far =
|
|||
(* Output .text section directive, or named .text.<name> if enabled. *)
|
||||
|
||||
let emit_named_text_section func_name =
|
||||
if Config.function_sections then begin
|
||||
if !Clflags.function_sections then begin
|
||||
` .text.{emit_symbol func_name},{emit_string_literal "ax"},{emit_string_literal "%progbits"}\n`
|
||||
end
|
||||
else
|
||||
|
|
|
@ -240,10 +240,10 @@ let make_startup_file ~ppf_dump units_list ~crc_interfaces =
|
|||
let globals_map = make_globals_map units_list ~crc_interfaces in
|
||||
compile_phrase (Cmmgen.globals_map globals_map);
|
||||
compile_phrase(Cmmgen.data_segment_table ("_startup" :: name_list));
|
||||
if (Config.function_sections) then
|
||||
compile_phrase(Cmmgen.code_segment_table ("_hot" :: "_startup" :: name_list))
|
||||
if !Clflags.function_sections then
|
||||
compile_phrase(Cmmgen.code_segment_table("_hot" :: "_startup" :: name_list))
|
||||
else
|
||||
compile_phrase(Cmmgen.code_segment_table ("_startup" :: name_list));
|
||||
compile_phrase(Cmmgen.code_segment_table("_startup" :: name_list));
|
||||
let all_names = "_startup" :: "_system" :: name_list in
|
||||
compile_phrase (Cmmgen.frame_table all_names);
|
||||
if Config.spacetime then begin
|
||||
|
|
|
@ -464,7 +464,7 @@ let emit_global_label s =
|
|||
(* Output .text section directive, or named .text.<name> if enabled. *)
|
||||
|
||||
let emit_named_text_section func_name =
|
||||
if Config.function_sections then
|
||||
if !Clflags.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"]
|
||||
|
|
|
@ -1521,9 +1521,8 @@ Optional Features:
|
|||
force strings to be safe
|
||||
--disable-flat-float-array
|
||||
do not use flat float arrays
|
||||
--enable-function-sections
|
||||
generate each function in a separate section if
|
||||
target supports it
|
||||
--disable-function-sections
|
||||
do not emit each function in a separate section
|
||||
--enable-shared[=PKGS] build shared libraries [default=yes]
|
||||
--enable-static[=PKGS] build static libraries [default=yes]
|
||||
--enable-fast-install[=PKGS]
|
||||
|
@ -16529,39 +16528,41 @@ else
|
|||
flat_float_array=true
|
||||
fi
|
||||
|
||||
if test x"$enable_function_sections" = "xyes"; then :
|
||||
if test x"$enable_function_sections" = "xno"; then :
|
||||
function_sections=false
|
||||
else
|
||||
case $arch in #(
|
||||
amd64|i386|arm|arm64) :
|
||||
case $target in #(
|
||||
*-*-cygwin*|*-*-mingw*|*-pc-windows) :
|
||||
*-cygwin*|*-mingw*|*-windows|*-apple-darwin*) :
|
||||
function_sections=false;
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Disabling function sections. No target support." >&5
|
||||
$as_echo "$as_me: WARNING: Disabling function sections. No target support." >&2;} ;; #(
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: Disabling function sections. No target support." >&5
|
||||
$as_echo "$as_me: Disabling function sections. No target support." >&6;} ;; #(
|
||||
*) :
|
||||
case $ocaml_cv_cc_vendor in #(
|
||||
gcc-0123-*|gcc-4-01234567) :
|
||||
function_sections=false;
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Disabling function sections.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: Disabling function sections.
|
||||
Not supported in GCC prior to version 4.8." >&5
|
||||
$as_echo "$as_me: WARNING: Disabling function sections.
|
||||
Not supported in GCC prior to version 4.8." >&2;} ;; #(
|
||||
$as_echo "$as_me: Disabling function sections.
|
||||
Not supported in GCC prior to version 4.8." >&6;} ;; #(
|
||||
clang-012-*|clang-3-01234) :
|
||||
function_sections=false;
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Disabling function sections.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: Disabling function sections.
|
||||
Not supported in Clang prior to version 3.5." >&5
|
||||
$as_echo "$as_me: WARNING: Disabling function sections.
|
||||
Not supported in Clang prior to version 3.5." >&2;} ;; #(
|
||||
$as_echo "$as_me: Disabling function sections.
|
||||
Not supported in Clang prior to version 3.5." >&6;} ;; #(
|
||||
gcc-*|clang-*) :
|
||||
function_sections=true;
|
||||
common_cflags="$common_cflags -ffunction-sections";
|
||||
internal_cflags="$internal_cflags -ffunction-sections";
|
||||
$as_echo "#define FUNCTION_SECTIONS 1" >>confdefs.h
|
||||
;; #(
|
||||
*) :
|
||||
function_sections=false;
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Disabling function sections.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: Disabling function sections.
|
||||
Compiler not supported." >&5
|
||||
$as_echo "$as_me: WARNING: Disabling function sections.
|
||||
Compiler not supported." >&2;} ;; #(
|
||||
$as_echo "$as_me: Disabling function sections.
|
||||
Compiler not supported." >&6;} ;; #(
|
||||
*) :
|
||||
;;
|
||||
esac ;; #(
|
||||
|
@ -16570,11 +16571,9 @@ esac ;; #(
|
|||
esac ;; #(
|
||||
*) :
|
||||
function_sections=false
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Disabling function sections on this target." >&5
|
||||
$as_echo "$as_me: WARNING: Disabling function sections on this target." >&2;} ;;
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: Disabling function sections on this target." >&5
|
||||
$as_echo "$as_me: Disabling function sections on this target." >&6;} ;;
|
||||
esac
|
||||
else
|
||||
function_sections=false
|
||||
fi
|
||||
|
||||
if test x"$with_afl" = "xyes"; then :
|
||||
|
|
22
configure.ac
22
configure.ac
|
@ -354,8 +354,8 @@ AC_ARG_ENABLE([flat-float-array],
|
|||
[do not use flat float arrays])])
|
||||
|
||||
AC_ARG_ENABLE([function-sections],
|
||||
[AS_HELP_STRING([--enable-function-sections],
|
||||
[generate each function in a separate section if target supports it])])
|
||||
[AS_HELP_STRING([--disable-function-sections],
|
||||
[do not emit each function in a separate section])])
|
||||
|
||||
AC_ARG_WITH([afl],
|
||||
[AS_HELP_STRING([--with-afl],
|
||||
|
@ -1618,34 +1618,34 @@ AS_IF([test x"$enable_flat_float_array" = "xno"],
|
|||
[AC_DEFINE([FLAT_FLOAT_ARRAY])
|
||||
flat_float_array=true])
|
||||
|
||||
AS_IF([test x"$enable_function_sections" = "xyes"],
|
||||
AS_IF([test x"$enable_function_sections" = "xno"],
|
||||
[function_sections=false],
|
||||
[AS_CASE([$arch],
|
||||
[amd64|i386|arm|arm64],
|
||||
[AS_CASE([$target],
|
||||
[*-*-cygwin*|*-*-mingw*|*-pc-windows],
|
||||
[*-cygwin*|*-mingw*|*-windows|*-apple-darwin*],
|
||||
[function_sections=false;
|
||||
AC_MSG_WARN([Disabling function sections. No target support.])],
|
||||
AC_MSG_NOTICE([Disabling function sections. No target support.])],
|
||||
[*],
|
||||
[AS_CASE([$ocaml_cv_cc_vendor],
|
||||
[gcc-[0123]-*|gcc-4-[01234567]],
|
||||
[function_sections=false;
|
||||
AC_MSG_WARN([Disabling function sections.
|
||||
AC_MSG_NOTICE([Disabling function sections.
|
||||
Not supported in GCC prior to version 4.8.])],
|
||||
[clang-[012]-*|clang-3-[01234]],
|
||||
[function_sections=false;
|
||||
AC_MSG_WARN([Disabling function sections.
|
||||
AC_MSG_NOTICE([Disabling function sections.
|
||||
Not supported in Clang prior to version 3.5.])],
|
||||
[gcc-*|clang-*],
|
||||
[function_sections=true;
|
||||
common_cflags="$common_cflags -ffunction-sections";
|
||||
internal_cflags="$internal_cflags -ffunction-sections";
|
||||
AC_DEFINE([FUNCTION_SECTIONS])],
|
||||
[*],
|
||||
[function_sections=false;
|
||||
AC_MSG_WARN([Disabling function sections.
|
||||
AC_MSG_NOTICE([Disabling function sections.
|
||||
Compiler not supported.])])])],
|
||||
[function_sections=false
|
||||
AC_MSG_WARN([Disabling function sections on this target.])])],
|
||||
[function_sections=false])
|
||||
AC_MSG_NOTICE([Disabling function sections on this target.])])])
|
||||
|
||||
AS_IF([test x"$with_afl" = "xyes"],
|
||||
[afl=true],
|
||||
|
|
|
@ -94,6 +94,18 @@ let mk_dllpath f =
|
|||
"<dir> Add <dir> to the run-time search path for shared libraries"
|
||||
;;
|
||||
|
||||
let mk_function_sections f =
|
||||
if Config.function_sections then
|
||||
"-function-sections", Arg.Unit f,
|
||||
" Generate each function in a separate section if target supports it"
|
||||
else
|
||||
let err () =
|
||||
raise (Arg.Bad "OCaml has been configured without support for \
|
||||
-function-sections")
|
||||
in
|
||||
"-function-sections", Arg.Unit err, " (option not available)"
|
||||
;;
|
||||
|
||||
let mk_stop_after f =
|
||||
"-stop-after", Arg.Symbol (Clflags.Compiler_pass.pass_names, f),
|
||||
" Stop after the given compilation pass."
|
||||
|
@ -1068,6 +1080,7 @@ module type Optcomp_options = sig
|
|||
val _afl_instrument : unit -> unit
|
||||
val _afl_inst_ratio : int -> unit
|
||||
val _dinterval : unit -> unit
|
||||
val _function_sections : unit -> unit
|
||||
end;;
|
||||
|
||||
module type Opttop_options = sig
|
||||
|
@ -1289,6 +1302,7 @@ struct
|
|||
mk_dtypes F._annot;
|
||||
mk_for_pack_opt F._for_pack;
|
||||
mk_g_opt F._g;
|
||||
mk_function_sections F._function_sections;
|
||||
mk_stop_after F._stop_after;
|
||||
mk_i F._i;
|
||||
mk_I F._I;
|
||||
|
|
|
@ -224,6 +224,7 @@ module type Optcomp_options = sig
|
|||
val _afl_instrument : unit -> unit
|
||||
val _afl_inst_ratio : int -> unit
|
||||
val _dinterval : unit -> unit
|
||||
val _function_sections : unit -> unit
|
||||
end;;
|
||||
|
||||
module type Opttop_options = sig
|
||||
|
|
|
@ -56,6 +56,10 @@ module Options = Main_args.Make_optcomp_options (struct
|
|||
let _config = Misc.show_config_and_exit
|
||||
let _config_var = Misc.show_config_variable_and_exit
|
||||
let _for_pack s = for_package := Some s
|
||||
let _function_sections () =
|
||||
assert (Config.function_sections);
|
||||
first_ccopts := "-ffunction-sections" :: !first_ccopts;
|
||||
function_sections := true
|
||||
let _g = set debug
|
||||
let _i () =
|
||||
print_types := true;
|
||||
|
|
|
@ -35,6 +35,9 @@ OPTCOMPFLAGS=-O3
|
|||
else
|
||||
OPTCOMPFLAGS=
|
||||
endif
|
||||
ifeq "$(FUNCTION_SECTIONS)" "true"
|
||||
OPTCOMPFLAGS += -function-sections
|
||||
endif
|
||||
MKLIB=$(CAMLRUN) $(ROOTDIR)/tools/ocamlmklib
|
||||
|
||||
# Variables that must be defined by individual libraries:
|
||||
|
|
|
@ -30,6 +30,9 @@ OPTCOMPFLAGS=-O3
|
|||
else
|
||||
OPTCOMPFLAGS=
|
||||
endif
|
||||
ifeq "$(FUNCTION_SECTIONS)" "true"
|
||||
OPTCOMPFLAGS += -function-sections
|
||||
endif
|
||||
OPTCOMPILER=$(ROOTDIR)/ocamlopt
|
||||
CAMLOPT=$(CAMLRUN) $(OPTCOMPILER)
|
||||
CAMLDEP=$(BOOT_OCAMLC) -depend
|
||||
|
|
|
@ -178,6 +178,8 @@ let inlining_report = ref false (* -inlining-report *)
|
|||
let afl_instrument = ref Config.afl_instrument (* -afl-instrument *)
|
||||
let afl_inst_ratio = ref 100 (* -afl-inst-ratio *)
|
||||
|
||||
let function_sections = ref false (* -function-sections *)
|
||||
|
||||
let simplify_rounds = ref None (* -rounds *)
|
||||
let default_simplify_rounds = ref 1 (* -rounds *)
|
||||
let rounds () =
|
||||
|
|
|
@ -206,6 +206,7 @@ val dump_flambda_verbose : bool ref
|
|||
val classic_inlining : bool ref
|
||||
val afl_instrument : bool ref
|
||||
val afl_inst_ratio : int ref
|
||||
val function_sections : bool ref
|
||||
|
||||
val all_passes : string list ref
|
||||
val dumped_pass : string -> bool
|
||||
|
|
|
@ -225,7 +225,7 @@ val flat_float_array : bool
|
|||
|
||||
val function_sections : bool
|
||||
(** Whether the compiler was configured to generate
|
||||
functions in separate section *)
|
||||
each function in a separate section *)
|
||||
|
||||
val windows_unicode: bool
|
||||
(** Whether Windows Unicode runtime is enabled *)
|
||||
|
|
Loading…
Reference in New Issue