binutils Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
bfd

Add sanity checks to dynamic reloc section creation in elflink.c

Improves robustness of dynamic reloc section creation by adding sanity checks.

This commit enhances the _bfd_elf_make_dynamic_reloc_section function in elflink.c by adding critical sanity checks. It now verifies that the byte order of input objects matches the output and ensures the dynobj is valid. Additionally, memory allocated for section names is freed if unused, and a minor change in the return type of get_dynamic_reloc_section_name avoids an unnecessary cast.

In Details

Adds sanity checks to _bfd_elf_make_dynamic_reloc_section in elflink.c. It verifies that dynobj is not NULL and that the relocation byte order is compatible between the input and output BFDs using relocs_compatible. If the section name generated by get_dynamic_reloc_section_name is unused, it is now freed. The return type of get_dynamic_reloc_section_name is changed from const char* to char* to avoid a cast when bfd_release is called.

For Context
dynamic reloc section
A section in an ELF file that contains relocation information needed for dynamically linked objects.
byte order
The order in which bytes are arranged in computer memory for multi-byte data types. Common orders are big-endian and little-endian.
sanity checks
Assertions or checks added to code to verify that the program's state is valid and as expected, helping to catch errors early.
BFD
Binary File Descriptor library. A library used by Binutils to abstract different object file formats.
Filed Under: linkerelfrobustnessrelocations