Consolidate creation of stub bfd
Patch consolidates stub BFD creation logic into `ldelf.c`, simplifying code and fixing MIPS target orphan section placement.
Alan Modra proposes a patch to refactor Binutils’ ELF handling by consolidating the creation of stub BFDs into a single location in ldelf.c. This change aims to reduce code duplication across various ELF targets. While intended to not alter target behavior, it fixes an issue on MIPS where the stub BFD was created later, affecting orphan section placement. The patch resolves this by ensuring earlier creation and adjusting test cases accordingly.
- proposer
Submits a patch to centralize stub BFD creation in `ldelf.c` and fix related issues, particularly on MIPS.
“This patch replaces the code creating a stub bfd in various ELF targets with one copy in ldelf.c. This shouldn't change target behaviour, except for mips which now creates the stub bfd like all other targets rather than delaying until the first stub section is needed.”
In Details
This patch refactors the Binutils linker (ld) by consolidating the logic for creating a 'stub' BFD (Binary File Descriptor) across different ELF targets. Previously, this creation logic was duplicated in various elfxx-*.c files. The new approach centralizes this in ldelf.c. A side effect, noted as a fix, is on MIPS targets where the stub BFD was previously created lazily. This lazy creation affected the placement of orphan sections. By forcing earlier creation, the patch resolves these test failures, requiring adjustments to section placement in the test scripts.
- BFD
- Binary File Descriptor. An abstract data structure used by GNU tools to represent object files, providing a common interface for handling different object file formats.
- Stub BFD
- A minimal BFD structure created early in the linking process for ELF targets. It serves as a placeholder or base for more detailed BFD structures.
- ELF
- Executable and Linkable Format. A standard file format for executable files, object code, shared libraries, and core dumps.
- ld
- The GNU linker, responsible for combining object files and libraries into an executable or shared library.
- Orphan section
- A section in an object file that is not explicitly placed or defined by the linker script, potentially leading to unpredictable placement.
- MIPS
- Microprocessor without Interlocked Pipeline Stages. A family of RISC instruction set architectures.