0

I'm trying to compile RISC-V assembly code to object file. I've built riscv-gnu-toolchain, selecting newlib, architecture rv32imac and abi ilp32.

However, when I try to compile assembly code with command: riscv32-unknown-elf-as -march=rv32imac -mabi=ilp32 main.s -o main.o, I'm getting: Error: unrecognized opcode 'mul a0,t4,t5', extension 'm' or 'zmmul' required.

I don't really understand, why I'm getting this. In both cases (building the toolchain and compiling the code) I specified m extension, but it looks like riscv32-unknown-elf-as doesn't detect it.

Do you know, what am I doing wrong and how can I fix it? Thanks!

EDIT:

I solved the problem: in source code I had the line .attribute 5, "rv32i2p0" that was overriding -march option from command line. I changed it to .attribute 5, "rv32imac" and fixed the problem.

user3272
  • 103
  • 1
  • 9
  • 1
    Works here. What version of binutils? – Jester Apr 20 '23 at 13:06
  • I used the default binutils (located inside `riscv-gnu-toolchain` repo) – user3272 Apr 20 '23 at 13:12
  • 1
    That does not help. What is the version number (`as --version`) – Jester Apr 20 '23 at 13:14
  • GNU assembler (GNU Binutils for Debian) 2.35.2 Copyright (C) 2020 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or later. This program has absolutely no warranty. This assembler was configured for a target of `x86_64-linux-gnu'. – user3272 Apr 20 '23 at 13:16
  • Should I rebuild/install binutils for riscv? – user3272 Apr 20 '23 at 13:24
  • *This assembler was configured for a target of `x86_64-linux-gnu`* - That's your system assembler, `as --version`. Not the `riscv32-unknown-elf-as` you used to assemble your RISC-V source. – Peter Cordes Apr 20 '23 at 13:28
  • 1
    Does your source have any directives that override the `-march` from the command line? A [mcve] would include a source file (probably just one line) and an `as` version (for `riscv32-unknown-elf-as` of course). And any config options you used when building the toolchain yourself. – Peter Cordes Apr 20 '23 at 13:29
  • `riscv32-unknown-elf-as` returns: GNU assembler (GNU Binutils) 2.40.0.20230214 Copyright (C) 2023 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or later. This program has absolutely no warranty. This assembler was configured for a target of `riscv32-unknown-elf'. – user3272 Apr 20 '23 at 13:34
  • 2
    I found the bug. Indeed, as @PeterCordes mentioned, I had in source code the attribute that overrode `-march` from CLI. Thanks y'all. – user3272 Apr 20 '23 at 13:41

0 Answers0