From c1daedb244d1f7586c12749642b0d78ae910e60a Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 17 Dec 2014 11:33:23 +0100 Subject: Clean up support for common symbols. Uninitialized "const" symbols can be common. --- arm/PrintAsm.ml | 6 ++++-- checklink/Check.ml | 11 +++++----- common/Sections.ml | 12 +++++------ common/Sections.mli | 4 ++-- ia32/PrintAsm.ml | 58 ++++++++++++++++++++++++++++++++++++++++------------- powerpc/PrintAsm.ml | 19 +++++++++--------- 6 files changed, 71 insertions(+), 39 deletions(-) diff --git a/arm/PrintAsm.ml b/arm/PrintAsm.ml index 7b9e2cc8..c7157aac 100644 --- a/arm/PrintAsm.ml +++ b/arm/PrintAsm.ml @@ -168,8 +168,10 @@ let thumbS oc = let name_of_section = function | Section_text -> ".text" - | Section_data i | Section_small_data i -> if i then ".data" else "COMM" - | Section_const | Section_small_const -> ".section .rodata" + | Section_data i | Section_small_data i -> + if i then ".data" else "COMM" + | Section_const i | Section_small_const i -> + if i then ".section .rodata" else "COMM" | Section_string -> ".section .rodata" | Section_literal -> ".text" | Section_jumptable -> ".text" diff --git a/checklink/Check.ml b/checklink/Check.ml index 87910863..db0159c4 100644 --- a/checklink/Check.ml +++ b/checklink/Check.ml @@ -69,8 +69,8 @@ let name_of_section_Linux: section_name -> string = function | Section_text -> ".text" | Section_data i -> if i then ".data" else "COMM" | Section_small_data i -> if i then ".sdata" else ".sbss" -| Section_const -> ".rodata" -| Section_small_const -> ".sdata2" +| Section_const i -> if i then ".rodata" else "COMM" +| Section_small_const i -> if i then ".sdata2" else "COMM" | Section_string -> ".rodata" | Section_literal -> ".rodata.cst8" | Section_jumptable -> ".text" @@ -79,10 +79,10 @@ let name_of_section_Linux: section_name -> string = function (** Adapted from CompCert *) let name_of_section_Diab: section_name -> string = function | Section_text -> ".text" -| Section_data i -> if i then ".data" else ".bss" +| Section_data i -> if i then ".data" else "COMM" | Section_small_data i -> if i then ".sdata" else ".sbss" -| Section_const -> ".text" -| Section_small_const -> ".sdata2" +| Section_const _ -> ".text" +| Section_small_const _ -> ".sdata2" | Section_string -> ".text" | Section_literal -> ".text" | Section_jumptable -> ".text" @@ -91,7 +91,6 @@ let name_of_section_Diab: section_name -> string = function (** Taken from CompCert *) let name_of_section: section_name -> string = begin match Configuration.system with - | "macosx" -> fatal "Unsupported CompCert configuration: macosx" | "linux" -> name_of_section_Linux | "diab" -> name_of_section_Diab | _ -> fatal "Unsupported CompCert configuration" diff --git a/common/Sections.ml b/common/Sections.ml index d7ae8195..c6d4c4c2 100644 --- a/common/Sections.ml +++ b/common/Sections.ml @@ -21,8 +21,8 @@ type section_name = | Section_text | Section_data of bool (* true = init data, false = uninit data *) | Section_small_data of bool - | Section_const - | Section_small_const + | Section_const of bool + | Section_small_const of bool | Section_string | Section_literal | Section_jumptable @@ -68,13 +68,13 @@ let builtin_sections = [ sec_writable = true; sec_executable = false; sec_access = Access_near}; "CONST", - {sec_name_init = Section_const; - sec_name_uninit = Section_const; + {sec_name_init = Section_const true; + sec_name_uninit = Section_const false; sec_writable = false; sec_executable = false; sec_access = Access_default}; "SCONST", - {sec_name_init = Section_small_const; - sec_name_uninit = Section_small_const; + {sec_name_init = Section_small_const true; + sec_name_uninit = Section_small_const false; sec_writable = false; sec_executable = false; sec_access = Access_near}; "STRING", diff --git a/common/Sections.mli b/common/Sections.mli index ff6c8c95..38b99db0 100644 --- a/common/Sections.mli +++ b/common/Sections.mli @@ -20,8 +20,8 @@ type section_name = | Section_text | Section_data of bool (* true = init data, false = uninit data *) | Section_small_data of bool - | Section_const - | Section_small_const + | Section_const of bool + | Section_small_const of bool | Section_string | Section_literal | Section_jumptable diff --git a/ia32/PrintAsm.ml b/ia32/PrintAsm.ml index 41002bac..649fd292 100644 --- a/ia32/PrintAsm.ml +++ b/ia32/PrintAsm.ml @@ -57,7 +57,7 @@ let preg oc = function (* System dependend printer functions *) -module type SYSTEM= +module type SYSTEM = sig val raw_symbol: out_channel -> string -> unit val symbol: out_channel -> P.t -> unit @@ -69,6 +69,8 @@ module type SYSTEM= val print_fun_info: out_channel -> P.t -> unit val print_var_info: out_channel -> P.t -> unit val print_epilogue: out_channel -> unit + val print_comm_decl: out_channel -> P.t -> Z.t -> int -> unit + val print_lcomm_decl: out_channel -> P.t -> Z.t -> int -> unit end (* Printer functions for cygwin *) @@ -86,8 +88,10 @@ module Cygwin_System = let name_of_section = function | Section_text -> ".text" - | Section_data _ | Section_small_data _ -> ".data" - | Section_const | Section_small_const -> ".section .rdata,\"dr\"" + | Section_data i | Section_small_data i -> + if i then ".data" else "COMM" + | Section_const i | Section_small_const i -> + if i then ".section .rdata,\"dr\"" else "COMM" | Section_string -> ".section .rdata,\"dr\"" | Section_literal -> ".section .rdata,\"dr\"" | Section_jumptable -> ".text" @@ -108,6 +112,14 @@ module Cygwin_System = let print_var_info _ _ = () let print_epilogue _ = () + + let print_comm_decl oc name sz al = + fprintf oc " .comm %a, %s, %d\n" symbol name (Z.to_string sz) al + + let print_lcomm_decl oc name sz al = + fprintf oc " .local %a\n" symbol name; + print_comm_decl oc name sz al + end:SYSTEM) (* Printer functions for ELF *) @@ -125,8 +137,10 @@ module ELF_System = let name_of_section = function | Section_text -> ".text" - | Section_data i | Section_small_data i -> if i then ".data" else "COMM" - | Section_const | Section_small_const -> ".section .rodata" + | Section_data i | Section_small_data i -> + if i then ".data" else "COMM" + | Section_const i | Section_small_const i -> + if i then ".section .rodata" else "COMM" | Section_string -> ".section .rodata" | Section_literal -> ".section .rodata.cst8,\"aM\",@progbits,8" | Section_jumptable -> ".text" @@ -151,6 +165,14 @@ module ELF_System = fprintf oc " .size %a, . - %a\n" symbol name symbol name let print_epilogue _ = () + + let print_comm_decl oc name sz al = + fprintf oc " .comm %a, %s, %d\n" symbol name (Z.to_string sz) al + + let print_lcomm_decl oc name sz al = + fprintf oc " .local %a\n" symbol name; + print_comm_decl oc name sz al + end:SYSTEM) (* Printer functions for MacOS *) @@ -168,8 +190,10 @@ module MacOS_System = let name_of_section = function | Section_text -> ".text" - | Section_data _ | Section_small_data _ -> ".data" - | Section_const | Section_small_const -> ".const" + | Section_data i | Section_small_data i -> + if i then ".data" else "COMM" + | Section_const i | Section_small_const i -> + if i then ".const" else "COMM" | Section_string -> ".const" | Section_literal -> ".literal8" | Section_jumptable -> ".const" @@ -209,6 +233,14 @@ module MacOS_System = !indirect_symbols; indirect_symbols := StringSet.empty + let print_comm_decl oc name sz al = + fprintf oc " .comm %a, %s, %d\n" + symbol name (Z.to_string sz) (log2 al) + + let print_lcomm_decl oc name sz al = + fprintf oc " .lcomm %a, %s, %d\n" + symbol name (Z.to_string sz) (log2 al) + end:SYSTEM) @@ -996,12 +1028,9 @@ let print_var oc name v = end else begin let sz = match v.gvar_init with [Init_space sz] -> sz | _ -> assert false in - if C2C.atom_is_static name then - fprintf oc " .local %a\n" symbol name; - fprintf oc " .comm %a, %s, %d\n" - symbol name - (Z.to_string sz) - align + if C2C.atom_is_static name + then Target.print_lcomm_decl oc name sz align + else Target.print_comm_decl oc name sz align end let print_globdef oc (name, gdef) = @@ -1032,7 +1061,8 @@ let print_program oc p = Hashtbl.clear Printer.filename_num; List.iter (Printer.print_globdef oc) p.prog_defs; if !Printer.need_masks then begin - Printer.section oc Section_const; (* not Section_literal because not 8-bytes *) + Printer.section oc (Section_const true); + (* not Section_literal because not 8-bytes *) Target.print_align oc 16; fprintf oc "%a: .quad 0x8000000000000000, 0\n" Target.raw_symbol "__negd_mask"; diff --git a/powerpc/PrintAsm.ml b/powerpc/PrintAsm.ml index 587dfccf..760ed275 100644 --- a/powerpc/PrintAsm.ml +++ b/powerpc/PrintAsm.ml @@ -105,13 +105,14 @@ module Linux_System = let name_of_section = function | Section_text -> ".text" - | Section_data i -> if i then ".data" else "COMM" + | Section_data i -> + if i then ".data" else "COMM" | Section_small_data i -> - if i - then ".section .sdata,\"aw\",@progbits" - else ".section .sbss,\"aw\",@progbits" - | Section_const -> ".rodata" - | Section_small_const -> ".section .sdata2,\"a\",@progbits" + if i then ".section .sdata,\"aw\",@progbits" else "COMM" + | Section_const i -> + if i then ".rodata" else "COMM" + | Section_small_const i -> + if i then ".section .sdata2,\"a\",@progbits" else "COMM" | Section_string -> ".rodata" | Section_literal -> ".section .rodata.cst8,\"aM\",@progbits,8" | Section_jumptable -> ".text" @@ -197,10 +198,10 @@ module Diab_System = let name_of_section = function | Section_text -> ".text" - | Section_data i -> if i then ".data" else ".bss" + | Section_data i -> if i then ".data" else "COMM" | Section_small_data i -> if i then ".sdata" else ".sbss" - | Section_const -> ".text" - | Section_small_const -> ".sdata2" + | Section_const _ -> ".text" + | Section_small_const _ -> ".sdata2" | Section_string -> ".text" | Section_literal -> ".text" | Section_jumptable -> ".text" -- cgit