agra-uni-bremen / riscv-vp

RISC-V Virtual Prototype
MIT License
139 stars 49 forks source link

docker method: fail to build the "simple-display" testcase #26

Closed hvishu closed 1 year ago

hvishu commented 1 year ago

I followed the steps from the link (https://github.com/agra-uni-bremen/riscv-vp "Alternative Setup: Docker"). Able to build and run the sw/basic-c using "make sim". But same is not working for "sw/simple-display", Below is the log.

riscv32-unknown-elf-g++ -g -std=c++14 main.cpp libDisplay.cpp -o main -march=rv32ima -mabi=ilp32
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccHeiNfO.o: can't link soft-float modules with double-float modules
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: failed to merge target specific data of file /tmp/ccHeiNfO.o
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccJoFOgf.o: can't link soft-float modules with double-float modules
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: failed to merge target specific data of file /tmp/ccJoFOgf.o
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccHeiNfO.o: in function `activeWait(float)':
/home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:17: undefined reference to `__floatsisf'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:17: undefined reference to `__mulsf3'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:17: undefined reference to `__ltsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccHeiNfO.o: in function `drawFunnyRects()':
/home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:52: undefined reference to `__mulsf3'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccHeiNfO.o: in function `progressBar(bool, Framebuffer::PointF, Framebuffer::PointF, unsigned short, unsigned short, float)':
/home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:57: undefined reference to `__mulsf3'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccHeiNfO.o: in function `drawFunnyBar(bool)':
/home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:81: undefined reference to `__extendsfdf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:84: undefined reference to `__adddf3'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:84: undefined reference to `__truncdfsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:84: undefined reference to `__lesf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:83: undefined reference to `__extendsfdf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:89: undefined reference to `__subdf3'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:90: undefined reference to `__truncdfsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:90: undefined reference to `__gesf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccHeiNfO.o: in function `Framebuffer::PointF::PointF(Framebuffer::Point)':
/home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:117: undefined reference to `__floatunsisf'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:117: undefined reference to `__floatunsisf'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccHeiNfO.o: in function `.L0 ':
/home/riscv-vp/riscv-vp/sw/simple-display/main.cpp:117: undefined reference to `__addsf3'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccHeiNfO.o: in function `operator+(Framebuffer::PointF, Framebuffer::PointF)':
/home/riscv-vp/riscv-vp/sw/simple-display/../../env/basic/vp-display/framebuffer.h:84: undefined reference to `__addsf3'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccJoFOgf.o: in function `display::drawRect(Framebuffer::Type, Framebuffer::PointF, Framebuffer::PointF, unsigned short)':
/home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:31: undefined reference to `__gtsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:33: undefined reference to `__gtsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccJoFOgf.o: in function `display::fillRect(Framebuffer::Type, Framebuffer::PointF, Framebuffer::PointF, unsigned short)':
/home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:44: undefined reference to `__eqsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:44: undefined reference to `__eqsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:45: undefined reference to `__gtsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:48: undefined reference to `__gtsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:51: undefined reference to `__subsf3'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:52: undefined reference to `__subsf3'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:52: undefined reference to `__gtsf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:54: undefined reference to `__floatunsisf'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:56: undefined reference to `__floatunsisf'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:57: undefined reference to `__floatsisf'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:57: undefined reference to `__lesf2'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:56: undefined reference to `__floatunsisf'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:56: undefined reference to `__floatunsisf'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:62: undefined reference to `__floatsisf'
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /home/riscv-vp/riscv-vp/sw/simple-display/libDisplay.cpp:62: undefined reference to `__lesf2'
collect2: error: ld returned 1 exit status
make: *** [Makefile:2: all] Error 1
Cirromulus commented 1 year ago

It seems that the compiler tries to build a hard-float executable, while the libraries are (correctly) built with soft-float support. Also, your output seems a bit off, I reformatted it for multiline support (`` instead of a single), but the newlines are missing. Perhaps you could re-copy the output.

TommyMurphyTM1234 commented 1 year ago

Is this of any relevance?

Cirromulus commented 1 year ago

Yes. In summary, you probably just did not update your PATH to actually use this newly built toolchain which will have soft-float libraries.

hvishu commented 1 year ago

It seems that the compiler tries to build a hard-float executable, while the libraries are (correctly) built with soft-float support. Also, your output seems a bit off, I reformatted it for multiline support (`` instead of a single), but the newlines are missing. Perhaps you could re-copy the output.

Updated the output.

I didn't try to play around much, and just followed the steps mentioned in the repo link "https://github.com/agra-uni-bremen/riscv-vp" under section "Alternative Setup: Docker"

You are right, from looking at (https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), all the undefined references seems to be from the soft float library which compiler is not able to find.

Also, I completely don't understand from where did the docker took the cross compilers from.

Some other experiments, I did

riscv32-unknown-elf-g++ -g -std=c++14 main.cpp libDisplay.cpp -o main -march=rv32ima -mabi=ilp32 --> fails

riscv32-unknown-elf-g++ -g -std=c++14 main.cpp libDisplay.cpp -o main -march=rv32im -mabi=ilp32  --> success

(change is arch=rv32im instead of rv32ima)
TommyMurphyTM1234 commented 1 year ago

As mentioned above, you most likely are picking to the wrong toolchain (the one installed by default in the Docker image in /usr/riscv-none-elf/bin) and didn't configure your PATH to pick up the one required here.

What do the following report?

which riscv32-unknown-elf-gcc
riscv32-unknown-elf-gcc -print-multi-lib
riscv32-unknown-elf-gcc --dumpspecs
echo $PATH
hvishu commented 1 year ago

@TommyMurphyTM1234, thank you for looking into this.

The docker settings is done by the file from the repo itself "https://github.com/agra-uni-bremen/riscv-vp/blob/master/Dockerfile". content being below.

FROM alpine:3.16

RUN apk update && apk add --no-cache  build-base cmake boost-dev \
    systemc-dev systemc-static git newlib-riscv-none-elf gdb-multiarch

# Examples expect riscv32-unknown-* compiler triplet.
# TODO: Find a better way to deal with this problem.
RUN sh -c 'ln -s $(command -v riscv-none-elf-gcc) /usr/local/bin/riscv32-unknown-elf-gcc && \
           ln -s $(command -v riscv-none-elf-g++) /usr/local/bin/riscv32-unknown-elf-g++ && \
           ln -s $(command -v riscv-none-elf-as) /usr/local/bin/riscv32-unknown-elf-as && \
           ln -s $(command -v riscv-none-elf-ld) /usr/local/bin/riscv32-unknown-elf-ld'

RUN adduser -G users -g 'RISC-V VP User' -D riscv-vp
ADD --chown=riscv-vp:users . /home/riscv-vp/riscv-vp
RUN su - riscv-vp -c 'make -C /home/riscv-vp/riscv-vp'
RUN su - riscv-vp -c 'echo export PATH=\"$PATH:/home/riscv-vp/riscv-vp/vp/build/bin\" >> /home/riscv-vp/.profile'
CMD su - riscv-vp

Below are the outputs of the commands you asked for

**which riscv32-unknown-elf-gcc**
**echo $PATH**
c7696f6fc366:~/riscv-vp/sw/simple-display$ which riscv32-unknown-elf-gcc
/usr/local/bin/riscv32-unknown-elf-gcc
c7696f6fc366:~/riscv-vp/sw/simple-display$ ls -la /usr/local/bin/riscv32-unknown-elf-gcc
lrwxrwxrwx    1 root     root            27 Dec 21 14:18 /usr/local/bin/riscv32-unknown-elf-gcc -> /usr/bin/riscv-none-elf-gcc
c7696f6fc366:~/riscv-vp/sw/simple-display$ 
c7696f6fc366:~/riscv-vp/sw/simple-display$ echo $PATH
/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/home/riscv-vp/riscv-vp/vp/build/bin
c7696f6fc366:~/riscv-vp/sw/simple-display$

**riscv32-unknown-elf-gcc -print-multi-lib**
c7696f6fc366:~/riscv-vp/sw/simple-display$ riscv32-unknown-elf-gcc --print-multi-lib
.;
rv32i/ilp32;@march=rv32i@mabi=ilp32
rv32im/ilp32;@march=rv32im@mabi=ilp32
rv32iac/ilp32;@march=rv32iac@mabi=ilp32
rv32imac/ilp32;@march=rv32imac@mabi=ilp32
rv32imafc/ilp32f;@march=rv32imafc@mabi=ilp32f
rv64imac/lp64;@march=rv64imac@mabi=lp64
rv64imafdc/lp64d;@march=rv64imafdc@mabi=lp64d
c7696f6fc366:~/riscv-vp/sw/simple-display$

**riscv32-unknown-elf-gcc --dumpspecs**

c7696f6fc366:~/riscv-vp/sw/simple-display$ riscv32-unknown-elf-gcc -dumpspecs
*asm:
--traditional-format %(subtarget_asm_debugging_spec) %{fpie|fPIE|fpic|fPIC:-fpic} %{march=*} %{mabi=*} %{mbig-endian} %{mlittle-endian} %(subtarget_asm_spec)%{misa-spec=*}

*asm_debug:
%{g*:%{%:debug-level-gt(0):}} %{fdebug-prefix-map=*:--debug-prefix-map %*}

*asm_debug_option:
%{g*:%{%:debug-level-gt(0):%{%:dwarf-version-gt(4):--gdwarf-5 ;%:dwarf-version-gt(3):--gdwarf-4 ;%:dwarf-version-gt(2):--gdwarf-3 ;:--gdwarf2 }}}

*asm_final:
%{gsplit-dwarf: 
       objcopy --extract-dwo     %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O}    %b.dwo 
       objcopy --strip-dwo   %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O}     }

*asm_options:
%{-target-help:%:print-asm-header()} %{v} %{w:-W} %{I*} %(asm_debug_option) %{gz|gz=zlib:--compress-debug-sections=zlib} %{gz=none:--compress-debug-sections=none} %{gz=zlib-gnu:--compress-debug-sections=zlib-gnu} %a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}

*invoke_as:
%{!fwpa*:   %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}   %{!S:-o %|.s |
 as %(asm_options) %m.s %A }  }

*cpp:

*cpp_options:
%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w} %{f*} %{g*:%{%:debug-level-gt(0):%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*} %{undef} %{save-temps*:-fpch-preprocess}

*cpp_debug_options:
%<dumpdir %<dumpbase %<dumpbase-ext %{d*} %:dumps()

*cpp_unique_options:
%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I %{MD:-MD %{!o:%b.d}%{o*:%.d%*}} %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}} %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{Mmodules} %{Mno-modules} %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}} %{remap} %{%:debug-level-gt(2):-dD} %{!iplugindir*:%{fplugin*:%:find-plugindir()}} %{H} %C %{D*&U*&A*} %{i*} %Z %i %{E|M|MM:%W{o*}}

*trad_capable_cpp:
cc1 -E %{traditional|traditional-cpp:-traditional-cpp}

*cc1:

*cc1_options:
%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}} %{!iplugindir*:%{fplugin*:%:find-plugindir()}} %1 %{!Q:-quiet} %(cpp_debug_options) %{m*} %{aux-info*} %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs} %{v:-version} %{pg:-p} %{p} %{f*} %{undef} %{Qn:-fno-ident} %{Qy:} %{-help:--help} %{-target-help:--target-help} %{-version:--version} %{-help=*:--help=%*} %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}} %{fsyntax-only:-o %j} %{-param*} %{coverage:-fprofile-arcs -ftest-coverage} %{fprofile-arcs|fprofile-generate*|coverage:   %{!fprofile-update=single:     %{pthread:-fprofile-update=prefer-atomic}}}

*cc1plus:

*link_gcc_c_sequence:
%G %{!nolibc:%L %G}

*link_ssp:
%{fstack-protector|fstack-protector-all|fstack-protector-strong|fstack-protector-explicit:}

*endfile:
crtend%O%s

*link:
-melf%{march=rv32*:32}%{march=rv64*:64}lriscv %{mno-relax:--no-relax} %{mbig-endian:-EB} %{mlittle-endian:-EL} %{shared}

*lib:
--start-group -lc %{!specs=nosys.specs:-lgloss} --end-group

*link_gomp:

*libgcc:
-lgcc

*startfile:
crt0%O%s crtbegin%O%s

*cross_compile:
1

*version:
11.2.0

*multilib:
. !march=rv32i !march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc !mabi=ilp32 !mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv32i/ilp32 march=rv32i !march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc mabi=ilp32 !mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv32im/ilp32 !march=rv32i !march=rv32ic march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc mabi=ilp32 !mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv32iac/ilp32 !march=rv32i !march=rv32ic !march=rv32im !march=rv32imc march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc mabi=ilp32 !mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv32imac/ilp32 !march=rv32i !march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc mabi=ilp32 !mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv32imafc/ilp32f !march=rv32i !march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc !mabi=ilp32 mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv64imac/lp64 !march=rv32i !march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc march=rv64imac !march=rv64imafdc !march=rv64gc !mabi=ilp32 !mabi=ilp32f mabi=lp64 !mabi=lp64d;rv64imafdc/lp64d !march=rv32i !march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac march=rv64imafdc !march=rv64gc !mabi=ilp32 !mabi=ilp32f !mabi=lp64 mabi=lp64d;

*multilib_defaults:
march=rv32gc mabi=ilp32d

*multilib_extra:

*multilib_matches:
march=rv32i march=rv32i;march=rv32ic march=rv32ic;march=rv32im march=rv32im;march=rv32imc march=rv32imc;march=rv32iac march=rv32iac;march=rv32imac march=rv32imac;march=rv32imafc march=rv32imafc;march=rv32imafdc march=rv32imafdc;march=rv32gc march=rv32gc;march=rv64imac march=rv64imac;march=rv64imafdc march=rv64imafdc;march=rv64gc march=rv64gc;mabi=ilp32 mabi=ilp32;mabi=ilp32f mabi=ilp32f;mabi=lp64 mabi=lp64;mabi=lp64d mabi=lp64d;

*multilib_exclusions:

*multilib_options:
march=rv32i/march=rv32ic/march=rv32im/march=rv32imc/march=rv32iac/march=rv32imac/march=rv32imafc/march=rv32imafdc/march=rv32gc/march=rv64imac/march=rv64imafdc/march=rv64gc mabi=ilp32/mabi=ilp32f/mabi=lp64/mabi=lp64d

*multilib_reuse:
rv32i/ilp32 !march=rv32i march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc mabi=ilp32 !mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv32im/ilp32 !march=rv32i !march=rv32ic !march=rv32im march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc mabi=ilp32 !mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv32imafc/ilp32f !march=rv32i !march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc !mabi=ilp32 mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv32imafc/ilp32f !march=rv32i !march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc march=rv32gc !march=rv64imac !march=rv64imafdc !march=rv64gc !mabi=ilp32 mabi=ilp32f !mabi=lp64 !mabi=lp64d;rv64imafdc/lp64d !march=rv32i !march=rv32ic !march=rv32im !march=rv32imc !march=rv32iac !march=rv32imac !march=rv32imafc !march=rv32imafdc !march=rv32gc !march=rv64imac !march=rv64imafdc march=rv64gc !mabi=ilp32 !mabi=ilp32f !mabi=lp64 mabi=lp64d;

*linker:
collect2

*linker_plugin_file:

*lto_wrapper:

*lto_gcc:

*post_link:

*link_libgcc:
%D

*md_exec_prefix:

*md_startfile_prefix:

*md_startfile_prefix_1:

*startfile_prefix_spec:

*sysroot_spec:
--sysroot=%R

*sysroot_suffix_spec:

*sysroot_hdrs_suffix_spec:

*self_spec:

*link_command:
%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:    %(linker) %{!fno-use-linker-plugin:%{!fno-lto:     -plugin %(linker_plugin_file)     -plugin-opt=%(lto_wrapper)     -plugin-opt=-fresolution=%u.res         %{flinker-output=*:-plugin-opt=-linker-output-known}     %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}}     }}%{flto|flto=*:%<fcompare-debug*}     %{flto} %{fno-lto} %{flto=*} %l %{static|shared|r:;pie:-pie} %{fuse-ld=*:-fuse-ld=%*}  %{gz|gz=zlib:--compress-debug-sections=zlib} %{gz=none:--compress-debug-sections=none} %{gz=zlib-gnu:--compress-debug-sections=zlib-gnu} %X %{o*} %{e*} %{N} %{n} %{r}    %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}}     %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) %{fvtable-verify=none:} %{fvtable-verify=std:   %e-fvtable-verify=std is not supported in this configuration} %{fvtable-verify=preinit:   %e-fvtable-verify=preinit is not supported in this configuration} %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):}     %{%:sanitize(hwaddress):}     %{%:sanitize(thread):}     %{%:sanitize(leak):}}}} %o      %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):  %:include(libgomp.spec)%(link_gomp)}    %{fgnu-tm:%:include(libitm.spec)%(link_itm)}    %(mflib)  %{fsplit-stack: --wrap=pthread_create}    %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):%{static-libasan:-Bstatic} -lasan %{static-libasan:-Bdynamic} %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)}    %{static:%ecannot specify -static with -fsanitize=address}}    %{%:sanitize(hwaddress):%{static-libhwasan:-Bstatic} -lhwasan %{static-libhwasan:-Bdynamic} %{static-libhwasan|static:%:include(libsanitizer.spec)%(link_libhwasan)}   %{static:%ecannot specify -static with -fsanitize=hwaddress}}    %{%:sanitize(thread):%{static-libtsan:-Bstatic} -ltsan %{static-libtsan:-Bdynamic} %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}    %{static:%ecannot specify -static with -fsanitize=thread}}    %{%:sanitize(undefined):%{static-libubsan:-Bstatic} -lubsan %{static-libubsan:-Bdynamic} %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}}    %{%:sanitize(leak):%{static-liblsan:-Bstatic} -llsan %{static-liblsan:-Bdynamic} %{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}}}}}     %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}    %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*}  
%(post_link) }}}}}}
TommyMurphyTM1234 commented 1 year ago

So that confirms that you're picking up the "system" RISC-V toolchain configured for rv32gc/ilp32d and not the toolchain that you built for these tests because you have not configured your PATH to use the latter.

hvishu commented 1 year ago

So that confirms that you're picking up the "system" RISC-V toolchain configured for rv32gc/ilp32d and not the toolchain that you built for these tests because you have not configured your PATH to use the latter.

@TommyMurphyTM1234
You are right.
I see from the docker build log below. Seems the docker image is created by using the soft links to the pre-built binaries taken from Alpine:3.16.

To correct this I might need to few changes on how the docker image built. Will try that. Thank you very much for the details.

(90/97) Installing pcre2 (10.40-r0)
(91/97) Installing git (2.36.3-r0)
(92/97) Installing binutils-riscv-none-elf (2.38-r0)
(93/97) Installing gcc-riscv-none-elf (11.2.0-r2)
(94/97) Installing newlib-riscv-none-elf (4.2.0.20211231-r1)
(95/97) Installing systemc (2.3.3-r1)
(96/97) Installing systemc-dev (2.3.3-r1)
(97/97) Installing systemc-static (2.3.3-r1)
Executing busybox-1.35.0-r17.trigger
Executing ca-certificates-20220614-r0.trigger
OK: 801 MiB in 110 packages
Removing intermediate container ab16ded9de04
 ---> d9f9ee264777
Step 3/8 : RUN sh -c 'ln -s $(command -v riscv-none-elf-gcc) /usr/local/bin/riscv32-unknown-elf-gcc &&            ln -s $(command -v riscv-none-elf-g++) /usr/local/bin/riscv32-unknown-elf-g++ &&            ln -s $(command -v riscv-none-elf-as) /usr/local/bin/riscv32-unknown-elf-as &&            ln -s $(command -v riscv-none-elf-ld) /usr/local/bin/riscv32-unknown-elf-ld'
 ---> Running in 775e5f989dda
Removing intermediate container 775e5f989dda
 ---> ef25a2b3e507

I am trying to build a linux image and it on the RISC-V virtual platform, I have built using this repo. Right now with this repo, able to build and run small examples. Do you happen to know any guide/tutorial that can be used for that?

TommyMurphyTM1234 commented 1 year ago

Why don't you just set your PATH so that it picks to the RISC-V toolchain required by this project instead of the "system" one?

hvishu commented 1 year ago

Why don't you just set your PATH so that it picks to the RISC-V toolchain required by this project instead of the "system" one?

I tried that. Tried to use the machine built toolchain in the docker environment, it doesn't work, same is true Vice versa. I checked the format and found they are different for the OS/ABI version they have built for (check below).

FYI, I found out that on docker using "-march=rv32im" instead of "-march=rv32ima" solves the problem. I understand this is not the final solution but due to time constraints, I will not be able to spend time on this. I am now concentrating on using the machine build where I don't see any problem as of now.

If the owner of this repo is interested, I can further check any changes suggested by them and confirm it works.

$ readelf -h ./riscv32-unknown-elf-g++_docker 
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x404cad
  Start of program headers:          64 (bytes into file)
  Start of section headers:          1540000 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         13
  Size of section headers:           64 (bytes)
  Number of section headers:         28
  Section header string table index: 27
$ readelf -h ./riscv32-unknown-elf-g++_machine
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - GNU
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x409b30
  Start of program headers:          64 (bytes into file)
  Start of section headers:          6583600 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         14
  Size of section headers:           64 (bytes)
  Number of section headers:         45
  Section header string table index: 44
TommyMurphyTM1234 commented 1 year ago

I followed the Docker instructions and was able to reproduce your problem.

The issue is that the Makefile for the simple-display example calls the compiler with -march=rv32ima -mabi=ilp32:

all : main.cpp libDisplay.cpp
        riscv32-unknown-elf-g++ -g -std=c++14 main.cpp libDisplay.cpp -o main -march=rv32ima -mabi=ilp32

But the pre-installed RISC-V compiler toolchain only supports the following multilibs:

riscv32-unknown-elf-gcc -print-multi-lib
.; /* This refers to the default arch/abi of rv32gc/ilp32d */
rv32i/ilp32;@march=rv32i@mabi=ilp32
rv32im/ilp32;@march=rv32im@mabi=ilp32
rv32iac/ilp32;@march=rv32iac@mabi=ilp32
rv32imac/ilp32;@march=rv32imac@mabi=ilp32
rv32imafc/ilp32f;@march=rv32imafc@mabi=ilp32f
rv64imac/lp64;@march=rv64imac@mabi=lp64
rv64imafdc/lp64d;@march=rv64imafdc@mabi=lp64d

The list of multilibs does not include rv32ima/ilp32 so, when -march=rv32ima -mabi=ilp32 is specified and it comes to linking the toolchain falls back to the toolchain default arch/abi of rv32gc/ilp32d (aka rv32imafdc/ilp32d). rv32ima/ilp32 uses soft float support while rv32gc/ilp32d uses hard float support and this is why the mismatch arises at link time.

Seems to me that the pre-installed toolchain in the Docker container should add rv32ima/ilp32 multilib support or the examples should only use arch/abi tuples that are already supported by the pre-installed toolchain's list of multilibs.

hvishu commented 1 year ago

I followed the Docker instructions and was able to reproduce your problem.

The issue is that the Makefile for the simple-display example calls the compiler with -march=rv32ima -mabi=ilp32:

all : main.cpp libDisplay.cpp
        riscv32-unknown-elf-g++ -g -std=c++14 main.cpp libDisplay.cpp -o main -march=rv32ima -mabi=ilp32

But the pre-installed RISC-V compiler toolchain only supports the following multilibs:

riscv32-unknown-elf-gcc -print-multi-lib
.; /* This refers to the default arch/abi of rv32gc/ilp32d */
rv32i/ilp32;@march=rv32i@mabi=ilp32
rv32im/ilp32;@march=rv32im@mabi=ilp32
rv32iac/ilp32;@march=rv32iac@mabi=ilp32
rv32imac/ilp32;@march=rv32imac@mabi=ilp32
rv32imafc/ilp32f;@march=rv32imafc@mabi=ilp32f
rv64imac/lp64;@march=rv64imac@mabi=lp64
rv64imafdc/lp64d;@march=rv64imafdc@mabi=lp64d

The list of multilibs does not include rv32ima/ilp32 so, when -march=rv32ima -mabi=ilp32 is specified and it comes to linking the toolchain falls back to the toolchain default arch/abi of rv32gc/ilp32d (aka rv32imafdc/ilp32d). rv32ima/ilp32 uses soft float support while rv32gc/ilp32d uses hard float support and this is why the mismatch arises at link time.

Seems to me that the pre-installed toolchain in the Docker container should add rv32ima/ilp32 multilib support or the examples should only use arch/abi tuples that are already supported by the pre-installed toolchain's list of multilibs.

Thanks for the analyzing and finding the root problem.
So this is the reason, why "-march=rv32im" would work, where as "-march=rv32ima" fails.

TommyMurphyTM1234 commented 1 year ago

Thanks for the analyzing and finding the root problem. So this is the reason, why "-march=rv32im" would work, where as "-march=rv32ima" fails.

Correct. The pre-installed toolchain is rv32gc/ilp32d by default but also supports other arch/abi targets, including rv32im/ilp32, via multilibs. But it does not include multilib support for rv32ima/ilp32.

When the RISC-V bare metal/newlib toolchain is configured with --enable-multilib before being built it supports a default set of multilibs as specified here:

The list does not include rv32ima/ilp32. To override this default set of multilibs and specify or add rv32ima/ilp32 requires the use of the --with-multilib-generator option at configuration time:

nmeum commented 1 year ago

Seems to me that the pre-installed toolchain in the Docker container should add rv32ima/ilp32 multilib support or the examples should only use arch/abi tuples that are already supported by the pre-installed toolchain's list of multilibs.

We have just upgraded the Docker image and our CI infrastructure to Alpine Linux Edge which supports ~23 additional RISC-V multilib targets. With this new Docker image, it is possible to also build sw/simple-display.

$ riscv-none-elf-gcc --print-multi-lib
rv32e/ilp32e;@march=rv32e@mabi=ilp32e
rv32ea/ilp32e;@march=rv32ea@mabi=ilp32e
rv32em/ilp32e;@march=rv32em@mabi=ilp32e
rv32eac/ilp32e;@march=rv32eac@mabi=ilp32e
rv32emac/ilp32e;@march=rv32emac@mabi=ilp32e
rv32i/ilp32;@march=rv32i@mabi=ilp32
rv32ia/ilp32;@march=rv32ia@mabi=ilp32
rv32im/ilp32;@march=rv32im@mabi=ilp32
rv32if_zicsr/ilp32f;@march=rv32if_zicsr@mabi=ilp32f
rv32ifd_zicsr/ilp32d;@march=rv32ifd_zicsr@mabi=ilp32d
rv32iaf_zicsr/ilp32f;@march=rv32iaf_zicsr@mabi=ilp32f
rv32iafd_zicsr/ilp32d;@march=rv32iafd_zicsr@mabi=ilp32d
rv32imf_zicsr/ilp32f;@march=rv32imf_zicsr@mabi=ilp32f
rv32imfd_zicsr/ilp32d;@march=rv32imfd_zicsr@mabi=ilp32d
rv32iac/ilp32;@march=rv32iac@mabi=ilp32
rv32imac/ilp32;@march=rv32imac@mabi=ilp32
rv32imafc_zicsr/ilp32f;@march=rv32imafc_zicsr@mabi=ilp32f
rv32imafdc_zicsr/ilp32d;@march=rv32imafdc_zicsr@mabi=ilp32d
rv64i/lp64;@march=rv64i@mabi=lp64
rv64ia/lp64;@march=rv64ia@mabi=lp64
rv64im/lp64;@march=rv64im@mabi=lp64
rv64if_zicsr/lp64f;@march=rv64if_zicsr@mabi=lp64f
rv64ifd_zicsr/lp64d;@march=rv64ifd_zicsr@mabi=lp64d
rv64iaf_zicsr/lp64f;@march=rv64iaf_zicsr@mabi=lp64f
rv64iafd_zicsr/lp64d;@march=rv64iafd_zicsr@mabi=lp64d
rv64imf_zicsr/lp64f;@march=rv64imf_zicsr@mabi=lp64f
rv64iac/lp64;@march=rv64iac@mabi=lp64
rv64imac/lp64;@march=rv64imac@mabi=lp64
rv64imafc_zicsr/lp64f;@march=rv64imafc_zicsr@mabi=lp64f
rv64imafdc_zicsr/lp64d;@march=rv64imafdc_zicsr@mabi=lp64d
TommyMurphyTM1234 commented 1 year ago

I don't understand how it works for you since that multilib list still doesn't include rv32ima/ilp32.

nmeum commented 1 year ago

I don't understand how it works for you since that multilib list still doesn't include rv32ima/ilp32.

GCC has this handy feature called MULTILIB_REUSE:

Sometimes it is desirable to reuse one existing multilib for different sets of options. Such kind of reuse can minimize the number of multilib variants.

Given that the multilib variant list posted above includes rv32ia/ilp32;@march=rv32ia@mabi=ilp32 and that any rv32ia/ilp32 program is a valid rv32ima/ilp32 program GCC will include an appropriate MULTILIB_REUSE rule along the lines of:

MULTILIB_REUSE = march.rv32ia/mabi.ilp32=march.rv32ima/mabi.ilp32
TommyMurphyTM1234 commented 1 year ago

Thanks. The multilib reuse details were not contained in the earlier post and we don't know for sure that the reuse scenario that you mention applies to the toolchain in question.

But, even if it does, then reusing the rv32ia/ilp32 libraries/startup code when targeting rv32ima/ilp32 means that those libraries/startup code will not exploit the M integer multiplication and division extension supported by the actual hardware. This may or may not be acceptable/desirable and may lead to less than optimal code/performance.

nmeum commented 1 year ago

But, even if it does, then reusing the rv32ia/ilp32 libraries/startup code when targeting rv32ima/ilp32 means that those libraries/startup code will not exploit the M integer multiplication […]

Correct, but this is not an issue for this particular use case.