Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC compiles code with --march=rv64gc but get c.zext.b that's in zcb extension #1454

Closed
Ye-Jinhong opened this issue Apr 6, 2024 · 9 comments

Comments

@Ye-Jinhong
Copy link

description
I compiles the tool with configuration:

  1. gcc 13.2
./configure --prefix=`pwd`/installed_tools --with-arch=rv64gc_zba_zbb_zbc_zbs_zicsr_zifencei_zicond_zcb_zfa --with-abi=lp64d

and 2. gcc 14.0

./configure --prefix=`pwd`/installed_tools --with-arch=rv64gc_zba_zbb_zbc_zbs_zicsr_zifencei_zicond_zcb_zfa --with-abi=lp64d --with-gcc-src=`pwd`/gcc-master --with-newlib-src=`pwd`/newlib-master

more details in #1448 .
However, when I compile the coremark with -march=rv64gc, unexpected instructions in zcb was generated like c.zext.b/h.

   138c6:	9fe9                	zext.h	a5,a5

By the way, does c.zext will dump as zext?

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Apr 6, 2024

Is the zext instruction appearing in a disassembly of library code by any chance? If so, then I suspect that the issue is that your toolchain doesn't have a multilib specifically for rv64gc/lp64d so it links the toolchain default libraries for rv64gc_zba_zbb_zbc_zbs_zicsr_zifencei_zicond_zcb_zfa/lp64d. This may be a bug in itself because I don't think that it should do that - but I don't really understand the multilib matching logic that was added last year and I'm always wary of letting the toolchain take care of this rather than ensuring that I build all necessary multilibs explicitly.

Or, come to think of it, maybe those matching rules are irrelevant since I think it was always the case that if an appropriate multilib wasn't available then the fallback was to try to just link the toolchain default libs. This is/was a common source of confusion especially when it led to rv32 vs rv64 mismatches at link time. For example:

Enabling verbose output when compiling should clarify if this is the case and the wrong libraries are being linked.

You probably want to configure your toolchain with --with-multilib-generator="rv64gc-lp64d--" if you're ever going to compile with -march=rv64gc -mabi=lp64d instead of the toolchain default arch/abi of rv64gc_zba_zbb_zbc_zbs_zicsr_zifencei_zicond_zcb_zfa/lp64d.

By the way, does c.zext will dump as zext?

I don't understand what you're asking here. Please clarify.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Apr 6, 2024

By the way, does c.zext will dump as zext?

I presume that you're asking why c.zext.h (not c.zext as there is no such instruction as far as I can see) decodes as zext.h?

Are you sure that you're correctly identifying the instruction in your disassembly?

Unfortunately this decoder doesn't help at the moment - maybe because it doesn't support all relevant extension yet:

@Ye-Jinhong
Copy link
Author

Thank you @TommyMurphyTM1234 , I understand. But when I build multilib following your step using make linux:

You probably want to configure your toolchain with --with-multilib-generator="rv64gc-lp64d--" if you're ever going to compile with -march=rv64gc -mabi=lp64d instead of the toolchain default arch/abi of rv64gc_zba_zbb_zbc_zbs_zicsr_zifencei_zicond_zcb_zfa/lp64d.

errors coming:

In file included from /home/yejinhong/hppa/riscv-multilib/sysroot/usr/include/features.h:527,
                 from /home/yejinhong/hppa/riscv-multilib/sysroot/usr/include/bits/libc-header-start.h:33,
                 from /home/yejinhong/hppa/riscv-multilib/sysroot/usr/include/stdio.h:28,
                 from ../../../../.././gcc/libgcc/../gcc/tsystem.h:87,
                 from ../../../../.././gcc/libgcc/libgcc2.c:27:
/home/yejinhong/hppa/riscv-multilib/sysroot/usr/include/gnu/stubs.h:8:11: fatal error: gnu/stubs-ilp32.h: No such file or directory
    8 | # include <gnu/stubs-ilp32.h>
      |           ^~~~~~~~~~~~~~~~~~~
compilation terminated.
make[5]: *** [Makefile:501: _ashldi3.o] Error 1
make[5]: Leaving directory '/home/yejinhong/hppa/riscv-gnu-toolchain/build-gcc-linux-stage2/riscv64-unknown-linux-gnu/lib32/ilp32/libgcc'
make[4]: *** [Makefile:1214: multi-do] Error 1
make[4]: Leaving directory '/home/yejinhong/hppa/riscv-gnu-toolchain/build-gcc-linux-stage2/riscv64-unknown-linux-gnu/libgcc'
make[3]: *** [Makefile:127: all-multi] Error 2
make[3]: *** Waiting for unfinished jobs....
In file included from ../../.././gcc/libgcc/unwind-dw2.c:410:
./md-unwind-support.h: In function 'riscv_fallback_frame_state':
./md-unwind-support.h:67:6: warning: assignment to 'struct sigcontext *' from incompatible pointer type 'mcontext_t *' [-Wincompatible-pointer-types]
   67 |   sc = &rt_->uc.uc_mcontext;
      |      ^
make[3]: Leaving directory '/home/yejinhong/hppa/riscv-gnu-toolchain/build-gcc-linux-stage2/riscv64-unknown-linux-gnu/libgcc'
make[2]: *** [Makefile:13274: all-target-libgcc] Error 2
make[2]: Leaving directory '/home/yejinhong/hppa/riscv-gnu-toolchain/build-gcc-linux-stage2'
make[1]: *** [Makefile:1039: all] Error 2
make[1]: Leaving directory '/home/yejinhong/hppa/riscv-gnu-toolchain/build-gcc-linux-stage2'
make: *** [Makefile:492: stamps/build-gcc-linux-stage2] Error 2

My configure is

./configure --prefix=/home/yejinhong/hppa/riscv-multilib --with-multilib-generator="rv64gc_zicsr_zifencei-lp64d--;rv64gc_zicond_zicsr_zifencei-lp64d--;rv64gc_zicsr_zifencei_zba_zbb_zbc_zbs-lp64d--;rv64gc_zicsr_zifencei_zba_zbb_zbc_zbs_zicond-lp64d--;rv64gc_zicsr_zifencei_zba_zbb_zbc_zbs_zicond_zcb_zfa-lp64d--;"

Whatever I do such as make clean -> make newlib -> make distclean, finally make linux will cause error.(follows #1445)

So how can I build multilib? OR is there anything wrong besides multilib building?

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Apr 7, 2024

Thank you @TommyMurphyTM1234 , I understand. But when I build multilib following your step using make linux:

I assumed that you were using a bare-metal toolchain. --with-multilib-generator only works with the bare-metal toolchain. It doesn't work with the Linux toolchain.

So how can I build multilib? OR is there anything wrong besides multilib building?

Unfortunately I haven't found a way to build the Linux toolchain with a custom set of multilibs ever since the approach of editing gcc/config/riscv/t-linux-multilib stopped working a while ago.

In any case there's another fundamental problem with Linux toolchain multilibs - only one multilib per XLEN/abi can be bundled:

All I can suggest is that you build a separate Linux toolchain for each arch/abi that you need specifying them via configure --with-arch=... --with-abi=....

@riscv-collab riscv-collab deleted a comment from Ye-Jinhong Apr 7, 2024
@TommyMurphyTM1234
Copy link
Collaborator

YES, and I am confused why c.zext.h will decoded as zext.h.

You'll probably need to ask about this upstream in the Binutils project.

@Ye-Jinhong
Copy link
Author

Thank you @TommyMurphyTM1234 , I build toolchains separately, and it works well. I then close this issue.

@kito-cheng
Copy link
Collaborator

YES, and I am confused why c.zext.h will decoded as zext.h.

Compressed instruction are disassemble into non compressed form by default, and this can be disabled by pass -M no-aliases to objdump

@TommyMurphyTM1234
Copy link
Collaborator

YES, and I am confused why c.zext.h will decoded as zext.h.

You'll probably need to ask about this upstream in the Binutils project.

Sincere apologies but I inadvertently deleted a post from @Ye-Jinhong earlier - the one that I was replying to here and quoted in part. Sorry about that @Ye-Jinhong.

@TommyMurphyTM1234
Copy link
Collaborator

YES, and I am confused why c.zext.h will decoded as zext.h.

Compressed instruction are disassemble into non compressed form by default, and this can be disabled by pass -M no-aliases to objdump

Thanks for that @kito-cheng - I, for one, wasn't aware of that! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants