From b1951a78110f991d31c8d2533184876cc6a4c975 Mon Sep 17 00:00:00 2001 From: Philipp van Kempen Date: Thu, 23 May 2024 18:04:42 +0200 Subject: [PATCH] [USMP] add missing const specifier for global_const_workspace (#16999) The `.rodata*` section of any program should not be writable. The missing `const` specifier in `static struct global_const_workspace {...}` leads to the following `readelf -e` output (shortened): ``` Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 001000 009fbe 00 AX 0 0 16 [ 2] .rodata PROGBITS 00009fc0 00afc0 000e50 00 WA 0 0 16 [ 3] .srodata PROGBITS 0000ae10 00be10 000068 08 AM 0 0 8 ... ``` After this fix, the output looks as follows (`AW` -> `A`): ``` Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 001000 00a1be 00 AX 0 0 16 [ 2] .rodata PROGBITS 0000a1c0 00b1c0 000e50 00 A 0 0 16 [ 3] .srodata PROGBITS 0000b010 00c010 000070 00 A 0 0 8 ``` --- src/target/source/source_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/source/source_module.cc b/src/target/source/source_module.cc index 90640a6db647..1877d3da8e63 100644 --- a/src/target/source/source_module.cc +++ b/src/target/source/source_module.cc @@ -337,7 +337,7 @@ class CSourceCrtMetadataModuleNode : public runtime::ModuleNode { // Pool is RO, form an initialized struct code_ << "__attribute__((section(\".rodata.tvm\"), "; code_ << "))\n"; - code_ << "static struct " << pool_info->pool_name << " {\n"; + code_ << "static const struct " << pool_info->pool_name << " {\n"; // emit struct field names std::vector const_info_vec(pool_info->constant_info_array.begin(), pool_info->constant_info_array.end());