diff options
author | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2020-12-30 11:00:22 +0100 |
---|---|---|
committer | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2021-02-23 11:33:14 +0100 |
commit | ed89275cb820bb7ab283c51e461d852d1c8bec63 (patch) | |
tree | e076d92145806c6de92194dfa816e9944c2d27f2 /backend | |
parent | 30feb31c6d6e9235acad42ec5d09d14f3919cc36 (diff) | |
download | compcert-ed89275cb820bb7ab283c51e461d852d1c8bec63.tar.gz compcert-ed89275cb820bb7ab283c51e461d852d1c8bec63.zip |
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.
Diffstat (limited to 'backend')
-rw-r--r-- | backend/JsonAST.ml | 10 | ||||
-rw-r--r-- | backend/PrintAsm.ml | 2 | ||||
-rw-r--r-- | backend/PrintAsmaux.ml | 23 |
3 files changed, 25 insertions, 10 deletions
diff --git a/backend/JsonAST.ml b/backend/JsonAST.ml index 8905e252..d218e567 100644 --- a/backend/JsonAST.ml +++ b/backend/JsonAST.ml @@ -21,14 +21,22 @@ open Sections let pp_storage pp static = pp_jstring pp (if static then "Static" else "Extern") +let pp_init pp init = + pp_jstring pp + (match init with + | Uninit -> "Uninit" + | Init -> "Init" + | Init_reloc -> "Init_reloc") + let pp_section pp sec = let pp_simple name = pp_jsingle_object pp "Section Name" pp_jstring name and pp_complex name init = pp_jobject_start pp; pp_jmember ~first:true pp "Section Name" pp_jstring name; - pp_jmember pp "Init" pp_jbool init; + pp_jmember pp "Init" pp_init init; pp_jobject_end pp in + match sec with | Section_text -> pp_simple "Text" | Section_data init -> pp_complex "Data" init diff --git a/backend/PrintAsm.ml b/backend/PrintAsm.ml index 155f5e55..22df68ae 100644 --- a/backend/PrintAsm.ml +++ b/backend/PrintAsm.ml @@ -121,7 +121,7 @@ module Printer(Target:TARGET) = let sec = match C2C.atom_sections name with | [s] -> s - | _ -> Section_data true + | _ -> Section_data Init and align = match C2C.atom_alignof name with | Some a -> a 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 |