arch/riscv: fix incorrect ASFLAGS#21672
Conversation
crasbe
left a comment
There was a problem hiding this comment.
What about the -misa-spec=2.2 flag in line 64? Would that also be relevant for the assembler?
I would also add a comment to the flags telling why it is set at this point exactly, otherwise one might assume that there are ASFLAGS missing.
makefiles/arch/riscv.inc.mk
Outdated
| GCC_DEFAULTS_TO_NEW_RISCV_ISA ?= 0 | ||
|
|
||
| CFLAGS_CPU := -march=rv32imac -mabi=ilp32 | ||
| ASFLAGS := $(CFLAGS_CPU) |
There was a problem hiding this comment.
| ASFLAGS := $(CFLAGS_CPU) | |
| # set ASFLAGS before incompatible flags are added to CFLAGS_CPU | |
| ASFLAGS := $(CFLAGS_CPU) |
makefiles/arch/riscv.inc.mk
Outdated
| @@ -87,7 +88,6 @@ LINKER_SCRIPT ?= $(CPU_MODEL).ld | |||
| LINKFLAGS += -T$(LINKER_SCRIPT) | |||
|
|
|||
| CFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) $(CFLAGS_LINK) | |||
There was a problem hiding this comment.
I would introduce a new CFLAGS_NO_ASM variable and add -mcmodel=medlow to that on when using GCC. E.g. like this:
| CFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) $(CFLAGS_LINK) | |
| CFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) $(CFLAGS_LINK) | |
| ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) | |
| # add CFLAGS that should not be added to the assembler | |
| CFLAGS += CFLAGS_NO_ASM |
As @crasbe pointed out, not specifying the ISA level is bound to cause regressions with older toolchains.
|
Integrated both reviews, ty :) |
|
squashy squash squashed :) |
|
That is not related to me whatsoever, not even on RISC-V 🤨 I guess you could say ... I had bad timing 🥁 |
|
The |
|
ty |
Contribution description
Coming in with a staggering 1 singular line changed this PR is surprisingly important (mostly to me 😛).
The riscv_common and by that the arch makefile for riscv in general sets the proper flags to build a riscv application, as used in the pico 2 support (soon ™️).
There is however a potential oversight, as the ASFLAGS gets incorrectly set to contain the C flags. In general this should be fine except that the GNU assembler does not have all the options later set. For example, while quite important in the context of IoT devices,
-mcmodel=medlowappears to be something that is only relevant with parsed code, as opposed to the pure assembly that you'd write when passing it to the assembler, given that all these options don't affect pure assembly, thus causing the assembler to crash/fail.Same goes for every other flag set starting at https://github.com/AnnsAnns/RIOT/blob/6c36aceada9ee8dcf0e6d83bfeff52c5d8033e98/makefiles/arch/riscv.inc.mk#L70
The potential reason this wasn't caught, even though riscv_common is really well written and also has a fairly important assembly file, is that it uses
start.Snotstart.sas the filename..S(uppercase) files are not actually handled byriscv32-unknown-elf-asand thus never actually use ASFLAGS but are simply passed to gcc (which also allows you to use macros, directives, etc) while.s(lowercase) files are pure assembly code handled byriscv32-unknown-elf-as. (See Makefile.base ~L178)A lot of yapping cut short, as of now
.s(lowercase) pure assembly code can not be compiled/linked, which did cause me a lot of confusion as I was trying to figure out why exactlypicobin.swhich I use for the RISC-V support of the pico2 refused to compile whilestart.Scompiles just fine.Note that I might also just be completely wrong, but this was my best guess in fixing this. @nmeum appears to be the original author based on git blame so I'm quite open to hear whether or not my theory is anywhere close to reality 😅
Testing procedure
Try to include a
.sassembly file in a RISC-V project.Issues/PRs references