https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128569
Bug ID: 128569
Summary: riscv: CSWTCH tables are placed in a writable section
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: kristerw at gcc dot gnu.org
Blocks: 118443
Target Milestone: ---
Consider the function:
unsigned char
bar (long long val)
{
unsigned char result = 1;
switch (val)
{
case 0: result = 8; break;
case 1: result = 31; break;
case 2: result = 72; break;
default: break;
}
return result;
}
Compiling this with -O2 generates code using a switch table in the .sdata
section:
.section .sdata,"aw"
.align 3
.type CSWTCH.1, @object
.size CSWTCH.1, 3
CSWTCH.1:
.byte 8
.byte 31
.byte 72
I would have expected it to be placed in a read-only section instead.
This may not make any difference in practice, as my understanding is that
.srodata is usually merged with .sdata in the linker script. But placing the
table in a writable section makes smtgcc report that the semantics of the
generated code are not guaranteed, since the contents of the table may change.
But smtgcc is not a critical tool, so feel free to close this bug report if it
is not deemed worth fixing.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118443
[Bug 118443] [Meta bug] Bugs triggered by and blocking more smtgcc testing