aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@college-de-france.fr>2020-12-30 11:41:10 +0100
committerXavier Leroy <xavierleroy@users.noreply.github.com>2021-02-23 11:33:14 +0100
commit30feb31c6d6e9235acad42ec5d09d14f3919cc36 (patch)
tree8bcf3c6c4a0bd2875d36858979de1a5cd219d677
parent25483cf1acce8695a438f4f2164b09fb1ecd9d2e (diff)
downloadcompcert-30feb31c6d6e9235acad42ec5d09d14f3919cc36.tar.gz
compcert-30feb31c6d6e9235acad42ec5d09d14f3919cc36.zip
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.
-rw-r--r--aarch64/TargetPrinter.ml8
-rw-r--r--arm/TargetPrinter.ml4
-rw-r--r--backend/PrintAsmaux.ml19
-rw-r--r--powerpc/TargetPrinter.ml22
-rw-r--r--riscV/TargetPrinter.ml4
-rw-r--r--x86/TargetPrinter.ml12
6 files changed, 34 insertions, 35 deletions
diff --git a/aarch64/TargetPrinter.ml b/aarch64/TargetPrinter.ml
index 800348a7..e31abf71 100644
--- a/aarch64/TargetPrinter.ml
+++ b/aarch64/TargetPrinter.ml
@@ -162,9 +162,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 common_section ()
+ variable_section ~sec:".data" ~bss:".bss" i
| Section_const i | Section_small_const i ->
- if i || (not !Clflags.option_fcommon) then ".section .rodata" else "COMM"
+ variable_section ~sec:".section .rodata" i
| Section_string -> ".section .rodata"
| Section_literal -> ".section .rodata"
| Section_jumptable -> ".section .rodata"
@@ -224,9 +224,9 @@ module MacOS_System : SYSTEM =
let name_of_section = function
| Section_text -> ".text"
| Section_data i | Section_small_data i ->
- if i || (not !Clflags.option_fcommon) then ".data" else "COMM"
+ variable_section ~sec:".data" i
| Section_const i | Section_small_const i ->
- if i || (not !Clflags.option_fcommon) then ".section __DATA,__CONST" else "COMM"
+ variable_section ~sec:".section __DATA,__CONST" i
| Section_string -> ".const"
| Section_literal -> ".const"
| Section_jumptable -> ".text"
diff --git a/arm/TargetPrinter.ml b/arm/TargetPrinter.ml
index 03e06a65..43dac44a 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 common_section ()
+ variable_section ~sec:".data" ~bss:".bss" i
| Section_const i | Section_small_const i ->
- if i || (not !Clflags.option_fcommon) then ".section .rodata" else "COMM"
+ variable_section ~sec:".section .rodata" i
| Section_string -> ".section .rodata"
| Section_literal -> ".text"
| Section_jumptable -> ".text"
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
diff --git a/powerpc/TargetPrinter.ml b/powerpc/TargetPrinter.ml
index 43d2447d..cf00e659 100644
--- a/powerpc/TargetPrinter.ml
+++ b/powerpc/TargetPrinter.ml
@@ -118,22 +118,16 @@ module Linux_System : SYSTEM =
let name_of_section = function
| Section_text -> ".text"
| Section_data i ->
- if i then
- ".data"
- else
- common_section ~sec:".section .bss" ()
+ variable_section ~sec:".data" ~bss:".section .bss" i
| Section_small_data i ->
- if i then
- ".section .sdata,\"aw\",@progbits"
- else
- common_section ~sec:".section .sbss,\"aw\",@nobits" ()
+ variable_section
+ ~sec:".section .sdata,\"aw\",@progbits"
+ ~bss:".section .sbss,\"aw\",@nobits"
+ i
| Section_const i ->
- if i || (not !Clflags.option_fcommon) then ".rodata" else "COMM"
+ variable_section ~sec:".rodata" i
| Section_small_const i ->
- if i || (not !Clflags.option_fcommon) then
- ".section .sdata2,\"a\",@progbits"
- else
- "COMM"
+ variable_section ~sec:".section .sdata2,\"a\",@progbits" i
| Section_string -> ".rodata"
| Section_literal -> ".section .rodata.cst8,\"aM\",@progbits,8"
| Section_jumptable -> ".text"
@@ -218,7 +212,7 @@ module Diab_System : SYSTEM =
let name_of_section = function
| Section_text -> ".text"
- | Section_data i -> if i then ".data" else common_section ()
+ | Section_data i -> variable_section ~sec:".data" ~bss:".bss" i
| 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 5cd47b46..d8137f84 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 common_section ()
+ variable_section ~sec:".data" ~bss:".bss" i
| Section_const i | Section_small_const i ->
- if i || (not !Clflags.option_fcommon) then ".section .rodata" else "COMM"
+ variable_section ~sec:".section .rodata" i
| Section_string -> ".section .rodata"
| Section_literal -> ".section .rodata"
| Section_jumptable -> ".section .rodata"
diff --git a/x86/TargetPrinter.ml b/x86/TargetPrinter.ml
index 39d0c7dc..102edce4 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 common_section ()
+ variable_section ~sec:".data" ~bss:".bss" i
| Section_const i | Section_small_const i ->
- if i || (not !Clflags.option_fcommon) then ".section .rodata" else "COMM"
+ variable_section ~sec:".section .rodata" i
| 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 || (not !Clflags.option_fcommon) then ".data" else "COMM"
+ variable_section ~sec:".data" i
| Section_const i | Section_small_const i ->
- if i || (not !Clflags.option_fcommon) then ".const" else "COMM"
+ variable_section ~sec:".const" i
| Section_string -> ".const"
| Section_literal -> ".literal8"
| Section_jumptable -> ".text"
@@ -254,9 +254,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 common_section ()
+ variable_section ~sec:".data" ~bss:".bss" i
| Section_const i | Section_small_const i ->
- if i || (not !Clflags.option_fcommon) then ".section .rdata,\"dr\"" else "COMM"
+ variable_section ~sec:".section .rdata,\"dr\"" i
| Section_string -> ".section .rdata,\"dr\""
| Section_literal -> ".section .rdata,\"dr\""
| Section_jumptable -> ".text"