~ubuntu-branches/debian/squeeze/binutils/squeeze

« back to all changes in this revision

Viewing changes to bfd/elf32-ppc.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-09-10 17:05:30 UTC
  • mfrom: (1.4.5 upstream) (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090910170530-wa6gpju9pq5c56on
Tags: 2.19.91.20090910-1
* Snapshot, taken from the 2.20 release branch 20090910, corresponding
  to the 2.19.90 upstream snapshot.
* Fix Thumb-2 shared libraries (Daniel Jacobowitz), patch taken
  from the trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2605
2605
};
2606
2606
 
2607
2607
/* Track PLT entries needed for a given symbol.  We might need more
2608
 
   than one glink entry per symbol.  */
 
2608
   than one glink entry per symbol when generating a pic binary.  */
2609
2609
struct plt_entry
2610
2610
{
2611
2611
  struct plt_entry *next;
2612
2612
 
2613
2613
  /* -fPIC uses multiple GOT sections, one per file, called ".got2".
2614
2614
     This field stores the offset into .got2 used to initialise the
2615
 
     GOT pointer reg.  It will always be at least 32768 (and for
2616
 
     current gcc this is the only offset used).  */
 
2615
     GOT pointer reg.  It will always be at least 32768.  (Current
 
2616
     gcc always uses an offset of 32768, but ld -r will pack .got2
 
2617
     sections together resulting in larger offsets).  */
2617
2618
  bfd_vma addend;
2618
2619
 
2619
2620
  /* The .got2 section.  */
3408
3409
    ppc_elf_howto_init ();
3409
3410
 
3410
3411
  htab = ppc_elf_hash_table (info);
 
3412
  if (htab->glink == NULL)
 
3413
    {
 
3414
      if (htab->elf.dynobj == NULL)
 
3415
        htab->elf.dynobj = abfd;
 
3416
      if (!ppc_elf_create_glink (htab->elf.dynobj, info))
 
3417
        return FALSE;
 
3418
    }
3411
3419
  tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3412
3420
                              FALSE, FALSE, TRUE);
3413
3421
  symtab_hdr = &elf_symtab_hdr (abfd);
3452
3460
      tls_type = 0;
3453
3461
      ifunc = NULL;
3454
3462
      r_type = ELF32_R_TYPE (rel->r_info);
3455
 
      if (!htab->is_vxworks && is_branch_reloc (r_type))
 
3463
      if (!htab->is_vxworks)
3456
3464
        {
3457
 
          if (h != NULL && h == tga)
3458
 
            {
3459
 
              if (rel != relocs
3460
 
                  && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD
3461
 
                      || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD))
3462
 
                /* We have a new-style __tls_get_addr call with a marker
3463
 
                   reloc.  */
3464
 
                ;
3465
 
              else
3466
 
                /* Mark this section as having an old-style call.  */
3467
 
                sec->has_tls_get_addr_call = 1;
3468
 
            }
3469
 
 
3470
 
          /* STT_GNU_IFUNC symbols must have a PLT entry.  */
3471
3465
          if (h != NULL)
3472
3466
            {
3473
3467
              if (h->type == STT_GNU_IFUNC)
3474
 
                {
3475
 
                  h->needs_plt = 1;
3476
 
                  ifunc = &h->plt.plist;
3477
 
                }
 
3468
                ifunc = &h->plt.plist;
3478
3469
            }
3479
3470
          else
3480
3471
            {
3483
3474
              if (isym == NULL)
3484
3475
                return FALSE;
3485
3476
 
3486
 
              if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
 
3477
              if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
 
3478
                  && (!info->shared
 
3479
                      || is_branch_reloc (r_type)))
3487
3480
                {
 
3481
                  bfd_vma addend;
 
3482
 
3488
3483
                  ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
3489
3484
                                                 PLT_IFUNC);
3490
3485
                  if (ifunc == NULL)
3491
3486
                    return FALSE;
3492
 
                }
3493
 
            }
3494
 
          if (ifunc != NULL)
3495
 
            {
3496
 
              bfd_vma addend = 0;
3497
 
 
3498
 
              if (r_type == R_PPC_PLTREL24)
3499
 
                {
3500
 
                  ppc_elf_tdata (abfd)->makes_plt_call = 1;
3501
 
                  addend = rel->r_addend;
3502
 
                }
3503
 
              if (!update_plt_info (abfd, ifunc,
3504
 
                                    addend < 32768 ? NULL : got2, addend))
3505
 
                return FALSE;
3506
 
 
3507
 
              if (htab->glink == NULL)
3508
 
                {
3509
 
                  if (htab->elf.dynobj == NULL)
3510
 
                    htab->elf.dynobj = abfd;
3511
 
                  if (!ppc_elf_create_glink (htab->elf.dynobj, info))
 
3487
 
 
3488
                  /* STT_GNU_IFUNC symbols must have a PLT entry;
 
3489
                     In a non-pie executable even when there are
 
3490
                     no plt calls.  */
 
3491
                  addend = 0;
 
3492
                  if (r_type == R_PPC_PLTREL24)
 
3493
                    {
 
3494
                      ppc_elf_tdata (abfd)->makes_plt_call = 1;
 
3495
                      if (info->shared)
 
3496
                        addend = rel->r_addend;
 
3497
                    }
 
3498
                  if (!update_plt_info (abfd, ifunc,
 
3499
                                        addend < 32768 ? NULL : got2, addend))
3512
3500
                    return FALSE;
3513
3501
                }
3514
3502
            }
3515
3503
        }
3516
3504
 
 
3505
      if (!htab->is_vxworks
 
3506
          && is_branch_reloc (r_type)
 
3507
          && h != NULL
 
3508
          && h == tga)
 
3509
        {
 
3510
          if (rel != relocs
 
3511
              && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD
 
3512
                  || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD))
 
3513
            /* We have a new-style __tls_get_addr call with a marker
 
3514
               reloc.  */
 
3515
            ;
 
3516
          else
 
3517
            /* Mark this section as having an old-style call.  */
 
3518
            sec->has_tls_get_addr_call = 1;
 
3519
        }
 
3520
 
3517
3521
      switch (r_type)
3518
3522
        {
3519
3523
        case R_PPC_TLSGD:
3576
3580
            /* This is a global offset table entry for a local symbol.  */
3577
3581
            if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
3578
3582
              return FALSE;
 
3583
 
 
3584
          /* We may also need a plt entry if the symbol turns out to be
 
3585
             an ifunc.  */
 
3586
          if (h != NULL && !info->shared)
 
3587
            {
 
3588
              if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
 
3589
                return FALSE;
 
3590
            }
3579
3591
          break;
3580
3592
 
3581
3593
          /* Indirect .sdata relocation.  */
3687
3699
          break;
3688
3700
 
3689
3701
        case R_PPC_PLTREL24:
3690
 
          if (h == NULL || ifunc != NULL)
 
3702
          if (h == NULL)
3691
3703
            break;
3692
3704
          /* Fall through */
3693
3705
        case R_PPC_PLT32:
3724
3736
              if (r_type == R_PPC_PLTREL24)
3725
3737
                {
3726
3738
                  ppc_elf_tdata (abfd)->makes_plt_call = 1;
3727
 
                  addend = rel->r_addend;
 
3739
                  if (info->shared)
 
3740
                    addend = rel->r_addend;
3728
3741
                }
3729
3742
              h->needs_plt = 1;
3730
3743
              if (!update_plt_info (abfd, &h->plt.plist,
3826
3839
          if (h == NULL
3827
3840
              && got2 != NULL
3828
3841
              && (sec->flags & SEC_CODE) != 0
3829
 
              && (info->shared || info->pie)
 
3842
              && info->shared
3830
3843
              && htab->plt_type == PLT_UNSET)
3831
3844
            {
3832
3845
              /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
3900
3913
              /* We may need a plt entry if the symbol turns out to be
3901
3914
                 a function defined in a dynamic object.  */
3902
3915
              h->needs_plt = 1;
3903
 
              if (ifunc == NULL
3904
 
                  && !update_plt_info (abfd, &h->plt.plist, NULL, 0))
 
3916
              if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
3905
3917
                return FALSE;
3906
3918
              break;
3907
3919
            }
4410
4422
        }
4411
4423
 
4412
4424
      r_type = ELF32_R_TYPE (rel->r_info);
4413
 
      if (!htab->is_vxworks && is_branch_reloc (r_type))
 
4425
      if (!htab->is_vxworks
 
4426
          && h == NULL
 
4427
          && local_got_refcounts != NULL
 
4428
          && (!info->shared
 
4429
              || is_branch_reloc (r_type)))
4414
4430
        {
4415
 
          struct plt_entry **ifunc = NULL;
4416
 
          if (h != NULL)
4417
 
            {
4418
 
              if (h->type == STT_GNU_IFUNC)
4419
 
                ifunc = &h->plt.plist;
4420
 
            }
4421
 
          else if (local_got_refcounts != NULL)
4422
 
            {
4423
 
              struct plt_entry **local_plt = (struct plt_entry **)
4424
 
                (local_got_refcounts + symtab_hdr->sh_info);
4425
 
              char *local_got_tls_masks = (char *)
4426
 
                (local_plt + symtab_hdr->sh_info);
4427
 
              if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
4428
 
                ifunc = local_plt + r_symndx;
4429
 
            }
4430
 
          if (ifunc != NULL)
4431
 
            {
4432
 
              bfd_vma addend = r_type == R_PPC_PLTREL24 ? rel->r_addend : 0;
4433
 
              struct plt_entry *ent = find_plt_ent (ifunc, got2, addend);
 
4431
          struct plt_entry **local_plt = (struct plt_entry **)
 
4432
            (local_got_refcounts + symtab_hdr->sh_info);
 
4433
          char *local_got_tls_masks = (char *)
 
4434
            (local_plt + symtab_hdr->sh_info);
 
4435
          if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
 
4436
            {
 
4437
              struct plt_entry **ifunc = local_plt + r_symndx;
 
4438
              bfd_vma addend = 0;
 
4439
              struct plt_entry *ent;
 
4440
 
 
4441
              if (r_type == R_PPC_PLTREL24 && info->shared)
 
4442
                addend = rel->r_addend;
 
4443
              ent = find_plt_ent (ifunc, got2, addend);
4434
4444
              if (ent->plt.refcount > 0)
4435
4445
                ent->plt.refcount -= 1;
4436
4446
              continue;
4463
4473
            {
4464
4474
              if (h->got.refcount > 0)
4465
4475
                h->got.refcount--;
 
4476
              if (!info->shared)
 
4477
                {
 
4478
                  struct plt_entry *ent;
 
4479
 
 
4480
                  ent = find_plt_ent (&h->plt.plist, NULL, 0);
 
4481
                  if (ent->plt.refcount > 0)
 
4482
                    ent->plt.refcount -= 1;
 
4483
                }
4466
4484
            }
4467
4485
          else if (local_got_refcounts != NULL)
4468
4486
            {
4502
4520
        case R_PPC_PLT16_HA:
4503
4521
          if (h != NULL)
4504
4522
            {
4505
 
              bfd_vma addend = r_type == R_PPC_PLTREL24 ? rel->r_addend : 0;
4506
 
              struct plt_entry *ent = find_plt_ent (&h->plt.plist,
4507
 
                                                    got2, addend);
 
4523
              bfd_vma addend = 0;
 
4524
              struct plt_entry *ent;
 
4525
 
 
4526
              if (r_type == R_PPC_PLTREL24 && info->shared)
 
4527
                addend = rel->r_addend;
 
4528
              ent = find_plt_ent (&h->plt.plist, got2, addend);
4508
4529
              if (ent->plt.refcount > 0)
4509
4530
                ent->plt.refcount -= 1;
4510
4531
            }
4822
4843
  htab = ppc_elf_hash_table (info);
4823
4844
  BFD_ASSERT (htab->elf.dynobj != NULL
4824
4845
              && (h->needs_plt
 
4846
                  || h->type == STT_GNU_IFUNC
4825
4847
                  || h->u.weakdef != NULL
4826
4848
                  || (h->def_dynamic
4827
4849
                      && h->ref_regular
4859
4881
        }
4860
4882
      else
4861
4883
        {
4862
 
          /* After adjust_dynamic_symbol, non_got_ref set means that
4863
 
             dyn_relocs for this symbol should be discarded.
 
4884
          /* After adjust_dynamic_symbol, non_got_ref set in the
 
4885
             non-shared case means that we have allocated space in
 
4886
             .dynbss for the symbol and thus dyn_relocs for this
 
4887
             symbol should be discarded.
4864
4888
             If we get here we know we are making a PLT entry for this
4865
4889
             symbol, and in an executable we'd normally resolve
4866
4890
             relocations against this symbol to the PLT entry.  Allow
4868
4892
             relocs will not cause text relocation.  */
4869
4893
          if (!h->ref_regular_nonweak
4870
4894
              && h->non_got_ref
 
4895
              && h->type != STT_GNU_IFUNC
4871
4896
              && !htab->is_vxworks
4872
4897
              && !ppc_elf_hash_entry (h)->has_sda_refs
4873
4898
              && !readonly_dynrelocs (h))
4986
5011
  const char *stub;
4987
5012
  struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
4988
5013
 
4989
 
  if (info->shared || info->pie)
 
5014
  if (info->shared)
4990
5015
    stub = ".plt_pic32.";
4991
5016
  else
4992
5017
    stub = ".plt_call32.";
5105
5130
                || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
5106
5131
              {
5107
5132
                asection *s = htab->plt;
5108
 
                if (!dyn)
 
5133
                if (!dyn || h->dynindx == -1)
5109
5134
                  s = htab->iplt;
5110
5135
 
5111
 
                if (htab->plt_type == PLT_NEW || !dyn)
 
5136
                if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1)
5112
5137
                  {
5113
5138
                    if (!doneone)
5114
5139
                      {
5118
5143
                    ent->plt.offset = plt_offset;
5119
5144
 
5120
5145
                    s = htab->glink;
5121
 
                    if (!doneone || info->shared || info->pie)
 
5146
                    if (!doneone || info->shared)
5122
5147
                      {
5123
5148
                        glink_offset = s->size;
5124
5149
                        s->size += GLINK_ENTRY_SIZE;
5158
5183
 
5159
5184
                        /* If this symbol is not defined in a regular
5160
5185
                           file, and we are not generating a shared
5161
 
                           library, then set the symbol to this location
5162
 
                           in the .plt.  This is required to make
 
5186
                           library, then set the symbol to this location 
 
5187
                           in the .plt.  This is to avoid text
 
5188
                           relocations, and is required to make
5163
5189
                           function pointers compare as equal between
5164
5190
                           the normal executable and the shared library.  */
5165
5191
                        if (! info->shared
5186
5212
                /* We also need to make an entry in the .rela.plt section.  */
5187
5213
                if (!doneone)
5188
5214
                  {
5189
 
                    if (!htab->elf.dynamic_sections_created)
 
5215
                    if (!htab->elf.dynamic_sections_created
 
5216
                        || h->dynindx == -1)
5190
5217
                      htab->reliplt->size += sizeof (Elf32_External_Rela);
5191
5218
                    else
5192
5219
                      {
5246
5273
      /* Make sure this symbol is output as a dynamic symbol.  */
5247
5274
      if (eh->elf.dynindx == -1
5248
5275
          && !eh->elf.forced_local
5249
 
          && !eh->elf.def_regular
 
5276
          && eh->elf.type != STT_GNU_IFUNC
5250
5277
          && htab->elf.dynamic_sections_created)
5251
5278
        {
5252
5279
          if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
5286
5313
              && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
5287
5314
                  || eh->elf.root.type != bfd_link_hash_undefweak))
5288
5315
            {
 
5316
              asection *rsec = htab->relgot;
5289
5317
              /* All the entries we allocated need relocs.
5290
5318
                 Except LD only needs one.  */
5291
5319
              if ((eh->tls_mask & TLS_LD) != 0
5292
5320
                  && eh->elf.def_dynamic)
5293
5321
                need -= 4;
5294
 
              htab->relgot->size += need * (sizeof (Elf32_External_Rela) / 4);
 
5322
              rsec->size += need * (sizeof (Elf32_External_Rela) / 4);
5295
5323
            }
5296
5324
        }
5297
5325
    }
5382
5410
          /* Make sure this symbol is output as a dynamic symbol.
5383
5411
             Undefined weak syms won't yet be marked as dynamic.  */
5384
5412
          if (h->dynindx == -1
5385
 
              && !h->forced_local
5386
 
              && !h->def_regular)
 
5413
              && !h->forced_local)
5387
5414
            {
5388
5415
              if (! bfd_elf_link_record_dynamic_symbol (info, h))
5389
5416
                return FALSE;
5404
5431
  for (p = eh->dyn_relocs; p != NULL; p = p->next)
5405
5432
    {
5406
5433
      asection *sreloc = elf_section_data (p->sec)->sreloc;
 
5434
      if (!htab->elf.dynamic_sections_created)
 
5435
        sreloc = htab->reliplt;
5407
5436
      sreloc->size += p->count * sizeof (Elf32_External_Rela);
5408
5437
    }
5409
5438
 
5508
5537
                }
5509
5538
              else if (p->count != 0)
5510
5539
                {
5511
 
                  elf_section_data (p->sec)->sreloc->size
5512
 
                    += p->count * sizeof (Elf32_External_Rela);
 
5540
                  asection *sreloc = elf_section_data (p->sec)->sreloc;
 
5541
                  if (!htab->elf.dynamic_sections_created)
 
5542
                    sreloc = htab->reliplt;
 
5543
                  sreloc->size += p->count * sizeof (Elf32_External_Rela);
5513
5544
                  if ((p->sec->output_section->flags
5514
5545
                       & (SEC_READONLY | SEC_ALLOC))
5515
5546
                      == (SEC_READONLY | SEC_ALLOC))
5581
5612
                ent->plt.offset = plt_offset;
5582
5613
 
5583
5614
                s = htab->glink;
5584
 
                if (!doneone || info->shared || info->pie)
 
5615
                if (!doneone || info->shared)
5585
5616
                  {
5586
5617
                    glink_offset = s->size;
5587
5618
                    s->size += GLINK_ENTRY_SIZE;
5590
5621
 
5591
5622
                if (!doneone)
5592
5623
                  {
5593
 
                    htab->reliplt += sizeof (Elf32_External_Rela);
 
5624
                    htab->reliplt->size += sizeof (Elf32_External_Rela);
5594
5625
                    doneone = TRUE;
5595
5626
                  }
5596
5627
              }
5826
5857
 
5827
5858
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
5828
5859
 
 
5860
/* Relaxation trampolines.  r12 is available for clobbering (r11, is
 
5861
   used for some functions that are allowed to break the ABI).  */
5829
5862
static const int shared_stub_entry[] =
5830
5863
  {
5831
5864
    0x7c0802a6, /* mflr 0 */
5832
5865
    0x429f0005, /* bcl 20, 31, .Lxxx */
5833
 
    0x7d6802a6, /* mflr 11 */
5834
 
    0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
5835
 
    0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
 
5866
    0x7d8802a6, /* mflr 12 */
 
5867
    0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */
 
5868
    0x398c0008, /* addi 12, 12, (xxx-.Lxxx)@l */
5836
5869
    0x7c0803a6, /* mtlr 0 */
5837
 
    0x7d6903a6, /* mtctr 11 */
 
5870
    0x7d8903a6, /* mtctr 12 */
5838
5871
    0x4e800420, /* bctr */
5839
5872
  };
5840
5873
 
5841
5874
static const int stub_entry[] =
5842
5875
  {
5843
 
    0x3d600000, /* lis 11,xxx@ha */
5844
 
    0x396b0000, /* addi 11,11,xxx@l */
5845
 
    0x7d6903a6, /* mtctr 11 */
 
5876
    0x3d800000, /* lis 12,xxx@ha */
 
5877
    0x398c0000, /* addi 12,12,xxx@l */
 
5878
    0x7d8903a6, /* mtctr 12 */
5846
5879
    0x4e800420, /* bctr */
5847
5880
  };
5848
5881
 
5856
5889
  {
5857
5890
    struct one_fixup *next;
5858
5891
    asection *tsec;
 
5892
    /* Final link, can use the symbol offset.  For a
 
5893
       relocatable link we use the symbol's index.  */
5859
5894
    bfd_vma toff;
5860
5895
    bfd_vma trampoff;
5861
5896
  };
5874
5909
  *again = FALSE;
5875
5910
 
5876
5911
  /* Nothing to do if there are no relocations, and no need to do
5877
 
     anything with non-alloc sections.  */
 
5912
     anything with non-alloc or non-code sections.  */
5878
5913
  if ((isec->flags & SEC_ALLOC) == 0
 
5914
      || (isec->flags & SEC_CODE) == 0
5879
5915
      || (isec->flags & SEC_RELOC) == 0
5880
5916
      || isec->reloc_count == 0)
5881
5917
    return TRUE;
5905
5941
  for (irel = internal_relocs; irel < irelend; irel++)
5906
5942
    {
5907
5943
      unsigned long r_type = ELF32_R_TYPE (irel->r_info);
5908
 
      bfd_vma symaddr, reladdr, toff, roff;
 
5944
      bfd_vma reladdr, toff, roff;
5909
5945
      asection *tsec;
5910
5946
      struct one_fixup *f;
5911
5947
      size_t insn_offset = 0;
5912
5948
      bfd_vma max_branch_offset, val;
5913
5949
      bfd_byte *hit_addr;
5914
5950
      unsigned long t0;
 
5951
      struct elf_link_hash_entry *h;
 
5952
      struct plt_entry **plist;
5915
5953
      unsigned char sym_type;
5916
5954
 
5917
5955
      switch (r_type)
5933
5971
        }
5934
5972
 
5935
5973
      /* Get the value of the symbol referred to by the reloc.  */
 
5974
      h = NULL;
5936
5975
      if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
5937
5976
        {
5938
5977
          /* A local symbol.  */
5966
6005
        {
5967
6006
          /* Global symbol handling.  */
5968
6007
          unsigned long indx;
5969
 
          struct elf_link_hash_entry *h;
5970
6008
 
5971
6009
          indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
5972
6010
          h = elf_sym_hashes (abfd)[indx];
5975
6013
                 || h->root.type == bfd_link_hash_warning)
5976
6014
            h = (struct elf_link_hash_entry *) h->root.u.i.link;
5977
6015
 
5978
 
          tsec = NULL;
5979
 
          toff = 0;
5980
 
          if (r_type == R_PPC_PLTREL24
5981
 
              && htab->plt != NULL)
5982
 
            {
5983
 
              struct plt_entry *ent = find_plt_ent (&h->plt.plist,
5984
 
                                                    got2, irel->r_addend);
5985
 
 
5986
 
              if (ent != NULL)
5987
 
                {
5988
 
                  if (htab->plt_type == PLT_NEW)
5989
 
                    {
5990
 
                      tsec = htab->glink;
5991
 
                      toff = ent->glink_offset;
5992
 
                    }
5993
 
                  else
5994
 
                    {
5995
 
                      tsec = htab->plt;
5996
 
                      toff = ent->plt.offset;
5997
 
                    }
5998
 
                }
5999
 
            }
6000
 
          if (tsec != NULL)
6001
 
            ;
6002
 
          else if (h->root.type == bfd_link_hash_defined
6003
 
                   || h->root.type == bfd_link_hash_defweak)
 
6016
          if (h->root.type == bfd_link_hash_defined
 
6017
              || h->root.type == bfd_link_hash_defweak)
6004
6018
            {
6005
6019
              tsec = h->root.u.def.section;
6006
6020
              toff = h->root.u.def.value;
6009
6023
                   || h->root.type == bfd_link_hash_undefweak)
6010
6024
            {
6011
6025
              tsec = bfd_und_section_ptr;
6012
 
              toff = 0;
 
6026
              toff = link_info->relocatable ? indx : 0;
6013
6027
            }
6014
6028
          else
6015
6029
            continue;
6017
6031
          sym_type = h->type;
6018
6032
        }
6019
6033
 
 
6034
      /* The condition here under which we call find_plt_ent must
 
6035
         match that in relocate_section.  If we call find_plt_ent here
 
6036
         but not in relocate_section, or vice versa, then the branch
 
6037
         destination used here may be incorrect.  */
 
6038
      plist = NULL;
 
6039
      if (h != NULL)
 
6040
        {
 
6041
          /* We know is_branch_reloc (r_type) is true.  */
 
6042
          if (h->type == STT_GNU_IFUNC
 
6043
              || r_type == R_PPC_PLTREL24)
 
6044
            plist = &h->plt.plist;
 
6045
        }
 
6046
      else if (sym_type == STT_GNU_IFUNC
 
6047
               && elf_local_got_offsets (abfd) != NULL)
 
6048
        {
 
6049
          bfd_vma *local_got_offsets = elf_local_got_offsets (abfd);
 
6050
          struct plt_entry **local_plt = (struct plt_entry **)
 
6051
            (local_got_offsets + symtab_hdr->sh_info);
 
6052
          plist = local_plt + ELF32_R_SYM (irel->r_info);
 
6053
        }
 
6054
      if (plist != NULL)
 
6055
        {
 
6056
          bfd_vma addend = 0;
 
6057
          struct plt_entry *ent;
 
6058
 
 
6059
          if (r_type == R_PPC_PLTREL24 && link_info->shared)
 
6060
            addend = irel->r_addend;
 
6061
          ent = find_plt_ent (plist, got2, addend);
 
6062
          if (ent != NULL)
 
6063
            {
 
6064
              if (htab->plt_type == PLT_NEW
 
6065
                  || h == NULL
 
6066
                  || !htab->elf.dynamic_sections_created
 
6067
                  || h->dynindx == -1)
 
6068
                {
 
6069
                  tsec = htab->glink;
 
6070
                  toff = ent->glink_offset;
 
6071
                }
 
6072
              else
 
6073
                {
 
6074
                  tsec = htab->plt;
 
6075
                  toff = ent->plt.offset;
 
6076
                }
 
6077
            }
 
6078
        }
 
6079
 
6020
6080
      /* If the branch and target are in the same section, you have
6021
6081
         no hope of adding stubs.  We'll error out later should the
6022
6082
         branch overflow.  */
6064
6124
      if (tsec->output_section == NULL)
6065
6125
        continue;
6066
6126
 
6067
 
      symaddr = tsec->output_section->vma + tsec->output_offset + toff;
6068
 
 
6069
6127
      roff = irel->r_offset;
6070
6128
      reladdr = isec->output_section->vma + isec->output_offset + roff;
6071
6129
 
6074
6132
          && (!link_info->relocatable
6075
6133
              /* A relocatable link may have sections moved during
6076
6134
                 final link, so do not presume they remain in range.  */
6077
 
              || tsec->output_section == isec->output_section)
6078
 
          && symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
6079
 
        continue;
 
6135
              || tsec->output_section == isec->output_section))
 
6136
        {
 
6137
          bfd_vma symaddr, reladdr;
 
6138
 
 
6139
          symaddr = tsec->output_section->vma + tsec->output_offset + toff;
 
6140
          reladdr = isec->output_section->vma + isec->output_offset + roff;
 
6141
          if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
 
6142
            continue;
 
6143
        }
6080
6144
 
6081
6145
      /* Look for an existing fixup to this address.  */
6082
6146
      for (f = fixups; f ; f = f->next)
6415
6479
         + plt_sec->output_offset);
6416
6480
  p = (unsigned char *) htab->glink->contents + ent->glink_offset;
6417
6481
 
6418
 
  if (info->shared || info->pie)
 
6482
  if (info->shared)
6419
6483
    {
6420
6484
      bfd_vma got = 0;
6421
6485
 
6912
6976
        }
6913
6977
 
6914
6978
      ifunc = NULL;
6915
 
      if (!htab->is_vxworks && is_branch_reloc (r_type))
 
6979
      if (!htab->is_vxworks)
6916
6980
        {
 
6981
          struct plt_entry *ent;
 
6982
 
6917
6983
          if (h != NULL)
6918
6984
            {
6919
6985
              if (h->type == STT_GNU_IFUNC)
6920
6986
                ifunc = &h->plt.plist;
6921
6987
            }
6922
 
          else if (local_got_offsets != NULL)
6923
 
            {
6924
 
              if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
6925
 
                {
6926
 
                  struct plt_entry **local_plt = (struct plt_entry **)
6927
 
                    (local_got_offsets + symtab_hdr->sh_info);
6928
 
 
6929
 
                  ifunc = local_plt + r_symndx;
6930
 
                }
6931
 
            }
6932
 
          if (ifunc != NULL)
6933
 
            {
6934
 
              struct plt_entry *ent = find_plt_ent (ifunc, got2, rel->r_addend);
6935
 
 
 
6988
          else if (local_got_offsets != NULL
 
6989
                   && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
 
6990
            {
 
6991
              struct plt_entry **local_plt;
 
6992
 
 
6993
              local_plt = (struct plt_entry **) (local_got_offsets
 
6994
                                                 + symtab_hdr->sh_info);
 
6995
              ifunc = local_plt + r_symndx;
 
6996
            }
 
6997
 
 
6998
          ent = NULL;
 
6999
          if (ifunc != NULL
 
7000
              && (!info->shared
 
7001
                  || is_branch_reloc (r_type)))
 
7002
            {
 
7003
              addend = 0;
 
7004
              if (r_type == R_PPC_PLTREL24 && info->shared)
 
7005
                addend = rel->r_addend;
 
7006
              ent = find_plt_ent (ifunc, got2, addend);
 
7007
            }
 
7008
          if (ent != NULL)
 
7009
            {
6936
7010
              if (h == NULL && (ent->plt.offset & 1) == 0)
6937
7011
                {
6938
7012
                  Elf_Internal_Rela rela;
6943
7017
                                   + ent->plt.offset);
6944
7018
                  rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
6945
7019
                  rela.r_addend = relocation;
6946
 
                  loc = (htab->reliplt->contents
6947
 
                         + ent->plt.offset * sizeof (Elf32_External_Rela) / 4);
 
7020
                  loc = htab->reliplt->contents;
 
7021
                  loc += (htab->reliplt->reloc_count++
 
7022
                          * sizeof (Elf32_External_Rela));
6948
7023
                  bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6949
7024
 
6950
7025
                  ent->plt.offset |= 1;
7125
7200
                            || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7126
7201
                            || h->root.type != bfd_link_hash_undefweak))
7127
7202
                      {
 
7203
                        asection *rsec = htab->relgot;
 
7204
 
7128
7205
                        outrel.r_offset = (htab->got->output_section->vma
7129
7206
                                           + htab->got->output_offset
7130
7207
                                           + off);
7134
7211
                            outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
7135
7212
                            if (tls_ty == (TLS_TLS | TLS_GD))
7136
7213
                              {
7137
 
                                loc = htab->relgot->contents;
7138
 
                                loc += (htab->relgot->reloc_count++
 
7214
                                loc = rsec->contents;
 
7215
                                loc += (rsec->reloc_count++
7139
7216
                                        * sizeof (Elf32_External_Rela));
7140
7217
                                bfd_elf32_swap_reloca_out (output_bfd,
7141
7218
                                                           &outrel, loc);
7148
7225
                          outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
7149
7226
                        else if (tls_ty == (TLS_TLS | TLS_TPREL))
7150
7227
                          outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
7151
 
                        else if (indx == 0)
7152
 
                          outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
 
7228
                        else if (indx != 0)
 
7229
                          outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
 
7230
                        else if (ifunc != NULL)
 
7231
                          outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
7153
7232
                        else
7154
 
                          outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
 
7233
                          outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
7155
7234
                        if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD))
7156
7235
                          {
7157
7236
                            outrel.r_addend += relocation;
7158
7237
                            if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
7159
7238
                              outrel.r_addend -= htab->elf.tls_sec->vma;
7160
7239
                          }
7161
 
                        loc = htab->relgot->contents;
7162
 
                        loc += (htab->relgot->reloc_count++
 
7240
                        loc = rsec->contents;
 
7241
                        loc += (rsec->reloc_count++
7163
7242
                                * sizeof (Elf32_External_Rela));
7164
7243
                        bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
7165
7244
                      }
7366
7445
                 time.  */
7367
7446
              if (sreloc == NULL)
7368
7447
                {
7369
 
                  sreloc = _bfd_elf_get_dynamic_reloc_section
7370
 
                    (input_bfd, input_section, /*rela?*/ TRUE);
 
7448
                  sreloc = elf_section_data (input_section)->sreloc;
 
7449
                  if (!htab->elf.dynamic_sections_created)
 
7450
                    sreloc = htab->reliplt;
7371
7451
                  if (sreloc == NULL)
7372
7452
                    return FALSE;
7373
7453
                }
7397
7477
                {
7398
7478
                  outrel.r_addend = relocation + rel->r_addend;
7399
7479
 
7400
 
                  if (r_type == R_PPC_ADDR32)
7401
 
                    outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
7402
 
                  else
 
7480
                  if (r_type != R_PPC_ADDR32)
7403
7481
                    {
7404
7482
                      long indx = 0;
7405
7483
 
7406
 
                      if (r_symndx == 0 || bfd_is_abs_section (sec))
 
7484
                      if (ifunc != NULL)
 
7485
                        {
 
7486
                          /* If we get here when building a static
 
7487
                             executable, then the libc startup function
 
7488
                             responsible for applying indirect function
 
7489
                             relocations is going to complain about
 
7490
                             the reloc type.
 
7491
                             If we get here when building a dynamic
 
7492
                             executable, it will be because we have
 
7493
                             a text relocation.  The dynamic loader
 
7494
                             will set the text segment writable and
 
7495
                             non-executable to apply text relocations.
 
7496
                             So we'll segfault when trying to run the
 
7497
                             indirection function to resolve the reloc.  */
 
7498
                          (*_bfd_error_handler)
 
7499
                            (_("%B(%A+0x%lx): relocation %s for indirect "
 
7500
                               "function %s unsupported"),
 
7501
                             input_bfd,
 
7502
                             input_section,
 
7503
                             (long) rel->r_offset,
 
7504
                             howto->name,
 
7505
                             sym_name);
 
7506
                          ret = FALSE;
 
7507
                        }
 
7508
                      else if (r_symndx == 0 || bfd_is_abs_section (sec))
7407
7509
                        ;
7408
7510
                      else if (sec == NULL || sec->owner == NULL)
7409
7511
                        {
7418
7520
                             against a section symbol.  It would be
7419
7521
                             proper to subtract the symbol's value,
7420
7522
                             osec->vma, from the emitted reloc addend,
7421
 
                             but ld.so expects buggy relocs.  */
 
7523
                             but ld.so expects buggy relocs.
 
7524
                             FIXME: Why not always use a zero index?  */
7422
7525
                          osec = sec->output_section;
7423
7526
                          indx = elf_section_data (osec)->dynindx;
7424
7527
                          if (indx == 0)
7437
7540
 
7438
7541
                      outrel.r_info = ELF32_R_INFO (indx, r_type);
7439
7542
                    }
 
7543
                  else if (ifunc != NULL)
 
7544
                    outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
 
7545
                  else
 
7546
                    outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
7440
7547
                }
7441
7548
 
7442
7549
              loc = sreloc->contents;
7461
7568
 
7462
7569
        case R_PPC_RELAX32PC_PLT:
7463
7570
        case R_PPC_RELAX32_PLT:
7464
 
          {
7465
 
            struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2, addend);
7466
 
 
7467
 
            if (htab->plt_type == PLT_NEW)
7468
 
              relocation = (htab->glink->output_section->vma
7469
 
                            + htab->glink->output_offset
7470
 
                            + ent->glink_offset);
7471
 
            else
7472
 
              relocation = (htab->plt->output_section->vma
7473
 
                            + htab->plt->output_offset
7474
 
                            + ent->plt.offset);
7475
 
          }
 
7571
          if (h != NULL)
 
7572
            {
 
7573
              struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2,
 
7574
                                                    info->shared ? addend : 0);
 
7575
              if (htab->plt_type == PLT_NEW)
 
7576
                relocation = (htab->glink->output_section->vma
 
7577
                              + htab->glink->output_offset
 
7578
                              + ent->glink_offset);
 
7579
              else
 
7580
                relocation = (htab->plt->output_section->vma
 
7581
                              + htab->plt->output_offset
 
7582
                              + ent->plt.offset);
 
7583
            }
7476
7584
          if (r_type == R_PPC_RELAX32_PLT)
7477
7585
            goto relax32;
7478
7586
          /* Fall thru */
7556
7664
          /* Relocation is to the entry for this symbol in the
7557
7665
             procedure linkage table.  */
7558
7666
          {
7559
 
            struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2, addend);
7560
 
 
 
7667
            struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2,
 
7668
                                                  info->shared ? addend : 0);
7561
7669
            addend = 0;
7562
7670
            if (ent == NULL
7563
7671
                || htab->plt == NULL)
7891
7999
            bfd_vma reloc_index;
7892
8000
 
7893
8001
            if (htab->plt_type == PLT_NEW
7894
 
                || !htab->elf.dynamic_sections_created)
 
8002
                || !htab->elf.dynamic_sections_created
 
8003
                || h->dynindx == -1)
7895
8004
              reloc_index = ent->plt.offset / 4;
7896
8005
            else
7897
8006
              {
7905
8014
            /* This symbol has an entry in the procedure linkage table.
7906
8015
               Set it up.  */
7907
8016
            if (htab->plt_type == PLT_VXWORKS
7908
 
                && htab->elf.dynamic_sections_created)
 
8017
                && htab->elf.dynamic_sections_created
 
8018
                && h->dynindx != -1)
7909
8019
              {
7910
8020
                bfd_vma got_offset;
7911
8021
                const bfd_vma *plt_entry;
8028
8138
            else
8029
8139
              {
8030
8140
                asection *splt = htab->plt;
8031
 
                if (!htab->elf.dynamic_sections_created)
 
8141
                if (!htab->elf.dynamic_sections_created
 
8142
                    || h->dynindx == -1)
8032
8143
                  splt = htab->iplt;
8033
8144
 
8034
8145
                rela.r_offset = (splt->output_section->vma
8035
8146
                                 + splt->output_offset
8036
8147
                                 + ent->plt.offset);
8037
8148
                if (htab->plt_type == PLT_OLD
8038
 
                    || !htab->elf.dynamic_sections_created)
 
8149
                    || !htab->elf.dynamic_sections_created
 
8150
                    || h->dynindx == -1)
8039
8151
                  {
8040
8152
                    /* We don't need to fill in the .plt.  The ppc dynamic
8041
8153
                       linker will fill it in.  */
8065
8177
            else
8066
8178
              rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
8067
8179
 
8068
 
            if (!htab->elf.dynamic_sections_created)
8069
 
              loc = htab->reliplt->contents;
 
8180
            if (!htab->elf.dynamic_sections_created
 
8181
                || h->dynindx == -1)
 
8182
              loc = (htab->reliplt->contents
 
8183
                     + (htab->reliplt->reloc_count++
 
8184
                        * sizeof (Elf32_External_Rela)));
8070
8185
            else
8071
 
              loc = htab->relplt->contents;
8072
 
            loc += reloc_index * sizeof (Elf32_External_Rela);
 
8186
              loc = (htab->relplt->contents
 
8187
                     + reloc_index * sizeof (Elf32_External_Rela));
8073
8188
            bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
8074
8189
 
8075
8190
            if (!h->def_regular)
8092
8207
                    sym->st_value = 0;
8093
8208
                  }
8094
8209
              }
 
8210
            else if (h->type == STT_GNU_IFUNC
 
8211
                     && !info->shared)
 
8212
              {
 
8213
                /* Set the value of ifunc symbols in a non-pie
 
8214
                   executable to the glink entry.  This is to avoid
 
8215
                   text relocations.  We can't do this for ifunc in
 
8216
                   allocate_dynrelocs, as we do for normal dynamic
 
8217
                   function symbols with plt entries, because we need
 
8218
                   to keep the original value around for the ifunc
 
8219
                   relocation.  */
 
8220
                sym->st_shndx = (_bfd_elf_section_from_bfd_section
 
8221
                                 (output_bfd, htab->glink->output_section));
 
8222
                sym->st_value = (ent->glink_offset +
 
8223
                                 htab->glink->output_offset
 
8224
                                 + htab->glink->output_section->vma);
 
8225
              }
8095
8226
            doneone = TRUE;
8096
8227
          }
8097
8228
 
8098
8229
        if (htab->plt_type == PLT_NEW
8099
 
            || !htab->elf.dynamic_sections_created)
 
8230
            || !htab->elf.dynamic_sections_created
 
8231
            || h->dynindx == -1)
8100
8232
          {
8101
8233
            asection *splt = htab->plt;
8102
 
            if (!htab->elf.dynamic_sections_created)
 
8234
            if (!htab->elf.dynamic_sections_created
 
8235
                || h->dynindx == -1)
8103
8236
              splt = htab->iplt;
8104
8237
 
8105
8238
            write_glink_stub (ent, splt, info);
8106
8239
 
8107
 
            if (!info->shared && !info->pie)
 
8240
            if (!info->shared)
8108
8241
              /* We only need one non-PIC glink stub.  */
8109
8242
              break;
8110
8243
          }
8511
8644
              + htab->glink->output_offset);
8512
8645
 
8513
8646
      /* Last comes the PLTresolve stub.  */
8514
 
      if (info->shared || info->pie)
 
8647
      if (info->shared)
8515
8648
        {
8516
8649
          bfd_vma bcl;
8517
8650