Changeset 609 for branches/GNU/src/binutils/bfd/elf32-hppa.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elf32-hppa.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* BFD back-end for HP PA-RISC ELF files. 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001 3 Free Software Foundation, Inc.2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001, 3 2002, 2003 Free Software Foundation, Inc. 4 4 5 5 Original code by … … 9 9 Largely rewritten by Alan Modra <alan@linuxcare.com.au> 10 10 11 This file is part of BFD, the Binary File Descriptor library.12 13 This program is free software; you can redistribute it and/or modify14 it under the terms of the GNU General Public License as published by15 the Free Software Foundation; either version 2 of the License, or16 (at your option) any later version.17 18 This program is distributed in the hope that it will be useful,19 but WITHOUT ANY WARRANTY; without even the implied warranty of20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the21 GNU General Public License for more details.22 23 You should have received a copy of the GNU General Public License24 along with this program; if not, write to the Free Software25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */11 This file is part of BFD, the Binary File Descriptor library. 12 13 This program is free software; you can redistribute it and/or modify 14 it under the terms of the GNU General Public License as published by 15 the Free Software Foundation; either version 2 of the License, or 16 (at your option) any later version. 17 18 This program is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program; if not, write to the Free Software 25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 26 26 27 27 #include "bfd.h" … … 33 33 #include "elf32-hppa.h" 34 34 #define ARCH_SIZE 32 35 #include "elf32-hppa.h" 35 36 #include "elf-hppa.h" 36 #include "elf32-hppa.h"37 37 38 38 /* In order to gain some understanding of code in this file without … … 72 72 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point 73 73 : ldw RR'lt_ptr+ltoff(%r1),%r21 74 : 74 : bv %r0(%r21) 75 75 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value. 76 76 … … 79 79 : addil LR'ltoff,%r19 ; get procedure entry point 80 80 : ldw RR'ltoff(%r1),%r21 81 : 81 : bv %r0(%r21) 82 82 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value. 83 83 … … 112 112 : ldsid (%rp),%r1 113 113 : mtsp %r1,%sr0 114 : be,n 0(%sr0,%rp) ; inter-space return */114 : be,n 0(%sr0,%rp) ; inter-space return. */ 115 115 116 116 #define PLT_ENTRY_SIZE 8 117 #define PLABEL_PLT_ENTRY_SIZE PLT_ENTRY_SIZE118 117 #define GOT_ENTRY_SIZE 4 119 118 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" … … 135 134 #define STUB_SUFFIX ".stub" 136 135 137 /* Setting the following non-zero makes all long branch stubs 138 generated during a shared link of the PIC variety. This saves on 139 relocs, but costs one extra instruction per stub. */ 140 #ifndef LONG_BRANCH_PIC_IN_SHLIB 141 #define LONG_BRANCH_PIC_IN_SHLIB 1 142 #endif 143 144 /* Set this non-zero to use import stubs instead of long branch stubs 145 where a .plt entry exists for the symbol. This is a fairly useless 146 option as import stubs are bigger than PIC long branch stubs. */ 147 #ifndef LONG_BRANCH_VIA_PLT 148 #define LONG_BRANCH_VIA_PLT 0 149 #endif 150 151 /* We don't need to copy any PC- or GP-relative dynamic relocs into a 152 shared object's dynamic section. */ 153 #ifndef RELATIVE_DYNAMIC_RELOCS 154 #define RELATIVE_DYNAMIC_RELOCS 0 136 /* We don't need to copy certain PC- or GP-relative dynamic relocs 137 into a shared object's dynamic section. All the relocs of the 138 limited class we are interested in, are absolute. */ 139 #ifndef RELATIVE_DYNRELOCS 140 #define RELATIVE_DYNRELOCS 0 141 #define IS_ABSOLUTE_RELOC(r_type) 1 155 142 #endif 156 143 … … 172 159 asection *stub_sec; 173 160 174 #if ! LONG_BRANCH_PIC_IN_SHLIB175 /* It's associated reloc section. */176 asection *reloc_sec;177 #endif178 179 161 /* Offset within stub_sec of the beginning of this stub. */ 180 162 bfd_vma stub_offset; … … 203 185 struct elf32_hppa_stub_hash_entry *stub_cache; 204 186 205 #if ! LONG_BRANCH_PIC_IN_SHLIB206 /* Used to track whether we have allocated space for a long branch207 stub relocation for this symbol in the given section. */208 asection *stub_reloc_sec;209 #endif210 211 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS212 187 /* Used to count relocations for delayed sizing of relocation 213 188 sections. */ … … 217 192 struct elf32_hppa_dyn_reloc_entry *next; 218 193 219 /* The section in dynobj. */220 asection *sec tion;194 /* The input section of the reloc. */ 195 asection *sec; 221 196 222 197 /* Number of relocs copied in this section. */ 223 198 bfd_size_type count; 224 } *reloc_entries; 199 200 #if RELATIVE_DYNRELOCS 201 /* Number of relative relocs copied for the input section. */ 202 bfd_size_type relative_count; 225 203 #endif 226 227 /* Set during a static link if we detect a function is PIC. */ 228 unsigned int maybe_pic_call:1; 204 } *dyn_relocs; 229 205 230 206 /* Set if the only reason we need a .plt entry is for a non-PIC to … … 234 210 /* Set if this symbol is used by a plabel reloc. */ 235 211 unsigned int plabel:1; 236 237 /* Set if this symbol is an init or fini function and thus should238 use an absolute reloc. */239 unsigned int plt_abs:1;240 212 }; 241 213 … … 243 215 244 216 /* The main hash table. */ 245 struct elf_link_hash_table root;217 struct elf_link_hash_table elf; 246 218 247 219 /* The stub hash table. */ … … 263 235 /* The stub section. */ 264 236 asection *stub_sec; 265 #if ! LONG_BRANCH_PIC_IN_SHLIB266 /* The stub section's reloc section. */267 asection *reloc_sec;268 #endif269 237 } *stub_group; 238 239 /* Assorted information used by elf32_hppa_size_stubs. */ 240 unsigned int bfd_count; 241 int top_index; 242 asection **input_list; 243 Elf_Internal_Sym **all_local_syms; 270 244 271 245 /* Short-cuts to get to dynamic linker sections. */ … … 285 259 unsigned int multi_subspace:1; 286 260 287 /* Flags set when PCREL12F and PCREL17F branchesdetected. Used to261 /* Flags set when various size branches are detected. Used to 288 262 select suitable defaults for the stub group size. */ 289 263 unsigned int has_12bit_branch:1; 290 264 unsigned int has_17bit_branch:1; 265 unsigned int has_22bit_branch:1; 291 266 292 267 /* Set if we need a .plt stub to support lazy dynamic linking. */ 293 268 unsigned int need_plt_stub:1; 269 270 /* Small local sym to section mapping cache. */ 271 struct sym_sec_cache sym_sec; 294 272 }; 295 273 … … 310 288 static struct bfd_link_hash_table *elf32_hppa_link_hash_table_create 311 289 PARAMS ((bfd *)); 290 291 static void elf32_hppa_link_hash_table_free 292 PARAMS ((struct bfd_link_hash_table *)); 312 293 313 294 /* Stub handling functions. */ … … 330 311 struct elf32_hppa_link_hash_entry *, bfd_vma)); 331 312 332 static b oolean hppa_build_one_stub313 static bfd_boolean hppa_build_one_stub 333 314 PARAMS ((struct bfd_hash_entry *, PTR)); 334 315 335 static b oolean hppa_size_one_stub316 static bfd_boolean hppa_size_one_stub 336 317 PARAMS ((struct bfd_hash_entry *, PTR)); 337 318 338 319 /* BFD and elf backend functions. */ 339 static b oolean elf32_hppa_object_p PARAMS ((bfd *));340 341 static b oolean elf32_hppa_add_symbol_hook320 static bfd_boolean elf32_hppa_object_p PARAMS ((bfd *)); 321 322 static bfd_boolean elf32_hppa_add_symbol_hook 342 323 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, 343 324 const char **, flagword *, asection **, bfd_vma *)); 344 325 345 static b oolean elf32_hppa_create_dynamic_sections326 static bfd_boolean elf32_hppa_create_dynamic_sections 346 327 PARAMS ((bfd *, struct bfd_link_info *)); 347 328 348 static boolean elf32_hppa_check_relocs 329 static void elf32_hppa_copy_indirect_symbol 330 PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *, 331 struct elf_link_hash_entry *)); 332 333 static bfd_boolean elf32_hppa_check_relocs 349 334 PARAMS ((bfd *, struct bfd_link_info *, 350 335 asection *, const Elf_Internal_Rela *)); 351 336 352 337 static asection *elf32_hppa_gc_mark_hook 353 PARAMS (( bfd*, struct bfd_link_info *, Elf_Internal_Rela *,338 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, 354 339 struct elf_link_hash_entry *, Elf_Internal_Sym *)); 355 340 356 static b oolean elf32_hppa_gc_sweep_hook341 static bfd_boolean elf32_hppa_gc_sweep_hook 357 342 PARAMS ((bfd *, struct bfd_link_info *, 358 343 asection *, const Elf_Internal_Rela *)); 359 344 360 345 static void elf32_hppa_hide_symbol 346 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean)); 347 348 static bfd_boolean elf32_hppa_adjust_dynamic_symbol 361 349 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); 362 350 363 static boolean elf32_hppa_adjust_dynamic_symbol 364 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); 365 366 static boolean hppa_handle_PIC_calls 351 static bfd_boolean mark_PIC_calls 367 352 PARAMS ((struct elf_link_hash_entry *, PTR)); 368 353 369 static b oolean allocate_plt_and_got354 static bfd_boolean allocate_plt_static 370 355 PARAMS ((struct elf_link_hash_entry *, PTR)); 371 356 372 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \ 373 || RELATIVE_DYNAMIC_RELOCS) 374 static boolean hppa_discard_copies 357 static bfd_boolean allocate_dynrelocs 375 358 PARAMS ((struct elf_link_hash_entry *, PTR)); 376 #endif 377 378 static boolean clobber_millicode_symbols 359 360 static bfd_boolean readonly_dynrelocs 361 PARAMS ((struct elf_link_hash_entry *, PTR)); 362 363 static bfd_boolean clobber_millicode_symbols 379 364 PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *)); 380 365 381 static b oolean elf32_hppa_size_dynamic_sections366 static bfd_boolean elf32_hppa_size_dynamic_sections 382 367 PARAMS ((bfd *, struct bfd_link_info *)); 383 368 384 static boolean elf32_hppa_final_link 369 static void group_sections 370 PARAMS ((struct elf32_hppa_link_hash_table *, bfd_size_type, bfd_boolean)); 371 372 static int get_local_syms 373 PARAMS ((bfd *, bfd *, struct bfd_link_info *)); 374 375 static bfd_boolean elf32_hppa_final_link 385 376 PARAMS ((bfd *, struct bfd_link_info *)); 386 377 … … 393 384 struct elf32_hppa_link_hash_entry *)); 394 385 395 static b oolean elf32_hppa_relocate_section386 static bfd_boolean elf32_hppa_relocate_section 396 387 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, 397 388 bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); 398 389 399 static int hppa_unwind_entry_compare 400 PARAMS ((const PTR, const PTR)); 401 402 static boolean elf32_hppa_finish_dynamic_symbol 390 static bfd_boolean elf32_hppa_finish_dynamic_symbol 403 391 PARAMS ((bfd *, struct bfd_link_info *, 404 392 struct elf_link_hash_entry *, Elf_Internal_Sym *)); 405 393 406 static boolean elf32_hppa_finish_dynamic_sections 394 static enum elf_reloc_type_class elf32_hppa_reloc_type_class 395 PARAMS ((const Elf_Internal_Rela *)); 396 397 static bfd_boolean elf32_hppa_finish_dynamic_sections 407 398 PARAMS ((bfd *, struct bfd_link_info *)); 408 399 … … 423 414 const char *string; 424 415 { 425 struct elf32_hppa_stub_hash_entry *ret;426 427 ret = (struct elf32_hppa_stub_hash_entry *) entry;428 429 416 /* Allocate the structure if it has not already been allocated by a 430 417 subclass. */ 431 if (ret == NULL) 432 { 433 ret = ((struct elf32_hppa_stub_hash_entry *) 434 bfd_hash_allocate (table, 435 sizeof (struct elf32_hppa_stub_hash_entry))); 436 if (ret == NULL) 437 return NULL; 418 if (entry == NULL) 419 { 420 entry = bfd_hash_allocate (table, 421 sizeof (struct elf32_hppa_stub_hash_entry)); 422 if (entry == NULL) 423 return entry; 438 424 } 439 425 440 426 /* Call the allocation method of the superclass. */ 441 ret = ((struct elf32_hppa_stub_hash_entry *)442 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string)); 443 444 if (ret)445 { 427 entry = bfd_hash_newfunc (entry, table, string); 428 if (entry != NULL) 429 { 430 struct elf32_hppa_stub_hash_entry *eh; 431 446 432 /* Initialize the local fields. */ 447 ret->stub_sec = NULL; 448 #if ! LONG_BRANCH_PIC_IN_SHLIB 449 ret->reloc_sec = NULL; 450 #endif 451 ret->stub_offset = 0; 452 ret->target_value = 0; 453 ret->target_section = NULL; 454 ret->stub_type = hppa_stub_long_branch; 455 ret->h = NULL; 456 ret->id_sec = NULL; 457 } 458 459 return (struct bfd_hash_entry *) ret; 433 eh = (struct elf32_hppa_stub_hash_entry *) entry; 434 eh->stub_sec = NULL; 435 eh->stub_offset = 0; 436 eh->target_value = 0; 437 eh->target_section = NULL; 438 eh->stub_type = hppa_stub_long_branch; 439 eh->h = NULL; 440 eh->id_sec = NULL; 441 } 442 443 return entry; 460 444 } 461 445 … … 468 452 const char *string; 469 453 { 470 struct elf32_hppa_link_hash_entry *ret;471 472 ret = (struct elf32_hppa_link_hash_entry *) entry;473 474 454 /* Allocate the structure if it has not already been allocated by a 475 455 subclass. */ 476 if (ret == NULL) 477 { 478 ret = ((struct elf32_hppa_link_hash_entry *) 479 bfd_hash_allocate (table, 480 sizeof (struct elf32_hppa_link_hash_entry))); 481 if (ret == NULL) 482 return NULL; 456 if (entry == NULL) 457 { 458 entry = bfd_hash_allocate (table, 459 sizeof (struct elf32_hppa_link_hash_entry)); 460 if (entry == NULL) 461 return entry; 483 462 } 484 463 485 464 /* Call the allocation method of the superclass. */ 486 ret = ((struct elf32_hppa_link_hash_entry *) 487 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, 488 table, string)); 489 490 if (ret) 491 { 465 entry = _bfd_elf_link_hash_newfunc (entry, table, string); 466 if (entry != NULL) 467 { 468 struct elf32_hppa_link_hash_entry *eh; 469 492 470 /* Initialize the local fields. */ 493 #if ! LONG_BRANCH_PIC_IN_SHLIB 494 ret->stub_reloc_sec = NULL; 495 #endif 496 ret->stub_cache = NULL; 497 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS 498 ret->reloc_entries = NULL; 499 #endif 500 ret->maybe_pic_call = 0; 501 ret->pic_call = 0; 502 ret->plabel = 0; 503 ret->plt_abs = 0; 504 } 505 506 return (struct bfd_hash_entry *) ret; 471 eh = (struct elf32_hppa_link_hash_entry *) entry; 472 eh->stub_cache = NULL; 473 eh->dyn_relocs = NULL; 474 eh->pic_call = 0; 475 eh->plabel = 0; 476 } 477 478 return entry; 507 479 } 508 480 … … 516 488 { 517 489 struct elf32_hppa_link_hash_table *ret; 518 519 ret = ((struct elf32_hppa_link_hash_table *) bfd_alloc (abfd, sizeof (*ret))); 490 bfd_size_type amt = sizeof (*ret); 491 492 ret = (struct elf32_hppa_link_hash_table *) bfd_malloc (amt); 520 493 if (ret == NULL) 521 494 return NULL; 522 495 523 if (!_bfd_elf_link_hash_table_init (&ret-> root, abfd, hppa_link_hash_newfunc))524 { 525 bfd_release (abfd,ret);496 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, hppa_link_hash_newfunc)) 497 { 498 free (ret); 526 499 return NULL; 527 500 } … … 546 519 ret->has_12bit_branch = 0; 547 520 ret->has_17bit_branch = 0; 521 ret->has_22bit_branch = 0; 548 522 ret->need_plt_stub = 0; 549 550 return &ret->root.root; 523 ret->sym_sec.abfd = NULL; 524 525 return &ret->elf.root; 526 } 527 528 /* Free the derived linker hash table. */ 529 530 static void 531 elf32_hppa_link_hash_table_free (hash) 532 struct bfd_link_hash_table *hash; 533 { 534 struct elf32_hppa_link_hash_table *ret 535 = (struct elf32_hppa_link_hash_table *) hash; 536 537 bfd_hash_table_free (&ret->stub_hash_table); 538 _bfd_generic_link_hash_table_free (hash); 551 539 } 552 540 … … 561 549 { 562 550 char *stub_name; 563 size_tlen;551 bfd_size_type len; 564 552 565 553 if (hash) … … 595 583 596 584 static struct elf32_hppa_stub_hash_entry * 597 hppa_get_stub_entry (input_section, sym_sec, hash, rel, h plink)585 hppa_get_stub_entry (input_section, sym_sec, hash, rel, htab) 598 586 const asection *input_section; 599 587 const asection *sym_sec; 600 588 struct elf32_hppa_link_hash_entry *hash; 601 589 const Elf_Internal_Rela *rel; 602 struct elf32_hppa_link_hash_table *h plink;590 struct elf32_hppa_link_hash_table *htab; 603 591 { 604 592 struct elf32_hppa_stub_hash_entry *stub_entry; … … 610 598 more than one stub used to reach say, printf, and we need to 611 599 distinguish between them. */ 612 id_sec = h plink->stub_group[input_section->id].link_sec;600 id_sec = htab->stub_group[input_section->id].link_sec; 613 601 614 602 if (hash != NULL && hash->stub_cache != NULL … … 626 614 return NULL; 627 615 628 stub_entry = hppa_stub_hash_lookup (&hplink->stub_hash_table, 629 stub_name, false, false); 630 if (stub_entry == NULL) 631 { 632 if (hash == NULL || hash->elf.root.type != bfd_link_hash_undefweak) 633 (*_bfd_error_handler) (_("%s(%s+0x%lx): cannot find stub entry %s"), 634 bfd_get_filename (input_section->owner), 635 input_section->name, 636 (long) rel->r_offset, 637 stub_name); 638 } 639 else 640 { 641 if (hash != NULL) 642 hash->stub_cache = stub_entry; 643 } 616 stub_entry = hppa_stub_hash_lookup (&htab->stub_hash_table, 617 stub_name, FALSE, FALSE); 618 if (hash != NULL) 619 hash->stub_cache = stub_entry; 644 620 645 621 free (stub_name); … … 653 629 654 630 static struct elf32_hppa_stub_hash_entry * 655 hppa_add_stub (stub_name, section, h plink)631 hppa_add_stub (stub_name, section, htab) 656 632 const char *stub_name; 657 633 asection *section; 658 struct elf32_hppa_link_hash_table *h plink;634 struct elf32_hppa_link_hash_table *htab; 659 635 { 660 636 asection *link_sec; … … 662 638 struct elf32_hppa_stub_hash_entry *stub_entry; 663 639 664 link_sec = h plink->stub_group[section->id].link_sec;665 stub_sec = h plink->stub_group[section->id].stub_sec;640 link_sec = htab->stub_group[section->id].link_sec; 641 stub_sec = htab->stub_group[section->id].stub_sec; 666 642 if (stub_sec == NULL) 667 643 { 668 stub_sec = h plink->stub_group[link_sec->id].stub_sec;644 stub_sec = htab->stub_group[link_sec->id].stub_sec; 669 645 if (stub_sec == NULL) 670 646 { 671 size_t len; 647 size_t namelen; 648 bfd_size_type len; 672 649 char *s_name; 673 650 674 len = strlen (link_sec->name) + sizeof (STUB_SUFFIX); 675 s_name = bfd_alloc (hplink->stub_bfd, len); 651 namelen = strlen (link_sec->name); 652 len = namelen + sizeof (STUB_SUFFIX); 653 s_name = bfd_alloc (htab->stub_bfd, len); 676 654 if (s_name == NULL) 677 655 return NULL; 678 656 679 strcpy (s_name, link_sec->name);680 strcpy (s_name + len - sizeof (STUB_SUFFIX), STUB_SUFFIX);681 stub_sec = (*h plink->add_stub_section) (s_name, link_sec);657 memcpy (s_name, link_sec->name, namelen); 658 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); 659 stub_sec = (*htab->add_stub_section) (s_name, link_sec); 682 660 if (stub_sec == NULL) 683 661 return NULL; 684 h plink->stub_group[link_sec->id].stub_sec = stub_sec;685 } 686 h plink->stub_group[section->id].stub_sec = stub_sec;662 htab->stub_group[link_sec->id].stub_sec = stub_sec; 663 } 664 htab->stub_group[section->id].stub_sec = stub_sec; 687 665 } 688 666 689 667 /* Enter this entry into the linker stub hash table. */ 690 stub_entry = hppa_stub_hash_lookup (&h plink->stub_hash_table, stub_name,691 true, false);668 stub_entry = hppa_stub_hash_lookup (&htab->stub_hash_table, stub_name, 669 TRUE, FALSE); 692 670 if (stub_entry == NULL) 693 671 { 694 672 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"), 695 bfd_ get_filename (section->owner),673 bfd_archive_filename (section->owner), 696 674 stub_name); 697 675 return NULL; … … 699 677 700 678 stub_entry->stub_sec = stub_sec; 701 #if ! LONG_BRANCH_PIC_IN_SHLIB702 stub_entry->reloc_sec = hplink->stub_group[section->id].reloc_sec;703 #endif704 679 stub_entry->stub_offset = 0; 705 680 stub_entry->id_sec = link_sec; … … 722 697 723 698 if (hash != NULL 724 && (((hash->elf.root.type == bfd_link_hash_defined 725 || hash->elf.root.type == bfd_link_hash_defweak) 726 && hash->elf.root.u.def.section->output_section == NULL) 727 || (hash->elf.root.type == bfd_link_hash_defweak 728 && hash->elf.dynindx != -1 729 && hash->elf.plt.offset != (bfd_vma) -1) 730 || hash->elf.root.type == bfd_link_hash_undefweak 731 || hash->elf.root.type == bfd_link_hash_undefined 732 || (hash->maybe_pic_call && !(input_sec->flags & SEC_HAS_GOT_REF)))) 733 { 734 /* If output_section is NULL, then it's a symbol defined in a 735 shared library. We will need an import stub. Decide between 736 hppa_stub_import and hppa_stub_import_shared later. For 737 shared links we need stubs for undefined or weak syms too; 738 They will presumably be resolved by the dynamic linker. */ 699 && hash->elf.plt.offset != (bfd_vma) -1 700 && (hash->elf.dynindx != -1 || hash->pic_call) 701 && !hash->plabel) 702 { 703 /* We need an import stub. Decide between hppa_stub_import 704 and hppa_stub_import_shared later. */ 739 705 return hppa_stub_import; 740 706 } … … 766 732 767 733 if (branch_offset + max_branch_offset >= 2*max_branch_offset) 768 { 769 #if LONG_BRANCH_VIA_PLT 770 if (hash != NULL 771 && hash->elf.dynindx != -1 772 && hash->elf.plt.offset != (bfd_vma) -1 773 && hash->elf.type != STT_PARISC_MILLI) 774 { 775 /* If we are doing a shared link and find we need a long 776 branch stub, then go via the .plt if possible. */ 777 return hppa_stub_import; 778 } 779 else 780 #endif 781 return hppa_stub_long_branch; 782 } 734 return hppa_stub_long_branch; 735 783 736 return hppa_stub_none; 784 737 } … … 807 760 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */ 808 761 762 #define BL22_RP 0xe800a002 /* b,l,n XXX,%rp */ 809 763 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */ 810 764 #define NOP 0x08000240 /* nop */ … … 823 777 #endif 824 778 825 static b oolean779 static bfd_boolean 826 780 hppa_build_one_stub (gen_entry, in_arg) 827 781 struct bfd_hash_entry *gen_entry; … … 830 784 struct elf32_hppa_stub_hash_entry *stub_entry; 831 785 struct bfd_link_info *info; 832 struct elf32_hppa_link_hash_table *h plink;786 struct elf32_hppa_link_hash_table *htab; 833 787 asection *stub_sec; 834 788 bfd *stub_bfd; … … 844 798 info = (struct bfd_link_info *) in_arg; 845 799 846 h plink= hppa_link_hash_table (info);800 htab = hppa_link_hash_table (info); 847 801 stub_sec = stub_entry->stub_sec; 848 802 … … 872 826 bfd_put_32 (stub_bfd, insn, loc + 4); 873 827 874 #if ! LONG_BRANCH_PIC_IN_SHLIB875 if (info->shared)876 {877 /* Output a dynamic relocation for this stub. We only878 output one PCREL21L reloc per stub, trusting that the879 dynamic linker will also fix the implied PCREL17R for the880 second instruction. PCREL21L dynamic relocs had better881 never be emitted for some other purpose... */882 asection *srel;883 Elf_Internal_Rela outrel;884 885 if (stub_entry->h == NULL)886 {887 (*_bfd_error_handler)888 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),889 bfd_get_filename (stub_entry->target_section->owner),890 stub_sec->name,891 (long) stub_entry->stub_offset,892 stub_entry->root.string);893 bfd_set_error (bfd_error_bad_value);894 return false;895 }896 897 srel = stub_entry->reloc_sec;898 if (srel == NULL)899 {900 (*_bfd_error_handler)901 (_("Could not find relocation section for %s"),902 stub_sec->name);903 bfd_set_error (bfd_error_bad_value);904 return false;905 }906 907 outrel.r_offset = (stub_entry->stub_offset908 + stub_sec->output_offset909 + stub_sec->output_section->vma);910 outrel.r_info = ELF32_R_INFO (0, R_PARISC_PCREL21L);911 outrel.r_addend = sym_value;912 bfd_elf32_swap_reloca_out (stub_sec->output_section->owner,913 &outrel,914 ((Elf32_External_Rela *)915 srel->contents + srel->reloc_count));916 ++srel->reloc_count;917 }918 #endif919 828 size = 8; 920 829 break; … … 950 859 off &= ~ (bfd_vma) 1; 951 860 sym_value = (off 952 + h plink->splt->output_offset953 + h plink->splt->output_section->vma954 - elf_gp (h plink->splt->output_section->owner));861 + htab->splt->output_offset 862 + htab->splt->output_section->vma 863 - elf_gp (htab->splt->output_section->owner)); 955 864 956 865 insn = ADDIL_DP; … … 972 881 bfd_put_32 (stub_bfd, insn, loc + 4); 973 882 974 if (h plink->multi_subspace)883 if (htab->multi_subspace) 975 884 { 976 885 val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel); … … 1005 914 bfd_vma value; 1006 915 1007 dynobj = h plink->root.dynobj;916 dynobj = htab->elf.dynobj; 1008 917 eh = (struct elf32_hppa_link_hash_entry *) stub_entry->h; 1009 918 … … 1022 931 <__gp>. */ 1023 932 1024 bfd_put_32 (h plink->splt->owner, value,1025 h plink->splt->contents + off);1026 value = elf_gp (h plink->splt->output_section->owner);1027 bfd_put_32 (h plink->splt->owner, value,1028 h plink->splt->contents + off + 4);933 bfd_put_32 (htab->splt->owner, value, 934 htab->splt->contents + off); 935 value = elf_gp (htab->splt->output_section->owner); 936 bfd_put_32 (htab->splt->owner, value, 937 htab->splt->contents + off + 4); 1029 938 } 1030 939 break; … … 1041 950 + stub_sec->output_section->vma); 1042 951 1043 if (sym_value - 8 + 0x40000 >= 0x80000) 952 if (sym_value - 8 + (1 << (17 + 1)) >= (1 << (17 + 2)) 953 && (!htab->has_22bit_branch 954 || sym_value - 8 + (1 << (22 + 1)) >= (1 << (22 + 2)))) 1044 955 { 1045 956 (*_bfd_error_handler) 1046 957 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"), 1047 bfd_ get_filename (stub_entry->target_section->owner),958 bfd_archive_filename (stub_entry->target_section->owner), 1048 959 stub_sec->name, 1049 960 (long) stub_entry->stub_offset, 1050 961 stub_entry->root.string); 1051 962 bfd_set_error (bfd_error_bad_value); 1052 return false;963 return FALSE; 1053 964 } 1054 965 1055 966 val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_fsel) >> 2; 1056 insn = hppa_rebuild_insn ((int) BL_RP, val, 17); 967 if (!htab->has_22bit_branch) 968 insn = hppa_rebuild_insn ((int) BL_RP, val, 17); 969 else 970 insn = hppa_rebuild_insn ((int) BL22_RP, val, 22); 1057 971 bfd_put_32 (stub_bfd, insn, loc); 1058 972 … … 1072 986 default: 1073 987 BFD_FAIL (); 1074 return false;988 return FALSE; 1075 989 } 1076 990 1077 991 stub_sec->_raw_size += size; 1078 return true;992 return TRUE; 1079 993 } 1080 994 … … 1104 1018 we know stub section sizes. */ 1105 1019 1106 static b oolean1020 static bfd_boolean 1107 1021 hppa_size_one_stub (gen_entry, in_arg) 1108 1022 struct bfd_hash_entry *gen_entry; … … 1110 1024 { 1111 1025 struct elf32_hppa_stub_hash_entry *stub_entry; 1112 struct elf32_hppa_link_hash_table *h plink;1026 struct elf32_hppa_link_hash_table *htab; 1113 1027 int size; 1114 1028 1115 1029 /* Massage our args to the form they really have. */ 1116 1030 stub_entry = (struct elf32_hppa_stub_hash_entry *) gen_entry; 1117 h plink= (struct elf32_hppa_link_hash_table *) in_arg;1031 htab = (struct elf32_hppa_link_hash_table *) in_arg; 1118 1032 1119 1033 if (stub_entry->stub_type == hppa_stub_long_branch) 1120 { 1121 #if ! LONG_BRANCH_PIC_IN_SHLIB 1122 if (stub_entry->reloc_sec != NULL) 1123 stub_entry->reloc_sec->_raw_size += sizeof (Elf32_External_Rela); 1124 #endif 1125 size = 8; 1126 } 1034 size = 8; 1127 1035 else if (stub_entry->stub_type == hppa_stub_long_branch_shared) 1128 1036 size = 12; … … 1131 1039 else /* hppa_stub_import or hppa_stub_import_shared. */ 1132 1040 { 1133 if (h plink->multi_subspace)1041 if (htab->multi_subspace) 1134 1042 size = 28; 1135 1043 else … … 1138 1046 1139 1047 stub_entry->stub_sec->_raw_size += size; 1140 return true;1048 return TRUE; 1141 1049 } 1142 1050 … … 1144 1052 Additionally we set the default architecture and machine. */ 1145 1053 1146 static b oolean1054 static bfd_boolean 1147 1055 elf32_hppa_object_p (abfd) 1148 1056 bfd *abfd; … … 1155 1063 { 1156 1064 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX) 1157 return false;1065 return FALSE; 1158 1066 } 1159 1067 else 1160 1068 { 1161 1069 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX) 1162 return false;1070 return FALSE; 1163 1071 } 1164 1072 … … 1175 1083 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25); 1176 1084 } 1177 return true;1085 return TRUE; 1178 1086 } 1179 1087 … … 1181 1089 value of each external symbol. */ 1182 1090 1183 static b oolean1091 static bfd_boolean 1184 1092 elf32_hppa_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) 1185 1093 bfd *abfd ATTRIBUTE_UNUSED; … … 1192 1100 { 1193 1101 *valp += (*secp)->vma; 1194 return true;1102 return TRUE; 1195 1103 } 1196 1104 … … 1198 1106 short-cuts to various dynamic sections. */ 1199 1107 1200 static b oolean1108 static bfd_boolean 1201 1109 elf32_hppa_create_dynamic_sections (abfd, info) 1202 1110 bfd *abfd; 1203 1111 struct bfd_link_info *info; 1204 1112 { 1205 struct elf32_hppa_link_hash_table *h plink;1113 struct elf32_hppa_link_hash_table *htab; 1206 1114 1207 1115 /* Don't try to create the .plt and .got twice. */ 1208 h plink= hppa_link_hash_table (info);1209 if (h plink->splt != NULL)1210 return true;1116 htab = hppa_link_hash_table (info); 1117 if (htab->splt != NULL) 1118 return TRUE; 1211 1119 1212 1120 /* Call the generic code to do most of the work. */ 1213 1121 if (! _bfd_elf_create_dynamic_sections (abfd, info)) 1214 return false;1215 1216 h plink->splt = bfd_get_section_by_name (abfd, ".plt");1217 h plink->srelplt = bfd_get_section_by_name (abfd, ".rela.plt");1218 1219 h plink->sgot = bfd_get_section_by_name (abfd, ".got");1220 h plink->srelgot = bfd_make_section (abfd, ".rela.got");1221 if (h plink->srelgot == NULL1222 || ! bfd_set_section_flags (abfd, h plink->srelgot,1122 return FALSE; 1123 1124 htab->splt = bfd_get_section_by_name (abfd, ".plt"); 1125 htab->srelplt = bfd_get_section_by_name (abfd, ".rela.plt"); 1126 1127 htab->sgot = bfd_get_section_by_name (abfd, ".got"); 1128 htab->srelgot = bfd_make_section (abfd, ".rela.got"); 1129 if (htab->srelgot == NULL 1130 || ! bfd_set_section_flags (abfd, htab->srelgot, 1223 1131 (SEC_ALLOC 1224 1132 | SEC_LOAD … … 1227 1135 | SEC_LINKER_CREATED 1228 1136 | SEC_READONLY)) 1229 || ! bfd_set_section_alignment (abfd, h plink->srelgot, 2))1230 return false;1231 1232 h plink->sdynbss = bfd_get_section_by_name (abfd, ".dynbss");1233 h plink->srelbss = bfd_get_section_by_name (abfd, ".rela.bss");1234 1235 return true;1137 || ! bfd_set_section_alignment (abfd, htab->srelgot, 2)) 1138 return FALSE; 1139 1140 htab->sdynbss = bfd_get_section_by_name (abfd, ".dynbss"); 1141 htab->srelbss = bfd_get_section_by_name (abfd, ".rela.bss"); 1142 1143 return TRUE; 1236 1144 } 1237 1145 1146 /* Copy the extra info we tack onto an elf_link_hash_entry. */ 1147 1148 static void 1149 elf32_hppa_copy_indirect_symbol (bed, dir, ind) 1150 struct elf_backend_data *bed; 1151 struct elf_link_hash_entry *dir, *ind; 1152 { 1153 struct elf32_hppa_link_hash_entry *edir, *eind; 1154 1155 edir = (struct elf32_hppa_link_hash_entry *) dir; 1156 eind = (struct elf32_hppa_link_hash_entry *) ind; 1157 1158 if (eind->dyn_relocs != NULL) 1159 { 1160 if (edir->dyn_relocs != NULL) 1161 { 1162 struct elf32_hppa_dyn_reloc_entry **pp; 1163 struct elf32_hppa_dyn_reloc_entry *p; 1164 1165 if (ind->root.type == bfd_link_hash_indirect) 1166 abort (); 1167 1168 /* Add reloc counts against the weak sym to the strong sym 1169 list. Merge any entries against the same section. */ 1170 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) 1171 { 1172 struct elf32_hppa_dyn_reloc_entry *q; 1173 1174 for (q = edir->dyn_relocs; q != NULL; q = q->next) 1175 if (q->sec == p->sec) 1176 { 1177 #if RELATIVE_DYNRELOCS 1178 q->relative_count += p->relative_count; 1179 #endif 1180 q->count += p->count; 1181 *pp = p->next; 1182 break; 1183 } 1184 if (q == NULL) 1185 pp = &p->next; 1186 } 1187 *pp = edir->dyn_relocs; 1188 } 1189 1190 edir->dyn_relocs = eind->dyn_relocs; 1191 eind->dyn_relocs = NULL; 1192 } 1193 1194 _bfd_elf_link_hash_copy_indirect (bed, dir, ind); 1195 } 1196 1238 1197 /* Look through the relocs for a section during the first phase, and 1239 allocate space in the global offset table orprocedure linkage1240 table . At this point we haven't necessarily read all the input1241 files. */1242 1243 static b oolean1198 calculate needed space in the global offset table, procedure linkage 1199 table, and dynamic reloc sections. At this point we haven't 1200 necessarily read all the input files. */ 1201 1202 static bfd_boolean 1244 1203 elf32_hppa_check_relocs (abfd, info, sec, relocs) 1245 1204 bfd *abfd; … … 1248 1207 const Elf_Internal_Rela *relocs; 1249 1208 { 1250 bfd *dynobj;1251 1209 Elf_Internal_Shdr *symtab_hdr; 1252 1210 struct elf_link_hash_entry **sym_hashes; 1253 bfd_signed_vma *local_got_refcounts;1254 1211 const Elf_Internal_Rela *rel; 1255 1212 const Elf_Internal_Rela *rel_end; 1256 struct elf32_hppa_link_hash_table *h plink;1213 struct elf32_hppa_link_hash_table *htab; 1257 1214 asection *sreloc; 1258 1215 asection *stubreloc; 1259 1216 1260 1217 if (info->relocateable) 1261 return true; 1262 1263 hplink = hppa_link_hash_table (info); 1264 dynobj = hplink->root.dynobj; 1218 return TRUE; 1219 1220 htab = hppa_link_hash_table (info); 1265 1221 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 1266 1222 sym_hashes = elf_sym_hashes (abfd); 1267 local_got_refcounts = elf_local_got_refcounts (abfd);1268 1223 sreloc = NULL; 1269 1224 stubreloc = NULL; … … 1276 1231 NEED_PLT = 2, 1277 1232 NEED_DYNREL = 4, 1278 #if LONG_BRANCH_PIC_IN_SHLIB 1279 NEED_STUBREL = 0, /* We won't be needing them in this case. */ 1280 #else 1281 NEED_STUBREL = 8, 1282 #endif 1283 PLT_PLABEL = 16 1233 PLT_PLABEL = 8 1284 1234 }; 1285 1235 … … 1337 1287 1338 1288 case R_PARISC_PCREL12F: 1339 hplink->has_12bit_branch = 1; 1340 /* Fall thru. */ 1289 htab->has_12bit_branch = 1; 1290 goto branch_common; 1291 1341 1292 case R_PARISC_PCREL17C: 1342 1293 case R_PARISC_PCREL17F: 1343 hplink->has_17bit_branch = 1; 1344 /* Fall thru. */ 1294 htab->has_17bit_branch = 1; 1295 goto branch_common; 1296 1345 1297 case R_PARISC_PCREL22F: 1298 htab->has_22bit_branch = 1; 1299 branch_common: 1346 1300 /* Function calls might need to go through the .plt, and 1347 1301 might require long branch stubs. */ … … 1362 1316 where a symbol is forced local by versioning, or due 1363 1317 to symbolic linking, and we lose the .plt entry. */ 1364 need_entry = NEED_PLT | NEED_STUBREL;1318 need_entry = NEED_PLT; 1365 1319 if (h->elf.type == STT_PARISC_MILLI) 1366 need_entry = NEED_STUBREL;1320 need_entry = 0; 1367 1321 } 1368 1322 break; … … 1385 1339 (*_bfd_error_handler) 1386 1340 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"), 1387 bfd_ get_filename (abfd),1341 bfd_archive_filename (abfd), 1388 1342 elf_hppa_howto_table[r_type].name); 1389 1343 bfd_set_error (bfd_error_bad_value); 1390 return false;1344 return FALSE; 1391 1345 } 1392 1346 /* Fall through. */ … … 1397 1351 case R_PARISC_DIR14R: 1398 1352 case R_PARISC_DIR21L: /* As above, and for ext branches too. */ 1399 #if 11353 #if 0 1400 1354 /* Help debug shared library creation. Any of the above 1401 1355 relocs can be used in shared libs, but they may cause … … 1405 1359 (*_bfd_error_handler) 1406 1360 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"), 1407 bfd_ get_filename (abfd),1361 bfd_archive_filename (abfd), 1408 1362 elf_hppa_howto_table[r_type].name); 1409 1363 } … … 1421 1375 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, 1422 1376 &h->elf, rel->r_offset)) 1423 return false;1377 return FALSE; 1424 1378 continue; 1425 1379 … … 1429 1383 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, 1430 1384 &h->elf, rel->r_addend)) 1431 return false;1385 return FALSE; 1432 1386 continue; 1433 1387 … … 1441 1395 /* Allocate space for a GOT entry, as well as a dynamic 1442 1396 relocation for this entry. */ 1443 if (dynobj == NULL) 1444 hplink->root.dynobj = dynobj = abfd; 1445 1446 if (hplink->sgot == NULL) 1397 if (htab->sgot == NULL) 1447 1398 { 1448 if (! elf32_hppa_create_dynamic_sections (dynobj, info)) 1449 return false; 1399 if (htab->elf.dynobj == NULL) 1400 htab->elf.dynobj = abfd; 1401 if (!elf32_hppa_create_dynamic_sections (htab->elf.dynobj, info)) 1402 return FALSE; 1450 1403 } 1451 1404 1452 1405 if (h != NULL) 1453 1406 { 1454 if (h->elf.got.refcount == -1) 1455 { 1456 h->elf.got.refcount = 1; 1457 1458 /* Make sure this symbol is output as a dynamic symbol. */ 1459 if (h->elf.dynindx == -1) 1460 { 1461 if (! bfd_elf32_link_record_dynamic_symbol (info, 1462 &h->elf)) 1463 return false; 1464 } 1465 } 1466 else 1467 h->elf.got.refcount += 1; 1407 h->elf.got.refcount += 1; 1468 1408 } 1469 1409 else 1470 1410 { 1411 bfd_signed_vma *local_got_refcounts; 1412 1471 1413 /* This is a global offset table entry for a local symbol. */ 1414 local_got_refcounts = elf_local_got_refcounts (abfd); 1472 1415 if (local_got_refcounts == NULL) 1473 1416 { 1474 size_tsize;1417 bfd_size_type size; 1475 1418 1476 1419 /* Allocate space for local got offsets and local … … 1478 1421 elf_obj_tdata with another target specific 1479 1422 pointer. */ 1480 size = symtab_hdr->sh_info * 2 * sizeof (bfd_signed_vma); 1423 size = symtab_hdr->sh_info; 1424 size *= 2 * sizeof (bfd_signed_vma); 1481 1425 local_got_refcounts = ((bfd_signed_vma *) 1482 bfd_ alloc (abfd, size));1426 bfd_zalloc (abfd, size)); 1483 1427 if (local_got_refcounts == NULL) 1484 return false;1428 return FALSE; 1485 1429 elf_local_got_refcounts (abfd) = local_got_refcounts; 1486 memset (local_got_refcounts, -1, size);1487 1430 } 1488 if (local_got_refcounts[r_symndx] == -1) 1489 local_got_refcounts[r_symndx] = 1; 1490 else 1491 local_got_refcounts[r_symndx] += 1; 1431 local_got_refcounts[r_symndx] += 1; 1492 1432 } 1493 1433 } … … 1507 1447 if (h != NULL) 1508 1448 { 1509 if (h->elf.plt.refcount == -1) 1510 { 1511 h->elf.plt.refcount = 1; 1512 h->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; 1513 } 1514 else 1515 h->elf.plt.refcount += 1; 1449 h->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; 1450 h->elf.plt.refcount += 1; 1516 1451 1517 1452 /* If this .plt entry is for a plabel, mark it so … … 1523 1458 else if (need_entry & PLT_PLABEL) 1524 1459 { 1525 int indx; 1526 1460 bfd_signed_vma *local_got_refcounts; 1461 bfd_signed_vma *local_plt_refcounts; 1462 1463 local_got_refcounts = elf_local_got_refcounts (abfd); 1527 1464 if (local_got_refcounts == NULL) 1528 1465 { 1529 size_tsize;1466 bfd_size_type size; 1530 1467 1531 1468 /* Allocate space for local got offsets and local 1532 1469 plt offsets. */ 1533 size = symtab_hdr->sh_info * 2 * sizeof (bfd_signed_vma); 1470 size = symtab_hdr->sh_info; 1471 size *= 2 * sizeof (bfd_signed_vma); 1534 1472 local_got_refcounts = ((bfd_signed_vma *) 1535 bfd_ alloc (abfd, size));1473 bfd_zalloc (abfd, size)); 1536 1474 if (local_got_refcounts == NULL) 1537 return false;1475 return FALSE; 1538 1476 elf_local_got_refcounts (abfd) = local_got_refcounts; 1539 memset (local_got_refcounts, -1, size);1540 1477 } 1541 indx = r_symndx + symtab_hdr->sh_info; 1542 if (local_got_refcounts[indx] == -1) 1543 local_got_refcounts[indx] = 1; 1544 else 1545 local_got_refcounts[indx] += 1; 1478 local_plt_refcounts = (local_got_refcounts 1479 + symtab_hdr->sh_info); 1480 local_plt_refcounts[r_symndx] += 1; 1546 1481 } 1547 1482 } 1548 1483 } 1549 1484 1550 if (need_entry & (NEED_DYNREL | NEED_STUBREL))1485 if (need_entry & NEED_DYNREL) 1551 1486 { 1552 1487 /* Flag this symbol as having a non-got, non-plt reference 1553 1488 so that we generate copy relocs if it turns out to be 1554 1489 dynamic. */ 1555 if (h != NULL )1490 if (h != NULL && !info->shared) 1556 1491 h->elf.elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; 1557 1492 … … 1566 1501 DEF_REGULAR is not set now but will be set later (it is 1567 1502 never cleared). We account for that possibility below by 1568 storing information in the reloc_entries field of the1503 storing information in the dyn_relocs field of the 1569 1504 hash table entry. 1570 1505 … … 1578 1513 is absolute too, as in that case it is the reloc in the 1579 1514 stub we will be creating, rather than copying the PCREL 1580 reloc in the branch. */ 1581 if ((sec->flags & SEC_ALLOC) != 0 1582 && info->shared 1583 #if RELATIVE_DYNAMIC_RELOCS 1584 && (!info->symbolic 1585 || is_absolute_reloc (r_type) 1586 || (h != NULL 1587 && ((h->elf.elf_link_hash_flags 1588 & ELF_LINK_HASH_DEF_REGULAR) == 0))) 1589 #endif 1590 ) 1515 reloc in the branch. 1516 1517 If on the other hand, we are creating an executable, we 1518 may need to keep relocations for symbols satisfied by a 1519 dynamic library if we manage to avoid copy relocs for the 1520 symbol. */ 1521 if ((info->shared 1522 && (sec->flags & SEC_ALLOC) != 0 1523 && (IS_ABSOLUTE_RELOC (r_type) 1524 || (h != NULL 1525 && (!info->symbolic 1526 || h->elf.root.type == bfd_link_hash_defweak 1527 || (h->elf.elf_link_hash_flags 1528 & ELF_LINK_HASH_DEF_REGULAR) == 0)))) 1529 || (!info->shared 1530 && (sec->flags & SEC_ALLOC) != 0 1531 && h != NULL 1532 && (h->elf.root.type == bfd_link_hash_defweak 1533 || (h->elf.elf_link_hash_flags 1534 & ELF_LINK_HASH_DEF_REGULAR) == 0))) 1591 1535 { 1592 boolean doit; 1593 asection *srel; 1594 1595 srel = sreloc; 1596 if ((need_entry & NEED_STUBREL)) 1597 srel = stubreloc; 1536 struct elf32_hppa_dyn_reloc_entry *p; 1537 struct elf32_hppa_dyn_reloc_entry **head; 1598 1538 1599 1539 /* Create a reloc section in dynobj and make room for 1600 1540 this reloc. */ 1601 if (srel == NULL)1541 if (sreloc == NULL) 1602 1542 { 1603 1543 char *name; 1604 1605 if (dynobj == NULL) 1606 hplink->root.dynobj = dynobj = abfd; 1607 1608 name = bfd_elf_string_from_elf_section 1609 (abfd, 1610 elf_elfheader (abfd)->e_shstrndx, 1611 elf_section_data (sec)->rel_hdr.sh_name); 1544 bfd *dynobj; 1545 1546 name = (bfd_elf_string_from_elf_section 1547 (abfd, 1548 elf_elfheader (abfd)->e_shstrndx, 1549 elf_section_data (sec)->rel_hdr.sh_name)); 1612 1550 if (name == NULL) 1613 1551 { … … 1616 1554 sec->name); 1617 1555 bfd_set_error (bfd_error_bad_value); 1618 return false;1556 return FALSE; 1619 1557 } 1620 1558 1621 if ((need_entry & NEED_STUBREL)) 1622 { 1623 size_t len = strlen (name) + sizeof (STUB_SUFFIX); 1624 char *newname = bfd_malloc (len); 1625 1626 if (newname == NULL) 1627 return false; 1628 strcpy (newname, name); 1629 strcpy (newname + len - sizeof (STUB_SUFFIX), 1630 STUB_SUFFIX); 1631 name = newname; 1632 } 1633 1634 srel = bfd_get_section_by_name (dynobj, name); 1635 if (srel == NULL) 1559 if (htab->elf.dynobj == NULL) 1560 htab->elf.dynobj = abfd; 1561 1562 dynobj = htab->elf.dynobj; 1563 sreloc = bfd_get_section_by_name (dynobj, name); 1564 if (sreloc == NULL) 1636 1565 { 1637 1566 flagword flags; 1638 1567 1639 srel = bfd_make_section (dynobj, name);1568 sreloc = bfd_make_section (dynobj, name); 1640 1569 flags = (SEC_HAS_CONTENTS | SEC_READONLY 1641 1570 | SEC_IN_MEMORY | SEC_LINKER_CREATED); 1642 1571 if ((sec->flags & SEC_ALLOC) != 0) 1643 1572 flags |= SEC_ALLOC | SEC_LOAD; 1644 if (srel == NULL1645 || !bfd_set_section_flags (dynobj, srel , flags)1646 || !bfd_set_section_alignment (dynobj, srel , 2))1647 return false;1573 if (sreloc == NULL 1574 || !bfd_set_section_flags (dynobj, sreloc, flags) 1575 || !bfd_set_section_alignment (dynobj, sreloc, 2)) 1576 return FALSE; 1648 1577 } 1649 else if ((need_entry & NEED_STUBREL)) 1650 free (name); 1651 1652 if ((need_entry & NEED_STUBREL)) 1653 stubreloc = srel; 1654 else 1655 sreloc = srel; 1578 1579 elf_section_data (sec)->sreloc = sreloc; 1656 1580 } 1657 1581 1658 #if ! LONG_BRANCH_PIC_IN_SHLIB 1659 /* If this is a function call, we only need one dynamic 1660 reloc for the stub as all calls to a particular 1661 function will go through the same stub. Actually, a 1662 long branch stub needs two relocations, but we count 1663 on some intelligence on the part of the dynamic 1664 linker. */ 1665 if ((need_entry & NEED_STUBREL)) 1582 /* If this is a global symbol, we count the number of 1583 relocations we need for this symbol. */ 1584 if (h != NULL) 1666 1585 { 1667 doit = h->stub_reloc_sec != stubreloc; 1668 h->stub_reloc_sec = stubreloc; 1586 head = &h->dyn_relocs; 1669 1587 } 1670 1588 else 1671 #endif1672 doit = 1;1673 1674 if (doit)1675 1589 { 1676 srel->_raw_size += sizeof (Elf32_External_Rela); 1677 1678 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS 1679 /* Keep track of relocations we have entered for 1680 this global symbol, so that we can discard them 1681 later if necessary. */ 1682 if (h != NULL 1683 && (0 1684 #if RELATIVE_DYNAMIC_RELOCS 1685 || ! is_absolute_reloc (rtype) 1686 #endif 1687 || (need_entry & NEED_STUBREL))) 1688 { 1689 struct elf32_hppa_dyn_reloc_entry *p; 1690 1691 for (p = h->reloc_entries; p != NULL; p = p->next) 1692 if (p->section == srel) 1693 break; 1694 1695 if (p == NULL) 1696 { 1697 p = ((struct elf32_hppa_dyn_reloc_entry *) 1698 bfd_alloc (dynobj, sizeof *p)); 1699 if (p == NULL) 1700 return false; 1701 p->next = h->reloc_entries; 1702 h->reloc_entries = p; 1703 p->section = srel; 1704 p->count = 0; 1705 } 1706 1707 /* NEED_STUBREL and NEED_DYNREL are never both 1708 set. Leave the count at zero for the 1709 NEED_STUBREL case as we only ever have one 1710 stub reloc per section per symbol, and this 1711 simplifies code in hppa_discard_copies. */ 1712 if (! (need_entry & NEED_STUBREL)) 1713 ++p->count; 1714 } 1590 /* Track dynamic relocs needed for local syms too. 1591 We really need local syms available to do this 1592 easily. Oh well. */ 1593 1594 asection *s; 1595 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, 1596 sec, r_symndx); 1597 if (s == NULL) 1598 return FALSE; 1599 1600 head = ((struct elf32_hppa_dyn_reloc_entry **) 1601 &elf_section_data (s)->local_dynrel); 1602 } 1603 1604 p = *head; 1605 if (p == NULL || p->sec != sec) 1606 { 1607 p = ((struct elf32_hppa_dyn_reloc_entry *) 1608 bfd_alloc (htab->elf.dynobj, 1609 (bfd_size_type) sizeof *p)); 1610 if (p == NULL) 1611 return FALSE; 1612 p->next = *head; 1613 *head = p; 1614 p->sec = sec; 1615 p->count = 0; 1616 #if RELATIVE_DYNRELOCS 1617 p->relative_count = 0; 1715 1618 #endif 1716 1619 } 1620 1621 p->count += 1; 1622 #if RELATIVE_DYNRELOCS 1623 if (!IS_ABSOLUTE_RELOC (rtype)) 1624 p->relative_count += 1; 1625 #endif 1717 1626 } 1718 1627 } 1719 1628 } 1720 1629 1721 return true;1630 return TRUE; 1722 1631 } 1723 1632 … … 1726 1635 1727 1636 static asection * 1728 elf32_hppa_gc_mark_hook ( abfd, info, rel, h, sym)1729 bfd *abfd;1637 elf32_hppa_gc_mark_hook (sec, info, rel, h, sym) 1638 asection *sec; 1730 1639 struct bfd_link_info *info ATTRIBUTE_UNUSED; 1731 1640 Elf_Internal_Rela *rel; … … 1757 1666 } 1758 1667 else 1759 { 1760 if (!(elf_bad_symtab (abfd) 1761 && ELF_ST_BIND (sym->st_info) != STB_LOCAL) 1762 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) 1763 && sym->st_shndx != SHN_COMMON)) 1764 { 1765 return bfd_section_from_elf_index (abfd, sym->st_shndx); 1766 } 1767 } 1668 return bfd_section_from_elf_index (sec->owner, sym->st_shndx); 1768 1669 1769 1670 return NULL; … … 1773 1674 removed. */ 1774 1675 1775 static b oolean1676 static bfd_boolean 1776 1677 elf32_hppa_gc_sweep_hook (abfd, info, sec, relocs) 1777 1678 bfd *abfd; … … 1785 1686 bfd_signed_vma *local_plt_refcounts; 1786 1687 const Elf_Internal_Rela *rel, *relend; 1787 unsigned long r_symndx; 1788 struct elf_link_hash_entry *h; 1789 struct elf32_hppa_link_hash_table *hplink; 1790 bfd *dynobj; 1688 1689 elf_section_data (sec)->local_dynrel = NULL; 1791 1690 1792 1691 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; … … 1796 1695 if (local_plt_refcounts != NULL) 1797 1696 local_plt_refcounts += symtab_hdr->sh_info; 1798 hplink = hppa_link_hash_table (info);1799 dynobj = hplink->root.dynobj;1800 if (dynobj == NULL)1801 return true;1802 1697 1803 1698 relend = relocs + sec->reloc_count; 1804 1699 for (rel = relocs; rel < relend; rel++) 1805 switch ((unsigned int) ELF32_R_TYPE (rel->r_info)) 1806 { 1807 case R_PARISC_DLTIND14F: 1808 case R_PARISC_DLTIND14R: 1809 case R_PARISC_DLTIND21L: 1810 r_symndx = ELF32_R_SYM (rel->r_info); 1811 if (r_symndx >= symtab_hdr->sh_info) 1812 { 1813 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 1814 if (h->got.refcount > 0) 1815 h->got.refcount -= 1; 1816 } 1817 else if (local_got_refcounts != NULL) 1818 { 1819 if (local_got_refcounts[r_symndx] > 0) 1820 local_got_refcounts[r_symndx] -= 1; 1821 } 1822 break; 1823 1824 case R_PARISC_PCREL12F: 1825 case R_PARISC_PCREL17C: 1826 case R_PARISC_PCREL17F: 1827 case R_PARISC_PCREL22F: 1828 r_symndx = ELF32_R_SYM (rel->r_info); 1829 if (r_symndx >= symtab_hdr->sh_info) 1830 { 1831 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 1832 if (h->plt.refcount > 0) 1833 h->plt.refcount -= 1; 1834 } 1835 break; 1836 1837 case R_PARISC_PLABEL14R: 1838 case R_PARISC_PLABEL21L: 1839 case R_PARISC_PLABEL32: 1840 r_symndx = ELF32_R_SYM (rel->r_info); 1841 if (r_symndx >= symtab_hdr->sh_info) 1842 { 1843 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 1844 if (h->plt.refcount > 0) 1845 h->plt.refcount -= 1; 1846 } 1847 else if (local_plt_refcounts != NULL) 1848 { 1849 if (local_plt_refcounts[r_symndx] > 0) 1850 local_plt_refcounts[r_symndx] -= 1; 1851 } 1852 break; 1853 1854 default: 1855 break; 1856 } 1857 1858 return true; 1700 { 1701 unsigned long r_symndx; 1702 unsigned int r_type; 1703 struct elf_link_hash_entry *h = NULL; 1704 1705 r_symndx = ELF32_R_SYM (rel->r_info); 1706 if (r_symndx >= symtab_hdr->sh_info) 1707 { 1708 struct elf32_hppa_link_hash_entry *eh; 1709 struct elf32_hppa_dyn_reloc_entry **pp; 1710 struct elf32_hppa_dyn_reloc_entry *p; 1711 1712 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 1713 eh = (struct elf32_hppa_link_hash_entry *) h; 1714 1715 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) 1716 if (p->sec == sec) 1717 { 1718 /* Everything must go for SEC. */ 1719 *pp = p->next; 1720 break; 1721 } 1722 } 1723 1724 r_type = ELF32_R_TYPE (rel->r_info); 1725 switch (r_type) 1726 { 1727 case R_PARISC_DLTIND14F: 1728 case R_PARISC_DLTIND14R: 1729 case R_PARISC_DLTIND21L: 1730 if (h != NULL) 1731 { 1732 if (h->got.refcount > 0) 1733 h->got.refcount -= 1; 1734 } 1735 else if (local_got_refcounts != NULL) 1736 { 1737 if (local_got_refcounts[r_symndx] > 0) 1738 local_got_refcounts[r_symndx] -= 1; 1739 } 1740 break; 1741 1742 case R_PARISC_PCREL12F: 1743 case R_PARISC_PCREL17C: 1744 case R_PARISC_PCREL17F: 1745 case R_PARISC_PCREL22F: 1746 if (h != NULL) 1747 { 1748 if (h->plt.refcount > 0) 1749 h->plt.refcount -= 1; 1750 } 1751 break; 1752 1753 case R_PARISC_PLABEL14R: 1754 case R_PARISC_PLABEL21L: 1755 case R_PARISC_PLABEL32: 1756 if (h != NULL) 1757 { 1758 if (h->plt.refcount > 0) 1759 h->plt.refcount -= 1; 1760 } 1761 else if (local_plt_refcounts != NULL) 1762 { 1763 if (local_plt_refcounts[r_symndx] > 0) 1764 local_plt_refcounts[r_symndx] -= 1; 1765 } 1766 break; 1767 1768 default: 1769 break; 1770 } 1771 } 1772 1773 return TRUE; 1859 1774 } 1860 1775 … … 1863 1778 1864 1779 static void 1865 elf32_hppa_hide_symbol (info, h )1866 struct bfd_link_info *info ATTRIBUTE_UNUSED;1780 elf32_hppa_hide_symbol (info, h, force_local) 1781 struct bfd_link_info *info; 1867 1782 struct elf_link_hash_entry *h; 1783 bfd_boolean force_local; 1868 1784 { 1869 if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0) 1870 h->dynindx = -1; 1785 if (force_local) 1786 { 1787 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL; 1788 if (h->dynindx != -1) 1789 { 1790 h->dynindx = -1; 1791 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, 1792 h->dynstr_index); 1793 } 1794 } 1795 1871 1796 if (! ((struct elf32_hppa_link_hash_entry *) h)->plabel) 1872 1797 { … … 1893 1818 understand. */ 1894 1819 1895 static b oolean1820 static bfd_boolean 1896 1821 elf32_hppa_adjust_dynamic_symbol (info, h) 1897 1822 struct bfd_link_info *info; 1898 1823 struct elf_link_hash_entry *h; 1899 1824 { 1900 bfd *dynobj; 1901 struct elf32_hppa_link_hash_table *hplink; 1825 struct elf32_hppa_link_hash_table *htab; 1826 struct elf32_hppa_link_hash_entry *eh; 1827 struct elf32_hppa_dyn_reloc_entry *p; 1902 1828 asection *s; 1903 1904 hplink = hppa_link_hash_table (info); 1905 dynobj = hplink->root.dynobj; 1829 unsigned int power_of_two; 1906 1830 1907 1831 /* If this is a function, put it in the procedure linkage table. We 1908 will fill in the contents of the procedure linkage table later, 1909 when we know the address of the .got section. */ 1832 will fill in the contents of the procedure linkage table later. */ 1910 1833 if (h->type == STT_FUNC 1911 1834 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) 1912 1835 { 1913 if (!info->shared1914 && h->plt.refcount > 01915 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 01916 && (h->root.u.def.section->flags & SEC_HAS_GOT_REF) != 0)1917 {1918 ((struct elf32_hppa_link_hash_entry *) h)->maybe_pic_call = 1;1919 }1920 1921 1836 if (h->plt.refcount <= 0 1922 1837 || ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 … … 1935 1850 /* As a special sop to the hppa ABI, we keep a .plt entry 1936 1851 for functions in sections containing PIC code. */ 1937 if (((struct elf32_hppa_link_hash_entry *) h)->maybe_pic_call) 1852 if (!info->shared 1853 && h->plt.refcount > 0 1854 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 1855 && (h->root.u.def.section->flags & SEC_HAS_GOT_REF) != 0) 1938 1856 ((struct elf32_hppa_link_hash_entry *) h)->pic_call = 1; 1939 1857 else … … 1941 1859 h->plt.offset = (bfd_vma) -1; 1942 1860 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 1943 return true;1944 1861 } 1945 1862 } 1946 1863 1947 if (! ((struct elf32_hppa_link_hash_entry *) h)->pic_call) 1948 { 1949 /* Make sure this symbol is output as a dynamic symbol. */ 1950 if (h->dynindx == -1 1951 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 1952 { 1953 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 1954 return false; 1955 } 1956 } 1957 1958 return true; 1959 } 1864 return TRUE; 1865 } 1866 else 1867 h->plt.offset = (bfd_vma) -1; 1960 1868 1961 1869 /* If this is a weak symbol, and there is a real definition, the … … 1969 1877 h->root.u.def.section = h->weakdef->root.u.def.section; 1970 1878 h->root.u.def.value = h->weakdef->root.u.def.value; 1971 return true;1879 return TRUE; 1972 1880 } 1973 1881 … … 1980 1888 be handled correctly by relocate_section. */ 1981 1889 if (info->shared) 1982 return true;1890 return TRUE; 1983 1891 1984 1892 /* If there are no references to this symbol that do not use the 1985 1893 GOT, we don't need to generate a copy reloc. */ 1986 1894 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) 1987 return true; 1895 return TRUE; 1896 1897 eh = (struct elf32_hppa_link_hash_entry *) h; 1898 for (p = eh->dyn_relocs; p != NULL; p = p->next) 1899 { 1900 s = p->sec->output_section; 1901 if (s != NULL && (s->flags & SEC_READONLY) != 0) 1902 break; 1903 } 1904 1905 /* If we didn't find any dynamic relocs in read-only sections, then 1906 we'll be keeping the dynamic relocs and avoiding the copy reloc. */ 1907 if (p == NULL) 1908 { 1909 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; 1910 return TRUE; 1911 } 1988 1912 1989 1913 /* We must allocate the symbol in our .dynbss section, which will … … 1997 1921 same memory location for the variable. */ 1998 1922 1999 s = hplink->sdynbss;1923 htab = hppa_link_hash_table (info); 2000 1924 2001 1925 /* We must generate a COPY reloc to tell the dynamic linker to 2002 1926 copy the initial value out of the dynamic object and into the 2003 runtime process image. We need to remember the offset into the 2004 .rela.bss section we are going to use. */ 1927 runtime process image. */ 2005 1928 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) 2006 1929 { 2007 asection *srel; 2008 2009 srel = hplink->srelbss; 2010 srel->_raw_size += sizeof (Elf32_External_Rela); 1930 htab->srelbss->_raw_size += sizeof (Elf32_External_Rela); 2011 1931 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; 2012 1932 } 2013 1933 2014 { 2015 /* We need to figure out the alignment required for this symbol. I 2016 have no idea how other ELF linkers handle this. */ 2017 unsigned int power_of_two; 2018 2019 power_of_two = bfd_log2 (h->size); 2020 if (power_of_two > 3) 2021 power_of_two = 3; 2022 2023 /* Apply the required alignment. */ 2024 s->_raw_size = BFD_ALIGN (s->_raw_size, 2025 (bfd_size_type) (1 << power_of_two)); 2026 if (power_of_two > bfd_get_section_alignment (dynobj, s)) 2027 { 2028 if (! bfd_set_section_alignment (dynobj, s, power_of_two)) 2029 return false; 2030 } 2031 } 1934 /* We need to figure out the alignment required for this symbol. I 1935 have no idea how other ELF linkers handle this. */ 1936 1937 power_of_two = bfd_log2 (h->size); 1938 if (power_of_two > 3) 1939 power_of_two = 3; 1940 1941 /* Apply the required alignment. */ 1942 s = htab->sdynbss; 1943 s->_raw_size = BFD_ALIGN (s->_raw_size, 1944 (bfd_size_type) (1 << power_of_two)); 1945 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) 1946 { 1947 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) 1948 return FALSE; 1949 } 1950 2032 1951 /* Define the symbol as being at this point in the section. */ 2033 1952 h->root.u.def.section = s; … … 2037 1956 s->_raw_size += h->size; 2038 1957 2039 return true;1958 return TRUE; 2040 1959 } 2041 1960 … … 2044 1963 the first part of elf32_hppa_adjust_dynamic_symbol. */ 2045 1964 2046 static b oolean2047 hppa_handle_PIC_calls (h, inf)1965 static bfd_boolean 1966 mark_PIC_calls (h, inf) 2048 1967 struct elf_link_hash_entry *h; 2049 1968 PTR inf ATTRIBUTE_UNUSED; 2050 1969 { 1970 if (h->root.type == bfd_link_hash_warning) 1971 h = (struct elf_link_hash_entry *) h->root.u.i.link; 1972 2051 1973 if (! (h->plt.refcount > 0 2052 1974 && (h->root.type == bfd_link_hash_defined … … 2056 1978 h->plt.offset = (bfd_vma) -1; 2057 1979 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 2058 return true;1980 return TRUE; 2059 1981 } 2060 1982 2061 1983 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; 2062 ((struct elf32_hppa_link_hash_entry *) h)->maybe_pic_call = 1;2063 1984 ((struct elf32_hppa_link_hash_entry *) h)->pic_call = 1; 2064 1985 2065 return true;1986 return TRUE; 2066 1987 } 2067 1988 2068 /* Allocate space in .plt, .got and associated reloc sections for2069 global syms. */2070 2071 static b oolean2072 allocate_plt_ and_got(h, inf)1989 /* Allocate space in the .plt for entries that won't have relocations. 1990 ie. pic_call and plabel entries. */ 1991 1992 static bfd_boolean 1993 allocate_plt_static (h, inf) 2073 1994 struct elf_link_hash_entry *h; 2074 1995 PTR inf; 2075 1996 { 2076 1997 struct bfd_link_info *info; 2077 struct elf32_hppa_link_hash_table *h plink;1998 struct elf32_hppa_link_hash_table *htab; 2078 1999 asection *s; 2079 2000 2080 if (h->root.type == bfd_link_hash_indirect 2081 || h->root.type == bfd_link_hash_warning) 2082 return true; 2001 if (h->root.type == bfd_link_hash_indirect) 2002 return TRUE; 2003 2004 if (h->root.type == bfd_link_hash_warning) 2005 h = (struct elf_link_hash_entry *) h->root.u.i.link; 2083 2006 2084 2007 info = (struct bfd_link_info *) inf; 2085 h plink= hppa_link_hash_table (info);2086 if (( hplink->root.dynamic_sections_created2087 && h->plt.refcount > 0)2088 || ((struct elf32_hppa_link_hash_entry *) h)->pic_call)2089 { 2090 /* Make an entry in the .plt section. */2091 s = h plink->splt;2008 htab = hppa_link_hash_table (info); 2009 if (((struct elf32_hppa_link_hash_entry *) h)->pic_call) 2010 { 2011 /* Make an entry in the .plt section for non-pic code that is 2012 calling pic code. */ 2013 ((struct elf32_hppa_link_hash_entry *) h)->plabel = 0; 2014 s = htab->splt; 2092 2015 h->plt.offset = s->_raw_size; 2093 if (PLABEL_PLT_ENTRY_SIZE != PLT_ENTRY_SIZE 2094 && ((struct elf32_hppa_link_hash_entry *) h)->plabel 2095 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 2096 { 2097 /* Add some extra space for the dynamic linker to use. */ 2098 s->_raw_size += PLABEL_PLT_ENTRY_SIZE; 2016 s->_raw_size += PLT_ENTRY_SIZE; 2017 } 2018 else if (htab->elf.dynamic_sections_created 2019 && h->plt.refcount > 0) 2020 { 2021 /* Make sure this symbol is output as a dynamic symbol. 2022 Undefined weak syms won't yet be marked as dynamic. */ 2023 if (h->dynindx == -1 2024 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 2025 && h->type != STT_PARISC_MILLI) 2026 { 2027 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 2028 return FALSE; 2029 } 2030 2031 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) 2032 { 2033 /* Allocate these later. From this point on, h->plabel 2034 means that the plt entry is only used by a plabel. 2035 We'll be using a normal plt entry for this symbol, so 2036 clear the plabel indicator. */ 2037 ((struct elf32_hppa_link_hash_entry *) h)->plabel = 0; 2038 } 2039 else if (((struct elf32_hppa_link_hash_entry *) h)->plabel) 2040 { 2041 /* Make an entry in the .plt section for plabel references 2042 that won't have a .plt entry for other reasons. */ 2043 s = htab->splt; 2044 h->plt.offset = s->_raw_size; 2045 s->_raw_size += PLT_ENTRY_SIZE; 2099 2046 } 2100 2047 else 2101 s->_raw_size += PLT_ENTRY_SIZE; 2102 2103 if (! ((struct elf32_hppa_link_hash_entry *) h)->pic_call 2104 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) 2105 { 2106 /* We also need to make an entry in the .rela.plt section. */ 2107 hplink->srelplt->_raw_size += sizeof (Elf32_External_Rela); 2108 hplink->need_plt_stub = 1; 2048 { 2049 /* No .plt entry needed. */ 2050 h->plt.offset = (bfd_vma) -1; 2051 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 2109 2052 } 2110 2053 } … … 2115 2058 } 2116 2059 2117 if (h->got.refcount > 0) 2118 { 2119 boolean dyn; 2120 2121 s = hplink->sgot; 2122 h->got.offset = s->_raw_size; 2123 s->_raw_size += GOT_ENTRY_SIZE; 2124 dyn = hplink->root.dynamic_sections_created; 2125 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)) 2126 hplink->srelgot->_raw_size += sizeof (Elf32_External_Rela); 2127 } 2128 else 2129 h->got.offset = (bfd_vma) -1; 2130 2131 return true; 2060 return TRUE; 2132 2061 } 2133 2062 2134 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \ 2135 || RELATIVE_DYNAMIC_RELOCS) 2136 /* This function is called via elf_link_hash_traverse to discard space 2137 we allocated for relocs that it turned out we didn't need. */ 2138 2139 static boolean 2140 hppa_discard_copies (h, inf) 2063 /* Allocate space in .plt, .got and associated reloc sections for 2064 global syms. */ 2065 2066 static bfd_boolean 2067 allocate_dynrelocs (h, inf) 2141 2068 struct elf_link_hash_entry *h; 2142 2069 PTR inf; 2143 2070 { 2144 struct elf32_hppa_dyn_reloc_entry *s; 2071 struct bfd_link_info *info; 2072 struct elf32_hppa_link_hash_table *htab; 2073 asection *s; 2145 2074 struct elf32_hppa_link_hash_entry *eh; 2146 struct bfd_link_info *info; 2075 struct elf32_hppa_dyn_reloc_entry *p; 2076 2077 if (h->root.type == bfd_link_hash_indirect) 2078 return TRUE; 2079 2080 if (h->root.type == bfd_link_hash_warning) 2081 h = (struct elf_link_hash_entry *) h->root.u.i.link; 2082 2083 info = (struct bfd_link_info *) inf; 2084 htab = hppa_link_hash_table (info); 2085 if (htab->elf.dynamic_sections_created 2086 && h->plt.offset != (bfd_vma) -1 2087 && !((struct elf32_hppa_link_hash_entry *) h)->pic_call 2088 && !((struct elf32_hppa_link_hash_entry *) h)->plabel) 2089 { 2090 /* Make an entry in the .plt section. */ 2091 s = htab->splt; 2092 h->plt.offset = s->_raw_size; 2093 s->_raw_size += PLT_ENTRY_SIZE; 2094 2095 /* We also need to make an entry in the .rela.plt section. */ 2096 htab->srelplt->_raw_size += sizeof (Elf32_External_Rela); 2097 htab->need_plt_stub = 1; 2098 } 2099 2100 if (h->got.refcount > 0) 2101 { 2102 /* Make sure this symbol is output as a dynamic symbol. 2103 Undefined weak syms won't yet be marked as dynamic. */ 2104 if (h->dynindx == -1 2105 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 2106 && h->type != STT_PARISC_MILLI) 2107 { 2108 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 2109 return FALSE; 2110 } 2111 2112 s = htab->sgot; 2113 h->got.offset = s->_raw_size; 2114 s->_raw_size += GOT_ENTRY_SIZE; 2115 if (htab->elf.dynamic_sections_created 2116 && (info->shared 2117 || (h->dynindx != -1 2118 && h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)) 2119 { 2120 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela); 2121 } 2122 } 2123 else 2124 h->got.offset = (bfd_vma) -1; 2147 2125 2148 2126 eh = (struct elf32_hppa_link_hash_entry *) h; 2149 info = (struct bfd_link_info *) inf; 2150 2151 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT 2152 /* Handle the stub reloc case. If we have a plt entry for the 2153 function, we won't be needing long branch stubs. s->count will 2154 only be zero for stub relocs, which provides a handy way of 2155 flagging these relocs, and means we need do nothing special for 2156 the forced local and symbolic link case. */ 2157 if (eh->stub_reloc_sec != NULL 2158 && eh->elf.plt.offset != (bfd_vma) -1) 2159 { 2160 for (s = eh->reloc_entries; s != NULL; s = s->next) 2161 if (s->count == 0) 2162 s->section->_raw_size -= sizeof (Elf32_External_Rela); 2163 } 2127 if (eh->dyn_relocs == NULL) 2128 return TRUE; 2129 2130 /* If this is a -Bsymbolic shared link, then we need to discard all 2131 space allocated for dynamic pc-relative relocs against symbols 2132 defined in a regular object. For the normal shared case, discard 2133 space for relocs that have become local due to symbol visibility 2134 changes. */ 2135 if (info->shared) 2136 { 2137 #if RELATIVE_DYNRELOCS 2138 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 2139 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 2140 || info->symbolic)) 2141 { 2142 struct elf32_hppa_dyn_reloc_entry **pp; 2143 2144 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) 2145 { 2146 p->count -= p->relative_count; 2147 p->relative_count = 0; 2148 if (p->count == 0) 2149 *pp = p->next; 2150 else 2151 pp = &p->next; 2152 } 2153 } 2164 2154 #endif 2165 2166 #if RELATIVE_DYNAMIC_RELOCS 2167 /* If a symbol has been forced local or we have found a regular 2168 definition for the symbolic link case, then we won't be needing 2169 any relocs. */ 2170 if (eh->elf.dynindx == -1 2171 || ((eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 2172 && !is_absolute_reloc (r_type) 2173 && info->symbolic)) 2174 { 2175 for (s = eh->reloc_entries; s != NULL; s = s->next) 2176 s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela); 2177 } 2178 #endif 2179 2180 return true; 2155 } 2156 else 2157 { 2158 /* For the non-shared case, discard space for relocs against 2159 symbols which turn out to need copy relocs or are not 2160 dynamic. */ 2161 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 2162 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 2163 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 2164 || (htab->elf.dynamic_sections_created 2165 && (h->root.type == bfd_link_hash_undefweak 2166 || h->root.type == bfd_link_hash_undefined)))) 2167 { 2168 /* Make sure this symbol is output as a dynamic symbol. 2169 Undefined weak syms won't yet be marked as dynamic. */ 2170 if (h->dynindx == -1 2171 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 2172 && h->type != STT_PARISC_MILLI) 2173 { 2174 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 2175 return FALSE; 2176 } 2177 2178 /* If that succeeded, we know we'll be keeping all the 2179 relocs. */ 2180 if (h->dynindx != -1) 2181 goto keep; 2182 } 2183 2184 eh->dyn_relocs = NULL; 2185 return TRUE; 2186 2187 keep: ; 2188 } 2189 2190 /* Finally, allocate space. */ 2191 for (p = eh->dyn_relocs; p != NULL; p = p->next) 2192 { 2193 asection *sreloc = elf_section_data (p->sec)->sreloc; 2194 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela); 2195 } 2196 2197 return TRUE; 2181 2198 } 2182 #endif2183 2199 2184 2200 /* This function is called via elf_link_hash_traverse to force … … 2189 2205 elf_adjust_dynamic_symbol. */ 2190 2206 2191 static b oolean2207 static bfd_boolean 2192 2208 clobber_millicode_symbols (h, info) 2193 2209 struct elf_link_hash_entry *h; 2194 2210 struct bfd_link_info *info; 2195 2211 { 2196 /* We only want to remove these from the dynamic symbol table. 2197 Therefore we do not leave ELF_LINK_FORCED_LOCAL set. */ 2198 if (h->type == STT_PARISC_MILLI) 2199 { 2200 unsigned short oldflags = h->elf_link_hash_flags; 2201 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL; 2202 elf32_hppa_hide_symbol (info, h); 2203 h->elf_link_hash_flags &= ~ELF_LINK_FORCED_LOCAL; 2204 h->elf_link_hash_flags |= oldflags & ELF_LINK_FORCED_LOCAL; 2205 } 2206 return true; 2212 if (h->root.type == bfd_link_hash_warning) 2213 h = (struct elf_link_hash_entry *) h->root.u.i.link; 2214 2215 if (h->type == STT_PARISC_MILLI 2216 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 2217 { 2218 elf32_hppa_hide_symbol (info, h, TRUE); 2219 } 2220 return TRUE; 2207 2221 } 2208 2222 2223 /* Find any dynamic relocs that apply to read-only sections. */ 2224 2225 static bfd_boolean 2226 readonly_dynrelocs (h, inf) 2227 struct elf_link_hash_entry *h; 2228 PTR inf; 2229 { 2230 struct elf32_hppa_link_hash_entry *eh; 2231 struct elf32_hppa_dyn_reloc_entry *p; 2232 2233 if (h->root.type == bfd_link_hash_warning) 2234 h = (struct elf_link_hash_entry *) h->root.u.i.link; 2235 2236 eh = (struct elf32_hppa_link_hash_entry *) h; 2237 for (p = eh->dyn_relocs; p != NULL; p = p->next) 2238 { 2239 asection *s = p->sec->output_section; 2240 2241 if (s != NULL && (s->flags & SEC_READONLY) != 0) 2242 { 2243 struct bfd_link_info *info = (struct bfd_link_info *) inf; 2244 2245 info->flags |= DF_TEXTREL; 2246 2247 /* Not an error, just cut short the traversal. */ 2248 return FALSE; 2249 } 2250 } 2251 return TRUE; 2252 } 2253 2209 2254 /* Set the sizes of the dynamic sections. */ 2210 2255 2211 static b oolean2256 static bfd_boolean 2212 2257 elf32_hppa_size_dynamic_sections (output_bfd, info) 2213 bfd *output_bfd ;2258 bfd *output_bfd ATTRIBUTE_UNUSED; 2214 2259 struct bfd_link_info *info; 2215 2260 { 2216 struct elf32_hppa_link_hash_table *h plink;2261 struct elf32_hppa_link_hash_table *htab; 2217 2262 bfd *dynobj; 2263 bfd *ibfd; 2218 2264 asection *s; 2219 boolean relocs; 2220 boolean reltext; 2221 2222 hplink = hppa_link_hash_table (info); 2223 dynobj = hplink->root.dynobj; 2265 bfd_boolean relocs; 2266 2267 htab = hppa_link_hash_table (info); 2268 dynobj = htab->elf.dynobj; 2224 2269 if (dynobj == NULL) 2225 2270 abort (); 2226 2271 2227 if (hplink->root.dynamic_sections_created) 2228 { 2229 bfd *i; 2230 2272 if (htab->elf.dynamic_sections_created) 2273 { 2231 2274 /* Set the contents of the .interp section to the interpreter. */ 2232 2275 if (! info->shared) … … 2240 2283 2241 2284 /* Force millicode symbols local. */ 2242 elf_link_hash_traverse (&h plink->root,2285 elf_link_hash_traverse (&htab->elf, 2243 2286 clobber_millicode_symbols, 2244 2287 info); 2245 2246 /* Set up .got and .plt offsets for local syms. */ 2247 for (i = info->input_bfds; i; i = i->link_next) 2248 { 2249 bfd_signed_vma *local_got; 2250 bfd_signed_vma *end_local_got; 2251 bfd_signed_vma *local_plt; 2252 bfd_signed_vma *end_local_plt; 2253 bfd_size_type locsymcount; 2254 Elf_Internal_Shdr *symtab_hdr; 2255 asection *srel; 2256 2257 if (bfd_get_flavour (i) != bfd_target_elf_flavour) 2258 continue; 2259 2260 local_got = elf_local_got_refcounts (i); 2261 if (!local_got) 2262 continue; 2263 2264 symtab_hdr = &elf_tdata (i)->symtab_hdr; 2265 locsymcount = symtab_hdr->sh_info; 2266 end_local_got = local_got + locsymcount; 2267 s = hplink->sgot; 2268 srel = hplink->srelgot; 2269 for (; local_got < end_local_got; ++local_got) 2288 } 2289 else 2290 { 2291 /* Run through the function symbols, looking for any that are 2292 PIC, and mark them as needing .plt entries so that %r19 will 2293 be set up. */ 2294 if (! info->shared) 2295 elf_link_hash_traverse (&htab->elf, mark_PIC_calls, (PTR) info); 2296 } 2297 2298 /* Set up .got and .plt offsets for local syms, and space for local 2299 dynamic relocs. */ 2300 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 2301 { 2302 bfd_signed_vma *local_got; 2303 bfd_signed_vma *end_local_got; 2304 bfd_signed_vma *local_plt; 2305 bfd_signed_vma *end_local_plt; 2306 bfd_size_type locsymcount; 2307 Elf_Internal_Shdr *symtab_hdr; 2308 asection *srel; 2309 2310 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) 2311 continue; 2312 2313 for (s = ibfd->sections; s != NULL; s = s->next) 2314 { 2315 struct elf32_hppa_dyn_reloc_entry *p; 2316 2317 for (p = ((struct elf32_hppa_dyn_reloc_entry *) 2318 elf_section_data (s)->local_dynrel); 2319 p != NULL; 2320 p = p->next) 2270 2321 { 2271 if (*local_got > 0) 2322 if (!bfd_is_abs_section (p->sec) 2323 && bfd_is_abs_section (p->sec->output_section)) 2272 2324 { 2273 *local_got = s->_raw_size;2274 s->_raw_size += GOT_ENTRY_SIZE;2275 if (info->shared)2276 srel->_raw_size += sizeof (Elf32_External_Rela);2325 /* Input section has been discarded, either because 2326 it is a copy of a linkonce section or due to 2327 linker script /DISCARD/, so we'll be discarding 2328 the relocs too. */ 2277 2329 } 2278 else 2279 *local_got = (bfd_vma) -1; 2330 else if (p->count != 0) 2331 { 2332 srel = elf_section_data (p->sec)->sreloc; 2333 srel->_raw_size += p->count * sizeof (Elf32_External_Rela); 2334 if ((p->sec->output_section->flags & SEC_READONLY) != 0) 2335 info->flags |= DF_TEXTREL; 2336 } 2280 2337 } 2281 2282 local_plt = end_local_got; 2283 end_local_plt = local_plt + locsymcount; 2284 s = hplink->splt; 2285 srel = hplink->srelplt; 2338 } 2339 2340 local_got = elf_local_got_refcounts (ibfd); 2341 if (!local_got) 2342 continue; 2343 2344 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; 2345 locsymcount = symtab_hdr->sh_info; 2346 end_local_got = local_got + locsymcount; 2347 s = htab->sgot; 2348 srel = htab->srelgot; 2349 for (; local_got < end_local_got; ++local_got) 2350 { 2351 if (*local_got > 0) 2352 { 2353 *local_got = s->_raw_size; 2354 s->_raw_size += GOT_ENTRY_SIZE; 2355 if (info->shared) 2356 srel->_raw_size += sizeof (Elf32_External_Rela); 2357 } 2358 else 2359 *local_got = (bfd_vma) -1; 2360 } 2361 2362 local_plt = end_local_got; 2363 end_local_plt = local_plt + locsymcount; 2364 if (! htab->elf.dynamic_sections_created) 2365 { 2366 /* Won't be used, but be safe. */ 2367 for (; local_plt < end_local_plt; ++local_plt) 2368 *local_plt = (bfd_vma) -1; 2369 } 2370 else 2371 { 2372 s = htab->splt; 2373 srel = htab->srelplt; 2286 2374 for (; local_plt < end_local_plt; ++local_plt) 2287 2375 { … … 2298 2386 } 2299 2387 } 2300 else 2301 { 2302 /* Run through the function symbols, looking for any that are 2303 PIC, and allocate space for the necessary .plt entries so 2304 that %r19 will be set up. */ 2305 if (! info->shared) 2306 elf_link_hash_traverse (&hplink->root, 2307 hppa_handle_PIC_calls, 2308 info); 2309 } 2310 2311 /* Allocate global sym .plt and .got entries. */ 2312 elf_link_hash_traverse (&hplink->root, 2313 allocate_plt_and_got, 2314 info); 2315 2316 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \ 2317 || RELATIVE_DYNAMIC_RELOCS) 2318 /* If this is a -Bsymbolic shared link, then we need to discard all 2319 relocs against symbols defined in a regular object. We also need 2320 to lose relocs we've allocated for long branch stubs if we know 2321 we won't be generating a stub. */ 2322 if (info->shared) 2323 elf_link_hash_traverse (&hplink->root, 2324 hppa_discard_copies, 2325 info); 2326 #endif 2388 2389 /* Do all the .plt entries without relocs first. The dynamic linker 2390 uses the last .plt reloc to find the end of the .plt (and hence 2391 the start of the .got) for lazy linking. */ 2392 elf_link_hash_traverse (&htab->elf, allocate_plt_static, (PTR) info); 2393 2394 /* Allocate global sym .plt and .got entries, and space for global 2395 sym dynamic relocs. */ 2396 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); 2327 2397 2328 2398 /* The check_relocs and adjust_dynamic_symbol entry points have 2329 2399 determined the sizes of the various dynamic sections. Allocate 2330 2400 memory for them. */ 2331 relocs = false; 2332 reltext = false; 2401 relocs = FALSE; 2333 2402 for (s = dynobj->sections; s != NULL; s = s->next) 2334 2403 { 2335 const char *name;2336 2337 2404 if ((s->flags & SEC_LINKER_CREATED) == 0) 2338 2405 continue; 2339 2406 2340 /* It's OK to base decisions on the section name, because none 2341 of the dynobj section names depend upon the input files. */ 2342 name = bfd_get_section_name (dynobj, s); 2343 2344 if (strncmp (name, ".rela", 5) == 0) 2345 { 2346 if (s->_raw_size != 0) 2347 { 2348 asection *target; 2349 const char *outname; 2350 2351 /* Remember whether there are any reloc sections other 2352 than .rela.plt. */ 2353 if (strcmp (name+5, ".plt") != 0) 2354 relocs = true; 2355 2356 /* If this relocation section applies to a read only 2357 section, then we probably need a DT_TEXTREL entry. */ 2358 outname = bfd_get_section_name (output_bfd, 2359 s->output_section); 2360 target = bfd_get_section_by_name (output_bfd, outname + 5); 2361 if (target != NULL 2362 && (target->flags & SEC_READONLY) != 0 2363 && (target->flags & SEC_ALLOC) != 0) 2364 reltext = true; 2365 2366 /* We use the reloc_count field as a counter if we need 2367 to copy relocs into the output file. */ 2368 s->reloc_count = 0; 2369 } 2370 } 2371 else if (strcmp (name, ".plt") == 0) 2372 { 2373 if (hplink->need_plt_stub) 2407 if (s == htab->splt) 2408 { 2409 if (htab->need_plt_stub) 2374 2410 { 2375 2411 /* Make space for the plt stub at the end of the .plt 2376 2412 section. We want this stub right at the end, up 2377 2413 against the .got section. */ 2378 int gotalign = bfd_section_alignment (dynobj, h plink->sgot);2414 int gotalign = bfd_section_alignment (dynobj, htab->sgot); 2379 2415 int pltalign = bfd_section_alignment (dynobj, s); 2380 2416 bfd_size_type mask; … … 2386 2422 } 2387 2423 } 2388 else if (s trcmp (name, ".got") == 0)2424 else if (s == htab->sgot) 2389 2425 ; 2426 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) 2427 { 2428 if (s->_raw_size != 0) 2429 { 2430 /* Remember whether there are any reloc sections other 2431 than .rela.plt. */ 2432 if (s != htab->srelplt) 2433 relocs = TRUE; 2434 2435 /* We use the reloc_count field as a counter if we need 2436 to copy relocs into the output file. */ 2437 s->reloc_count = 0; 2438 } 2439 } 2390 2440 else 2391 2441 { … … 2413 2463 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); 2414 2464 if (s->contents == NULL && s->_raw_size != 0) 2415 return false;2416 } 2417 2418 if (h plink->root.dynamic_sections_created)2465 return FALSE; 2466 } 2467 2468 if (htab->elf.dynamic_sections_created) 2419 2469 { 2420 2470 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It … … 2422 2472 communicate the LTP value of a load module to the dynamic 2423 2473 linker. */ 2424 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)) 2425 return false; 2474 #define add_dynamic_entry(TAG, VAL) \ 2475 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) 2476 2477 if (!add_dynamic_entry (DT_PLTGOT, 0)) 2478 return FALSE; 2426 2479 2427 2480 /* Add some entries to the .dynamic section. We fill in the … … 2430 2483 the .dynamic section. The DT_DEBUG entry is filled in by the 2431 2484 dynamic linker and used by the debugger. */ 2432 if (! 2433 { 2434 if (! bfd_elf32_add_dynamic_entry (info,DT_DEBUG, 0))2435 return false;2436 } 2437 2438 if (h plink->srelplt->_raw_size != 0)2439 { 2440 if (! bfd_elf32_add_dynamic_entry (info,DT_PLTRELSZ, 0)2441 || ! bfd_elf32_add_dynamic_entry (info,DT_PLTREL, DT_RELA)2442 || ! bfd_elf32_add_dynamic_entry (info,DT_JMPREL, 0))2443 return false;2485 if (!info->shared) 2486 { 2487 if (!add_dynamic_entry (DT_DEBUG, 0)) 2488 return FALSE; 2489 } 2490 2491 if (htab->srelplt->_raw_size != 0) 2492 { 2493 if (!add_dynamic_entry (DT_PLTRELSZ, 0) 2494 || !add_dynamic_entry (DT_PLTREL, DT_RELA) 2495 || !add_dynamic_entry (DT_JMPREL, 0)) 2496 return FALSE; 2444 2497 } 2445 2498 2446 2499 if (relocs) 2447 2500 { 2448 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0) 2449 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0) 2450 || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT, 2451 sizeof (Elf32_External_Rela))) 2452 return false; 2453 } 2454 2455 if (reltext) 2456 { 2457 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0)) 2458 return false; 2459 info->flags |= DF_TEXTREL; 2460 } 2461 } 2462 2463 return true; 2501 if (!add_dynamic_entry (DT_RELA, 0) 2502 || !add_dynamic_entry (DT_RELASZ, 0) 2503 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) 2504 return FALSE; 2505 2506 /* If any dynamic relocs apply to a read-only section, 2507 then we need a DT_TEXTREL entry. */ 2508 if ((info->flags & DF_TEXTREL) == 0) 2509 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, 2510 (PTR) info); 2511 2512 if ((info->flags & DF_TEXTREL) != 0) 2513 { 2514 if (!add_dynamic_entry (DT_TEXTREL, 0)) 2515 return FALSE; 2516 } 2517 } 2518 } 2519 #undef add_dynamic_entry 2520 2521 return TRUE; 2464 2522 } 2465 2523 2466 2524 /* External entry points for sizing and building linker stubs. */ 2467 2525 2468 /* Determine and set the size of the stub section for a final link. 2469 2470 The basic idea here is to examine all the relocations looking for 2471 PC-relative calls to a target that is unreachable with a "bl" 2472 instruction. */ 2473 2474 boolean 2475 elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace, group_size, 2476 add_stub_section, layout_sections_again) 2526 /* Set up various things so that we can make a list of input sections 2527 for each output section included in the link. Returns -1 on error, 2528 0 when no stubs will be needed, and 1 on success. */ 2529 2530 int 2531 elf32_hppa_setup_section_lists (output_bfd, info) 2477 2532 bfd *output_bfd; 2478 bfd *stub_bfd;2479 2533 struct bfd_link_info *info; 2480 boolean multi_subspace;2481 bfd_signed_vma group_size;2482 asection * (*add_stub_section) PARAMS ((const char *, asection *));2483 void (*layout_sections_again) PARAMS ((void));2484 2534 { 2485 2535 bfd *input_bfd; 2536 unsigned int bfd_count; 2537 int top_id, top_index; 2486 2538 asection *section; 2487 2539 asection **input_list, **list; 2488 Elf_Internal_Sym *local_syms, **all_local_syms; 2489 unsigned int bfd_indx, bfd_count; 2490 int top_id, top_index; 2491 struct elf32_hppa_link_hash_table *hplink; 2492 bfd_size_type stub_group_size; 2493 boolean stubs_always_before_branch; 2494 boolean stub_changed = 0; 2495 boolean ret = 0; 2496 2497 hplink = hppa_link_hash_table (info); 2498 2499 /* Stash our params away. */ 2500 hplink->stub_bfd = stub_bfd; 2501 hplink->multi_subspace = multi_subspace; 2502 hplink->add_stub_section = add_stub_section; 2503 hplink->layout_sections_again = layout_sections_again; 2504 stubs_always_before_branch = group_size < 0; 2505 if (group_size < 0) 2506 stub_group_size = -group_size; 2507 else 2508 stub_group_size = group_size; 2509 if (stub_group_size == 1) 2510 { 2511 /* Default values. */ 2512 stub_group_size = 8000000; 2513 if (hplink->has_17bit_branch || hplink->multi_subspace) 2514 stub_group_size = 250000; 2515 if (hplink->has_12bit_branch) 2516 stub_group_size = 7812; 2517 } 2540 bfd_size_type amt; 2541 struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); 2542 2543 if (htab->elf.root.creator->flavour != bfd_target_elf_flavour) 2544 return 0; 2518 2545 2519 2546 /* Count the number of input BFDs and find the top input section id. */ … … 2531 2558 } 2532 2559 } 2533 2534 hplink->stub_group 2535 = (struct map_stub *) bfd_zmalloc (sizeof (struct map_stub) * (top_id + 1)); 2536 if (hplink->stub_group == NULL) 2537 return false; 2538 2539 /* Make a list of input sections for each output section included in 2540 the link. 2541 2542 We can't use output_bfd->section_count here to find the top output 2560 htab->bfd_count = bfd_count; 2561 2562 amt = sizeof (struct map_stub) * (top_id + 1); 2563 htab->stub_group = (struct map_stub *) bfd_zmalloc (amt); 2564 if (htab->stub_group == NULL) 2565 return -1; 2566 2567 /* We can't use output_bfd->section_count here to find the top output 2543 2568 section index as some sections may have been removed, and 2544 2569 _bfd_strip_section_from_output doesn't renumber the indices. */ … … 2551 2576 } 2552 2577 2553 input_list 2554 = (asection **) bfd_malloc (sizeof (asection *) * (top_index + 1)); 2578 htab->top_index = top_index; 2579 amt = sizeof (asection *) * (top_index + 1); 2580 input_list = (asection **) bfd_malloc (amt); 2581 htab->input_list = input_list; 2555 2582 if (input_list == NULL) 2556 return false;2583 return -1; 2557 2584 2558 2585 /* For sections we aren't interested in, mark their entries with a … … 2571 2598 } 2572 2599 2573 /* Now actually build the lists. */ 2574 for (input_bfd = info->input_bfds; 2575 input_bfd != NULL; 2576 input_bfd = input_bfd->link_next) 2577 { 2578 for (section = input_bfd->sections; 2579 section != NULL; 2580 section = section->next) 2581 { 2582 if (section->output_section != NULL 2583 && section->output_section->owner == output_bfd 2584 && section->output_section->index <= top_index) 2585 { 2586 list = input_list + section->output_section->index; 2587 if (*list != bfd_abs_section_ptr) 2588 { 2589 /* Steal the link_sec pointer for our list. */ 2590 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec) 2591 /* This happens to make the list in reverse order, 2592 which is what we want. */ 2593 PREV_SEC (section) = *list; 2594 *list = section; 2595 } 2596 } 2597 } 2598 } 2599 2600 /* See whether we can group stub sections together. Grouping stub 2601 sections may result in fewer stubs. More importantly, we need to 2602 put all .init* and .fini* stubs at the beginning of the .init or 2603 .fini output sections respectively, because glibc splits the 2604 _init and _fini functions into multiple parts. Putting a stub in 2605 the middle of a function is not a good idea. */ 2606 list = input_list + top_index; 2600 return 1; 2601 } 2602 2603 /* The linker repeatedly calls this function for each input section, 2604 in the order that input sections are linked into output sections. 2605 Build lists of input sections to determine groupings between which 2606 we may insert linker stubs. */ 2607 2608 void 2609 elf32_hppa_next_input_section (info, isec) 2610 struct bfd_link_info *info; 2611 asection *isec; 2612 { 2613 struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); 2614 2615 if (isec->output_section->index <= htab->top_index) 2616 { 2617 asection **list = htab->input_list + isec->output_section->index; 2618 if (*list != bfd_abs_section_ptr) 2619 { 2620 /* Steal the link_sec pointer for our list. */ 2621 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) 2622 /* This happens to make the list in reverse order, 2623 which is what we want. */ 2624 PREV_SEC (isec) = *list; 2625 *list = isec; 2626 } 2627 } 2628 } 2629 2630 /* See whether we can group stub sections together. Grouping stub 2631 sections may result in fewer stubs. More importantly, we need to 2632 put all .init* and .fini* stubs at the beginning of the .init or 2633 .fini output sections respectively, because glibc splits the 2634 _init and _fini functions into multiple parts. Putting a stub in 2635 the middle of a function is not a good idea. */ 2636 2637 static void 2638 group_sections (htab, stub_group_size, stubs_always_before_branch) 2639 struct elf32_hppa_link_hash_table *htab; 2640 bfd_size_type stub_group_size; 2641 bfd_boolean stubs_always_before_branch; 2642 { 2643 asection **list = htab->input_list + htab->top_index; 2607 2644 do 2608 2645 { … … 2615 2652 asection *prev; 2616 2653 bfd_size_type total; 2654 bfd_boolean big_sec; 2617 2655 2618 2656 curr = tail; … … 2621 2659 else 2622 2660 total = tail->_raw_size; 2661 big_sec = total >= stub_group_size; 2662 2623 2663 while ((prev = PREV_SEC (curr)) != NULL 2624 2664 && ((total += curr->output_offset - prev->output_offset) … … 2627 2667 2628 2668 /* OK, the size from the start of CURR to the end is less 2629 than 2 50000 bytes and thus can be handled by one stub2669 than 240000 bytes and thus can be handled by one stub 2630 2670 section. (or the tail section is itself larger than 2631 2 50000 bytes, in which case we may be toast.)2671 240000 bytes, in which case we may be toast.) 2632 2672 We should really be keeping track of the total size of 2633 2673 stubs added here, as stubs contribute to the final output 2634 2674 section size. That's a little tricky, and this way will 2635 only break if stubs added total more than 12144 bytes, or 2636 1518 long branch stubs. It seems unlikely for more than 2637 1518 different functions to be called, especially from 2638 code only 250000 bytes long. */ 2675 only break if stubs added total more than 22144 bytes, or 2676 2768 long branch stubs. It seems unlikely for more than 2677 2768 different functions to be called, especially from 2678 code only 240000 bytes long. This limit used to be 2679 250000, but c++ code tends to generate lots of little 2680 functions, and sometimes violated the assumption. */ 2639 2681 do 2640 2682 { 2641 2683 prev = PREV_SEC (tail); 2642 2684 /* Set up this stub group. */ 2643 h plink->stub_group[tail->id].link_sec = curr;2685 htab->stub_group[tail->id].link_sec = curr; 2644 2686 } 2645 2687 while (tail != curr && (tail = prev) != NULL); 2646 2688 2647 /* But wait, there's more! Input sections up to 250000 2648 bytes before the stub section can be handled by it too. */ 2649 if (!stubs_always_before_branch) 2689 /* But wait, there's more! Input sections up to 240000 2690 bytes before the stub section can be handled by it too. 2691 Don't do this if we have a really large section after the 2692 stubs, as adding more stubs increases the chance that 2693 branches may not reach into the stub section. */ 2694 if (!stubs_always_before_branch && !big_sec) 2650 2695 { 2651 2696 total = 0; … … 2656 2701 tail = prev; 2657 2702 prev = PREV_SEC (tail); 2658 h plink->stub_group[tail->id].link_sec = curr;2703 htab->stub_group[tail->id].link_sec = curr; 2659 2704 } 2660 2705 } … … 2662 2707 } 2663 2708 } 2664 while (list-- != input_list);2665 free ( input_list);2709 while (list-- != htab->input_list); 2710 free (htab->input_list); 2666 2711 #undef PREV_SEC 2712 } 2713 2714 /* Read in all local syms for all input bfds, and create hash entries 2715 for export stubs if we are building a multi-subspace shared lib. 2716 Returns -1 on error, 1 if export stubs created, 0 otherwise. */ 2717 2718 static int 2719 get_local_syms (output_bfd, input_bfd, info) 2720 bfd *output_bfd; 2721 bfd *input_bfd; 2722 struct bfd_link_info *info; 2723 { 2724 unsigned int bfd_indx; 2725 Elf_Internal_Sym *local_syms, **all_local_syms; 2726 int stub_changed = 0; 2727 struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); 2667 2728 2668 2729 /* We want to read in symbol extension records only once. To do this 2669 2730 we need to read in the local symbols in parallel and save them for 2670 2731 later use; so hold pointers to the local symbols in an array. */ 2671 all_local_syms2672 = (Elf_Internal_Sym **) bfd_zmalloc (sizeof (Elf_Internal_Sym *)2673 * bfd_count);2732 bfd_size_type amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count; 2733 all_local_syms = (Elf_Internal_Sym **) bfd_zmalloc (amt); 2734 htab->all_local_syms = all_local_syms; 2674 2735 if (all_local_syms == NULL) 2675 return false;2736 return -1; 2676 2737 2677 2738 /* Walk over all the input BFDs, swapping in local symbols. 2678 2739 If we are creating a shared library, create hash entries for the 2679 2740 export stubs. */ 2680 for ( input_bfd = info->input_bfds,bfd_indx = 0;2741 for (bfd_indx = 0; 2681 2742 input_bfd != NULL; 2682 2743 input_bfd = input_bfd->link_next, bfd_indx++) 2683 2744 { 2684 2745 Elf_Internal_Shdr *symtab_hdr; 2685 Elf_Internal_Sym *isym;2686 Elf32_External_Sym *ext_syms, *esym, *end_sy;2687 2746 2688 2747 /* We'll need the symbol table in a second. */ … … 2691 2750 continue; 2692 2751 2693 /* We need an array of the local symbols attached to the input bfd. 2694 Unfortunately, we're going to have to read & swap them in. */ 2695 local_syms = (Elf_Internal_Sym *) 2696 bfd_malloc (symtab_hdr->sh_info * sizeof (Elf_Internal_Sym)); 2752 /* We need an array of the local symbols attached to the input bfd. */ 2753 local_syms = (Elf_Internal_Sym *) symtab_hdr->contents; 2697 2754 if (local_syms == NULL) 2698 2755 { 2699 goto error_ret_free_local; 2700 } 2756 local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, 2757 symtab_hdr->sh_info, 0, 2758 NULL, NULL, NULL); 2759 /* Cache them for elf_link_input_bfd. */ 2760 symtab_hdr->contents = (unsigned char *) local_syms; 2761 } 2762 if (local_syms == NULL) 2763 return -1; 2764 2701 2765 all_local_syms[bfd_indx] = local_syms; 2702 ext_syms = (Elf32_External_Sym *) 2703 bfd_malloc (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)); 2704 if (ext_syms == NULL) 2705 { 2706 goto error_ret_free_local; 2707 } 2708 2709 if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0 2710 || (bfd_read (ext_syms, 1, 2711 (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)), 2712 input_bfd) 2713 != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)))) 2714 { 2715 free (ext_syms); 2716 goto error_ret_free_local; 2717 } 2718 2719 /* Swap the local symbols in. */ 2720 isym = local_syms; 2721 esym = ext_syms; 2722 for (end_sy = esym + symtab_hdr->sh_info; esym < end_sy; esym++, isym++) 2723 bfd_elf32_swap_symbol_in (input_bfd, esym, isym); 2724 2725 /* Now we can free the external symbols. */ 2726 free (ext_syms); 2727 2728 #if ! LONG_BRANCH_PIC_IN_SHLIB 2729 /* If this is a shared link, find all the stub reloc sections. */ 2730 if (info->shared) 2731 for (section = input_bfd->sections; 2732 section != NULL; 2733 section = section->next) 2734 { 2735 char *name; 2736 asection *reloc_sec; 2737 2738 name = bfd_malloc (strlen (section->name) 2739 + sizeof STUB_SUFFIX 2740 + 5); 2741 if (name == NULL) 2742 return false; 2743 sprintf (name, ".rela%s%s", section->name, STUB_SUFFIX); 2744 reloc_sec = bfd_get_section_by_name (hplink->root.dynobj, name); 2745 hplink->stub_group[section->id].reloc_sec = reloc_sec; 2746 free (name); 2747 } 2748 #endif 2749 2750 if (info->shared && hplink->multi_subspace) 2766 2767 if (info->shared && htab->multi_subspace) 2751 2768 { 2752 2769 struct elf_link_hash_entry **sym_hashes; … … 2792 2809 sec = hash->elf.root.u.def.section; 2793 2810 stub_name = hash->elf.root.root.string; 2794 stub_entry = hppa_stub_hash_lookup (&h plink->stub_hash_table,2811 stub_entry = hppa_stub_hash_lookup (&htab->stub_hash_table, 2795 2812 stub_name, 2796 false, false);2813 FALSE, FALSE); 2797 2814 if (stub_entry == NULL) 2798 2815 { 2799 stub_entry = hppa_add_stub (stub_name, sec, h plink);2816 stub_entry = hppa_add_stub (stub_name, sec, htab); 2800 2817 if (!stub_entry) 2801 goto error_ret_free_local;2818 return -1; 2802 2819 2803 2820 stub_entry->target_value = hash->elf.root.u.def.value; … … 2810 2827 { 2811 2828 (*_bfd_error_handler) (_("%s: duplicate export stub %s"), 2812 bfd_get_filename (input_bfd),2813 stub_name);2829 bfd_archive_filename (input_bfd), 2830 stub_name); 2814 2831 } 2815 2832 } … … 2818 2835 } 2819 2836 2837 return stub_changed; 2838 } 2839 2840 /* Determine and set the size of the stub section for a final link. 2841 2842 The basic idea here is to examine all the relocations looking for 2843 PC-relative calls to a target that is unreachable with a "bl" 2844 instruction. */ 2845 2846 bfd_boolean 2847 elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace, group_size, 2848 add_stub_section, layout_sections_again) 2849 bfd *output_bfd; 2850 bfd *stub_bfd; 2851 struct bfd_link_info *info; 2852 bfd_boolean multi_subspace; 2853 bfd_signed_vma group_size; 2854 asection * (*add_stub_section) PARAMS ((const char *, asection *)); 2855 void (*layout_sections_again) PARAMS ((void)); 2856 { 2857 bfd_size_type stub_group_size; 2858 bfd_boolean stubs_always_before_branch; 2859 bfd_boolean stub_changed; 2860 struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); 2861 2862 /* Stash our params away. */ 2863 htab->stub_bfd = stub_bfd; 2864 htab->multi_subspace = multi_subspace; 2865 htab->add_stub_section = add_stub_section; 2866 htab->layout_sections_again = layout_sections_again; 2867 stubs_always_before_branch = group_size < 0; 2868 if (group_size < 0) 2869 stub_group_size = -group_size; 2870 else 2871 stub_group_size = group_size; 2872 if (stub_group_size == 1) 2873 { 2874 /* Default values. */ 2875 if (stubs_always_before_branch) 2876 { 2877 stub_group_size = 7680000; 2878 if (htab->has_17bit_branch || htab->multi_subspace) 2879 stub_group_size = 240000; 2880 if (htab->has_12bit_branch) 2881 stub_group_size = 7500; 2882 } 2883 else 2884 { 2885 stub_group_size = 6971392; 2886 if (htab->has_17bit_branch || htab->multi_subspace) 2887 stub_group_size = 217856; 2888 if (htab->has_12bit_branch) 2889 stub_group_size = 6808; 2890 } 2891 } 2892 2893 group_sections (htab, stub_group_size, stubs_always_before_branch); 2894 2895 switch (get_local_syms (output_bfd, info->input_bfds, info)) 2896 { 2897 default: 2898 if (htab->all_local_syms) 2899 goto error_ret_free_local; 2900 return FALSE; 2901 2902 case 0: 2903 stub_changed = FALSE; 2904 break; 2905 2906 case 1: 2907 stub_changed = TRUE; 2908 break; 2909 } 2910 2820 2911 while (1) 2821 2912 { 2913 bfd *input_bfd; 2914 unsigned int bfd_indx; 2822 2915 asection *stub_sec; 2823 2916 … … 2827 2920 { 2828 2921 Elf_Internal_Shdr *symtab_hdr; 2922 asection *section; 2923 Elf_Internal_Sym *local_syms; 2829 2924 2830 2925 /* We'll need the symbol table in a second. */ … … 2833 2928 continue; 2834 2929 2835 local_syms = all_local_syms[bfd_indx];2930 local_syms = htab->all_local_syms[bfd_indx]; 2836 2931 2837 2932 /* Walk over each section attached to the input bfd. */ … … 2840 2935 section = section->next) 2841 2936 { 2842 Elf_Internal_Shdr *input_rel_hdr;2843 Elf32_External_Rela *external_relocs, *erelaend, *erela;2844 2937 Elf_Internal_Rela *internal_relocs, *irelaend, *irela; 2845 2938 … … 2856 2949 continue; 2857 2950 2858 /* Allocate space for the external relocations. */ 2859 external_relocs 2860 = ((Elf32_External_Rela *) 2861 bfd_malloc (section->reloc_count 2862 * sizeof (Elf32_External_Rela))); 2863 if (external_relocs == NULL) 2864 { 2865 goto error_ret_free_local; 2866 } 2867 2868 /* Likewise for the internal relocations. */ 2869 internal_relocs = ((Elf_Internal_Rela *) 2870 bfd_malloc (section->reloc_count 2871 * sizeof (Elf_Internal_Rela))); 2951 /* Get the relocs. */ 2952 internal_relocs 2953 = _bfd_elf32_link_read_relocs (input_bfd, section, NULL, 2954 (Elf_Internal_Rela *) NULL, 2955 info->keep_memory); 2872 2956 if (internal_relocs == NULL) 2873 { 2874 free (external_relocs); 2875 goto error_ret_free_local; 2876 } 2877 2878 /* Read in the external relocs. */ 2879 input_rel_hdr = &elf_section_data (section)->rel_hdr; 2880 if (bfd_seek (input_bfd, input_rel_hdr->sh_offset, SEEK_SET) != 0 2881 || bfd_read (external_relocs, 1, 2882 input_rel_hdr->sh_size, 2883 input_bfd) != input_rel_hdr->sh_size) 2884 { 2885 free (external_relocs); 2886 error_ret_free_internal: 2887 free (internal_relocs); 2888 goto error_ret_free_local; 2889 } 2890 2891 /* Swap in the relocs. */ 2892 erela = external_relocs; 2893 erelaend = erela + section->reloc_count; 2894 irela = internal_relocs; 2895 for (; erela < erelaend; erela++, irela++) 2896 bfd_elf32_swap_reloca_in (input_bfd, erela, irela); 2897 2898 /* We're done with the external relocs, free them. */ 2899 free (external_relocs); 2957 goto error_ret_free_local; 2900 2958 2901 2959 /* Now examine each relocation. */ … … 2920 2978 { 2921 2979 bfd_set_error (bfd_error_bad_value); 2922 goto error_ret_free_internal; 2980 error_ret_free_internal: 2981 if (elf_section_data (section)->relocs == NULL) 2982 free (internal_relocs); 2983 goto error_ret_free_local; 2923 2984 } 2924 2985 … … 2984 3045 && !info->no_undefined 2985 3046 && (ELF_ST_VISIBILITY (hash->elf.other) 2986 == STV_DEFAULT))) 3047 == STV_DEFAULT) 3048 && hash->elf.type != STT_PARISC_MILLI)) 2987 3049 continue; 2988 3050 } … … 3001 3063 3002 3064 /* Support for grouping stub sections. */ 3003 id_sec = h plink->stub_group[section->id].link_sec;3065 id_sec = htab->stub_group[section->id].link_sec; 3004 3066 3005 3067 /* Get the name of this stub. */ … … 3008 3070 goto error_ret_free_internal; 3009 3071 3010 stub_entry = hppa_stub_hash_lookup (&h plink->stub_hash_table,3072 stub_entry = hppa_stub_hash_lookup (&htab->stub_hash_table, 3011 3073 stub_name, 3012 false, false);3074 FALSE, FALSE); 3013 3075 if (stub_entry != NULL) 3014 3076 { … … 3018 3080 } 3019 3081 3020 stub_entry = hppa_add_stub (stub_name, section, h plink);3082 stub_entry = hppa_add_stub (stub_name, section, htab); 3021 3083 if (stub_entry == NULL) 3022 3084 { 3023 3085 free (stub_name); 3024 goto error_ret_free_ local;3086 goto error_ret_free_internal; 3025 3087 } 3026 3088 … … 3032 3094 if (stub_type == hppa_stub_import) 3033 3095 stub_entry->stub_type = hppa_stub_import_shared; 3034 else if (stub_type == hppa_stub_long_branch 3035 && (LONG_BRANCH_PIC_IN_SHLIB || hash == NULL)) 3096 else if (stub_type == hppa_stub_long_branch) 3036 3097 stub_entry->stub_type = hppa_stub_long_branch_shared; 3037 3098 } 3038 3099 stub_entry->h = hash; 3039 stub_changed = 1;3100 stub_changed = TRUE; 3040 3101 } 3041 3102 3042 3103 /* We're done with the internal relocs, free them. */ 3043 free (internal_relocs); 3104 if (elf_section_data (section)->relocs == NULL) 3105 free (internal_relocs); 3044 3106 } 3045 3107 } … … 3050 3112 /* OK, we've added some stubs. Find out the new size of the 3051 3113 stub sections. */ 3052 for (stub_sec = h plink->stub_bfd->sections;3114 for (stub_sec = htab->stub_bfd->sections; 3053 3115 stub_sec != NULL; 3054 3116 stub_sec = stub_sec->next) … … 3057 3119 stub_sec->_cooked_size = 0; 3058 3120 } 3059 #if ! LONG_BRANCH_PIC_IN_SHLIB 3060 { 3061 int i; 3062 3063 for (i = top_id; i >= 0; --i) 3064 { 3065 /* This will probably hit the same section many times.. */ 3066 stub_sec = hplink->stub_group[i].reloc_sec; 3067 if (stub_sec != NULL) 3068 { 3069 stub_sec->_raw_size = 0; 3070 stub_sec->_cooked_size = 0; 3071 } 3072 } 3073 } 3074 #endif 3075 3076 bfd_hash_traverse (&hplink->stub_hash_table, 3077 hppa_size_one_stub, 3078 hplink); 3121 3122 bfd_hash_traverse (&htab->stub_hash_table, hppa_size_one_stub, htab); 3079 3123 3080 3124 /* Ask the linker to do its stuff. */ 3081 (*hplink->layout_sections_again) (); 3082 stub_changed = 0; 3083 } 3084 3085 ret = 1; 3125 (*htab->layout_sections_again) (); 3126 stub_changed = FALSE; 3127 } 3128 3129 free (htab->all_local_syms); 3130 return TRUE; 3086 3131 3087 3132 error_ret_free_local: 3088 while (bfd_count-- > 0) 3089 if (all_local_syms[bfd_count]) 3090 free (all_local_syms[bfd_count]); 3091 free (all_local_syms); 3092 3093 return ret; 3133 free (htab->all_local_syms); 3134 return FALSE; 3094 3135 } 3095 3136 … … 3097 3138 stubs to provide a value for __gp. */ 3098 3139 3099 b oolean3140 bfd_boolean 3100 3141 elf32_hppa_set_gp (abfd, info) 3101 3142 bfd *abfd; 3102 3143 struct bfd_link_info *info; 3103 3144 { 3104 struct elf32_hppa_link_hash_table *hplink; 3105 struct elf_link_hash_entry *h; 3106 asection *sec; 3107 bfd_vma gp_val; 3108 3109 hplink = hppa_link_hash_table (info); 3110 h = elf_link_hash_lookup (&hplink->root, "$global$", 3111 false, false, false); 3145 struct bfd_link_hash_entry *h; 3146 asection *sec = NULL; 3147 bfd_vma gp_val = 0; 3148 struct elf32_hppa_link_hash_table *htab; 3149 3150 htab = hppa_link_hash_table (info); 3151 h = bfd_link_hash_lookup (&htab->elf.root, "$global$", FALSE, FALSE, FALSE); 3112 3152 3113 3153 if (h != NULL 3114 && (h-> root.type == bfd_link_hash_defined3115 || h-> root.type == bfd_link_hash_defweak))3116 { 3117 gp_val = h-> root.u.def.value;3118 sec = h-> root.u.def.section;3154 && (h->type == bfd_link_hash_defined 3155 || h->type == bfd_link_hash_defweak)) 3156 { 3157 gp_val = h->u.def.value; 3158 sec = h->u.def.section; 3119 3159 } 3120 3160 else 3121 3161 { 3162 asection *splt; 3163 asection *sgot; 3164 3165 if (htab->elf.root.creator->flavour == bfd_target_elf_flavour) 3166 { 3167 splt = htab->splt; 3168 sgot = htab->sgot; 3169 } 3170 else 3171 { 3172 /* If we're not elf, look up the output sections in the 3173 hope we may actually find them. */ 3174 splt = bfd_get_section_by_name (abfd, ".plt"); 3175 sgot = bfd_get_section_by_name (abfd, ".got"); 3176 } 3177 3122 3178 /* Choose to point our LTP at, in this order, one of .plt, .got, 3123 3179 or .data, if these sections exist. In the case of choosing … … 3128 3184 the .plt and .got are smaller than 0x2000, choose the end of 3129 3185 the .plt section. */ 3130 3131 sec = hplink->splt; 3186 sec = splt; 3132 3187 if (sec != NULL) 3133 3188 { 3134 3189 gp_val = sec->_raw_size; 3135 if (gp_val > 0x2000 3136 || (hplink->sgot && hplink->sgot->_raw_size > 0x2000)) 3190 if (gp_val > 0x2000 || (sgot && sgot->_raw_size > 0x2000)) 3137 3191 { 3138 3192 gp_val = 0x2000; … … 3141 3195 else 3142 3196 { 3143 gp_val = 0; 3144 sec = hplink->sgot; 3197 sec = sgot; 3145 3198 if (sec != NULL) 3146 3199 { … … 3159 3212 if (h != NULL) 3160 3213 { 3161 h-> root.type = bfd_link_hash_defined;3162 h-> root.u.def.value = gp_val;3214 h->type = bfd_link_hash_defined; 3215 h->u.def.value = gp_val; 3163 3216 if (sec != NULL) 3164 h-> root.u.def.section = sec;3217 h->u.def.section = sec; 3165 3218 else 3166 h-> root.u.def.section = bfd_abs_section_ptr;3219 h->u.def.section = bfd_abs_section_ptr; 3167 3220 } 3168 3221 } … … 3172 3225 3173 3226 elf_gp (abfd) = gp_val; 3174 return true;3227 return TRUE; 3175 3228 } 3176 3229 … … 3181 3234 linker. */ 3182 3235 3183 b oolean3236 bfd_boolean 3184 3237 elf32_hppa_build_stubs (info) 3185 3238 struct bfd_link_info *info; … … 3187 3240 asection *stub_sec; 3188 3241 struct bfd_hash_table *table; 3189 struct elf32_hppa_link_hash_table *h plink;3190 3191 h plink= hppa_link_hash_table (info);3192 3193 for (stub_sec = h plink->stub_bfd->sections;3242 struct elf32_hppa_link_hash_table *htab; 3243 3244 htab = hppa_link_hash_table (info); 3245 3246 for (stub_sec = htab->stub_bfd->sections; 3194 3247 stub_sec != NULL; 3195 3248 stub_sec = stub_sec->next) 3196 3249 { 3197 size_tsize;3250 bfd_size_type size; 3198 3251 3199 3252 /* Allocate memory to hold the linker stubs. */ 3200 3253 size = stub_sec->_raw_size; 3201 stub_sec->contents = (unsigned char *) bfd_zalloc (hplink->stub_bfd, 3202 size); 3254 stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, size); 3203 3255 if (stub_sec->contents == NULL && size != 0) 3204 return false;3256 return FALSE; 3205 3257 stub_sec->_raw_size = 0; 3206 3258 } 3207 3259 3208 3260 /* Build the stubs as directed by the stub hash table. */ 3209 table = &h plink->stub_hash_table;3261 table = &htab->stub_hash_table; 3210 3262 bfd_hash_traverse (table, hppa_build_one_stub, info); 3211 3263 3212 return true;3264 return TRUE; 3213 3265 } 3214 3266 3215 3267 /* Perform a final link. */ 3216 3268 3217 static b oolean3269 static bfd_boolean 3218 3270 elf32_hppa_final_link (abfd, info) 3219 3271 bfd *abfd; 3220 3272 struct bfd_link_info *info; 3221 3273 { 3222 asection *s;3223 3224 3274 /* Invoke the regular ELF linker to do all the work. */ 3225 3275 if (!bfd_elf32_bfd_final_link (abfd, info)) 3226 return false;3276 return FALSE; 3227 3277 3228 3278 /* If we're producing a final executable, sort the contents of the 3229 unwind section. Magic section names, but this is much safer than 3230 having elf32_hppa_relocate_section remember where SEGREL32 relocs 3231 occurred. Consider what happens if someone inept creates a 3232 linker script that puts unwind information in .text. */ 3233 s = bfd_get_section_by_name (abfd, ".PARISC.unwind"); 3234 if (s != NULL) 3235 { 3236 bfd_size_type size; 3237 char *contents; 3238 3239 size = s->_raw_size; 3240 contents = bfd_malloc (size); 3241 if (contents == NULL) 3242 return false; 3243 3244 if (! bfd_get_section_contents (abfd, s, contents, (file_ptr) 0, size)) 3245 return false; 3246 3247 qsort (contents, size / 16, 16, hppa_unwind_entry_compare); 3248 3249 if (! bfd_set_section_contents (abfd, s, contents, (file_ptr) 0, size)) 3250 return false; 3251 } 3252 return true; 3279 unwind section. */ 3280 return elf_hppa_sort_unwind (abfd); 3253 3281 } 3254 3282 … … 3261 3289 PTR data; 3262 3290 { 3263 struct elf32_hppa_link_hash_table *h plink;3264 3265 h plink= (struct elf32_hppa_link_hash_table *) data;3291 struct elf32_hppa_link_hash_table *htab; 3292 3293 htab = (struct elf32_hppa_link_hash_table *) data; 3266 3294 3267 3295 if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) … … 3271 3299 if ((section->flags & SEC_READONLY) != 0) 3272 3300 { 3273 if (value < h plink->text_segment_base)3274 h plink->text_segment_base = value;3301 if (value < htab->text_segment_base) 3302 htab->text_segment_base = value; 3275 3303 } 3276 3304 else 3277 3305 { 3278 if (value < h plink->data_segment_base)3279 h plink->data_segment_base = value;3306 if (value < htab->data_segment_base) 3307 htab->data_segment_base = value; 3280 3308 } 3281 3309 } … … 3285 3313 3286 3314 static bfd_reloc_status_type 3287 final_link_relocate (input_section, contents, rel, value, h plink, sym_sec, h)3315 final_link_relocate (input_section, contents, rel, value, htab, sym_sec, h) 3288 3316 asection *input_section; 3289 3317 bfd_byte *contents; 3290 3318 const Elf_Internal_Rela *rel; 3291 3319 bfd_vma value; 3292 struct elf32_hppa_link_hash_table *h plink;3320 struct elf32_hppa_link_hash_table *htab; 3293 3321 asection *sym_sec; 3294 3322 struct elf32_hppa_link_hash_entry *h; … … 3323 3351 case R_PARISC_PCREL17F: 3324 3352 case R_PARISC_PCREL22F: 3325 /* If this is a call to a function defined in another dynamic 3326 library, or if it is a call to a PIC function in the same 3327 object, or if this is a shared link and it is a call to a 3328 weak symbol which may or may not be in the same object, then 3329 find the import stub in the stub hash. */ 3353 /* If this call should go via the plt, find the import stub in 3354 the stub hash. */ 3330 3355 if (sym_sec == NULL 3331 3356 || sym_sec->output_section == NULL 3332 3357 || (h != NULL 3333 && ((h->maybe_pic_call 3334 && !(input_section->flags & SEC_HAS_GOT_REF)) 3335 || (h->elf.root.type == bfd_link_hash_defweak 3336 && h->elf.dynindx != -1 3337 && h->elf.plt.offset != (bfd_vma) -1)))) 3358 && h->elf.plt.offset != (bfd_vma) -1 3359 && (h->elf.dynindx != -1 || h->pic_call) 3360 && !h->plabel)) 3338 3361 { 3339 3362 stub_entry = hppa_get_stub_entry (input_section, sym_sec, 3340 h, rel, h plink);3363 h, rel, htab); 3341 3364 if (stub_entry != NULL) 3342 3365 { … … 3358 3381 } 3359 3382 else 3360 return bfd_reloc_ notsupported;3383 return bfd_reloc_undefined; 3361 3384 } 3362 3385 /* Fall thru. */ … … 3376 3399 case R_PARISC_DPREL14F: 3377 3400 /* For all the DP relative relocations, we need to examine the symbol's 3378 section. If it's a code section, then "data pointer relative" makes 3379 no sense. In that case we don't adjust the "value", and for 21 bit 3380 addil instructions, we change the source addend register from %dp to 3381 %r0. This situation commonly arises when a variable's "constness" 3401 section. If it has no section or if it's a code section, then 3402 "data pointer relative" makes no sense. In that case we don't 3403 adjust the "value", and for 21 bit addil instructions, we change the 3404 source addend register from %dp to %r0. This situation commonly 3405 arises for undefined weak symbols and when a variable's "constness" 3382 3406 is declared differently from the way the variable is defined. For 3383 3407 instance: "extern int foo" with foo defined as "const int foo". */ 3384 if (sym_sec == NULL) 3385 break; 3386 if ((sym_sec->flags & SEC_CODE) != 0) 3408 if (sym_sec == NULL || (sym_sec->flags & SEC_CODE) != 0) 3387 3409 { 3388 3410 if ((insn & ((0x3f << 26) | (0x1f << 21))) … … 3390 3412 { 3391 3413 insn &= ~ (0x1f << 21); 3392 #if 1/* debug them. */3414 #if 0 /* debug them. */ 3393 3415 (*_bfd_error_handler) 3394 3416 (_("%s(%s+0x%lx): fixing %s"), 3395 bfd_ get_filename (input_bfd),3417 bfd_archive_filename (input_bfd), 3396 3418 input_section->name, 3397 3419 (long) rel->r_offset, … … 3413 3435 case R_PARISC_SEGREL32: 3414 3436 if ((sym_sec->flags & SEC_CODE) != 0) 3415 value -= h plink->text_segment_base;3437 value -= htab->text_segment_base; 3416 3438 else 3417 value -= h plink->data_segment_base;3439 value -= htab->data_segment_base; 3418 3440 break; 3419 3441 … … 3437 3459 break; 3438 3460 3461 case R_PARISC_DLTIND21L: 3462 case R_PARISC_PCREL21L: 3463 case R_PARISC_PLABEL21L: 3464 r_field = e_lsel; 3465 break; 3466 3439 3467 case R_PARISC_DIR21L: 3440 case R_PARISC_PCREL21L:3441 3468 case R_PARISC_DPREL21L: 3442 case R_PARISC_PLABEL21L:3443 case R_PARISC_DLTIND21L:3444 3469 r_field = e_lrsel; 3445 3470 break; 3446 3471 3447 case R_PARISC_DIR17R:3448 3472 case R_PARISC_PCREL17R: 3449 case R_PARISC_DIR14R:3450 3473 case R_PARISC_PCREL14R: 3451 case R_PARISC_DPREL14R:3452 3474 case R_PARISC_PLABEL14R: 3453 3475 case R_PARISC_DLTIND14R: 3476 r_field = e_rsel; 3477 break; 3478 3479 case R_PARISC_DIR17R: 3480 case R_PARISC_DIR14R: 3481 case R_PARISC_DPREL14R: 3454 3482 r_field = e_rrsel; 3455 3483 break; … … 3484 3512 { 3485 3513 stub_entry = hppa_get_stub_entry (input_section, sym_sec, 3486 h, rel, h plink);3514 h, rel, htab); 3487 3515 if (stub_entry == NULL) 3488 return bfd_reloc_ notsupported;3516 return bfd_reloc_undefined; 3489 3517 3490 3518 /* Munge up the value and addend so that we call the stub … … 3509 3537 (*_bfd_error_handler) 3510 3538 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"), 3511 bfd_ get_filename (input_bfd),3539 bfd_archive_filename (input_bfd), 3512 3540 input_section->name, 3513 3541 (long) rel->r_offset, 3514 3542 stub_entry->root.string); 3543 bfd_set_error (bfd_error_bad_value); 3515 3544 return bfd_reloc_notsupported; 3516 3545 } … … 3547 3576 /* Relocate an HPPA ELF section. */ 3548 3577 3549 static b oolean3578 static bfd_boolean 3550 3579 elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section, 3551 3580 contents, relocs, local_syms, local_sections) … … 3559 3588 asection **local_sections; 3560 3589 { 3561 bfd *dynobj;3562 3590 bfd_vma *local_got_offsets; 3563 struct elf32_hppa_link_hash_table *h plink;3591 struct elf32_hppa_link_hash_table *htab; 3564 3592 Elf_Internal_Shdr *symtab_hdr; 3565 3593 Elf_Internal_Rela *rel; 3566 3594 Elf_Internal_Rela *relend; 3567 asection *sreloc; 3595 3596 if (info->relocateable) 3597 return TRUE; 3568 3598 3569 3599 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 3570 3600 3571 hplink = hppa_link_hash_table (info); 3572 dynobj = hplink->root.dynobj; 3601 htab = hppa_link_hash_table (info); 3573 3602 local_got_offsets = elf_local_got_offsets (input_bfd); 3574 sreloc = NULL;3575 3603 3576 3604 rel = relocs; … … 3587 3615 bfd_reloc_status_type r; 3588 3616 const char *sym_name; 3589 boolean plabel; 3617 bfd_boolean plabel; 3618 bfd_boolean warned_undef; 3590 3619 3591 3620 r_type = ELF32_R_TYPE (rel->r_info); … … 3593 3622 { 3594 3623 bfd_set_error (bfd_error_bad_value); 3595 return false;3624 return FALSE; 3596 3625 } 3597 3626 if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY … … 3599 3628 continue; 3600 3629 3630 /* This is a final link. */ 3601 3631 r_symndx = ELF32_R_SYM (rel->r_info); 3602 3603 if (info->relocateable)3604 {3605 /* This is a relocateable link. We don't have to change3606 anything, unless the reloc is against a section symbol,3607 in which case we have to adjust according to where the3608 section symbol winds up in the output section. */3609 if (r_symndx < symtab_hdr->sh_info)3610 {3611 sym = local_syms + r_symndx;3612 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)3613 {3614 sym_sec = local_sections[r_symndx];3615 rel->r_addend += sym_sec->output_offset;3616 }3617 }3618 continue;3619 }3620 3621 /* This is a final link. */3622 3632 h = NULL; 3623 3633 sym = NULL; 3624 3634 sym_sec = NULL; 3635 warned_undef = FALSE; 3625 3636 if (r_symndx < symtab_hdr->sh_info) 3626 3637 { … … 3628 3639 sym = local_syms + r_symndx; 3629 3640 sym_sec = local_sections[r_symndx]; 3630 relocation = ((ELF_ST_TYPE (sym->st_info) == STT_SECTION 3631 ? 0 : sym->st_value) 3632 + sym_sec->output_offset 3633 + sym_sec->output_section->vma); 3641 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sym_sec, rel); 3634 3642 } 3635 3643 else … … 3659 3667 else if (h->elf.root.type == bfd_link_hash_undefweak) 3660 3668 ; 3661 else if (info->shared && !info->no_undefined 3669 else if (info->shared 3670 && !info->no_undefined 3662 3671 && ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT 3663 3672 && h->elf.type != STT_PARISC_MILLI) 3664 { 3665 if (info->symbolic) 3666 if (!((*info->callbacks->undefined_symbol) 3667 (info, h->elf.root.root.string, input_bfd, 3668 input_section, rel->r_offset, false))) 3669 return false; 3670 } 3673 ; 3671 3674 else 3672 3675 { 3673 3676 if (!((*info->callbacks->undefined_symbol) 3674 3677 (info, h->elf.root.root.string, input_bfd, 3675 input_section, rel->r_offset, true))) 3676 return false; 3678 input_section, rel->r_offset, TRUE))) 3679 return FALSE; 3680 warned_undef = TRUE; 3677 3681 } 3678 3682 } … … 3687 3691 case R_PARISC_DLTIND14R: 3688 3692 case R_PARISC_DLTIND21L: 3689 /* Relocation is to the entry for this symbol in the global 3690 offset table. */ 3691 if (h != NULL) 3692 { 3693 bfd_vma off; 3694 boolean dyn; 3695 3696 off = h->elf.got.offset; 3697 if (off == (bfd_vma) -1) 3698 abort (); 3699 3700 dyn = hplink->root.dynamic_sections_created; 3701 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, &h->elf)) 3702 { 3703 /* This is actually a static link, or it is a 3704 -Bsymbolic link and the symbol is defined 3705 locally, or the symbol was forced to be local 3706 because of a version file. We must initialize 3707 this entry in the global offset table. Since the 3708 offset must always be a multiple of 4, we use the 3709 least significant bit to record whether we have 3710 initialized it already. 3711 3712 When doing a dynamic link, we create a .rela.got 3713 relocation entry to initialize the value. This 3714 is done in the finish_dynamic_symbol routine. */ 3715 if ((off & 1) != 0) 3716 off &= ~1; 3717 else 3718 { 3719 bfd_put_32 (output_bfd, relocation, 3720 hplink->sgot->contents + off); 3721 h->elf.got.offset |= 1; 3722 } 3723 } 3724 3725 relocation = off; 3726 } 3727 else 3728 { 3729 /* Local symbol case. */ 3730 bfd_vma off; 3731 3732 if (local_got_offsets == NULL 3733 || (off = local_got_offsets[r_symndx]) == (bfd_vma) -1) 3734 abort (); 3735 3736 /* The offset must always be a multiple of 4. We use 3737 the least significant bit to record whether we have 3738 already generated the necessary reloc. */ 3739 if ((off & 1) != 0) 3740 off &= ~1; 3741 else 3742 { 3693 { 3694 bfd_vma off; 3695 bfd_boolean do_got = 0; 3696 3697 /* Relocation is to the entry for this symbol in the 3698 global offset table. */ 3699 if (h != NULL) 3700 { 3701 bfd_boolean dyn; 3702 3703 off = h->elf.got.offset; 3704 dyn = htab->elf.dynamic_sections_created; 3705 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, &h->elf)) 3706 { 3707 /* If we aren't going to call finish_dynamic_symbol, 3708 then we need to handle initialisation of the .got 3709 entry and create needed relocs here. Since the 3710 offset must always be a multiple of 4, we use the 3711 least significant bit to record whether we have 3712 initialised it already. */ 3713 if ((off & 1) != 0) 3714 off &= ~1; 3715 else 3716 { 3717 h->elf.got.offset |= 1; 3718 do_got = 1; 3719 } 3720 } 3721 } 3722 else 3723 { 3724 /* Local symbol case. */ 3725 if (local_got_offsets == NULL) 3726 abort (); 3727 3728 off = local_got_offsets[r_symndx]; 3729 3730 /* The offset must always be a multiple of 4. We use 3731 the least significant bit to record whether we have 3732 already generated the necessary reloc. */ 3733 if ((off & 1) != 0) 3734 off &= ~1; 3735 else 3736 { 3737 local_got_offsets[r_symndx] |= 1; 3738 do_got = 1; 3739 } 3740 } 3741 3742 if (do_got) 3743 { 3744 if (info->shared) 3745 { 3746 /* Output a dynamic relocation for this GOT entry. 3747 In this case it is relative to the base of the 3748 object because the symbol index is zero. */ 3749 Elf_Internal_Rela outrel; 3750 bfd_byte *loc; 3751 asection *s = htab->srelgot; 3752 3753 outrel.r_offset = (off 3754 + htab->sgot->output_offset 3755 + htab->sgot->output_section->vma); 3756 outrel.r_info = ELF32_R_INFO (0, R_PARISC_DIR32); 3757 outrel.r_addend = relocation; 3758 loc = s->contents; 3759 loc += s->reloc_count++ * sizeof (Elf32_External_Rela); 3760 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 3761 } 3762 else 3743 3763 bfd_put_32 (output_bfd, relocation, 3744 hplink->sgot->contents + off); 3745 3746 if (info->shared) 3747 { 3748 /* Output a dynamic relocation for this GOT 3749 entry. In this case it is relative to the 3750 base of the object because the symbol index 3751 is zero. */ 3752 Elf_Internal_Rela outrel; 3753 asection *srelgot = hplink->srelgot; 3754 3755 outrel.r_offset = (off 3756 + hplink->sgot->output_offset 3757 + hplink->sgot->output_section->vma); 3758 outrel.r_info = ELF32_R_INFO (0, R_PARISC_DIR32); 3759 outrel.r_addend = relocation; 3760 bfd_elf32_swap_reloca_out (output_bfd, &outrel, 3761 ((Elf32_External_Rela *) 3762 srelgot->contents 3763 + srelgot->reloc_count)); 3764 ++srelgot->reloc_count; 3765 } 3766 3767 local_got_offsets[r_symndx] |= 1; 3768 } 3769 3770 relocation = off; 3771 } 3772 3773 /* Add the base of the GOT to the relocation value. */ 3774 relocation += (hplink->sgot->output_offset 3775 + hplink->sgot->output_section->vma); 3764 htab->sgot->contents + off); 3765 } 3766 3767 if (off >= (bfd_vma) -2) 3768 abort (); 3769 3770 /* Add the base of the GOT to the relocation value. */ 3771 relocation = (off 3772 + htab->sgot->output_offset 3773 + htab->sgot->output_section->vma); 3774 } 3776 3775 break; 3777 3776 … … 3779 3778 /* If this is the first SEGREL relocation, then initialize 3780 3779 the segment base values. */ 3781 if (hplink->text_segment_base == (bfd_vma) -1) 3782 bfd_map_over_sections (output_bfd, 3783 hppa_record_segment_addr, 3784 hplink); 3780 if (htab->text_segment_base == (bfd_vma) -1) 3781 bfd_map_over_sections (output_bfd, hppa_record_segment_addr, htab); 3785 3782 break; 3786 3783 … … 3788 3785 case R_PARISC_PLABEL21L: 3789 3786 case R_PARISC_PLABEL32: 3790 if (h plink->root.dynamic_sections_created)3787 if (htab->elf.dynamic_sections_created) 3791 3788 { 3792 3789 bfd_vma off; 3790 bfd_boolean do_plt = 0; 3793 3791 3794 3792 /* If we have a global symbol with a PLT slot, then … … 3801 3799 /* In a non-shared link, adjust_dynamic_symbols 3802 3800 isn't called for symbols forced local. We 3803 need to write out the plt entry here. */ 3801 need to write out the plt entry here. */ 3804 3802 if ((off & 1) != 0) 3805 3803 off &= ~1; 3806 3804 else 3807 3805 { 3808 bfd_put_32 (output_bfd,3809 relocation,3810 hplink->splt->contents + off);3811 bfd_put_32 (output_bfd,3812 elf_gp (hplink->splt->output_section->owner),3813 hplink->splt->contents + off + 4);3814 3806 h->elf.plt.offset |= 1; 3807 do_plt = 1; 3815 3808 } 3816 3809 } … … 3818 3811 else 3819 3812 { 3820 int indx; 3821 3822 indx = r_symndx + symtab_hdr->sh_info; 3823 off = local_got_offsets[indx]; 3813 bfd_vma *local_plt_offsets; 3814 3815 if (local_got_offsets == NULL) 3816 abort (); 3817 3818 local_plt_offsets = local_got_offsets + symtab_hdr->sh_info; 3819 off = local_plt_offsets[r_symndx]; 3824 3820 3825 3821 /* As for the local .got entry case, we use the last … … 3830 3826 else 3831 3827 { 3828 local_plt_offsets[r_symndx] |= 1; 3829 do_plt = 1; 3830 } 3831 } 3832 3833 if (do_plt) 3834 { 3835 if (info->shared) 3836 { 3837 /* Output a dynamic IPLT relocation for this 3838 PLT entry. */ 3839 Elf_Internal_Rela outrel; 3840 bfd_byte *loc; 3841 asection *s = htab->srelplt; 3842 3843 outrel.r_offset = (off 3844 + htab->splt->output_offset 3845 + htab->splt->output_section->vma); 3846 outrel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT); 3847 outrel.r_addend = relocation; 3848 loc = s->contents; 3849 loc += s->reloc_count++ * sizeof (Elf32_External_Rela); 3850 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 3851 } 3852 else 3853 { 3832 3854 bfd_put_32 (output_bfd, 3833 3855 relocation, 3834 h plink->splt->contents + off);3856 htab->splt->contents + off); 3835 3857 bfd_put_32 (output_bfd, 3836 elf_gp (hplink->splt->output_section->owner), 3837 hplink->splt->contents + off + 4); 3838 3839 if (info->shared) 3840 { 3841 /* Output a dynamic IPLT relocation for this 3842 PLT entry. */ 3843 Elf_Internal_Rela outrel; 3844 asection *srelplt = hplink->srelplt; 3845 3846 outrel.r_offset = (off 3847 + hplink->splt->output_offset 3848 + hplink->splt->output_section->vma); 3849 outrel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT); 3850 outrel.r_addend = relocation; 3851 bfd_elf32_swap_reloca_out (output_bfd, &outrel, 3852 ((Elf32_External_Rela *) 3853 srelplt->contents 3854 + srelplt->reloc_count)); 3855 ++srelplt->reloc_count; 3856 } 3857 3858 local_got_offsets[indx] |= 1; 3858 elf_gp (htab->splt->output_section->owner), 3859 htab->splt->contents + off + 4); 3859 3860 } 3860 3861 } 3861 3862 3862 if (off >= (bfd_vma) -2 || (off & 1) != 0)3863 if (off >= (bfd_vma) -2) 3863 3864 abort (); 3864 3865 … … 3874 3875 { 3875 3876 relocation = (off 3876 + h plink->splt->output_offset3877 + h plink->splt->output_section->vma3877 + htab->splt->output_offset 3878 + htab->splt->output_section->vma 3878 3879 + 2); 3879 3880 } … … 3891 3892 case R_PARISC_DPREL21L: 3892 3893 case R_PARISC_DIR32: 3894 /* r_symndx will be zero only for relocs against symbols 3895 from removed linkonce sections, or sections discarded by 3896 a linker script. */ 3897 if (r_symndx == 0 3898 || (input_section->flags & SEC_ALLOC) == 0) 3899 break; 3900 3893 3901 /* The reloc types handled here and this conditional 3894 expression must match the code in check_relocs and 3895 hppa_discard_copies. ie. We need exactly the same 3896 condition as in check_relocs, with some extra conditions 3897 (dynindx test in this case) to cater for relocs removed 3898 by hppa_discard_copies. */ 3899 if ((input_section->flags & SEC_ALLOC) != 0 3900 && info->shared 3901 #if RELATIVE_DYNAMIC_RELOCS 3902 && (is_absolute_reloc (r_type) 3903 || ((!info->symbolic 3904 || (h != NULL 3905 && ((h->elf.elf_link_hash_flags 3906 & ELF_LINK_HASH_DEF_REGULAR) == 0 3907 || h->elf.root.type == bfd_link_hash_defweak))) 3908 && (h == NULL || h->elf.dynindx != -1))) 3909 #endif 3910 ) 3902 expression must match the code in ..check_relocs and 3903 allocate_dynrelocs. ie. We need exactly the same condition 3904 as in ..check_relocs, with some extra conditions (dynindx 3905 test in this case) to cater for relocs removed by 3906 allocate_dynrelocs. If you squint, the non-shared test 3907 here does indeed match the one in ..check_relocs, the 3908 difference being that here we test DEF_DYNAMIC as well as 3909 !DEF_REGULAR. All common syms end up with !DEF_REGULAR, 3910 which is why we can't use just that test here. 3911 Conversely, DEF_DYNAMIC can't be used in check_relocs as 3912 there all files have not been loaded. */ 3913 if ((info->shared 3914 && (IS_ABSOLUTE_RELOC (r_type) 3915 || (h != NULL 3916 && h->elf.dynindx != -1 3917 && (!info->symbolic 3918 || (h->elf.elf_link_hash_flags 3919 & ELF_LINK_HASH_DEF_REGULAR) == 0)))) 3920 || (!info->shared 3921 && h != NULL 3922 && h->elf.dynindx != -1 3923 && (h->elf.elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 3924 && (((h->elf.elf_link_hash_flags 3925 & ELF_LINK_HASH_DEF_DYNAMIC) != 0 3926 && (h->elf.elf_link_hash_flags 3927 & ELF_LINK_HASH_DEF_REGULAR) == 0) 3928 || h->elf.root.type == bfd_link_hash_undefweak 3929 || h->elf.root.type == bfd_link_hash_undefined))) 3911 3930 { 3912 3931 Elf_Internal_Rela outrel; 3913 boolean skip; 3932 bfd_boolean skip; 3933 asection *sreloc; 3934 bfd_byte *loc; 3914 3935 3915 3936 /* When generating a shared object, these relocations … … 3917 3938 time. */ 3918 3939 3919 if (sreloc == NULL)3920 {3921 const char *name;3922 3923 name = (bfd_elf_string_from_elf_section3924 (input_bfd,3925 elf_elfheader (input_bfd)->e_shstrndx,3926 elf_section_data (input_section)->rel_hdr.sh_name));3927 if (name == NULL)3928 return false;3929 sreloc = bfd_get_section_by_name (dynobj, name);3930 if (sreloc == NULL)3931 abort ();3932 }3933 3934 outrel.r_offset = rel->r_offset;3935 3940 outrel.r_addend = rel->r_addend; 3936 skip = false; 3937 if (elf_section_data (input_section)->stab_info != NULL) 3938 { 3939 bfd_vma off; 3940 3941 off = (_bfd_stab_section_offset 3942 (output_bfd, &hplink->root.stab_info, 3943 input_section, 3944 &elf_section_data (input_section)->stab_info, 3945 rel->r_offset)); 3946 if (off == (bfd_vma) -1) 3947 skip = true; 3948 outrel.r_offset = off; 3949 } 3950 3941 outrel.r_offset = 3942 _bfd_elf_section_offset (output_bfd, info, input_section, 3943 rel->r_offset); 3944 skip = (outrel.r_offset == (bfd_vma) -1 3945 || outrel.r_offset == (bfd_vma) -2); 3951 3946 outrel.r_offset += (input_section->output_offset 3952 3947 + input_section->output_section->vma); … … 3959 3954 && h->elf.dynindx != -1 3960 3955 && (plabel 3956 || !IS_ABSOLUTE_RELOC (r_type) 3957 || !info->shared 3961 3958 || !info->symbolic 3962 3959 || (h->elf.elf_link_hash_flags … … 3993 3990 outrel.r_info = ELF32_R_INFO (indx, r_type); 3994 3991 } 3995 3996 bfd_elf32_swap_reloca_out (output_bfd, &outrel, 3997 ((Elf32_External_Rela *) 3998 sreloc->contents 3999 + sreloc->reloc_count)); 4000 ++sreloc->reloc_count; 3992 #if 0 3993 /* EH info can cause unaligned DIR32 relocs. 3994 Tweak the reloc type for the dynamic linker. */ 3995 if (r_type == R_PARISC_DIR32 && (outrel.r_offset & 3) != 0) 3996 outrel.r_info = ELF32_R_INFO (ELF32_R_SYM (outrel.r_info), 3997 R_PARISC_DIR32U); 3998 #endif 3999 sreloc = elf_section_data (input_section)->sreloc; 4000 if (sreloc == NULL) 4001 abort (); 4002 4003 loc = sreloc->contents; 4004 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); 4005 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 4001 4006 } 4002 4007 break; … … 4007 4012 4008 4013 r = final_link_relocate (input_section, contents, rel, relocation, 4009 h plink, sym_sec, h);4014 htab, sym_sec, h); 4010 4015 4011 4016 if (r == bfd_reloc_ok) … … 4020 4025 sym->st_name); 4021 4026 if (sym_name == NULL) 4022 return false;4027 return FALSE; 4023 4028 if (*sym_name == '\0') 4024 4029 sym_name = bfd_section_name (input_bfd, sym_sec); … … 4029 4034 if (r == bfd_reloc_undefined || r == bfd_reloc_notsupported) 4030 4035 { 4031 (*_bfd_error_handler) 4032 (_("%s(%s+0x%lx): cannot handle %s for %s"), 4033 bfd_get_filename (input_bfd), 4034 input_section->name, 4035 (long) rel->r_offset, 4036 howto->name, 4037 sym_name); 4036 if (r == bfd_reloc_notsupported || !warned_undef) 4037 { 4038 (*_bfd_error_handler) 4039 (_("%s(%s+0x%lx): cannot handle %s for %s"), 4040 bfd_archive_filename (input_bfd), 4041 input_section->name, 4042 (long) rel->r_offset, 4043 howto->name, 4044 sym_name); 4045 bfd_set_error (bfd_error_bad_value); 4046 return FALSE; 4047 } 4038 4048 } 4039 4049 else … … 4042 4052 (info, sym_name, howto->name, (bfd_vma) 0, 4043 4053 input_bfd, input_section, rel->r_offset))) 4044 return false; 4045 } 4046 } 4047 4048 return true; 4049 } 4050 4051 /* Comparison function for qsort to sort unwind section during a 4052 final link. */ 4053 4054 static int 4055 hppa_unwind_entry_compare (a, b) 4056 const PTR a; 4057 const PTR b; 4058 { 4059 const bfd_byte *ap, *bp; 4060 unsigned long av, bv; 4061 4062 ap = (const bfd_byte *) a; 4063 av = (unsigned long) ap[0] << 24; 4064 av |= (unsigned long) ap[1] << 16; 4065 av |= (unsigned long) ap[2] << 8; 4066 av |= (unsigned long) ap[3]; 4067 4068 bp = (const bfd_byte *) b; 4069 bv = (unsigned long) bp[0] << 24; 4070 bv |= (unsigned long) bp[1] << 16; 4071 bv |= (unsigned long) bp[2] << 8; 4072 bv |= (unsigned long) bp[3]; 4073 4074 return av < bv ? -1 : av > bv ? 1 : 0; 4054 return FALSE; 4055 } 4056 } 4057 4058 return TRUE; 4075 4059 } 4076 4060 … … 4078 4062 dynamic sections here. */ 4079 4063 4080 static b oolean4064 static bfd_boolean 4081 4065 elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym) 4082 4066 bfd *output_bfd; … … 4085 4069 Elf_Internal_Sym *sym; 4086 4070 { 4087 struct elf32_hppa_link_hash_table *hplink; 4088 bfd *dynobj; 4089 4090 hplink = hppa_link_hash_table (info); 4091 dynobj = hplink->root.dynobj; 4071 struct elf32_hppa_link_hash_table *htab; 4072 4073 htab = hppa_link_hash_table (info); 4092 4074 4093 4075 if (h->plt.offset != (bfd_vma) -1) … … 4118 4100 { 4119 4101 Elf_Internal_Rela rel; 4102 bfd_byte *loc; 4120 4103 4121 4104 /* Create a dynamic IPLT relocation for this entry. */ 4122 4105 rel.r_offset = (h->plt.offset 4123 + hplink->splt->output_offset 4124 + hplink->splt->output_section->vma); 4125 if (! ((struct elf32_hppa_link_hash_entry *) h)->plt_abs 4126 && h->dynindx != -1) 4106 + htab->splt->output_offset 4107 + htab->splt->output_section->vma); 4108 if (h->dynindx != -1) 4127 4109 { 4128 /* To support lazy linking, the function pointer is4129 initialised to point to a special stub stored at the4130 end of the .plt. This is not done for plt entries4131 with a base-relative dynamic relocation. */4132 value = (hplink->splt->output_offset4133 + hplink->splt->output_section->vma4134 + hplink->splt->_raw_size4135 - sizeof (plt_stub)4136 + PLT_STUB_ENTRY);4137 4110 rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_IPLT); 4138 4111 rel.r_addend = 0; … … 4146 4119 } 4147 4120 4148 bfd_elf32_swap_reloca_out (hplink->splt->output_section->owner, 4149 &rel, 4150 ((Elf32_External_Rela *) 4151 hplink->srelplt->contents 4152 + hplink->srelplt->reloc_count)); 4153 hplink->srelplt->reloc_count++; 4154 } 4155 4156 bfd_put_32 (hplink->splt->owner, 4157 value, 4158 hplink->splt->contents + h->plt.offset); 4159 bfd_put_32 (hplink->splt->owner, 4160 elf_gp (hplink->splt->output_section->owner), 4161 hplink->splt->contents + h->plt.offset + 4); 4162 if (PLABEL_PLT_ENTRY_SIZE != PLT_ENTRY_SIZE 4163 && ((struct elf32_hppa_link_hash_entry *) h)->plabel 4164 && h->dynindx != -1) 4165 { 4166 memset (hplink->splt->contents + h->plt.offset + 8, 4167 0, PLABEL_PLT_ENTRY_SIZE - PLT_ENTRY_SIZE); 4121 loc = htab->srelplt->contents; 4122 loc += htab->srelplt->reloc_count++ * sizeof (Elf32_External_Rela); 4123 bfd_elf32_swap_reloca_out (htab->splt->output_section->owner, 4124 &rel, loc); 4125 } 4126 else 4127 { 4128 bfd_put_32 (htab->splt->owner, 4129 value, 4130 htab->splt->contents + h->plt.offset); 4131 bfd_put_32 (htab->splt->owner, 4132 elf_gp (htab->splt->output_section->owner), 4133 htab->splt->contents + h->plt.offset + 4); 4168 4134 } 4169 4135 … … 4179 4145 { 4180 4146 Elf_Internal_Rela rel; 4147 bfd_byte *loc; 4181 4148 4182 4149 /* This symbol has an entry in the global offset table. Set it … … 4184 4151 4185 4152 rel.r_offset = ((h->got.offset &~ (bfd_vma) 1) 4186 + h plink->sgot->output_offset4187 + h plink->sgot->output_section->vma);4153 + htab->sgot->output_offset 4154 + htab->sgot->output_section->vma); 4188 4155 4189 4156 /* If this is a -Bsymbolic link and the symbol is defined … … 4206 4173 abort (); 4207 4174 bfd_put_32 (output_bfd, (bfd_vma) 0, 4208 h plink->sgot->contents + h->got.offset);4175 htab->sgot->contents + h->got.offset); 4209 4176 rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_DIR32); 4210 4177 rel.r_addend = 0; 4211 4178 } 4212 4179 4213 bfd_elf32_swap_reloca_out (output_bfd, &rel, 4214 ((Elf32_External_Rela *) 4215 hplink->srelgot->contents 4216 + hplink->srelgot->reloc_count)); 4217 ++hplink->srelgot->reloc_count; 4180 loc = htab->srelgot->contents; 4181 loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela); 4182 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc); 4218 4183 } 4219 4184 … … 4222 4187 asection *s; 4223 4188 Elf_Internal_Rela rel; 4189 bfd_byte *loc; 4224 4190 4225 4191 /* This symbol needs a copy reloc. Set it up. */ … … 4230 4196 abort (); 4231 4197 4232 s = h plink->srelbss;4198 s = htab->srelbss; 4233 4199 4234 4200 rel.r_offset = (h->root.u.def.value … … 4237 4203 rel.r_addend = 0; 4238 4204 rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_COPY); 4239 bfd_elf32_swap_reloca_out (output_bfd, &rel, 4240 ((Elf32_External_Rela *) s->contents 4241 + s->reloc_count)); 4242 ++s->reloc_count; 4205 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); 4206 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc); 4243 4207 } 4244 4208 … … 4251 4215 } 4252 4216 4253 return true;4217 return TRUE; 4254 4218 } 4255 4219 4220 /* Used to decide how to sort relocs in an optimal manner for the 4221 dynamic linker, before writing them out. */ 4222 4223 static enum elf_reloc_type_class 4224 elf32_hppa_reloc_type_class (rela) 4225 const Elf_Internal_Rela *rela; 4226 { 4227 if (ELF32_R_SYM (rela->r_info) == 0) 4228 return reloc_class_relative; 4229 4230 switch ((int) ELF32_R_TYPE (rela->r_info)) 4231 { 4232 case R_PARISC_IPLT: 4233 return reloc_class_plt; 4234 case R_PARISC_COPY: 4235 return reloc_class_copy; 4236 default: 4237 return reloc_class_normal; 4238 } 4239 } 4240 4256 4241 /* Finish up the dynamic sections. */ 4257 4242 4258 static b oolean4243 static bfd_boolean 4259 4244 elf32_hppa_finish_dynamic_sections (output_bfd, info) 4260 4245 bfd *output_bfd; … … 4262 4247 { 4263 4248 bfd *dynobj; 4264 struct elf32_hppa_link_hash_table *h plink;4249 struct elf32_hppa_link_hash_table *htab; 4265 4250 asection *sdyn; 4266 4251 4267 h plink= hppa_link_hash_table (info);4268 dynobj = h plink->root.dynobj;4252 htab = hppa_link_hash_table (info); 4253 dynobj = htab->elf.dynobj; 4269 4254 4270 4255 sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); 4271 4256 4272 if (h plink->root.dynamic_sections_created)4257 if (htab->elf.dynamic_sections_created) 4273 4258 { 4274 4259 Elf32_External_Dyn *dyncon, *dynconend; … … 4289 4274 { 4290 4275 default: 4291 break;4276 continue; 4292 4277 4293 4278 case DT_PLTGOT: 4294 4279 /* Use PLTGOT to set the GOT register. */ 4295 4280 dyn.d_un.d_ptr = elf_gp (output_bfd); 4296 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);4297 4281 break; 4298 4282 4299 4283 case DT_JMPREL: 4300 s = h plink->srelplt;4284 s = htab->srelplt; 4301 4285 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 4302 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);4303 4286 break; 4304 4287 4305 4288 case DT_PLTRELSZ: 4306 s = hplink->srelplt; 4307 if (s->_cooked_size != 0) 4308 dyn.d_un.d_val = s->_cooked_size; 4309 else 4310 dyn.d_un.d_val = s->_raw_size; 4311 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 4289 s = htab->srelplt; 4290 dyn.d_un.d_val = s->_raw_size; 4291 break; 4292 4293 case DT_RELASZ: 4294 /* Don't count procedure linkage table relocs in the 4295 overall reloc count. */ 4296 s = htab->srelplt; 4297 if (s == NULL) 4298 continue; 4299 dyn.d_un.d_val -= s->_raw_size; 4300 break; 4301 4302 case DT_RELA: 4303 /* We may not be using the standard ELF linker script. 4304 If .rela.plt is the first .rela section, we adjust 4305 DT_RELA to not include it. */ 4306 s = htab->srelplt; 4307 if (s == NULL) 4308 continue; 4309 if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) 4310 continue; 4311 dyn.d_un.d_ptr += s->_raw_size; 4312 4312 break; 4313 4313 } 4314 } 4315 } 4316 4317 if (hplink->sgot->_raw_size != 0) 4314 4315 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 4316 } 4317 } 4318 4319 if (htab->sgot != NULL && htab->sgot->_raw_size != 0) 4318 4320 { 4319 4321 /* Fill in the first entry in the global offset table. … … 4323 4325 ? sdyn->output_section->vma + sdyn->output_offset 4324 4326 : (bfd_vma) 0), 4325 h plink->sgot->contents);4327 htab->sgot->contents); 4326 4328 4327 4329 /* The second entry is reserved for use by the dynamic linker. */ 4328 memset (h plink->sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE);4330 memset (htab->sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE); 4329 4331 4330 4332 /* Set .got entry size. */ 4331 elf_section_data (h plink->sgot->output_section)4333 elf_section_data (htab->sgot->output_section) 4332 4334 ->this_hdr.sh_entsize = GOT_ENTRY_SIZE; 4333 4335 } 4334 4336 4335 if (h plink->splt->_raw_size != 0)4337 if (htab->splt != NULL && htab->splt->_raw_size != 0) 4336 4338 { 4337 4339 /* Set plt entry size. */ 4338 elf_section_data (h plink->splt->output_section)4340 elf_section_data (htab->splt->output_section) 4339 4341 ->this_hdr.sh_entsize = PLT_ENTRY_SIZE; 4340 4342 4341 if (h plink->need_plt_stub)4343 if (htab->need_plt_stub) 4342 4344 { 4343 4345 /* Set up the .plt stub. */ 4344 memcpy (h plink->splt->contents4345 + h plink->splt->_raw_size - sizeof (plt_stub),4346 memcpy (htab->splt->contents 4347 + htab->splt->_raw_size - sizeof (plt_stub), 4346 4348 plt_stub, sizeof (plt_stub)); 4347 4349 4348 if ((h plink->splt->output_offset4349 + h plink->splt->output_section->vma4350 + h plink->splt->_raw_size)4351 != (h plink->sgot->output_offset4352 + h plink->sgot->output_section->vma))4350 if ((htab->splt->output_offset 4351 + htab->splt->output_section->vma 4352 + htab->splt->_raw_size) 4353 != (htab->sgot->output_offset 4354 + htab->sgot->output_section->vma)) 4353 4355 { 4354 4356 (*_bfd_error_handler) 4355 4357 (_(".got section not immediately after .plt section")); 4356 return false;4358 return FALSE; 4357 4359 } 4358 4360 } 4359 4361 } 4360 4362 4361 return true;4363 return TRUE; 4362 4364 } 4363 4365 … … 4405 4407 #define bfd_elf32_bfd_final_link elf32_hppa_final_link 4406 4408 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create 4409 #define bfd_elf32_bfd_link_hash_table_free elf32_hppa_link_hash_table_free 4407 4410 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook 4408 4411 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol 4412 #define elf_backend_copy_indirect_symbol elf32_hppa_copy_indirect_symbol 4409 4413 #define elf_backend_check_relocs elf32_hppa_check_relocs 4410 4414 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections … … 4421 4425 #define elf_backend_post_process_headers elf32_hppa_post_process_headers 4422 4426 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type 4427 #define elf_backend_reloc_type_class elf32_hppa_reloc_type_class 4423 4428 4424 4429 #define elf_backend_can_gc_sections 1 4430 #define elf_backend_can_refcount 1 4425 4431 #define elf_backend_plt_alignment 2 4426 4432 #define elf_backend_want_got_plt 0 … … 4428 4434 #define elf_backend_want_plt_sym 0 4429 4435 #define elf_backend_got_header_size 8 4436 #define elf_backend_rela_normal 1 4430 4437 4431 4438 #define TARGET_BIG_SYM bfd_elf32_hppa_vec -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.