OLD | NEW |
1 // dynobj.cc -- dynamic object support for gold | 1 // dynobj.cc -- dynamic object support for gold |
2 | 2 |
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc. | 3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc. |
4 // Written by Ian Lance Taylor <iant@google.com>. | 4 // Written by Ian Lance Taylor <iant@google.com>. |
5 | 5 |
6 // This file is part of gold. | 6 // This file is part of gold. |
7 | 7 |
8 // This program is free software; you can redistribute it and/or modify | 8 // This program is free software; you can redistribute it and/or modify |
9 // it under the terms of the GNU General Public License as published by | 9 // it under the terms of the GNU General Public License as published by |
10 // the Free Software Foundation; either version 3 of the License, or | 10 // the Free Software Foundation; either version 3 of the License, or |
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 } | 1293 } |
1294 | 1294 |
1295 return pb; | 1295 return pb; |
1296 } | 1296 } |
1297 | 1297 |
1298 // Versions methods. | 1298 // Versions methods. |
1299 | 1299 |
1300 Versions::Versions(const Version_script_info& version_script, | 1300 Versions::Versions(const Version_script_info& version_script, |
1301 Stringpool* dynpool) | 1301 Stringpool* dynpool) |
1302 : defs_(), needs_(), version_table_(), | 1302 : defs_(), needs_(), version_table_(), |
1303 is_finalized_(false), version_script_(version_script) | 1303 is_finalized_(false), version_script_(version_script), |
| 1304 needs_base_version_(parameters->options().shared()) |
1304 { | 1305 { |
1305 // We always need a base version, so define that first. Nothing | |
1306 // explicitly declares itself as part of base, so it doesn't need to | |
1307 // be in version_table_. | |
1308 if (parameters->options().shared()) | |
1309 { | |
1310 const char* name = parameters->options().soname(); | |
1311 if (name == NULL) | |
1312 name = parameters->options().output_file_name(); | |
1313 name = dynpool->add(name, false, NULL); | |
1314 Verdef* vdbase = new Verdef(name, std::vector<std::string>(), | |
1315 true, false, true); | |
1316 this->defs_.push_back(vdbase); | |
1317 } | |
1318 | |
1319 if (!this->version_script_.empty()) | 1306 if (!this->version_script_.empty()) |
1320 { | 1307 { |
1321 // Parse the version script, and insert each declared version into | 1308 // Parse the version script, and insert each declared version into |
1322 // defs_ and version_table_. | 1309 // defs_ and version_table_. |
1323 std::vector<std::string> versions = this->version_script_.get_versions(); | 1310 std::vector<std::string> versions = this->version_script_.get_versions(); |
| 1311 |
| 1312 if (this->needs_base_version_ && !versions.empty()) |
| 1313 this->define_base_version(dynpool); |
| 1314 |
1324 for (size_t k = 0; k < versions.size(); ++k) | 1315 for (size_t k = 0; k < versions.size(); ++k) |
1325 { | 1316 { |
1326 Stringpool::Key version_key; | 1317 Stringpool::Key version_key; |
1327 const char* version = dynpool->add(versions[k].c_str(), | 1318 const char* version = dynpool->add(versions[k].c_str(), |
1328 true, &version_key); | 1319 true, &version_key); |
1329 Verdef* const vd = new Verdef( | 1320 Verdef* const vd = new Verdef( |
1330 version, | 1321 version, |
1331 this->version_script_.get_dependencies(version), | 1322 this->version_script_.get_dependencies(version), |
1332 false, false, false); | 1323 false, false, false); |
1333 this->defs_.push_back(vd); | 1324 this->defs_.push_back(vd); |
1334 Key key(version_key, 0); | 1325 Key key(version_key, 0); |
1335 this->version_table_.insert(std::make_pair(key, vd)); | 1326 this->version_table_.insert(std::make_pair(key, vd)); |
1336 } | 1327 } |
1337 } | 1328 } |
1338 } | 1329 } |
1339 | 1330 |
1340 Versions::~Versions() | 1331 Versions::~Versions() |
1341 { | 1332 { |
1342 for (Defs::iterator p = this->defs_.begin(); | 1333 for (Defs::iterator p = this->defs_.begin(); |
1343 p != this->defs_.end(); | 1334 p != this->defs_.end(); |
1344 ++p) | 1335 ++p) |
1345 delete *p; | 1336 delete *p; |
1346 | 1337 |
1347 for (Needs::iterator p = this->needs_.begin(); | 1338 for (Needs::iterator p = this->needs_.begin(); |
1348 p != this->needs_.end(); | 1339 p != this->needs_.end(); |
1349 ++p) | 1340 ++p) |
1350 delete *p; | 1341 delete *p; |
1351 } | 1342 } |
1352 | 1343 |
| 1344 // Define the base version of a shared library. The base version definition |
| 1345 // must be the first entry in defs_. We insert it lazily so that defs_ is |
| 1346 // empty if no symbol versioning is used. Then layout can just drop the |
| 1347 // version sections. |
| 1348 |
| 1349 void |
| 1350 Versions::define_base_version(Stringpool* dynpool) |
| 1351 { |
| 1352 // If we do any versioning at all, we always need a base version, so |
| 1353 // define that first. Nothing explicitly declares itself as part of base, |
| 1354 // so it doesn't need to be in version_table_. |
| 1355 gold_assert(this->defs_.empty()); |
| 1356 const char* name = parameters->options().soname(); |
| 1357 if (name == NULL) |
| 1358 name = parameters->options().output_file_name(); |
| 1359 name = dynpool->add(name, false, NULL); |
| 1360 Verdef* vdbase = new Verdef(name, std::vector<std::string>(), |
| 1361 true, false, true); |
| 1362 this->defs_.push_back(vdbase); |
| 1363 this->needs_base_version_ = false; |
| 1364 } |
| 1365 |
1353 // Return the dynamic object which a symbol refers to. | 1366 // Return the dynamic object which a symbol refers to. |
1354 | 1367 |
1355 Dynobj* | 1368 Dynobj* |
1356 Versions::get_dynobj_for_sym(const Symbol_table* symtab, | 1369 Versions::get_dynobj_for_sym(const Symbol_table* symtab, |
1357 const Symbol* sym) const | 1370 const Symbol* sym) const |
1358 { | 1371 { |
1359 if (sym->is_copied_from_dynobj()) | 1372 if (sym->is_copied_from_dynobj()) |
1360 return symtab->get_copy_source(sym); | 1373 return symtab->get_copy_source(sym); |
1361 else | 1374 else |
1362 { | 1375 { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 vb->clear_weak(); | 1427 vb->clear_weak(); |
1415 } | 1428 } |
1416 else | 1429 else |
1417 { | 1430 { |
1418 // If we are creating a shared object, it is an error to | 1431 // If we are creating a shared object, it is an error to |
1419 // find a definition of a symbol with a version which is not | 1432 // find a definition of a symbol with a version which is not |
1420 // in the version script. | 1433 // in the version script. |
1421 if (parameters->options().shared()) | 1434 if (parameters->options().shared()) |
1422 gold_error(_("symbol %s has undefined version %s"), | 1435 gold_error(_("symbol %s has undefined version %s"), |
1423 sym->demangled_name().c_str(), version); | 1436 sym->demangled_name().c_str(), version); |
1424 | 1437 else |
| 1438 » // We only insert a base version for shared library. |
| 1439 » gold_assert(!this->needs_base_version_); |
| 1440 » |
1425 // When creating a regular executable, automatically define | 1441 // When creating a regular executable, automatically define |
1426 // a new version. | 1442 // a new version. |
1427 Verdef* vd = new Verdef(version, std::vector<std::string>(), | 1443 Verdef* vd = new Verdef(version, std::vector<std::string>(), |
1428 false, false, false); | 1444 false, false, false); |
1429 this->defs_.push_back(vd); | 1445 this->defs_.push_back(vd); |
1430 ins.first->second = vd; | 1446 ins.first->second = vd; |
1431 } | 1447 } |
1432 } | 1448 } |
1433 | 1449 |
1434 // Add a reference to version NAME in file FILENAME. | 1450 // Add a reference to version NAME in file FILENAME. |
(...skipping 26 matching lines...) Expand all Loading... |
1461 { | 1477 { |
1462 if ((*p)->filename() == filename) | 1478 if ((*p)->filename() == filename) |
1463 { | 1479 { |
1464 vn = *p; | 1480 vn = *p; |
1465 break; | 1481 break; |
1466 } | 1482 } |
1467 } | 1483 } |
1468 | 1484 |
1469 if (vn == NULL) | 1485 if (vn == NULL) |
1470 { | 1486 { |
| 1487 // Create base version definition lazily for shared library. |
| 1488 if (this->needs_base_version_) |
| 1489 this->define_base_version(dynpool); |
| 1490 |
1471 // We have a new filename. | 1491 // We have a new filename. |
1472 vn = new Verneed(filename); | 1492 vn = new Verneed(filename); |
1473 this->needs_.push_back(vn); | 1493 this->needs_.push_back(vn); |
1474 } | 1494 } |
1475 | 1495 |
1476 ins.first->second = vn->add_name(name); | 1496 ins.first->second = vn->add_name(name); |
1477 } | 1497 } |
1478 | 1498 |
1479 // Set the version indexes. Create a new dynamic version symbol for | 1499 // Set the version indexes. Create a new dynamic version symbol for |
1480 // each new version definition. | 1500 // each new version definition. |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1841 template | 1861 template |
1842 void | 1862 void |
1843 Versions::need_section_contents<64, true>( | 1863 Versions::need_section_contents<64, true>( |
1844 const Stringpool*, | 1864 const Stringpool*, |
1845 unsigned char**, | 1865 unsigned char**, |
1846 unsigned int*, | 1866 unsigned int*, |
1847 unsigned int*) const; | 1867 unsigned int*) const; |
1848 #endif | 1868 #endif |
1849 | 1869 |
1850 } // End namespace gold. | 1870 } // End namespace gold. |
OLD | NEW |