Hi!
Does somebody know, why the GNU ld developers disabled shared library and PIE support on RISCV bare metal targets (riscv64-none-elf)? I'm wondering why PIE is enabled on ARM bare metal targets, but not on RISCV.
I have enabled it in the sources from GNU ld, but currently not tested. The reason was I had big troubles with building Newlib with GCC with the riscv64-linux-gnu configuration. Doesn't worked, because the compilation from libgcc always failed (missing sys/ucontext.h header in libgcc/unwind-dw2.c). Tried also different configuration switches link --disable-libunwind and --disable-libunwind-exceptions, but no success. So I modified GNU ld...
GNU ld for RISCV bare metal targets without -shared/-pie support
-
Octocontrabass
- Member

- Posts: 6251
- Joined: Mon Mar 25, 2013 7:01 pm
Re: GNU ld for RISCV bare metal targets without -shared/-pie support
Why are those enabled for ARM? Bare metal targets can't support shared libraries or position-independent executables, those things depend on the C standard library and the C standard library depends on the OS.
Why are you trying to build Newlib? It'll be easier to figure out the "correct" way to do things if we know what you're trying to do.
Why are you trying to build Newlib? It'll be easier to figure out the "correct" way to do things if we know what you're trying to do.
-
toasterdev
- Posts: 1
- Joined: Thu Sep 17, 2026 4:21 am
Re: GNU ld for RISCV bare metal targets without -shared/-pie support
-elf toolchains don't need a modified ld for PIE anymore. binutils had a patch in 2024 to remove the RISC-V -elf restriction on -shared and -pie.
the sys/ucontext.h error is from using riscv64-linux-gnu. that's the Linux target, whereas riscv64-unknown-elf is intended for bare-metal/Newlib setups.
also, PIE itself doesn't need a C library. ld normally expects a dynamic linker to handle the runtime relocations, but a custom loader can handle those relocations itself.
the sys/ucontext.h error is from using riscv64-linux-gnu. that's the Linux target, whereas riscv64-unknown-elf is intended for bare-metal/Newlib setups.
also, PIE itself doesn't need a C library. ld normally expects a dynamic linker to handle the runtime relocations, but a custom loader can handle those relocations itself.
Re: GNU ld for RISCV bare metal targets without -shared/-pie support
And static PIE has the dynamic linker integrated into the executable. Because for static PIE, you really only need to support relative relocations, so that's a single pass over the relocation table and you're done.toasterdev wrote: ↑Thu Sep 17, 2026 6:25 am also, PIE itself doesn't need a C library. ld normally expects a dynamic linker to handle the runtime relocations, but a custom loader can handle those relocations itself.
Carpe diem!