binutils Newspaper
NOVEMBER 30, 2026
ld — Proposed

ld: refuse the link when no stub file was created

Prevents crashes in AVR and M68HC11 emulations by refusing to link when a required stub file is not created due to a generic ELF output format.

This patch addresses crashes in the AVR and M68HC11 linker emulations that occur when a linker script uses OUTPUT_FORMAT to select a generic ELF flavor. In such cases, no stub file is created, but the emulation hooks (e.g., avr_elf_after_open_output) attempt to dereference the null stub_file. This change makes these hooks refuse the link with a fatal error when stub_file is NULL, preventing crashes and ensuring a clean failure message.

In the Thread 1 participant
  1. Harshit Kumar proposer

    Proposes to refuse the link when `stub_file` is NULL in AVR and M68HC11 emulations, preventing crashes caused by generic ELF output formats.

    “When a linker script uses OUTPUT_FORMAT to select a generic ELF flavour, the output BFD reports the ELF flavour but no stub file is created, leaving stub_file == NULL. Both the AVR and M68HC emulation hooks then dereference stub_file.”

In Details

This patch fixes a crash occurring in the AVR and M68HC11 linker emulations when a linker script specifies a generic ELF output format (e.g., OUTPUT_FORMAT("elf32-little")). The generic ELF backends do not create a stub BFD, resulting in stub_file being NULL. However, the emulation hooks (avr_elf_after_open_output and m68hc11elf_after_open_output) incorrectly assume stub_file is always valid and dereference it, leading to a crash. The fix ensures these hooks refuse the link if stub_file is NULL, and also correctly calls ldelf_after_open_output earlier in the AVR case.

For Context
stub file
A special file used by the linker to handle certain linking scenarios, particularly related to dynamic linking or specific target architectures.
AVR
A family of microcontrollers manufactured by Atmel.
M68HC11
A microcontroller from Motorola's M68HC11 family.
ELF
Executable and Linkable Format, a standard file format for executables, object code, shared libraries, and core dumps on Unix-like systems.
Filed Under: linkeravrm68hc11elfcrash