OLD | NEW |
1 // symtab.cc -- the gold symbol table | 1 // symtab.cc -- the gold symbol table |
2 | 2 |
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. | 3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 } | 520 } |
521 } | 521 } |
522 | 522 |
523 // Class Symbol_table. | 523 // Class Symbol_table. |
524 | 524 |
525 Symbol_table::Symbol_table(unsigned int count, | 525 Symbol_table::Symbol_table(unsigned int count, |
526 const Version_script_info& version_script) | 526 const Version_script_info& version_script) |
527 : saw_undefined_(0), offset_(0), table_(count), namepool_(), | 527 : saw_undefined_(0), offset_(0), table_(count), namepool_(), |
528 forwarders_(), commons_(), tls_commons_(), small_commons_(), | 528 forwarders_(), commons_(), tls_commons_(), small_commons_(), |
529 large_commons_(), forced_locals_(), warnings_(), | 529 large_commons_(), forced_locals_(), warnings_(), |
530 version_script_(version_script), gc_(NULL), icf_(NULL) | 530 version_script_(version_script), gc_(NULL), icf_(NULL), |
| 531 global_got_index_((unsigned int)-1) |
531 { | 532 { |
532 namepool_.reserve(count); | 533 namepool_.reserve(count); |
533 } | 534 } |
534 | 535 |
535 Symbol_table::~Symbol_table() | 536 Symbol_table::~Symbol_table() |
536 { | 537 { |
537 } | 538 } |
538 | 539 |
539 // The symbol table key equality function. This is called with | 540 // The symbol table key equality function. This is called with |
540 // Stringpool keys. | 541 // Stringpool keys. |
(...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2346 #endif | 2347 #endif |
2347 } | 2348 } |
2348 | 2349 |
2349 gold_assert(oldsym == NULL); | 2350 gold_assert(oldsym == NULL); |
2350 | 2351 |
2351 sym->init_undefined(name, version, elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL, | 2352 sym->init_undefined(name, version, elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL, |
2352 elfcpp::STV_DEFAULT, 0); | 2353 elfcpp::STV_DEFAULT, 0); |
2353 ++this->saw_undefined_; | 2354 ++this->saw_undefined_; |
2354 } | 2355 } |
2355 | 2356 |
| 2357 bool got_offset_compare(Symbol* sym1, Symbol* sym2) |
| 2358 { |
| 2359 return sym1->got_offset(0) < sym2->got_offset(0); |
| 2360 } |
| 2361 |
| 2362 // Returns true if symbol is external global symbol. |
| 2363 |
| 2364 bool is_external_symbol(Symbol* sym) |
| 2365 { |
| 2366 return ((!sym->has_dynsym_index() && sym->has_got_offset(0)) |
| 2367 && (!sym->final_value_is_known() |
| 2368 || (parameters->options().output_is_position_independent()))); |
| 2369 } |
| 2370 |
2356 // Set the dynamic symbol indexes. INDEX is the index of the first | 2371 // Set the dynamic symbol indexes. INDEX is the index of the first |
2357 // global dynamic symbol. Pointers to the symbols are stored into the | 2372 // global dynamic symbol. Pointers to the symbols are stored into the |
2358 // vector SYMS. The names are added to DYNPOOL. This returns an | 2373 // vector SYMS. The names are added to DYNPOOL. This returns an |
2359 // updated dynamic symbol index. | 2374 // updated dynamic symbol index. |
2360 | 2375 |
| 2376 // [MIPS] The dynamic symbol table is divided into local and global parts. |
| 2377 // The global part of the dynamic symbol table is further divided into two |
| 2378 // parts: symbols that do not have GOT entries associated with them and |
| 2379 // symbols that do have GOT entries associated with them. |
2361 unsigned int | 2380 unsigned int |
2362 Symbol_table::set_dynsym_indexes(unsigned int index, | 2381 Symbol_table::set_dynsym_indexes(unsigned int index, |
2363 std::vector<Symbol*>* syms, | 2382 std::vector<Symbol*>* syms, |
2364 Stringpool* dynpool, | 2383 Stringpool* dynpool, |
2365 Versions* versions) | 2384 Versions* versions) |
2366 { | 2385 { |
| 2386 std::vector<Symbol*> externals; |
| 2387 int i; |
| 2388 |
2367 for (Symbol_table_type::iterator p = this->table_.begin(); | 2389 for (Symbol_table_type::iterator p = this->table_.begin(); |
2368 p != this->table_.end(); | 2390 p != this->table_.end(); |
2369 ++p) | 2391 ++p) |
2370 { | 2392 { |
2371 Symbol* sym = p->second; | 2393 Symbol* sym = p->second; |
2372 | 2394 |
2373 // Note that SYM may already have a dynamic symbol index, since | 2395 // Note that SYM may already have a dynamic symbol index, since |
2374 // some symbols appear more than once in the symbol table, with | 2396 // some symbols appear more than once in the symbol table, with |
2375 // and without a version. | 2397 // and without a version. |
2376 | 2398 |
2377 if (!sym->should_add_dynsym_entry(this)) | 2399 if (!sym->should_add_dynsym_entry(this)) |
2378 sym->set_dynsym_index(-1U); | 2400 sym->set_dynsym_index(-1U); |
| 2401 else if (is_external_symbol(sym)) |
| 2402 { |
| 2403 externals.push_back(sym); |
| 2404 } |
2379 else if (!sym->has_dynsym_index()) | 2405 else if (!sym->has_dynsym_index()) |
2380 { | 2406 { |
2381 sym->set_dynsym_index(index); | 2407 sym->set_dynsym_index(index); |
2382 ++index; | 2408 ++index; |
2383 syms->push_back(sym); | 2409 syms->push_back(sym); |
2384 dynpool->add(sym->name(), false, NULL); | 2410 dynpool->add(sym->name(), false, NULL); |
2385 | 2411 |
2386 // Record any version information. | 2412 // Record any version information. |
2387 if (sym->version() != NULL) | 2413 if (sym->version() != NULL) |
2388 versions->record_version(this, dynpool, sym); | 2414 versions->record_version(this, dynpool, sym); |
2389 | 2415 |
2390 // If the symbol is defined in a dynamic object and is | 2416 // If the symbol is defined in a dynamic object and is |
2391 // referenced in a regular object, then mark the dynamic | 2417 // referenced in a regular object, then mark the dynamic |
2392 // object as needed. This is used to implement --as-needed. | 2418 // object as needed. This is used to implement --as-needed. |
2393 if (sym->is_from_dynobj() && sym->in_reg()) | 2419 if (sym->is_from_dynobj() && sym->in_reg()) |
2394 sym->object()->set_is_needed(); | 2420 sym->object()->set_is_needed(); |
2395 } | 2421 } |
2396 } | 2422 } |
2397 | 2423 |
2398 // Finish up the versions. In some cases this may add new dynamic | 2424 // At the end of dynamic symbol table place global symbols that has |
2399 // symbols. | 2425 // .got entry. |
| 2426 std::sort(externals.begin(), externals.end(), got_offset_compare); |
| 2427 for (i = 0; (unsigned int)i < externals.size(); i++) |
| 2428 { |
| 2429 Symbol* sym = externals[i]; |
| 2430 |
| 2431 if (sym->has_dynsym_index()) |
| 2432 continue; |
| 2433 |
| 2434 // Record any version information. |
| 2435 if (sym->version() != NULL) |
| 2436 versions->record_version(this, dynpool, sym); |
| 2437 } |
| 2438 |
2400 index = versions->finalize(this, index, syms); | 2439 index = versions->finalize(this, index, syms); |
2401 | 2440 |
| 2441 // Set index of the first external symbol that has .got entry. |
| 2442 this->global_got_index_ = index; |
| 2443 |
| 2444 for (i = 0; (unsigned int)i < externals.size(); i++) |
| 2445 { |
| 2446 Symbol* sym = externals[i]; |
| 2447 |
| 2448 if (sym->has_dynsym_index()) |
| 2449 continue; |
| 2450 |
| 2451 sym->set_dynsym_index(index); |
| 2452 ++index; |
| 2453 syms->push_back(sym); |
| 2454 dynpool->add(sym->name(), false, NULL); |
| 2455 |
| 2456 // If the symbol is defined in a dynamic object and is |
| 2457 // referenced in a regular object, then mark the dynamic |
| 2458 // object as needed. This is used to implement --as-needed. |
| 2459 if (sym->is_from_dynobj() && sym->in_reg()) |
| 2460 sym->object()->set_is_needed(); |
| 2461 } |
| 2462 |
| 2463 // If there are no global symbols with .got entry set value to -1. |
| 2464 if (this->global_got_index_ == index) |
| 2465 this->global_got_index_ = (unsigned int)-1; |
| 2466 |
2402 return index; | 2467 return index; |
2403 } | 2468 } |
2404 | 2469 |
2405 // Set the final values for all the symbols. The index of the first | 2470 // Set the final values for all the symbols. The index of the first |
2406 // global symbol in the output file is *PLOCAL_SYMCOUNT. Record the | 2471 // global symbol in the output file is *PLOCAL_SYMCOUNT. Record the |
2407 // file offset OFF. Add their names to POOL. Return the new file | 2472 // file offset OFF. Add their names to POOL. Return the new file |
2408 // offset. Update *PLOCAL_SYMCOUNT if necessary. | 2473 // offset. Update *PLOCAL_SYMCOUNT if necessary. |
2409 | 2474 |
2410 off_t | 2475 off_t |
2411 Symbol_table::finalize(off_t off, off_t dynoff, size_t dyn_global_index, | 2476 Symbol_table::finalize(off_t off, off_t dynoff, size_t dyn_global_index, |
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3573 | 3638 |
3574 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG) | 3639 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG) |
3575 template | 3640 template |
3576 void | 3641 void |
3577 Symbol_table::define_with_copy_reloc<64>( | 3642 Symbol_table::define_with_copy_reloc<64>( |
3578 Sized_symbol<64>* sym, | 3643 Sized_symbol<64>* sym, |
3579 Output_data* posd, | 3644 Output_data* posd, |
3580 elfcpp::Elf_types<64>::Elf_Addr value); | 3645 elfcpp::Elf_types<64>::Elf_Addr value); |
3581 #endif | 3646 #endif |
3582 | 3647 |
| 3648 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG) |
| 3649 template |
| 3650 void |
| 3651 Sized_symbol<32>::init_output_data( |
| 3652 const char* name, |
| 3653 const char* version, |
| 3654 Output_data* od, |
| 3655 Value_type value, |
| 3656 Size_type symsize, |
| 3657 elfcpp::STT type, |
| 3658 elfcpp::STB binding, |
| 3659 elfcpp::STV visibility, |
| 3660 unsigned char nonvis, |
| 3661 bool offset_is_from_end, |
| 3662 bool is_predefined); |
| 3663 #endif |
| 3664 |
| 3665 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG) |
| 3666 template |
| 3667 void |
| 3668 Sized_symbol<64>::init_output_data( |
| 3669 const char* name, |
| 3670 const char* version, |
| 3671 Output_data* od, |
| 3672 Value_type value, |
| 3673 Size_type symsize, |
| 3674 elfcpp::STT type, |
| 3675 elfcpp::STB binding, |
| 3676 elfcpp::STV visibility, |
| 3677 unsigned char nonvis, |
| 3678 bool offset_is_from_end, |
| 3679 bool is_predefined); |
| 3680 #endif |
| 3681 |
3583 #ifdef HAVE_TARGET_32_LITTLE | 3682 #ifdef HAVE_TARGET_32_LITTLE |
3584 template | 3683 template |
3585 void | 3684 void |
3586 Warnings::issue_warning<32, false>(const Symbol* sym, | 3685 Warnings::issue_warning<32, false>(const Symbol* sym, |
3587 const Relocate_info<32, false>* relinfo, | 3686 const Relocate_info<32, false>* relinfo, |
3588 size_t relnum, off_t reloffset) const; | 3687 size_t relnum, off_t reloffset) const; |
3589 #endif | 3688 #endif |
3590 | 3689 |
3591 #ifdef HAVE_TARGET_32_BIG | 3690 #ifdef HAVE_TARGET_32_BIG |
3592 template | 3691 template |
(...skipping 13 matching lines...) Expand all Loading... |
3606 | 3705 |
3607 #ifdef HAVE_TARGET_64_BIG | 3706 #ifdef HAVE_TARGET_64_BIG |
3608 template | 3707 template |
3609 void | 3708 void |
3610 Warnings::issue_warning<64, true>(const Symbol* sym, | 3709 Warnings::issue_warning<64, true>(const Symbol* sym, |
3611 const Relocate_info<64, true>* relinfo, | 3710 const Relocate_info<64, true>* relinfo, |
3612 size_t relnum, off_t reloffset) const; | 3711 size_t relnum, off_t reloffset) const; |
3613 #endif | 3712 #endif |
3614 | 3713 |
3615 } // End namespace gold. | 3714 } // End namespace gold. |
OLD | NEW |