+ break;
+
+ case R_386_TLS_GD:
+ case R_386_TLS_IE_32:
+ r_type = elf_i386_tls_transition (info, r_type, h == NULL);
+ tls_type = GOT_UNKNOWN;
+ if (h == NULL && local_got_offsets)
+ tls_type = elf_i386_local_got_tls_type (input_bfd) [r_symndx];
+ else if (h != NULL)
+ {
+ tls_type = elf_i386_hash_entry(h)->tls_type;
+ if (!info->shared && h->dynindx == -1 && tls_type == GOT_TLS_IE)
+ r_type = R_386_TLS_LE_32;
+ }
+ if (r_type == R_386_TLS_GD && tls_type == GOT_TLS_IE)
+ r_type = R_386_TLS_IE_32;
+
+ if (r_type == R_386_TLS_LE_32)
+ {
+ BFD_ASSERT (unresolved_reloc == false);
+ if (ELF32_R_TYPE (rel->r_info) == R_386_TLS_GD)
+ {
+ unsigned int val, type;
+ bfd_vma roff;
+
+ /* GD->LE transition. */
+ BFD_ASSERT (rel->r_offset >= 2);
+ type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
+ BFD_ASSERT (type == 0x8d || type == 0x04);
+ BFD_ASSERT (rel->r_offset + 9 <= input_section->_raw_size);
+ BFD_ASSERT (bfd_get_8 (input_bfd,
+ contents + rel->r_offset + 4)
+ == 0xe8);
+ BFD_ASSERT (rel + 1 < relend);
+ BFD_ASSERT (ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32);
+ roff = rel->r_offset + 5;
+ val = bfd_get_8 (input_bfd,
+ contents + rel->r_offset - 1);
+ if (type == 0x04)
+ {
+ /* leal foo(,%reg,1), %eax; call ___tls_get_addr
+ Change it into:
+ movl %gs:0, %eax; subl $foo@tpoff, %eax
+ (6 byte form of subl). */
+ BFD_ASSERT (rel->r_offset >= 3);
+ BFD_ASSERT (bfd_get_8 (input_bfd,
+ contents + rel->r_offset - 3)
+ == 0x8d);
+ BFD_ASSERT ((val & 0xc7) == 0x05 && val != (4 << 3));
+ memcpy (contents + rel->r_offset - 3,
+ "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
+ }
+ else
+ {
+ BFD_ASSERT ((val & 0xf8) == 0x80 && (val & 7) != 4);
+ if (rel->r_offset + 10 <= input_section->_raw_size
+ && bfd_get_8 (input_bfd,
+ contents + rel->r_offset + 9) == 0x90)
+ {
+ /* leal foo(%reg), %eax; call ___tls_get_addr; nop
+ Change it into:
+ movl %gs:0, %eax; subl $foo@tpoff, %eax
+ (6 byte form of subl). */
+ memcpy (contents + rel->r_offset - 2,
+ "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
+ roff = rel->r_offset + 6;
+ }
+ else
+ {
+ /* leal foo(%reg), %eax; call ___tls_get_addr
+ Change it into:
+ movl %gs:0, %eax; subl $foo@tpoff, %eax
+ (5 byte form of subl). */
+ memcpy (contents + rel->r_offset - 2,
+ "\x65\xa1\0\0\0\0\x2d\0\0\0", 11);
+ }
+ }
+ bfd_put_32 (output_bfd, tpoff (info, relocation),
+ contents + roff);
+ /* Skip R_386_PLT32. */
+ rel++;
+ continue;
+ }
+ else
+ {
+ unsigned int val, type;
+
+ /* IE->LE transition:
+ Originally it can be either:
+ subl foo(%reg1), %reg2
+ or
+ movl foo(%reg1), %reg2
+ We change it into:
+ subl $foo, %reg2
+ or
+ movl $foo, %reg2 (6 byte form) */
+ BFD_ASSERT (rel->r_offset >= 2);
+ type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
+ val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
+ BFD_ASSERT (rel->r_offset + 4 <= input_section->_raw_size);
+ if (type == 0x8b)
+ {
+ /* movl */
+ BFD_ASSERT ((val & 0xc0) == 0x80 && (val & 7) != 4);
+ bfd_put_8 (output_bfd, 0xc7,
+ contents + rel->r_offset - 2);
+ bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
+ contents + rel->r_offset - 1);
+ }
+ else if (type == 0x2b)
+ {
+ /* subl */
+ BFD_ASSERT ((val & 0xc0) == 0x80 && (val & 7) != 4);
+ bfd_put_8 (output_bfd, 0x81,
+ contents + rel->r_offset - 2);
+ bfd_put_8 (output_bfd, 0xe8 | ((val >> 3) & 7),
+ contents + rel->r_offset - 1);
+ }
+ else
+ BFD_FAIL ();
+ bfd_put_32 (output_bfd, tpoff (info, relocation),
+ contents + rel->r_offset);
+ continue;
+ }
+ }
+
+ if (htab->sgot == NULL)
+ abort ();
+
+ if (h != NULL)
+ off = h->got.offset;
+ else
+ {
+ if (local_got_offsets == NULL)
+ abort ();
+
+ off = local_got_offsets[r_symndx];
+ }
+
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ Elf_Internal_Rel outrel;
+ Elf32_External_Rel *loc;
+ int dr_type, indx;
+
+ if (htab->srelgot == NULL)
+ abort ();
+
+ outrel.r_offset = (htab->sgot->output_section->vma
+ + htab->sgot->output_offset + off);
+
+ bfd_put_32 (output_bfd, 0,
+ htab->sgot->contents + off);
+ indx = h && h->dynindx != -1 ? h->dynindx : 0;
+ if (r_type == R_386_TLS_GD)
+ dr_type = R_386_TLS_DTPMOD32;
+ else
+ dr_type = R_386_TLS_TPOFF32;
+ outrel.r_info = ELF32_R_INFO (indx, dr_type);
+ loc = (Elf32_External_Rel *) htab->srelgot->contents;
+ loc += htab->srelgot->reloc_count++;
+ bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+
+ if (r_type == R_386_TLS_GD)
+ {
+ if (indx == 0)
+ {
+ BFD_ASSERT (unresolved_reloc == false);
+ bfd_put_32 (output_bfd,
+ relocation - dtpoff_base (info),
+ htab->sgot->contents + off + 4);
+ }
+ else
+ {
+ bfd_put_32 (output_bfd, 0,
+ htab->sgot->contents + off + 4);
+ outrel.r_info = ELF32_R_INFO (indx,
+ R_386_TLS_DTPOFF32);
+ outrel.r_offset += 4;
+ htab->srelgot->reloc_count++;
+ loc++;
+ bfd_elf32_swap_reloc_out (output_bfd, &outrel,
+ loc);
+ }
+ }
+
+ if (h != NULL)
+ h->got.offset |= 1;
+ else
+ local_got_offsets[r_symndx] |= 1;
+ }
+
+ if (off >= (bfd_vma) -2)
+ abort ();
+ if (r_type == ELF32_R_TYPE (rel->r_info))
+ {
+ relocation = htab->sgot->output_offset + off;
+ unresolved_reloc = false;
+ }
+ else
+ {
+ unsigned int val, type;
+ bfd_vma roff;
+
+ /* GD->IE transition. */
+ BFD_ASSERT (rel->r_offset >= 2);
+ type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
+ BFD_ASSERT (type == 0x8d || type == 0x04);
+ BFD_ASSERT (rel->r_offset + 9 <= input_section->_raw_size);
+ BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset + 4)
+ == 0xe8);
+ BFD_ASSERT (rel + 1 < relend);
+ BFD_ASSERT (ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32);
+ roff = rel->r_offset - 3;
+ val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
+ if (type == 0x04)
+ {
+ /* leal foo(,%reg,1), %eax; call ___tls_get_addr
+ Change it into:
+ movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
+ BFD_ASSERT (rel->r_offset >= 3);
+ BFD_ASSERT (bfd_get_8 (input_bfd,
+ contents + rel->r_offset - 3)
+ == 0x8d);
+ BFD_ASSERT ((val & 0xc7) == 0x05 && val != (4 << 3));
+ val >>= 3;
+ }
+ else
+ {
+ /* leal foo(%reg), %eax; call ___tls_get_addr; nop
+ Change it into:
+ movl %gs:0, %eax; subl $foo@gottpoff(%reg), %eax. */
+ BFD_ASSERT (rel->r_offset + 10 <= input_section->_raw_size);
+ BFD_ASSERT ((val & 0xf8) == 0x80 && (val & 7) != 4);
+ BFD_ASSERT (bfd_get_8 (input_bfd,
+ contents + rel->r_offset + 9)
+ == 0x90);
+ roff = rel->r_offset - 2;
+ }
+ memcpy (contents + roff,
+ "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
+ contents[roff + 7] = 0x80 | (val & 7);
+ bfd_put_32 (output_bfd, htab->sgot->output_offset + off,
+ contents + roff + 8);
+ /* Skip R_386_PLT32. */
+ rel++;
+ continue;
+ }
+ break;
+
+ case R_386_TLS_LDM:
+ if (! info->shared)
+ {
+ unsigned int val;
+
+ /* LD->LE transition:
+ Ensure it is:
+ leal foo(%reg), %eax; call ___tls_get_addr.
+ We change it into:
+ movl %gs:0, %eax; nop; leal 0(%esi,1), %esi. */
+ BFD_ASSERT (rel->r_offset >= 2);
+ BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 2)
+ == 0x8d);
+ val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
+ BFD_ASSERT ((val & 0xf8) == 0x80 && (val & 7) != 4);
+ BFD_ASSERT (rel->r_offset + 9 <= input_section->_raw_size);
+ BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset + 4)
+ == 0xe8);
+ BFD_ASSERT (rel + 1 < relend);
+ BFD_ASSERT (ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32);
+ memcpy (contents + rel->r_offset - 2,
+ "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
+ /* Skip R_386_PLT32. */
+ rel++;
+ continue;
+ }
+
+ if (htab->sgot == NULL)
+ abort ();
+
+ off = htab->tls_ldm_got.offset;
+ if (off & 1)
+ off &= ~1;
+ else
+ {
+ Elf_Internal_Rel outrel;
+ Elf32_External_Rel *loc;
+
+ if (htab->srelgot == NULL)
+ abort ();