0

How can differentiate between a rv64imafd and rv64imafdc binary without executing them? I am using few compiler flags for changing the extensions but I'm not sure how to verify it. I don't want to dump the executable every time for testing on my imafd board.
I tried to study objdump of both the files and even though there was a clear difference between the opcodes, but it is not enough. Let me know if I can share more information on this regard.

2 Answers2

1

Even if you compile with the rv64imafd flag, your executable can be rv64imadfc if you link to a library (or a crt file) compiled with rv64imadfc.
This seems to be the case because your final executable contains the c flag even if you compile to rv64imafd.
If you are using https://github.com/riscv/riscv-gnu-toolchain
The build defaults to targeting rv64gc so you are linking against rv64gc libraries. if you used --enable-multilib you are linking against rv64imafdc.

In order to generate an rv64imafd executable you have three choices:

  • use the nostdlib and nostartfiles options and pass the necessary files (compiled with rv64imafd) by hand.
  • build a toolchain with -march=rv64imafd -mabi=lp64d
  • modify t-elf-multilib to also generate rv64imafd and build the toolchain with --enable-multilib option.
yflelion
  • 1,698
  • 2
  • 5
  • 16
  • Yes, you're right. I went for the second option since I was working with Yocto . Here is how I did [it] (https://stackoverflow.com/questions/63127165/porting-linux-for-a-custom-risc-v-imafd-soc) – Anaadi Mishra Aug 28 '20 at 12:02
  • Happy to help. If this answer or any other one solved your issue, please mark it as accepted. – yflelion Nov 09 '20 at 19:55
0

objdump or a program that does an equivalent level of decoding is probably necessary to confirm no compressed instructions are present in the binary. However ELF executables made by the GNU toolchain use the flags of the elf binary to encode if it was compiled with compressed instructions enabled.

$readelf -h no_compressed.o 
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  ...
  Flags:                             0x4, double-float ABI
  ...
$ readelf -h compressed.o 
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  ...
  Flags:                             0x5, RVC, double-float ABI
  ...
TheThirdOne
  • 427
  • 3
  • 10
  • I have 2 executables and both have same flags enabled, but one of them is executing and giving "illegal instruction" error on imafd board. – Anaadi Mishra Jul 29 '20 at 10:08
  • If the executables are in the ELF format have you tried taking a look at readelf? Its possible they both have the RVC flag, but only one of them actually uses compressed instructions. In that case you would want to change/add options to your compilation to get rid of the flag which should make sure no compressed instructions are present. – TheThirdOne Jul 29 '20 at 23:45