Skip to content

Commit

Permalink
[USMP] add missing const specifier for global_const_workspace (#16999)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
PhilippvK committed May 23, 2024
1 parent e978a44 commit b1951a7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/target/source/source_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConstantInfo> const_info_vec(pool_info->constant_info_array.begin(),
pool_info->constant_info_array.end());
Expand Down

0 comments on commit b1951a7

Please sign in to comment.