diff --git a/gold/gc.cc b/gold/gc.cc index 08a2bba..eff4968 100644 --- a/gold/gc.cc +++ b/gold/gc.cc @@ -38,7 +38,7 @@ Garbage_collection::do_transitive_closure() { // Add elements from the work list to the referenced list // one by one. - Section_id entry = this->worklist().back(); + Rel_section_id entry = this->worklist().back(); this->worklist().pop_back(); if (!this->referenced_list().insert(entry).second) continue; diff --git a/gold/gc.h b/gold/gc.h index bf4023d..9723e3f 100644 --- a/gold/gc.h +++ b/gold/gc.h @@ -49,9 +49,9 @@ class Garbage_collection { public: - typedef Unordered_set Sections_reachable; - typedef std::map Section_ref; - typedef std::vector Worklist_type; + typedef Unordered_set Sections_reachable; + typedef std::map Section_ref; + typedef std::vector Worklist_type; // This maps the name of the section which can be represented as a C // identifier (cident) to the list of sections that have that name. // Different object files can have cident sections with the same name. @@ -87,8 +87,8 @@ class Garbage_collection do_transitive_closure(); bool - is_section_garbage(Object* obj, unsigned int shndx) - { return (this->referenced_list().find(Section_id(obj, shndx)) + is_section_garbage(Relobj* obj, unsigned int shndx) + { return (this->referenced_list().find(Rel_section_id(obj, shndx)) == this->referenced_list().end()); } Cident_section_map* @@ -97,17 +97,17 @@ class Garbage_collection void add_cident_section(std::string section_name, - Section_id secn) + Rel_section_id secn) { this->cident_sections_[section_name].insert(secn); } // Add a reference from the SRC_SHNDX-th section of SRC_OBJECT to // DST_SHNDX-th section of DST_OBJECT. void - add_reference(Object* src_object, unsigned int src_shndx, - Object* dst_object, unsigned int dst_shndx) + add_reference(Relobj* src_object, unsigned int src_shndx, + Relobj* dst_object, unsigned int dst_shndx) { - Section_id src_id(src_object, src_shndx); - Section_id dst_id(dst_object, dst_shndx); + Rel_section_id src_id(src_object, src_shndx); + Rel_section_id dst_id(dst_object, dst_shndx); Sections_reachable& reachable = this->section_reloc_map_[src_id]; reachable.insert(dst_id); } @@ -229,7 +229,7 @@ gc_process_relocs( unsigned int r_type = elfcpp::elf_r_type(r_info); typename elfcpp::Elf_types::Elf_Swxword addend = Reloc_types::get_reloc_addend_noerror(&reloc); - Object* dst_obj; + Relobj* dst_obj; unsigned int dst_indx; typedef typename elfcpp::Elf_types::Elf_Addr Address; Address dst_off; @@ -291,7 +291,7 @@ gc_process_relocs( bool is_ordinary = false; if (gsym->source() == Symbol::FROM_OBJECT) { - dst_obj = gsym->object(); + dst_obj = gsym->relobj(); dst_indx = gsym->shndx(&is_ordinary); } dst_off = static_cast*>(gsym)->value(); @@ -340,7 +340,7 @@ gc_process_relocs( src_obj)); } - if (gsym->source() != Symbol::FROM_OBJECT) + if (dst_obj == NULL) continue; if (!is_ordinary) continue; @@ -357,7 +357,7 @@ gc_process_relocs( symtab->gc()->cident_sections()->find(std::string(cident_section_name)); if (ele == symtab->gc()->cident_sections()->end()) continue; - Section_id src_id(src_obj, src_indx); + Rel_section_id src_id(src_obj, src_indx); Garbage_collection::Sections_reachable& v(symtab->gc()->section_reloc_map()[src_id]); Garbage_collection::Sections_reachable& cident_secn(ele->second); diff --git a/gold/object.cc b/gold/object.cc index 18c6670..a2bad83 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -1602,7 +1602,7 @@ Sized_relobj_file::do_layout(Symbol_table* symtab, || shdr.get_sh_type() == elfcpp::SHT_INIT_ARRAY || shdr.get_sh_type() == elfcpp::SHT_FINI_ARRAY) { - symtab->gc()->worklist().push_back(Section_id(this, i)); + symtab->gc()->worklist().push_back(Rel_section_id(this, i)); } // If the section name XXX can be represented as a C identifier // it cannot be discarded if there are references to @@ -1610,7 +1610,7 @@ Sized_relobj_file::do_layout(Symbol_table* symtab, // specially handled. if (is_cident(name)) { - symtab->gc()->add_cident_section(name, Section_id(this, i)); + symtab->gc()->add_cident_section(name, Rel_section_id(this, i)); } } diff --git a/gold/object.h b/gold/object.h index fc93abd..29376f2 100644 --- a/gold/object.h +++ b/gold/object.h @@ -2865,6 +2865,8 @@ struct Relocate_info // key type for various section maps. typedef std::pair Section_id; +typedef std::pair Rel_section_id; + // This is similar to Section_id but is used when the section // pointers are const. typedef std::pair Const_section_id; diff --git a/gold/powerpc.cc b/gold/powerpc.cc index fddf3fa..57e0082 100644 --- a/gold/powerpc.cc +++ b/gold/powerpc.cc @@ -79,7 +79,7 @@ class Powerpc_relobj : public Sized_relobj_file { public: typedef typename elfcpp::Elf_types::Elf_Addr Address; - typedef Unordered_set Section_refs; + typedef Unordered_set Section_refs; typedef Unordered_map Access_from; Powerpc_relobj(const std::string& name, Input_file* input_file, off_t offset, @@ -212,11 +212,11 @@ public: // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd // section at DST_OFF. void - add_reference(Object* src_obj, + add_reference(Relobj* src_obj, unsigned int src_indx, typename elfcpp::Elf_types::Elf_Addr dst_off) { - Section_id src_id(src_obj, src_indx); + Rel_section_id src_id(src_obj, src_indx); this->access_from_map_[dst_off].insert(src_id); } @@ -238,7 +238,7 @@ public: if (this->opd_ent_[i].gc_mark) { unsigned int shndx = this->opd_ent_[i].shndx; - symtab->gc()->worklist().push_back(Section_id(this, shndx)); + symtab->gc()->worklist().push_back(Rel_section_id(this, shndx)); } } @@ -780,9 +780,9 @@ class Target_powerpc : public Sized_target // section of a function descriptor. void do_gc_add_reference(Symbol_table* symtab, - Object* src_obj, + Relobj* src_obj, unsigned int src_shndx, - Object* dst_obj, + Relobj* dst_obj, unsigned int dst_shndx, Address dst_off) const; @@ -6347,7 +6347,7 @@ Target_powerpc::gc_process_relocs( typename Powerpc_relobj::Section_refs::iterator s; for (s = p->second.begin(); s != p->second.end(); ++s) { - Object* src_obj = s->first; + Relobj* src_obj = s->first; unsigned int src_indx = s->second; symtab->gc()->add_reference(src_obj, src_indx, ppc_object, dst_indx); @@ -6384,9 +6384,9 @@ template void Target_powerpc::do_gc_add_reference( Symbol_table* symtab, - Object* src_obj, + Relobj* src_obj, unsigned int src_shndx, - Object* dst_obj, + Relobj* dst_obj, unsigned int dst_shndx, Address dst_off) const { @@ -6434,8 +6434,8 @@ Target_powerpc::do_gc_mark_symbol( if (ppc_object->opd_valid()) { unsigned int dst_indx = ppc_object->get_opd_ent(dst_off); - symtab->gc()->worklist().push_back(Section_id(ppc_object, - dst_indx)); + symtab->gc()->worklist().push_back(Rel_section_id(ppc_object, + dst_indx)); } else ppc_object->add_gc_mark(dst_off); diff --git a/gold/symtab.cc b/gold/symtab.cc index c197221..385024f 100644 --- a/gold/symtab.cc +++ b/gold/symtab.cc @@ -653,7 +653,7 @@ Symbol_table::gc_mark_symbol(Symbol* sym) if (is_ordinary && shndx != elfcpp::SHN_UNDEF) { gold_assert(this->gc_!= NULL); - this->gc_->worklist().push_back(Section_id(sym->object(), shndx)); + this->gc_->worklist().push_back(Rel_section_id(sym->relobj(), shndx)); } parameters->target().gc_mark_symbol(this, sym); } diff --git a/gold/symtab.h b/gold/symtab.h index 9413360..4144aef 100644 --- a/gold/symtab.h +++ b/gold/symtab.h @@ -157,6 +157,17 @@ class Symbol return this->u_.from_object.object; } + Relobj* + relobj() const + { + if (this->source_ != FROM_OBJECT) + return NULL; + Object *r = this->u_.from_object.object; + if (r->is_dynamic() || r->pluginobj() != NULL) + return NULL; + return static_cast(r); + } + // Return the index of the section in the input relocatable or // dynamic object file. unsigned int diff --git a/gold/target.h b/gold/target.h index 95bc57e..dfbc5ee 100644 --- a/gold/target.h +++ b/gold/target.h @@ -1056,9 +1056,9 @@ class Sized_target : public Target // and DST_OFF. void gc_add_reference(Symbol_table* symtab, - Object* src_obj, + Relobj* src_obj, unsigned int src_shndx, - Object* dst_obj, + Relobj* dst_obj, unsigned int dst_shndx, typename elfcpp::Elf_types::Elf_Addr dst_off) const { @@ -1080,8 +1080,8 @@ class Sized_target : public Target // Handle target specific gc actions when adding a gc reference. virtual void - do_gc_add_reference(Symbol_table*, Object*, unsigned int, - Object*, unsigned int, + do_gc_add_reference(Symbol_table*, Relobj*, unsigned int, + Relobj*, unsigned int, typename elfcpp::Elf_types::Elf_Addr) const { }