[PATCH] x86: Suggest -fPIE when not building shared object
H.J. Lu
hjl.tools@gmail.com
Wed Apr 17 17:26:00 GMT 2019
More information about the Binutils mailing list
Wed Apr 17 17:26:00 GMT 2019
- Previous message (by thread): [PATCH, BFD, AArch64] Improve bti/pac plts.
- Next message (by thread): [PATCH] [MSP430] [GAS] Define symbols for functions to run through .{preinit,init,fini}_array sections
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
---
bfd/ChangeLog | 6 +++++
bfd/elf64-x86-64.c | 21 +++++++++++++-----
bfd/elfxx-x86.c | 3 ++-
ld/ChangeLog | 22 +++++++++++++++++++
ld/testsuite/ld-i386/i386.exp | 3 ++-
.../ld-i386/{pr18801.d => pr18801a.d} | 3 ++-
ld/testsuite/ld-i386/pr18801b.d | 4 ++++
ld/testsuite/ld-x86-64/pie2.d | 2 +-
.../ld-x86-64/{pr18801.d => pr18801a.d} | 3 ++-
ld/testsuite/ld-x86-64/pr18801b.d | 4 ++++
ld/testsuite/ld-x86-64/pr19719.d | 2 +-
ld/testsuite/ld-x86-64/pr19807-2a.d | 2 +-
ld/testsuite/ld-x86-64/pr19969.d | 2 +-
ld/testsuite/ld-x86-64/pr21997-1a.err | 2 +-
ld/testsuite/ld-x86-64/pr21997-1b.err | 2 +-
ld/testsuite/ld-x86-64/pr22001-1a.err | 2 +-
ld/testsuite/ld-x86-64/pr22001-1b.err | 2 +-
ld/testsuite/ld-x86-64/pr22791-1.err | 2 +-
ld/testsuite/ld-x86-64/x86-64.exp | 3 ++-
19 files changed, 70 insertions(+), 20 deletions(-)
rename ld/testsuite/ld-i386/{pr18801.d => pr18801a.d} (74%)
create mode 100644 ld/testsuite/ld-i386/pr18801b.d
rename ld/testsuite/ld-x86-64/{pr18801.d => pr18801a.d} (74%)
create mode 100644 ld/testsuite/ld-x86-64/pr18801b.d
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 2d1c14faff..e61981f86b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 27e23a0793..2f6923927f 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -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 "
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index e661ad30c1..78ed41ad38 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -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;
}
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 0fae659df4..c1632c292e 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index e9c2cfb9f6..9579df653e 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -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/pr18801a.d
similarity index 74%
rename from ld/testsuite/ld-i386/pr18801.d
rename to ld/testsuite/ld-i386/pr18801a.d
index 4bb2efb9f7..f8dc3f170b 100644
--- a/ld/testsuite/ld-i386/pr18801.d
+++ b/ld/testsuite/ld-i386/pr18801a.d
@@ -1,3 +1,4 @@
+#source: pr18801.s
#as: --32
#ld: -m elf_i386 -pie
-#error: read-only segment has dynamic IFUNC relocations; recompile with -fPIC
+#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
index 0000000000..f1d5c8daee
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr18801b.d
@@ -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
diff --git a/ld/testsuite/ld-x86-64/pie2.d b/ld/testsuite/ld-x86-64/pie2.d
index 95321414c5..37ca9ddb4f 100644
--- a/ld/testsuite/ld-x86-64/pie2.d
+++ b/ld/testsuite/ld-x86-64/pie2.d
@@ -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/pr18801a.d
similarity index 74%
rename from ld/testsuite/ld-x86-64/pr18801.d
rename to ld/testsuite/ld-x86-64/pr18801a.d
index 459db6bb29..b527f04250 100644
--- a/ld/testsuite/ld-x86-64/pr18801.d
+++ b/ld/testsuite/ld-x86-64/pr18801a.d
@@ -1,3 +1,4 @@
+#source: pr18801.s
#as: --64
#ld: -melf_x86_64 -pie
-#error: read-only segment has dynamic IFUNC relocations; recompile with -fPIC
+#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
index 0000000000..7cdb2cd17d
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr18801b.d
@@ -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
diff --git a/ld/testsuite/ld-x86-64/pr19719.d b/ld/testsuite/ld-x86-64/pr19719.d
index 03cfc15c97..b5220c7922 100644
--- a/ld/testsuite/ld-x86-64/pr19719.d
+++ b/ld/testsuite/ld-x86-64/pr19719.d
@@ -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
diff --git a/ld/testsuite/ld-x86-64/pr19807-2a.d b/ld/testsuite/ld-x86-64/pr19807-2a.d
index c99852a972..da044e3961 100644
--- a/ld/testsuite/ld-x86-64/pr19807-2a.d
+++ b/ld/testsuite/ld-x86-64/pr19807-2a.d
@@ -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
diff --git a/ld/testsuite/ld-x86-64/pr19969.d b/ld/testsuite/ld-x86-64/pr19969.d
index 1aea67c93e..2bca08fd77 100644
--- a/ld/testsuite/ld-x86-64/pr19969.d
+++ b/ld/testsuite/ld-x86-64/pr19969.d
@@ -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
diff --git a/ld/testsuite/ld-x86-64/pr21997-1a.err b/ld/testsuite/ld-x86-64/pr21997-1a.err
index 5d663a31c3..e57ebd1f46 100644
--- a/ld/testsuite/ld-x86-64/pr21997-1a.err
+++ b/ld/testsuite/ld-x86-64/pr21997-1a.err
@@ -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
#...
diff --git a/ld/testsuite/ld-x86-64/pr21997-1b.err b/ld/testsuite/ld-x86-64/pr21997-1b.err
index 365de67167..a99fc1d514 100644
--- a/ld/testsuite/ld-x86-64/pr21997-1b.err
+++ b/ld/testsuite/ld-x86-64/pr21997-1b.err
@@ -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
#...
diff --git a/ld/testsuite/ld-x86-64/pr22001-1a.err b/ld/testsuite/ld-x86-64/pr22001-1a.err
index 640aa072b8..0cd41704e0 100644
--- a/ld/testsuite/ld-x86-64/pr22001-1a.err
+++ b/ld/testsuite/ld-x86-64/pr22001-1a.err
@@ -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
#...
diff --git a/ld/testsuite/ld-x86-64/pr22001-1b.err b/ld/testsuite/ld-x86-64/pr22001-1b.err
index 9617e73f58..e9a80e3c8d 100644
--- a/ld/testsuite/ld-x86-64/pr22001-1b.err
+++ b/ld/testsuite/ld-x86-64/pr22001-1b.err
@@ -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
#...
diff --git a/ld/testsuite/ld-x86-64/pr22791-1.err b/ld/testsuite/ld-x86-64/pr22791-1.err
index 5500fa55ce..8c5565992e 100644
--- a/ld/testsuite/ld-x86-64/pr22791-1.err
+++ b/ld/testsuite/ld-x86-64/pr22791-1.err
@@ -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
#...
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 7ebc4613ee..98aa4b04d8 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -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"
--
2.20.1
- Previous message (by thread): [PATCH, BFD, AArch64] Improve bti/pac plts.
- Next message (by thread): [PATCH] [MSP430] [GAS] Define symbols for functions to run through .{preinit,init,fini}_array sections
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list