Skip to content

Commit

Permalink
Fix a Binutils 2.40 regression
Browse files Browse the repository at this point in the history
In Binutils 2.40, there is a regression that ld fails with MSVC lib
files. Add a patch to fix it. Closes #59.

[1] msys2/MINGW-packages#15469
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=30079
  • Loading branch information
GalaxySnail authored and skeeto committed May 1, 2023
1 parent 5875e0b commit 0d66644
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ ARG ARCH=x86_64-w64-mingw32
# Build cross-compiler

WORKDIR /binutils-$BINUTILS_VERSION
RUN sed -ri 's/(static bool insert_timestamp = )/\1!/' ld/emultempl/pe*.em
COPY src/binutils-*.patch $PREFIX/src/
RUN sed -ri 's/(static bool insert_timestamp = )/\1!/' ld/emultempl/pe*.em \
&& cat $PREFIX/src/binutils-*.patch | patch -p1
WORKDIR /x-binutils
RUN /binutils-$BINUTILS_VERSION/configure \
--prefix=/bootstrap \
Expand Down
31 changes: 31 additions & 0 deletions src/binutils-fix-ld-compare-section.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From b7eab2a9d4f4e92692daf14b09fc95ca11b72e30 Mon Sep 17 00:00:00 2001
From: Michael Matz <matz@suse.de>
Date: Thu, 9 Feb 2023 15:29:00 +0100
Subject: [PATCH] Fix PR30079: abort on mingw

the early-out in wild_sort is not enough, it might still be
that filenames are equal _and_ the wildcard list doesn't specify
a sort order either. Don't call compare_section then.

Tested on all targets.
---
ld/ldlang.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 84a2914fc26..b5e0d026ae4 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -649,7 +649,8 @@ wild_sort (lang_wild_statement_type *wild,
looking at the sections for this file. */

/* Find the correct node to append this section. */
- if (compare_section (sec->spec.sorted, section, (*tree)->section) < 0)
+ if (sec && sec->spec.sorted != none && sec->spec.sorted != by_none
+ && compare_section (sec->spec.sorted, section, (*tree)->section) < 0)
tree = &((*tree)->left);
else
tree = &((*tree)->right);
--
2.31.1

0 comments on commit 0d66644

Please sign in to comment.