From 030b83f3a808c0c969bd18d3d8f8e430df33e766 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 31 Jan 2018 12:26:40 -0500 Subject: [PATCH] add binutils patches fixing mips tls reloc output when linking pie the linker was wrongly leaving dynamic relocations for GD-model TLS defined in the main program when linking the main program as PIE. this was only suboptimal for dynamic pie, but for static pie it resulted in runtime failure since there is no dynamic linker to resolve the DTPMOD reference. this has been reported as binutils bug #22570. --- .../binutils-2.25.1/0008-mips-pie-tls.diff | 21 +++++++++++++++++++ patches/binutils-2.27/0004-mips-pie-tls.diff | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 patches/binutils-2.25.1/0008-mips-pie-tls.diff create mode 100644 patches/binutils-2.27/0004-mips-pie-tls.diff diff --git a/patches/binutils-2.25.1/0008-mips-pie-tls.diff b/patches/binutils-2.25.1/0008-mips-pie-tls.diff new file mode 100644 index 0000000..f1df3a4 --- /dev/null +++ b/patches/binutils-2.25.1/0008-mips-pie-tls.diff @@ -0,0 +1,21 @@ +diff -ur binutils-2.25.1.orig/bfd/elfxx-mips.c binutils-2.25.1/bfd/elfxx-mips.c +--- binutils-2.25.1.orig/bfd/elfxx-mips.c 2018-01-31 11:26:12.000000000 -0500 ++++ binutils-2.25.1/bfd/elfxx-mips.c 2018-01-31 12:16:00.179841734 -0500 +@@ -3228,7 +3228,7 @@ + && (!info->shared || !SYMBOL_REFERENCES_LOCAL (info, h))) + indx = h->dynindx; + +- if ((info->shared || indx != 0) ++ if ((!info->executable || indx != 0) + && (h == NULL + || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak)) +@@ -3338,7 +3338,7 @@ + if (entry->tls_initialized) + return; + +- if ((info->shared || indx != 0) ++ if ((!info->executable || indx != 0) + && (h == NULL + || ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak)) diff --git a/patches/binutils-2.27/0004-mips-pie-tls.diff b/patches/binutils-2.27/0004-mips-pie-tls.diff new file mode 100644 index 0000000..9c4f0ff --- /dev/null +++ b/patches/binutils-2.27/0004-mips-pie-tls.diff @@ -0,0 +1,21 @@ +diff -ur binutils-2.27.orig/bfd/elfxx-mips.c binutils-2.27/bfd/elfxx-mips.c +--- binutils-2.27.orig/bfd/elfxx-mips.c 2016-08-03 03:36:51.000000000 -0400 ++++ binutils-2.27/bfd/elfxx-mips.c 2018-01-31 12:11:22.458824584 -0500 +@@ -3242,7 +3242,7 @@ + && (!bfd_link_pic (info) || !SYMBOL_REFERENCES_LOCAL (info, h))) + indx = h->dynindx; + +- if ((bfd_link_pic (info) || indx != 0) ++ if ((bfd_link_dll (info) || indx != 0) + && (h == NULL + || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak)) +@@ -3354,7 +3354,7 @@ + if (entry->tls_initialized) + return; + +- if ((bfd_link_pic (info) || indx != 0) ++ if ((bfd_link_dll (info) || indx != 0) + && (h == NULL + || ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak))