Add .gdb_index version 7 support.

This patch adds support for .gdb_index version 7, which adds several
flag bits to the symbol index.  It also fixes a problem where it did
not handle compressed debug sections correctly.

Tested with a google/gcc-4_8 branch compiler, which supports
the -ggnu-pubnames option to generate .debug_gnu_pubnames/pubtypes
tables. (We will submit that patch to GCC when stage 1 reopens.)

2014-01-28  Cary Coutant  <ccoutant@google.com>

	* gold/dwarf_reader.cc: include <utility> (for make_pair).
	(Dwarf_abbrev_table::do_read_abbrevs): Check for compressed
	debug sections.
	(Dwarf_ranges_table::read_ranges_table): Likewise.
	(Dwarf_pubnames_table::read_section): Check for GNU-style
	sections, and for compressed debug sections.
	(Dwarf_pubnames_table::read_header): Compute end address of table.
	(Dwarf_pubnames_table::next_name): Return flag_byte.  Check
	for end of list by offset, not by offset == 0.
	(Dwarf_info_reader::do_read_string_table): Check for compressed
	debug sections.
	* gold/dwarf_reader.h (Dwarf_pubnames_table::Dwarf_pubnames_table):
	Initialize new data members.
	(Dwarf_pubnames_table::next_name): return flag_byte.
	(Dwarf_pubnames_table::end_of_table_): New data member.
	(Dwarf_pubnames_table::is_gnu_style_): New data member.
	* gold/gdb-index.cc (gdb_index_version): Update to version 7.
	(Gdb_index_info_reader::read_pubtable): Read flag_byte.
	(Gdb_index_info_reader::read_pubnames_and_pubtypes): Don't
	read skeleton type unit DIEs.
	(Gdb_index::add_symbol): Add flag_byte; adjust all callers.
	(Gdb_index::do_write): Write flag_byte.
	* gold/gdb-index.h (Gdb_index::add_symbol): Add flags parameter.
	(Gdb_index::Cu_vector): Store flags along with cu indexes.
	* gold/testsuite/gdb_index_test_3.sh: Allow versions 4-7.
	* gold/testsuite/gdb_index_test_comm.sh: Likewise.
This commit is contained in:
Cary Coutant
2014-01-28 15:35:47 -08:00
parent 8b92472967
commit ec673e648c
7 changed files with 111 additions and 35 deletions

View File

@ -1,3 +1,34 @@
2014-01-28 Cary Coutant <ccoutant@google.com>
Add .gdb_index version 7 support.
* gold/dwarf_reader.cc: include <utility> (for make_pair).
(Dwarf_abbrev_table::do_read_abbrevs): Check for compressed
debug sections.
(Dwarf_ranges_table::read_ranges_table): Likewise.
(Dwarf_pubnames_table::read_section): Check for GNU-style
sections, and for compressed debug sections.
(Dwarf_pubnames_table::read_header): Compute end address of table.
(Dwarf_pubnames_table::next_name): Return flag_byte. Check
for end of list by offset, not by offset == 0.
(Dwarf_info_reader::do_read_string_table): Check for compressed
debug sections.
* gold/dwarf_reader.h (Dwarf_pubnames_table::Dwarf_pubnames_table):
Initialize new data members.
(Dwarf_pubnames_table::next_name): return flag_byte.
(Dwarf_pubnames_table::end_of_table_): New data member.
(Dwarf_pubnames_table::is_gnu_style_): New data member.
* gold/gdb-index.cc (gdb_index_version): Update to version 7.
(Gdb_index_info_reader::read_pubtable): Read flag_byte.
(Gdb_index_info_reader::read_pubnames_and_pubtypes): Don't
read skeleton type unit DIEs.
(Gdb_index::add_symbol): Add flag_byte; adjust all callers.
(Gdb_index::do_write): Write flag_byte.
* gold/gdb-index.h (Gdb_index::add_symbol): Add flags parameter.
(Gdb_index::Cu_vector): Store flags along with cu indexes.
* gold/testsuite/gdb_index_test_3.sh: Allow versions 4-7.
* gold/testsuite/gdb_index_test_comm.sh: Likewise.
2014-01-08 H.J. Lu <hongjiu.lu@intel.com>
* version.cc (print_version): Update copyright year to 2014.

View File

@ -23,6 +23,7 @@
#include "gold.h"
#include <algorithm>
#include <utility>
#include <vector>
#include "elfcpp_swap.h"
@ -180,7 +181,7 @@ Dwarf_abbrev_table::do_read_abbrevs(
for (unsigned int i = 1; i < object->shnum(); ++i)
{
std::string name = object->section_name(i);
if (name == ".debug_abbrev")
if (name == ".debug_abbrev" || name == ".zdebug_abbrev")
{
abbrev_shndx = i;
// Correct the offset. For incremental update links, we have a
@ -317,7 +318,7 @@ Dwarf_ranges_table::read_ranges_table(
for (unsigned int i = 1; i < object->shnum(); ++i)
{
std::string name = object->section_name(i);
if (name == ".debug_ranges")
if (name == ".debug_ranges" || name == ".zdebug_ranges")
{
ranges_shndx = i;
this->output_section_offset_ = object->output_section_offset(i);
@ -486,24 +487,38 @@ Dwarf_pubnames_table::read_section(Relobj* object, const unsigned char* symtab,
{
section_size_type buffer_size;
unsigned int shndx = 0;
const char* name = this->is_pubtypes_ ? "pubtypes" : "pubnames";
const char* gnu_name = (this->is_pubtypes_
? "gnu_pubtypes"
: "gnu_pubnames");
// Find the .debug_pubnames/pubtypes section.
const char* name = (this->is_pubtypes_
? ".debug_pubtypes"
: ".debug_pubnames");
for (unsigned int i = 1; i < object->shnum(); ++i)
{
if (object->section_name(i) == name)
std::string section_name = object->section_name(i);
const char* section_name_suffix = section_name.c_str();
if (is_prefix_of(".debug_", section_name_suffix))
section_name_suffix += 7;
else if (is_prefix_of(".zdebug_", section_name_suffix))
section_name_suffix += 8;
else
continue;
if (strcmp(section_name_suffix, name) == 0)
{
shndx = i;
this->output_section_offset_ = object->output_section_offset(i);
break;
}
else if (strcmp(section_name_suffix, gnu_name) == 0)
{
shndx = i;
this->output_section_offset_ = object->output_section_offset(i);
this->is_gnu_style_ = true;
break;
}
}
if (shndx == 0)
return false;
this->buffer_ = object->decompressed_section_contents(shndx,
&buffer_size,
&this->owns_buffer_);
@ -570,6 +585,7 @@ Dwarf_pubnames_table::read_header(off_t offset)
this->unit_length_ = unit_length + 4;
this->offset_size_ = 4;
}
this->end_of_table_ = pinfo + unit_length;
// Check the version.
unsigned int version = this->dwinfo_->read_from_pointer<16>(pinfo);
@ -593,20 +609,27 @@ Dwarf_pubnames_table::read_header(off_t offset)
// Read the next name from the set.
const char*
Dwarf_pubnames_table::next_name()
Dwarf_pubnames_table::next_name(uint8_t* flag_byte)
{
const unsigned char* pinfo = this->pinfo_;
// Read the offset within the CU. If this is zero, we have reached
// the end of the list.
uint32_t offset;
if (this->offset_size_ == 4)
offset = this->dwinfo_->read_from_pointer<32>(&pinfo);
else
offset = this->dwinfo_->read_from_pointer<64>(&pinfo);
if (offset == 0)
// Check for end of list. The table should be terminated by an
// entry containing nothing but a DIE offset of 0.
if (pinfo + this->offset_size_ >= this->end_of_table_)
return NULL;
// Skip the offset within the CU. If this is zero, but we're not
// at the end of the table, then we have a real pubnames entry
// whose DIE offset is 0 (likely to be a GCC bug). Since we
// don't actually use the DIE offset in building .gdb_index,
// it's harmless.
pinfo += this->offset_size_;
if (this->is_gnu_style_)
*flag_byte = *pinfo++;
else
*flag_byte = 0;
// Return a pointer to the string at the current location,
// and advance the pointer to the next entry.
const char* ret = reinterpret_cast<const char*>(pinfo);
@ -1366,7 +1389,7 @@ Dwarf_info_reader::do_read_string_table(unsigned int string_shndx)
for (unsigned int i = 1; i < this->object_->shnum(); ++i)
{
std::string name = object->section_name(i);
if (name == ".debug_str")
if (name == ".debug_str" || name == ".zdebug_str")
{
string_shndx = i;
this->string_output_section_offset_ =

View File

@ -400,7 +400,8 @@ class Dwarf_pubnames_table
public:
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),
offset_size_(0), pinfo_(NULL), end_of_table_(NULL),
is_pubtypes_(is_pubtypes), is_gnu_style_(false),
output_section_offset_(0), unit_length_(0), cu_offset_(0)
{ }
@ -431,9 +432,10 @@ class Dwarf_pubnames_table
subsection_size()
{ return this->unit_length_; }
// Read the next name from the set.
// Read the next name from the set. If the pubname table is gnu-style,
// FLAG_BYTE is set to the high-byte of a gdb_index version 7 cu_index.
const char*
next_name();
next_name(uint8_t* flag_byte);
private:
// The Dwarf_info_reader, for reading data.
@ -447,8 +449,13 @@ class Dwarf_pubnames_table
unsigned int offset_size_;
// The current position within the buffer.
const unsigned char* pinfo_;
// The end of the current pubnames table.
const unsigned char* end_of_table_;
// TRUE if this is a .debug_pubtypes section.
bool is_pubtypes_;
// Gnu-style pubnames table. This style has an extra flag byte between the
// offset and the name, and is used for generating version 7 of gdb-index.
bool is_gnu_style_;
// For incremental update links, this will hold the offset of the
// input section within the output section. Offsets read from
// relocated data will be relative to the output section, and need

View File

@ -32,7 +32,7 @@
namespace gold
{
const int gdb_index_version = 5;
const int gdb_index_version = 7;
// Sizes of various records in the .gdb_index section.
const int gdb_index_offset_size = 4;
@ -436,7 +436,8 @@ Gdb_index_info_reader::visit_die(Dwarf_die* die, Dwarf_die* context)
// If the DIE is not a declaration, add it to the index.
std::string full_name = this->get_qualified_name(die, context);
if (!full_name.empty())
this->gdb_index_->add_symbol(this->cu_index_, full_name.c_str());
this->gdb_index_->add_symbol(this->cu_index_,
full_name.c_str(), 0);
}
break;
case elfcpp::DW_TAG_typedef:
@ -476,7 +477,7 @@ Gdb_index_info_reader::visit_die(Dwarf_die* die, Dwarf_die* context)
full_name = this->get_qualified_name(die, context);
if (!full_name.empty())
this->gdb_index_->add_symbol(this->cu_index_,
full_name.c_str());
full_name.c_str(), 0);
}
// We're interested in the children only for namespaces and
@ -870,11 +871,12 @@ Gdb_index_info_reader::read_pubtable(Dwarf_pubnames_table* table, off_t offset)
return false;
while (true)
{
const char* name = table->next_name();
uint8_t flag_byte;
const char* name = table->next_name(&flag_byte);
if (name == NULL)
break;
this->gdb_index_->add_symbol(this->cu_index_, name);
this->gdb_index_->add_symbol(this->cu_index_, name, flag_byte);
}
return true;
}
@ -885,6 +887,14 @@ Gdb_index_info_reader::read_pubtable(Dwarf_pubnames_table* table, off_t offset)
bool
Gdb_index_info_reader::read_pubnames_and_pubtypes(Dwarf_die* die)
{
// If this is a skeleton debug-type die (generated via
// -gsplit-dwarf), then the associated pubnames should have been
// read along with the corresponding CU. In any case, there isn't
// enough info inside to build a gdb index entry.
if (die->tag() == elfcpp::DW_TAG_type_unit
&& die->string_attribute(elfcpp::DW_AT_GNU_dwo_name))
return true;
// We use stmt_list_off as a unique identifier for the
// compilation unit and its associated type units.
unsigned int shndx;
@ -1112,7 +1122,7 @@ Gdb_index::scan_debug_info(bool is_type_unit,
// Add a symbol.
void
Gdb_index::add_symbol(int cu_index, const char* sym_name)
Gdb_index::add_symbol(int cu_index, const char* sym_name, uint8_t flags)
{
unsigned int hash = mapped_index_string_hash(
reinterpret_cast<const unsigned char*>(sym_name));
@ -1139,8 +1149,10 @@ Gdb_index::add_symbol(int cu_index, const char* sym_name)
// if it's not already on the list. We only need to
// check the last added entry.
Cu_vector* cu_vec = this->cu_vector_list_[found->cu_vector_index];
if (cu_vec->size() == 0 || cu_vec->back() != cu_index)
cu_vec->push_back(cu_index);
if (cu_vec->size() == 0
|| cu_vec->back().first != cu_index
|| cu_vec->back().second != flags)
cu_vec->push_back(std::make_pair(cu_index, flags));
}
// Return TRUE if we have already processed the pubnames associated
@ -1317,9 +1329,11 @@ Gdb_index::do_write(Output_file* of)
pov += 4;
for (unsigned int j = 0; j < cu_vec->size(); ++j)
{
int cu_index = (*cu_vec)[j];
int cu_index = (*cu_vec)[j].first;
uint8_t flags = (*cu_vec)[j].second;
if (cu_index < 0)
cu_index = comp_units_count + (-1 - cu_index);
cu_index |= flags << 24;
elfcpp::Swap<32, false>::writeval(pov, cu_index);
pov += 4;
}

View File

@ -89,9 +89,10 @@ class Gdb_index : public Output_section_data
this->ranges_.push_back(Per_cu_range_list(object, cu_index, ranges));
}
// Add a symbol.
// Add a symbol. FLAGS are the gdb_index version 7 flags to be stored in
// the high-byte of the cu_index field.
void
add_symbol(int cu_index, const char* sym_name);
add_symbol(int cu_index, const char* sym_name, uint8_t flags);
// Return the offset into the pubnames table for the cu at the given
// offset.
@ -213,7 +214,7 @@ class Gdb_index : public Output_section_data
{ return this->name_key == symbol->name_key; }
};
typedef std::vector<int> Cu_vector;
typedef std::vector<std::pair<int, uint8_t> > Cu_vector;
typedef Unordered_map<off_t, off_t> Pubname_offset_map;
Pubname_offset_map cu_pubname_map_;

View File

@ -37,7 +37,7 @@ check()
STDOUT=gdb_index_test_3.stdout
check $STDOUT "^Version [45]"
check $STDOUT "^Version [4-7]"
# Look for the symbols we know should be in the symbol table.

View File

@ -37,7 +37,7 @@ check()
STDOUT="$1"
check $STDOUT "^Version [45]"
check $STDOUT "^Version [4-7]"
# Look for the symbols we know should be in the symbol table.