On Tue, Jan 14, 2020 at 10:06 AM xinx <
goxi...@gmail.com> wrote:
> ... the generated code is strange (a5 is stored at stack but not used at all) and not entirely correct (content of t0, t1 are used but not saved at stack):
The code emitted by the compiler uses a5, but linker relaxation
eliminates the need for a5 for address calculation. Linker relaxation
can't remove the save/restore of a5 on the stack though. So this is
unfortunate, but not wrong, just not optimized as well as possible,
and not easy to fix. You can see this if you compile with -S and look
at the assembly code.
The use of t0 and t1 look wrong, but I get correct code when I try it
with my copy of the compiler. You mentioned you have gcc-9.2, but you
didn't mention which exact gcc-9.2 you have. Different vendors have
different patch sets applied to their compilers, and each tree will
have different patches applied at different times. So I'd need a git
commit id or something to reproduce. Or maybe the bug was already
fixed, and you just need to update. If you don't see the t0 or t1
references in the assembly code, then maybe this is a linker
relaxation error, but the upstream binutils doesn't change register
allocation, so you would have to have some modified vendor binutils if
this is the problem.
I see you are using -Wa,-march=rv32imc which is odd. This will tell
the assembler to use a different architecture than the compiler, which
is unlikely to work. The compiler will pass march options to the
assembler, so you should just use -march directly.
Jim