binutils: allow creating an empty import library

Fixes #7029
This commit is contained in:
Jeremy Drake
2020-09-24 12:51:13 -07:00
parent 014d3367ae
commit a2a71015f8
5 changed files with 128 additions and 63 deletions

View File

@@ -0,0 +1,62 @@
From 79347866a5174c5941c4060c6fb97101efafd3a3 Mon Sep 17 00:00:00 2001
From: Jeremy Drake <sourceware-bugzilla@jdrake.com>
Date: Fri, 11 Sep 2020 17:51:16 +0100
Subject: [PATCH 5/8] Fix a segfault when creating an import library with 0
exports.
PR 26588
* emultempl/pe.em (_finish): Only generate a import library if not
exporting relocs.
* emultempl/pep.em: Likewise.
---
ld/ChangeLog | 7 +++++++
ld/emultempl/pe.em | 3 ++-
ld/emultempl/pep.em | 3 ++-
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index f8ad16235f..06c06956a3 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2020-09-11 Jeremy Drake <sourceware-bugzilla@jdrake.com>
+
+ PR 26588
+ * emultempl/pe.em (_finish): Only generate a import library if not
+ exporting relocs.
+ * emultempl/pep.em: Likewise.
+
2020-08-28 Nick Clifton <nickc@redhat.com>
PR 19011
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index f45518eafb..38b5536f72 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -2013,7 +2013,8 @@ gld_${EMULATION_NAME}_finish (void)
)
{
pe_dll_fill_sections (link_info.output_bfd, &link_info);
- if (command_line.out_implib_filename)
+ if (command_line.out_implib_filename
+ && pe_def_file->num_exports != 0)
pe_dll_generate_implib (pe_def_file, command_line.out_implib_filename,
&link_info);
}
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 7d9395168d..f161cce2b5 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -1823,7 +1823,8 @@ gld_${EMULATION_NAME}_finish (void)
&& pep_def_file->num_exports != 0))
{
pep_dll_fill_sections (link_info.output_bfd, &link_info);
- if (command_line.out_implib_filename)
+ if (command_line.out_implib_filename
+ && pep_def_file->num_exports != 0)
pep_dll_generate_implib (pep_def_file,
command_line.out_implib_filename, &link_info);
}
--
2.28.0.windows.1

View File

@@ -1,7 +1,7 @@
From 3542e64573975b82f74f68215c7603e94879ac6d Mon Sep 17 00:00:00 2001
From 13e838b003009bfc4850e5be1da62b409497a6ca Mon Sep 17 00:00:00 2001
From: Jeremy Drake <github@jdrake.com>
Date: Mon, 31 Aug 2020 10:26:19 -0700
Subject: [PATCH 1/3] Temporarily revert default dll characteristics.
Subject: [PATCH 6/8] Temporarily revert default dll characteristics.
Until more testing is done, this patch reverts the
DEFAULT_DLL_CHARACTERISTICS to 0, but keeps the new --disable- options
@@ -11,18 +11,21 @@ Note that this does NOT revert the default --enable-reloc-section. This
shouldn't hurt anything other than making the resulting executable
larger.
---
ld/ChangeLog | 8 ++++++++
ld/ChangeLog | 7 +++++++
ld/NEWS | 2 ++
ld/emultempl/pe.em | 3 +--
ld/emultempl/pep.em | 4 +---
ld/ld.texi | 7 +++----
5 files changed, 15 insertions(+), 9 deletions(-)
5 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index f8ad16235f..4f9ccb6b10 100644
index 06c06956a3..9fa615b712 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,11 @@
@@ -4,6 +4,13 @@
* emultempl/pe.em (_finish): Only generate a import library if not
exporting relocs.
* emultempl/pep.em: Likewise.
+2020-08-30 Jeremy Drake <sourceware-bugzilla@jdrake.com>
+
+ PR 19011
@@ -30,10 +33,9 @@ index f8ad16235f..4f9ccb6b10 100644
+ * emultempl/pep.em: Likewise.
+ * ld.texi: Document the reverted defaults.
+ * NEWS: Mention the reverted defaults.
+
2020-08-28 Nick Clifton <nickc@redhat.com>
PR 19011
diff --git a/ld/NEWS b/ld/NEWS
index 004e7c5d41..a947ff2f1a 100644
--- a/ld/NEWS
@@ -48,7 +50,7 @@ index 004e7c5d41..a947ff2f1a 100644
* X86 NaCl target support is removed.
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index f45518eafb..b3990cf677 100644
index 38b5536f72..32cd175ebb 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -104,8 +104,7 @@ fragment <<EOF
@@ -62,7 +64,7 @@ index f45518eafb..b3990cf677 100644
#if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
#define PE_DEF_SUBSYSTEM 3
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 7d9395168d..ea792fe25a 100644
index f161cce2b5..28d451e9af 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -99,9 +99,7 @@ fragment <<EOF

View File

@@ -0,0 +1,46 @@
From d4c5a3da694e8293b8fc187290eba27d51523a1e Mon Sep 17 00:00:00 2001
From: Jeremy Drake <github@jdrake.com>
Date: Thu, 24 Sep 2020 12:20:12 -0700
Subject: [PATCH 8/8] Allow creating an empty import library for a dll.
After preventing creating an import library for an exe when there are no
exports, to avoid a crash, it turned out that some projects expected to
be able to create an import library for a dll with no exports, so more
closely match the condition to the condition around initializing the dll
name.
---
ld/emultempl/pe.em | 3 ++-
ld/emultempl/pep.em | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 32cd175ebb..6c14af5e29 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -2013,7 +2013,8 @@ gld_${EMULATION_NAME}_finish (void)
{
pe_dll_fill_sections (link_info.output_bfd, &link_info);
if (command_line.out_implib_filename
- && pe_def_file->num_exports != 0)
+ && (pe_def_file->num_exports != 0
+ || bfd_link_pic (&link_info)))
pe_dll_generate_implib (pe_def_file, command_line.out_implib_filename,
&link_info);
}
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 0b43ec515d..0918a68059 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -1866,7 +1866,8 @@ gld_${EMULATION_NAME}_finish (void)
{
pep_dll_fill_sections (link_info.output_bfd, &link_info);
if (command_line.out_implib_filename
- && pep_def_file->num_exports != 0)
+ && (pep_def_file->num_exports != 0
+ || bfd_link_pic (&link_info)))
pep_dll_generate_implib (pep_def_file,
command_line.out_implib_filename, &link_info);
}
--
2.28.0.windows.1

View File

@@ -1,48 +0,0 @@
From bcf96e82c0d340556a4ed863f76788510f002555 Mon Sep 17 00:00:00 2001
From: Jeremy Drake <github@jdrake.com>
Date: Thu, 10 Sep 2020 10:31:34 -0700
Subject: [PATCH 3/3] Don't crash if asked to create an empty implib.
With --enable-reloc-section (now default), ld segfaults if asked to
create an import lib for an executable with 0 exports. With
--disable-reloc-section (the old default), it would just silently not
create one. This patch restores the latter behavior for the
--enable-reloc-section case.
PR 26588
---
ld/emultempl/pe.em | 3 ++-
ld/emultempl/pep.em | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index b3990cf677..32cd175ebb 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -2012,7 +2012,8 @@ gld_${EMULATION_NAME}_finish (void)
)
{
pe_dll_fill_sections (link_info.output_bfd, &link_info);
- if (command_line.out_implib_filename)
+ if (command_line.out_implib_filename
+ && pe_def_file->num_exports != 0)
pe_dll_generate_implib (pe_def_file, command_line.out_implib_filename,
&link_info);
}
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index de6d7aafbb..0b43ec515d 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -1865,7 +1865,8 @@ gld_${EMULATION_NAME}_finish (void)
&& pep_def_file->num_exports != 0))
{
pep_dll_fill_sections (link_info.output_bfd, &link_info);
- if (command_line.out_implib_filename)
+ if (command_line.out_implib_filename
+ && pep_def_file->num_exports != 0)
pep_dll_generate_implib (pep_def_file,
command_line.out_implib_filename, &link_info);
}
--
2.28.0.windows.1

View File

@@ -6,7 +6,7 @@ _realname=binutils
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.35
pkgrel=6
pkgrel=7
pkgdesc="A set of programs to assemble and manipulate binary and object files (mingw-w64)"
arch=('any')
url="https://www.gnu.org/software/binutils/"
@@ -28,9 +28,10 @@ source=(https://ftp.gnu.org/gnu/binutils/${_realname}-${pkgver}.tar.xz{,.sig}
1002-mingw-plugin-test-regressions-due-to-commit-514b4e19.patch
1003-Fixes-for-testsuite-failures-introduced-by-the-chang.patch
1004-Pass-disable-reloc-section-on-PE-targets-for-PR-2566.patch
1005-Fix-a-segfault-when-creating-an-import-library-with-.patch
2000-Temporarily-revert-default-dll-characteristics.patch
2001-ld-option-to-move-default-bases-under-4GB.patch
2002-Don-t-crash-if-asked-to-create-an-empty-implib.patch)
2002-Allow-creating-an-empty-import-library-for-a-dll.patch)
sha256sums=('1b11659fb49e20e18db460d44485f09442c8c56d5df165de9461eb09c8302f85'
'SKIP'
'93296b909e1a4f9d8a4bbe2437aafa17ca565ef6642a9812b0360c05be228c9d'
@@ -43,9 +44,10 @@ sha256sums=('1b11659fb49e20e18db460d44485f09442c8c56d5df165de9461eb09c8302f85'
'111a7385b93e9f1bf97503fe354ebe50f9be4b6d25cbb8678dde45df5e29ee8a'
'57a61ac664027bed5da848a16af2ea3ad63e820d7db2d24588c33168d93276bb'
'dc3724a9f42db77b38cb5db78aeaf3f92dbe8ea630db80e73135e9358d1e55c9'
'a9b0e140a34032a67a051d693460b10c03f1a1361c210e687a214d0505deb494'
'19229691da6a8e74be1d81caedd322f9d125dcd99bbb93937df3d22739d0ed2a'
'ca835968772bd144d71a6408b4e13d55ae3b10b30138fd2ca5b57409e4557810'
'b790b09db892a1acde82bfe570ca52b50ed2ca98e6a99254cc8a8528eb87f8b2'
'f37671f4d571d4b5477979798887d245c2e163a6e247591a01761b136c673eaa')
'23efc95826a4a60bccb4ee304129066c2f955149093c1320f6854500e41c36e0')
validpgpkeys=('EAF1C276A747E9ED86210CBAC3126D3B4AE55E93'
'3A24BC1E8FB409FA9F14371813FCEF89DD9E3C4F')
@@ -62,13 +64,14 @@ prepare() {
patch -p1 -i "${srcdir}"/1002-mingw-plugin-test-regressions-due-to-commit-514b4e19.patch
patch -p1 -i "${srcdir}"/1003-Fixes-for-testsuite-failures-introduced-by-the-chang.patch
patch -p1 -i "${srcdir}"/1004-Pass-disable-reloc-section-on-PE-targets-for-PR-2566.patch
patch -p1 -i "${srcdir}"/1005-Fix-a-segfault-when-creating-an-import-library-with-.patch
# Temporarily revert defaults change while testing.
patch -p1 -i "${srcdir}"/2000-Temporarily-revert-default-dll-characteristics.patch
# Add an option to change default bases back below 4GB to ease transition
patch -p1 -i "${srcdir}"/2001-ld-option-to-move-default-bases-under-4GB.patch
# https://sourceware.org/bugzilla/show_bug.cgi?id=26588
patch -p1 -i "${srcdir}"/2002-Don-t-crash-if-asked-to-create-an-empty-implib.patch
patch -p1 -i "${srcdir}"/2002-Allow-creating-an-empty-import-library-for-a-dll.patch
}
build() {