Skip to content

Commit 94cbae4

Browse files
RISC-V: restrict inclusion of Zcf by Zce
Currently, the Zce extension includes Zcf unconditionally; however, according to the Zc* spec version 1.0.4 [1]: * Specifying Zce on RV32 without F includes Zca, Zcb, Zcmp, Zcmt * Specifying Zce on RV32 with F includes Zca, Zcb, Zcmp, Zcmt and Zcf * Specifying Zce on RV64 always includes Zca, Zcb, Zcmp, Zcmt - Zcf doesn’t exist for RV64 This patch checks whether (a) F is enabled and (b) the target is 32-bit; to that end, the check_func() helper receives the current list of used extensions (riscv_parse_subset_t *) as a third parameter so that the information about currently enabled extensions and the target can be retrieved. [1] https://github.com/riscvarchive/riscv-code-size-reduction/releases/download/v1.0.4-3/Zc-1.0.4-3.pdf Signed-off-by: Artemiy Volkov <[email protected]> Conflicts: bfd/elfxx-riscv.c
1 parent 12e7628 commit 94cbae4

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

bfd/elfxx-riscv.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,28 +1148,45 @@ riscv_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,
11481148
/* Always add implicit extensions for the SUBSET. */
11491149

11501150
static bool
1151-
check_implicit_always (riscv_subset_t *subset ATTRIBUTE_UNUSED)
1151+
check_implicit_always (const char *implicit ATTRIBUTE_UNUSED,
1152+
riscv_parse_subset_t *rps ATTRIBUTE_UNUSED,
1153+
riscv_subset_t *subset ATTRIBUTE_UNUSED)
11521154
{
11531155
return true;
11541156
}
11551157

11561158
/* Add implicit extensions only when the version of SUBSET less than 2.1. */
11571159

11581160
static bool
1159-
check_implicit_for_i (riscv_subset_t *subset)
1161+
check_implicit_for_i (const char *implicit ATTRIBUTE_UNUSED,
1162+
riscv_parse_subset_t *rps ATTRIBUTE_UNUSED,
1163+
riscv_subset_t *subset)
11601164
{
11611165
return (subset->major_version < 2
11621166
|| (subset->major_version == 2
11631167
&& subset->minor_version < 1));
11641168
}
11651169

1170+
/* Zce includes Zcf only in the presence of F, and only if the target is
1171+
32-bit (see Zc* v1.0.4 section 1.4). */
1172+
1173+
static bool
1174+
check_implicit_for_zce_zcf (const char *implicit ATTRIBUTE_UNUSED,
1175+
riscv_parse_subset_t *rps,
1176+
riscv_subset_t *subset ATTRIBUTE_UNUSED)
1177+
{
1178+
riscv_subset_t *current;
1179+
return riscv_lookup_subset (rps->subset_list, "f", &current)
1180+
&& *rps->xlen == 32;
1181+
}
1182+
11661183
/* Record all implicit information for the subsets. */
11671184
struct riscv_implicit_subset
11681185
{
11691186
const char *ext;
11701187
const char *implicit_exts;
11711188
/* A function to determine if we need to add the implicit subsets. */
1172-
bool (*check_func) (riscv_subset_t *);
1189+
bool (*check_func) (const char *, riscv_parse_subset_t *, riscv_subset_t *);
11731190
};
11741191
/* Please added in order since this table is only run once time. */
11751192
static struct riscv_implicit_subset riscv_implicit_subsets[] =
@@ -1211,7 +1228,8 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
12111228

12121229
{"zcb", "+zca", check_implicit_always},
12131230
{"zcd", "+d,+zca", check_implicit_always},
1214-
{"zce", "+zca,+zcb,+zcf,+zcmp,+zcmt", check_implicit_always},
1231+
{"zce", "+zca,+zcb,+zcmp,+zcmt", check_implicit_always},
1232+
{"zce", "+zcf", check_implicit_for_zce_zcf},
12151233
{"zcf", "+f,+zca", check_implicit_always},
12161234
{"zcmp", "+zca", check_implicit_always},
12171235
{"zcmt", "+zca", check_implicit_always},
@@ -1271,6 +1289,8 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
12711289
{"svade", "+zicsr", check_implicit_always},
12721290
{"svadu", "+zicsr", check_implicit_always},
12731291
{"svbare", "+zicsr", check_implicit_always},
1292+
1293+
{"xsfvcp", "zve32x", check_implicit_always},
12741294
{NULL, NULL, NULL}
12751295
};
12761296

@@ -2042,7 +2062,7 @@ riscv_parse_add_implicit_subsets (riscv_parse_subset_t *rps)
20422062
{
20432063
riscv_subset_t *subset = NULL;
20442064
if (riscv_lookup_subset (rps->subset_list, t->ext, &subset)
2045-
&& t->check_func (subset))
2065+
&& t->check_func (t->implicit_exts, rps, subset))
20462066
riscv_update_subset1 (rps, subset, t->implicit_exts);
20472067
}
20482068
}

0 commit comments

Comments
 (0)