Skip to content

fails build with 'configure: error' #1485

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

Closed
accesSudo opened this issue Jun 1, 2024 · 16 comments
Closed

fails build with 'configure: error' #1485

accesSudo opened this issue Jun 1, 2024 · 16 comments

Comments

@accesSudo
Copy link

accesSudo commented Jun 1, 2024

I have searched through a multitude of other similarily listed issues and it seems like none of the solutions have been able to work. I downloaded and was able to succesfully run the toolchain initially, but after I added one new custom instruction it seems as though the toolchain will refuse to recompile as I exit out with this error constantly:

checking for suffix of object files... configure: error: in /home/ulx3/projects/rv32i/sw/toolchain/build-gcc-linux-stage1/riscv32-unknown-linux-gnu/libgcc': configure: error: cannot compute suffix of object files: cannot compile See config.log' for more details
make[1]: *** [Makefile:12811: configure-target-libgcc] Error 1
make[1]: Leaving directory '/home/ulx3/projects/rv32i/sw/toolchain/build-gcc-linux-stage1'
make: *** [Makefile:455: stamps/build-gcc-linux-stage1] Error 2

Just to make it clear I have done the following solutions:
deleted and reinstalled a new virtual machine (Ubuntu)
deleted and did a fresh install of the riscv-gnu-toolchain
I make sure to delete the previosu prefix dir before each run so each run uses a clean unusued dir
I run make distclean and make clean before every new run
I do not change config arguements, and always call only "make linux" to build

The exact changes I have made are as follows (the functionality i am seeking is to add sin(x)):
in toolchain/gdb/opcodes/riscv-opc.c (same changes in toolchain/binutils/opcodes/riscv-opc.c)
{"fsin.s", 0, INSN_CLASS_F_INX, "d,s", MATCH_FSIN, MASK_FSIN, match_opcode, 0 }

in toolchain/gdb/include/opcode.riscv-opc.h (same changes in toolchain/binutils/opcodes/riscv-opc.c))
#define MATCH_FSIN 0x30000053
#define MASK_FSIN 0xfff0007f
DECLARE_INSN(fsin_s, MATCH_FSIN, MASK_FSIN)

After cloning the repo into the toolchain directory and creating a empty bin and build dir I run this config path:
./configure --prefix=/home/ulx3/build --with-arch=rv32gc --with-abi=ilp32d
make linux
I am aiming to work with the rv32i emulator so I need to stay with the 32 bit build

CONFIG LOG:
(I realized now that this is the wrong config log I tried --disable: float in ./config which was incorrect on my part, but I do end up with this configure error when running with this exact config command: ./configure --prefix=/home/ulx3/build --with-arch=rv32gc --with-abi=ilp32d

config error: cannot compute suffix of object files: cannot compile
See `config.log' for more details
make[1]: *** [Makefile:12811: configure-target-libgcc] Error 1
make[1]: Leaving directory '/home/ulx3/projects/rv32i/sw/toolchain/build-gcc-linux-stage1'
make: *** [Makefile:455: stamps/build-gcc-linux-stage1] Error 2 )

This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by riscv-toolchain configure 1.0, which was
generated by GNU Autoconf 2.69. Invocation command line was

$ ./configure --prefix=/home/ulx3/build --with-arch=rv32gc --with-abi=ilp32d

---------

Platform.

---------

hostname = xx
uname -m = x86_64
uname -r = 5.15.0-105-generic
uname -s = Linux
uname -v = #115-Ubuntu SMP Mon Apr 15 09:52:04 UTC 2024

/usr/bin/uname -p = x86_64
/bin/uname -X = unknown

/bin/arch = x86_64
/usr/bin/arch -k = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo = unknown
/bin/machine = unknown
/usr/bin/oslevel = unknown
/bin/universe = unknown

PATH: /home/ulx3/build/bin
PATH: /home/ulx3/build/bin
PATH: /home/ulx3/bin
PATH: /home/ulx3/bin
PATH: /home/.local/bin
PATH: /opt/xilinx/xrt/bin
PATH: /mnt/ssd0/Xilinx/Vitis_HLS/2021.2/bin
PATH: /mnt/ssd0/Xilinx/Model_Composer/2021.2/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/microblaze/lin/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/arm/lin/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/microblaze/linux_toolchain/lin64_le/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/aarch32/lin/gcc-arm-none-eabi/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/aarch64/lin/aarch64-linux/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/aarch64/lin/aarch64-none/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/armr5/lin/gcc-arm-none-eabi/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/tps/lnx64/cmake-3.3.2/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/aietools/bin
PATH: /mnt/ssd0/Xilinx/Vivado/2021.2/bin
PATH: /mnt/sdb/Xilinx/DocNav
PATH: /mnt/ssd0/Xilinx/Vitis_HLS/2021.2/bin
PATH: /mnt/ssd0/Xilinx/Model_Composer/2021.2/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/microblaze/lin/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/arm/lin/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/microblaze/linux_toolchain/lin64_le/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/aarch32/lin/gcc-arm-none-eabi/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/aarch64/lin/aarch64-linux/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/aarch64/lin/aarch64-none/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/gnu/armr5/lin/gcc-arm-none-eabi/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/tps/lnx64/cmake-3.3.2/bin
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2/aietools/bin
PATH: /mnt/ssd0/Xilinx/Vivado/2021.2/bin
PATH: /mnt/sdb/Xilinx/DocNav
PATH: /mnt/ssd0/Xilinx/Vitis/2021.2//bin/
PATH: /mnt/ssd0/Xilinx/Vivado/2021.2//bin/
PATH: /opt/bluespecpcie_manager/
PATH: /opt/Bluespec/Bluespec-Open-2023-02/inst//bin/
PATH: /usr/local/sbin
PATH: /usr/local/bin
PATH: /usr/sbin
PATH: /usr/bin
PATH: /sbin
PATH: /bin
PATH: /usr/games
PATH: /usr/local/games
PATH: /snap/bin

-----------

Core tests.

-----------

configure:1970: checking for gcc
configure:1986: found /usr/bin/gcc
configure:1997: result: gcc
configure:2226: checking for C compiler version
configure:2235: gcc --version >&5
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

configure:2246: $? = 0
configure:2235: gcc -v >&5
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.4.0-1ubuntu122.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1
22.04)
... rest of stderr output deleted ...
configure:2246: $? = 0
configure:2235: gcc -V >&5
gcc: error: unrecognized command-line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:2246: $? = 1
configure:2235: gcc -qversion >&5
gcc: error: unrecognized command-line option '-qversion'; did you mean '--version'?
gcc: fatal error: no input files
compilation terminated.
configure:2246: $? = 1
configure:2266: checking whether the C compiler works
configure:2288: gcc conftest.c >&5
configure:2292: $? = 0
configure:2340: result: yes
configure:2343: checking for C compiler default output file name
configure:2345: result: a.out
configure:2351: checking for suffix of executables
configure:2358: gcc -o conftest conftest.c >&5
configure:2362: $? = 0
configure:2384: result:
configure:2406: checking whether we are cross compiling
configure:2414: gcc -o conftest conftest.c >&5
configure:2418: $? = 0
configure:2425: ./conftest
configure:2429: $? = 0
configure:2444: result: no
configure:2449: checking for suffix of object files
configure:2471: gcc -c conftest.c >&5
configure:2475: $? = 0
configure:2496: result: o
configure:2500: checking whether we are using the GNU C compiler
configure:2519: gcc -c conftest.c >&5
configure:2519: $? = 0
configure:2528: result: yes
configure:2537: checking whether gcc accepts -g
configure:2557: gcc -c -g conftest.c >&5
configure:2557: $? = 0
configure:2598: result: yes
configure:2615: checking for gcc option to accept ISO C89
configure:2678: gcc -c -g -O2 conftest.c >&5
configure:2678: $? = 0
configure:2691: result: none needed
configure:2711: checking for grep that handles long lines and -e
configure:2769: result: /usr/bin/grep
configure:2774: checking for fgrep
configure:2836: result: /usr/bin/grep -F
configure:2841: checking for grep that handles long lines and -e
configure:2899: result: /usr/bin/grep
configure:2907: checking for bash
configure:2938: result: /bin/bash
configure:3009: checking for __gmpz_init in -lgmp
configure:3034: gcc -o conftest -g -O2 conftest.c -lgmp >&5
configure:3034: $? = 0
configure:3043: result: yes
configure:3056: checking for mpfr_init in -lmpfr
configure:3081: gcc -o conftest -g -O2 conftest.c -lmpfr -lgmp >&5
configure:3081: $? = 0
configure:3090: result: yes
configure:3103: checking for mpc_init2 in -lmpc
configure:3128: gcc -o conftest -g -O2 conftest.c -lmpc -lmpfr -lgmp >&5
configure:3128: $? = 0
configure:3137: result: yes
configure:3160: checking for curl
configure:3178: found /usr/bin/curl
configure:3191: result: /usr/bin/curl
configure:3201: checking for wget
configure:3219: found /usr/bin/wget
configure:3232: result: /usr/bin/wget
configure:3242: checking for ftp
configure:3260: found /usr/bin/ftp
configure:3273: result: /usr/bin/ftp
configure:4049: creating ./config.status

----------------------

Running config.status.

----------------------

This file was extended by riscv-toolchain config.status 1.0, which was
generated by GNU Autoconf 2.69. Invocation command line was

CONFIG_FILES =
CONFIG_HEADERS =
CONFIG_LINKS =
CONFIG_COMMANDS =
$ ./config.status

on xx

config.status:768: creating Makefile
config.status:768: creating scripts/wrapper/awk/awk
config.status:768: creating scripts/wrapper/sed/sed
configure:5058: WARNING: unrecognized options:

----------------

Cache variables.

----------------

ac_cv_c_compiler_gnu=yes
ac_cv_env_CC_set=
ac_cv_env_CC_value=
ac_cv_env_CFLAGS_set=
ac_cv_env_CFLAGS_value=
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=
ac_cv_env_LDFLAGS_set=
ac_cv_env_LDFLAGS_value=
ac_cv_env_LIBS_set=
ac_cv_env_LIBS_value=
ac_cv_env_build_alias_set=
ac_cv_env_build_alias_value=
ac_cv_env_host_alias_set=
ac_cv_env_host_alias_value=
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_lib_gmp___gmpz_init=yes
ac_cv_lib_mpc_mpc_init2=yes
ac_cv_lib_mpfr_mpfr_init=yes
ac_cv_objext=o
ac_cv_path_BASH=/bin/bash
ac_cv_path_CURL=/usr/bin/curl
ac_cv_path_FGREP='/usr/bin/grep -F'
ac_cv_path_FTP=/usr/bin/ftp
ac_cv_path_GAWK=/usr/bin/gawk
ac_cv_path_GREP=/usr/bin/grep
ac_cv_path_GSED=/usr/bin/sed
ac_cv_path_WGET=/usr/bin/wget
ac_cv_prog_ac_ct_CC=gcc
ac_cv_prog_cc_c89=
ac_cv_prog_cc_g=yes

-----------------

Output variables.

-----------------

BASH='/bin/bash'
CC='gcc'
CFLAGS='-g -O2'
CPPFLAGS=''
CURL='/usr/bin/curl'
DEFS='-DPACKAGE_NAME="riscv-toolchain" -DPACKAGE_TARNAME="riscv-toolchain" -DPACKAGE_VERSION="1.0" -DPACKAGE_STRING="riscv-toolchain\ 1.0" -DPACKAGE_BUGREPORT="" -DPACKAGE_URL="" -DHAVE_LIBGMP=1 -DHAVE_LIBMPFR=1 -DHAVE_LIBMPC=1'
ECHO_C=''
ECHO_N='-n'
ECHO_T=''
EXEEXT=''
FETCHER='/usr/bin/curl -L -o - --ftp-pasv --retry 10'
FGREP='/usr/bin/grep -F'
FTP='/usr/bin/ftp'
GAWK='/usr/bin/gawk'
GREP='/usr/bin/grep'
GSED='/usr/bin/sed'
LDFLAGS=''
LIBOBJS=''
LIBS='-lmpc -lmpfr -lgmp '
LTLIBOBJS=''
NEED_GCC_EXTERNAL_LIBRARIES='false'
OBJEXT='o'
PACKAGE_BUGREPORT=''
PACKAGE_NAME='riscv-toolchain'
PACKAGE_STRING='riscv-toolchain 1.0'
PACKAGE_TARNAME='riscv-toolchain'
PACKAGE_URL=''
PACKAGE_VERSION='1.0'
PATH_SEPARATOR=':'
SHELL='/bin/bash'
WGET='/usr/bin/wget'
WITH_ABI='--with-abi=ilp32d'
WITH_ARCH='--with-arch=rv32gc'
WITH_ISA_SPEC='--with-isa-spec=20191213'
WITH_SIM='qemu'
WITH_TUNE='--with-tune=rocket'
ac_ct_CC='gcc'
bindir='${exec_prefix}/bin'
build_alias=''
cmodel='-mcmodel=medlow'
configure_host=''
datadir='${datarootdir}'
datarootdir='${prefix}/share'
debug_info=''
default_target='newlib'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
dvidir='${docdir}'
enable_gdb='--enable-gdb'
enable_host_gcc='--disable-host-gcc'
enable_libsanitizer='--disable-libsanitizer'
enable_llvm='--disable-llvm'
exec_prefix='${prefix}'
extra_multilib_test=''
gcc_checking=''
glibc_multilib_names='rv32gc-ilp32d'
host_alias=''
htmldir='${docdir}'
includedir='${prefix}/include'
infodir='${datarootdir}/info'
libdir='${exec_prefix}/lib'
libexecdir='${exec_prefix}/libexec'
localedir='${datarootdir}/locale'
localstatedir='${prefix}/var'
mandir='${datarootdir}/man'
multilib_flags='--disable-multilib'
multilib_gen=''
musl_multilib_names='rv32gc-ilp32d'
newlib_multilib_names='rv32gc-ilp32d'
oldincludedir='/usr/include'
pdfdir='${docdir}'
prefix='/home/ulx3/build'
program_transform_name='s,x,x,'
psdir='${docdir}'
qemu_targets='riscv64-linux-user,riscv32-linux-user'
sbindir='${exec_prefix}/sbin'
sharedstatedir='${prefix}/com'
sysconfdir='${prefix}/etc'
target_alias=''
target_cflags=''
target_cxxflags=''
with_binutils_src='$(srcdir)/binutils'
with_dejagnu_src='$(srcdir)/dejagnu'
with_gcc_src='$(srcdir)/gcc'
with_gdb_src='$(srcdir)/gdb'
with_glibc_src='$(srcdir)/glibc'
with_guile=''
with_linux_headers_src='$(srcdir)/linux-headers/include'
with_llvm_src='$(srcdir)/llvm'
with_musl_src='$(srcdir)/musl'
with_newlib_src='$(srcdir)/newlib'
with_pk_src='$(srcdir)/pk'
with_qemu_src='$(srcdir)/qemu'
with_spike_src='$(srcdir)/spike'
with_system_zlib='--with-system-zlib'

-----------

confdefs.h.

-----------

/* confdefs.h */
#define PACKAGE_NAME "riscv-toolchain"
#define PACKAGE_TARNAME "riscv-toolchain"
#define PACKAGE_VERSION "1.0"
#define PACKAGE_STRING "riscv-toolchain 1.0"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
#define HAVE_LIBGMP 1
#define HAVE_LIBMPFR 1
#define HAVE_LIBMPC 1

configure: exit 0

@TommyMurphyTM1234
Copy link
Collaborator

I have kicked off a build to see if I can reproduce this.

However, one tangential thing to note:

After cloning the repo into the toolchain directory and creating a empty bin and build dir I run this config path:
./configure --prefix=/home/ulx3/build --with-arch=rv32gc --with-abi=ilp32d
make linux
I am aiming to work with the rv32i emulator so I need to stay with the 32 bit build

If you're targeting rv32i/ilp32 then an rv32gc/ilp32d toolchain is probably not appropriate as, by default (e.g. without explicitly specifying -march=rv32i -mabi=ilp32), it will generate instructions not supported by the former arch/abi - e.g. instructions from some or all of the MAFDC extensions. And I don't think that running Linux on rv32i/ilp32 is easy if it's possible at all. I think you really need at least rv32gc/ilp32d.

@TommyMurphyTM1234
Copy link
Collaborator

I suspect that this is incorrect?

The exact changes I have made are as follows (the functionality i am seeking is to add sin(x)):
in toolchain/gdb/opcodes/riscv-opc.c (same changes in toolchain/binutils/opcodes/riscv-opc.c)
{"fsin.s", 0, INSN_CLASS_F_INX, "d,s", MATCH_FSIN, MASK_FSIN, match_opcode, 0 }

in toolchain/gdb/include/opcode.riscv-opc.h (same changes in toolchain/binutils/opcodes/riscv-opc.c))
#define MATCH_FSIN 0x30000053
#define MASK_FSIN 0xfff0007f
DECLARE_INSN(fsin_s, MATCH_FSIN, MASK_FSIN)

Ignoring GDB for the moment, isn't it the case that the following changes need to be made:

// Add this to binutils/opcodes/riscv-opc.c
{"fsin.s", 0, INSN_CLASS_F_INX, "d,s", MATCH_FSIN, MASK_FSIN, match_opcode, 0 }

// Add this to binutils/include/opcode/riscv-opc.h
#define MATCH_FSIN 0x30000053
#define MASK_FSIN 0xfff0007f
DECLARE_INSN(fsin_s, MATCH_FSIN, MASK_FSIN)

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Jun 1, 2024

OK - I can reproduce the issue but it seems to be down to some problem with the addition of the custom instruction - something wrong with the opcode and/or mask used perhaps?
It doesn't seem to be a problem with the riscv-gnu-toolchain per se.

This is what I see in build-gcc-linux-stage1/riscv32-unknown-linux-gnu/libgcc/config.log after the failure:

configure:3792: checking for suffix of object files                                                                                                                                         configure:3814:  /home/user/Downloads/issue-1485/build-gcc-linux-stage1/./gcc/xgcc -B/home/user/Downloads/issue-1485/build-gcc-linux-stage1/./gcc/ -B/home/user/Downloads/issue-1485/installed-tools/riscv32-unknown-linux-gnu/bin/ -B/home/user/Downloads/issue-1485/installed-tools/riscv32-unknown-linux-gnu/lib/ -isystem /home/user/Downloads/issue-1485/installed-tools/riscv32-unknown-linux-gnu/include -isystem /home/user/Downloads/issue-1485/installed-tools/riscv32-unknown-linux-gnu/sys-include    -c -O2    -mcmodel=medlow  conftest.c >&5
Assembler messages:
Error: internal: bad RISC-V opcode (bits 0x7000 undefined or invalid): fsin.s d,s
Fatal error: internal: broken assembler.  No assembly attempted
Internal error (Segmentation fault).
Please report this bug.
configure:3818: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU C Runtime Library"
| #define PACKAGE_TARNAME "libgcc"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU C Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL "http://www.gnu.org/software/libgcc/"
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:3832: error: in `/home/user/Downloads/issue-1485/build-gcc-linux-stage1/riscv32-unknown-linux-gnu/libgcc':
configure:3834: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Jun 1, 2024

OK - I can reproduce the issue but it seems to be down to some problem with the addition of the custom instruction - something wrong with the opcode and/or mask used perhaps?

Can you explain the rationale behind your choice of instruction opcode and mask here?

#define MATCH_FSIN 0x30000053
#define MASK_FSIN 0xfff0007f
DECLARE_INSN(fsin_s, MATCH_FSIN, MASK_FSIN)

And how you arrived at the aforementioned changes to the toolchain source files for adding a custom floating point instruction?

Note that this issue and the third party tutorial that it links to shows how to successfully add a custom integer instruction (mod in this example) but I haven't seen any similar tutorial that deals with the addition of custom floating point instructions.

@accesSudo
Copy link
Author

Hello Tommy appreciate your prompt reply.

The way I arrived at the specific match and mask values was by utilizing the riscv-tools repo.

First I went to riscv-tools/riscv-opcodes/opcodes where I inputted this (using other floating point instructions as a reference):
fsin.s rd rs1 24..20=0 31..27=0x06 rm 26..25=0 6..2=0x14 1..0=3

From there I called:
cat opcodes | ./parse-opcodes -c > temp.h

Which is what gave me the auto generated mask and match values. Is that wrong? Is there someother way to get match and mask values? I apologize if that is a low level question but I am extremely new to RISCV.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Jun 1, 2024

Is that wrong? Is there someother way to get match and mask values?

Sorry, I don't know enough about adding custom floating point instructions to the toolchain to advise. But I guess that there's something wrong with your first attempt above given that the toolchain builds fine on a clean clone from the repo but fails when you make your custom fsin.s instruction changes to the sources. That's certainly what the error message seems to be suggesting:

Error: internal: bad RISC-V opcode (bits 0x7000 undefined or invalid): fsin.s d,s
Fatal error: internal: broken assembler.  No assembly attempted

@accesSudo
Copy link
Author

Oh thank you, do you perhaps know what github repo would have better resources in terms of adding custom floating point instructions? like riscv-tools perhaps?

@TommyMurphyTM1234
Copy link
Collaborator

Oh thank you, do you perhaps know what github repo would have better resources in terms of adding custom floating point instructions?

Unfortunately I don't. You could maybe ask on a GCC mailing list why your changes trigger a build error.

like riscv-tools perhaps?

That repo is archived/deprecated:

@accesSudo
Copy link
Author

Sure thank you one last question, what file did you find this error message in (and where was it located):

Error: internal: bad RISC-V opcode (bits 0x7000 undefined or invalid): fsin.s d,s
Fatal error: internal: broken assembler. No assembly attempted

@TommyMurphyTM1234
Copy link
Collaborator

Sure thank you one last question, what file did you find this error message in (and where was it located):

Error: internal: bad RISC-V opcode (bits 0x7000 undefined or invalid): fsin.s d,s Fatal error: internal: broken assembler. No assembly attempted

This is what I see in build-gcc-linux-stage1/riscv32-unknown-linux-gnu/libgcc/config.log after the failure:
...

This is the log file that the original error is pointing to:

checking for suffix of object files... configure: error: in /home/ulx3/projects/rv32i/sw/toolchain/build-gcc-linux-stage1/riscv32-unknown-linux-gnu/libgcc': configure: error: cannot compute suffix of object files: cannot compile See config.log' for more details
make[1]: *** [Makefile:12811: configure-target-libgcc] Error 1
make[1]: Leaving directory '/home/ulx3/projects/rv32i/sw/toolchain/build-gcc-linux-stage1'
make: *** [Makefile:455: stamps/build-gcc-linux-stage1] Error 2

@accesSudo
Copy link
Author

Ah, I see I must have overlooked that comment.

Thank you, I was able to figure out how to add a floating point instruction as well!

@TommyMurphyTM1234
Copy link
Collaborator

Ah, I see I must have overlooked that comment.

Thank you, I was able to figure out how to add a floating point instruction as well!

Can you clarify what you had to change in your original attempt on order to address the problem as it may help others in the same position in the future?

@accesSudo
Copy link
Author

accesSudo commented Jun 3, 2024

Oh yeah sure, for potential future readers I do not know if this is 100% the right thing to do because I have yet to add sin to an emulator to fully test it, however the changes I made did let me successfully recompile the gnu-toolchain.

First I went into riscv-tools/riscv-opcodes/opcodes-custom
From there I assumed the original creator created basic templates that could be used to create custom instructions, I used:
custom rd rs1 imm12 14..12=0 6..2=0x02 1..0=3 since I was just going to load an immediate value into sin(x) and did not need source registers

Then I ran: cat opcodes-custom | ./parse-opcodes -c > temp.h

From which I got:
#define MATCH_CUSTOM 0xb
#define MASK_CUSTOM 0x707f
DECLARE_INSN(custom, MATCH_CUSTOM, MASK_CUSTOM)

I plugged those above values into:
toolchain/gdb/include/opcode/riscv-opc.h & toolchain/binutils/opcodes/include/riscv-opc.h

This next part is what I am a little unsure of, to make sure it was a floating point instruction in
toolchain/gdb/opcode.riscv-opc.c & toolchain/binutils/opcodes/riscv-opc.c
{"custom", 0, INSN_CLASS_D_INX, "d,a", MATCH_CUSTOM, MASK_CUSTOM, match_opcode, 0 }

Rebuilding this gave me no errors (keep in mind I have yet to add it to an emulator so I can not say for certain it works)

I would appreciate if anyone could let me know if this looks right, or if it looks like I made a mistake along the way with my assumptions!

@accesSudo accesSudo reopened this Jun 3, 2024
@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Jun 4, 2024

Rebuilding this gave me no errors (keep in mind I have yet to add it to an emulator so I can not say for certain it works)

If the modified toolchain can generate your custom instruction (e.g. using GCC inline assembly) when you compile a program then you have presumably made the correct changes to the toolchain. Have you checked this?

I'm not clear why you seem to have changed from using fsin.s and INSN_CLASS_F_INX to using custom and INSN_CLASS_D_INX though? But the specific name and class of instruction is probably irrelevant to the general exercise of adding such a custom instruction.

@accesSudo
Copy link
Author

accesSudo commented Jun 4, 2024

Hi Tommy,

So first by inline assembly do you mean compiling a c program using: riscv32-unknown-linux-gnu-gcc?

If so then yes I was able to do this, coverting a .c file to a .o and a .dump file (using riscv32-unknown-elf-objdump).

This is the c file that I was using is calling this to test custom:
float custom_sin() {
float fact_result_ptr;

asm volatile("custom %0, %1\n":"=r"(fact_result_ptr):"i"(30):);

return fact_result_ptr;

}

As for changing fsin.s -> custom I just did not want to change the name but it should be fine to change custom -> fsin.s

As for changing INSN_CLASS_F_INX -> INSN_CLASS_D_INX I noticed in opcodes/risc-opc.c that
INSN_CLASS_F_INX was used under / * Single-precision floating-point instruction subset. */
while on the other hand
INSN_CLASS_D_INX was used under / * Double-precision floating-point instruction subset. */ and I wanted to use double precision instead of single

@TommyMurphyTM1234
Copy link
Collaborator

So first by inline assembly do you mean compiling a c program using: riscv32-unknown-linux-gnu-gcc?

If so then yes I was able to do this, coverting a .c file to a .o and a .dump file (using riscv32-unknown-elf-objdump).

This is the c file that I was using is calling this to test custom: float custom_sin() { float fact_result_ptr;

asm volatile("custom %0, %1\n":"=r"(fact_result_ptr):"i"(30):);

return fact_result_ptr;
}

That being the case it sounds like your toolchain changes to add your custom instruction were successful.

As for changing fsin.s -> custom I just did not want to change the name but it should be fine to change custom -> fsin.s

As for changing INSN_CLASS_F_INX -> INSN_CLASS_D_INX I noticed in opcodes/risc-opc.c that INSN_CLASS_F_INX was used under / * Single-precision floating-point instruction subset. */ while on the other hand INSN_CLASS_D_INX was used under / * Double-precision floating-point instruction subset. */ and I wanted to use double precision instead of single

OK - thanks.

I will close this again since the original issue has been addressed.

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

2 participants