aboutsummaryrefslogtreecommitdiff
path: root/gold/reduced_debug_output.h
blob: 04a75063b15d4ca7e81be21f04b1c2c68cc4cb28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// reduced_debug_output.h -- reduce debugging information  -*- C++ -*-

// Copyright (C) 2008-2016 Free Software Foundation, Inc.
// Written by Caleb Howe <cshowe@google.com>.

// This file is part of gold.

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
// MA 02110-1301, USA.

// Reduce the size of the debug sections by emitting only debug line number
// information.  We still need to emit skeleton debug_info and debug_abbrev
// sections for standard tools to parse the debug information correctly.  These
// classes remove all debug information entries from the .debug_info section
// except for those describing compilation units as these DIEs contain
// references to the debug line information needed by most parsers.

#ifndef GOLD_REDUCED_DEBUG_OUTPUT_H
#define GOLD_REDUCED_DEBUG_OUTPUT_H

#include <map>
#include <utility>
#include <vector>

#include "output.h"

namespace gold
{

class Output_reduced_debug_abbrev_section : public Output_section
{
 public:
  Output_reduced_debug_abbrev_section(const char* name, elfcpp::Elf_Word flags,
			              elfcpp::Elf_Xword type)
    : Output_section(name, flags, type), sized_(false),
      abbrev_count_(0), failed_(false)
  { this->set_requires_postprocessing(); }

  unsigned char* get_new_abbrev(uint64_t* abbrev_number,
                                uint64_t abbrev_offset);

 protected:
  // Set the final data size.
  void
  set_final_data_size();

  // Write out the new debug abbreviations
  void
  do_write(Output_file*);

 private:
  void
  failed(std::string reason)
  {
    gold_warning("%s", reason.c_str());
    failed_ = true;
  }

  // The reduced debug abbreviations
  std::vector<unsigned char> data_;

  // We map the abbreviation table offset and abbreviation number of the
  // old abbreviation to the number and size of the new abbreviation.
  std::map<std::pair<uint64_t, uint64_t>,
           std::pair<uint64_t, uint64_t> > abbrev_mapping_;

  bool sized_;

  // The count of abbreviations in the output data
  int abbrev_count_;

  // Whether or not the debug reduction has failed for any reason
  bool failed_;
};

class Output_reduced_debug_info_section : public Output_section
{
 public:
  Output_reduced_debug_info_section(const char* name, elfcpp::Elf_Word flags,
			            elfcpp::Elf_Xword type)
    : Output_section(name, flags, type), failed_(false)
  { this->set_requires_postprocessing(); }

  void
  set_abbreviations(Output_reduced_debug_abbrev_section* abbrevs)
  { associated_abbrev_ = abbrevs; }

 protected:
  // Set the final data size.
  void
  set_final_data_size();

  // Write out the new debug info
  void
  do_write(Output_file*);

 private:
  void
  failed(std::string reason)
  {
    gold_warning("%s", reason.c_str());
    this->failed_ = true;
  }

  // Given a pointer to the beginning of a die and the beginning of the
  // associated abbreviation fills in die_end with the end of the information
  // entry.  If successful returns true.  Get_die_end also takes a pointer to
  // the end of the buffer containing the die. If die_end would be beyond the
  // end of the buffer, or if an unsupported dwarf form is encountered returns
  // false.
  bool
  get_die_end(unsigned char* die, unsigned char* abbrev,
	      unsigned char** die_end, unsigned char* buffer_end,
	      int address_size, bool is64);

  // The reduced debug info
  std::vector<unsigned char> data_;

  // Each debug info section needs to be associated with a debug abbrev section
  Output_reduced_debug_abbrev_section* associated_abbrev_;

  // Whether or not the debug reduction has failed for any reason
  bool failed_;
};

} // End namespace gold.

#endif // !defined(GOLD_REDUCED_DEBUG_OUTPUT_H)