binutils Newspaper
NOVEMBER 30, 2026
rl78 — Proposed

rl78: check relaxation delete range, propagate failures

Strengthens RL78 relaxation by validating deletion ranges and propagating errors.

This patch (v2 7/8) enhances the relaxation process for the RL78 architecture in binutils. It introduces validation for deletion ranges within elf32_rl78_relax_delete_bytes using _bfd_elf_relax_delete_range_ok, ensuring that byte deletions do not go out of bounds. The patch also wraps macros like SNIPNR and SNIP in do-while(0) blocks for safety and ensures that any failures during the deletion process are propagated to rl78_elf_relax_section. A new DejaGnu regression test (rl78-relax-underflow.exp) is added to cover these scenarios. The author notes that pre-deletion opcode rewriting issues may still exist and will be addressed separately.

In the Thread 1 participant
  1. Harshit Kumar proposer

    Submits a patch to improve RL78 relaxation by validating deletion ranges, propagating failures, and adding a regression test.

    “Validate deletion range in elf32_rl78_relax_delete_bytes using _bfd_elf_relax_delete_range_ok. Wrap SNIPNR and SNIP macros in do-while(0) blocks. Propagate deletion return status in rl78_elf_relax_section and branch to error_return on failure. Add DejaGnu regression test ld-rl78/rl78-relax-underflow.exp. Note that crafted inputs with out-of-range relocation offsets can still fault during pre-d…”

In Details

This patch is part of a series addressing relaxation robustness for embedded architectures in binutils, focusing on RL78. It enhances the elf32_rl78_relax_delete_bytes function by incorporating a call to _bfd_elf_relax_delete_range_ok. This check ensures that the addr, count, and toaddr parameters for byte deletion are within the valid bounds of the section, preventing potential underflow or out-of-bounds writes during relaxation. Additionally, it wraps certain macros (SNIPNR, SNIP) in do-while(0) for safer use in conditional contexts. Crucially, the patch ensures that the suc…

For Context
relaxation
A process in linkers where the linker adjusts machine code after initial assembly to resolve symbolic addresses and optimize code, often involving changing instruction lengths or operand values.
RL78
A family of microcontrollers developed by Renesas Electronics. Binutils provides support for assembling and linking code for RL78 targets.
linker
A program that combines one or more object files (produced by an assembler or compiler) into a single executable file, library file, or another object file. It resolves symbolic references between files.
underflow
In this context, an underflow during relaxation likely refers to an operation that results in an invalid or nonsensical memory address or size calculation, potentially due to incorrect calculations or boundary violations.
DejaGnu
A testing framework developed by the Free Software Foundation for testing C compilers and other programming tools. It provides a common infrastructure for writing test harnesses.
BFD
Binutils 'Binary File Descriptor' library. It provides a common interface for reading and writing various object file formats, including ELF files used by RL78.
Filed Under: rl78linkerrelaxationerror-handlingtesting