Skip to content

Commit 49b290e

Browse files
mmindpalmer-dabbelt
authored andcommitted
riscv: prevent compressed instructions in alternatives
Instructions are opportunistically compressed by the RISC-V assembler when possible, but in alternatives-blocks both the old and new content need to be the same size, so having the toolchain do somewhat random optimizations will cause strange side-effects like "attempt to move .org backwards" compile-time errors. Already a simple "and" used in alternatives assembly will cause these mismatched code sizes. So prevent compressed instructions to be generated in alternatives- code and use option-push and -pop to only limit this to the relevant code blocks Signed-off-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Philipp Tomsich <philipp.tomsich@vrull.eu> Link: https://lore.kernel.org/r/20220511192921.2223629-7-heiko@sntech.de Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent e509204 commit 49b290e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

arch/riscv/include/asm/alternative-macros.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
.popsection
2222
.subsection 1
2323
888 :
24+
.option push
25+
.option norvc
26+
.option norelax
2427
\new_c
28+
.option pop
2529
889 :
2630
.previous
2731
.org . - (889b - 888b) + (887b - 886b)
@@ -31,7 +35,11 @@
3135

3236
.macro __ALTERNATIVE_CFG old_c, new_c, vendor_id, errata_id, enable
3337
886 :
38+
.option push
39+
.option norvc
40+
.option norelax
3441
\old_c
42+
.option pop
3543
887 :
3644
ALT_NEW_CONTENT \vendor_id, \errata_id, \enable, \new_c
3745
.endm
@@ -42,7 +50,11 @@
4250
.macro __ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \
4351
new_c_2, vendor_id_2, errata_id_2, enable_2
4452
886 :
53+
.option push
54+
.option norvc
55+
.option norelax
4556
\old_c
57+
.option pop
4658
887 :
4759
ALT_NEW_CONTENT \vendor_id_1, \errata_id_1, \enable_1, \new_c_1
4860
ALT_NEW_CONTENT \vendor_id_2, \errata_id_2, \enable_2, \new_c_2
@@ -76,7 +88,11 @@
7688
".popsection\n" \
7789
".subsection 1\n" \
7890
"888 :\n" \
91+
".option push\n" \
92+
".option norvc\n" \
93+
".option norelax\n" \
7994
new_c "\n" \
95+
".option pop\n" \
8096
"889 :\n" \
8197
".previous\n" \
8298
".org . - (887b - 886b) + (889b - 888b)\n" \
@@ -85,7 +101,11 @@
85101

86102
#define __ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, enable) \
87103
"886 :\n" \
104+
".option push\n" \
105+
".option norvc\n" \
106+
".option norelax\n" \
88107
old_c "\n" \
108+
".option pop\n" \
89109
"887 :\n" \
90110
ALT_NEW_CONTENT(vendor_id, errata_id, enable, new_c)
91111

@@ -97,7 +117,11 @@
97117
new_c_2, vendor_id_2, errata_id_2, \
98118
enable_2) \
99119
"886 :\n" \
120+
".option push\n" \
121+
".option norvc\n" \
122+
".option norelax\n" \
100123
old_c "\n" \
124+
".option pop\n" \
101125
"887 :\n" \
102126
ALT_NEW_CONTENT(vendor_id_1, errata_id_1, enable_1, new_c_1) \
103127
ALT_NEW_CONTENT(vendor_id_2, errata_id_2, enable_2, new_c_2)

0 commit comments

Comments
 (0)