Skip to content
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

build error #240

Open
dragonware-com opened this issue Sep 1, 2018 · 38 comments
Open

build error #240

dragonware-com opened this issue Sep 1, 2018 · 38 comments
Assignees

Comments

@dragonware-com
Copy link

So I built the riscv-gnu-toolchain without any problem (https://github.com/pulp-platform/pulp-riscv-gnu-toolchain), however, cmake_configure.zeroriscy.gcc.sh execution has some problems:

  1. it says -m32 is not supported. So I removed the -m32 in cmake_configure.zeroriscy.gcc.sh. Then it has the second problem:

  2. riscv32-unknown-elf/bin/ld: cannot open linker script file riscv.ld: No such file or directory

@dragonware-com
Copy link
Author

The the fundamental problem I figured out is related to cmake.
When cmake is probing the compiler, it tries to compile a very simple code. However, for some reason, cmake is not using CMAKE_EXE_LINKER_FLAGS specified in the CMakeLists.txt. Maybe it is caused by the way the script is calling cmake: the script used -DCMAKE_C_FLAGS on the command line, which makes cmake not using CMAKE_EXE_LINKER_FLAGS for linking? But then, the cmake compiler probing is a single "gcc" call, instead of a "gcc -c" followed by "ld".

One workaround is to modify the cmake_configure.zeroriscy.gcc.sh script to add the linker flags to the C_FLGAS in the script, but this is more like a hack.

Another idea is to somehow make the riscv gcc use a default linker script so that it passes compiler probing, but use user-specified flags during real compilation. However, the riscv-gcc toolchain I compiled from the pulp doesn't seem to have a default linker script thus failing the compiler probe.

Any ideas/comments?

@dragonware-com
Copy link
Author

After working around the -m32 and compiler probing problem, now there is another problem "make helloworld":

riscv32-unknown-elf/bin/ld: unrecognised emulation mode: elflriscv
Supported emulations: elf32lriscv elf64lriscv

@haugoug
Copy link
Member

haugoug commented Sep 4, 2018

pulp-riscv-gnu-toolchain cannot be used with the current pulpino cmake flow you have to use this compiler instead: https://github.com/pulp-platform/ri5cy_gnu_toolchain

@FrancescoConti
Copy link
Member

I believe the correct toolchain for PULPino is this one: https://github.com/pulp-platform/ri5cy_gnu_toolchain (the one you are using is more up to date and we use it for PULP / PULPissimo, and it is used by derivatives e.g. https://github.com/GreenWaves-Technologies/gap_sdk). However, I am assigning the issue to @haugoug who might know better.

@FrancescoConti
Copy link
Member

Whoops, @haugoug was too fast for me :)

@dragonware-com
Copy link
Author

That's good to know. Thanks for the replies!

@dragonware-com
Copy link
Author

Well, the problem with https://github.com/pulp-platform/ri5cy_gnu_toolchain is that it failed to build:

libtool: compile: gcc -DHAVE_CONFIG_H -I. -I/home/wsun/ri5cy_gnu_toolchain/build/src/binutils/bfd -I. -I/home/wsun/ri5cy_gnu_toolchain/build/src/binutils/bfd -I/home/wsun/ri5cy_gnu_toolchain/build/src/binutils/bfd/../include -DHAVE_riscv_elf32_vec -DHAVE_elf32_le_vec -DHAVE_elf32_be_vec -DHAVE_plugin_vec -DBINDIR="/home/wsun/ri5cy_gnu_toolchain/install/bin" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -g -O2 -MT elf32-riscv.lo -MD -MP -MF .deps/elf32-riscv.Tpo -c elf32-riscv.c -o elf32-riscv.o
/home/wsun/ri5cy_gnu_toolchain/build/src/binutils/bfd/elfxx-riscv.c:26:17: fatal error: bfd.h: No such file or directory
compilation terminated.
Makefile:1607: recipe for target 'elfxx-riscv.lo' failed
make[5]: *** [elfxx-riscv.lo] Error 1
make[5]: *** Waiting for unfinished jobs....
/home/wsun/ri5cy_gnu_toolchain/build/src/binutils/bfd/elfnn-riscv.c:28:17: fatal error: bfd.h: No such file or directory
compilation terminated.

@FrancescoConti FrancescoConti reopened this Sep 5, 2018
@mbolivar
Copy link

riscv32-unknown-elf/bin/ld: cannot open linker script file riscv.ld: No such file or directory

I'm running into the same problem trying to use this toolchain with CMake.

In particular, the project I'm working on uses a line like check_c_compiler_flag("" toolchain_is_ok) in CMake to test that the C compiler can build and link a basic file (src.c below, which just contains int main(void) { return 0; }). The result is the above error, as check_c_compiler_flag() does a "compiler probe" probably very similar to what was originally reported:

/home/mbolivar/bin/pulp-toolchain/bin/riscv32-unknown-elf-gcc   -Dtoolchain_is_ok -nostartfiles -nostdlib -isystem "/home/mbolivar/bin/pulp-toolchain/bin/../lib/gcc/riscv32-unknown-elf/7.1.1/include" -isystem "/home/mbolivar/bin/pulp-toolchain/bin/../lib/gcc/riscv32-unknown-elf/7.1.1/include-fixed" -Wl,--unresolved-symbols=ignore-in-object-files -o CMakeFiles/cmTC_68b99.dir/src.c.obj   -c src.c

/home/mbolivar/bin/pulp-toolchain/bin/riscv32-unknown-elf-gcc -Dtoolchain_is_ok -nostartfiles -nostdlib -isystem "/home/mbolivar/bin/pulp-toolchain/bin/../lib/gcc/riscv32-unknown-elf/7.1.1/include" -isystem "/home/mbolivar/bin/pulp-toolchain/bin/../lib/gcc/riscv32-unknown-elf/7.1.1/include-fixed" -Wl,--unresolved-symbols=ignore-in-object-files   CMakeFiles/cmTC_68b99.dir/src.c.obj  -o cmTC_68b99

Another idea is to somehow make the riscv gcc use a default linker script so that it passes compiler probing, but use user-specified flags during real compilation. However, the riscv-gcc toolchain I compiled from the pulp doesn't seem to have a default linker script thus failing the compiler probe.

@dragonware-com you wouldn't happen to have any patches doing this floating around, would you?

I tried just creating an empty riscv.ld in the temporary CMake build directory which is being used by check_c_compiler_flag and the build system was able to generate an executable, so I'm wondering if that's enough.

Well, the problem with https://github.com/pulp-platform/ri5cy_gnu_toolchain is that it failed to build:

I'm stuck on the same at this point. @FrancescoConti, @haugoug, any advice appreciated.

@zejiang0jason
Copy link

pulp-riscv-gnu-toolchain cannot be used with the current pulpino cmake flow you have to use this compiler instead: https://github.com/pulp-platform/ri5cy_gnu_toolchain

Hi @haugoug , as you said, pulp-riscv-gnu-toolchain cannot be used with the pulpino cmake flow. But the pulp-riscv-gnu-toolchain readme.md told that

This will use the multilib support to build the libraries for the various cores (riscy, zeroriscy and so on). The right libraries will be selected depending on which compiler options you use.

Does it mean that the pulp-riscv-gnu-toolchain supports pulpino cores with some cmake modification? Thank you very much.

@haugoug
Copy link
Member

haugoug commented Oct 30, 2018

Indeed pulp-riscv-gnu-toolchain should supports pulpino, this just requires a few modifications in the pulpino cmake flow.
It is probably better to make these modifications and use pulp-riscv-gnu-toolchain as ri5cy_gnu_toolchain is quite old.

@zejiang0jason
Copy link

Indeed pulp-riscv-gnu-toolchain should supports pulpino, this just requires a few modifications in the pulpino cmake flow.
It is probably better to make these modifications and use pulp-riscv-gnu-toolchain as ri5cy_gnu_toolchain is quite old.

Thank you very much, haugoug

@jasonchu024
Copy link

So I just come across exactly the same problem, ri5cy_gnu_toolchain is failed to build, pulp-riscv-gnu-toolchain can be built but it doesn't support pulpino. Could @haugoug suggest a fix to the cmake flow?

@mbolivar
Copy link

mbolivar commented Nov 5, 2018

The the fundamental problem I figured out is related to cmake.
When cmake is probing the compiler, it tries to compile a very simple code. However, for some reason, cmake is not using CMAKE_EXE_LINKER_FLAGS specified in the CMakeLists.txt. Maybe it is caused by the way the script is calling cmake: the script used -DCMAKE_C_FLAGS on the command line, which makes cmake not using CMAKE_EXE_LINKER_FLAGS for linking? But then, the cmake compiler probing is a single "gcc" call, instead of a "gcc -c" followed by "ld".

One workaround is to modify the cmake_configure.zeroriscy.gcc.sh script to add the linker flags to the C_FLGAS in the script, but this is more like a hack.

Another idea is to somehow make the riscv gcc use a default linker script so that it passes compiler probing, but use user-specified flags during real compilation. However, the riscv-gcc toolchain I compiled from the pulp doesn't seem to have a default linker script thus failing the compiler probe.

Any ideas/comments?

@dragonware-com I found a solution, by adding the following to my CMake files before doing the compiler probing:

set(CMAKE_REQUIRED_FLAGS -Wl,-dT=${CMAKE_CURRENT_LIST_DIR}/empty-file.ld)

The CMAKE_REQUIRED_FLAGS variable is exactly what you write about: it allows setting options for compiler probing only. It is not used during real compilation.

@mbolivar
Copy link

mbolivar commented Nov 5, 2018

(Note that you need to make an empty file named "empty-file.ld" in the directory containing your CMakeLists.txt for the above to work)

@dragonware-com
Copy link
Author

@haugoug Great! Thanks for the effort!

@mbolivar
Copy link

mbolivar commented Nov 6, 2018

@haugoug Great! Thanks for the effort!

I am not hagoug but you are welcome!

@dragonware-com
Copy link
Author

@mbolivar Sorry, thank you for the effort!

@jasonchu024
Copy link

set(CMAKE_REQUIRED_FLAGS -Wl,-dT=${CMAKE_CURRENT_LIST_DIR}/empty-file.ld)

@mbolivar, the issue remains on me, should I add this to the CMakeList.txt file before cmake version probing? Thanks.

@mbolivar
Copy link

mbolivar commented Nov 9, 2018

set(CMAKE_REQUIRED_FLAGS -Wl,-dT=${CMAKE_CURRENT_LIST_DIR}/empty-file.ld)

@mbolivar, the issue remains on me, should I add this to the CMakeList.txt file before cmake version probing? Thanks.

Hi @jasonchu024, I assume you are using a CMake function like check_c_compiler_flag() or some other function that calls check_c_source_compiles() as the "compiler probe" discussed in previous comments. In that case, yup, you will need to set this variable first. See https://cmake.org/cmake/help/latest/module/CheckCSourceCompiles.html#module:CheckCSourceCompiles for details.

@sofchet
Copy link

sofchet commented Nov 12, 2018

@mbolivar or @dragonware-com can you please specify where set(CMAKE_REQUIRED_FLAGS -Wl,-dT=${CMAKE_CURRENT_LIST_DIR}/empty-file.ld) shoud be added ?
I mean which cmake files are talking about ? I am a bit confused, like where these files ( or is it only one file ) is supposed to be located at ? the same thing for the CMakelist.txt, where is it located ?

Thanks

@mbolivar
Copy link

@sofchet I'm not sure how to answer your question unfortunately.

People's individual CMake projects are going to vary a lot. They may contain one or more CMakeLists.txt files to control the project build. There may be multiple projects being integrated into a parent build system in this way.

I've tried to clarify that if toolchain checks in functions like check_c_compiler_flag are the problem, they can be worked around as described above by using a dummy linker script. (If you already have a real linker script to use at this point in the build, so much the better, but the environment I'm working on can't figure out the real linker script until later in the build so I have to provide a dummy via -dT at this stage.)

See for example https://sourceware.org/binutils/docs/ld/Scripts.html for more information on linker scripts.

See the gcc manpage for details on -Wl and the ld manpage for details on -dT.

Good luck!

@mbolivar
Copy link

Hi --- I just thought I'd ping this issue again.

In my opinion, something is misconfigured with this ld. You can run riscv32-unknown-elf-ld --verbose and get a full linker script, so the tool knows what to do by default.

Forcing the user to create a riscv.ld seems like a bug then: all the information to do a default link is already available to the linker. If that file is missing, there should be no error.

@stefanct
Copy link

Hi,
thanks for some very useful hints in this report. Unfortunately, I am not able to get it working with current master (aka Pulpino_v2.1-367-g0cdfddd) though. My goal for now is to simply get sw/cmake_configure.riscv.gcc.sh working with pulp-platform/pulp-riscv-gnu-toolchain. I can confirm that riscv32-unknown-elf-ld --verbose outputs something that looks like a valid linker script. I have tried to modify the cmake call in the shell script to use a given linker script by setting -DCMAKE_C_FLAGS="-Wl,-dT=$(realpath ../empty-file.ld)".

With an empty linker script I get this as first error (when linking):

In function `_start':
(.text+0x8): undefined reference to `__global_pointer$'

(followed by _fbss and _end).

When I change the linker script to the output of riscv32-unknown-elf-ld --verbose I get

In function `.L0 ':
(.text+0x10): undefined reference to `_fbss'

(that is indeed not mentioned in the linker script). FWIW, I was creating the toolchain using --with-arch=rv32imc --with-cmodel=medlow --enable-multilib. No idea why this is different to the results of @mbolivar. :/

alexandru-porosanu-nxp added a commit to alexandru-porosanu-nxp/zephyr that referenced this issue Oct 18, 2019
Add a special target that's marked build_only so the BLE SW LL
implementation on VEGABoard is built daily. This helps ensuring
that it doesn't get inadvertedly broken by subsequent updates.
The name of the target is peripheral_hr_rv32m1_vega_ri5cy
and it can be run with the following command:

sanitycheck -v --all -p rv32m1_vega_ri5cy \
            -x=CMAKE_REQUIRED_FLAGS=-Wl,-dT=/dev/null \
            --test samples/bluetooth/peripheral_hr/\
              sample.bluetooth.peripheral_hr_rv32m1_vega_ri5cy

Note: The extra CMake flags are required due to this linker
      issue: pulp-platform/pulpino#240

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
@zejiang0jason
Copy link

Hi @stefanct ,

About the error:

In function `.L0 ':
(.text+0x10): undefined reference to `_fbss'

The symbol _fbss required by crt0.o is not defined in the *.ld file. After checking the newlib code,
https://github.com/pulp-platform/pulp-riscv-newlib/blob/1e52935101d096bb2e9381c7b131d6b976f0acd9/libgloss/riscv/crt0.S,
the _fbss is previously named _edata. I modified _fbss back to _edata, and rebuild the toolchain, the error disappears.

Another solution I think is, don't use the crt0.o, by adding build parameter -nostartfiles and using your own startup code.

@zejiang0jason
Copy link

Hi,

I found the issue about missing riscv.ld is because of the LINK_SPEC defined in https://github.com/pulp-platform/pulp-riscv-gcc/blob/daa865ea46d212dee71872cabd390f700ac2f0c4/gcc/config/riscv/elf.h

The flag %{!T:-dT riscv.ld} means if the T is not defined in link command, then use -dT riscv.ld. The detailed explanation could be found here. I removed this line and rebuild the toolchain, the issue disappears.

@sunil3690
Copy link

sunil3690 commented Oct 23, 2019 via email

@mbolivar
Copy link

The flag %{!T:-dT riscv.ld} means if the T is not defined in link command, then use -dT riscv.ld. The detailed explanation could be found here. I removed this line and rebuild the toolchain, the issue disappears.

Note that doing this would break the build for any users that rely on this file implicitly being used as the linker script. They would all have to update their build systems to use -T riscv.ld manually.

zejiang0jason added a commit to open-isa-rv32m1/rv32m1_gnu_toolchain_patch that referenced this issue Nov 1, 2019
 - The issue is pulp-platform/pulpino#240
 - The root cause is, `LINK_SPEC` defined `-dT riscv.ld`, which means
   that if the `T` is not defined in link command, then use `-dT riscv.ld`.
   The workaround is user define `-dT=${CMAKE_CURRENT_LIST_DIR}/empty-file.ld`
   to override the default setting.
 - This patch removes the flag, then the workaround is not necessary.

Signed-off-by: Jason Yu <zejiang.yu@nxp.com>
alexandru-porosanu-nxp added a commit to alexandru-porosanu-nxp/zephyr that referenced this issue Nov 8, 2019
Add a special target that's marked build_only so the BLE SW LL
implementation on VEGABoard is built daily. This helps ensuring
that it doesn't get inadvertedly broken by subsequent updates.
The name of the target is peripheral_hr_rv32m1_vega_ri5cy
and it can be run with the following command:

sanitycheck -v --all -p rv32m1_vega_ri5cy \
            -x=CMAKE_REQUIRED_FLAGS=-Wl,-dT=/dev/null \
            --test samples/bluetooth/peripheral_hr/\
              sample.bluetooth.peripheral_hr_rv32m1_vega_ri5cy

Note: The extra CMake flags are required if running with the official
      VEGABoard compiler, due to this linker issue:
      pulp-platform/pulpino#240

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
carlescufi pushed a commit to zephyrproject-rtos/zephyr that referenced this issue Nov 8, 2019
Add a special target that's marked build_only so the BLE SW LL
implementation on VEGABoard is built daily. This helps ensuring
that it doesn't get inadvertedly broken by subsequent updates.
The name of the target is peripheral_hr_rv32m1_vega_ri5cy
and it can be run with the following command:

sanitycheck -v --all -p rv32m1_vega_ri5cy \
            -x=CMAKE_REQUIRED_FLAGS=-Wl,-dT=/dev/null \
            --test samples/bluetooth/peripheral_hr/\
              sample.bluetooth.peripheral_hr_rv32m1_vega_ri5cy

Note: The extra CMake flags are required if running with the official
      VEGABoard compiler, due to this linker issue:
      pulp-platform/pulpino#240

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
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