binutils Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
pe-coff

PE-COFF linker handles weak externals when strong undefined symbols appear first

Fixes PE-COFF object linking to correctly resolve weak external symbols, even when a strong undefined symbol is seen first.

This commit corrects how the PE-COFF linker resolves weak external symbols by ensuring proper handling when a strong undefined symbol for the same name is encountered earlier in the linking process. Previously, this scenario could lead to “undefined reference” errors for symbols like GCC-emitted personality routines that use weak externals with fallbacks. The fix ensures that symbol class and auxiliary records are stored correctly, and the weak alias fallback mechanism is activated even for initially strong undefined symbols that later take on weak external characteristics.

In Details

When linking PE COFF objects, coff_link_add_symbols previously failed to store the COFF-specific symbol_class and aux record when a weak external (with aux) met a strong undefined symbol. The action taken was NOACT, preserving the strong undefined hash entry. Additionally, _bfd_coff_generic_relocate_section's weak alias fallback logic only applied to bfd_link_hash_undefweak, not to bfd_link_hash_undefined which could retain the strong undefined status. This patch updates coff_link_add_symbols to store the weak external's information when the existing entry is undefined, and modifies…

For Context
PE-COFF
Portable Executable - Common Object File Format. A file format used for executables, object code, and DLLs on 32-bit and 64-bit versions of Windows.
weak external
A symbol declaration that allows a linker to resolve it to a definition if one exists, but otherwise provides a default (fallback) implementation or resolves to NULL if no definition is found. This is indicated by C_NT_WEAK with an auxiliary record in PE-COFF files.
strong undefined reference
A symbol that is referenced in an object file but has not yet been defined. Unlike a weak external, a strong undefined symbol must be resolved by a definition in another object file or library; if not, the linker will produce an "undefined reference" error.
auxiliary record
Additional data associated with a symbol in an object file, providing more information. For PE-COFF weak externals (C_NT_WEAK), the auxiliary record specifies the fallback alias.
bfd_link_hash_undefined
An internal linker hash table state indicating that a symbol has been seen but not yet defined. This state can correspond to a strong undefined symbol.
bfd_link_hash_undefweak
An internal linker hash table state indicating that a symbol is a weak external symbol that has not yet been defined. The linker may still attempt to resolve its fallback alias.
Filed Under: pe-cofflinkerweak symbols