TARGET riscv64-elf- vs riscv64-linux-

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
exo
Posts: 9
Joined: Fri Feb 03, 2023 4:53 am

TARGET riscv64-elf- vs riscv64-linux-

Post by exo »

What I'm trying to do is

- compile OpenSBI with u-boot as payload
- start QEMU with the previously compiled OpenSBI as BIOS, which should load u-boot
- use u-boot to load my own risc-v kernel from some partition (the partition is from a block device that I've created for QEMU)

I've build my gcc cross-compile toolchain with TARGET=riscv64-elf- but apparently u-boot doesn't compile with it. At some point during compilation I get this error

riscv64-elf-ld.bfd: warning: -z nocombreloc ignored
riscv64-elf-ld.bfd: -shared not supported
make[2]: *** [scripts/Makefile.lib:442: lib/efi_loader/helloworld_efi.so] Error 1
make[1]: *** [scripts/Makefile.build:398: lib/efi_loader] Error 2
make: *** [Makefile:1871: lib] Error 2

I've researched the issue and as far as I understand the riscv64-elf target is not supported, but riscv64-linux is. My question is what's the practical difference between the two targets?
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: TARGET riscv64-elf- vs riscv64-linux-

Post by nullplan »

exo wrote:I've researched the issue and as far as I understand the riscv64-elf target is not supported, but riscv64-linux is. My question is what's the practical difference between the two targets?
The -elf target does not associate with any OS, whereas -linux does. This has side-effects such as where GCC searches for the stack canary when compiling with -fstack-protector. In your case, you are noticing that it also fails to add a few linker scripts (that is all the -z options change, in the end), and it disables shared libraries. I presume that is because without an OS, there is nothing that can interpret relocation entries. Now, in your case there actually is, the UEFI runtime will do it for you. I don't know what the best solution here is. I usually just use a compiler that outputs PE directly for the purpose of compiling UEFI bootloaders. But that wouldn't work for the u-boot build system, since it clearly expects to create an ELF file and then objcopy it.
Carpe diem!
Post Reply