x86-64: Limit PIC check to shared library build
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 17 Jul 2017 19:17:59 +0000 (12:17 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 17 Jul 2017 19:17:59 +0000 (12:17 -0700)
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.

bfd/elf64-x86-64.c
ld/testsuite/ld-x86-64/pie3-nacl.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pie3.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pie3.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index 79bc9fbecff502fd3c6182d52bba197bd6e2b00e..3658df456238e6fc973c30a8f860097f1b839838 100644 (file)
@@ -4968,9 +4968,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/testsuite/ld-x86-64/pie3-nacl.d b/ld/testsuite/ld-x86-64/pie3-nacl.d
new file mode 100644 (file)
index 0000000..59f5e3e
--- /dev/null
@@ -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 (file)
index 0000000..a200deb
--- /dev/null
@@ -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 (file)
index 0000000..72914d9
--- /dev/null
@@ -0,0 +1,5 @@
+       .text
+       .global _start
+       .weak foo
+_start:
+       leaq    foo(%rip), %rax
index 9b83e1c5ce8d84fd111ec40c9a7b60371f53ef43..c582582297862de40954c7a6e0931a51e98ed0ac 100644 (file)
@@ -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"