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

Compiling issue in linux #81

Open
bat52 opened this issue Nov 24, 2020 · 14 comments
Open

Compiling issue in linux #81

bat52 opened this issue Nov 24, 2020 · 14 comments
Labels
bug Something isn't working

Comments

@bat52
Copy link

bat52 commented Nov 24, 2020

Compiling on my ubuntu 20.04 fails.
It seems the components are compiled correctly, but the main is not compiled, nor found by the linker.
See the error below.

marco@Latitude-E6440:/media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi$ make use existing version.txt file LD build_out/bl602_demo_wifi.elf /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/lib/rv64imafdc/lp64d/crt0.o: in function.L0 ':
(.text+0x2e): undefined reference to main' collect2: error: ld returned 1 exit status make: *** [/media/marco/DATA/programming/riscv/bl_iot_sdk-master/make_scripts_riscv/project.mk:420: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi/build_out/bl602_demo_wifi.elf] Errore 1

@robertlipe
Copy link

robertlipe commented Nov 25, 2020

Missing main is a symptom, not the problem. The linker is being invoked to build an rv64 executable when this is an rv32 system. (It's confusing because the entire chain is called "riscv64" but the flags should be setting flags to build and link in 32-bit mode. The hint is the "...lib/rv64imacfd" part of the pathname.

run make V=1 and show us the lines leading up to that linker invocation. It will be called by collect2 which is called by the gcc front-end.

Do you have any environmental variables like CFLAGs or LDFLAGS that are polluting the build environment?

Do other directories build successfully for you?

Actually, I'm seeing that directory fail to build for a different reason, but the failure is ignored (!) and is covered up in the avalanche of jibber jabber of unnecessary recompilation (!!). But the invocation that matches what I think is failing for you starts:

riscv64-unknown-elf-gcc -march=rv32imfc -mabi=ilp32f -Wl,--cref -nostartfiles -Wl,--gc-sections -Wl,-static -Wl,--start-gr [ ... ]

Your failure is about what I'd expect if the -march -mabi flags were missing.

@gamelaster gamelaster added the bug Something isn't working label Nov 25, 2020
@gamelaster
Copy link
Member

Also, it's known that some examples are not possible to compile, although this one if I remember correctly should work fine.

@bat52
Copy link
Author

bat52 commented Nov 25, 2020

Thank you for the quick reply.
I found that indeed I had the LDFLAGS set, therefore after doing
unset LDFLAGS
the bl602_boot2 compiled flawlessly.

However, when going to the bl602_demo_wifi it still does not compile, with following errors

'make V=1
...
/media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/components/bl602/bl602_wifi/lib/libbl602_wifi.a(cfg_api.o): in function cfg_api_element_set': /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:91: undefined reference to _ld_bl_static_cfg_entry_start'
/media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:91: undefined reference to _ld_bl_static_cfg_entry_end' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:164: undefined reference to _ld_bl_static_cfg_entry_start'
/media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:167: undefined reference to _ld_bl_static_cfg_entry_end' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/components/bl602/bl602_wifi/lib/libbl602_wifi.a(cfg_task.o): in function dump_cfg_entries':
/home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:24: undefined reference to _ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:28: undefined reference to _ld_bl_static_cfg_entry_end'
/media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:24: undefined reference to _ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:27: undefined reference to _ld_bl_static_cfg_entry_end'
collect2: error: ld returned 1 exit status
make: *** [/media/marco/DATA/programming/riscv/bl_iot_sdk-master/make_scripts_riscv/project.mk:420: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi/build_out/bl602_demo_wifi.elf] Errore 1
'

@robertlipe
Copy link

robertlipe commented Nov 25, 2020 via email

@bat52
Copy link
Author

bat52 commented Nov 25, 2020

Thank you Robert for your help and comment.
Do you mean that this example does not work even in the original SDK ?

@robertlipe
Copy link

robertlipe commented Nov 25, 2020 via email

@robertlipe
Copy link

I just pulled the Boufallou tree and tried to build demo_wifi. It fails in almost the same way[1].

I then did a git checkout ee4a10b to revert to their first public release and it failed in the identical way.

I have no reason to think this is a Mac-only thing (wait, @bat52 is on Linux) but it's my suspicion this directory has never built in a publicly released version.

As an aside, @bat52, do I know you with a slightly different name?

[1] Why "almost"? Because Bouffalo accepted a commit today that broke the tree in a slightly overlapping way. :-/ See bouffalolab#18. It's awesome debugging two trees that are broken in three different ways.

@bat52
Copy link
Author

bat52 commented Nov 26, 2020

Thank you for your comments @robertlipe !

> As an aside, @bat52, do I know you with a slightly different name?
I do not think I have ever known you before this discussion... but nice to meet you! :-)

@gamelaster
Copy link
Member

"_ld_bl_static_cfg_entry_start" happens when you compile without CONFIG_LINK_ROM=1

@bat52
Copy link
Author

bat52 commented Nov 28, 2020

Thank you for the comment @gamelaster.
I have tried compiling again after calling

export CONFIG_LINK_ROM=1

but I still get the linker error below.
What am I doing wrong?

marco@Latitude-E6440:/media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi$ make CONFIG_LINK_ROM=1 use existing version.txt file LD build_out/bl602_demo_wifi.elf /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/lib/rv64imafdc/lp64d/crt0.o: in function .L0 ':
(.text+0x2e): undefined reference to main' collect2: error: ld returned 1 exit status make: *** [/media/marco/DATA/programming/riscv/bl_iot_sdk-master/make_scripts_riscv/project.mk:420: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi/build_out/bl602_demo_wifi.elf] Errore 1

@gamelaster
Copy link
Member

Hi @bat52
Did you cleaned the project before compiling?

@bat52
Copy link
Author

bat52 commented Nov 28, 2020 via email

@suculent
Copy link

suculent commented Dec 3, 2020

I've stumbled upon the same issue on MacOS as well, @bat52. Make sure to make clean after changing the CONFIG_LINK_ROM variable.

  1. My build returned same error, verified that CPPFLAGS and LDFLAGS are clean.
  2. I've set the export CONFIG_LINK_ROM=1 but forgot to clean!
  3. Build returned same error.
    4. make clean && export CONFIG_LINK_ROM=1 && ./genromap and voilá it works.

@bat52
Copy link
Author

bat52 commented Dec 5, 2020

thank you @suculent , it ended up working as you said.
It was not clear to me I should have used genromap, and indeed I had LDFLAGS still defined in my environment.
cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants