X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gold%2Ftarget-reloc.h;h=039621c50ff5145a7043800f0bf66a61c93cac6f;hb=c3d399e712774f8c8e4cd6b6a5bb8230c42bc760;hp=fabc0a9f9186e4a0df1256da4796506782e704f3;hpb=191f1a2dccbc09da4c6cf7dc9b3ad5fa8520a4e8;p=deliverable%2Fbinutils-gdb.git diff --git a/gold/target-reloc.h b/gold/target-reloc.h index fabc0a9f91..039621c50f 100644 --- a/gold/target-reloc.h +++ b/gold/target-reloc.h @@ -1,6 +1,7 @@ // target-reloc.h -- target specific relocation support -*- C++ -*- -// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 +// Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -81,30 +82,25 @@ scan_relocs( unsigned int shndx = lsym.get_st_shndx(); bool is_ordinary; shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary); - if (is_ordinary - && shndx != elfcpp::SHN_UNDEF - && !object->is_section_included(shndx) - && !symtab->is_section_folded(object, shndx)) - { - // RELOC is a relocation against a local symbol in a - // section we are discarding. We can ignore this - // relocation. It will eventually become a reloc - // against the value zero. - // - // FIXME: We should issue a warning if this is an - // allocated section; is this the best place to do it? - // - // FIXME: The old GNU linker would in some cases look - // for the linkonce section which caused this section to - // be discarded, and, if the other section was the same - // size, change the reloc to refer to the other section. - // That seems risky and weird to me, and I don't know of - // any case where it is actually required. - - continue; - } + // If RELOC is a relocation against a local symbol in a + // section we are discarding then we can ignore it. It will + // eventually become a reloc against the value zero. + // + // FIXME: We should issue a warning if this is an + // allocated section; is this the best place to do it? + // + // FIXME: The old GNU linker would in some cases look + // for the linkonce section which caused this section to + // be discarded, and, if the other section was the same + // size, change the reloc to refer to the other section. + // That seems risky and weird to me, and I don't know of + // any case where it is actually required. + bool is_discarded = (is_ordinary + && shndx != elfcpp::SHN_UNDEF + && !object->is_section_included(shndx) + && !symtab->is_section_folded(object, shndx)); scan.local(symtab, layout, target, object, data_shndx, - output_section, reloc, r_type, lsym); + output_section, reloc, r_type, lsym, is_discarded); } else { @@ -129,20 +125,24 @@ enum Comdat_behavior CB_WARNING // Print a warning. }; -// Decide what the linker should do for relocations that refer to discarded -// comdat sections. This decision is based on the name of the section being -// relocated. - -inline Comdat_behavior -get_comdat_behavior(const char* name) +class Default_comdat_behavior { - if (Layout::is_debug_info_section(name)) - return CB_PRETEND; - if (strcmp(name, ".eh_frame") == 0 - || strcmp(name, ".gcc_except_table") == 0) - return CB_IGNORE; - return CB_WARNING; -} + public: + // Decide what the linker should do for relocations that refer to + // discarded comdat sections. This decision is based on the name of + // the section being relocated. + + inline Comdat_behavior + get(const char* name) + { + if (Layout::is_debug_info_section(name)) + return CB_PRETEND; + if (strcmp(name, ".eh_frame") == 0 + || strcmp(name, ".gcc_except_table") == 0) + return CB_IGNORE; + return CB_WARNING; + } +}; // Give an error for a symbol with non-default visibility which is not // defined locally. @@ -176,13 +176,48 @@ visibility_error(const Symbol* sym) inline bool issue_undefined_symbol_error(const Symbol* sym) { - return (sym != NULL - && (sym->is_undefined() || sym->is_placeholder()) - && sym->binding() != elfcpp::STB_WEAK - && !sym->is_defined_in_discarded_section() - && !parameters->target().is_defined_by_abi(sym) - && (!parameters->options().shared() - || parameters->options().defs())); + // We only report global symbols. + if (sym == NULL) + return false; + + // We only report undefined symbols. + if (!sym->is_undefined() && !sym->is_placeholder()) + return false; + + // We don't report weak symbols. + if (sym->binding() == elfcpp::STB_WEAK) + return false; + + // We don't report symbols defined in discarded sections. + if (sym->is_defined_in_discarded_section()) + return false; + + // If the target defines this symbol, don't report it here. + if (parameters->target().is_defined_by_abi(sym)) + return false; + + // See if we've been told to ignore whether this symbol is + // undefined. + const char* const u = parameters->options().unresolved_symbols(); + if (u != NULL) + { + if (strcmp(u, "ignore-all") == 0) + return false; + if (strcmp(u, "report-all") == 0) + return true; + if (strcmp(u, "ignore-in-object-files") == 0 && !sym->in_dyn()) + return false; + if (strcmp(u, "ignore-in-shared-libs") == 0 && !sym->in_reg()) + return false; + } + + // When creating a shared library, only report unresolved symbols if + // -z defs was used. + if (parameters->options().shared() && !parameters->options().defs()) + return false; + + // Otherwise issue a warning. + return true; } // This function implements the generic part of relocation processing. @@ -190,6 +225,11 @@ issue_undefined_symbol_error(const Symbol* sym) // a single function, relocate(), which implements the machine // specific part of a relocation. +// The template parameter Relocate_comdat_behavior is a class type +// which provides a single function, get(), which determines what the +// linker should do for relocations that refer to discarded comdat +// sections. + // SIZE is the ELF size: 32 or 64. BIG_ENDIAN is the endianness of // the data. SH_TYPE is the section type: SHT_REL or SHT_RELA. // RELOCATE implements operator() to do a relocation. @@ -211,7 +251,8 @@ issue_undefined_symbol_error(const Symbol* sym) // relocation. template + typename Relocate, + typename Relocate_comdat_behavior> inline void relocate_section( const Relocate_info* relinfo, @@ -228,6 +269,7 @@ relocate_section( typedef typename Reloc_types::Reloc Reltype; const int reloc_size = Reloc_types::reloc_size; Relocate relocate; + Relocate_comdat_behavior relocate_comdat_behavior; Sized_relobj_file* object = relinfo->object; unsigned int local_count = object->local_symbol_count(); @@ -270,7 +312,7 @@ relocate_section( // If the local symbol belongs to a section we are discarding, // and that section is a debug section, try to find the // corresponding kept section and map this symbol to its - // counterpart in the kept section. The symbol must not + // counterpart in the kept section. The symbol must not // correspond to a section we are folding. bool is_ordinary; shndx = psymval->input_shndx(&is_ordinary); @@ -318,7 +360,7 @@ relocate_section( if (comdat_behavior == CB_UNDETERMINED) { std::string name = object->section_name(relinfo->data_shndx); - comdat_behavior = get_comdat_behavior(name.c_str()); + comdat_behavior = relocate_comdat_behavior.get(name.c_str()); } if (comdat_behavior == CB_PRETEND) { @@ -388,17 +430,17 @@ apply_relocation(const Relocate_info* relinfo, section_size_type view_size) { // Construct the ELF relocation in a temporary buffer. - const int reloc_size = elfcpp::Elf_sizes<64>::rela_size; + const int reloc_size = elfcpp::Elf_sizes::rela_size; unsigned char relbuf[reloc_size]; - elfcpp::Rela<64, false> rel(relbuf); - elfcpp::Rela_write<64, false> orel(relbuf); + elfcpp::Rela rel(relbuf); + elfcpp::Rela_write orel(relbuf); orel.put_r_offset(r_offset); - orel.put_r_info(elfcpp::elf_r_info<64>(0, r_type)); + orel.put_r_info(elfcpp::elf_r_info(0, r_type)); orel.put_r_addend(r_addend); // Setup a Symbol_value for the global symbol. - const Sized_symbol<64>* sym = static_cast*>(gsym); - Symbol_value<64> symval; + const Sized_symbol* sym = static_cast*>(gsym); + Symbol_value symval; gold_assert(sym->has_symtab_index() && sym->symtab_index() != -1U); symval.set_output_symtab_index(sym->symtab_index()); symval.set_output_value(sym->value()); @@ -555,17 +597,17 @@ scan_relocatable_relocs( } } -// Relocate relocs during a relocatable link. This is a default -// definition which should work for most targets. +// Relocate relocs. Called for a relocatable link, and for --emit-relocs. +// This is a default definition which should work for most targets. template void -relocate_for_relocatable( +relocate_relocs( const Relocate_info* relinfo, const unsigned char* prelocs, size_t reloc_count, Output_section* output_section, - typename elfcpp::Elf_types::Elf_Addr offset_in_output_section, + typename elfcpp::Elf_types::Elf_Off offset_in_output_section, const Relocatable_relocs* rr, unsigned char* view, typename elfcpp::Elf_types::Elf_Addr view_address, @@ -634,6 +676,7 @@ relocate_for_relocatable( case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2: case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4: case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8: + case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4_UNALIGNED: { // We are adjusting a section symbol. We need to find // the symbol table index of the section symbol for @@ -755,6 +798,12 @@ relocate_for_relocatable( psymval); break; + case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4_UNALIGNED: + Relocate_functions::rel32_unaligned(padd, + object, + psymval); + break; + default: gold_unreachable(); }