From: Cary Coutant Date: Tue, 23 Oct 2012 21:41:37 +0000 (+0000) Subject: gold/ X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ed5d6712b825edd0c4de10d7e7907d3332e6fe7e;p=binutils-gdb.git gold/ * dwarf_reader.cc (Dwarf_ranges_table::read_range_list): Call Dwarf_info_reader::read_from_pointer. (Dwarf_pubnames_table::read_header): Likewise. (Dwarf_pubnames_table::next_name): Likewise. (Dwarf_die::read_attributes): Likewise. (Dwarf_die::skip_attributes): Likewise. (Dwarf_info_reader::read_from_pointer): New function template. * dwarf_reader.h (Dwarf_ranges_table): Add dwinfo_. (Dwarf_pubnames_table): Likewise. (Dwarf_info_reader::read_from_pointer): New function template. * gdb-index.cc (Gdb_index_info_reader): Adjust call to Dwarf_pubnames_table ctor. --- diff --git a/gold/ChangeLog b/gold/ChangeLog index 7c37dcb2b9e..1e6032292ce 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,18 @@ +2012-10-23 Cary Coutant + + * dwarf_reader.cc (Dwarf_ranges_table::read_range_list): Call + Dwarf_info_reader::read_from_pointer. + (Dwarf_pubnames_table::read_header): Likewise. + (Dwarf_pubnames_table::next_name): Likewise. + (Dwarf_die::read_attributes): Likewise. + (Dwarf_die::skip_attributes): Likewise. + (Dwarf_info_reader::read_from_pointer): New function template. + * dwarf_reader.h (Dwarf_ranges_table): Add dwinfo_. + (Dwarf_pubnames_table): Likewise. + (Dwarf_info_reader::read_from_pointer): New function template. + * gdb-index.cc (Gdb_index_info_reader): Adjust call to + Dwarf_pubnames_table ctor. + 2012-10-23 Cary Coutant * dwarf_reader.cc (Dwarf_info_reader::do_parse): Use stored diff --git a/gold/dwarf_reader.cc b/gold/dwarf_reader.cc index 14222c57a0a..c80e8cbc378 100644 --- a/gold/dwarf_reader.cc +++ b/gold/dwarf_reader.cc @@ -412,13 +412,17 @@ Dwarf_ranges_table::read_range_list( // Read the raw contents of the section. if (addr_size == 4) { - start = read_from_pointer<32>(this->ranges_buffer_ + offset); - end = read_from_pointer<32>(this->ranges_buffer_ + offset + 4); + start = this->dwinfo_->read_from_pointer<32>(this->ranges_buffer_ + + offset); + end = this->dwinfo_->read_from_pointer<32>(this->ranges_buffer_ + + offset + 4); } else { - start = read_from_pointer<64>(this->ranges_buffer_ + offset); - end = read_from_pointer<64>(this->ranges_buffer_ + offset + 8); + start = this->dwinfo_->read_from_pointer<64>(this->ranges_buffer_ + + offset); + end = this->dwinfo_->read_from_pointer<64>(this->ranges_buffer_ + + offset + 8); } // Check for relocations and adjust the values. @@ -510,11 +514,11 @@ Dwarf_pubnames_table::read_header(off_t offset) const unsigned char* pinfo = this->buffer_ + offset; // Read the unit_length field. - uint32_t unit_length = read_from_pointer<32>(pinfo); + uint32_t unit_length = this->dwinfo_->read_from_pointer<32>(pinfo); pinfo += 4; if (unit_length == 0xffffffff) { - unit_length = read_from_pointer<64>(pinfo); + unit_length = this->dwinfo_->read_from_pointer<64>(pinfo); pinfo += 8; this->offset_size_ = 8; } @@ -522,7 +526,7 @@ Dwarf_pubnames_table::read_header(off_t offset) this->offset_size_ = 4; // Check the version. - unsigned int version = read_from_pointer<16>(pinfo); + unsigned int version = this->dwinfo_->read_from_pointer<16>(pinfo); pinfo += 2; if (version != 2) return false; @@ -548,9 +552,9 @@ Dwarf_pubnames_table::next_name() // the end of the list. uint32_t offset; if (this->offset_size_ == 4) - offset = read_from_pointer<32>(&pinfo); + offset = this->dwinfo_->read_from_pointer<32>(&pinfo); else - offset = read_from_pointer<64>(&pinfo); + offset = this->dwinfo_->read_from_pointer<64>(&pinfo); if (offset == 0) return NULL; @@ -638,9 +642,9 @@ Dwarf_die::read_attributes() { off_t str_off; if (this->dwinfo_->offset_size() == 4) - str_off = read_from_pointer<32>(&pattr); + str_off = this->dwinfo_->read_from_pointer<32>(&pattr); else - str_off = read_from_pointer<64>(&pattr); + str_off = this->dwinfo_->read_from_pointer<64>(&pattr); unsigned int shndx = this->dwinfo_->lookup_reloc(attr_off, &str_off); attr_value.aux.shndx = shndx; @@ -651,9 +655,9 @@ Dwarf_die::read_attributes() { off_t sec_off; if (this->dwinfo_->offset_size() == 4) - sec_off = read_from_pointer<32>(&pattr); + sec_off = this->dwinfo_->read_from_pointer<32>(&pattr); else - sec_off = read_from_pointer<64>(&pattr); + sec_off = this->dwinfo_->read_from_pointer<64>(&pattr); unsigned int shndx = this->dwinfo_->lookup_reloc(attr_off, &sec_off); attr_value.aux.shndx = shndx; @@ -666,9 +670,9 @@ Dwarf_die::read_attributes() { off_t sec_off; if (this->dwinfo_->address_size() == 4) - sec_off = read_from_pointer<32>(&pattr); + sec_off = this->dwinfo_->read_from_pointer<32>(&pattr); else - sec_off = read_from_pointer<64>(&pattr); + sec_off = this->dwinfo_->read_from_pointer<64>(&pattr); unsigned int shndx = this->dwinfo_->lookup_reloc(attr_off, &sec_off); attr_value.aux.shndx = shndx; @@ -682,12 +686,14 @@ Dwarf_die::read_attributes() pattr += attr_value.aux.blocklen; break; case elfcpp::DW_FORM_block2: - attr_value.aux.blocklen = read_from_pointer<16>(&pattr); + attr_value.aux.blocklen = + this->dwinfo_->read_from_pointer<16>(&pattr); attr_value.val.blockval = pattr; pattr += attr_value.aux.blocklen; break; case elfcpp::DW_FORM_block4: - attr_value.aux.blocklen = read_from_pointer<32>(&pattr); + attr_value.aux.blocklen = + this->dwinfo_->read_from_pointer<32>(&pattr); attr_value.val.blockval = pattr; pattr += attr_value.aux.blocklen; break; @@ -706,16 +712,18 @@ Dwarf_die::read_attributes() ref_form = true; break; case elfcpp::DW_FORM_data2: - attr_value.val.intval = read_from_pointer<16>(&pattr); + attr_value.val.intval = + this->dwinfo_->read_from_pointer<16>(&pattr); break; case elfcpp::DW_FORM_ref2: - attr_value.val.refval = read_from_pointer<16>(&pattr); + attr_value.val.refval = + this->dwinfo_->read_from_pointer<16>(&pattr); ref_form = true; break; case elfcpp::DW_FORM_data4: { off_t sec_off; - sec_off = read_from_pointer<32>(&pattr); + sec_off = this->dwinfo_->read_from_pointer<32>(&pattr); unsigned int shndx = this->dwinfo_->lookup_reloc(attr_off, &sec_off); attr_value.aux.shndx = shndx; @@ -725,7 +733,7 @@ Dwarf_die::read_attributes() case elfcpp::DW_FORM_ref4: { off_t sec_off; - sec_off = read_from_pointer<32>(&pattr); + sec_off = this->dwinfo_->read_from_pointer<32>(&pattr); unsigned int shndx = this->dwinfo_->lookup_reloc(attr_off, &sec_off); attr_value.aux.shndx = shndx; @@ -736,7 +744,7 @@ Dwarf_die::read_attributes() case elfcpp::DW_FORM_data8: { off_t sec_off; - sec_off = read_from_pointer<64>(&pattr); + sec_off = this->dwinfo_->read_from_pointer<64>(&pattr); unsigned int shndx = this->dwinfo_->lookup_reloc(attr_off, &sec_off); attr_value.aux.shndx = shndx; @@ -744,12 +752,13 @@ Dwarf_die::read_attributes() break; } case elfcpp::DW_FORM_ref_sig8: - attr_value.val.uintval = read_from_pointer<64>(&pattr); + attr_value.val.uintval = + this->dwinfo_->read_from_pointer<64>(&pattr); break; case elfcpp::DW_FORM_ref8: { off_t sec_off; - sec_off = read_from_pointer<64>(&pattr); + sec_off = this->dwinfo_->read_from_pointer<64>(&pattr); unsigned int shndx = this->dwinfo_->lookup_reloc(attr_off, &sec_off); attr_value.aux.shndx = shndx; @@ -876,14 +885,14 @@ Dwarf_die::skip_attributes() case elfcpp::DW_FORM_block2: { uint16_t block_size; - block_size = read_from_pointer<16>(&pattr); + block_size = this->dwinfo_->read_from_pointer<16>(&pattr); pattr += block_size; break; } case elfcpp::DW_FORM_block4: { uint32_t block_size; - block_size = read_from_pointer<32>(&pattr); + block_size = this->dwinfo_->read_from_pointer<32>(&pattr); pattr += block_size; break; } @@ -1352,6 +1361,33 @@ Dwarf_info_reader::do_read_string_table(unsigned int string_shndx) return true; } +// Read a possibly unaligned integer of SIZE. +template +inline typename elfcpp::Valtype_base::Valtype +Dwarf_info_reader::read_from_pointer(const unsigned char* source) +{ + typename elfcpp::Valtype_base::Valtype return_value; + if (this->object_->is_big_endian()) + return_value = elfcpp::Swap_unaligned::readval(source); + else + return_value = elfcpp::Swap_unaligned::readval(source); + return return_value; +} + +// Read a possibly unaligned integer of SIZE. Update SOURCE after read. +template +inline typename elfcpp::Valtype_base::Valtype +Dwarf_info_reader::read_from_pointer(const unsigned char** source) +{ + typename elfcpp::Valtype_base::Valtype return_value; + if (this->object_->is_big_endian()) + return_value = elfcpp::Swap_unaligned::readval(*source); + else + return_value = elfcpp::Swap_unaligned::readval(*source); + *source += valsize / 8; + return return_value; +} + // Look for a relocation at offset ATTR_OFF in the dwarf info, // and return the section index and offset of the target. diff --git a/gold/dwarf_reader.h b/gold/dwarf_reader.h index aea63ab80c7..2a8e56edd51 100644 --- a/gold/dwarf_reader.h +++ b/gold/dwarf_reader.h @@ -335,10 +335,10 @@ class Dwarf_range_list class Dwarf_ranges_table { public: - Dwarf_ranges_table() - : ranges_shndx_(0), ranges_buffer_(NULL), ranges_buffer_end_(NULL), - owns_ranges_buffer_(false), ranges_reloc_mapper_(NULL), - output_section_offset_(0) + Dwarf_ranges_table(Dwarf_info_reader* dwinfo) + : dwinfo_(dwinfo), ranges_shndx_(0), ranges_buffer_(NULL), + ranges_buffer_end_(NULL), owns_ranges_buffer_(false), + ranges_reloc_mapper_(NULL), output_section_offset_(0) { } ~Dwarf_ranges_table() @@ -366,6 +366,8 @@ class Dwarf_ranges_table off_t ranges_offset); private: + // The Dwarf_info_reader, for reading data. + Dwarf_info_reader* dwinfo_; // The section index of the ranges table. unsigned int ranges_shndx_; // The buffer containing the .debug_ranges section. @@ -388,8 +390,8 @@ class Dwarf_ranges_table class Dwarf_pubnames_table { public: - Dwarf_pubnames_table(bool is_pubtypes) - : buffer_(NULL), buffer_end_(NULL), owns_buffer_(false), + Dwarf_pubnames_table(Dwarf_info_reader* dwinfo, bool is_pubtypes) + : dwinfo_(dwinfo), buffer_(NULL), buffer_end_(NULL), owns_buffer_(false), offset_size_(0), pinfo_(NULL), is_pubtypes_(is_pubtypes), output_section_offset_(0) { } @@ -413,6 +415,8 @@ class Dwarf_pubnames_table next_name(); private: + // The Dwarf_info_reader, for reading data. + Dwarf_info_reader* dwinfo_; // The buffer containing the .debug_ranges section. const unsigned char* buffer_; const unsigned char* buffer_end_; @@ -665,8 +669,8 @@ class Dwarf_info_reader reloc_type_(reloc_type), abbrev_shndx_(0), string_shndx_(0), buffer_(NULL), buffer_end_(NULL), cu_offset_(0), cu_length_(0), offset_size_(0), address_size_(0), cu_version_(0), type_signature_(0), - type_offset_(0), abbrev_table_(), reloc_mapper_(NULL), - string_buffer_(NULL), string_buffer_end_(NULL), + type_offset_(0), abbrev_table_(), ranges_table_(this), + reloc_mapper_(NULL), string_buffer_(NULL), string_buffer_end_(NULL), owns_string_buffer_(false), string_output_section_offset_(0) { } @@ -700,6 +704,16 @@ class Dwarf_info_reader return NULL; } + // Read a possibly unaligned integer of SIZE. + template + inline typename elfcpp::Valtype_base::Valtype + read_from_pointer(const unsigned char* source); + + // Read a possibly unaligned integer of SIZE. Update SOURCE after read. + template + inline typename elfcpp::Valtype_base::Valtype + read_from_pointer(const unsigned char** source); + // Look for a relocation at offset ATTR_OFF in the dwarf info, // and return the section index and offset of the target. unsigned int diff --git a/gold/gdb-index.cc b/gold/gdb-index.cc index 51d0816f1b1..d3c9d612c15 100644 --- a/gold/gdb-index.cc +++ b/gold/gdb-index.cc @@ -869,7 +869,7 @@ Gdb_index_info_reader::read_pubnames_and_pubtypes(Dwarf_die* die) ret = true; else { - Dwarf_pubnames_table pubnames(false); + Dwarf_pubnames_table pubnames(this, false); if (!pubnames.read_section(this->object(), pubnames_shndx)) return false; if (!pubnames.read_header(pubnames_offset)) @@ -896,7 +896,7 @@ Gdb_index_info_reader::read_pubnames_and_pubtypes(Dwarf_die* die) ret = true; else { - Dwarf_pubnames_table pubtypes(true); + Dwarf_pubnames_table pubtypes(this, true); if (!pubtypes.read_section(this->object(), pubtypes_shndx)) return false; if (!pubtypes.read_header(pubtypes_offset))