This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH]: Fix slow sparc relocation lookup
- From: David Miller <davem at davemloft dot net>
- To: binutils at sourceware dot org
- Date: Mon, 01 Mar 2010 21:24:20 -0800 (PST)
- Subject: [PATCH]: Fix slow sparc relocation lookup
I've always known this was a problem, just never got around
to addressing it.
The relocation lookup function in the sparc BFD backend has this
loop that iterates over a table to translate from BFD relocation
values to sparc ones so it can index into the HOWTO table.
So if you use the largest numbered relocation in the table it walks
over this translation array 84 times.
I wrote a test case that is simply an assembler file with 64,000
instructions that will use the R_SPARC_GOTDATA_HIX22 relocation.
Before this change:
davem@maramba:~/src/GIT/BINUTILS/build-sparc-linux$ time ./gas/as-new -o test.o test.s
real 0m0.910s
user 0m0.850s
sys 0m0.050s
davem@maramba:~/src/GIT/BINUTILS/build-sparc-linux$
# Samples: 410510621
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
14.11% as-new as-new [.] do_scrub_chars
12.29% as-new as-new [.] md_assemble
10.85% as-new as-new [.] _bfd_sparc_elf_reloc_type_lookup
10.84% as-new libc-2.7.so [.] __GI_strncmp
9.61% as-new as-new [.] _find_end_of_line
3.68% as-new libc-2.7.so [.] _int_malloc
...
After the change:
davem@maramba:~/src/GIT/BINUTILS/build-sparc-linux$ time ./gas/as-new -o test.o test.s
real 0m0.833s
user 0m0.750s
sys 0m0.080s
davem@maramba:~/src/GIT/BINUTILS/build-sparc-linux$
# Samples: 368740256
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
14.88% as-new libc-2.7.so [.] __GI_strncmp
13.49% as-new as-new [.] do_scrub_chars
10.11% as-new as-new [.] md_assemble
7.11% as-new as-new [.] _find_end_of_line
5.26% as-new libc-2.7.so [.] _int_malloc
4.95% as-new as-new [.] hash_lookup
Ok to commit?
bfd/
2010-03-01 David S. Miller <davem@davemloft.net>
* elfxx-sparc.c (struct elf_reloc_map): Delete.
(sparc_reloc_map): Delete.
(_bfd_sparc_elf_reloc_type_lookup): Explicitly handle each
relocation type in switch statements.
diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c
index 2137df0..c0841db 100644
--- a/bfd/elfxx-sparc.c
+++ b/bfd/elfxx-sparc.c
@@ -278,109 +278,249 @@ static reloc_howto_type sparc_vtentry_howto =
static reloc_howto_type sparc_rev32_howto =
HOWTO(R_SPARC_REV32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_REV32", FALSE,0,0xffffffff,TRUE);
-struct elf_reloc_map {
- bfd_reloc_code_real_type bfd_reloc_val;
- unsigned char elf_reloc_val;
-};
-
-static const struct elf_reloc_map sparc_reloc_map[] =
-{
- { BFD_RELOC_NONE, R_SPARC_NONE, },
- { BFD_RELOC_16, R_SPARC_16, },
- { BFD_RELOC_16_PCREL, R_SPARC_DISP16 },
- { BFD_RELOC_8, R_SPARC_8 },
- { BFD_RELOC_8_PCREL, R_SPARC_DISP8 },
- { BFD_RELOC_CTOR, R_SPARC_64 },
- { BFD_RELOC_32, R_SPARC_32 },
- { BFD_RELOC_32_PCREL, R_SPARC_DISP32 },
- { BFD_RELOC_HI22, R_SPARC_HI22 },
- { BFD_RELOC_LO10, R_SPARC_LO10, },
- { BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 },
- { BFD_RELOC_64_PCREL, R_SPARC_DISP64 },
- { BFD_RELOC_SPARC22, R_SPARC_22 },
- { BFD_RELOC_SPARC13, R_SPARC_13 },
- { BFD_RELOC_SPARC_GOT10, R_SPARC_GOT10 },
- { BFD_RELOC_SPARC_GOT13, R_SPARC_GOT13 },
- { BFD_RELOC_SPARC_GOT22, R_SPARC_GOT22 },
- { BFD_RELOC_SPARC_PC10, R_SPARC_PC10 },
- { BFD_RELOC_SPARC_PC22, R_SPARC_PC22 },
- { BFD_RELOC_SPARC_WPLT30, R_SPARC_WPLT30 },
- { BFD_RELOC_SPARC_COPY, R_SPARC_COPY },
- { BFD_RELOC_SPARC_GLOB_DAT, R_SPARC_GLOB_DAT },
- { BFD_RELOC_SPARC_JMP_SLOT, R_SPARC_JMP_SLOT },
- { BFD_RELOC_SPARC_RELATIVE, R_SPARC_RELATIVE },
- { BFD_RELOC_SPARC_WDISP22, R_SPARC_WDISP22 },
- { BFD_RELOC_SPARC_UA16, R_SPARC_UA16 },
- { BFD_RELOC_SPARC_UA32, R_SPARC_UA32 },
- { BFD_RELOC_SPARC_UA64, R_SPARC_UA64 },
- { BFD_RELOC_SPARC_10, R_SPARC_10 },
- { BFD_RELOC_SPARC_11, R_SPARC_11 },
- { BFD_RELOC_SPARC_64, R_SPARC_64 },
- { BFD_RELOC_SPARC_OLO10, R_SPARC_OLO10 },
- { BFD_RELOC_SPARC_HH22, R_SPARC_HH22 },
- { BFD_RELOC_SPARC_HM10, R_SPARC_HM10 },
- { BFD_RELOC_SPARC_LM22, R_SPARC_LM22 },
- { BFD_RELOC_SPARC_PC_HH22, R_SPARC_PC_HH22 },
- { BFD_RELOC_SPARC_PC_HM10, R_SPARC_PC_HM10 },
- { BFD_RELOC_SPARC_PC_LM22, R_SPARC_PC_LM22 },
- { BFD_RELOC_SPARC_WDISP16, R_SPARC_WDISP16 },
- { BFD_RELOC_SPARC_WDISP19, R_SPARC_WDISP19 },
- { BFD_RELOC_SPARC_7, R_SPARC_7 },
- { BFD_RELOC_SPARC_5, R_SPARC_5 },
- { BFD_RELOC_SPARC_6, R_SPARC_6 },
- { BFD_RELOC_SPARC_DISP64, R_SPARC_DISP64 },
- { BFD_RELOC_SPARC_TLS_GD_HI22, R_SPARC_TLS_GD_HI22 },
- { BFD_RELOC_SPARC_TLS_GD_LO10, R_SPARC_TLS_GD_LO10 },
- { BFD_RELOC_SPARC_TLS_GD_ADD, R_SPARC_TLS_GD_ADD },
- { BFD_RELOC_SPARC_TLS_GD_CALL, R_SPARC_TLS_GD_CALL },
- { BFD_RELOC_SPARC_TLS_LDM_HI22, R_SPARC_TLS_LDM_HI22 },
- { BFD_RELOC_SPARC_TLS_LDM_LO10, R_SPARC_TLS_LDM_LO10 },
- { BFD_RELOC_SPARC_TLS_LDM_ADD, R_SPARC_TLS_LDM_ADD },
- { BFD_RELOC_SPARC_TLS_LDM_CALL, R_SPARC_TLS_LDM_CALL },
- { BFD_RELOC_SPARC_TLS_LDO_HIX22, R_SPARC_TLS_LDO_HIX22 },
- { BFD_RELOC_SPARC_TLS_LDO_LOX10, R_SPARC_TLS_LDO_LOX10 },
- { BFD_RELOC_SPARC_TLS_LDO_ADD, R_SPARC_TLS_LDO_ADD },
- { BFD_RELOC_SPARC_TLS_IE_HI22, R_SPARC_TLS_IE_HI22 },
- { BFD_RELOC_SPARC_TLS_IE_LO10, R_SPARC_TLS_IE_LO10 },
- { BFD_RELOC_SPARC_TLS_IE_LD, R_SPARC_TLS_IE_LD },
- { BFD_RELOC_SPARC_TLS_IE_LDX, R_SPARC_TLS_IE_LDX },
- { BFD_RELOC_SPARC_TLS_IE_ADD, R_SPARC_TLS_IE_ADD },
- { BFD_RELOC_SPARC_TLS_LE_HIX22, R_SPARC_TLS_LE_HIX22 },
- { BFD_RELOC_SPARC_TLS_LE_LOX10, R_SPARC_TLS_LE_LOX10 },
- { BFD_RELOC_SPARC_TLS_DTPMOD32, R_SPARC_TLS_DTPMOD32 },
- { BFD_RELOC_SPARC_TLS_DTPMOD64, R_SPARC_TLS_DTPMOD64 },
- { BFD_RELOC_SPARC_TLS_DTPOFF32, R_SPARC_TLS_DTPOFF32 },
- { BFD_RELOC_SPARC_TLS_DTPOFF64, R_SPARC_TLS_DTPOFF64 },
- { BFD_RELOC_SPARC_TLS_TPOFF32, R_SPARC_TLS_TPOFF32 },
- { BFD_RELOC_SPARC_TLS_TPOFF64, R_SPARC_TLS_TPOFF64 },
- { BFD_RELOC_SPARC_PLT32, R_SPARC_PLT32 },
- { BFD_RELOC_SPARC_PLT64, R_SPARC_PLT64 },
- { BFD_RELOC_SPARC_HIX22, R_SPARC_HIX22 },
- { BFD_RELOC_SPARC_LOX10, R_SPARC_LOX10 },
- { BFD_RELOC_SPARC_H44, R_SPARC_H44 },
- { BFD_RELOC_SPARC_M44, R_SPARC_M44 },
- { BFD_RELOC_SPARC_L44, R_SPARC_L44 },
- { BFD_RELOC_SPARC_GOTDATA_HIX22, R_SPARC_GOTDATA_HIX22 },
- { BFD_RELOC_SPARC_GOTDATA_LOX10, R_SPARC_GOTDATA_LOX10 },
- { BFD_RELOC_SPARC_GOTDATA_OP_HIX22, R_SPARC_GOTDATA_OP_HIX22 },
- { BFD_RELOC_SPARC_GOTDATA_OP_LOX10, R_SPARC_GOTDATA_OP_LOX10 },
- { BFD_RELOC_SPARC_GOTDATA_OP, R_SPARC_GOTDATA_OP },
- { BFD_RELOC_SPARC_REGISTER, R_SPARC_REGISTER },
- { BFD_RELOC_SPARC_JMP_IREL, R_SPARC_JMP_IREL },
- { BFD_RELOC_SPARC_IRELATIVE, R_SPARC_IRELATIVE },
- { BFD_RELOC_VTABLE_INHERIT, R_SPARC_GNU_VTINHERIT },
- { BFD_RELOC_VTABLE_ENTRY, R_SPARC_GNU_VTENTRY },
- { BFD_RELOC_SPARC_REV32, R_SPARC_REV32 },
-};
-
reloc_howto_type *
_bfd_sparc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
bfd_reloc_code_real_type code)
{
- unsigned int i;
-
switch (code)
{
+ case BFD_RELOC_NONE:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_NONE];
+
+ case BFD_RELOC_8:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_8];
+
+ case BFD_RELOC_16:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_16];
+
+ case BFD_RELOC_32:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_32];
+
+ case BFD_RELOC_8_PCREL:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_DISP8];
+
+ case BFD_RELOC_16_PCREL:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_DISP16];
+
+ case BFD_RELOC_32_PCREL:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_DISP32];
+
+ case BFD_RELOC_32_PCREL_S2:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP30];
+
+ case BFD_RELOC_SPARC_WDISP22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP22];
+
+ case BFD_RELOC_HI22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_HI22];
+
+ case BFD_RELOC_SPARC22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_22];
+
+ case BFD_RELOC_SPARC13:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_13];
+
+ case BFD_RELOC_LO10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_LO10];
+
+ case BFD_RELOC_SPARC_GOT10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_GOT10];
+
+ case BFD_RELOC_SPARC_GOT13:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_GOT13];
+
+ case BFD_RELOC_SPARC_GOT22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_GOT22];
+
+ case BFD_RELOC_SPARC_PC10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_PC10];
+
+ case BFD_RELOC_SPARC_PC22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_PC22];
+
+ case BFD_RELOC_SPARC_WPLT30:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_WPLT30];
+
+ case BFD_RELOC_SPARC_COPY:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_COPY];
+
+ case BFD_RELOC_SPARC_GLOB_DAT:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_GLOB_DAT];
+
+ case BFD_RELOC_SPARC_JMP_SLOT:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_JMP_SLOT];
+
+ case BFD_RELOC_SPARC_RELATIVE:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_RELATIVE];
+
+ case BFD_RELOC_SPARC_UA32:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_UA32];
+
+ case BFD_RELOC_SPARC_PLT32:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_PLT32];
+
+ case BFD_RELOC_SPARC_10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_10];
+
+ case BFD_RELOC_SPARC_11:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_11];
+
+ case BFD_RELOC_SPARC_64:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_64];
+
+ case BFD_RELOC_SPARC_OLO10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_OLO10];
+
+ case BFD_RELOC_SPARC_HH22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_HH22];
+
+ case BFD_RELOC_SPARC_HM10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_HM10];
+
+ case BFD_RELOC_SPARC_LM22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_LM22];
+
+ case BFD_RELOC_SPARC_PC_HH22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_PC_HH22];
+
+ case BFD_RELOC_SPARC_PC_HM10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_PC_HM10];
+
+ case BFD_RELOC_SPARC_PC_LM22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_PC_LM22];
+
+ case BFD_RELOC_SPARC_WDISP16:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP16];
+
+ case BFD_RELOC_SPARC_WDISP19:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP19];
+
+ case BFD_RELOC_SPARC_7:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_7];
+
+ case BFD_RELOC_SPARC_5:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_5];
+
+ case BFD_RELOC_SPARC_6:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_6];
+
+ case BFD_RELOC_SPARC_DISP64:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_DISP64];
+
+ case BFD_RELOC_SPARC_PLT64:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_PLT64];
+
+ case BFD_RELOC_SPARC_HIX22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_HIX22];
+
+ case BFD_RELOC_SPARC_LOX10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_LOX10];
+
+ case BFD_RELOC_SPARC_H44:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_H44];
+
+ case BFD_RELOC_SPARC_M44:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_M44];
+
+ case BFD_RELOC_SPARC_L44:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_L44];
+
+ case BFD_RELOC_SPARC_REGISTER:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_REGISTER];
+
+ case BFD_RELOC_SPARC_UA64:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_UA64];
+
+ case BFD_RELOC_SPARC_UA16:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_UA16];
+
+ case BFD_RELOC_SPARC_TLS_GD_HI22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_HI22];
+
+ case BFD_RELOC_SPARC_TLS_GD_LO10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_LO10];
+
+ case BFD_RELOC_SPARC_TLS_GD_ADD:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_ADD];
+
+ case BFD_RELOC_SPARC_TLS_GD_CALL:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_CALL];
+
+ case BFD_RELOC_SPARC_TLS_LDM_HI22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_HI22];
+
+ case BFD_RELOC_SPARC_TLS_LDM_LO10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_LO10];
+
+ case BFD_RELOC_SPARC_TLS_LDM_ADD:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_ADD];
+
+ case BFD_RELOC_SPARC_TLS_LDM_CALL:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_CALL];
+
+ case BFD_RELOC_SPARC_TLS_LDO_HIX22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDO_HIX22];
+
+ case BFD_RELOC_SPARC_TLS_LDO_LOX10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDO_LOX10];
+
+ case BFD_RELOC_SPARC_TLS_LDO_ADD:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDO_ADD];
+
+ case BFD_RELOC_SPARC_TLS_IE_HI22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_HI22];
+
+ case BFD_RELOC_SPARC_TLS_IE_LO10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_LO10];
+
+ case BFD_RELOC_SPARC_TLS_IE_LD:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_LD];
+
+ case BFD_RELOC_SPARC_TLS_IE_LDX:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_LDX];
+
+ case BFD_RELOC_SPARC_TLS_IE_ADD:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_ADD];
+
+ case BFD_RELOC_SPARC_TLS_LE_HIX22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LE_HIX22];
+
+ case BFD_RELOC_SPARC_TLS_LE_LOX10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LE_LOX10];
+
+ case BFD_RELOC_SPARC_TLS_DTPMOD32:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPMOD32];
+
+ case BFD_RELOC_SPARC_TLS_DTPMOD64:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPMOD64];
+
+ case BFD_RELOC_SPARC_TLS_DTPOFF32:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPOFF32];
+
+ case BFD_RELOC_SPARC_TLS_DTPOFF64:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPOFF64];
+
+ case BFD_RELOC_SPARC_TLS_TPOFF32:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_TPOFF32];
+
+ case BFD_RELOC_SPARC_TLS_TPOFF64:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_TPOFF64];
+
+ case BFD_RELOC_SPARC_GOTDATA_HIX22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_HIX22];
+
+ case BFD_RELOC_SPARC_GOTDATA_LOX10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_LOX10];
+
+ case BFD_RELOC_SPARC_GOTDATA_OP_HIX22:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_OP_HIX22];
+
+ case BFD_RELOC_SPARC_GOTDATA_OP_LOX10:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_OP_LOX10];
+
+ case BFD_RELOC_SPARC_GOTDATA_OP:
+ return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_OP];
+
case BFD_RELOC_SPARC_JMP_IREL:
return &sparc_jmp_irel_howto;
@@ -397,14 +537,7 @@ _bfd_sparc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
return &sparc_rev32_howto;
default:
- for (i = 0;
- i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map);
- i++)
- {
- if (sparc_reloc_map[i].bfd_reloc_val == code)
- return (_bfd_sparc_elf_howto_table
- + (int) sparc_reloc_map[i].elf_reloc_val);
- }
+ break;
}
bfd_set_error (bfd_error_bad_value);
return NULL;