binutils Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
risc-v

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

Shared library and PIE support are now enabled for RISC-V bare-metal ELF targets.

Previously, the RISC-V bare-metal ELF target (riscv*-elf) refused to generate shared libraries and Position-Independent Executables (PIE). This was due to specific configurations in elf32lriscv-defs.sh that withheld GENERATE_SHLIB_SCRIPT and GENERATE_PIE_SCRIPT. This commit removes those restrictions, aligning the target with other bare-metal ELF targets that support these features and do not explicitly set the EMBEDDED flag.

In Details

The linker configuration for riscv*-elf in ld/emulparams/elf32lriscv-defs.sh previously contained conditional logic to disable GENERATE_SHLIB_SCRIPT and GENERATE_PIE_SCRIPT. This was likely a conservative choice made when RISC-V embedded support was first introduced. This patch removes those conditions, enabling the generation of ET_DYN (shared object) and PIE executables for riscv*-elf targets. This aligns with the broader ELF target behavior where the mere presence of ELF/program headers does not preclude PIE/shared library generation, even for targets that might be considered 'em…

For Context
shared library
A library whose code and data can be loaded by multiple programs simultaneously at runtime, reducing memory footprint and allowing for easier updates.
PIE
Position-Independent Executable. An executable program that can be loaded at any arbitrary memory address during runtime. This is crucial for security, as it allows the operating system to randomize the executable's base address, making it harder for attackers to exploit memory corruption vulnerabilities.
riscv*-elf
A target triplet specifying the RISC-V architecture, typically for bare-metal or embedded systems using the ELF object file format.
GENERATE_SHLIB_SCRIPT
A linker configuration option that enables the generation of scripts needed to build shared libraries.
GENERATE_PIE_SCRIPT
A linker configuration option that enables the generation of scripts required for building Position-Independent Executables.
ET_DYN
An ELF file type that indicates a dynamically linked executable or shared object. It can be loaded at different virtual addresses.
EMBEDDED
A flag or configuration setting indicating that a target system is embedded, which might imply certain constraints on dynamic linking or executable types.
Filed Under: risc-vlinkershared libraryPIE