[PATCH] ia64: Fix .rela.got sizing for __ehdr_start during relaxation

Frank Scheiner frank.scheiner@web.de
Sat Nov 21 14:52:16 GMT 2026


Noticed during porting musl to ia64 ([1]). Trying to link the dynamic
libc.so fails an assertion in ld.bfd (BFD version 2.46-slack151):

```
/usr/bin/ld.bfd: BFD version 2.46-slack151 assertion fail elfnn-ia64.c:3238
```

[1]: https://github.com/johnny-mnemonic/epic-musl

The reason is a mismatch between the symbol state seen by different
sizing passes.

The attached patch solves that and allows for a successful dynamic build
of musl for ia64.

Debugging and patch creation was done with the help of an LLM using
qemu-system-ia64 ([2]). Actually the whole musl port was done mainly
under emulation, with verification runs on real hardware - just in case
someone wonders if it can be used for something more than just running
an OS for ia64.

[2]: https://github.com/syunnPC/qemu-system-ia64

The patch adds a single line, so I assume it does not fall under the
"legally significant" rule mentioned on [3].

[3]: https://sourceware.org/binutils/wiki/LLM_Generated_Content

The patch was tested against:

base-commit: de6d0c54d749a19e7422bf04b9b8f924d5e35bd5

...by building and testing binutils w/o and with the patch on real
hardware (rx2800 i2) running EPIC Slack. There was no difference
detected in the test_summary created output for the vanilla sources
(baseline) and the patched sources except for different paths of the
build directories.

built with: `make all-ld all-gas all-binutils`
checked with: `make check-ld check-gas check-binutils`
configure flags: --enable-targets=all --disable-gdb --disable-sim --disable-gold --disable-gprof --disable-gprofng

Cheers,
Frank

P.S.
The commit message has all the details:

```
When linking a shared object that references the linker-defined symbol
__ehdr_start (such as musl libc's dynamic linker), the IA-64 backend
can trigger a BFD_ASSERT failure in elfNN_ia64_install_dyn_reloc()
due to an undersized .rela.got section.

  /usr/bin/ld.bfd: BFD version 2.46-slack151 assertion fail elfnn-ia64.c:3238

The root cause is a mismatch between the symbol state seen by different
sizing passes. The generic ELF linker (ld/ldelf.c) temporarily forces
__ehdr_start to bfd_link_hash_defined during size_dynamic_sections (and
thus elfNN_ia64_late_size_sections), then restores it to its original
type (typically bfd_link_hash_undefweak) afterward.

However, the IA-64 backend's elfNN_ia64_relax_section() contains a
resize path that zeroes srelgot->size and recomputes it by invoking
allocate_dynrel_entries(). This resize pass runs after the generic
linker has restored __ehdr_start to undefweak. Because
allocate_dynrel_entries() computes resolved_zero for undefweak symbols,
it omits the .rela.got slot for __ehdr_start.

Later, during the relocation emission phase, set_got_entry() still
emits the dynamic relocation for __ehdr_start (since it genuinely
requires a GOT entry to hold the ELF header address). This writes past
the end of the undersized .rela.got buffer, triggering the assertion:

  BFD_ASSERT (sizeof (ElfNN_External_Rela) * srel->reloc_count <= srel->size);

Fix this by excluding __ehdr_start (identified via
elf_hash_table(info)->hehdr_start) from the resolved_zero optimization
in allocate_dynrel_entries(). This ensures its GOT relocation slot is
consistently allocated regardless of which sizing pass is evaluating it.

Tested by building musl libc (which combines libc and the dynamic
linker into a single shared object) for ia64-unknown-linux-gnu, which
previously failed with the above assertion.

bfd/
	* elfnn-ia64.c (allocate_dynrel_entries): Exclude __ehdr_start
	from the resolved_zero optimization.
```
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ia64-Fix-.rela.got-sizing-for-__ehdr_start-during-re.patch
Type: text/x-patch
Size: 2919 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20261121/37f83123/attachment.bin>


More information about the Binutils mailing list