aboutsummaryrefslogtreecommitdiff
path: root/gold/layout.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2008-05-28 20:48:16 +0000
committerIan Lance Taylor <ian@airs.com>2008-05-28 20:48:16 +0000
commit62b01cb5034c3694d07c60158529f18cb301bb5c (patch)
tree22682d726ba0094de43e3b3eb47306a3e08f5e93 /gold/layout.cc
parent1a51c1a48dafc996d6c199832cb75b46779d33ae (diff)
downloadgdb-62b01cb5034c3694d07c60158529f18cb301bb5c.zip
gdb-62b01cb5034c3694d07c60158529f18cb301bb5c.tar.gz
gdb-62b01cb5034c3694d07c60158529f18cb301bb5c.tar.bz2
elfcpp/:
* dwarf.h (enum DW_FORM): Define. gold/: * reduced_debug_output.cc: New file. * reduced_debug_output.h: New file. * options.h (class General_optoins): Add --strip-debug-non-line. * options.cc (General_options::finalize): Add strip_debug_non_line to the strip heirarchy. * layout.h (class Layout): Add debug_abbrev_ and debug_info_ fields. * layout.cc: Include "reduced_debug_output.h". (Layout::Layout): Initialize new fields. (line_only_debug_sections): New static array. (is_lines_only_debug_sections): New static inline function. (Layout::include_section): Handle --strip-debug-non-line. (Layout::make_output_section): If --strip-debug-non-line, build new output sections for .debug_abbrev and .debug_info. * dwarf_reader.cc (read_unsigned_LEB_128): Move to namespace gold. Warn about possible overflow. (read_signed_LEB_128): Likewise. * dwarf_reader.h: (read_unsigned_LEB_128): Declare. (read_signed_LEB_128): Declare. * Makefile.am (CCFILES): Add reduced_debug_output.cc. (HFILES): Add reduced_debug_output.h. * Makefile.in: Rebuild.
Diffstat (limited to 'gold/layout.cc')
-rw-r--r--gold/layout.cc57
1 files changed, 56 insertions, 1 deletions
diff --git a/gold/layout.cc b/gold/layout.cc
index a4003d5..2c8c524 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -43,6 +43,7 @@
#include "dynobj.h"
#include "ehframe.h"
#include "compressed_output.h"
+#include "reduced_debug_output.h"
#include "reloc.h"
#include "layout.h"
@@ -110,6 +111,8 @@ Layout::Layout(const General_options& options, Script_options* script_options)
added_eh_frame_data_(false),
eh_frame_hdr_section_(NULL),
build_id_note_(NULL),
+ debug_abbrev_(NULL),
+ debug_info_(NULL),
group_signatures_(),
output_file_size_(-1),
input_requires_executable_stack_(false),
@@ -160,6 +163,19 @@ static const char* gdb_sections[] =
".debug_str",
};
+static const char* lines_only_debug_sections[] =
+{ ".debug_abbrev",
+ // ".debug_aranges", // not used by gdb as of 6.7.1
+ // ".debug_frame",
+ ".debug_info",
+ ".debug_line",
+ // ".debug_loc",
+ // ".debug_macinfo",
+ // ".debug_pubnames", // not used by gdb as of 6.7.1
+ // ".debug_ranges",
+ ".debug_str",
+};
+
static inline bool
is_gdb_debug_section(const char* str)
{
@@ -170,6 +186,18 @@ is_gdb_debug_section(const char* str)
return false;
}
+static inline bool
+is_lines_only_debug_section(const char* str)
+{
+ // We can do this faster: binary search or a hashtable. But why bother?
+ for (size_t i = 0;
+ i < sizeof(lines_only_debug_sections)/sizeof(*lines_only_debug_sections);
+ ++i)
+ if (strcmp(str, lines_only_debug_sections[i]) == 0)
+ return true;
+ return false;
+}
+
// Whether to include this section in the link.
template<int size, bool big_endian>
@@ -204,6 +232,14 @@ Layout::include_section(Sized_relobj<size, big_endian>*, const char* name,
if (is_debug_info_section(name))
return false;
}
+ if (parameters->options().strip_debug_non_line()
+ && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0)
+ {
+ // Debugging sections can only be recognized by name.
+ if (is_prefix_of(".debug", name)
+ && !is_lines_only_debug_section(name))
+ return false;
+ }
if (parameters->options().strip_debug_gdb()
&& (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0)
{
@@ -702,7 +738,26 @@ Layout::make_output_section(const char* name, elfcpp::Elf_Word type,
&& strcmp(this->options_.compress_debug_sections(), "none") != 0
&& is_compressible_debug_section(name))
os = new Output_compressed_section(&this->options_, name, type, flags);
- else
+
+ else if ((flags & elfcpp::SHF_ALLOC) == 0
+ && this->options_.strip_debug_non_line()
+ && strcmp(".debug_abbrev", name) == 0)
+ {
+ os = this->debug_abbrev_ = new Output_reduced_debug_abbrev_section(
+ name, type, flags);
+ if (this->debug_info_)
+ this->debug_info_->set_abbreviations(this->debug_abbrev_);
+ }
+ else if ((flags & elfcpp::SHF_ALLOC) == 0
+ && this->options_.strip_debug_non_line()
+ && strcmp(".debug_info", name) == 0)
+ {
+ os = this->debug_info_ = new Output_reduced_debug_info_section(
+ name, type, flags);
+ if (this->debug_abbrev_)
+ this->debug_info_->set_abbreviations(this->debug_abbrev_);
+ }
+ else
os = new Output_section(name, type, flags);
this->section_list_.push_back(os);