x86: Suggest -fPIE when not building shared object
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 17 Apr 2019 17:22:19 +0000 (10:22 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 17 Apr 2019 17:25:28 +0000 (10:25 -0700)
When PIC is needed, linker should suggest -fPIE, instead of -fPIC, when
not building shared object.

bfd/

* elf64-x86-64.c (elf_x86_64_need_pic): Suggest -fPIE when not
building shared object.
* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Likewise.

ld/

* testsuite/ld-i386/i386.exp: Run pr18801a and pr18801b instead
of pr18801.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-i386/pr18801.d: Removed.
* testsuite/ld-x86-64/pr18801.d: Likewise.
* testsuite/ld-i386/pr18801a.d: New file.
* testsuite/ld-i386/pr18801b.d: Likewise.
* testsuite/ld-x86-64/pr18801a.d: Likewise.
* testsuite/ld-x86-64/pr18801b.d: Likewise.
* testsuite/ld-x86-64/pie2.d: Suggest -fPIE instead of -fPIC.
* testsuite/ld-x86-64/pie2.d: Likewise.
* testsuite/ld-x86-64/pr19719.d: Likewise.
* testsuite/ld-x86-64/pr19807-2a.d: Likewise.
* testsuite/ld-x86-64/pr19969.d: Likewise.
* testsuite/ld-x86-64/pr21997-1a.err: Likewise.
* testsuite/ld-x86-64/pr21997-1b.err: Likewise.
* testsuite/ld-x86-64/pr22001-1a.err: Likewise.
* testsuite/ld-x86-64/pr22001-1b.err: Likewise.
* testsuite/ld-x86-64/pr22791-1.err: Likewise.

21 files changed:
bfd/ChangeLog
bfd/elf64-x86-64.c
bfd/elfxx-x86.c
ld/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr18801.d [deleted file]
ld/testsuite/ld-i386/pr18801a.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr18801b.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pie2.d
ld/testsuite/ld-x86-64/pr18801.d [deleted file]
ld/testsuite/ld-x86-64/pr18801a.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr18801b.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr19719.d
ld/testsuite/ld-x86-64/pr19807-2a.d
ld/testsuite/ld-x86-64/pr19969.d
ld/testsuite/ld-x86-64/pr21997-1a.err
ld/testsuite/ld-x86-64/pr21997-1b.err
ld/testsuite/ld-x86-64/pr22001-1a.err
ld/testsuite/ld-x86-64/pr22001-1b.err
ld/testsuite/ld-x86-64/pr22791-1.err
ld/testsuite/ld-x86-64/x86-64.exp

index 2d1c14faff996e3ed53d95e33e33f1779d55803d..e61981f86b06d60fe3ad3ea8e076d1b5cacb385c 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf64-x86-64.c (elf_x86_64_need_pic): Suggest -fPIE when not
+       building shared object.
+       * elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Likewise.
+
 2019-04-17  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/24458
index 27e23a0793e1d9261e6986c1bd4267f63d6f464e..2f6923927f998d8d03d31495bab82198de4f7b15 100644 (file)
@@ -1422,7 +1422,7 @@ elf_x86_64_need_pic (struct bfd_link_info *info,
            v = _("protected symbol ");
          else
            v = _("symbol ");
-         pic = _("; recompile with -fPIC");
+         pic = NULL;
          break;
        }
 
@@ -1432,15 +1432,24 @@ elf_x86_64_need_pic (struct bfd_link_info *info,
   else
     {
       name = bfd_elf_sym_name (input_bfd, symtab_hdr, isym, NULL);
-      pic = _("; recompile with -fPIC");
+      pic = NULL;
     }
 
   if (bfd_link_dll (info))
-    object = _("a shared object");
-  else if (bfd_link_pie (info))
-    object = _("a PIE object");
+    {
+      object = _("a shared object");
+      if (!pic)
+       pic = _("; recompile with -fPIC");
+    }
   else
-    object = _("a PDE object");
+    {
+      if (bfd_link_pie (info))
+       object = _("a PIE object");
+      else
+       object = _("a PDE object");
+      if (!pic)
+       pic = _("; recompile with -fPIE");
+    }
 
   /* xgettext:c-format */
   _bfd_error_handler (_("%pB: relocation %s against %s%s`%s' can "
index e661ad30c121ce32a7c13d917d5091d38093ddad..78ed41ad381f771ce0e6d17decf224d6bb6894df 100644 (file)
@@ -1381,7 +1381,8 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd,
                {
                  info->callbacks->einfo
                    (_("%P%X: read-only segment has dynamic IFUNC relocations;"
-                      " recompile with -fPIC\n"));
+                      " recompile with %s\n"),
+                    bfd_link_dll (info) ? "-fPIC" : "-fPIE");
                  bfd_set_error (bfd_error_bad_value);
                  return FALSE;
                }
index 0fae659df4535bd67804b774993d96b898340fd7..c1632c292e44f7422706be058a45e3d131df44db 100644 (file)
@@ -1,3 +1,25 @@
+2019-04-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * testsuite/ld-i386/i386.exp: Run pr18801a and pr18801b instead
+       of pr18801.
+       * testsuite/ld-x86-64/x86-64.exp: Likewise.
+       * testsuite/ld-i386/pr18801.d: Removed.
+       * testsuite/ld-x86-64/pr18801.d: Likewise.
+       * testsuite/ld-i386/pr18801a.d: New file.
+       * testsuite/ld-i386/pr18801b.d: Likewise.
+       * testsuite/ld-x86-64/pr18801a.d: Likewise.
+       * testsuite/ld-x86-64/pr18801b.d: Likewise.
+       * testsuite/ld-x86-64/pie2.d: Suggest -fPIE instead of -fPIC.
+       * testsuite/ld-x86-64/pie2.d: Likewise.
+       * testsuite/ld-x86-64/pr19719.d: Likewise.
+       * testsuite/ld-x86-64/pr19807-2a.d: Likewise.
+       * testsuite/ld-x86-64/pr19969.d: Likewise.
+       * testsuite/ld-x86-64/pr21997-1a.err: Likewise.
+       * testsuite/ld-x86-64/pr21997-1b.err: Likewise.
+       * testsuite/ld-x86-64/pr22001-1a.err: Likewise.
+       * testsuite/ld-x86-64/pr22001-1b.err: Likewise.
+       * testsuite/ld-x86-64/pr22791-1.err: Likewise.
+
 2019-04-17  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/24458
index e9c2cfb9f6b970ce7ce661fcb3fabaa9008eeefa..9579df653ea31340505eae33975240b247741363 100644 (file)
@@ -512,7 +512,8 @@ run_dump_test "pr14215"
 run_dump_test "pr17057"
 run_dump_test "pr17935-1"
 run_dump_test "pr17935-2"
-run_dump_test "pr18801"
+run_dump_test "pr18801a"
+run_dump_test "pr18801b"
 run_dump_test "pr18815"
 run_dump_test "pr19939a"
 run_dump_test "pr19939b"
diff --git a/ld/testsuite/ld-i386/pr18801.d b/ld/testsuite/ld-i386/pr18801.d
deleted file mode 100644 (file)
index 4bb2efb..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#as: --32
-#ld: -m elf_i386 -pie
-#error: read-only segment has dynamic IFUNC relocations; recompile with -fPIC
diff --git a/ld/testsuite/ld-i386/pr18801a.d b/ld/testsuite/ld-i386/pr18801a.d
new file mode 100644 (file)
index 0000000..f8dc3f1
--- /dev/null
@@ -0,0 +1,4 @@
+#source: pr18801.s
+#as: --32
+#ld: -m elf_i386 -pie
+#error: read-only segment has dynamic IFUNC relocations; recompile with -fPIE
diff --git a/ld/testsuite/ld-i386/pr18801b.d b/ld/testsuite/ld-i386/pr18801b.d
new file mode 100644 (file)
index 0000000..f1d5c8d
--- /dev/null
@@ -0,0 +1,4 @@
+#source: pr18801.s
+#as: --32
+#ld: -m elf_i386 -shared
+#error: read-only segment has dynamic IFUNC relocations; recompile with -fPIC
index 95321414c52c8c63c62078457672770d784c3c83..37ca9ddb4fa62cc8db07d0e199974601ccf3b18a 100644 (file)
@@ -1,3 +1,3 @@
 #as: --64
 #ld: -pie -melf_x86_64
-#error: .*relocation R_X86_64_32 against symbol `foo' can not be used when making a PIE object; recompile with -fPIC
+#error: .*relocation R_X86_64_32 against symbol `foo' can not be used when making a PIE object; recompile with -fPIE
diff --git a/ld/testsuite/ld-x86-64/pr18801.d b/ld/testsuite/ld-x86-64/pr18801.d
deleted file mode 100644 (file)
index 459db6b..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#as: --64
-#ld: -melf_x86_64 -pie
-#error: read-only segment has dynamic IFUNC relocations; recompile with -fPIC
diff --git a/ld/testsuite/ld-x86-64/pr18801a.d b/ld/testsuite/ld-x86-64/pr18801a.d
new file mode 100644 (file)
index 0000000..b527f04
--- /dev/null
@@ -0,0 +1,4 @@
+#source: pr18801.s
+#as: --64
+#ld: -melf_x86_64 -pie
+#error: read-only segment has dynamic IFUNC relocations; recompile with -fPIE
diff --git a/ld/testsuite/ld-x86-64/pr18801b.d b/ld/testsuite/ld-x86-64/pr18801b.d
new file mode 100644 (file)
index 0000000..7cdb2cd
--- /dev/null
@@ -0,0 +1,4 @@
+#source: pr18801.s
+#as: --64
+#ld: -melf_x86_64 -shared
+#error: read-only segment has dynamic IFUNC relocations; recompile with -fPIC
index 03cfc15c97df99e893c0c3f7f8f3c4da279481bc..b5220c79220526640e8dda0b151e88a04f750c83 100644 (file)
@@ -1,3 +1,3 @@
 #as: --64
 #ld: -pie -melf_x86_64
-#error: .*relocation R_X86_64_32 against undefined symbol `foo' can not be used when making a PIE object; recompile with -fPIC
+#error: .*relocation R_X86_64_32 against undefined symbol `foo' can not be used when making a PIE object; recompile with -fPIE
index c99852a97210c883017dd55d246ccf548b2a3b46..da044e3961b1c08dd1a88eab5f50958452ac16a6 100644 (file)
@@ -1,4 +1,4 @@
 #source: pr19807-2.s
 #as: --64
 #ld: -pie -melf_x86_64
-#error: .*relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIC
+#error: .*relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIE
index 1aea67c93ede5ae78157eabef0b0ac445873b494..2bca08fd7783b1a8069dcbc2da025a5b880f7f1b 100644 (file)
@@ -1,4 +1,4 @@
 #source: pr19969b.S
 #as: --64
 #ld: -melf_x86_64 tmpdir/pr19969.so
-#error: .*relocation R_X86_64_32 against symbol `foo' can not be used when making a PDE object; recompile with -fPIC
+#error: .*relocation R_X86_64_32 against symbol `foo' can not be used when making a PDE object; recompile with -fPIE
index 5d663a31c302c975f09e91f4e28afb61c9521d40..e57ebd1f4613333eaeb13717890f046a08f8261e 100644 (file)
@@ -1,2 +1,2 @@
-.*relocation R_X86_64_PC32 against protected symbol `protected' can not be used when making a P(D|I)E object; recompile with -fPIC
+.*relocation R_X86_64_PC32 against protected symbol `protected' can not be used when making a P(D|I)E object; recompile with -fPIE
 #...
index 365de67167ce0b7ac904526331b4adfb2481d38f..a99fc1d5149e6a227cb8643312a3db88c71ea088 100644 (file)
@@ -1,2 +1,2 @@
-.*relocation R_X86_64_32S against protected symbol `protected' can not be used when making a P(D|I)E object; recompile with -fPIC
+.*relocation R_X86_64_32S against protected symbol `protected' can not be used when making a P(D|I)E object; recompile with -fPIE
 #...
index 640aa072b86a551a44342be76721b6aa738d2467..0cd41704e04c6fd3390e5011bf83eadb3214f515 100644 (file)
@@ -1,2 +1,2 @@
-.*relocation R_X86_64_PC32 against symbol `copy' can not be used when making a P(D|I)E object; recompile with -fPIC
+.*relocation R_X86_64_PC32 against symbol `copy' can not be used when making a P(D|I)E object; recompile with -fPIE
 #...
index 9617e73f58c835d309792b081e1d9819def564c7..e9a80e3c8db27b9c45b81461b25d7b740c77a7d4 100644 (file)
@@ -1,2 +1,2 @@
-.*relocation R_X86_64_32S against symbol `copy' can not be used when making a P(D|I)E object; recompile with -fPIC
+.*relocation R_X86_64_32S against symbol `copy' can not be used when making a P(D|I)E object; recompile with -fPIE
 #...
index 5500fa55ce660e31d10cc69509881019bbf62f00..8c5565992e78fb0e06d9d2ef49eedf25bcbbd020 100644 (file)
@@ -1,2 +1,2 @@
-.*relocation R_X86_64_PC32 against symbol `foo' can not be used when making a PIE object; recompile with -fPIC
+.*relocation R_X86_64_PC32 against symbol `foo' can not be used when making a PIE object; recompile with -fPIE
 #...
index 7ebc4613eedf8aaf0cce8e40421deba0b0a5f518..98aa4b04d8bee13afda8deafa7713153fa2b383e 100644 (file)
@@ -566,7 +566,8 @@ run_dump_test "pr17935-1"
 run_dump_test "pr17935-2"
 run_dump_test "pr18160"
 run_dump_test "pr18176"
-run_dump_test "pr18801"
+run_dump_test "pr18801a"
+run_dump_test "pr18801b"
 run_dump_test "pr18815"
 run_dump_test "pr19013"
 run_dump_test "pr19013-x32"