diff options
-rw-r--r-- | arm/TargetPrinter.ml | 4 | ||||
-rw-r--r-- | backend/PrintAsmaux.ml | 8 | ||||
-rw-r--r-- | doc/ccomp.1 | 6 | ||||
-rw-r--r-- | driver/Clflags.ml | 1 | ||||
-rw-r--r-- | driver/Driver.ml | 2 | ||||
-rw-r--r-- | powerpc/TargetPrinter.ml | 19 | ||||
-rw-r--r-- | riscV/TargetPrinter.ml | 4 | ||||
-rw-r--r-- | x86/TargetPrinter.ml | 12 |
8 files changed, 41 insertions, 15 deletions
diff --git a/arm/TargetPrinter.ml b/arm/TargetPrinter.ml index bf37b0e4..20989615 100644 --- a/arm/TargetPrinter.ml +++ b/arm/TargetPrinter.ml @@ -148,9 +148,9 @@ struct let name_of_section = function | Section_text -> ".text" | Section_data i | Section_small_data i -> - if i then ".data" else "COMM" + if i then ".data" else common_section () | Section_const i | Section_small_const i -> - if i then ".section .rodata" else "COMM" + if i || (not !Clflags.option_fcommon) then ".section .rodata" else "COMM" | Section_string -> ".section .rodata" | Section_literal -> ".text" | Section_jumptable -> ".text" diff --git a/backend/PrintAsmaux.ml b/backend/PrintAsmaux.ml index 0fd164b0..7e075f04 100644 --- a/backend/PrintAsmaux.ml +++ b/backend/PrintAsmaux.ml @@ -298,3 +298,11 @@ 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 diff --git a/doc/ccomp.1 b/doc/ccomp.1 index 36fe4e7b..1579beb9 100644 --- a/doc/ccomp.1 +++ b/doc/ccomp.1 @@ -180,6 +180,12 @@ Set alignment of function entry points to <n> bytes. The default alignment is 16 bytes for x86 targets and 4 bytes for ARM and PowerPC. . .TP +.BR \-fcommon ", " \-fno\-common +Turn on/off placement of global variables defined without an initializer (tentative definitions) in the common section. +Disabling the use of the common section inhibits merging of tentative definitions by the linker and may lead to multiple-definition errors. +Enabled by default. +. +.TP .BR \-ffpu ", " \-fno\-fpu Turn on/off use of FP registers for some integer operations. Enabled by default. diff --git a/driver/Clflags.ml b/driver/Clflags.ml index a886ee9b..fc12863d 100644 --- a/driver/Clflags.ml +++ b/driver/Clflags.ml @@ -31,6 +31,7 @@ let option_falignfunctions = ref (None: int option) let option_falignbranchtargets = ref 0 let option_faligncondbranchs = ref 0 let option_finline_asm = ref false +let option_fcommon = ref true let option_mthumb = ref (Configuration.model = "armv7m") let option_Osize = ref false let option_finline = ref true diff --git a/driver/Driver.ml b/driver/Driver.ml index 5f7d0b20..50f14d13 100644 --- a/driver/Driver.ml +++ b/driver/Driver.ml @@ -203,6 +203,7 @@ Code generation options: (use -fno-<opt> to turn off -f<opt>) -falign-functions <n> Set alignment (in bytes) of function entry points -falign-branch-targets <n> Set alignment (in bytes) of branch targets -falign-cond-branches <n> Set alignment (in bytes) of conditional branches + -fcommon Put uninitialized globals in the common section [on]. |} ^ target_help ^ toolchain_help ^ @@ -304,6 +305,7 @@ let cmdline_actions = Exact "-falign-functions", Integer(fun n -> check_align n; option_falignfunctions := Some n); Exact "-falign-branch-targets", Integer(fun n -> check_align n; option_falignbranchtargets := n); Exact "-falign-cond-branches", Integer(fun n -> check_align n; option_faligncondbranchs := n);] @ + f_opt "common" option_fcommon @ (* Target processor options *) (if Configuration.arch = "arm" then if Configuration.model = "armv6" then diff --git a/powerpc/TargetPrinter.ml b/powerpc/TargetPrinter.ml index c1aaa55d..0a98584b 100644 --- a/powerpc/TargetPrinter.ml +++ b/powerpc/TargetPrinter.ml @@ -118,13 +118,22 @@ module Linux_System : SYSTEM = let name_of_section = function | Section_text -> ".text" | Section_data i -> - if i then ".data" else "COMM" + if i then + ".data" + else + common_section ~sec:".section .bss" () | Section_small_data i -> - if i then ".section .sdata,\"aw\",@progbits" else "COMM" + if i then + ".section .sdata,\"aw\",@progbits" + else + common_section ~sec:".section .sbss,\"aw\",@nobits" () | Section_const i -> - if i then ".rodata" else "COMM" + if i || (not !Clflags.option_fcommon) then ".rodata" else "COMM" | Section_small_const i -> - if i then ".section .sdata2,\"a\",@progbits" else "COMM" + if i || (not !Clflags.option_fcommon) then + ".section .sdata2,\"a\",@progbits" + else + "COMM" | Section_string -> ".rodata" | Section_literal -> ".section .rodata.cst8,\"aM\",@progbits,8" | Section_jumptable -> ".text" @@ -209,7 +218,7 @@ module Diab_System : 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 common_section () | Section_small_data i -> if i then ".sdata" else ".sbss" | Section_const _ -> ".text" | Section_small_const _ -> ".sdata2" diff --git a/riscV/TargetPrinter.ml b/riscV/TargetPrinter.ml index 19704bad..92df7a76 100644 --- a/riscV/TargetPrinter.ml +++ b/riscV/TargetPrinter.ml @@ -108,9 +108,9 @@ module Target : TARGET = let name_of_section = function | Section_text -> ".text" | Section_data i | Section_small_data i -> - if i then ".data" else "COMM" + if i then ".data" else common_section () | Section_const i | Section_small_const i -> - if i then ".section .rodata" else "COMM" + if i || (not !Clflags.option_fcommon) then ".section .rodata" else "COMM" | Section_string -> ".section .rodata" | Section_literal -> ".section .rodata" | Section_jumptable -> ".section .rodata" diff --git a/x86/TargetPrinter.ml b/x86/TargetPrinter.ml index 3ac2f36e..2e28e983 100644 --- a/x86/TargetPrinter.ml +++ b/x86/TargetPrinter.ml @@ -134,9 +134,9 @@ module ELF_System : SYSTEM = let name_of_section = function | Section_text -> ".text" | Section_data i | Section_small_data i -> - if i then ".data" else "COMM" + if i then ".data" else common_section () | Section_const i | Section_small_const i -> - if i then ".section .rodata" else "COMM" + if i || (not !Clflags.option_fcommon) then ".section .rodata" else "COMM" | Section_string -> ".section .rodata" | Section_literal -> ".section .rodata.cst8,\"aM\",@progbits,8" | Section_jumptable -> ".text" @@ -192,9 +192,9 @@ module MacOS_System : SYSTEM = let name_of_section = function | Section_text -> ".text" | Section_data i | Section_small_data i -> - if i then ".data" else "COMM" + if i || (not !Clflags.option_fcommon) then ".data" else "COMM" | Section_const i | Section_small_const i -> - if i then ".const" else "COMM" + if i || (not !Clflags.option_fcommon) then ".const" else "COMM" | Section_string -> ".const" | Section_literal -> ".literal8" | Section_jumptable -> ".text" (* needed in 64 bits, not a problem in 32 bits *) @@ -269,9 +269,9 @@ module Cygwin_System : SYSTEM = let name_of_section = function | Section_text -> ".text" | Section_data i | Section_small_data i -> - if i then ".data" else "COMM" + if i then ".data" else common_section () | Section_const i | Section_small_const i -> - if i then ".section .rdata,\"dr\"" else "COMM" + if i || (not !Clflags.option_fcommon) then ".section .rdata,\"dr\"" else "COMM" | Section_string -> ".section .rdata,\"dr\"" | Section_literal -> ".section .rdata,\"dr\"" | Section_jumptable -> ".text" |