From ed89275cb820bb7ab283c51e461d852d1c8bec63 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 30 Dec 2020 11:00:22 +0100 Subject: Section handling: finer control of variable initialization Distinguish between: - uninitialized variables, which can go in COMM if supported - variables initialized with fixed, numeric quantities, which can go in a readonly section if "const" - variables initialized with symbol addresses which may need relocation, which cannot go in a readonly section even if "const", but can go in a special "const_data" section. Also: on macOS, use ".const" instead of ".literal8" for literals, as not all literals have size 8. --- backend/PrintAsmaux.ml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'backend/PrintAsmaux.ml') diff --git a/backend/PrintAsmaux.ml b/backend/PrintAsmaux.ml index 82621010..7a692d20 100644 --- a/backend/PrintAsmaux.ml +++ b/backend/PrintAsmaux.ml @@ -305,14 +305,21 @@ let print_version_and_options oc comment = fprintf oc "\n" (** Determine the name of the section to use for a variable. - [i] says whether the variable is initialized (true) or not (false). - [sec] is the name of the section to use if initialized or if - no other cases apply. - [bss] is the name of the section to use if uninitialized and + - [i] is the initialization status of the variable. + - [sec] is the name of the section to use if initialized (with no + relocations) or if no other cases apply. + - [reloc] is the name of the section to use if initialized and + containing relocations. If not provided, [sec] is used. + - [bss] is the name of the section to use if uninitialized and common declarations are not used. If not provided, [sec] is used. *) -let variable_section ~sec ?bss i = - if i then sec - else if !Clflags.option_fcommon then "COMM" - else match bss with None -> sec | Some b -> b +let variable_section ~sec ?bss ?reloc i = + match i with + | Uninit -> + if !Clflags.option_fcommon + then "COMM" + else begin match bss with Some s -> s | None -> sec end + | Init -> sec + | Init_reloc -> + begin match reloc with Some s -> s | None -> sec end -- cgit