diff options
author | Doug Kwan <dougkwan@google.com> | 2009-10-16 19:11:32 +0000 |
---|---|---|
committer | Doug Kwan <dougkwan@google.com> | 2009-10-16 19:11:32 +0000 |
commit | c5617f2fb6d7c6a1898d920ac662209a195b3c9e (patch) | |
tree | 3cc0e6f7022a7431503777045283809c0aa3f762 /gold/dynobj.cc | |
parent | 0a8d1bde177b4f1ef4df5ba6a7b79a9df3d1497f (diff) | |
download | gdb-c5617f2fb6d7c6a1898d920ac662209a195b3c9e.zip gdb-c5617f2fb6d7c6a1898d920ac662209a195b3c9e.tar.gz gdb-c5617f2fb6d7c6a1898d920ac662209a195b3c9e.tar.bz2 |
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.
* testsuite/Makefile.am (check_SCRIPTS): Add no_version_test.sh
(check_DATA): Add no_version_test.stdout.
(libno_version_test.so, no_version_test.o no_version_test.stdout):
New make rules.
* testsuite/Makefile.in: Regenerate.
* testsuite/no_version_test.c: New file.
* testsuite/no_version_test.sh: Ditto.
Diffstat (limited to 'gold/dynobj.cc')
-rw-r--r-- | gold/dynobj.cc | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/gold/dynobj.cc b/gold/dynobj.cc index b14d06d..dec6f3d 100644 --- a/gold/dynobj.cc +++ b/gold/dynobj.cc @@ -1300,27 +1300,18 @@ Verneed::write(const Stringpool* dynpool, bool is_last, 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, const char* version, 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, const char* filename, const char* name, 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); |