Deleted Added
full compact
elf32-ppc.c (272888) elf32-ppc.c (275718)
1/* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
5
6 This file is part of BFD, the Binary File Descriptor library.
7
8 This program is free software; you can redistribute it and/or modify

--- 732 unchanged lines hidden (view full) ---

741 complain_overflow_bitfield, /* complain_on_overflow */
742 ppc_elf_addr16_ha_reloc, /* special_function */
743 "R_PPC_SECTOFF_HA", /* name */
744 FALSE, /* partial_inplace */
745 0, /* src_mask */
746 0xffff, /* dst_mask */
747 FALSE), /* pcrel_offset */
748
1/* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
5
6 This file is part of BFD, the Binary File Descriptor library.
7
8 This program is free software; you can redistribute it and/or modify

--- 732 unchanged lines hidden (view full) ---

741 complain_overflow_bitfield, /* complain_on_overflow */
742 ppc_elf_addr16_ha_reloc, /* special_function */
743 "R_PPC_SECTOFF_HA", /* name */
744 FALSE, /* partial_inplace */
745 0, /* src_mask */
746 0xffff, /* dst_mask */
747 FALSE), /* pcrel_offset */
748
749 /* Marker reloc for TLS. */
749 /* Marker relocs for TLS. */
750 HOWTO (R_PPC_TLS,
751 0, /* rightshift */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
753 32, /* bitsize */
754 FALSE, /* pc_relative */
755 0, /* bitpos */
756 complain_overflow_dont, /* complain_on_overflow */
757 bfd_elf_generic_reloc, /* special_function */
758 "R_PPC_TLS", /* name */
759 FALSE, /* partial_inplace */
760 0, /* src_mask */
761 0, /* dst_mask */
762 FALSE), /* pcrel_offset */
763
750 HOWTO (R_PPC_TLS,
751 0, /* rightshift */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
753 32, /* bitsize */
754 FALSE, /* pc_relative */
755 0, /* bitpos */
756 complain_overflow_dont, /* complain_on_overflow */
757 bfd_elf_generic_reloc, /* special_function */
758 "R_PPC_TLS", /* name */
759 FALSE, /* partial_inplace */
760 0, /* src_mask */
761 0, /* dst_mask */
762 FALSE), /* pcrel_offset */
763
764 HOWTO (R_PPC_TLSGD,
765 0, /* rightshift */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
767 32, /* bitsize */
768 FALSE, /* pc_relative */
769 0, /* bitpos */
770 complain_overflow_dont, /* complain_on_overflow */
771 bfd_elf_generic_reloc, /* special_function */
772 "R_PPC_TLSGD", /* name */
773 FALSE, /* partial_inplace */
774 0, /* src_mask */
775 0, /* dst_mask */
776 FALSE), /* pcrel_offset */
777
778 HOWTO (R_PPC_TLSLD,
779 0, /* rightshift */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
781 32, /* bitsize */
782 FALSE, /* pc_relative */
783 0, /* bitpos */
784 complain_overflow_dont, /* complain_on_overflow */
785 bfd_elf_generic_reloc, /* special_function */
786 "R_PPC_TLSLD", /* name */
787 FALSE, /* partial_inplace */
788 0, /* src_mask */
789 0, /* dst_mask */
790 FALSE), /* pcrel_offset */
791
764 /* Computes the load module index of the load module that contains the
765 definition of its TLS sym. */
766 HOWTO (R_PPC_DTPMOD32,
767 0, /* rightshift */
768 2, /* size (0 = byte, 1 = short, 2 = long) */
769 32, /* bitsize */
770 FALSE, /* pc_relative */
771 0, /* bitpos */

--- 747 unchanged lines hidden (view full) ---

1519 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
1520 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
1521 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
1522 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
1523 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
1524 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
1525 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
1526 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
792 /* Computes the load module index of the load module that contains the
793 definition of its TLS sym. */
794 HOWTO (R_PPC_DTPMOD32,
795 0, /* rightshift */
796 2, /* size (0 = byte, 1 = short, 2 = long) */
797 32, /* bitsize */
798 FALSE, /* pc_relative */
799 0, /* bitpos */

--- 747 unchanged lines hidden (view full) ---

1547 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
1548 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
1549 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
1550 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
1551 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
1552 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
1553 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
1554 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
1555 case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break;
1556 case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break;
1527 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
1528 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
1529 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
1530 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
1531 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
1532 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
1533 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
1534 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;

--- 805 unchanged lines hidden (view full) ---

2340 bfd_signed_vma refcount;
2341 bfd_vma offset;
2342 } plt;
2343
2344 /* .glink stub offset. */
2345 bfd_vma glink_offset;
2346};
2347
1557 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
1558 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
1559 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
1560 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
1561 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
1562 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
1563 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
1564 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;

--- 805 unchanged lines hidden (view full) ---

2370 bfd_signed_vma refcount;
2371 bfd_vma offset;
2372 } plt;
2373
2374 /* .glink stub offset. */
2375 bfd_vma glink_offset;
2376};
2377
2348/* Of those relocs that might be copied as dynamic relocs, this macro
2378/* Of those relocs that might be copied as dynamic relocs, this function
2349 selects those that must be copied when linking a shared library,
2350 even when the symbol is local. */
2351
2379 selects those that must be copied when linking a shared library,
2380 even when the symbol is local. */
2381
2352#define MUST_BE_DYN_RELOC(RTYPE) \
2353 ((RTYPE) != R_PPC_REL24 \
2354 && (RTYPE) != R_PPC_REL14 \
2355 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2356 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2357 && (RTYPE) != R_PPC_REL32)
2382static int
2383must_be_dyn_reloc (struct bfd_link_info *info,
2384 enum elf_ppc_reloc_type r_type)
2385{
2386 switch (r_type)
2387 {
2388 default:
2389 return 1;
2358
2390
2391 case R_PPC_REL24:
2392 case R_PPC_REL14:
2393 case R_PPC_REL14_BRTAKEN:
2394 case R_PPC_REL14_BRNTAKEN:
2395 case R_PPC_REL32:
2396 return 0;
2397
2398 case R_PPC_TPREL32:
2399 case R_PPC_TPREL16:
2400 case R_PPC_TPREL16_LO:
2401 case R_PPC_TPREL16_HI:
2402 case R_PPC_TPREL16_HA:
2403 return !info->executable;
2404 }
2405}
2406
2359/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2360 copying dynamic variables from a shared lib into an app's dynbss
2361 section, and instead use a dynamic relocation to point into the
2362 shared lib. */
2363#define ELIMINATE_COPY_RELOCS 1
2364
2365/* PPC ELF linker hash entry. */
2366

--- 49 unchanged lines hidden (view full) ---

2416 asection *sbss;
2417
2418 /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
2419 asection *srelplt2;
2420
2421 /* The .got.plt section (VxWorks only)*/
2422 asection *sgotplt;
2423
2407/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2408 copying dynamic variables from a shared lib into an app's dynbss
2409 section, and instead use a dynamic relocation to point into the
2410 shared lib. */
2411#define ELIMINATE_COPY_RELOCS 1
2412
2413/* PPC ELF linker hash entry. */
2414

--- 49 unchanged lines hidden (view full) ---

2464 asection *sbss;
2465
2466 /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
2467 asection *srelplt2;
2468
2469 /* The .got.plt section (VxWorks only)*/
2470 asection *sgotplt;
2471
2424 /* Shortcut to .__tls_get_addr. */
2472 /* Shortcut to __tls_get_addr. */
2425 struct elf_link_hash_entry *tls_get_addr;
2426
2427 /* The bfd that forced an old-style PLT. */
2428 bfd *old_bfd;
2429
2430 /* TLS local dynamic got entry handling. */
2431 union {
2432 bfd_signed_vma refcount;

--- 602 unchanged lines hidden (view full) ---

3035 const Elf_Internal_Rela *relocs)
3036{
3037 struct ppc_elf_link_hash_table *htab;
3038 Elf_Internal_Shdr *symtab_hdr;
3039 struct elf_link_hash_entry **sym_hashes;
3040 const Elf_Internal_Rela *rel;
3041 const Elf_Internal_Rela *rel_end;
3042 asection *got2, *sreloc;
2473 struct elf_link_hash_entry *tls_get_addr;
2474
2475 /* The bfd that forced an old-style PLT. */
2476 bfd *old_bfd;
2477
2478 /* TLS local dynamic got entry handling. */
2479 union {
2480 bfd_signed_vma refcount;

--- 602 unchanged lines hidden (view full) ---

3083 const Elf_Internal_Rela *relocs)
3084{
3085 struct ppc_elf_link_hash_table *htab;
3086 Elf_Internal_Shdr *symtab_hdr;
3087 struct elf_link_hash_entry **sym_hashes;
3088 const Elf_Internal_Rela *rel;
3089 const Elf_Internal_Rela *rel_end;
3090 asection *got2, *sreloc;
3091 struct elf_link_hash_entry *tga;
3043
3044 if (info->relocatable)
3045 return TRUE;
3046
3047 /* Don't do anything special with non-loaded, non-alloced sections.
3048 In particular, any relocs in such sections should not affect GOT
3049 and PLT reference counting (ie. we don't allow them to create GOT
3050 or PLT entries), there's no possibility or desire to optimize TLS

--- 7 unchanged lines hidden (view full) ---

3058 sec, abfd);
3059#endif
3060
3061 /* Initialize howto table if not already done. */
3062 if (!ppc_elf_howto_table[R_PPC_ADDR32])
3063 ppc_elf_howto_init ();
3064
3065 htab = ppc_elf_hash_table (info);
3092
3093 if (info->relocatable)
3094 return TRUE;
3095
3096 /* Don't do anything special with non-loaded, non-alloced sections.
3097 In particular, any relocs in such sections should not affect GOT
3098 and PLT reference counting (ie. we don't allow them to create GOT
3099 or PLT entries), there's no possibility or desire to optimize TLS

--- 7 unchanged lines hidden (view full) ---

3107 sec, abfd);
3108#endif
3109
3110 /* Initialize howto table if not already done. */
3111 if (!ppc_elf_howto_table[R_PPC_ADDR32])
3112 ppc_elf_howto_init ();
3113
3114 htab = ppc_elf_hash_table (info);
3115 tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3116 FALSE, FALSE, TRUE);
3066 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3067 sym_hashes = elf_sym_hashes (abfd);
3068 got2 = bfd_get_section_by_name (abfd, ".got2");
3069 sreloc = NULL;
3070
3071 rel_end = relocs + sec->reloc_count;
3072 for (rel = relocs; rel < rel_end; rel++)
3073 {
3074 unsigned long r_symndx;
3075 enum elf_ppc_reloc_type r_type;
3076 struct elf_link_hash_entry *h;
3117 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3118 sym_hashes = elf_sym_hashes (abfd);
3119 got2 = bfd_get_section_by_name (abfd, ".got2");
3120 sreloc = NULL;
3121
3122 rel_end = relocs + sec->reloc_count;
3123 for (rel = relocs; rel < rel_end; rel++)
3124 {
3125 unsigned long r_symndx;
3126 enum elf_ppc_reloc_type r_type;
3127 struct elf_link_hash_entry *h;
3077 int tls_type = 0;
3128 int tls_type;
3078
3079 r_symndx = ELF32_R_SYM (rel->r_info);
3080 if (r_symndx < symtab_hdr->sh_info)
3081 h = NULL;
3082 else
3083 {
3084 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3085 while (h->root.type == bfd_link_hash_indirect

--- 10 unchanged lines hidden (view full) ---

3096 {
3097 if (htab->elf.dynobj == NULL)
3098 htab->elf.dynobj = abfd;
3099 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3100 return FALSE;
3101 BFD_ASSERT (h == htab->elf.hgot);
3102 }
3103
3129
3130 r_symndx = ELF32_R_SYM (rel->r_info);
3131 if (r_symndx < symtab_hdr->sh_info)
3132 h = NULL;
3133 else
3134 {
3135 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3136 while (h->root.type == bfd_link_hash_indirect

--- 10 unchanged lines hidden (view full) ---

3147 {
3148 if (htab->elf.dynobj == NULL)
3149 htab->elf.dynobj = abfd;
3150 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3151 return FALSE;
3152 BFD_ASSERT (h == htab->elf.hgot);
3153 }
3154
3155 tls_type = 0;
3104 r_type = ELF32_R_TYPE (rel->r_info);
3156 r_type = ELF32_R_TYPE (rel->r_info);
3157 if (h != NULL && h == tga)
3158 switch (r_type)
3159 {
3160 default:
3161 break;
3162
3163 case R_PPC_PLTREL24:
3164 case R_PPC_LOCAL24PC:
3165 case R_PPC_REL24:
3166 case R_PPC_REL14:
3167 case R_PPC_REL14_BRTAKEN:
3168 case R_PPC_REL14_BRNTAKEN:
3169 case R_PPC_ADDR24:
3170 case R_PPC_ADDR14:
3171 case R_PPC_ADDR14_BRTAKEN:
3172 case R_PPC_ADDR14_BRNTAKEN:
3173 if (rel != relocs
3174 && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD
3175 || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD))
3176 /* We have a new-style __tls_get_addr call with a marker
3177 reloc. */
3178 ;
3179 else
3180 /* Mark this section as having an old-style call. */
3181 sec->has_tls_get_addr_call = 1;
3182 break;
3183 }
3184
3105 switch (r_type)
3106 {
3185 switch (r_type)
3186 {
3187 case R_PPC_TLSGD:
3188 case R_PPC_TLSLD:
3189 /* These special tls relocs tie a call to __tls_get_addr with
3190 its parameter symbol. */
3191 break;
3192
3107 case R_PPC_GOT_TLSLD16:
3108 case R_PPC_GOT_TLSLD16_LO:
3109 case R_PPC_GOT_TLSLD16_HI:
3110 case R_PPC_GOT_TLSLD16_HA:
3193 case R_PPC_GOT_TLSLD16:
3194 case R_PPC_GOT_TLSLD16_LO:
3195 case R_PPC_GOT_TLSLD16_HI:
3196 case R_PPC_GOT_TLSLD16_HA:
3111 htab->tlsld_got.refcount += 1;
3112 tls_type = TLS_TLS | TLS_LD;
3113 goto dogottls;
3114
3115 case R_PPC_GOT_TLSGD16:
3116 case R_PPC_GOT_TLSGD16_LO:
3117 case R_PPC_GOT_TLSGD16_HI:
3118 case R_PPC_GOT_TLSGD16_HA:
3119 tls_type = TLS_TLS | TLS_GD;
3120 goto dogottls;
3121
3122 case R_PPC_GOT_TPREL16:
3123 case R_PPC_GOT_TPREL16_LO:
3124 case R_PPC_GOT_TPREL16_HI:
3125 case R_PPC_GOT_TPREL16_HA:
3197 tls_type = TLS_TLS | TLS_LD;
3198 goto dogottls;
3199
3200 case R_PPC_GOT_TLSGD16:
3201 case R_PPC_GOT_TLSGD16_LO:
3202 case R_PPC_GOT_TLSGD16_HI:
3203 case R_PPC_GOT_TLSGD16_HA:
3204 tls_type = TLS_TLS | TLS_GD;
3205 goto dogottls;
3206
3207 case R_PPC_GOT_TPREL16:
3208 case R_PPC_GOT_TPREL16_LO:
3209 case R_PPC_GOT_TPREL16_HI:
3210 case R_PPC_GOT_TPREL16_HA:
3126 if (info->shared)
3211 if (!info->executable)
3127 info->flags |= DF_STATIC_TLS;
3128 tls_type = TLS_TLS | TLS_TPREL;
3129 goto dogottls;
3130
3131 case R_PPC_GOT_DTPREL16:
3132 case R_PPC_GOT_DTPREL16_LO:
3133 case R_PPC_GOT_DTPREL16_HI:
3134 case R_PPC_GOT_DTPREL16_HA:

--- 218 unchanged lines hidden (view full) ---

3353 case R_PPC_EMB_RELST_LO:
3354 case R_PPC_EMB_RELST_HI:
3355 case R_PPC_EMB_RELST_HA:
3356 case R_PPC_EMB_BIT_FLD:
3357 break;
3358
3359 /* This refers only to functions defined in the shared library. */
3360 case R_PPC_LOCAL24PC:
3212 info->flags |= DF_STATIC_TLS;
3213 tls_type = TLS_TLS | TLS_TPREL;
3214 goto dogottls;
3215
3216 case R_PPC_GOT_DTPREL16:
3217 case R_PPC_GOT_DTPREL16_LO:
3218 case R_PPC_GOT_DTPREL16_HI:
3219 case R_PPC_GOT_DTPREL16_HA:

--- 218 unchanged lines hidden (view full) ---

3438 case R_PPC_EMB_RELST_LO:
3439 case R_PPC_EMB_RELST_HI:
3440 case R_PPC_EMB_RELST_HA:
3441 case R_PPC_EMB_BIT_FLD:
3442 break;
3443
3444 /* This refers only to functions defined in the shared library. */
3445 case R_PPC_LOCAL24PC:
3361 if (h && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
3446 if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
3362 {
3363 htab->plt_type = PLT_OLD;
3364 htab->old_bfd = abfd;
3365 }
3366 break;
3367
3368 /* This relocation describes the C++ object vtable hierarchy.
3369 Reconstruct it for later use during GC. */

--- 6 unchanged lines hidden (view full) ---

3376 used. Record for later use during GC. */
3377 case R_PPC_GNU_VTENTRY:
3378 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3379 return FALSE;
3380 break;
3381
3382 /* We shouldn't really be seeing these. */
3383 case R_PPC_TPREL32:
3447 {
3448 htab->plt_type = PLT_OLD;
3449 htab->old_bfd = abfd;
3450 }
3451 break;
3452
3453 /* This relocation describes the C++ object vtable hierarchy.
3454 Reconstruct it for later use during GC. */

--- 6 unchanged lines hidden (view full) ---

3461 used. Record for later use during GC. */
3462 case R_PPC_GNU_VTENTRY:
3463 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3464 return FALSE;
3465 break;
3466
3467 /* We shouldn't really be seeing these. */
3468 case R_PPC_TPREL32:
3384 if (info->shared)
3469 case R_PPC_TPREL16:
3470 case R_PPC_TPREL16_LO:
3471 case R_PPC_TPREL16_HI:
3472 case R_PPC_TPREL16_HA:
3473 if (!info->executable)
3385 info->flags |= DF_STATIC_TLS;
3386 goto dodyn;
3387
3388 /* Nor these. */
3389 case R_PPC_DTPMOD32:
3390 case R_PPC_DTPREL32:
3391 goto dodyn;
3392
3474 info->flags |= DF_STATIC_TLS;
3475 goto dodyn;
3476
3477 /* Nor these. */
3478 case R_PPC_DTPMOD32:
3479 case R_PPC_DTPREL32:
3480 goto dodyn;
3481
3393 case R_PPC_TPREL16:
3394 case R_PPC_TPREL16_LO:
3395 case R_PPC_TPREL16_HI:
3396 case R_PPC_TPREL16_HA:
3397 if (info->shared)
3398 info->flags |= DF_STATIC_TLS;
3399 goto dodyn;
3400
3401 case R_PPC_REL32:
3402 if (h == NULL
3403 && got2 != NULL
3404 && (sec->flags & SEC_CODE) != 0
3405 && (info->shared || info->pie)
3406 && htab->plt_type == PLT_UNSET)
3407 {
3408 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before

--- 74 unchanged lines hidden (view full) ---

3483 shared libraries and symbol visibility changes render the
3484 symbol local.
3485
3486 If on the other hand, we are creating an executable, we
3487 may need to keep relocations for symbols satisfied by a
3488 dynamic library if we manage to avoid copy relocs for the
3489 symbol. */
3490 if ((info->shared
3482 case R_PPC_REL32:
3483 if (h == NULL
3484 && got2 != NULL
3485 && (sec->flags & SEC_CODE) != 0
3486 && (info->shared || info->pie)
3487 && htab->plt_type == PLT_UNSET)
3488 {
3489 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before

--- 74 unchanged lines hidden (view full) ---

3564 shared libraries and symbol visibility changes render the
3565 symbol local.
3566
3567 If on the other hand, we are creating an executable, we
3568 may need to keep relocations for symbols satisfied by a
3569 dynamic library if we manage to avoid copy relocs for the
3570 symbol. */
3571 if ((info->shared
3491 && (MUST_BE_DYN_RELOC (r_type)
3572 && (must_be_dyn_reloc (info, r_type)
3492 || (h != NULL
3493 && (! info->symbolic
3494 || h->root.type == bfd_link_hash_defweak
3495 || !h->def_regular))))
3496 || (ELIMINATE_COPY_RELOCS
3497 && !info->shared
3498 && h != NULL
3499 && (h->root.type == bfd_link_hash_defweak

--- 78 unchanged lines hidden (view full) ---

3578 p->next = *head;
3579 *head = p;
3580 p->sec = sec;
3581 p->count = 0;
3582 p->pc_count = 0;
3583 }
3584
3585 p->count += 1;
3573 || (h != NULL
3574 && (! info->symbolic
3575 || h->root.type == bfd_link_hash_defweak
3576 || !h->def_regular))))
3577 || (ELIMINATE_COPY_RELOCS
3578 && !info->shared
3579 && h != NULL
3580 && (h->root.type == bfd_link_hash_defweak

--- 78 unchanged lines hidden (view full) ---

3659 p->next = *head;
3660 *head = p;
3661 p->sec = sec;
3662 p->count = 0;
3663 p->pc_count = 0;
3664 }
3665
3666 p->count += 1;
3586 if (!MUST_BE_DYN_RELOC (r_type))
3667 if (!must_be_dyn_reloc (info, r_type))
3587 p->pc_count += 1;
3588 }
3589
3590 break;
3591 }
3592 }
3593
3594 return TRUE;

--- 303 unchanged lines hidden (view full) ---

3898
3899 r_type = ELF32_R_TYPE (rel->r_info);
3900 switch (r_type)
3901 {
3902 case R_PPC_GOT_TLSLD16:
3903 case R_PPC_GOT_TLSLD16_LO:
3904 case R_PPC_GOT_TLSLD16_HI:
3905 case R_PPC_GOT_TLSLD16_HA:
3668 p->pc_count += 1;
3669 }
3670
3671 break;
3672 }
3673 }
3674
3675 return TRUE;

--- 303 unchanged lines hidden (view full) ---

3979
3980 r_type = ELF32_R_TYPE (rel->r_info);
3981 switch (r_type)
3982 {
3983 case R_PPC_GOT_TLSLD16:
3984 case R_PPC_GOT_TLSLD16_LO:
3985 case R_PPC_GOT_TLSLD16_HI:
3986 case R_PPC_GOT_TLSLD16_HA:
3906 htab->tlsld_got.refcount -= 1;
3907 /* Fall thru */
3908
3909 case R_PPC_GOT_TLSGD16:
3910 case R_PPC_GOT_TLSGD16_LO:
3911 case R_PPC_GOT_TLSGD16_HI:
3912 case R_PPC_GOT_TLSGD16_HA:
3913 case R_PPC_GOT_TPREL16:
3914 case R_PPC_GOT_TPREL16_LO:
3915 case R_PPC_GOT_TPREL16_HI:
3916 case R_PPC_GOT_TPREL16_HA:

--- 57 unchanged lines hidden (view full) ---

3974
3975 default:
3976 break;
3977 }
3978 }
3979 return TRUE;
3980}
3981
3987 case R_PPC_GOT_TLSGD16:
3988 case R_PPC_GOT_TLSGD16_LO:
3989 case R_PPC_GOT_TLSGD16_HI:
3990 case R_PPC_GOT_TLSGD16_HA:
3991 case R_PPC_GOT_TPREL16:
3992 case R_PPC_GOT_TPREL16_LO:
3993 case R_PPC_GOT_TPREL16_HI:
3994 case R_PPC_GOT_TPREL16_HA:

--- 57 unchanged lines hidden (view full) ---

4052
4053 default:
4054 break;
4055 }
4056 }
4057 return TRUE;
4058}
4059
3982/* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
4060/* Set plt output section type, htab->tls_get_addr, and call the
4061 generic ELF tls_setup function. */
3983
3984asection *
3985ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
3986{
3987 struct ppc_elf_link_hash_table *htab;
3988
3989 htab = ppc_elf_hash_table (info);
3990 if (htab->plt_type == PLT_NEW

--- 4 unchanged lines hidden (view full) ---

3995 elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
3996 }
3997
3998 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3999 FALSE, FALSE, TRUE);
4000 return _bfd_elf_tls_setup (obfd, info);
4001}
4002
4062
4063asection *
4064ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
4065{
4066 struct ppc_elf_link_hash_table *htab;
4067
4068 htab = ppc_elf_hash_table (info);
4069 if (htab->plt_type == PLT_NEW

--- 4 unchanged lines hidden (view full) ---

4074 elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
4075 }
4076
4077 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
4078 FALSE, FALSE, TRUE);
4079 return _bfd_elf_tls_setup (obfd, info);
4080}
4081
4082/* Return TRUE iff REL is a branch reloc with a global symbol matching
4083 HASH. */
4084
4085static bfd_boolean
4086branch_reloc_hash_match (const bfd *ibfd,
4087 const Elf_Internal_Rela *rel,
4088 const struct elf_link_hash_entry *hash)
4089{
4090 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4091 enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info);
4092 unsigned int r_symndx = ELF32_R_SYM (rel->r_info);
4093
4094 if (r_symndx >= symtab_hdr->sh_info
4095 && (r_type == R_PPC_PLTREL24
4096 || r_type == R_PPC_LOCAL24PC
4097 || r_type == R_PPC_REL14
4098 || r_type == R_PPC_REL14_BRTAKEN
4099 || r_type == R_PPC_REL14_BRNTAKEN
4100 || r_type == R_PPC_REL24
4101 || r_type == R_PPC_ADDR24
4102 || r_type == R_PPC_ADDR14
4103 || r_type == R_PPC_ADDR14_BRTAKEN
4104 || r_type == R_PPC_ADDR14_BRNTAKEN))
4105 {
4106 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
4107 struct elf_link_hash_entry *h;
4108
4109 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4110 while (h->root.type == bfd_link_hash_indirect
4111 || h->root.type == bfd_link_hash_warning)
4112 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4113 if (h == hash)
4114 return TRUE;
4115 }
4116 return FALSE;
4117}
4118
4003/* Run through all the TLS relocs looking for optimization
4004 opportunities. */
4005
4006bfd_boolean
4007ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
4008 struct bfd_link_info *info)
4009{
4010 bfd *ibfd;
4011 asection *sec;
4012 struct ppc_elf_link_hash_table *htab;
4119/* Run through all the TLS relocs looking for optimization
4120 opportunities. */
4121
4122bfd_boolean
4123ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
4124 struct bfd_link_info *info)
4125{
4126 bfd *ibfd;
4127 asection *sec;
4128 struct ppc_elf_link_hash_table *htab;
4129 int pass;
4013
4130
4014 if (info->relocatable || info->shared)
4131 if (info->relocatable || !info->executable)
4015 return TRUE;
4016
4017 htab = ppc_elf_hash_table (info);
4132 return TRUE;
4133
4134 htab = ppc_elf_hash_table (info);
4018 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4019 {
4020 Elf_Internal_Sym *locsyms = NULL;
4021 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4135 /* Make two passes through the relocs. First time check that tls
4136 relocs involved in setting up a tls_get_addr call are indeed
4137 followed by such a call. If they are not, exclude them from
4138 the optimizations done on the second pass. */
4139 for (pass = 0; pass < 2; ++pass)
4140 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4141 {
4142 Elf_Internal_Sym *locsyms = NULL;
4143 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4022
4144
4023 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
4024 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
4025 {
4026 Elf_Internal_Rela *relstart, *rel, *relend;
4027 int expecting_tls_get_addr;
4145 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
4146 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
4147 {
4148 Elf_Internal_Rela *relstart, *rel, *relend;
4028
4149
4029 /* Read the relocations. */
4030 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
4031 info->keep_memory);
4032 if (relstart == NULL)
4033 return FALSE;
4150 /* Read the relocations. */
4151 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
4152 info->keep_memory);
4153 if (relstart == NULL)
4154 return FALSE;
4034
4155
4035 expecting_tls_get_addr = 0;
4036 relend = relstart + sec->reloc_count;
4037 for (rel = relstart; rel < relend; rel++)
4038 {
4039 enum elf_ppc_reloc_type r_type;
4040 unsigned long r_symndx;
4041 struct elf_link_hash_entry *h = NULL;
4042 char *tls_mask;
4043 char tls_set, tls_clear;
4044 bfd_boolean is_local;
4156 relend = relstart + sec->reloc_count;
4157 for (rel = relstart; rel < relend; rel++)
4158 {
4159 enum elf_ppc_reloc_type r_type;
4160 unsigned long r_symndx;
4161 struct elf_link_hash_entry *h = NULL;
4162 char *tls_mask;
4163 char tls_set, tls_clear;
4164 bfd_boolean is_local;
4165 int expecting_tls_get_addr;
4166 bfd_signed_vma *got_count;
4045
4167
4046 r_symndx = ELF32_R_SYM (rel->r_info);
4047 if (r_symndx >= symtab_hdr->sh_info)
4048 {
4049 struct elf_link_hash_entry **sym_hashes;
4168 r_symndx = ELF32_R_SYM (rel->r_info);
4169 if (r_symndx >= symtab_hdr->sh_info)
4170 {
4171 struct elf_link_hash_entry **sym_hashes;
4050
4172
4051 sym_hashes = elf_sym_hashes (ibfd);
4052 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4053 while (h->root.type == bfd_link_hash_indirect
4054 || h->root.type == bfd_link_hash_warning)
4055 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4056 }
4173 sym_hashes = elf_sym_hashes (ibfd);
4174 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4175 while (h->root.type == bfd_link_hash_indirect
4176 || h->root.type == bfd_link_hash_warning)
4177 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4178 }
4057
4179
4058 is_local = FALSE;
4059 if (h == NULL
4060 || !h->def_dynamic)
4061 is_local = TRUE;
4180 expecting_tls_get_addr = 0;
4181 is_local = FALSE;
4182 if (h == NULL
4183 || !h->def_dynamic)
4184 is_local = TRUE;
4062
4185
4063 r_type = ELF32_R_TYPE (rel->r_info);
4064 switch (r_type)
4065 {
4066 case R_PPC_GOT_TLSLD16:
4067 case R_PPC_GOT_TLSLD16_LO:
4068 case R_PPC_GOT_TLSLD16_HI:
4069 case R_PPC_GOT_TLSLD16_HA:
4070 /* These relocs should never be against a symbol
4071 defined in a shared lib. Leave them alone if
4072 that turns out to be the case. */
4073 expecting_tls_get_addr = 0;
4074 htab->tlsld_got.refcount -= 1;
4075 if (!is_local)
4076 continue;
4186 r_type = ELF32_R_TYPE (rel->r_info);
4187 switch (r_type)
4188 {
4189 case R_PPC_GOT_TLSLD16:
4190 case R_PPC_GOT_TLSLD16_LO:
4191 expecting_tls_get_addr = 1;
4192 /* Fall thru */
4077
4193
4078 /* LD -> LE */
4079 tls_set = 0;
4080 tls_clear = TLS_LD;
4081 expecting_tls_get_addr = 1;
4082 break;
4194 case R_PPC_GOT_TLSLD16_HI:
4195 case R_PPC_GOT_TLSLD16_HA:
4196 /* These relocs should never be against a symbol
4197 defined in a shared lib. Leave them alone if
4198 that turns out to be the case. */
4199 if (!is_local)
4200 continue;
4083
4201
4084 case R_PPC_GOT_TLSGD16:
4085 case R_PPC_GOT_TLSGD16_LO:
4086 case R_PPC_GOT_TLSGD16_HI:
4087 case R_PPC_GOT_TLSGD16_HA:
4088 if (is_local)
4089 /* GD -> LE */
4202 /* LD -> LE */
4090 tls_set = 0;
4203 tls_set = 0;
4091 else
4092 /* GD -> IE */
4093 tls_set = TLS_TLS | TLS_TPRELGD;
4094 tls_clear = TLS_GD;
4095 expecting_tls_get_addr = 1;
4096 break;
4204 tls_clear = TLS_LD;
4205 break;
4097
4206
4098 case R_PPC_GOT_TPREL16:
4099 case R_PPC_GOT_TPREL16_LO:
4100 case R_PPC_GOT_TPREL16_HI:
4101 case R_PPC_GOT_TPREL16_HA:
4102 expecting_tls_get_addr = 0;
4103 if (is_local)
4104 {
4105 /* IE -> LE */
4207 case R_PPC_GOT_TLSGD16:
4208 case R_PPC_GOT_TLSGD16_LO:
4209 expecting_tls_get_addr = 1;
4210 /* Fall thru */
4211
4212 case R_PPC_GOT_TLSGD16_HI:
4213 case R_PPC_GOT_TLSGD16_HA:
4214 if (is_local)
4215 /* GD -> LE */
4106 tls_set = 0;
4216 tls_set = 0;
4107 tls_clear = TLS_TPREL;
4108 break;
4109 }
4110 else
4217 else
4218 /* GD -> IE */
4219 tls_set = TLS_TLS | TLS_TPRELGD;
4220 tls_clear = TLS_GD;
4221 break;
4222
4223 case R_PPC_GOT_TPREL16:
4224 case R_PPC_GOT_TPREL16_LO:
4225 case R_PPC_GOT_TPREL16_HI:
4226 case R_PPC_GOT_TPREL16_HA:
4227 if (is_local)
4228 {
4229 /* IE -> LE */
4230 tls_set = 0;
4231 tls_clear = TLS_TPREL;
4232 break;
4233 }
4234 else
4235 continue;
4236
4237 default:
4111 continue;
4238 continue;
4239 }
4112
4240
4113 case R_PPC_REL14:
4114 case R_PPC_REL14_BRTAKEN:
4115 case R_PPC_REL14_BRNTAKEN:
4116 case R_PPC_REL24:
4117 if (expecting_tls_get_addr
4118 && h != NULL
4119 && h == htab->tls_get_addr)
4120 {
4121 struct plt_entry *ent = find_plt_ent (h, NULL, 0);
4122 if (ent != NULL && ent->plt.refcount > 0)
4123 ent->plt.refcount -= 1;
4124 }
4125 expecting_tls_get_addr = 0;
4126 continue;
4241 if (pass == 0)
4242 {
4243 if (!expecting_tls_get_addr
4244 || !sec->has_tls_get_addr_call)
4245 continue;
4127
4246
4128 default:
4129 expecting_tls_get_addr = 0;
4130 continue;
4131 }
4247 if (rel + 1 < relend
4248 && branch_reloc_hash_match (ibfd, rel + 1,
4249 htab->tls_get_addr))
4250 continue;
4132
4251
4133 if (h != NULL)
4134 {
4135 if (tls_set == 0)
4136 {
4137 /* We managed to get rid of a got entry. */
4138 if (h->got.refcount > 0)
4139 h->got.refcount -= 1;
4140 }
4141 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
4142 }
4143 else
4144 {
4145 Elf_Internal_Sym *sym;
4146 bfd_signed_vma *lgot_refs;
4147 char *lgot_masks;
4252 /* Uh oh, we didn't find the expected call. We
4253 could just mark this symbol to exclude it
4254 from tls optimization but it's safer to skip
4255 the entire section. */
4256 sec->has_tls_reloc = 0;
4257 break;
4258 }
4148
4259
4149 if (locsyms == NULL)
4150 {
4151 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
4152 if (locsyms == NULL)
4153 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
4154 symtab_hdr->sh_info,
4155 0, NULL, NULL, NULL);
4156 if (locsyms == NULL)
4157 {
4158 if (elf_section_data (sec)->relocs != relstart)
4159 free (relstart);
4160 return FALSE;
4161 }
4162 }
4163 sym = locsyms + r_symndx;
4164 lgot_refs = elf_local_got_refcounts (ibfd);
4165 if (lgot_refs == NULL)
4166 abort ();
4167 if (tls_set == 0)
4168 {
4169 /* We managed to get rid of a got entry. */
4170 if (lgot_refs[r_symndx] > 0)
4171 lgot_refs[r_symndx] -= 1;
4172 }
4173 lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
4174 tls_mask = &lgot_masks[r_symndx];
4175 }
4260 if (h != NULL)
4261 {
4262 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
4263 got_count = &h->got.refcount;
4264 }
4265 else
4266 {
4267 Elf_Internal_Sym *sym;
4268 bfd_signed_vma *lgot_refs;
4269 char *lgot_masks;
4176
4270
4177 *tls_mask |= tls_set;
4178 *tls_mask &= ~tls_clear;
4179 }
4271 if (locsyms == NULL)
4272 {
4273 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
4274 if (locsyms == NULL)
4275 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
4276 symtab_hdr->sh_info,
4277 0, NULL, NULL, NULL);
4278 if (locsyms == NULL)
4279 {
4280 if (elf_section_data (sec)->relocs != relstart)
4281 free (relstart);
4282 return FALSE;
4283 }
4284 }
4285 sym = locsyms + r_symndx;
4286 lgot_refs = elf_local_got_refcounts (ibfd);
4287 if (lgot_refs == NULL)
4288 abort ();
4289 lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
4290 tls_mask = &lgot_masks[r_symndx];
4291 got_count = &lgot_refs[r_symndx];
4292 }
4180
4293
4181 if (elf_section_data (sec)->relocs != relstart)
4182 free (relstart);
4183 }
4294 if (tls_set == 0)
4295 {
4296 /* We managed to get rid of a got entry. */
4297 if (*got_count > 0)
4298 *got_count -= 1;
4299 }
4184
4300
4185 if (locsyms != NULL
4186 && (symtab_hdr->contents != (unsigned char *) locsyms))
4187 {
4188 if (!info->keep_memory)
4189 free (locsyms);
4190 else
4191 symtab_hdr->contents = (unsigned char *) locsyms;
4192 }
4193 }
4301 if (expecting_tls_get_addr)
4302 {
4303 struct plt_entry *ent;
4304
4305 ent = find_plt_ent (htab->tls_get_addr, NULL, 0);
4306 if (ent != NULL && ent->plt.refcount > 0)
4307 ent->plt.refcount -= 1;
4308 }
4309
4310 *tls_mask |= tls_set;
4311 *tls_mask &= ~tls_clear;
4312 }
4313
4314 if (elf_section_data (sec)->relocs != relstart)
4315 free (relstart);
4316 }
4317
4318 if (locsyms != NULL
4319 && (symtab_hdr->contents != (unsigned char *) locsyms))
4320 {
4321 if (!info->keep_memory)
4322 free (locsyms);
4323 else
4324 symtab_hdr->contents = (unsigned char *) locsyms;
4325 }
4326 }
4194 return TRUE;
4195}
4196
4197/* Adjust a symbol defined by a dynamic object and referenced by a
4198 regular object. The current definition is in some section of the
4199 dynamic object, but we're not including those sections. We have to
4200 change the definition to something the rest of the link can
4201 understand. */

--- 408 unchanged lines hidden (view full) ---

4610 && !eh->elf.forced_local)
4611 {
4612 if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
4613 return FALSE;
4614 }
4615
4616 if (eh->tls_mask == (TLS_TLS | TLS_LD)
4617 && !eh->elf.def_dynamic)
4327 return TRUE;
4328}
4329
4330/* Adjust a symbol defined by a dynamic object and referenced by a
4331 regular object. The current definition is in some section of the
4332 dynamic object, but we're not including those sections. We have to
4333 change the definition to something the rest of the link can
4334 understand. */

--- 408 unchanged lines hidden (view full) ---

4743 && !eh->elf.forced_local)
4744 {
4745 if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
4746 return FALSE;
4747 }
4748
4749 if (eh->tls_mask == (TLS_TLS | TLS_LD)
4750 && !eh->elf.def_dynamic)
4618 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
4619 eh->elf.got.offset = (bfd_vma) -1;
4751 {
4752 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
4753 htab->tlsld_got.refcount += 1;
4754 eh->elf.got.offset = (bfd_vma) -1;
4755 }
4620 else
4621 {
4622 bfd_boolean dyn;
4623 unsigned int need = 0;
4624 if ((eh->tls_mask & TLS_TLS) != 0)
4625 {
4626 if ((eh->tls_mask & TLS_LD) != 0)
4627 need += 8;

--- 31 unchanged lines hidden (view full) ---

4659 dynamic pc-relative relocs against symbols which turn out to be
4660 defined in regular objects. For the normal shared case, discard
4661 space for relocs that have become local due to symbol visibility
4662 changes. */
4663
4664 if (info->shared)
4665 {
4666 /* Relocs that use pc_count are those that appear on a call insn,
4756 else
4757 {
4758 bfd_boolean dyn;
4759 unsigned int need = 0;
4760 if ((eh->tls_mask & TLS_TLS) != 0)
4761 {
4762 if ((eh->tls_mask & TLS_LD) != 0)
4763 need += 8;

--- 31 unchanged lines hidden (view full) ---

4795 dynamic pc-relative relocs against symbols which turn out to be
4796 defined in regular objects. For the normal shared case, discard
4797 space for relocs that have become local due to symbol visibility
4798 changes. */
4799
4800 if (info->shared)
4801 {
4802 /* Relocs that use pc_count are those that appear on a call insn,
4667 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
4803 or certain REL relocs (see must_be_dyn_reloc) that can be
4668 generated via assembly. We want calls to protected symbols to
4669 resolve directly to the function rather than going via the plt.
4670 If people want function pointer comparisons to work as expected
4671 then they should avoid writing weird assembly. */
4672 if (SYMBOL_CALLS_LOCAL (info, h))
4673 {
4674 struct ppc_elf_dyn_relocs **pp;
4675

--- 210 unchanged lines hidden (view full) ---

4886 htab->relgot->size += (need
4887 * (sizeof (Elf32_External_Rela) / 4));
4888 }
4889 }
4890 else
4891 *local_got = (bfd_vma) -1;
4892 }
4893
4804 generated via assembly. We want calls to protected symbols to
4805 resolve directly to the function rather than going via the plt.
4806 If people want function pointer comparisons to work as expected
4807 then they should avoid writing weird assembly. */
4808 if (SYMBOL_CALLS_LOCAL (info, h))
4809 {
4810 struct ppc_elf_dyn_relocs **pp;
4811

--- 210 unchanged lines hidden (view full) ---

5022 htab->relgot->size += (need
5023 * (sizeof (Elf32_External_Rela) / 4));
5024 }
5025 }
5026 else
5027 *local_got = (bfd_vma) -1;
5028 }
5029
5030 /* Allocate space for global sym dynamic relocs. */
5031 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
5032
4894 if (htab->tlsld_got.refcount > 0)
4895 {
4896 htab->tlsld_got.offset = allocate_got (htab, 8);
4897 if (info->shared)
4898 htab->relgot->size += sizeof (Elf32_External_Rela);
4899 }
4900 else
4901 htab->tlsld_got.offset = (bfd_vma) -1;
4902
5033 if (htab->tlsld_got.refcount > 0)
5034 {
5035 htab->tlsld_got.offset = allocate_got (htab, 8);
5036 if (info->shared)
5037 htab->relgot->size += sizeof (Elf32_External_Rela);
5038 }
5039 else
5040 htab->tlsld_got.offset = (bfd_vma) -1;
5041
4903 /* Allocate space for global sym dynamic relocs. */
4904 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
4905
4906 if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
4907 {
4908 unsigned int g_o_t = 32768;
4909
4910 /* If we haven't allocated the header, do so now. When we get here,
4911 for old plt/got the got size will be 0 to 32764 (not allocated),
4912 or 32780 to 65536 (header allocated). For new plt/got, the
4913 corresponding ranges are 0 to 32768 and 32780 to 65536. */

--- 835 unchanged lines hidden (view full) ---

5749 }
5750
5751 /* TLS optimizations. Replace instruction sequences and relocs
5752 based on information we collected in tls_optimize. We edit
5753 RELOCS so that --emit-relocs will output something sensible
5754 for the final instruction stream. */
5755 tls_mask = 0;
5756 tls_gd = 0;
5042 if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
5043 {
5044 unsigned int g_o_t = 32768;
5045
5046 /* If we haven't allocated the header, do so now. When we get here,
5047 for old plt/got the got size will be 0 to 32764 (not allocated),
5048 or 32780 to 65536 (header allocated). For new plt/got, the
5049 corresponding ranges are 0 to 32768 and 32780 to 65536. */

--- 835 unchanged lines hidden (view full) ---

5885 }
5886
5887 /* TLS optimizations. Replace instruction sequences and relocs
5888 based on information we collected in tls_optimize. We edit
5889 RELOCS so that --emit-relocs will output something sensible
5890 for the final instruction stream. */
5891 tls_mask = 0;
5892 tls_gd = 0;
5757 if (IS_PPC_TLS_RELOC (r_type))
5893 if (h != NULL)
5894 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
5895 else if (local_got_offsets != NULL)
5758 {
5896 {
5759 if (h != NULL)
5760 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
5761 else if (local_got_offsets != NULL)
5762 {
5763 char *lgot_masks;
5764 lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
5765 tls_mask = lgot_masks[r_symndx];
5766 }
5897 char *lgot_masks;
5898 lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
5899 tls_mask = lgot_masks[r_symndx];
5767 }
5768
5769 /* Ensure reloc mapping code below stays sane. */
5770 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
5771 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
5772 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
5773 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
5774 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)

--- 90 unchanged lines hidden (view full) ---

5865 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5866 }
5867 break;
5868
5869 case R_PPC_GOT_TLSGD16:
5870 case R_PPC_GOT_TLSGD16_LO:
5871 tls_gd = TLS_TPRELGD;
5872 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
5900 }
5901
5902 /* Ensure reloc mapping code below stays sane. */
5903 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
5904 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
5905 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
5906 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
5907 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)

--- 90 unchanged lines hidden (view full) ---

5998 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5999 }
6000 break;
6001
6002 case R_PPC_GOT_TLSGD16:
6003 case R_PPC_GOT_TLSGD16_LO:
6004 tls_gd = TLS_TPRELGD;
6005 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
5873 goto tls_get_addr_check;
6006 goto tls_ldgd_opt;
5874 break;
5875
5876 case R_PPC_GOT_TLSLD16:
5877 case R_PPC_GOT_TLSLD16_LO:
5878 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
5879 {
6007 break;
6008
6009 case R_PPC_GOT_TLSLD16:
6010 case R_PPC_GOT_TLSLD16_LO:
6011 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
6012 {
5880 tls_get_addr_check:
5881 if (rel + 1 < relend)
5882 {
5883 enum elf_ppc_reloc_type r_type2;
5884 unsigned long r_symndx2;
5885 struct elf_link_hash_entry *h2;
5886 bfd_vma insn1, insn2;
5887 bfd_vma offset;
6013 unsigned int insn1, insn2;
6014 bfd_vma offset;
5888
6015
5889 /* The next instruction should be a call to
5890 __tls_get_addr. Peek at the reloc to be sure. */
5891 r_type2 = ELF32_R_TYPE (rel[1].r_info);
5892 r_symndx2 = ELF32_R_SYM (rel[1].r_info);
5893 if (r_symndx2 < symtab_hdr->sh_info
5894 || (r_type2 != R_PPC_REL14
5895 && r_type2 != R_PPC_REL14_BRTAKEN
5896 && r_type2 != R_PPC_REL14_BRNTAKEN
5897 && r_type2 != R_PPC_REL24
5898 && r_type2 != R_PPC_PLTREL24))
5899 break;
5900
5901 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
5902 while (h2->root.type == bfd_link_hash_indirect
5903 || h2->root.type == bfd_link_hash_warning)
5904 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
5905 if (h2 == NULL || h2 != htab->tls_get_addr)
5906 break;
5907
5908 /* OK, it checks out. Replace the call. */
5909 offset = rel[1].r_offset;
6016 tls_ldgd_opt:
6017 offset = (bfd_vma) -1;
6018 /* If not using the newer R_PPC_TLSGD/LD to mark
6019 __tls_get_addr calls, we must trust that the call
6020 stays with its arg setup insns, ie. that the next
6021 reloc is the __tls_get_addr call associated with
6022 the current reloc. Edit both insns. */
6023 if (input_section->has_tls_get_addr_call
6024 && rel + 1 < relend
6025 && branch_reloc_hash_match (input_bfd, rel + 1,
6026 htab->tls_get_addr))
6027 offset = rel[1].r_offset;
6028 if ((tls_mask & tls_gd) != 0)
6029 {
6030 /* IE */
5910 insn1 = bfd_get_32 (output_bfd,
5911 contents + rel->r_offset - d_offset);
6031 insn1 = bfd_get_32 (output_bfd,
6032 contents + rel->r_offset - d_offset);
5912 if ((tls_mask & tls_gd) != 0)
6033 insn1 &= (1 << 26) - 1;
6034 insn1 |= 32 << 26; /* lwz */
6035 if (offset != (bfd_vma) -1)
5913 {
6036 {
5914 /* IE */
5915 insn1 &= (1 << 26) - 1;
5916 insn1 |= 32 << 26; /* lwz */
6037 rel[1].r_info
6038 = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info),
6039 R_PPC_NONE);
5917 insn2 = 0x7c631214; /* add 3,3,2 */
6040 insn2 = 0x7c631214; /* add 3,3,2 */
5918 rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
5919 rel[1].r_addend = 0;
5920 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
5921 + R_PPC_GOT_TPREL16);
5922 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6041 bfd_put_32 (output_bfd, insn2, contents + offset);
5923 }
6042 }
5924 else
6043 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
6044 + R_PPC_GOT_TPREL16);
6045 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6046 }
6047 else
6048 {
6049 /* LE */
6050 insn1 = 0x3c620000; /* addis 3,2,0 */
6051 if (tls_gd == 0)
5925 {
6052 {
5926 /* LE */
5927 insn1 = 0x3c620000; /* addis 3,2,0 */
5928 insn2 = 0x38630000; /* addi 3,3,0 */
5929 if (tls_gd == 0)
5930 {
5931 /* Was an LD reloc. */
5932 r_symndx = 0;
5933 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
5934 }
5935 r_type = R_PPC_TPREL16_HA;
5936 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5937 rel[1].r_info = ELF32_R_INFO (r_symndx,
5938 R_PPC_TPREL16_LO);
5939 rel[1].r_offset += d_offset;
5940 rel[1].r_addend = rel->r_addend;
6053 /* Was an LD reloc. */
6054 for (r_symndx = 0;
6055 r_symndx < symtab_hdr->sh_info;
6056 r_symndx++)
6057 if (local_sections[r_symndx] == sec)
6058 break;
6059 if (r_symndx >= symtab_hdr->sh_info)
6060 r_symndx = 0;
6061 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
6062 if (r_symndx != 0)
6063 rel->r_addend -= (local_syms[r_symndx].st_value
6064 + sec->output_offset
6065 + sec->output_section->vma);
5941 }
6066 }
5942 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - d_offset);
5943 bfd_put_32 (output_bfd, insn2, contents + offset);
5944 if (tls_gd == 0)
6067 r_type = R_PPC_TPREL16_HA;
6068 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6069 if (offset != (bfd_vma) -1)
5945 {
6070 {
5946 /* We changed the symbol on an LD reloc. Start over
5947 in order to get h, sym, sec etc. right. */
5948 rel--;
5949 continue;
6071 rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
6072 rel[1].r_offset = offset + d_offset;
6073 rel[1].r_addend = rel->r_addend;
6074 insn2 = 0x38630000; /* addi 3,3,0 */
6075 bfd_put_32 (output_bfd, insn2, contents + offset);
5950 }
5951 }
6076 }
6077 }
6078 bfd_put_32 (output_bfd, insn1,
6079 contents + rel->r_offset - d_offset);
6080 if (tls_gd == 0)
6081 {
6082 /* We changed the symbol on an LD reloc. Start over
6083 in order to get h, sym, sec etc. right. */
6084 rel--;
6085 continue;
6086 }
5952 }
5953 break;
6087 }
6088 break;
6089
6090 case R_PPC_TLSGD:
6091 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
6092 {
6093 unsigned int insn2;
6094 bfd_vma offset = rel->r_offset;
6095
6096 if ((tls_mask & TLS_TPRELGD) != 0)
6097 {
6098 /* IE */
6099 r_type = R_PPC_NONE;
6100 insn2 = 0x7c631214; /* add 3,3,2 */
6101 }
6102 else
6103 {
6104 /* LE */
6105 r_type = R_PPC_TPREL16_LO;
6106 rel->r_offset += d_offset;
6107 insn2 = 0x38630000; /* addi 3,3,0 */
6108 }
6109 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6110 bfd_put_32 (output_bfd, insn2, contents + offset);
6111 /* Zap the reloc on the _tls_get_addr call too. */
6112 BFD_ASSERT (offset == rel[1].r_offset);
6113 rel[1].r_info = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info),
6114 R_PPC_NONE);
6115 }
6116 break;
6117
6118 case R_PPC_TLSLD:
6119 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
6120 {
6121 unsigned int insn2;
6122
6123 for (r_symndx = 0;
6124 r_symndx < symtab_hdr->sh_info;
6125 r_symndx++)
6126 if (local_sections[r_symndx] == sec)
6127 break;
6128 if (r_symndx >= symtab_hdr->sh_info)
6129 r_symndx = 0;
6130 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
6131 if (r_symndx != 0)
6132 rel->r_addend -= (local_syms[r_symndx].st_value
6133 + sec->output_offset
6134 + sec->output_section->vma);
6135
6136 rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
6137 rel->r_offset += d_offset;
6138 insn2 = 0x38630000; /* addi 3,3,0 */
6139 bfd_put_32 (output_bfd, insn2,
6140 contents + rel->r_offset - d_offset);
6141 /* Zap the reloc on the _tls_get_addr call too. */
6142 BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset);
6143 rel[1].r_info = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info),
6144 R_PPC_NONE);
6145 rel--;
6146 continue;
6147 }
6148 break;
5954 }
5955
5956 /* Handle other relocations that tweak non-addend part of insn. */
5957 branch_bit = 0;
5958 switch (r_type)
5959 {
5960 default:
5961 break;

--- 36 unchanged lines hidden (view full) ---

5998 input_bfd, (int) r_type, sym_name);
5999
6000 bfd_set_error (bfd_error_bad_value);
6001 ret = FALSE;
6002 continue;
6003
6004 case R_PPC_NONE:
6005 case R_PPC_TLS:
6149 }
6150
6151 /* Handle other relocations that tweak non-addend part of insn. */
6152 branch_bit = 0;
6153 switch (r_type)
6154 {
6155 default:
6156 break;

--- 36 unchanged lines hidden (view full) ---

6193 input_bfd, (int) r_type, sym_name);
6194
6195 bfd_set_error (bfd_error_bad_value);
6196 ret = FALSE;
6197 continue;
6198
6199 case R_PPC_NONE:
6200 case R_PPC_TLS:
6201 case R_PPC_TLSGD:
6202 case R_PPC_TLSLD:
6006 case R_PPC_EMB_MRKREF:
6007 case R_PPC_GNU_VTINHERIT:
6008 case R_PPC_GNU_VTENTRY:
6009 continue;
6010
6011 /* GOT16 relocations. Like an ADDR16 using the symbol's
6012 address in the GOT as relocation value instead of the
6013 symbol's value itself. Also, create a GOT entry for the

--- 25 unchanged lines hidden (view full) ---

6039 case R_PPC_GOT_DTPREL16_HA:
6040 tls_type = TLS_TLS | TLS_DTPREL;
6041 goto dogot;
6042
6043 case R_PPC_GOT16:
6044 case R_PPC_GOT16_LO:
6045 case R_PPC_GOT16_HI:
6046 case R_PPC_GOT16_HA:
6203 case R_PPC_EMB_MRKREF:
6204 case R_PPC_GNU_VTINHERIT:
6205 case R_PPC_GNU_VTENTRY:
6206 continue;
6207
6208 /* GOT16 relocations. Like an ADDR16 using the symbol's
6209 address in the GOT as relocation value instead of the
6210 symbol's value itself. Also, create a GOT entry for the

--- 25 unchanged lines hidden (view full) ---

6236 case R_PPC_GOT_DTPREL16_HA:
6237 tls_type = TLS_TLS | TLS_DTPREL;
6238 goto dogot;
6239
6240 case R_PPC_GOT16:
6241 case R_PPC_GOT16_LO:
6242 case R_PPC_GOT16_HI:
6243 case R_PPC_GOT16_HA:
6244 tls_mask = 0;
6047 dogot:
6048 {
6049 /* Relocation is to the entry for this symbol in the global
6050 offset table. */
6051 bfd_vma off;
6052 bfd_vma *offp;
6053 unsigned long indx;
6054

--- 282 unchanged lines hidden (view full) ---

6337 if ((input_section->flags & SEC_ALLOC) == 0)
6338 break;
6339 /* Fall thru. */
6340
6341 if ((info->shared
6342 && (h == NULL
6343 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6344 || h->root.type != bfd_link_hash_undefweak)
6245 dogot:
6246 {
6247 /* Relocation is to the entry for this symbol in the global
6248 offset table. */
6249 bfd_vma off;
6250 bfd_vma *offp;
6251 unsigned long indx;
6252

--- 282 unchanged lines hidden (view full) ---

6535 if ((input_section->flags & SEC_ALLOC) == 0)
6536 break;
6537 /* Fall thru. */
6538
6539 if ((info->shared
6540 && (h == NULL
6541 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6542 || h->root.type != bfd_link_hash_undefweak)
6345 && (MUST_BE_DYN_RELOC (r_type)
6543 && (must_be_dyn_reloc (info, r_type)
6346 || !SYMBOL_CALLS_LOCAL (info, h)))
6347 || (ELIMINATE_COPY_RELOCS
6348 && !info->shared
6349 && h != NULL
6350 && h->dynindx != -1
6351 && !h->non_got_ref
6352 && h->def_dynamic
6353 && !h->def_regular))

--- 52 unchanged lines hidden (view full) ---

6406 else
6407 {
6408 outrel.r_addend = relocation + rel->r_addend;
6409
6410 if (r_type == R_PPC_ADDR32)
6411 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
6412 else
6413 {
6544 || !SYMBOL_CALLS_LOCAL (info, h)))
6545 || (ELIMINATE_COPY_RELOCS
6546 && !info->shared
6547 && h != NULL
6548 && h->dynindx != -1
6549 && !h->non_got_ref
6550 && h->def_dynamic
6551 && !h->def_regular))

--- 52 unchanged lines hidden (view full) ---

6604 else
6605 {
6606 outrel.r_addend = relocation + rel->r_addend;
6607
6608 if (r_type == R_PPC_ADDR32)
6609 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
6610 else
6611 {
6414 long indx;
6612 long indx = 0;
6415
6613
6416 if (bfd_is_abs_section (sec))
6417 indx = 0;
6614 if (r_symndx == 0 || bfd_is_abs_section (sec))
6615 ;
6418 else if (sec == NULL || sec->owner == NULL)
6419 {
6420 bfd_set_error (bfd_error_bad_value);
6421 return FALSE;
6422 }
6423 else
6424 {
6425 asection *osec;

--- 1317 unchanged lines hidden ---
6616 else if (sec == NULL || sec->owner == NULL)
6617 {
6618 bfd_set_error (bfd_error_bad_value);
6619 return FALSE;
6620 }
6621 else
6622 {
6623 asection *osec;

--- 1317 unchanged lines hidden ---