From 30feb31c6d6e9235acad42ec5d09d14f3919cc36 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 30 Dec 2020 11:41:10 +0100 Subject: Introduce and use PrintAsmaux.variable_section This is a generalization of the previous PrintAsmaux.common_section function that - handles initialized variables in addition to uninitialized variables; - can be used for Section_const, not just for Section_data. --- backend/PrintAsmaux.ml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'backend/PrintAsmaux.ml') diff --git a/backend/PrintAsmaux.ml b/backend/PrintAsmaux.ml index d31507ff..82621010 100644 --- a/backend/PrintAsmaux.ml +++ b/backend/PrintAsmaux.ml @@ -303,11 +303,16 @@ let print_version_and_options oc comment = fprintf oc " %s" Commandline.argv.(i) done; fprintf oc "\n" -(** Get the name of the common section if it is used otherwise the given section - name, with bss as default *) -let common_section ?(sec = ".bss") () = - if !Clflags.option_fcommon then - "COMM" - else - sec +(** 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 + 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 -- cgit 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 From 014883f2f4cfc4fd64fe9aa5f561a971e2ed1345 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Fri, 19 Feb 2021 09:31:03 +0100 Subject: Fix regression on PowerPC / Diab On PowerPC/Diab, common declarations must not be used for small data sections. Add a `~common` option to `PrintAsmaux.variable_section` to control the use of common declarations. The default is whatever is specified on the command line using the `-fcommon` and `-fno-common` options. Use `~common:false` for `Section_small_data` on PowerPC / Diab. Note that on PowerPC/Linux, GCC uses common declarations for uninitialized variables in small data section, so we keep doing this in CompCert as well. --- backend/PrintAsmaux.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'backend/PrintAsmaux.ml') diff --git a/backend/PrintAsmaux.ml b/backend/PrintAsmaux.ml index 7a692d20..e39ba8aa 100644 --- a/backend/PrintAsmaux.ml +++ b/backend/PrintAsmaux.ml @@ -312,12 +312,17 @@ let print_version_and_options oc comment = 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. + - [common] says whether common declarations can be used for uninitialized + variables. It defaults to the status of the [-fcommon] / [-fno-common] + command-line option. Passing [~common:false] is needed when + common declarations cannot be used at all, for example in the context of + small data areas. *) -let variable_section ~sec ?bss ?reloc i = +let variable_section ~sec ?bss ?reloc ?(common = !Clflags.option_fcommon) i = match i with | Uninit -> - if !Clflags.option_fcommon + if common then "COMM" else begin match bss with Some s -> s | None -> sec end | Init -> sec -- cgit