From aab921adcb656e4eefcc7d0f14241f3d7504400e Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 23 Aug 2017 13:40:49 -0700 Subject: [PATCH] x86-64: Properly report output type when PIC is needed -fPIC may be needed to compile PIE or PDE objects, not just shared object. bfd/ * elf64-x86-64.c (elf_x86_64_need_pic): Add an argument for bfd_link_info. Report shared, PIE or PDE object based on bfd_link_info. (elf_x86_64_check_relocs): Update elf_x86_64_need_pic call. (elf_x86_64_relocate_section): Likewise. ld/ * testsuite/ld-x86-64/pie2.d: Updated. * testsuite/ld-x86-64/pr19719.d: Likewise. * testsuite/ld-x86-64/pr19807-2a.d: Likewise. * testsuite/ld-x86-64/pr19969.d: Likewise. --- bfd/ChangeLog | 8 ++++++++ bfd/elf64-x86-64.c | 22 ++++++++++++++++------ ld/ChangeLog | 7 +++++++ ld/testsuite/ld-x86-64/pie2.d | 2 +- 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 +- 7 files changed, 35 insertions(+), 10 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index db93894511..9cb390c25d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2017-08-23 H.J. Lu + + * elf64-x86-64.c (elf_x86_64_need_pic): Add an argument for + bfd_link_info. Report shared, PIE or PDE object based on + bfd_link_info. + (elf_x86_64_check_relocs): Update elf_x86_64_need_pic call. + (elf_x86_64_relocate_section): Likewise. + 2017-08-23 H.J. Lu * elf32-i386.c (elf_i386_check_relocs): Increment PLT count only diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 3dc2c356c4..775c911307 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -1880,7 +1880,8 @@ elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd, #define check_relocs_failed sec_flg1 static bfd_boolean -elf_x86_64_need_pic (bfd *input_bfd, asection *sec, +elf_x86_64_need_pic (struct bfd_link_info *info, + bfd *input_bfd, asection *sec, struct elf_link_hash_entry *h, Elf_Internal_Shdr *symtab_hdr, Elf_Internal_Sym *isym, @@ -1889,6 +1890,7 @@ elf_x86_64_need_pic (bfd *input_bfd, asection *sec, const char *v = ""; const char *und = ""; const char *pic = ""; + const char *object; const char *name; if (h) @@ -1920,10 +1922,18 @@ elf_x86_64_need_pic (bfd *input_bfd, asection *sec, pic = _("; recompile with -fPIC"); } + if (bfd_link_dll (info)) + object = _("a shared object"); + else if (bfd_link_pie (info)) + object = _("a PIE object"); + else + object = _("a PDE object"); + /* xgettext:c-format */ _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can " - "not be used when making a shared object%s"), - input_bfd, howto->name, und, v, name, pic); + "not be used when making %s%s"), + input_bfd, howto->name, und, v, name, + object, pic); bfd_set_error (bfd_error_bad_value); sec->check_relocs_failed = 1; return FALSE; @@ -2519,7 +2529,7 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, case R_X86_64_TPOFF32: if (!bfd_link_executable (info) && ABI_64_P (abfd)) - return elf_x86_64_need_pic (abfd, sec, h, symtab_hdr, isym, + return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym, &x86_64_elf_howto_table[r_type]); if (eh != NULL) eh->has_got_reloc = 1; @@ -2685,7 +2695,7 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, && !h->def_regular && h->def_dynamic && (sec->flags & SEC_READONLY) == 0))) - return elf_x86_64_need_pic (abfd, sec, h, symtab_hdr, isym, + return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym, &x86_64_elf_howto_table[r_type]); /* Fall through. */ @@ -4966,7 +4976,7 @@ do_ifunc_pointer: } if (fail) - return elf_x86_64_need_pic (input_bfd, input_section, + return elf_x86_64_need_pic (info, input_bfd, input_section, h, NULL, NULL, howto); } /* Fall through. */ diff --git a/ld/ChangeLog b/ld/ChangeLog index c499de7cd8..bd732799cd 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2017-08-23 H.J. Lu + + * testsuite/ld-x86-64/pie2.d: Updated. + * testsuite/ld-x86-64/pr19719.d: Likewise. + * testsuite/ld-x86-64/pr19807-2a.d: Likewise. + * testsuite/ld-x86-64/pr19969.d: Likewise. + 2017-08-23 H.J. Lu * testsuite/ld-i386/i386.exp: Run protected7. diff --git a/ld/testsuite/ld-x86-64/pie2.d b/ld/testsuite/ld-x86-64/pie2.d index ef9f58acb7..95321414c5 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 shared object; recompile with -fPIC +#error: .*relocation R_X86_64_32 against symbol `foo' can not be used when making a PIE object; recompile with -fPIC diff --git a/ld/testsuite/ld-x86-64/pr19719.d b/ld/testsuite/ld-x86-64/pr19719.d index b2daf0e3c9..03cfc15c97 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 shared 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 -fPIC diff --git a/ld/testsuite/ld-x86-64/pr19807-2a.d b/ld/testsuite/ld-x86-64/pr19807-2a.d index 1357d72f4c..c99852a972 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 shared object; recompile with -fPIC +#error: .*relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIC diff --git a/ld/testsuite/ld-x86-64/pr19969.d b/ld/testsuite/ld-x86-64/pr19969.d index c56af2ff1f..1aea67c93e 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 shared object; recompile with -fPIC +#error: .*relocation R_X86_64_32 against symbol `foo' can not be used when making a PDE object; recompile with -fPIC -- 2.34.1