binutils Newspaper
OCTOBER 6, 2026
risc-v — Proposed

RISC-V: Enable shared library and PIE support for riscv*-elf

Enable shared library and PIE support for RISC-V ELF targets to facilitate UEFI application development.

This patch series enables support for shared libraries and Position-Independent Executables (PIE) for RISC-V ELF targets, specifically the riscv*-elf toolchain. Historically, these features were disabled for this target, but the author argues there’s no technical dependency and other bare-metal ELF targets support them. The primary motivation is to enable the building of UEFI applications, which require PIE or shared library support.

In the Thread 1 participant
  1. mintsuki <mintsuki@protonmail.com> proposer

    Proposes enabling shared library and PIE support for riscv*-elf by modifying elf32lriscv-defs.sh, citing the need for UEFI application development.

    “riscv*-elf is the only RISC-V target for which ld refuses -shared and -pie. elf32lriscv-defs.sh has withheld GENERATE_SHLIB_SCRIPT and GENERATE_PIE_SCRIPT from it since be1dce26256a ("RISC-V: Disable shared library support for embedded elf."), whose commit message is a ChangeLog entry and records no reason. Nothing in the RISC-V backend depends on the exclusion, and riscv*-elf does not even set…”

In Details

This series modifies ld/emulparams/elf32lriscv-defs.sh to unconditionally enable GENERATE_SHLIB_SCRIPT and GENERATE_PIE_SCRIPT for the riscv*-elf target. The change removes a historical restriction that prevented the generation of scripts necessary for building dynamically linked executables (ET_DYN) and Position-Independent Executables (PIE). This is crucial for targets like UEFI applications, which are ET_DYN images and rely on PIE or shared -Bsymbolic for self-relocation.

For Context
PIE
Position-Independent Executable. An executable file that can be loaded at any address in memory without modification. This is achieved through special relocation entries and is crucial for security and flexibility.
ET_DYN
Executable ELF file type. Indicates a dynamically linked executable or a shared object. PIE executables are of this type.
UEFI
Unified Extensible Firmware Interface. A specification that defines the software interface between an operating system and platform firmware. UEFI applications are typically loaded and run by the UEFI firmware.
R_RISCV_RELATIVE
A RISC-V specific relocation type used for position-independent code, where the relocation value is determined by adding the image's base address to the symbol's offset.
elf32lriscv-defs.sh
A shell script within Binutils that defines linker emulation parameters specific to the 32-bit little-endian RISC-V architecture.
ld
The GNU linker, responsible for combining object files and libraries into an executable or library.
Filed Under: binutilsldrisc-vshared-librariespie