aboutsummaryrefslogtreecommitdiff
path: root/gold/layout.cc
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@google.com>2012-03-21 19:02:22 +0000
committerCary Coutant <ccoutant@google.com>2012-03-21 19:02:22 +0000
commitc1027032c2fec15b7a334a09bab8882984716764 (patch)
tree5f0623fb4d01b2456a7a827e49daf53a6239cb2e /gold/layout.cc
parentbd0b9f9e12441312c46482764448a8a8ce236107 (diff)
downloadgdb-c1027032c2fec15b7a334a09bab8882984716764.zip
gdb-c1027032c2fec15b7a334a09bab8882984716764.tar.gz
gdb-c1027032c2fec15b7a334a09bab8882984716764.tar.bz2
2012-03-21 Cary Coutant <ccoutant@google.com>
* Makefile.am: Add gdb-index.cc, gdb-index.h. * Makefile.in: Regenerate. * dwarf_reader.cc (Sized_elf_reloc_mapper::do_initialize): New function. (Sized_elf_reloc_mapper::symbol_section): New function. (Sized_elf_reloc_mapper::do_get_reloc_target): New function. (make_elf_reloc_mapper): New function. (Dwarf_abbrev_table::clear_abbrev_codes): New function. (Dwarf_abbrev_table::do_read_abbrevs): New function. (Dwarf_abbrev_table::do_get_abbrev): New function. (Dwarf_ranges_table::read_ranges_table): New function. (Dwarf_ranges_table::read_range_list): New function. (Dwarf_pubnames_table::read_section): New function. (Dwarf_pubnames_table::read_header): New function. (Dwarf_pubnames_table::next_name): New function. (Dwarf_die::Dwarf_die): New function. (Dwarf_die::read_attributes): New function. (Dwarf_die::skip_attributes): New function. (Dwarf_die::set_name): New function. (Dwarf_die::set_linkage_name): New function. (Dwarf_die::attribute): New function. (Dwarf_die::string_attribute): New function. (Dwarf_die::int_attribute): New function. (Dwarf_die::uint_attribute): New function. (Dwarf_die::ref_attribute): New function. (Dwarf_die::child_offset): New function. (Dwarf_die::sibling_offset): New function. (Dwarf_info_reader::check_buffer): New function. (Dwarf_info_reader::parse): New function. (Dwarf_info_reader::do_parse): New function. (Dwarf_info_reader::do_read_string_table): New function. (Dwarf_info_reader::lookup_reloc): New function. (Dwarf_info_reader::get_string): New function. (Dwarf_info_reader::visit_compilation_unit): New function. (Dwarf_info_reader::visit_type_unit): New function. (Sized_dwarf_line_info::Sized_dwarf_line_info): Use Sized_elf_reloc_mapper. (Sized_dwarf_line_info::symbol_section): Remove function. (Sized_dwarf_line_info::read_relocs): Use Sized_elf_reloc_mapper. (Sized_dwarf_line_info::read_line_mappings): Remove object parameter, adjust callers. (Sized_dwarf_line_info::format_file_lineno): Fix type of cast. * dwarf_reader.h: Include <sys/types.h>. (class Track_relocs): Remove forward declaration. (class Elf_reloc_mapper): New class. (class Sized_elf_reloc_mapper): New class. (class Dwarf_abbrev_table): New class. (class Dwarf_range_list): New class. (class Dwarf_ranges_table): New class. (class Dwarf_pubnames_table): New class. (class Dwarf_die): New class. (class Dwarf_info_reader): New class. (Sized_dwarf_line_info::read_line_mappings): Remove object parameter. (Sized_dwarf_line_info::symbol_section): Remove member function. * dynobj.h (Sized_dynobj::do_section_contents): Refactor code from base class. * gdb-index.cc: New source file. * gdb-index.h: New source file. * incremental.cc (Sized_relobj_incr::do_layout): Track .debug_info and .debug_types sections, call Layout::add_to_gdb_index. (Sized_relobj_incr::do_section_name): Implement. (Sized_relobj_incr::do_section_contents): Adjust parameter list and return type; Implement. (Sized_incr_dynobj::do_section_contents): Adjust parameter list and return type. * incremental.h (Sized_relobj_incr::do_section_contents): Adjust parameter list and return type. (Sized_incr_dynobj::do_section_contents): Likewise. * layout.cc: Include gdb-index.h. (Layout::Layout): Initialize gdb_index_data_. (Layout::init_fixed_output_section): Check for .gdb_index section. (Layout::add_to_gdb_index): New function. Instantiate. * layout.h: Add forward declaration for class Gdb_index. (Layout::add_to_gdb_index): New member function. (Layout::gdb_index_data_): New data member. * main.cc: Include gdb-index.h. (main): Print statistics for gdb index. * object.cc (Object::section_contents): Move code into do_section_contents. (need_decompressed_section): Check for sections needed when building gdb index. (build_compressed_section_map): Likewise. (Sized_relobj_file::do_read_symbols): Need local symbols when building gdb index. (Sized_relobj_file::do_layout): Track .debug_info and .debug_types sections; call Layout::add_to_gdb_index. (Sized_relobj_file::do_decompressed_section_contents): Call do_section_contents directly. * object.h (Object::do_section_contents): Adjust parameter list and return type. (Object::do_decompressed_section_contents): Call do_section_contents directly. (Sized_relobj_file::do_section_contents): Adjust parameter list and return type. * options.h (class General_options): Add --gdb-index option. * plugin.cc (Sized_pluginobj::do_section_contents): Adjust parameter list and return type. * plugin.h (Sized_pluginobj::do_section_contents): Likewise. * reloc.h (Track_relocs::checkpoint): New function. (Track_relocs::reset): New function. * testsuite/Makefile.am (gdb_index_test_1.sh, gdb_index_test_2.sh): New test cases. * testsuite/Makefile.in: Regenerate. * testsuite/gdb_index_test.cc: New test source file. * testsuite/gdb_index_test_1.sh: New test source file. * testsuite/gdb_index_test_2.sh: New test source file.
Diffstat (limited to 'gold/layout.cc')
-rw-r--r--gold/layout.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/gold/layout.cc b/gold/layout.cc
index c120376..65d1432 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -44,6 +44,7 @@
#include "symtab.h"
#include "dynobj.h"
#include "ehframe.h"
+#include "gdb-index.h"
#include "compressed_output.h"
#include "reduced_debug_output.h"
#include "object.h"
@@ -390,6 +391,7 @@ Layout::Layout(int number_of_input_files, Script_options* script_options)
eh_frame_data_(NULL),
added_eh_frame_data_(false),
eh_frame_hdr_section_(NULL),
+ gdb_index_data_(NULL),
build_id_note_(NULL),
debug_abbrev_(NULL),
debug_info_(NULL),
@@ -905,6 +907,13 @@ Layout::init_fixed_output_section(const char* name,
if (!can_incremental_update(sh_type))
return NULL;
+ // If we're generating a .gdb_index section, we need to regenerate
+ // it from scratch.
+ if (parameters->options().gdb_index()
+ && sh_type == elfcpp::SHT_PROGBITS
+ && strcmp(name, ".gdb_index") == 0)
+ return NULL;
+
typename elfcpp::Elf_types<size>::Elf_Addr sh_addr = shdr.get_sh_addr();
typename elfcpp::Elf_types<size>::Elf_Off sh_offset = shdr.get_sh_offset();
typename elfcpp::Elf_types<size>::Elf_WXword sh_size = shdr.get_sh_size();
@@ -1292,6 +1301,38 @@ Layout::add_eh_frame_for_plt(Output_data* plt, const unsigned char* cie_data,
}
}
+// Scan a .debug_info or .debug_types section, and add summary
+// information to the .gdb_index section.
+
+template<int size, bool big_endian>
+void
+Layout::add_to_gdb_index(bool is_type_unit,
+ Sized_relobj<size, big_endian>* object,
+ const unsigned char* symbols,
+ off_t symbols_size,
+ unsigned int shndx,
+ unsigned int reloc_shndx,
+ unsigned int reloc_type)
+{
+ if (this->gdb_index_data_ == NULL)
+ {
+ Output_section* os = this->choose_output_section(NULL, ".gdb_index",
+ elfcpp::SHT_PROGBITS, 0,
+ false, ORDER_INVALID,
+ false);
+ if (os == NULL)
+ return;
+
+ this->gdb_index_data_ = new Gdb_index(os);
+ os->add_output_section_data(this->gdb_index_data_);
+ os->set_after_input_sections();
+ }
+
+ this->gdb_index_data_->scan_debug_info(is_type_unit, object, symbols,
+ symbols_size, shndx, reloc_shndx,
+ reloc_type);
+}
+
// Add POSD to an output section using NAME, TYPE, and FLAGS. Return
// the output section.
@@ -5297,4 +5338,52 @@ Layout::layout_eh_frame<64, true>(Sized_relobj_file<64, true>* object,
off_t* off);
#endif
+#ifdef HAVE_TARGET_32_LITTLE
+template
+void
+Layout::add_to_gdb_index(bool is_type_unit,
+ Sized_relobj<32, false>* object,
+ const unsigned char* symbols,
+ off_t symbols_size,
+ unsigned int shndx,
+ unsigned int reloc_shndx,
+ unsigned int reloc_type);
+#endif
+
+#ifdef HAVE_TARGET_32_BIG
+template
+void
+Layout::add_to_gdb_index(bool is_type_unit,
+ Sized_relobj<32, true>* object,
+ const unsigned char* symbols,
+ off_t symbols_size,
+ unsigned int shndx,
+ unsigned int reloc_shndx,
+ unsigned int reloc_type);
+#endif
+
+#ifdef HAVE_TARGET_64_LITTLE
+template
+void
+Layout::add_to_gdb_index(bool is_type_unit,
+ Sized_relobj<64, false>* object,
+ const unsigned char* symbols,
+ off_t symbols_size,
+ unsigned int shndx,
+ unsigned int reloc_shndx,
+ unsigned int reloc_type);
+#endif
+
+#ifdef HAVE_TARGET_64_BIG
+template
+void
+Layout::add_to_gdb_index(bool is_type_unit,
+ Sized_relobj<64, true>* object,
+ const unsigned char* symbols,
+ off_t symbols_size,
+ unsigned int shndx,
+ unsigned int reloc_shndx,
+ unsigned int reloc_type);
+#endif
+
} // End namespace gold.