This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Cache the .MIPS.stubs section
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: binutils at sourceware dot org
- Date: Sat, 28 Jun 2008 17:30:37 +0100
- Subject: [PATCH] Cache the .MIPS.stubs section
Most special sections are cached in the mips_elf_link_hash_table
for quick access. This patch does the same for the .MIPS.stubs section.
It also avoids allocating a dummy stub if there are no stubs for it to
protect.
_bfd_mips_elf_create_dynamic_sections currently protects against the
case where .MIPS.stubs already exists:
if (bfd_get_section_by_name (abfd,
MIPS_ELF_STUB_SECTION_NAME (abfd)) == NULL)
...
We don't do this for other special sections, and I think it's
more robust not to. Silently ignoring an existing section is
only going to make things worse later, where we assume we have
full control over the section's contents.
Tested on mips64-linux-gnu and mips64el-linux-gnu. OK to install?
Richard
bfd/
* elfxx-mips.c (mips_elf_link_hash_table): Add an "sstubs" field.
(_bfd_mips_elf_create_dynamic_sections): Use it to cache the stubs
section. Don't check whether the section already exists.
(_bfd_mips_elf_adjust_dynamic_symbol): Use htab->sstubs.
(_bfd_mips_elf_finish_dynamic_symbol): Likewise.
(_bfd_mips_elf_finish_dynamic_sections): Likewise.
(_bfd_mips_elf_size_dynamic_sections): Likewise. Don't add the
dummy stub to an empty section.
(_bfd_mips_elf_link_hash_table_create): Initialize the "sstubs" field.
ld/testsuite/
* ld-mips-elf/tls-hidden3.ld: Remove the unused .MIPS.stubs section.
Keep the text start address the same.
* ld-mips-elf/tls-multi-got-1.got: We have removed a .MIPS.stubs
section that contained only a 16-byte dummy stub. Subtract 16
from addresses to account for the change.
* ld-mips-elf/tls-multi-got-1.r: Likewise. Adjust MIPS_UNREFEXTNO
to account the removed section symbol.
* ld-mips-elf/tlsdyn-o32-1.d: We have deleted a .MIPS.stubs
section that contained only a 16-byte dummy stub. Remove it
from the disassembly.
* ld-mips-elf/tlsdyn-o32-2.d: Likewise.
* ld-mips-elf/tlsdyn-o32-3.d: Likewise.
* ld-mips-elf/tlsdyn-o32.d: Likewise.
* ld-mips-elf/relax-jalr-n32-shared.d: Likewise.
* ld-mips-elf/relax-jalr-n64-shared.d: Likewise.
Index: bfd/elfxx-mips.c
===================================================================
--- bfd/elfxx-mips.c 2008-06-28 17:14:17.000000000 +0100
+++ bfd/elfxx-mips.c 2008-06-28 17:14:30.000000000 +0100
@@ -363,6 +363,7 @@ struct mips_elf_link_hash_table
asection *srelplt2;
asection *sgotplt;
asection *splt;
+ asection *sstubs;
/* The size of the PLT header in bytes (VxWorks only). */
bfd_vma plt_header_size;
/* The size of a PLT entry in bytes (VxWorks only). */
@@ -6328,17 +6329,14 @@ _bfd_mips_elf_create_dynamic_sections (b
return FALSE;
/* Create .stub section. */
- if (bfd_get_section_by_name (abfd,
- MIPS_ELF_STUB_SECTION_NAME (abfd)) == NULL)
- {
- s = bfd_make_section_with_flags (abfd,
- MIPS_ELF_STUB_SECTION_NAME (abfd),
- flags | SEC_CODE);
- if (s == NULL
- || ! bfd_set_section_alignment (abfd, s,
- MIPS_ELF_LOG_FILE_ALIGN (abfd)))
- return FALSE;
- }
+ s = bfd_make_section_with_flags (abfd,
+ MIPS_ELF_STUB_SECTION_NAME (abfd),
+ flags | SEC_CODE);
+ if (s == NULL
+ || ! bfd_set_section_alignment (abfd, s,
+ MIPS_ELF_LOG_FILE_ALIGN (abfd)))
+ return FALSE;
+ htab->sstubs = s;
if ((IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none)
&& !info->shared
@@ -7483,7 +7481,6 @@ _bfd_mips_elf_adjust_dynamic_symbol (str
{
bfd *dynobj;
struct mips_elf_link_hash_entry *hmips;
- asection *s;
struct mips_elf_link_hash_table *htab;
htab = mips_elf_hash_table (info);
@@ -7528,18 +7525,14 @@ _bfd_mips_elf_adjust_dynamic_symbol (str
if (!h->def_regular)
{
/* We need .stub section. */
- s = bfd_get_section_by_name (dynobj,
- MIPS_ELF_STUB_SECTION_NAME (dynobj));
- BFD_ASSERT (s != NULL);
-
- h->root.u.def.section = s;
- h->root.u.def.value = s->size;
+ h->root.u.def.section = htab->sstubs;
+ h->root.u.def.value = htab->sstubs->size;
/* XXX Write this stub address somewhere. */
- h->plt.offset = s->size;
+ h->plt.offset = htab->sstubs->size;
/* Make room for this stub code. */
- s->size += htab->function_stub_size;
+ htab->sstubs->size += htab->function_stub_size;
/* The last half word of the stub will be filled with the index
of this symbol in .dynsym section. */
@@ -7904,7 +7897,12 @@ _bfd_mips_elf_size_dynamic_sections (bfd
s->contents
= (bfd_byte *) ELF_DYNAMIC_INTERPRETER (output_bfd);
}
- }
+ }
+
+ /* IRIX rld assumes that the function stub isn't at the end
+ of the .text section, so add a dummy entry to the end. */
+ if (htab->sstubs && htab->sstubs->size > 0)
+ htab->sstubs->size += htab->function_stub_size;
/* The check_relocs and adjust_dynamic_symbol entry points have
determined the sizes of the various dynamic sections. Allocate
@@ -8042,12 +8040,6 @@ _bfd_mips_elf_size_dynamic_sections (bfd
mips_elf_allocate_dynamic_relocations (dynobj, info,
needed_relocs);
}
- else if (strcmp (name, MIPS_ELF_STUB_SECTION_NAME (output_bfd)) == 0)
- {
- /* IRIX rld assumes that the function stub isn't at the end
- of .text section. So put a dummy. XXX */
- s->size += htab->function_stub_size;
- }
else if (! info->shared
&& ! mips_elf_hash_table (info)->use_rld_obj_head
&& CONST_STRNEQ (name, ".rld_map"))
@@ -8061,7 +8053,8 @@ _bfd_mips_elf_size_dynamic_sections (bfd
s->size += mips_elf_hash_table (info)->compact_rel_size;
else if (! CONST_STRNEQ (name, ".init")
&& s != htab->sgotplt
- && s != htab->splt)
+ && s != htab->splt
+ && s != htab->sstubs)
{
/* It's not one of our sections, so don't allocate space. */
continue;
@@ -8683,17 +8676,12 @@ _bfd_mips_elf_finish_dynamic_symbol (bfd
if (h->plt.offset != MINUS_ONE)
{
- asection *s;
bfd_byte stub[MIPS_FUNCTION_STUB_BIG_SIZE];
/* This symbol has a stub. Set it up. */
BFD_ASSERT (h->dynindx != -1);
- s = bfd_get_section_by_name (dynobj,
- MIPS_ELF_STUB_SECTION_NAME (dynobj));
- BFD_ASSERT (s != NULL);
-
BFD_ASSERT ((htab->function_stub_size == MIPS_FUNCTION_STUB_BIG_SIZE)
|| (h->dynindx <= 0xffff));
@@ -8728,8 +8716,9 @@ _bfd_mips_elf_finish_dynamic_symbol (bfd
bfd_put_32 (output_bfd, STUB_LI16S (output_bfd, h->dynindx),
stub + idx);
- BFD_ASSERT (h->plt.offset <= s->size);
- memcpy (s->contents + h->plt.offset, stub, htab->function_stub_size);
+ BFD_ASSERT (h->plt.offset <= htab->sstubs->size);
+ memcpy (htab->sstubs->contents + h->plt.offset,
+ stub, htab->function_stub_size);
/* Mark the symbol as undefined. plt.offset != -1 occurs
only for the referenced symbol. */
@@ -8738,7 +8727,8 @@ _bfd_mips_elf_finish_dynamic_symbol (bfd
/* The run-time linker uses the st_value field of the symbol
to reset the global offset table entry for this external
to its stub address when unlinking a shared object. */
- sym->st_value = (s->output_section->vma + s->output_offset
+ sym->st_value = (htab->sstubs->output_section->vma
+ + htab->sstubs->output_offset
+ h->plt.offset);
}
@@ -9553,15 +9543,13 @@ _bfd_mips_elf_finish_dynamic_sections (b
s->contents));
/* Clean up a dummy stub function entry in .text. */
- s = bfd_get_section_by_name (dynobj,
- MIPS_ELF_STUB_SECTION_NAME (dynobj));
- if (s != NULL)
+ if (htab->sstubs != NULL)
{
file_ptr dummy_offset;
- BFD_ASSERT (s->size >= htab->function_stub_size);
- dummy_offset = s->size - htab->function_stub_size;
- memset (s->contents + dummy_offset, 0,
+ BFD_ASSERT (htab->sstubs->size >= htab->function_stub_size);
+ dummy_offset = htab->sstubs->size - htab->function_stub_size;
+ memset (htab->sstubs->contents + dummy_offset, 0,
htab->function_stub_size);
}
}
@@ -10740,6 +10728,7 @@ _bfd_mips_elf_link_hash_table_create (bf
ret->srelplt2 = NULL;
ret->sgotplt = NULL;
ret->splt = NULL;
+ ret->sstubs = NULL;
ret->plt_header_size = 0;
ret->plt_entry_size = 0;
ret->function_stub_size = 0;
Index: ld/testsuite/ld-mips-elf/tls-hidden3.ld
===================================================================
--- ld/testsuite/ld-mips-elf/tls-hidden3.ld 2008-06-28 17:09:16.000000000 +0100
+++ ld/testsuite/ld-mips-elf/tls-hidden3.ld 2008-06-28 17:14:30.000000000 +0100
@@ -9,10 +9,7 @@ SECTIONS
. = ALIGN (0x400);
.rel.dyn : { *(.rel.dyn) }
- . = ALIGN (0x400);
- .MIPS.stubs : { *(.MIPS.stubs) }
-
- . = ALIGN (0x400);
+ . = ALIGN (0x400) + 0x400;
.text : { *(.text) }
. = ALIGN (0x10000);
Index: ld/testsuite/ld-mips-elf/tls-multi-got-1.got
===================================================================
--- ld/testsuite/ld-mips-elf/tls-multi-got-1.got 2008-06-28 17:09:16.000000000 +0100
+++ ld/testsuite/ld-mips-elf/tls-multi-got-1.got 2008-06-28 17:14:30.000000000 +0100
@@ -4,33 +4,33 @@
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
00000000 R_MIPS_NONE \*ABS\*
-0013f840 R_MIPS_TLS_DTPMOD32 \*ABS\*
-0014949c R_MIPS_TLS_DTPMOD32 \*ABS\*
-0013f84c R_MIPS_TLS_DTPMOD32 tlsvar_gd
-0013f850 R_MIPS_TLS_DTPREL32 tlsvar_gd
-001494a8 R_MIPS_TLS_DTPMOD32 tlsvar_gd
-001494ac R_MIPS_TLS_DTPREL32 tlsvar_gd
-0013f848 R_MIPS_TLS_TPREL32 tlsvar_ie
-001494a4 R_MIPS_TLS_TPREL32 tlsvar_ie
-00143e48 R_MIPS_REL32 sym_1_9526
+0013f830 R_MIPS_TLS_DTPMOD32 \*ABS\*
+0014948c R_MIPS_TLS_DTPMOD32 \*ABS\*
+0013f83c R_MIPS_TLS_DTPMOD32 tlsvar_gd
+0013f840 R_MIPS_TLS_DTPREL32 tlsvar_gd
+00149498 R_MIPS_TLS_DTPMOD32 tlsvar_gd
+0014949c R_MIPS_TLS_DTPREL32 tlsvar_gd
+0013f838 R_MIPS_TLS_TPREL32 tlsvar_ie
+00149494 R_MIPS_TLS_TPREL32 tlsvar_ie
+00143e38 R_MIPS_REL32 sym_1_9526
#...
-00139ac8 R_MIPS_REL32 sym_2_8654
+00139ab8 R_MIPS_REL32 sym_2_8654
Contents of section .got:
- 122370 00000000 80000000 000d7f98 000d65f4 .*
- 122380 000d1fa4 000d6010 000d5a48 000d19c0 .*
+ 122360 00000000 80000000 000d7f98 000d65f4 .*
+ 122370 000d1fa4 000d6010 000d5a48 000d19c0 .*
#...
- 135bf0 000cf204 000e0e48 00000000 80000000 .*
- 135c00 00000000 00000000 00000000 00000000 .*
+ 135be0 000cf204 000e0e48 00000000 80000000 .*
+ 135bf0 00000000 00000000 00000000 00000000 .*
#...
+ 13f820 00000000 00000000 00000000 00000000 .*
13f830 00000000 00000000 00000000 00000000 .*
- 13f840 00000000 00000000 00000000 00000000 .*
- 13f850 00000000 00000000 80000000 00000000 .*
+ 13f840 00000000 00000000 80000000 00000000 .*
#...
+ 149450 00000000 00000000 00000000 00000000 .*
149460 00000000 00000000 00000000 00000000 .*
149470 00000000 00000000 00000000 00000000 .*
149480 00000000 00000000 00000000 00000000 .*
149490 00000000 00000000 00000000 00000000 .*
- 1494a0 00000000 00000000 00000000 00000000 .*
#pass
Index: ld/testsuite/ld-mips-elf/tls-multi-got-1.r
===================================================================
--- ld/testsuite/ld-mips-elf/tls-multi-got-1.r 2008-06-28 17:09:16.000000000 +0100
+++ ld/testsuite/ld-mips-elf/tls-multi-got-1.r 2008-06-28 17:14:30.000000000 +0100
@@ -6,7 +6,7 @@ Dynamic section at offset .* contains 18
0x00000006 \(SYMTAB\).*
0x0000000a \(STRSZ\) 220091 \(bytes\)
0x0000000b \(SYMENT\) 16 \(bytes\)
- 0x00000003 \(PLTGOT\) 0x122370
+ 0x00000003 \(PLTGOT\) 0x122360
0x00000011 \(REL\) 0xa7978
0x00000012 \(RELSZ\) 160072 \(bytes\)
0x00000013 \(RELENT\) 8 \(bytes\)
@@ -15,7 +15,7 @@ Dynamic section at offset .* contains 18
0x70000006 \(MIPS_BASE_ADDRESS\) 0
0x7000000a \(MIPS_LOCAL_GOTNO\) 2
0x70000011 \(MIPS_SYMTABNO\) 20013
- 0x70000012 \(MIPS_UNREFEXTNO\) 11
+ 0x70000012 \(MIPS_UNREFEXTNO\) 10
0x70000013 \(MIPS_GOTSYM\) 0xd
0x0000001e \(FLAGS\) STATIC_TLS
0x00000000 \(NULL\) 0x0
Index: ld/testsuite/ld-mips-elf/tlsdyn-o32-1.d
===================================================================
--- ld/testsuite/ld-mips-elf/tlsdyn-o32-1.d 2008-06-28 17:09:16.000000000 +0100
+++ ld/testsuite/ld-mips-elf/tlsdyn-o32-1.d 2008-06-28 17:14:30.000000000 +0100
@@ -98,7 +98,3 @@ Disassembly of section .text:
.*: 03e00008 jr ra
.*: 27bd0010 addiu sp,sp,16
.*: 00000000 nop
-Disassembly of section .MIPS.stubs:
-
-.* <.MIPS.stubs>:
- ...
Index: ld/testsuite/ld-mips-elf/tlsdyn-o32-2.d
===================================================================
--- ld/testsuite/ld-mips-elf/tlsdyn-o32-2.d 2008-06-28 17:09:16.000000000 +0100
+++ ld/testsuite/ld-mips-elf/tlsdyn-o32-2.d 2008-06-28 17:14:30.000000000 +0100
@@ -98,7 +98,3 @@ Disassembly of section .text:
.*: 03e00008 jr ra
.*: 27bd0010 addiu sp,sp,16
.*: 00000000 nop
-Disassembly of section .MIPS.stubs:
-
-.* <.MIPS.stubs>:
- ...
Index: ld/testsuite/ld-mips-elf/tlsdyn-o32-3.d
===================================================================
--- ld/testsuite/ld-mips-elf/tlsdyn-o32-3.d 2008-06-28 17:09:16.000000000 +0100
+++ ld/testsuite/ld-mips-elf/tlsdyn-o32-3.d 2008-06-28 17:14:30.000000000 +0100
@@ -98,7 +98,3 @@ Disassembly of section .text:
.*: 03e00008 jr ra
.*: 00000000 nop
...
-Disassembly of section .MIPS.stubs:
-
-.* <.MIPS.stubs>:
- ...
Index: ld/testsuite/ld-mips-elf/tlsdyn-o32.d
===================================================================
--- ld/testsuite/ld-mips-elf/tlsdyn-o32.d 2008-06-28 17:09:16.000000000 +0100
+++ ld/testsuite/ld-mips-elf/tlsdyn-o32.d 2008-06-28 17:14:30.000000000 +0100
@@ -52,7 +52,3 @@ Disassembly of section .text:
.*: 03e00008 jr ra
.*: 00000000 nop
...
-Disassembly of section .MIPS.stubs:
-
-.* <.MIPS.stubs>:
- ...
Index: ld/testsuite/ld-mips-elf/relax-jalr-n32-shared.d
===================================================================
--- ld/testsuite/ld-mips-elf/relax-jalr-n32-shared.d 2008-06-28 17:09:16.000000000 +0100
+++ ld/testsuite/ld-mips-elf/relax-jalr-n32-shared.d 2008-06-28 17:14:30.000000000 +0100
@@ -21,5 +21,3 @@ Disassembly of section \.text:
.* bal .* <__start>
.* nop
\.\.\.
-Disassembly of section \.MIPS\.stubs:
- \.\.\.
Index: ld/testsuite/ld-mips-elf/relax-jalr-n64-shared.d
===================================================================
--- ld/testsuite/ld-mips-elf/relax-jalr-n64-shared.d 2008-06-28 17:09:16.000000000 +0100
+++ ld/testsuite/ld-mips-elf/relax-jalr-n64-shared.d 2008-06-28 17:14:30.000000000 +0100
@@ -21,5 +21,3 @@ Disassembly of section \.text:
.* bal .* <__start>
.* nop
\.\.\.
-Disassembly of section \.MIPS\.stubs:
- \.\.\.