From e31e645f5c29b6587404c1efe534c65b4691e023 Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Fri, 1 Apr 2022 22:00:36 -0700 Subject: RISC-V: don't die() on -march errors, just warn Parsing RISC-V ISA strings is extremely complicated: there are many extensions, versions of extensions, versions of the ISA string rules, and a bunch of unwritten rules to deal with all the bugs that fell out of that complexity. Rather than die()ing when the ISA string parsing fails, just stop parsing where we get lost and emit a warning. Changes tend to end up at the end of the ISA string, so that's probably going to work (and if it doesn't there's a warning to true and clue folks in). This does have the oddity in that "-Wsparse-error" is ignored for this warning but this option was never meant to be used at this stage of the processing.. [Luc Van Oostenryck: drop handling of "-Wsparse-error"] Suggested-by: Linus Torvalds Based-on-patch-by: Palmer Dabbelt Signed-off-by: Luc Van Oostenryck --- target-riscv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/target-riscv.c b/target-riscv.c index 3bba7c15..1707e6b9 100644 --- a/target-riscv.c +++ b/target-riscv.c @@ -3,6 +3,7 @@ #include "target.h" #include "machine.h" #include +#include #define RISCV_32BIT (1 << 0) #define RISCV_64BIT (1 << 1) @@ -64,7 +65,10 @@ static void parse_march_riscv(const char *arg) goto ext; } } - die("invalid argument to '-march': '%s'\n", arg); + +unknown: + fprintf(stderr, "WARNING: invalid argument to '-march': '%s'\n", arg); + return; ext: for (i = 0; i < ARRAY_SIZE(extensions); i++) { @@ -77,7 +81,7 @@ ext: } } if (arg[0]) - die("invalid argument to '-march': '%s'\n", arg); + goto unknown; } static void init_riscv(const struct target *self) -- cgit 1.2.3-korg From 90feaaa967227961fc9972a0a46bb4fa51eec7b2 Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Fri, 1 Apr 2022 22:00:37 -0700 Subject: RISC-V: Match GCC's semantics for multiple -march instances GCC's semantics for "-march=X -march=Y" are that Y entirely overrides X, but sparse takes the union of these two ISA strings. This fixes the behavior by setting, instead of oring, the flags whenever a base ISA is encountered. RISC-V ISA strings can only have a single base ISA, it's not like x86 where the 64-bit ISA is an extension of the 32-bit ISA. [Luc Van Oostenryck: reset the flags at the start of the parsing loop] Signed-off-by: Palmer Dabbelt Signed-off-by: Luc Van Oostenryck --- target-riscv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target-riscv.c b/target-riscv.c index 1707e6b9..80f2588f 100644 --- a/target-riscv.c +++ b/target-riscv.c @@ -55,6 +55,9 @@ static void parse_march_riscv(const char *arg) }; int i; + // Each -march=.. options entirely overrides previous ones + riscv_flags = 0; + for (i = 0; i < ARRAY_SIZE(basic_sets); i++) { const char *pat = basic_sets[i].pattern; size_t len = strlen(pat); -- cgit 1.2.3-korg From dcb3887d85c10c96cc56d2715bf21566e3c31d9b Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Fri, 1 Apr 2022 22:00:38 -0700 Subject: RISC-V: Remove the unimplemented ISA extensions This made sense when we die()d on unknown ISA extensions, but now that we're just warning it's actually a bit detrimental: users won't see that their unimplemented ISA extensions are silently having the wrong definitions set, which may cause hard to debug failures. Signed-off-by: Palmer Dabbelt Signed-off-by: Luc Van Oostenryck --- target-riscv.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/target-riscv.c b/target-riscv.c index 80f2588f..d6dbb7d5 100644 --- a/target-riscv.c +++ b/target-riscv.c @@ -39,17 +39,7 @@ static void parse_march_riscv(const char *arg) { "f", RISCV_FLOAT|RISCV_FDIV|RISCV_ZICSR }, { "d", RISCV_DOUBLE|RISCV_FDIV|RISCV_ZICSR }, { "g", RISCV_GENERIC }, - { "q", 0 }, - { "l", 0 }, { "c", RISCV_COMP }, - { "b", 0 }, - { "j", 0 }, - { "t", 0 }, - { "p", 0 }, - { "v", 0 }, - { "n", 0 }, - { "h", 0 }, - { "s", 0 }, { "_zicsr", RISCV_ZICSR }, { "_zifencei", RISCV_ZIFENCEI }, }; -- cgit 1.2.3-korg From b296539554213125eb8f61291c862eec190e4c9b Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Fri, 1 Apr 2022 22:00:39 -0700 Subject: RISC-V: Remove "g" from the extension list "g" goes along with the base ISA, but it was being treated as an extension. This allows for all sorts of odd ISA strings to be accepted by sparse, things like "rv32ig" or "rv32gg". We're still allowing some oddities, like "rv32ga", but this one was easy to catch. Signed-off-by: Palmer Dabbelt Signed-off-by: Luc Van Oostenryck --- target-riscv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/target-riscv.c b/target-riscv.c index d6dbb7d5..217ab7e8 100644 --- a/target-riscv.c +++ b/target-riscv.c @@ -38,7 +38,6 @@ static void parse_march_riscv(const char *arg) { "a", RISCV_ATOMIC }, { "f", RISCV_FLOAT|RISCV_FDIV|RISCV_ZICSR }, { "d", RISCV_DOUBLE|RISCV_FDIV|RISCV_ZICSR }, - { "g", RISCV_GENERIC }, { "c", RISCV_COMP }, { "_zicsr", RISCV_ZICSR }, { "_zifencei", RISCV_ZIFENCEI }, -- cgit 1.2.3-korg