#include "dwarf2.h"
#include "opcode/ppc.h"
+/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
+#define OCTETS_PER_BYTE(ABFD, SEC) 1
+
typedef enum split16_format_type
{
split16a_type = 0,
+ input_section->output_section->vma);
value >>= 16;
- octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+ octets = reloc_entry->address * OCTETS_PER_BYTE (abfd, input_section);
insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
insn &= ~0x1fffc1;
insn |= (value & 0xffc1) | ((value & 0x3e) << 15);
return FALSE;
newsect = hdr->bfd_section;
- flags = bfd_get_section_flags (abfd, newsect);
+ flags = bfd_section_flags (newsect);
if (hdr->sh_flags & SHF_EXCLUDE)
flags |= SEC_EXCLUDE;
if (hdr->sh_type == SHT_ORDERED)
flags |= SEC_SORT_ENTRIES;
- bfd_set_section_flags (abfd, newsect, flags);
+ bfd_set_section_flags (newsect, flags);
return TRUE;
}
/* Set the output section size, if it exists. */
asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
- if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4))
+ if (asec && !bfd_set_section_size (asec, 20 + num_entries * 4))
{
ibfd = abfd;
/* xgettext:c-format */
/* Finally we can generate the output section. */
static void
-ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
+ppc_final_write_processing (bfd *abfd)
{
bfd_byte *buffer;
asection *asec;
apuinfo_list_finish ();
}
+
+static bfd_boolean
+ppc_elf_final_write_processing (bfd *abfd)
+{
+ ppc_final_write_processing (abfd);
+ return _bfd_elf_final_write_processing (abfd);
+}
\f
static bfd_boolean
is_nonpic_glink_stub (bfd *abfd, asection *glink, bfd_vma off)
of the other TLS bits are set. tls_optimize clears bits when
optimizing to indicate the corresponding GOT entry type is not
needed. If set, TLS_TLS is never cleared. tls_optimize may also
- set TLS_TPRELGD when a GD reloc turns into a TPREL one. We use a
- separate flag rather than setting TPREL just for convenience in
- distinguishing the two cases.
+ set TLS_GDIE when a GD reloc turns into an IE one.
These flags are also kept for local symbols. */
#define TLS_TLS 1 /* Any TLS reloc. */
#define TLS_GD 2 /* GD reloc. */
#define TLS_TPREL 8 /* TPREL reloc, => IE. */
#define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
#define TLS_MARK 32 /* __tls_get_addr call marked. */
-#define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
+#define TLS_GDIE 64 /* GOT TPREL reloc resulting from GD->IE. */
unsigned char tls_mask;
/* The above field is also used to mark function symbols. In which
/* Nonzero if this section has TLS related relocations. */
#define has_tls_reloc sec_flg0
-/* Nonzero if this section has a call to __tls_get_addr. */
-#define has_tls_get_addr_call sec_flg1
+/* Nonzero if this section has a call to __tls_get_addr lacking marker
+ relocs. */
+#define nomark_tls_get_addr sec_flg1
/* Flag set when PLTCALL relocs are detected. */
#define has_pltcall sec_flg2
executable. */
flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS
| SEC_IN_MEMORY | SEC_LINKER_CREATED);
- if (!bfd_set_section_flags (abfd, htab->elf.sgot, flags))
+ if (!bfd_set_section_flags (htab->elf.sgot, flags))
return FALSE;
}
if (p2align < htab->params->plt_stub_align)
p2align = htab->params->plt_stub_align;
if (s == NULL
- || !bfd_set_section_alignment (abfd, s, p2align))
+ || !bfd_set_section_alignment (s, p2align))
return FALSE;
if (!info->no_ld_generated_unwind_info)
s = bfd_make_section_anyway_with_flags (abfd, ".eh_frame", flags);
htab->glink_eh_frame = s;
if (s == NULL
- || !bfd_set_section_alignment (abfd, s, 2))
+ || !bfd_set_section_alignment (s, 2))
return FALSE;
}
s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags);
htab->elf.iplt = s;
if (s == NULL
- || !bfd_set_section_alignment (abfd, s, 4))
+ || !bfd_set_section_alignment (s, 4))
return FALSE;
flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
s = bfd_make_section_anyway_with_flags (abfd, ".rela.iplt", flags);
htab->elf.irelplt = s;
if (s == NULL
- || ! bfd_set_section_alignment (abfd, s, 2))
+ || ! bfd_set_section_alignment (s, 2))
return FALSE;
/* Local plt entries. */
htab->pltlocal = bfd_make_section_anyway_with_flags (abfd, ".branch_lt",
flags);
if (htab->pltlocal == NULL
- || ! bfd_set_section_alignment (abfd, htab->pltlocal, 2))
+ || !bfd_set_section_alignment (htab->pltlocal, 2))
return FALSE;
if (bfd_link_pic (info))
htab->relpltlocal
= bfd_make_section_anyway_with_flags (abfd, ".rela.branch_lt", flags);
if (htab->relpltlocal == NULL
- || ! bfd_set_section_alignment (abfd, htab->relpltlocal, 2))
+ || !bfd_set_section_alignment (htab->relpltlocal, 2))
return FALSE;
}
s = bfd_make_section_anyway_with_flags (abfd, ".rela.sbss", flags);
htab->relsbss = s;
if (s == NULL
- || ! bfd_set_section_alignment (abfd, s, 2))
+ || !bfd_set_section_alignment (s, 2))
return FALSE;
}
if (htab->plt_type == PLT_VXWORKS)
/* The VxWorks PLT is a loaded section with contents. */
flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
- return bfd_set_section_flags (abfd, s, flags);
+ return bfd_set_section_flags (s, flags);
}
/* Copy the extra info we tack onto an elf_link_hash_entry. */
linker_section_ptr->lsect = lsect;
*ptr_linker_section_ptr = linker_section_ptr;
- if (!bfd_set_section_alignment (lsect->section->owner, lsect->section, 2))
+ if (!bfd_set_section_alignment (lsect->section, 2))
return FALSE;
linker_section_ptr->offset = lsect->section->size;
lsect->section->size += 4;
;
else
/* Mark this section as having an old-style call. */
- sec->has_tls_get_addr_call = 1;
+ sec->nomark_tls_get_addr = 1;
}
switch (r_type)
/* Indirect .sdata relocation. */
case R_PPC_EMB_SDAI16:
- if (bfd_link_pic (info))
- {
- bad_shared_reloc (abfd, r_type);
- return FALSE;
- }
htab->sdata[0].sym->ref_regular = 1;
if (!elf_allocate_pointer_linker_section (abfd, &htab->sdata[0],
h, rel))
/* Indirect .sdata2 relocation. */
case R_PPC_EMB_SDA2I16:
- if (bfd_link_pic (info))
+ if (!bfd_link_executable (info))
{
bad_shared_reloc (abfd, r_type);
return FALSE;
break;
case R_PPC_EMB_SDA2REL:
- if (bfd_link_pic (info))
+ if (!bfd_link_executable (info))
{
bad_shared_reloc (abfd, r_type);
return FALSE;
case R_PPC_VLE_SDA21:
case R_PPC_EMB_SDA21:
case R_PPC_EMB_RELSDA:
- if (bfd_link_pic (info))
- {
- bad_shared_reloc (abfd, r_type);
- return FALSE;
- }
if (h != NULL)
{
ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
case R_PPC_EMB_NADDR16_LO:
case R_PPC_EMB_NADDR16_HI:
case R_PPC_EMB_NADDR16_HA:
- if (bfd_link_pic (info))
- {
- bad_shared_reloc (abfd, r_type);
- return FALSE;
- }
if (h != NULL)
h->non_got_ref = TRUE;
break;
/* The new PLT is a loaded section. */
if (htab->elf.splt != NULL
- && !bfd_set_section_flags (htab->elf.dynobj, htab->elf.splt, flags))
+ && !bfd_set_section_flags (htab->elf.splt, flags))
return -1;
/* The new GOT is not executable. */
if (htab->elf.sgot != NULL
- && !bfd_set_section_flags (htab->elf.dynobj, htab->elf.sgot, flags))
+ && !bfd_set_section_flags (htab->elf.sgot, flags))
return -1;
}
else
{
/* Stop an unused .glink section from affecting .text alignment. */
if (htab->glink != NULL
- && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
+ && !bfd_set_section_alignment (htab->glink, 0))
return -1;
}
return htab->plt_type == PLT_NEW;
h = (struct elf_link_hash_entry *) h->root.u.i.link;
}
- is_local = FALSE;
- if (h == NULL
- || !h->def_dynamic)
- is_local = TRUE;
-
+ is_local = SYMBOL_REFERENCES_LOCAL (info, h);
r_type = ELF32_R_TYPE (rel->r_info);
/* If this section has old-style __tls_get_addr calls
without marker relocs, then check that each
setup insn. If we don't find matching arg setup
relocs, don't do any tls optimization. */
if (pass == 0
- && sec->has_tls_get_addr_call
+ && sec->nomark_tls_get_addr
&& h != NULL
&& h == htab->tls_get_addr
&& !expecting_tls_get_addr
tls_set = 0;
else
/* GD -> IE */
- tls_set = TLS_TLS | TLS_TPRELGD;
+ tls_set = TLS_TLS | TLS_GDIE;
tls_clear = TLS_GD;
break;
else
continue;
- case R_PPC_TLSGD:
case R_PPC_TLSLD:
+ if (!is_local)
+ continue;
+ /* Fall through. */
+ case R_PPC_TLSGD:
if (rel + 1 < relend
&& is_plt_seq_reloc (ELF32_R_TYPE (rel[1].r_info)))
{
if (pass == 0)
{
if (!expecting_tls_get_addr
- || !sec->has_tls_get_addr_call)
+ || !sec->nomark_tls_get_addr)
continue;
if (rel + 1 < relend
indirect call to __tls_get_addr without a marker.
Disable optimization in this case. */
if ((tls_clear & (TLS_GD | TLS_LD)) != 0
- && !sec->has_tls_get_addr_call
+ && !sec->nomark_tls_get_addr
&& ((*tls_mask & (TLS_TLS | TLS_MARK))
!= (TLS_TLS | TLS_MARK)))
continue;
- if (expecting_tls_get_addr)
+ if (expecting_tls_get_addr == 1 + !sec->nomark_tls_get_addr)
{
struct plt_entry *ent;
bfd_vma addend = 0;
got2, addend);
if (ent != NULL && ent->plt.refcount > 0)
ent->plt.refcount -= 1;
-
- if (expecting_tls_get_addr == 2)
- continue;
}
+ if (tls_clear == 0)
+ continue;
if (tls_set == 0)
{
need = 0;
if ((tls_mask & TLS_GD) != 0)
need += 8;
- if ((tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
+ if ((tls_mask & (TLS_TPREL | TLS_GDIE)) != 0)
need += 4;
if ((tls_mask & TLS_DTPREL) != 0)
need += 4;
return need;
}
-/* Calculate size of relocs needed for symbol given its TLS_MASK and
- NEEDed GOT entries. KNOWN says a TPREL offset can be calculated at
- link time. */
-
-static inline unsigned int
-got_relocs_needed (int tls_mask, unsigned int need, bfd_boolean known)
-{
- /* All the entries we allocated need relocs.
- Except IE in executable with a local symbol. We could also omit
- the DTPREL reloc on the second word of a GD entry under the same
- condition as that for IE, but ld.so needs to differentiate
- LD and GD entries. */
- if (known && (tls_mask & TLS_TLS) != 0
- && (tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
- need -= 4;
- return need * sizeof (Elf32_External_Rela) / 4;
-}
-
/* If H is undefined, make it dynamic if that makes sense. */
static bfd_boolean
need = 0;
if ((eh->tls_mask & (TLS_TLS | TLS_LD)) == (TLS_TLS | TLS_LD))
{
- if (!eh->elf.def_dynamic)
+ if (SYMBOL_REFERENCES_LOCAL (info, &eh->elf))
/* We'll just use htab->tlsld_got.offset. This should
always be the case. It's a little odd if we have
a local dynamic reloc against a non-local symbol. */
else
{
eh->elf.got.offset = allocate_got (htab, need);
- if ((bfd_link_pic (info)
+ if (((bfd_link_pic (info)
+ && !((eh->tls_mask & TLS_TLS) != 0
+ && bfd_link_executable (info)
+ && SYMBOL_REFERENCES_LOCAL (info, &eh->elf)))
|| (htab->elf.dynamic_sections_created
&& eh->elf.dynindx != -1
&& !SYMBOL_REFERENCES_LOCAL (info, &eh->elf)))
&& !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &eh->elf))
{
asection *rsec;
- bfd_boolean tprel_known = (bfd_link_executable (info)
- && SYMBOL_REFERENCES_LOCAL (info,
- &eh->elf));
- need = got_relocs_needed (eh->tls_mask, need, tprel_known);
- if ((eh->tls_mask & (TLS_TLS | TLS_LD)) == (TLS_TLS | TLS_LD)
- && eh->elf.def_dynamic)
+ need *= sizeof (Elf32_External_Rela) / 4;
+ if ((eh->tls_mask & (TLS_TLS | TLS_LD)) == (TLS_TLS | TLS_LD))
need -= sizeof (Elf32_External_Rela);
rsec = htab->elf.srelgot;
if (eh->elf.type == STT_GNU_IFUNC)
else
{
*local_got = allocate_got (htab, need);
- if (bfd_link_pic (info))
+ if (bfd_link_pic (info)
+ && !((*lgot_masks & TLS_TLS) != 0
+ && bfd_link_executable (info)))
{
asection *srel;
- bfd_boolean tprel_known = bfd_link_executable (info);
- need = got_relocs_needed (*lgot_masks, need, tprel_known);
+ need *= sizeof (Elf32_External_Rela) / 4;
srel = htab->elf.srelgot;
if ((*lgot_masks & (TLS_TLS | PLT_IFUNC)) == PLT_IFUNC)
srel = htab->elf.irelplt;
if (htab->tlsld_got.refcount > 0)
{
htab->tlsld_got.offset = allocate_got (htab, 8);
- if (bfd_link_pic (info))
+ if (bfd_link_dll (info))
htab->elf.srelgot->size += sizeof (Elf32_External_Rela);
}
else
{
strip_section = (s->flags & SEC_KEEP) == 0;
}
- else if (CONST_STRNEQ (bfd_get_section_name (htab->elf.dynobj, s),
- ".rela"))
+ else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
{
if (s->size != 0)
{
case R_PPC_GOT_TLSGD16_HI:
case R_PPC_GOT_TLSGD16_HA:
- tls_gd = TLS_TPRELGD;
+ tls_gd = TLS_GDIE;
if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
goto tls_gdld_hi;
break;
case R_PPC_GOT_TLSGD16:
case R_PPC_GOT_TLSGD16_LO:
- tls_gd = TLS_TPRELGD;
+ tls_gd = TLS_GDIE;
if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
goto tls_ldgd_opt;
break;
stays with its arg setup insns, ie. that the next
reloc is the __tls_get_addr call associated with
the current reloc. Edit both insns. */
- if (input_section->has_tls_get_addr_call
+ if (input_section->nomark_tls_get_addr
&& rel + 1 < relend
&& branch_reloc_hash_match (input_bfd, rel + 1,
htab->tls_get_addr))
break;
}
- if ((tls_mask & TLS_TPRELGD) != 0)
+ if ((tls_mask & TLS_GDIE) != 0)
{
/* IE */
r_type = R_PPC_NONE;
indx = 0;
if (tls_type == (TLS_TLS | TLS_LD)
- && (h == NULL
- || !h->def_dynamic))
+ && SYMBOL_REFERENCES_LOCAL (info, h))
offp = &htab->tlsld_got.offset;
else if (h != NULL)
{
{
unsigned int tls_m = ((tls_mask & TLS_TLS) != 0
? tls_mask & (TLS_LD | TLS_GD | TLS_DTPREL
- | TLS_TPREL | TLS_TPRELGD)
+ | TLS_TPREL | TLS_GDIE)
: 0);
if (offp == &htab->tlsld_got.offset)
tls_m = TLS_LD;
- else if (h == NULL
- || !h->def_dynamic)
+ else if ((tls_m & TLS_LD) != 0
+ && SYMBOL_REFERENCES_LOCAL (info, h))
tls_m &= ~TLS_LD;
/* We might have multiple got entries for this sym.
tls_ty = TLS_TLS | TLS_DTPREL;
tls_m &= ~TLS_DTPREL;
}
- else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
+ else if ((tls_m & (TLS_TPREL | TLS_GDIE)) != 0)
{
tls_ty = TLS_TLS | TLS_TPREL;
tls_m = 0;
if (indx != 0
|| (bfd_link_pic (info)
&& (h == NULL
- || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)
- || offp == &htab->tlsld_got.offset)
- && !(tls_ty == (TLS_TLS | TLS_TPREL)
+ || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
+ && !(tls_ty != 0
&& bfd_link_executable (info)
&& SYMBOL_REFERENCES_LOCAL (info, h))))
{
if (tls_type != (TLS_TLS | TLS_LD))
{
if ((tls_mask & TLS_LD) != 0
- && !(h == NULL
- || !h->def_dynamic))
+ && !SYMBOL_REFERENCES_LOCAL (info, h))
off += 8;
if (tls_type != (TLS_TLS | TLS_GD))
{
outrel.r_offset += (input_section->output_section->vma
+ input_section->output_offset);
+ /* Optimize unaligned reloc use. */
+ if ((r_type == R_PPC_ADDR32 && (outrel.r_offset & 3) != 0)
+ || (r_type == R_PPC_UADDR32 && (outrel.r_offset & 3) == 0))
+ r_type ^= R_PPC_ADDR32 ^ R_PPC_UADDR32;
+ if ((r_type == R_PPC_ADDR16 && (outrel.r_offset & 1) != 0)
+ || (r_type == R_PPC_UADDR16 && (outrel.r_offset & 1) == 0))
+ r_type ^= R_PPC_ADDR16 ^ R_PPC_UADDR16;
+
if (skip)
memset (&outrel, 0, sizeof outrel);
else if (!SYMBOL_REFERENCES_LOCAL (info, h))
but ld.so expects buggy relocs.
FIXME: Why not always use a zero index? */
osec = sec->output_section;
- indx = elf_section_data (osec)->dynindx;
- if (indx == 0)
+ if ((osec->flags & SEC_THREAD_LOCAL) != 0)
+ {
+ osec = htab->elf.tls_sec;
+ indx = 0;
+ }
+ else
{
- osec = htab->elf.text_index_section;
indx = elf_section_data (osec)->dynindx;
+ if (indx == 0)
+ {
+ osec = htab->elf.text_index_section;
+ indx = elf_section_data (osec)->dynindx;
+ }
+ BFD_ASSERT (indx != 0);
}
- BFD_ASSERT (indx != 0);
-#ifdef DEBUG
- if (indx == 0)
- printf ("indx=%ld section=%s flags=%08x name=%s\n",
- indx, osec->name, osec->flags,
- h->root.root.string);
-#endif
+
+ /* ld.so doesn't expect buggy TLS relocs.
+ Don't leave the symbol value in the
+ addend for them. */
+ if (IS_PPC_TLS_RELOC (r_type))
+ outrel.r_addend -= osec->vma;
}
outrel.r_info = ELF32_R_INFO (indx, r_type);
unresolved_reloc = TRUE;
break;
}
- BFD_ASSERT (strcmp (bfd_get_section_name (sec->owner, sec),
- ".got") == 0
- || strcmp (bfd_get_section_name (sec->owner, sec),
- ".cgot") == 0);
+ BFD_ASSERT (strcmp (bfd_section_name (sec), ".got") == 0
+ || strcmp (bfd_section_name (sec), ".cgot") == 0);
addend -= sec->output_section->vma + sec->output_offset + 0x8000;
break;
}
addend -= SYM_VAL (sda);
- name = bfd_get_section_name (output_bfd, sec->output_section);
+ name = bfd_section_name (sec->output_section);
if (!(strcmp (name, ".sdata") == 0
|| strcmp (name, ".sbss") == 0))
{
}
addend -= SYM_VAL (sda);
- name = bfd_get_section_name (output_bfd, sec->output_section);
+ name = bfd_section_name (sec->output_section);
if (!(strcmp (name, ".sdata2") == 0
|| strcmp (name, ".sbss2") == 0))
{
break;
}
- name = bfd_get_section_name (output_bfd, sec->output_section);
+ name = bfd_section_name (sec->output_section);
if (strcmp (name, ".sdata") == 0
|| strcmp (name, ".sbss") == 0)
{
break;
}
- name = bfd_get_section_name (output_bfd, sec->output_section);
+ name = bfd_section_name (sec->output_section);
if (strcmp (name, ".sdata") == 0
|| strcmp (name, ".sbss") == 0)
sda = htab->sdata[0].sym;
return ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp);
}
-static void
-ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
+static bfd_boolean
+ppc_elf_vxworks_final_write_processing (bfd *abfd)
{
- ppc_elf_final_write_processing (abfd, linker);
- elf_vxworks_final_write_processing (abfd, linker);
+ ppc_final_write_processing (abfd);
+ return elf_vxworks_final_write_processing (abfd);
}
/* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
#undef elf32_bed
#define elf32_bed ppc_elf_vxworks_bed
-#undef elf_backend_post_process_headers
#include "elf32-target.h"