aboutsummaryrefslogtreecommitdiff
path: root/gold
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-11-15 23:03:45 +0000
committerIan Lance Taylor <iant@google.com>2007-11-15 23:03:45 +0000
commit02d2ba740273e3f539501337eebf0c6007af0b4b (patch)
treed5f227a534ef7accd13c1aff4327c00935b7bbef /gold
parent557586a2002c600f50084e3ea9931393b44dbe46 (diff)
downloadgdb-02d2ba740273e3f539501337eebf0c6007af0b4b.zip
gdb-02d2ba740273e3f539501337eebf0c6007af0b4b.tar.gz
gdb-02d2ba740273e3f539501337eebf0c6007af0b4b.tar.bz2
From Craig Silverstein: Add --strip-debug-gdb.
Diffstat (limited to 'gold')
-rw-r--r--gold/layout.cc35
-rw-r--r--gold/options.cc5
-rw-r--r--gold/options.h14
-rw-r--r--gold/parameters.cc2
-rw-r--r--gold/parameters.h12
5 files changed, 66 insertions, 2 deletions
diff --git a/gold/layout.cc b/gold/layout.cc
index e4eda44..d3c5d69 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -98,6 +98,33 @@ is_prefix_of(const char* prefix, const char* str)
return strncmp(prefix, str, strlen(prefix)) == 0;
}
+// Returns whether the given section is in the list of
+// debug-sections-used-by-some-version-of-gdb. Currently,
+// we've checked versions of gdb up to and including 6.7.1.
+
+static const char* gdb_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)
+{
+ // We can do this faster: binary search or a hashtable. But why bother?
+ for (size_t i = 0; i < sizeof(gdb_sections)/sizeof(*gdb_sections); ++i)
+ if (strcmp(str, gdb_sections[i]) == 0)
+ return true;
+ return false;
+}
+
// Whether to include this section in the link.
template<int size, bool big_endian>
@@ -134,6 +161,14 @@ Layout::include_section(Sized_relobj<size, big_endian>*, const char* name,
|| is_prefix_of(".stab", name))
return false;
}
+ if (parameters->strip_debug_gdb()
+ && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0)
+ {
+ // Debugging sections can only be recognized by name.
+ if (is_prefix_of(".debug", name)
+ && !is_gdb_debug_section(name))
+ return false;
+ }
return true;
default:
diff --git a/gold/options.cc b/gold/options.cc
index 2071435..c962188 100644
--- a/gold/options.cc
+++ b/gold/options.cc
@@ -402,6 +402,11 @@ options::Command_line_options::options[] =
&General_options::add_to_rpath_link),
GENERAL_NOARG('s', "strip-all", N_("Strip all symbols"), NULL,
TWO_DASHES, &General_options::set_strip_all),
+ GENERAL_NOARG('\0', "strip-debug-gdb",
+ N_("Strip debug symbols that are unused by gdb "
+ "(at least versions <= 6.7)"),
+ NULL, TWO_DASHES, &General_options::set_strip_debug_gdb),
+ // This must come after -Sdebug since it's a prefix of it.
GENERAL_NOARG('S', "strip-debug", N_("Strip debugging information"), NULL,
TWO_DASHES, &General_options::set_strip_debug),
GENERAL_NOARG('\0', "shared", N_("Generate shared library"),
diff --git a/gold/options.h b/gold/options.h
index 1a67a7e..48047c2 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -148,6 +148,12 @@ class General_options
strip_debug() const
{ return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG; }
+ // -Sgdb: strip only debugging information that's not used by
+ // gdb (at least, for gdb versions <= 6.7).
+ bool
+ strip_debug_gdb() const
+ { return this->strip_debug() || this->strip_ == STRIP_DEBUG_UNUSED_BY_GDB; }
+
// --allow-shlib-undefined: do not warn about unresolved symbols in
// --shared libraries.
bool
@@ -259,7 +265,9 @@ class General_options
// Strip all symbols.
STRIP_ALL,
// Strip debugging information.
- STRIP_DEBUG
+ STRIP_DEBUG,
+ // Strip debugging information that's not used by gdb (at least <= 6.7)
+ STRIP_DEBUG_UNUSED_BY_GDB
};
// Whether to mark the stack as executable.
@@ -312,6 +320,10 @@ class General_options
{ this->strip_ = STRIP_DEBUG; }
void
+ set_strip_debug_gdb()
+ { this->strip_ = STRIP_DEBUG_UNUSED_BY_GDB; }
+
+ void
set_allow_shlib_undefined()
{ this->allow_shlib_undefined_ = true; }
diff --git a/gold/parameters.cc b/gold/parameters.cc
index aceb61e..7fbbf83 100644
--- a/gold/parameters.cc
+++ b/gold/parameters.cc
@@ -66,6 +66,8 @@ Parameters::set_from_options(const General_options* options)
this->strip_ = STRIP_ALL;
else if (options->strip_debug())
this->strip_ = STRIP_DEBUG;
+ else if (options->strip_debug_gdb())
+ this->strip_ = STRIP_DEBUG_UNUSED_BY_GDB;
else
this->strip_ = STRIP_NONE;
diff --git a/gold/parameters.h b/gold/parameters.h
index b760ece..3186b6d 100644
--- a/gold/parameters.h
+++ b/gold/parameters.h
@@ -112,6 +112,14 @@ class Parameters
return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG;
}
+ // Whether to strip debugging information that's not used by gdb.
+ bool
+ strip_debug_gdb() const
+ {
+ gold_assert(this->strip_ != STRIP_INVALID);
+ return this->strip_debug() || this->strip_ == STRIP_DEBUG_UNUSED_BY_GDB;
+ }
+
// Whether to permit unresolved references from shared libraries.
bool
allow_shlib_undefined() const
@@ -221,7 +229,9 @@ class Parameters
// Strip all symbols.
STRIP_ALL,
// Strip debugging information.
- STRIP_DEBUG
+ STRIP_DEBUG,
+ // Strip debugging information that's not used by gdb (at least <= 6.7)
+ STRIP_DEBUG_UNUSED_BY_GDB
};
// A pointer to the error handling object.