• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修订版76b3c0a5333ab4741e9d4d0c57972c1d14a8cd19 (tree)
时间2015-02-23 16:44:23
作者Cary Coutant <ccoutant@goog...>
CommiterCary Coutant

Log Message

Support compressed debug in dyn objects.

2015-02-09 Cary Coutant <ccoutant@google.com>

gold/
* dwp.cc (Sized_relobj_dwo::do_decompressed_section_contents): Delete.
(Sized_relobj_dwo::setup): Setup map of compressed sections.
(print_version): Update copyright.
* dynobj.cc (Sized_dynobj::base_read_symbols): Set up map of compressed
sections.
* object.cc (Sized_relobj_file::compressed_sections): Delete.
(build_compressed_section_map): Add decompress_if_needed parameter.
Adjust callers.
(Sized_relobj_file::do_find_special_sections): Set compressed sections
map in Object base class.
(Sized_relobj_file::do_decompressed_section_contents): Rename to
Object::decompressed_section_contents.
(Sized_relobj_file::do_discard_decompressed_sections): Rename to
Object::discard_decompressed_sections.
* object.h (Object::compressed_sections_): New data member.
(Object::section_is_compressed): Remove virtual, implement here.
(Object::decompressed_section_contents): Remove virtual.
(Object::do_section_is_compressed): Delete.
(Object::do_decompressed_section_contents): Delete.
(Object::set_compressed_sections): New method.
(Object::compressed_sections): New method.
(Sized_relobj_file::do_section_is_compressed): Delete.
(Sized_relobj_file::do_decompressed_section_contents): Delete.
(Sized_relobj_file::do_discard_decompressed_sections): Delete.
(Sized_relobj_file::compressed_sections): Delete.

更改概述

差异

--- a/gold/dwp.cc
+++ b/gold/dwp.cc
@@ -284,14 +284,6 @@ class Sized_relobj_dwo : public Sized_relobj<size, big_endian>
284284 const unsigned char*
285285 do_section_contents(unsigned int, section_size_type*, bool);
286286
287- // Return a view of the uncompressed contents of a section. Set *PLEN
288- // to the size. Set *IS_NEW to true if the contents need to be deleted
289- // by the caller.
290- const unsigned char*
291- do_decompressed_section_contents(unsigned int shndx,
292- section_size_type* plen,
293- bool* is_new);
294-
295287 // The following virtual functions are abstract in the base classes,
296288 // but are not used here.
297289
@@ -781,9 +773,36 @@ template <int size, bool big_endian>
781773 void
782774 Sized_relobj_dwo<size, big_endian>::setup()
783775 {
776+ const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
777+ const off_t shoff = this->elf_file_.shoff();
784778 const unsigned int shnum = this->elf_file_.shnum();
779+
785780 this->set_shnum(shnum);
786781 this->section_offsets().resize(shnum);
782+
783+ // Read the section headers.
784+ const unsigned char* const pshdrs = this->get_view(shoff, shnum * shdr_size,
785+ true, false);
786+
787+ // Read the section names.
788+ const unsigned char* pshdrnames =
789+ pshdrs + this->elf_file_.shstrndx() * shdr_size;
790+ typename elfcpp::Shdr<size, big_endian> shdrnames(pshdrnames);
791+ if (shdrnames.get_sh_type() != elfcpp::SHT_STRTAB)
792+ this->error(_("section name section has wrong type: %u"),
793+ static_cast<unsigned int>(shdrnames.get_sh_type()));
794+ section_size_type section_names_size =
795+ convert_to_section_size_type(shdrnames.get_sh_size());
796+ const unsigned char* namesu = this->get_view(shdrnames.get_sh_offset(),
797+ section_names_size, false,
798+ false);
799+ const char* names = reinterpret_cast<const char*>(namesu);
800+
801+ Compressed_section_map* compressed_sections =
802+ build_compressed_section_map<size, big_endian>(
803+ pshdrs, this->shnum(), names, section_names_size, this, true);
804+ if (compressed_sections != NULL && !compressed_sections->empty())
805+ this->set_compressed_sections(compressed_sections);
787806 }
788807
789808 // Return a view of the contents of a section.
@@ -805,43 +824,6 @@ Sized_relobj_dwo<size, big_endian>::do_section_contents(
805824 return this->get_view(loc.file_offset, *plen, true, cache);
806825 }
807826
808-// Return a view of the uncompressed contents of a section. Set *PLEN
809-// to the size. Set *IS_NEW to true if the contents need to be deleted
810-// by the caller.
811-
812-template <int size, bool big_endian>
813-const unsigned char*
814-Sized_relobj_dwo<size, big_endian>::do_decompressed_section_contents(
815- unsigned int shndx,
816- section_size_type* plen,
817- bool* is_new)
818-{
819- section_size_type buffer_size;
820- const unsigned char* buffer = this->do_section_contents(shndx, &buffer_size,
821- false);
822-
823- std::string sect_name = this->do_section_name(shndx);
824- if (!is_prefix_of(".zdebug_", sect_name.c_str()))
825- {
826- *plen = buffer_size;
827- *is_new = false;
828- return buffer;
829- }
830-
831- section_size_type uncompressed_size = get_uncompressed_size(buffer,
832- buffer_size);
833- unsigned char* uncompressed_data = new unsigned char[uncompressed_size];
834- if (!decompress_input_section(buffer,
835- buffer_size,
836- uncompressed_data,
837- uncompressed_size))
838- this->error(_("could not decompress section %s"),
839- this->section_name(shndx).c_str());
840- *plen = uncompressed_size;
841- *is_new = true;
842- return uncompressed_data;
843-}
844-
845827 // Class Dwo_file.
846828
847829 Dwo_file::~Dwo_file()
@@ -2352,7 +2334,7 @@ print_version()
23522334 {
23532335 // This output is intended to follow the GNU standards.
23542336 printf("GNU dwp %s\n", BFD_VERSION_STRING);
2355- printf(_("Copyright (C) 2014-2015 Free Software Foundation, Inc.\n"));
2337+ printf(_("Copyright (C) 2015 Free Software Foundation, Inc.\n"));
23562338 printf(_("\
23572339 This program is free software; you may redistribute it under the terms of\n\
23582340 the GNU General Public License version 3 or (at your option) any later version.\n\
--- a/gold/dynobj.cc
+++ b/gold/dynobj.cc
@@ -374,6 +374,17 @@ Sized_dynobj<size, big_endian>::base_read_symbols(Read_symbols_data* sd)
374374 sd->verneed_size = 0;
375375 sd->verneed_info = 0;
376376
377+ const unsigned char* namesu = sd->section_names->data();
378+ const char* names = reinterpret_cast<const char*>(namesu);
379+ if (memmem(names, sd->section_names_size, ".zdebug_", 8) != NULL)
380+ {
381+ Compressed_section_map* compressed_sections =
382+ build_compressed_section_map<size, big_endian>(
383+ pshdrs, this->shnum(), names, sd->section_names_size, this, true);
384+ if (compressed_sections != NULL)
385+ this->set_compressed_sections(compressed_sections);
386+ }
387+
377388 if (this->dynsym_shndx_ != -1U)
378389 {
379390 // Get the dynamic symbols.
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -432,8 +432,7 @@ Sized_relobj_file<size, big_endian>::Sized_relobj_file(
432432 discarded_eh_frame_shndx_(-1U),
433433 is_deferred_layout_(false),
434434 deferred_layout_(),
435- deferred_layout_relocs_(),
436- compressed_sections_()
435+ deferred_layout_relocs_()
437436 {
438437 this->e_type_ = ehdr.get_e_type();
439438 }
@@ -675,7 +674,8 @@ build_compressed_section_map(
675674 unsigned int shnum,
676675 const char* names,
677676 section_size_type names_size,
678- Sized_relobj_file<size, big_endian>* obj)
677+ Object* obj,
678+ bool decompress_if_needed)
679679 {
680680 Compressed_section_map* uncompressed_map = new Compressed_section_map();
681681 const unsigned int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
@@ -707,7 +707,7 @@ build_compressed_section_map(
707707 if (uncompressed_size != -1ULL)
708708 {
709709 unsigned char* uncompressed_data = NULL;
710- if (need_decompressed_section(name))
710+ if (decompress_if_needed && need_decompressed_section(name))
711711 {
712712 uncompressed_data = new unsigned char[uncompressed_size];
713713 if (decompress_input_section(contents, len,
@@ -741,9 +741,14 @@ Sized_relobj_file<size, big_endian>::do_find_special_sections(
741741 this->has_eh_frame_ = true;
742742
743743 if (memmem(names, sd->section_names_size, ".zdebug_", 8) != NULL)
744- this->compressed_sections_
745- = build_compressed_section_map(pshdrs, this->shnum(), names,
746- sd->section_names_size, this);
744+ {
745+ Compressed_section_map* compressed_sections =
746+ build_compressed_section_map<size, big_endian>(
747+ pshdrs, this->shnum(), names, sd->section_names_size, this, true);
748+ if (compressed_sections != NULL)
749+ this->set_compressed_sections(compressed_sections);
750+ }
751+
747752 return (this->has_eh_frame_
748753 || (!parameters->options().relocatable()
749754 && parameters->options().gdb_index()
@@ -2804,9 +2809,8 @@ Sized_relobj_file<size, big_endian>::do_get_global_symbol_counts(
28042809 // to the size. Set *IS_NEW to true if the contents need to be freed
28052810 // by the caller.
28062811
2807-template<int size, bool big_endian>
28082812 const unsigned char*
2809-Sized_relobj_file<size, big_endian>::do_decompressed_section_contents(
2813+Object::decompressed_section_contents(
28102814 unsigned int shndx,
28112815 section_size_type* plen,
28122816 bool* is_new)
@@ -2860,9 +2864,8 @@ Sized_relobj_file<size, big_endian>::do_decompressed_section_contents(
28602864 // Discard any buffers of uncompressed sections. This is done
28612865 // at the end of the Add_symbols task.
28622866
2863-template<int size, bool big_endian>
28642867 void
2865-Sized_relobj_file<size, big_endian>::do_discard_decompressed_sections()
2868+Object::discard_decompressed_sections()
28662869 {
28672870 if (this->compressed_sections_ == NULL)
28682871 return;
--- a/gold/object.h
+++ b/gold/object.h
@@ -314,6 +314,21 @@ class Got_offset_list
314314 Got_offset_list* got_next_;
315315 };
316316
317+// Type for mapping section index to uncompressed size and contents.
318+
319+struct Compressed_section_info
320+{
321+ section_size_type size;
322+ const unsigned char* contents;
323+};
324+typedef std::map<unsigned int, Compressed_section_info> Compressed_section_map;
325+
326+template<int size, bool big_endian>
327+Compressed_section_map*
328+build_compressed_section_map(const unsigned char* pshdrs, unsigned int shnum,
329+ const char* names, section_size_type names_size,
330+ Object* obj, bool decompress_if_needed);
331+
317332 // Object is an abstract base class which represents either a 32-bit
318333 // or a 64-bit input object. This can be a regular object file
319334 // (ET_REL) or a shared object (ET_DYN).
@@ -332,7 +347,8 @@ class Object
332347 : name_(name), input_file_(input_file), offset_(offset), shnum_(-1U),
333348 is_dynamic_(is_dynamic), is_needed_(false), uses_split_stack_(false),
334349 has_no_split_stack_(false), no_export_(false),
335- is_in_system_directory_(false), as_needed_(false), xindex_(NULL)
350+ is_in_system_directory_(false), as_needed_(false), xindex_(NULL),
351+ compressed_sections_(NULL)
336352 {
337353 if (input_file != NULL)
338354 {
@@ -725,26 +741,34 @@ class Object
725741 set_no_export(bool value)
726742 { this->no_export_ = value; }
727743
728- // Return TRUE if the section is a compressed debug section, and set
729- // *UNCOMPRESSED_SIZE to the size of the uncompressed data.
730744 bool
731745 section_is_compressed(unsigned int shndx,
732746 section_size_type* uncompressed_size) const
733- { return this->do_section_is_compressed(shndx, uncompressed_size); }
747+ {
748+ if (this->compressed_sections_ == NULL)
749+ return false;
750+ Compressed_section_map::const_iterator p =
751+ this->compressed_sections_->find(shndx);
752+ if (p != this->compressed_sections_->end())
753+ {
754+ if (uncompressed_size != NULL)
755+ *uncompressed_size = p->second.size;
756+ return true;
757+ }
758+ return false;
759+ }
734760
735761 // Return a view of the decompressed contents of a section. Set *PLEN
736762 // to the size. Set *IS_NEW to true if the contents need to be freed
737763 // by the caller.
738764 const unsigned char*
739765 decompressed_section_contents(unsigned int shndx, section_size_type* plen,
740- bool* is_cached)
741- { return this->do_decompressed_section_contents(shndx, plen, is_cached); }
766+ bool* is_cached);
742767
743768 // Discard any buffers of decompressed sections. This is done
744769 // at the end of the Add_symbols task.
745770 void
746- discard_decompressed_sections()
747- { this->do_discard_decompressed_sections(); }
771+ discard_decompressed_sections();
748772
749773 // Return the index of the first incremental relocation for symbol SYMNDX.
750774 unsigned int
@@ -923,27 +947,6 @@ class Object
923947 bool
924948 handle_split_stack_section(const char* name);
925949
926- // Return TRUE if the section is a compressed debug section, and set
927- // *UNCOMPRESSED_SIZE to the size of the uncompressed data.
928- virtual bool
929- do_section_is_compressed(unsigned int, section_size_type*) const
930- { return false; }
931-
932- // Return a view of the decompressed contents of a section. Set *PLEN
933- // to the size. This default implementation simply returns the
934- // raw section contents and sets *IS_NEW to false to indicate
935- // that the contents do not need to be freed by the caller.
936- // This function must be overridden for any types of object files
937- // that might contain compressed sections.
938- virtual const unsigned char*
939- do_decompressed_section_contents(unsigned int shndx,
940- section_size_type* plen,
941- bool* is_new)
942- {
943- *is_new = false;
944- return this->do_section_contents(shndx, plen, false);
945- }
946-
947950 // Discard any buffers of decompressed sections. This is done
948951 // at the end of the Add_symbols task.
949952 virtual void
@@ -962,6 +965,14 @@ class Object
962965 do_get_incremental_reloc_count(unsigned int) const
963966 { gold_unreachable(); }
964967
968+ void
969+ set_compressed_sections(Compressed_section_map* compressed_sections)
970+ { this->compressed_sections_ = compressed_sections; }
971+
972+ Compressed_section_map*
973+ compressed_sections()
974+ { return this->compressed_sections_; }
975+
965976 private:
966977 // This class may not be copied.
967978 Object(const Object&);
@@ -996,6 +1007,9 @@ class Object
9961007 bool as_needed_ : 1;
9971008 // Many sections for objects with more than SHN_LORESERVE sections.
9981009 Xindex* xindex_;
1010+ // For compressed debug sections, map section index to uncompressed size
1011+ // and contents.
1012+ Compressed_section_map* compressed_sections_;
9991013 };
10001014
10011015 // A regular object (ET_REL). This is an abstract base class itself.
@@ -1862,15 +1876,6 @@ class Reloc_symbol_changes
18621876 std::vector<Symbol*> vec_;
18631877 };
18641878
1865-// Type for mapping section index to uncompressed size and contents.
1866-
1867-struct Compressed_section_info
1868-{
1869- section_size_type size;
1870- const unsigned char* contents;
1871-};
1872-typedef std::map<unsigned int, Compressed_section_info> Compressed_section_map;
1873-
18741879 // Abstract base class for a regular object file, either a real object file
18751880 // or an incremental (unchanged) object. This is size and endian specific.
18761881
@@ -2453,38 +2458,6 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
24532458 set_output_local_symbol_count(unsigned int value)
24542459 { this->output_local_symbol_count_ = value; }
24552460
2456- // Return TRUE if the section is a compressed debug section, and set
2457- // *UNCOMPRESSED_SIZE to the size of the uncompressed data.
2458- bool
2459- do_section_is_compressed(unsigned int shndx,
2460- section_size_type* uncompressed_size) const
2461- {
2462- if (this->compressed_sections_ == NULL)
2463- return false;
2464- Compressed_section_map::const_iterator p =
2465- this->compressed_sections_->find(shndx);
2466- if (p != this->compressed_sections_->end())
2467- {
2468- if (uncompressed_size != NULL)
2469- *uncompressed_size = p->second.size;
2470- return true;
2471- }
2472- return false;
2473- }
2474-
2475- // Return a view of the uncompressed contents of a section. Set *PLEN
2476- // to the size. Set *IS_NEW to true if the contents need to be deleted
2477- // by the caller.
2478- const unsigned char*
2479- do_decompressed_section_contents(unsigned int shndx,
2480- section_size_type* plen,
2481- bool* is_new);
2482-
2483- // Discard any buffers of decompressed sections. This is done
2484- // at the end of the Add_symbols task.
2485- void
2486- do_discard_decompressed_sections();
2487-
24882461 private:
24892462 // For convenience.
24902463 typedef Sized_relobj_file<size, big_endian> This;
@@ -2751,9 +2724,6 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
27512724 std::vector<Deferred_layout> deferred_layout_;
27522725 // The list of relocation sections whose layout was deferred.
27532726 std::vector<Deferred_layout> deferred_layout_relocs_;
2754- // For compressed debug sections, map section index to uncompressed size
2755- // and contents.
2756- Compressed_section_map* compressed_sections_;
27572727 };
27582728
27592729 // A class to manage the list of all objects.