This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [committed, PATCH] x86-64: Limit PIC check to shared library build
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Mon, 17 Jul 2017 12:54:01 -0700
- Subject: Re: [committed, PATCH] x86-64: Limit PIC check to shared library build
- Authentication-results: sourceware.org; auth=none
- References: <20170717191953.GA28939@gmail.com>
On Mon, Jul 17, 2017 at 12:19 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> When building an executable, undefined symbols are error and undefined
> weak symbols are resolved to zero. We only need to check PIC for
> building a shared library.
>
> bfd/
>
> PR ld/21782
> * elf64-x86-64.c (elf_x86_64_relocate_section): Limit PIC check
> to shared library.
>
> ld/
>
> PR ld/21782
> * testsuite/ld-x86-64/pie3-nacl.d: New file.
> * testsuite/ld-x86-64/pie3.d: Likewise.
> * testsuite/ld-x86-64/pie3.s: Likewise.
> * testsuite/ld-x86-64/x86-64.exp: Run pie3 and pie3-nacl.
>
I backported it to 2.29 branch.
--
H.J.
From 89f512d3eca31aae9498430d3cdad6be8cf44c9a Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 17 Jul 2017 12:17:59 -0700
Subject: [PATCH] x86-64: Limit PIC check to shared library build
When building an executable, undefined symbols are error and undefined
weak symbols are resolved to zero. We only need to check PIC for
building a shared library.
bfd/
PR ld/21782
* elf64-x86-64.c (elf_x86_64_relocate_section): Limit PIC check
to shared library.
ld/
PR ld/21782
* testsuite/ld-x86-64/pie3-nacl.d: New file.
* testsuite/ld-x86-64/pie3.d: Likewise.
* testsuite/ld-x86-64/pie3.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run pie3 and pie3-nacl.
(cherry picked from commit c5bb8910e80c6cd80c63541f86471c18375c8198)
---
bfd/ChangeLog | 6 ++++++
bfd/elf64-x86-64.c | 4 +---
ld/ChangeLog | 8 ++++++++
ld/testsuite/ld-x86-64/pie3-nacl.d | 14 ++++++++++++++
ld/testsuite/ld-x86-64/pie3.d | 13 +++++++++++++
ld/testsuite/ld-x86-64/pie3.s | 5 +++++
ld/testsuite/ld-x86-64/x86-64.exp | 2 ++
7 files changed, 49 insertions(+), 3 deletions(-)
create mode 100644 ld/testsuite/ld-x86-64/pie3-nacl.d
create mode 100644 ld/testsuite/ld-x86-64/pie3.d
create mode 100644 ld/testsuite/ld-x86-64/pie3.s
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 571edd1770..e1e71e1af3 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2017-07-17 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/21782
+ * elf64-x86-64.c (elf_x86_64_relocate_section): Limit PIC check
+ to shared library.
+
2017-07-16 Alan Modra <amodra@gmail.com>
* elf64-ppc.c (ppc64_elf_relocate_section): Don't optimize
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 8cef9f5e74..c80a9caaa6 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4969,9 +4969,7 @@ do_ifunc_pointer:
&& ((bfd_link_executable (info)
&& h->root.type == bfd_link_hash_undefweak
&& !resolved_to_zero)
- || (bfd_link_pic (info)
- && !(bfd_link_pie (info)
- && h->root.type == bfd_link_hash_undefined))))
+ || bfd_link_dll (info)))
{
bfd_boolean fail = FALSE;
bfd_boolean branch
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 165dee962f..2fb8c79de9 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,11 @@
+2017-07-17 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/21782
+ * testsuite/ld-x86-64/pie3-nacl.d: New file.
+ * testsuite/ld-x86-64/pie3.d: Likewise.
+ * testsuite/ld-x86-64/pie3.s: Likewise.
+ * testsuite/ld-x86-64/x86-64.exp: Run pie3 and pie3-nacl.
+
2016-07-14 Maciej W. Rozycki <macro@imgtec.com>
* testsuite/ld-unique/pr21529.ld: New test linker script.
diff --git a/ld/testsuite/ld-x86-64/pie3-nacl.d b/ld/testsuite/ld-x86-64/pie3-nacl.d
new file mode 100644
index 0000000000..59f5e3e020
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pie3-nacl.d
@@ -0,0 +1,14 @@
+#source: pie3.s
+#as: --64
+#ld: -pie -melf_x86_64
+#objdump: -dw
+#target: x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+0+ <_start>:
+ +0: 48 8d 05 f9 ff ff ff lea -0x7\(%rip\),%rax # 0 <_start>
+#pass
diff --git a/ld/testsuite/ld-x86-64/pie3.d b/ld/testsuite/ld-x86-64/pie3.d
new file mode 100644
index 0000000000..a200deb32e
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pie3.d
@@ -0,0 +1,13 @@
+#as: --64
+#ld: -pie -melf_x86_64
+#objdump: -dw
+#notarget: x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+0+191 <_start>:
+ +191: 48 8d 05 68 fe ff ff lea -0x198\(%rip\),%rax # 0 <_start-0x191>
+#pass
diff --git a/ld/testsuite/ld-x86-64/pie3.s b/ld/testsuite/ld-x86-64/pie3.s
new file mode 100644
index 0000000000..72914d9134
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pie3.s
@@ -0,0 +1,5 @@
+ .text
+ .global _start
+ .weak foo
+_start:
+ leaq foo(%rip), %rax
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 9b83e1c5ce..c582582297 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -310,6 +310,8 @@ run_dump_test "pr14207"
run_dump_test "gotplt1"
run_dump_test "pie1"
run_dump_test "pie2"
+run_dump_test "pie3"
+run_dump_test "pie3-nacl"
run_dump_test "pic1"
run_dump_test "largecomm-1a"
run_dump_test "largecomm-1b"
--
2.13.0