aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavierleroy@users.noreply.github.com>2022-10-24 11:04:31 +0200
committerGitHub <noreply@github.com>2022-10-24 11:04:31 +0200
commit0fca312236475ccc2de12da45221c311d99a19d1 (patch)
tree7c9a09783910292d351df9f64ef4a494d7955094
parenta1f01c844aaa0ff41aa9095e9d5d01606a0e90c9 (diff)
downloadcompcert-0fca312236475ccc2de12da45221c311d99a19d1.tar.gz
compcert-0fca312236475ccc2de12da45221c311d99a19d1.zip
Use .data.rel.ro section for const data with relocatable inits on ELF targets (#457)
Follow-up to ed89275cb. AArch64, ARM, RISC-V and x86 ELF targets are changed. PowerPC / ELF is unchanged because we use the EABI variant, which has no `.data.rel.ro` section as far as I can see in GCC's output. (The SVR4 variant has `.data.rel.ro` but does not have `.sdata2`, which CompCert uses.) Fixes: #454
-rw-r--r--aarch64/TargetPrinter.ml5
-rw-r--r--arm/TargetPrinter.ml5
-rw-r--r--riscV/TargetPrinter.ml5
-rw-r--r--x86/TargetPrinter.ml5
4 files changed, 16 insertions, 4 deletions
diff --git a/aarch64/TargetPrinter.ml b/aarch64/TargetPrinter.ml
index cde5668b..664110d1 100644
--- a/aarch64/TargetPrinter.ml
+++ b/aarch64/TargetPrinter.ml
@@ -164,7 +164,10 @@ module ELF_System : SYSTEM =
| Section_data i | Section_small_data i ->
variable_section ~sec:".data" ~bss:".bss" i
| Section_const i | Section_small_const i ->
- variable_section ~sec:".section .rodata" i
+ variable_section
+ ~sec:".section .rodata"
+ ~reloc:".section .data.rel.ro,\"aw\",@progbits"
+ i
| Section_string sz ->
elf_mergeable_string_section sz ".section .rodata"
| Section_literal sz ->
diff --git a/arm/TargetPrinter.ml b/arm/TargetPrinter.ml
index 20ca59d6..b6362ca9 100644
--- a/arm/TargetPrinter.ml
+++ b/arm/TargetPrinter.ml
@@ -150,7 +150,10 @@ struct
| Section_data i | Section_small_data i ->
variable_section ~sec:".data" ~bss:".bss" i
| Section_const i | Section_small_const i ->
- variable_section ~sec:".section .rodata" i
+ variable_section
+ ~sec:".section .rodata"
+ ~reloc:".section .data.rel.ro,\"aw\",%progbits"
+ i
| Section_string _ -> ".section .rodata"
| Section_literal _ -> ".text"
| Section_jumptable -> ".text"
diff --git a/riscV/TargetPrinter.ml b/riscV/TargetPrinter.ml
index 373bd1a5..3d258257 100644
--- a/riscV/TargetPrinter.ml
+++ b/riscV/TargetPrinter.ml
@@ -110,7 +110,10 @@ module Target : TARGET =
| Section_data i | Section_small_data i ->
variable_section ~sec:".data" ~bss:".bss" i
| Section_const i | Section_small_const i ->
- variable_section ~sec:".section .rodata" i
+ variable_section
+ ~sec:".section .rodata"
+ ~reloc:".section .data.rel.ro,\"aw\",@progbits"
+ i
| Section_string sz ->
elf_mergeable_string_section sz ".section .rodata"
| Section_literal sz ->
diff --git a/x86/TargetPrinter.ml b/x86/TargetPrinter.ml
index dad8d15c..f529a89d 100644
--- a/x86/TargetPrinter.ml
+++ b/x86/TargetPrinter.ml
@@ -137,7 +137,10 @@ module ELF_System : SYSTEM =
| Section_data i | Section_small_data i ->
variable_section ~sec:".data" ~bss:".bss" i
| Section_const i | Section_small_const i ->
- variable_section ~sec:".section .rodata" i
+ variable_section
+ ~sec:".section .rodata"
+ ~reloc:".section .data.rel.ro,\"aw\",@progbits"
+ i
| Section_string sz ->
elf_mergeable_string_section sz ".section .rodata"
| Section_literal sz ->