[PATCH v2 0/3] PE-COFF weak external fixes

Peter Damianov peter0x44@disroot.org
Mon Jun 22 03:39:23 GMT 2026


This is v2 of the PE-COFF weak external fixes.  The series fixes two
weak external resolution bugs in the BFD linker and adds tests covering
the weak/strong interaction matrix.

Changes from v1:

  * Drop unnecessary casts from bfd_hash_allocate results.
  * Make the null-fallback handling in patch 2 more explicit: a COFF
    weak declaration uses the null symbol as its fallback, which appears
    in the hash table as a defined absolute symbol with value zero.  The
    updated code now treats that case as unresolved on both the old and
    incoming fallback sides.

Alan reported two test failures with Ubuntu's x86_64-w64-mingw32 cross
compiler.  I reproduced that as a testsuite setup issue rather than a
linker regression: that compiler is configured with --with-ld=/usr/bin/
x86_64-w64-mingw32-ld and ignores the testsuite's -B path, so the new
tests were being linked with the installed linker instead of the just
built one.

For my GitHub Actions coverage I worked around that by replacing the
disposable runner's hardwired MinGW ld/as entry points with symlinks to
the just-built tools before running the DejaGnu tests:

  https://github.com/Peter0x44/binutils-gdb/blob/30db88d4da5db6b3ddcfc745a8438ce8d1f600fe/.github/workflows/ld-pe-tests.yml#L126-L133

A successful run using that workaround is here:

  https://github.com/Peter0x44/binutils-gdb/actions/runs/27926498479/job/82629812736

Peter Damianov (3):
  PE-COFF: Fix weak external symbol resolution when strong undef is seen
    first
  PE-COFF: Prefer weak external with defined fallback over null fallback
  ld/testsuite: Add comprehensive PE COFF weak external tests

 bfd/cofflink.c                                | 137 ++++++++++++++++--
 ld/testsuite/ld-pe/pe-compile.exp             |  88 +++++++++++
 .../ld-pe/weak-ext-add1-weak-chained.c        |  13 ++
 ld/testsuite/ld-pe/weak-ext-add2.c            |   8 +
 ld/testsuite/ld-pe/weak-ext-dummy.c           |   5 +
 ld/testsuite/ld-pe/weak-ext-expected1.c       |   1 +
 .../ld-pe/weak-ext-expected3-add1-weak.c      |   9 ++
 ld/testsuite/ld-pe/weak-ext-expected3.c       |   1 +
 ld/testsuite/ld-pe/weak-ext-expected5.c       |   1 +
 ld/testsuite/ld-pe/weak-ext-main-weak-def.c   |  26 ++++
 ld/testsuite/ld-pe/weak-ext-main-weak.c       |  22 +++
 ld/testsuite/ld-pe/weak-ext-main.c            |  21 +++
 12 files changed, 319 insertions(+), 13 deletions(-)
 create mode 100644 ld/testsuite/ld-pe/weak-ext-add1-weak-chained.c
 create mode 100644 ld/testsuite/ld-pe/weak-ext-add2.c
 create mode 100644 ld/testsuite/ld-pe/weak-ext-dummy.c
 create mode 100644 ld/testsuite/ld-pe/weak-ext-expected1.c
 create mode 100644 ld/testsuite/ld-pe/weak-ext-expected3-add1-weak.c
 create mode 100644 ld/testsuite/ld-pe/weak-ext-expected3.c
 create mode 100644 ld/testsuite/ld-pe/weak-ext-expected5.c
 create mode 100644 ld/testsuite/ld-pe/weak-ext-main-weak-def.c
 create mode 100644 ld/testsuite/ld-pe/weak-ext-main-weak.c
 create mode 100644 ld/testsuite/ld-pe/weak-ext-main.c

-- 
2.54.0



More information about the Binutils mailing list