From 0fca312236475ccc2de12da45221c311d99a19d1 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Mon, 24 Oct 2022 11:04:31 +0200 Subject: 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 --- aarch64/TargetPrinter.ml | 5 ++++- arm/TargetPrinter.ml | 5 ++++- riscV/TargetPrinter.ml | 5 ++++- x86/TargetPrinter.ml | 5 ++++- 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 -> -- cgit