This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
gold 2.20 backport: Don't create unnecessary version symbol
- From: Ian Lance Taylor <iant at google dot com>
- To: binutils at sourceware dot org
- Date: Fri, 06 Nov 2009 18:18:39 -0800
- Subject: gold 2.20 backport: Don't create unnecessary version symbol
I think Doug's patch to make gold not create an unnecessary version
symbol is appropriate for the 2.20.1 release. I backported it as
follows.
Ian
2009-11-06 Ian Lance Taylor <iant@google.com>
Bring over from mainline:
2009-10-16 Doug Kwan <dougkwan@google.com>
* dynobj.cc (Versions::Versions): Initialize version_script_.
Only insert base version symbol definition for a shared object
if version script defines any version versions.
(Versions::define_base_version): New method definition.
(Versions::add_def): Check that base version is not needed.
(Versions::add_need): Define base version lazily.
* dynobj.h (Versions::define_base_version): New method declaration.
(Versions::needs_base_version_): New data member declaration.
Index: dynobj.cc
===================================================================
RCS file: /cvs/src/src/gold/dynobj.cc,v
retrieving revision 1.44.2.1
diff -p -u -r1.44.2.1 dynobj.cc
--- dynobj.cc 16 Oct 2009 05:51:17 -0000 1.44.2.1
+++ dynobj.cc 7 Nov 2009 02:14:50 -0000
@@ -1300,27 +1300,18 @@ Verneed::write(const Stringpool* dynpool
Versions::Versions(const Version_script_info& version_script,
Stringpool* dynpool)
: defs_(), needs_(), version_table_(),
- is_finalized_(false), version_script_(version_script)
+ is_finalized_(false), version_script_(version_script),
+ needs_base_version_(parameters->options().shared())
{
- // We always need a base version, so define that first. Nothing
- // explicitly declares itself as part of base, so it doesn't need to
- // be in version_table_.
- if (parameters->options().shared())
- {
- const char* name = parameters->options().soname();
- if (name == NULL)
- name = parameters->options().output_file_name();
- name = dynpool->add(name, false, NULL);
- Verdef* vdbase = new Verdef(name, std::vector<std::string>(),
- true, false, true);
- this->defs_.push_back(vdbase);
- }
-
if (!this->version_script_.empty())
{
// Parse the version script, and insert each declared version into
// defs_ and version_table_.
std::vector<std::string> versions = this->version_script_.get_versions();
+
+ if (this->needs_base_version_ && !versions.empty())
+ this->define_base_version(dynpool);
+
for (size_t k = 0; k < versions.size(); ++k)
{
Stringpool::Key version_key;
@@ -1350,6 +1341,28 @@ Versions::~Versions()
delete *p;
}
+// Define the base version of a shared library. The base version definition
+// must be the first entry in defs_. We insert it lazily so that defs_ is
+// empty if no symbol versioning is used. Then layout can just drop the
+// version sections.
+
+void
+Versions::define_base_version(Stringpool* dynpool)
+{
+ // If we do any versioning at all, we always need a base version, so
+ // define that first. Nothing explicitly declares itself as part of base,
+ // so it doesn't need to be in version_table_.
+ gold_assert(this->defs_.empty());
+ const char* name = parameters->options().soname();
+ if (name == NULL)
+ name = parameters->options().output_file_name();
+ name = dynpool->add(name, false, NULL);
+ Verdef* vdbase = new Verdef(name, std::vector<std::string>(),
+ true, false, true);
+ this->defs_.push_back(vdbase);
+ this->needs_base_version_ = false;
+}
+
// Return the dynamic object which a symbol refers to.
Dynobj*
@@ -1421,7 +1434,10 @@ Versions::add_def(const Symbol* sym, con
if (parameters->options().shared())
gold_error(_("symbol %s has undefined version %s"),
sym->demangled_name().c_str(), version);
-
+ else
+ // We only insert a base version for shared library.
+ gold_assert(!this->needs_base_version_);
+
// When creating a regular executable, automatically define
// a new version.
Verdef* vd = new Verdef(version, std::vector<std::string>(),
@@ -1468,6 +1484,10 @@ Versions::add_need(Stringpool* dynpool,
if (vn == NULL)
{
+ // Create base version definition lazily for shared library.
+ if (this->needs_base_version_)
+ this->define_base_version(dynpool);
+
// We have a new filename.
vn = new Verneed(filename);
this->needs_.push_back(vn);
Index: dynobj.h
===================================================================
RCS file: /cvs/src/src/gold/dynobj.h,v
retrieving revision 1.32.2.1
diff -p -u -r1.32.2.1 dynobj.h
--- dynobj.h 16 Oct 2009 05:51:17 -0000 1.32.2.1
+++ dynobj.h 7 Nov 2009 02:14:51 -0000
@@ -584,6 +584,10 @@ class Versions
version_index(const Symbol_table*, const Stringpool*,
const Symbol* sym) const;
+ // Define the base version of a shared library.
+ void
+ define_base_version(Stringpool* dynpool);
+
// We keep a hash table mapping canonicalized name/version pairs to
// a version base.
typedef std::pair<Stringpool::Key, Stringpool::Key> Key;
@@ -616,6 +620,9 @@ class Versions
bool is_finalized_;
// Contents of --version-script, if passed, or NULL.
const Version_script_info& version_script_;
+ // Whether we need to insert a base version. This is only used for
+ // shared libaries and is cleared when the base version is defined.
+ bool needs_base_version_;
};
} // End namespace gold.