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>
|| 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:
&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"),
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
// 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.
{ 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; }
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;
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
// 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.