aboutsummaryrefslogtreecommitdiff
path: root/gold/object.h
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2008-04-19 18:30:58 +0000
committerIan Lance Taylor <ian@airs.com>2008-04-19 18:30:58 +0000
commitd491d34e930046f820def9d3d67a2491df8a2198 (patch)
tree7e955be0ab4ec83f4711c309a6dcf130f341da99 /gold/object.h
parent8e91f0232ca9c286299092c896288b8657c9311b (diff)
downloadgdb-d491d34e930046f820def9d3d67a2491df8a2198.zip
gdb-d491d34e930046f820def9d3d67a2491df8a2198.tar.gz
gdb-d491d34e930046f820def9d3d67a2491df8a2198.tar.bz2
* object.cc (Xindex::initialize_symtab_xindex): New function.
(Xindex::read_symtab_xindex): New function. (Xindex::sym_xindex_to_shndx): New function. (Sized_relobj::find_symtab): Pick up SHT_SYMTAB_SHNDX section if available. (Sized_relobj::do_initialize_xindex): New function. (Sized_relobj::do_read_symbols): Adjust section links. (Sized_relobj::symbol_section_and_value): Add is_ordinary parameter. Change all callers. (Sized_relobj::include_section_group): Adjust section links and symbol section indexes. (Sized_relobj::do_layout): Adjust section links. (Sized_relobj::do_count_local_symbols): Adjust section links and symbol section indexes. (Sized_relobj::do_finalize_local_symbols): Distinguish between ordinary and special symbols. (Sized_relobj::write_local_symbols): Add symtab_xindex and dynsym_xindex parameters. Change all callers. Adjust section links. Use SHN_XINDEX when needed. (Sized_relobj::get_symbol_location_info): Adjust section links. Don't get fooled by special symbols. * object.h (class Xindex): Define. (class Object): Add xindex_ parameter. Declare virtual functoin do_initialize_xindex. (Object::adjust_sym_shndx): New function. (Object::set_xindex): New protected function. (class Symbol_value): Add is_ordinary_shndx_ field. (Symbol_value::Symbol_value): Initialize is_ordinary_shndx_. (Symbol_value::value): Assert ordinary section. (Symbol_value::initialize_input_to_output_map): Likewise. (Symbol_value::set_input_shndx): Add is_ordinary parameter. Change all callers. (Symbol_value::input_shndx): Add is_ordinary parameter. Change all callers. (class Sized_relobj): Update declarations. (Sized_relobj::local_symbol_input_shndx): Add is_ordinary parameter. Change all callers. (Sized_relobj::adjust_shndx): New function. * dynobj.cc (Sized_dynobj::Sized_dynobj): Initialize dynsym_shndx_ field. (Sized_dynobj::find_dynsym_sections): Remove pdynsym_shndx parameter. Change all callers. Pick up SHT_DYNSYM_SHNDX section for SHT_DYNSYM section if available. Set dynsym_shndx_ field. (Sized_dynobj::read_dynsym_section): Adjust section links. (Sized_dynobj::read_dynamic): Likewise. (Sized_dynobj::do_read_symbols): Use dynsym_shndx_ field. Adjust section links. (Sized_dynobj::do_initialize_xindex): New function. * dynobj.h (class Sized_dynobj): Add dynsym_shndx_ field. Declare do_initialize_xindex. (Sized_dynobj::adjust_shndx): New function. * layout.cc (Layout::Layout): Initialize symtab_xindex_ and dynsym_xindex_ fields. (Layout::finalize): Add a call to set_section_indexes before creating the symtab sections. (Layout::set_section_indexes): Don't do anything if the section already has a section index. (Layout::create_symtab_sections): Add shnum parameter. Change caller. Create .symtab_shndx section if needed. (Layout::create_shdrs): Add shstrtab_section parameter. Change caller. (Layout::allocated_output_section_count): New function. (Layout::create_dynamic_symtab): Create .dynsym_shndx section if needed. * layout.h (class Layout): Add symtab_xindex_ and dynsym_xindex_ fields. Update declarations. (Layout::symtab_xindex): New function. (Layout::dynsym_xindex): New function. (class Write_symbols_task): Add layout_ field. (Write_symbols_task::Write_symbols_task): Add layout parameter. Change caller. * output.cc (Output_section_headers::Output_section_headers): Add shstrtab_section parameter. Change all callers. (Output_section_headers::do_sized_write): Store overflow values for section count and section string table section index in section header zero. (Output_file_header::do_sized_write): Check for overflow of section count and section string table section index. (Output_symtab_xindex::do_write): New function. (Output_symtab_xindex::endian_do_write): New function. * output.h (class Output_section_headers): Add shstrtab_section_. Update declarations. (class Output_symtab_xindex): Define. (Output_section::has_out_shndx): New function. * symtab.cc (Symbol::init_fields): Initialize is_ordinary_shndx_ field. (Symbol::init_base): Add st_shndx and is_ordinary parameters. Change all callers. (Sized_symbol::init): Likewise. (Symbol::output_section): Check for ordinary symbol. (Symbol_table::add_from_object): Remove orig_sym parameter. Add st_shndx, is_ordinary, and orig_st_shndx parameters. Change all callers. (Symbol_table::add_from_relobj): Add symndx_offset parameter. Change all callers. Simplify handling of symbols from sections not included in the link. (Symbol_table::add_from_dynobj): Handle ordinary symbol distinction. (Weak_alias_sorter::operator()): Assert that symbols are ordinary. (Symbol_table::sized_finalize_symbol): Handle ordinary symbol distinction. (Symbol_table::write_globals): Add symtab_xindex and dynsym_xindex parameters. Change all callers. (Symbol_table::sized_write_globals): Likewise. Handle ordinary symbol distinction. Use SHN_XINDEX when needed. (Symbol_table::write_section_symbol): Add symtab_xindex parameter. Change all callers. (Symbol_table::sized_write_section_symbol): Likewise. Use SHN_XINDEX when needed. * symtab.h (class Symbol): Add is_ordinary_shndx_ field. Update declarations. (Symbol::shndx): Add is_ordinary parameter. Change all callers. (Symbol::is_defined): Check is_ordinary. (Symbol::is_undefined, Symbol::is_weak_undefined): Likewise. (Symbol::is_absolute, Symbol::is_common): Likewise. (class Sized_symbol): Update declarations. (class Symbol_table): Update declarations. * resolve.cc (Symbol::override_base): Add st_shndx and is_ordinary parameters. Change all callers. (Sized_symbol::override): Likewise. (Symbol_table::override): Likewise. (symbol_to_bits): Add is_ordinary parameter. Change all callers. (Symbol_table::resolve): Remove orig_sym parameter. Add st_shndx, is_ordinary, and orig_st_shndx parameters. Change all callers. * copy-relocs.cc (Copy_relocs::emit_copy_reloc): Require symbol to be in an ordinary section. * dwarf_reader.cc (Sized_dwarf_line_info::symbol_section): Add object and is_ordinary parameters. Change all callers. (Sized_dwarf_line_info::read_relocs): Add object parameter. Change all callers. Don't add undefined or non-ordinary symbols to reloc_map_. (Sized_dwarf_line_info::read_line_mappings): Add object parameter. Change all callers. * dwarf_reader.h (class Sized_dwarf_line_info): Update declarations. * ehframe.cc (Eh_frame::read_fde): Check for ordinary symbol. * reloc.cc (Sized_relobj::do_read_relocs): Adjust section links. (Sized_relobj::relocate_sections): Likewise. * target-reloc.h (scan_relocs): Adjust section symbol index. (scan_relocatable_relocs): Likewise. * i386.cc (Scan::local): Check for ordinary symbols. * sparc.cc (Scan::local): Likewise. * x86_64.cc (Scan::local): Likewise. * testsuite/binary_unittest.cc (Sized_binary_test): Update calls to symbol_section_and_value. * testsuite/many_sections_test.cc: New file. * testsuite/Makefile.am (BUILT_SOURCES): Define. (check_PROGRAMS): Add many_sections_test. (many_sections_test_SOURCES): Define. (many_sections_test_DEPENDENCIES): Define. (many_sections_test_LDFLAGS): Define. (BUILT_SOURCES): Add many_sections_define.h. (many_sections_define.h): New target. (BUILT_SOURCES): Add many_sections_check.h. (many_sections_check.h): New target. (check_PROGRAMS): Add many_sections_r_test. (many_sections_r_test_SOURCES): Define. (many_sections_r_test_DEPENDENCIES): Define. (many_sections_r_test_LDFLAGS): Define. (many_sections_r_test_LDADD): Define. (many_sections_r_test.o): New target. * testsuite/Makefile.in: Rebuild.
Diffstat (limited to 'gold/object.h')
-rw-r--r--gold/object.h149
1 files changed, 131 insertions, 18 deletions
diff --git a/gold/object.h b/gold/object.h
index 9e64277..aaaa48d 100644
--- a/gold/object.h
+++ b/gold/object.h
@@ -39,6 +39,7 @@ class Task;
class Layout;
class Output_section;
class Output_file;
+class Output_symtab_xindex;
class Dynobj;
class Object_merge_map;
class Relocatable_relocs;
@@ -127,6 +128,55 @@ struct Read_relocs_data
File_view* local_symbols;
};
+// The Xindex class manages section indexes for objects with more than
+// 0xff00 sections.
+
+class Xindex
+{
+ public:
+ Xindex(int large_shndx_offset)
+ : large_shndx_offset_(large_shndx_offset), symtab_xindex_()
+ { }
+
+ // Initialize the symtab_xindex_ array, given the object and the
+ // section index of the symbol table to use.
+ template<int size, bool big_endian>
+ void
+ initialize_symtab_xindex(Object*, unsigned int symtab_shndx);
+
+ // Read in the symtab_xindex_ array, given its section index.
+ // PSHDRS may optionally point to the section headers.
+ template<int size, bool big_endian>
+ void
+ read_symtab_xindex(Object*, unsigned int xindex_shndx,
+ const unsigned char* pshdrs);
+
+ // Symbol SYMNDX in OBJECT has a section of SHN_XINDEX; return the
+ // real section index.
+ unsigned int
+ sym_xindex_to_shndx(Object* object, unsigned int symndx);
+
+ private:
+ // The type of the array giving the real section index for symbols
+ // whose st_shndx field holds SHN_XINDEX.
+ typedef std::vector<unsigned int> Symtab_xindex;
+
+ // Adjust a section index if necessary. This should only be called
+ // for ordinary section indexes.
+ unsigned int
+ adjust_shndx(unsigned int shndx)
+ {
+ if (shndx >= elfcpp::SHN_LORESERVE)
+ shndx += this->large_shndx_offset_;
+ return shndx;
+ }
+
+ // Adjust to apply to large section indexes.
+ int large_shndx_offset_;
+ // The data from the SHT_SYMTAB_SHNDX section.
+ Symtab_xindex symtab_xindex_;
+};
+
// Object is an abstract base class which represents either a 32-bit
// or a 64-bit input object. This can be a regular object file
// (ET_REL) or a shared object (ET_DYN).
@@ -141,7 +191,7 @@ class Object
Object(const std::string& name, Input_file* input_file, bool is_dynamic,
off_t offset = 0)
: name_(name), input_file_(input_file), offset_(offset), shnum_(-1U),
- is_dynamic_(is_dynamic), target_(NULL)
+ is_dynamic_(is_dynamic), target_(NULL), xindex_(NULL)
{ input_file->file().add_object(); }
virtual ~Object()
@@ -214,6 +264,29 @@ class Object
const unsigned char*
section_contents(unsigned int shndx, section_size_type* plen, bool cache);
+ // Adjust a symbol's section index as needed. SYMNDX is the index
+ // of the symbol and SHNDX is the symbol's section from
+ // get_st_shndx. This returns the section index. It sets
+ // *IS_ORDINARY to indicate whether this is a normal section index,
+ // rather than a special code between SHN_LORESERVE and
+ // SHN_HIRESERVE.
+ unsigned int
+ adjust_sym_shndx(unsigned int symndx, unsigned int shndx, bool* is_ordinary)
+ {
+ if (shndx < elfcpp::SHN_LORESERVE)
+ *is_ordinary = true;
+ else if (shndx == elfcpp::SHN_XINDEX)
+ {
+ if (this->xindex_ == NULL)
+ this->xindex_ = this->do_initialize_xindex();
+ shndx = this->xindex_->sym_xindex_to_shndx(this, symndx);
+ *is_ordinary = true;
+ }
+ else
+ *is_ordinary = false;
+ return shndx;
+ }
+
// Return the size of a section given a section index.
uint64_t
section_size(unsigned int shndx)
@@ -399,6 +472,10 @@ class Object
virtual uint64_t
do_section_addralign(unsigned int shndx) = 0;
+ // Return the Xindex structure to use.
+ virtual Xindex*
+ do_initialize_xindex() = 0;
+
// Get the file. We pass on const-ness.
Input_file*
input_file()
@@ -426,6 +503,14 @@ class Object
read_section_data(elfcpp::Elf_file<size, big_endian, Object>*,
Read_symbols_data*);
+ // Let the child class initialize the xindex object directly.
+ void
+ set_xindex(Xindex* xindex)
+ {
+ gold_assert(this->xindex_ == NULL);
+ this->xindex_ = xindex;
+ }
+
// If NAME is the name of a special .gnu.warning section, arrange
// for the warning to be issued. SHNDX is the section index.
// Return whether it is a warning section.
@@ -451,6 +536,8 @@ class Object
bool is_dynamic_;
// Target functions--may be NULL if the target is not known.
Target* target_;
+ // Many sections for objects with more than SHN_LORESERVE sections.
+ Xindex* xindex_;
};
// Implement sized_target inline for efficiency. This approach breaks
@@ -774,8 +861,8 @@ class Symbol_value
Symbol_value()
: output_symtab_index_(0), output_dynsym_index_(-1U), input_shndx_(0),
- is_section_symbol_(false), is_tls_symbol_(false),
- has_output_value_(true)
+ is_ordinary_shndx_(false), is_section_symbol_(false),
+ is_tls_symbol_(false), has_output_value_(true)
{ this->u_.value = 0; }
// Get the value of this symbol. OBJECT is the object in which this
@@ -787,8 +874,11 @@ class Symbol_value
if (this->has_output_value_)
return this->u_.value + addend;
else
- return this->u_.merged_symbol_value->value(object, this->input_shndx_,
- addend);
+ {
+ gold_assert(this->is_ordinary_shndx_);
+ return this->u_.merged_symbol_value->value(object, this->input_shndx_,
+ addend);
+ }
}
// Set the value of this symbol in the output symbol table.
@@ -814,7 +904,7 @@ class Symbol_value
{
if (!this->has_output_value_)
{
- gold_assert(this->is_section_symbol_);
+ gold_assert(this->is_section_symbol_ && this->is_ordinary_shndx_);
Merged_symbol_value<size>* msv = this->u_.merged_symbol_value;
msv->initialize_input_to_output_map(object, this->input_shndx_);
}
@@ -908,18 +998,22 @@ class Symbol_value
// Set the index of the input section in the input file.
void
- set_input_shndx(unsigned int i)
+ set_input_shndx(unsigned int i, bool is_ordinary)
{
this->input_shndx_ = i;
// input_shndx_ field is a bitfield, so make sure that the value
// fits.
gold_assert(this->input_shndx_ == i);
+ this->is_ordinary_shndx_ = is_ordinary;
}
// Return the index of the input section in the input file.
unsigned int
- input_shndx() const
- { return this->input_shndx_; }
+ input_shndx(bool* is_ordinary) const
+ {
+ *is_ordinary = this->is_ordinary_shndx_;
+ return this->input_shndx_;
+ }
// Whether this is a section symbol.
bool
@@ -953,7 +1047,10 @@ class Symbol_value
unsigned int output_dynsym_index_;
// The section index in the input file in which this symbol is
// defined.
- unsigned int input_shndx_ : 29;
+ unsigned int input_shndx_ : 28;
+ // Whether the section index is an ordinary index, not a special
+ // value.
+ bool is_ordinary_shndx_ : 1;
// Whether this is a STT_SECTION symbol.
bool is_section_symbol_ : 1;
// Whether this is a STT_TLS symbol.
@@ -1087,12 +1184,13 @@ class Sized_relobj : public Relobj
}
// Return the section index of symbol SYM. Set *VALUE to its value
- // in the object file. Note that for a symbol which is not defined
- // in this object file, this will set *VALUE to 0 and return
- // SHN_UNDEF; it will not return the final value of the symbol in
- // the link.
+ // in the object file. Set *IS_ORDINARY if this is an ordinary
+ // section index, not a special code between SHN_LORESERVE and
+ // SHN_HIRESERVE. Note that for a symbol which is not defined in
+ // this object file, this will set *VALUE to 0 and return SHN_UNDEF;
+ // it will not return the final value of the symbol in the link.
unsigned int
- symbol_section_and_value(unsigned int sym, Address* value);
+ symbol_section_and_value(unsigned int sym, Address* value, bool* is_ordinary);
// Return a pointer to the Symbol_value structure which holds the
// value of a local symbol.
@@ -1123,10 +1221,10 @@ class Sized_relobj : public Relobj
// Return the input section index of local symbol SYM.
unsigned int
- local_symbol_input_shndx(unsigned int sym) const
+ local_symbol_input_shndx(unsigned int sym, bool* is_ordinary) const
{
gold_assert(sym < this->local_values_.size());
- return this->local_values_[sym].input_shndx();
+ return this->local_values_[sym].input_shndx(is_ordinary);
}
// Return the appropriate Sized_target structure.
@@ -1284,6 +1382,10 @@ class Sized_relobj : public Relobj
do_section_addralign(unsigned int shndx)
{ return this->elf_file_.section_addralign(shndx); }
+ // Return the Xindex structure to use.
+ Xindex*
+ do_initialize_xindex();
+
private:
// For convenience.
typedef Sized_relobj<size, big_endian> This;
@@ -1292,6 +1394,15 @@ class Sized_relobj : public Relobj
static const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
typedef elfcpp::Shdr<size, big_endian> Shdr;
+ // Adjust a section index if necessary.
+ unsigned int
+ adjust_shndx(unsigned int shndx)
+ {
+ if (shndx >= elfcpp::SHN_LORESERVE)
+ shndx += this->elf_file_.large_shndx_offset();
+ return shndx;
+ }
+
// Find the SHT_SYMTAB section, given the section headers.
void
find_symtab(const unsigned char* pshdrs);
@@ -1391,7 +1502,9 @@ class Sized_relobj : public Relobj
void
write_local_symbols(Output_file*,
const Stringpool_template<char>*,
- const Stringpool_template<char>*);
+ const Stringpool_template<char>*,
+ Output_symtab_xindex*,
+ Output_symtab_xindex*);
// Clear the local symbol information.
void