Porting linux for a custom imafd SOC

Hi all,
I am trying to build a yocto demo-coreip-cli image for my custom risc-v SOC which only supports imafd instructions.
For the compilation of cross toolchain that is used by Bitbake, I tried changing cross-binutils.inc recipe and cross-gcc.inc recipe in openembedded-core layer by including “–with-arch=rv64imafd” in "EXTRA_OECONF " variable.
Is there anything else I am missing or doing wrong?
Thank You.

I don’t know if anyone has ever tried that. it sounds like it should work. Did you try that? Did you run into a problem? What exact problem did you run into? Did you try debugging it?

Yes, I did tried that but no, its not working. I think we have to change the recipes for dependencies also which are used for compiling the cross-toolchain. But I’m not sure which recipes are to be edited.

I also included
“TARGET_LDFLAGS += " -march=rv64imafd”
within local.conf file in the build directory. So that TARGET_LDFLAGS can be passed to every package.

This is the error I got:

ERROR: glibc-2.31+gitAUTOINC+1094741224-r0 do_configure: configure failed
ERROR: glibc-2.31+gitAUTOINC+1094741224-r0 do_configure: Execution of ‘/home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/temp/run.do_configure.44528’ failed with exit code 1:
checking build system type… x86_64-pc-linux-gnu
checking host system type… riscv64-oe-linux-gnu
checking for riscv64-oe-linux-gcc… riscv64-oe-linux-gcc --sysroot=/home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether riscv64-oe-linux-gcc --sysroot=/home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot accepts -g… yes
checking for gcc… gcc
checking for riscv64-oe-linux-readelf… riscv64-oe-linux-readelf
checking whether we are using the GNU C++ compiler… yes
checking whether riscv64-oe-linux-g++ --sysroot=/home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot accepts -g… yes
checking whether riscv64-oe-linux-g++ --sysroot=/home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot can link programs… no
checking for sysdeps preconfigure fragments… aarch64 alpha arm csky hppa i386 m68k microblaze checking for grep that handles long lines and -e… /home/qc/anaadi/riscv-sifive/build/tmp-glibc/hosttools/grep
checking for egrep… /home/qc/anaadi/riscv-sifive/build/tmp-glibc/hosttools/grep -E
mips nios2 powerpc riscv s390 sh checking for grep that handles long lines and -e… (cached) /home/qc/anaadi/riscv-sifive/build/tmp-glibc/hosttools/grep
checking for egrep… (cached) /home/qc/anaadi/riscv-sifive/build/tmp-glibc/hosttools/grep -E
sparc x86_64
checking for use of fpu sysdeps directories… yes
checking for -fstack-protector… (cached) no
checking for -fstack-protector-strong… (cached) no
checking for -fstack-protector-all… (cached) no
checking for assembler and linker STT_GNU_IFUNC support… no
checking for gcc attribute ifunc support… no
checking whether the linker supports textrels along with ifunc… no
checking if compiler warns about alias for function with incompatible types… yes
configure: WARNING: gcc emits a warning for alias between functions of incompatible types
configure: WARNING: Multi-arch is disabled.
checking sysdep dirs… sysdeps/unix/sysv/linux/riscv/rv64 sysdeps/unix/sysv/linux/riscv sysdeps/riscv/nptl sysdeps/unix/sysv/linux/generic sysdeps/unix/sysv/linux/wordsize-64 sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix sysdeps/posix sysdeps/riscv/rv64/rvd sysdeps/riscv/rv64/rvf sysdeps/riscv/rvf sysdeps/riscv/rvd sysdeps/riscv/rv64 sysdeps/riscv sysdeps/init_array sysdeps/ieee754/ldbl-128 sysdeps/ieee754/dbl-64 sysdeps/ieee754/flt-32 sysdeps/wordsize-64 sysdeps/ieee754 sysdeps/generic
checking for a BSD-compatible install… /home/qc/anaadi/riscv-sifive/build/tmp-glibc/hosttools/install -c
checking whether ln -s works… yes
checking whether /home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot-native/usr/bin/riscv64-oe-linux/…/…/libexec/riscv64-oe-linux/gcc/riscv64-oe-linux/10.1.0/as is GNU as… yes
checking whether /home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot-native/usr/bin/riscv64-oe-linux/…/…/libexec/riscv64-oe-linux/gcc/riscv64-oe-linux/10.1.0/ld is GNU ld… yes
checking for /home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot-native/usr/bin/riscv64-oe-linux/…/…/libexec/riscv64-oe-linux/gcc/riscv64-oe-linux/10.1.0/as… /home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot-native/usr/bin/riscv64-oe-linux/…/…/libexec/riscv64-oe-linux/gcc/riscv64-oe-linux/10.1.0/as
checking version of /home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot-native/usr/bin/riscv64-oe-linux/…/…/libexec/riscv64-oe-linux/gcc/riscv64-oe-linux/10.1.0/as…, ok
checking for /home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot-native/usr/bin/riscv64-oe-linux/…/…/libexec/riscv64-oe-linux/gcc/riscv64-oe-linux/10.1.0/ld… /home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot-native/usr/bin/riscv64-oe-linux/…/…/libexec/riscv64-oe-linux/gcc/riscv64-oe-linux/10.1.0/ld
checking version of /home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot-native/usr/bin/riscv64-oe-linux/…/…/libexec/riscv64-oe-linux/gcc/riscv64-oe-linux/10.1.0/ld…, ok
checking for gnumake… make
checking version of make… 4.3, ok
checking for gnumsgfmt… (cached) no
checking for gmsgfmt… (cached) no
checking for msgfmt… (cached) no
checking for makeinfo… makeinfo
checking version of makeinfo… 5.2, ok
checking for sed… sed
checking version of sed… 4.2.2, ok
checking for gawk… gawk
checking version of gawk… 4.1.3, ok
checking for bison… bison
checking version of bison… 3.6.4, ok
checking if riscv64-oe-linux-gcc --sysroot=/home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot is sufficient to build libc… yes
checking for riscv64-oe-linux-nm… riscv64-oe-linux-nm
checking for python3… python3
checking version of python3… 3.7.6, ok
configure: WARNING:
*** These auxiliary programs are missing or incompatible versions: msgfmt
*** some features or tests will be disabled.
*** Check the INSTALL file for required versions.
checking LD_LIBRARY_PATH variable… ok
checking for bash… (cached) /bin/bash
checking for perl… /home/qc/anaadi/riscv-sifive/build/tmp-glibc/hosttools/perl
checking for install-info… /home/qc/anaadi/riscv-sifive/build/tmp-glibc/work/riscv64-oe-linux/glibc/2.31+gitAUTOINC+1094741224-r0/recipe-sysroot-native/bin/install-info
checking for .set assembler directive… no
checking linker support for protected data symbol… yes
checking linker support for INSERT in linker script… yes
checking for broken attribute((alias()))… no
checking whether to put _rtld_local into .sdata section… yes
checking whether to use .ctors/.dtors header and trailer… configure: error: missing attribute ((constructor)) support??
WARNING: exit code 1 from a shell command.

You have a configure error

configure: error: missing attribute ((constructor)) support??
Try looking at the config.log file in the glibc build dir to see why the tests for attribute constructor failed.

Trying to pass -march=rv64imafd to every package is the hard way to do this. The easy way is to configure binutils and gcc to handle rv64imafd by default, and since most everything gets built by binutils and gcc you don’t have to change the other packages. There might be some stuff built by clang, so you might need to fix clang too.

It worked! After I removed
“TARGET_LDFLAGS += " -march=rv64imafd”
and only added the “–with-arch=rv64g” in gcc-cross.inc , the toolchain was by default building for imafd extension.
But now when I’m trying to build the corresponding sdk for the yocto image , its giving me configuration error in gcc-crosssdk i.e. cpu architecture not supported.
The same flag “–with-arch=rv64g” is being passed to the do_configure task.

I don’t know how the cross sdk stuff works. But I don’t know why adding the --with-arch option would cause a problem. You should try to figure out exactly what failed. Maybe search the source code for the error message you got.

If there is a reason why adding a --with-arch option can’t work, then another option might be to add a patch to gcc to make rv64g the default when configuring. Then you don’t need to change configure flag. But I don’t know if this helps or hurts.

I did some tweaking with the recipes and this helped me:

-In cross.bbclass add
TOOLCHAIN_OPTIONS = " --with-arch=rv64g "

-In gcc-crosssdk.inc add
EXTRA_OECONF_remove = " --with-arch=rv64g "
EXTRA_OECONF += " target_configargs=–with-arch=rv64g "

-In gcc-cross-canadian.inc add
EXTRA_OECONF += " --with-arch=rv64g "

-In binutils-cross-canadian.inc add
EXTRA_OECONF += " --with-arch=rv64g "

This is a bit messy as I’m directly editing the recipes which isn’t recommended.