diff options
author | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2022-08-22 17:35:49 +0200 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2022-08-29 13:55:35 +0200 |
commit | 169007c52e27ce1fce6ca5fdd5fc7f43071b8841 (patch) | |
tree | 86e52680d32759cf4c78219fb245bd0467c070a1 /backend/PrintAsmaux.ml | |
parent | 50836f2a04575402aa61a256fe7047c16610992f (diff) | |
download | compcert-169007c52e27ce1fce6ca5fdd5fc7f43071b8841.tar.gz compcert-169007c52e27ce1fce6ca5fdd5fc7f43071b8841.zip |
Support mergeable sections for fixed-size literals
On platforms that support them (ELF, macOS), use mergeable sections
(like `.rodata.cst8`) for 4-, 8- and 16-byte wide literals.
Works only if the LITERAL section is the default one. If the user
provided their own LITERAL section, all literals are put in it
regardless of their sizes.
Support for mergeable string sections is introduced in this commit too
but needs further changes in C2C.ml .
Diffstat (limited to 'backend/PrintAsmaux.ml')
-rw-r--r-- | backend/PrintAsmaux.ml | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/backend/PrintAsmaux.ml b/backend/PrintAsmaux.ml index e39ba8aa..841f4579 100644 --- a/backend/PrintAsmaux.ml +++ b/backend/PrintAsmaux.ml @@ -28,7 +28,6 @@ module type TARGET = val print_comm_symb: out_channel -> Z.t -> P.t -> int -> unit val print_var_info: out_channel -> P.t -> unit val print_fun_info: out_channel -> P.t -> unit - val get_section_names: P.t -> section_name * section_name * section_name val print_file_line: out_channel -> string -> int -> unit val print_optional_fun_info: out_channel -> unit val cfi_startproc: out_channel -> unit @@ -328,3 +327,29 @@ let variable_section ~sec ?bss ?reloc ?(common = !Clflags.option_fcommon) i = | Init -> sec | Init_reloc -> begin match reloc with Some s -> s | None -> sec end + +(** ELF and macOS mergeable section names for literals and strings. *) + +let elf_mergeable_literal_section sz sec = + match sz with + | 0 -> sec + | 4 | 8 | 16 -> sprintf "%s.cst%d,\"aM\",@progbits,%d" sec sz sz + | _ -> assert false + +let elf_mergeable_string_section sz sec = + match sz with + | 0 -> sec + | 1 | 2 | 4 -> sprintf "%s.str%d.%d,\"aMS\",@progbits,%d" sec sz sz sz + | _ -> assert false + +let macos_mergeable_literal_section sz = + match sz with + | 0 -> ".const" + | 4 | 8 | 16 -> sprintf ".literal%d" sz + | _ -> assert false + +let macos_mergeable_string_section sz = + match sz with + | 0 | 2 | 4 -> ".const" + | 1 -> ".cstring" + | _ -> assert false |