aboutsummaryrefslogtreecommitdiff
path: root/gold/target-reloc.h
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@gmail.com>2018-04-06 16:06:16 -0700
committerCary Coutant <ccoutant@gmail.com>2018-04-06 22:50:14 -0700
commit43193fe9fc39138c912095ba6f21c4302abafe5e (patch)
treeeeb5ed5dd17f654c78a0ef45cde2ac7c442d40b6 /gold/target-reloc.h
parentef4bf13b1f47b59b69335178367734dfc9ad166e (diff)
downloadfsf-binutils-gdb-43193fe9fc39138c912095ba6f21c4302abafe5e.zip
fsf-binutils-gdb-43193fe9fc39138c912095ba6f21c4302abafe5e.tar.gz
fsf-binutils-gdb-43193fe9fc39138c912095ba6f21c4302abafe5e.tar.bz2
Further improve warnings for relocations referring to discarded sections.
Relocations referring to discarded sections are now treated as errors instead of warnings. Also with this patch, we will now print the section group signature and the object file with the prevailing definition of that group along with the name of the symbol that the relocation is referring to. This additional information should be much more useful to anyone trying to track down the source of such errors. To do so, we now map each discarded section to the Kept_section info in the Layout class, and defer the logic that maps a discarded section to its counterpart in the kept group. This gives us the information we need to identify the signature symbol given the discarded section, and the name of the object file that provided the prevailing (i.e., first) definition of that group. gold/ * object.cc (Sized_relobj_file::include_section_group): Store reference to Kept_section info for discarded comdat sections regardless of size. Move size checking to map_to_kept_section. (Sized_relobj_file::include_linkonce_section): Likewise. (Sized_relobj_file::map_to_kept_section): Add section name parameter. Insert size checking logic from above functions. (Sized_relobj_file::find_kept_section_object): New method. (Sized_relobj_file::get_symbol_name): New method. * object.h (Sized_relobj_file::map_to_kept_section): Add section_name parameter. Adjust all callers. (Sized_relobj_file::find_kept_section_object): New method. (Sized_relobj_file::get_symbol_name): New method. (Sized_relobj_file::Kept_comdat_section): Replace object and shndx fields with sh_size, kept_section, symndx, and is_comdat fields. (Sized_relobj_file::set_kept_comdat_section): Replace kept_object and kept_shndx parameters with is_comdat, symndx, sh_size, and kept_section. (Sized_relobj_file::get_kept_comdat_section): Likewise. * target-reloc.h (enum Comdat_behavior): Change CB_WARNING to CB_ERROR. Adjust all references. (issue_undefined_symbol_error): New function template. (relocate_section): Pass section name to map_to_kept_section. Move discarded section code to new function above. * aarch64.cc (Target_aarch64::scan_reloc_section_for_stubs): Move declaration for gsym out one level. Call issue_discarded_error. * arm.cc (Target_arm::scan_reloc_section_for_stubs): Likewise. * powerpc.cc (Relocate_comdat_behavior): Change CB_WARNING to CB_ERROR.
Diffstat (limited to 'gold/target-reloc.h')
-rw-r--r--gold/target-reloc.h79
1 files changed, 54 insertions, 25 deletions
diff --git a/gold/target-reloc.h b/gold/target-reloc.h
index 36032fb..6bde51d 100644
--- a/gold/target-reloc.h
+++ b/gold/target-reloc.h
@@ -120,7 +120,7 @@ enum Comdat_behavior
CB_UNDETERMINED, // Not yet determined -- need to look at section name.
CB_PRETEND, // Attempt to map to the corresponding kept section.
CB_IGNORE, // Ignore the relocation.
- CB_WARNING // Print a warning.
+ CB_ERROR // Print an error.
};
class Default_comdat_behavior
@@ -138,7 +138,7 @@ class Default_comdat_behavior
if (strcmp(name, ".eh_frame") == 0
|| strcmp(name, ".gcc_except_table") == 0)
return CB_IGNORE;
- return CB_WARNING;
+ return CB_ERROR;
}
};
@@ -224,6 +224,52 @@ issue_undefined_symbol_error(const Symbol* sym)
return true;
}
+template<int size, bool big_endian>
+inline void
+issue_discarded_error(
+ const Relocate_info<size, big_endian>* relinfo,
+ size_t shndx,
+ section_offset_type offset,
+ unsigned int r_sym,
+ const Symbol* gsym)
+{
+ Sized_relobj_file<size, big_endian>* object = relinfo->object;
+
+ if (gsym == NULL)
+ {
+ gold_error_at_location(
+ relinfo, shndx, offset,
+ _("relocation refers to local symbol \"%s\" [%u], "
+ "which is defined in a discarded section"),
+ object->get_symbol_name(r_sym), r_sym);
+ }
+ else
+ {
+ gold_error_at_location(
+ relinfo, shndx, offset,
+ _("relocation refers to global symbol \"%s\", "
+ "which is defined in a discarded section"),
+ gsym->demangled_name().c_str());
+ }
+
+ bool is_ordinary;
+ typename elfcpp::Elf_types<size>::Elf_Addr value;
+ unsigned int orig_shndx = object->symbol_section_and_value(r_sym, &value,
+ &is_ordinary);
+ if (orig_shndx != elfcpp::SHN_UNDEF)
+ {
+ unsigned int key_symndx;
+ Relobj* kept_obj = object->find_kept_section_object(orig_shndx,
+ &key_symndx);
+ if (key_symndx != 0)
+ gold_info(_(" section group signature: \"%s\""),
+ object->get_symbol_name(key_symndx));
+ if (kept_obj != NULL)
+ gold_info(_(" prevailing definition is from %s"),
+ kept_obj->name().c_str());
+ }
+}
+
// This function implements the generic part of relocation processing.
// The template parameter Relocate must be a class type which provides
// a single function, relocate(), which implements the machine
@@ -360,11 +406,11 @@ relocate_section(
Symbol_value<size> symval2;
if (is_defined_in_discarded_section)
{
+ std::string name = object->section_name(relinfo->data_shndx);
+
if (comdat_behavior == CB_UNDETERMINED)
- {
- std::string name = object->section_name(relinfo->data_shndx);
comdat_behavior = relocate_comdat_behavior.get(name.c_str());
- }
+
if (comdat_behavior == CB_PRETEND)
{
// FIXME: This case does not work for global symbols.
@@ -374,7 +420,7 @@ relocate_section(
// script.
bool found;
typename elfcpp::Elf_types<size>::Elf_Addr value =
- object->map_to_kept_section(shndx, &found);
+ object->map_to_kept_section(shndx, name, &found);
if (found)
symval2.set_output_value(value + psymval->input_value());
else
@@ -382,25 +428,8 @@ relocate_section(
}
else
{
- if (comdat_behavior == CB_WARNING)
- {
- if (gsym == NULL)
- {
- gold_warning_at_location(
- relinfo, i, offset,
- _("relocation refers to local symbol %d "
- "defined in discarded section"),
- r_sym);
- }
- else
- {
- gold_warning_at_location(
- relinfo, i, offset,
- _("relocation refers to symbol \"%s\" "
- "defined in discarded section"),
- gsym->demangled_name().c_str());
- }
- }
+ if (comdat_behavior == CB_ERROR)
+ issue_discarded_error(relinfo, i, offset, r_sym, gsym);
symval2.set_output_value(0);
}
symval2.set_no_output_symtab_entry();