/* Rename some of the generic section flags to better document how they
are used here. */
-#define need_convert_load sec_flg0
+#define need_convert_load sec_flg0
+#define check_relocs_failed sec_flg1
+
+static bfd_boolean
+elf_x86_64_need_pic (bfd *input_bfd, asection *sec,
+ struct elf_link_hash_entry *h,
+ Elf_Internal_Shdr *symtab_hdr,
+ Elf_Internal_Sym *isym,
+ reloc_howto_type *howto)
+{
+ const char *v = "";
+ const char *und = "";
+ const char *pic = "";
+
+ const char *name;
+ if (h)
+ {
+ name = h->root.root.string;
+ switch (ELF_ST_VISIBILITY (h->other))
+ {
+ case STV_HIDDEN:
+ v = _("hidden symbol ");
+ break;
+ case STV_INTERNAL:
+ v = _("internal symbol ");
+ break;
+ case STV_PROTECTED:
+ v = _("protected symbol ");
+ break;
+ default:
+ v = _("symbol ");
+ pic = _("; recompile with -fPIC");
+ break;
+ }
+
+ if (!h->def_regular && !h->def_dynamic)
+ und = _("undefined ");
+ }
+ else
+ {
+ name = bfd_elf_sym_name (input_bfd, symtab_hdr, isym, NULL);
+ pic = _("; recompile with -fPIC");
+ }
+
+ (*_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);
+ bfd_set_error (bfd_error_bad_value);
+ sec->check_relocs_failed = 1;
+ return FALSE;
+}
/* Look through the relocs for a section during the first phase, and
calculate needed space in the global offset table, procedure
case R_X86_64_TPOFF32:
if (!bfd_link_executable (info) && ABI_64_P (abfd))
- {
- if (h)
- name = h->root.root.string;
- else
- name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
- NULL);
- (*_bfd_error_handler)
- (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
- abfd,
- x86_64_elf_howto_table[r_type].name, name);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
- }
+ return elf_x86_64_need_pic (abfd, sec, h, symtab_hdr, isym,
+ &x86_64_elf_howto_table[r_type]);
if (eh != NULL)
eh->has_got_reloc = 1;
break;
case R_X86_64_8:
case R_X86_64_16:
case R_X86_64_32S:
- /* Let's help debug shared library creation. These relocs
- cannot be used in shared libs. Don't error out for
+ /* Check relocation overflow as these relocs may lead to
+ run-time relocation overflow. Don't error out for
sections we don't care about, such as debug sections or
- non-constant sections, or when relocation overflow check
- is disabled. */
+ when relocation overflow check is disabled. */
if (!info->no_reloc_overflow_check
- && bfd_link_pic (info)
- && (sec->flags & SEC_ALLOC) != 0
- && (sec->flags & SEC_READONLY) != 0)
- {
- if (h)
- name = h->root.root.string;
- else
- name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
- (*_bfd_error_handler)
- (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
- abfd, x86_64_elf_howto_table[r_type].name, name);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
- }
+ && (bfd_link_pic (info)
+ || (bfd_link_executable (info)
+ && h != NULL
+ && !h->def_regular
+ && h->def_dynamic
+ && (sec->flags & SEC_READONLY) == 0))
+ && (sec->flags & SEC_ALLOC) != 0)
+ return elf_x86_64_need_pic (abfd, sec, h, symtab_hdr, isym,
+ &x86_64_elf_howto_table[r_type]);
/* Fall through. */
case R_X86_64_PC8:
&& (contents [offset - 1] & 0xf0) == 0x80));
}
-static bfd_boolean
-elf_x86_64_need_pic (bfd *input_bfd, struct elf_link_hash_entry *h,
- reloc_howto_type *howto)
-{
- const char *fmt;
- const char *v;
- const char *pic = "";
-
- switch (ELF_ST_VISIBILITY (h->other))
- {
- case STV_HIDDEN:
- v = _("hidden symbol");
- break;
- case STV_INTERNAL:
- v = _("internal symbol");
- break;
- case STV_PROTECTED:
- v = _("protected symbol");
- break;
- default:
- v = _("symbol");
- pic = _("; recompile with -fPIC");
- break;
- }
-
- if (h->def_regular)
- fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
- else
- fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
-
- (*_bfd_error_handler) (fmt, input_bfd, howto->name,
- v, h->root.root.string, pic);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
-}
-
/* Relocate an x86_64 ELF section. */
static bfd_boolean
BFD_ASSERT (is_x86_64_elf (input_bfd));
+ /* Skip if check_relocs failed. */
+ if (input_section->check_relocs_failed)
+ return FALSE;
+
htab = elf_x86_64_hash_table (info);
if (htab == NULL)
return FALSE;
}
if (fail)
- return elf_x86_64_need_pic (input_bfd, h, howto);
+ return elf_x86_64_need_pic (input_bfd, input_section,
+ h, NULL, NULL, howto);
}
/* Fall through. */
|| SYMBOLIC_BIND (info, h))
|| ! h->def_regular))
{
- if ((r_type != R_X86_64_PC64 && r_type != R_X86_64_64)
- && bfd_link_executable (info)
- && h->root.type == bfd_link_hash_undefweak
- && !resolved_to_zero)
- return elf_x86_64_need_pic (input_bfd, h, howto);
outrel.r_info = htab->r_info (h->dynindx, r_type);
outrel.r_addend = rel->r_addend;
}