[PATCH v3 0/4] PE-COFF weak external fixes
Peter Damianov
peter0x44@disroot.org
Tue Jun 23 21:38:03 GMT 2026
After I sent my last patch series, I was reminded of:
https://gcc.gnu.org/PR124263 and
https://github.com/skeeto/w64devkit/issues/393 , which looked
related and like this patch could fix them. It turned out to be
a related issue but with archives instead. This submission adds
an extra patch to fix that reported issue and adds extra tests
covering that issue. I tested that it also fixes the upstream GCC
issue.
Changes from v2:
* Add a new BFD archive fix for GCC PR124263. PE weak externals are
canonicalized as undefined BFD symbols even when their aux entry
names a real fallback definition. The archive map now advertises
those public weak names, while still excluding weak declarations
whose fallback is the absolute-zero null symbol.
* Avoid extracting the same archive member again during repeated
archive searches once a PE weak external resolves through a real
fallback definition.
* Extend the testsuite patch with an archive regression test covering
the positive real-fallback armap case, the negative null-fallback
declaration case, and the duplicate archive search case.
The first two patches are unchanged from v2. The new archive fix is
patch 3, and the testsuite patch is modified with extra tests exercising
the fix.
Peter Damianov (4):
PE-COFF: Fix weak external symbol resolution when strong undef is seen
first
PE-COFF: Prefer weak external with defined fallback over null fallback
bfd: Handle PE weak externals with real fallbacks in archives
ld/testsuite: Add comprehensive PE COFF weak external tests
bfd/archive.c | 22 ++-
bfd/coff-bfd.c | 47 +++++
bfd/coff-bfd.h | 3 +
bfd/cofflink.c | 183 ++++++++++++++++--
ld/testsuite/ld-pe/pe-compile.exp | 167 ++++++++++++++++
.../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 ++
15 files changed, 510 insertions(+), 19 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