This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] riscv: Cache the max alignment of output sections
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: binutils at sourceware dot org
- Cc: Palmer Dabbelt <palmer at dabbelt dot com>, Andrew Waterman <andrew at sifive dot com>
- Date: Mon, 9 Oct 2017 18:53:39 -0700
- Subject: [PATCH] riscv: Cache the max alignment of output sections
- Authentication-results: sourceware.org; auth=none
Cache the max alignment of output sections instead of scanning all
output sections for each input section, which can take a very long
time if there are millions of input/output sections.
OK for master?
H.J.
---
PR ld/22274
* elfnn-riscv.c (riscv_elf_link_hash_table): Add max_alignment.
(riscv_elf_link_hash_table_create): Initialize max_alignment to
(bfd_vma) -1.
(_bfd_riscv_relax_section): Cache the max alignment of output
sections if possible.
---
bfd/elfnn-riscv.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 59964ba163..d28cabded5 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -127,6 +127,9 @@ struct riscv_elf_link_hash_table
/* Small local sym to section mapping cache. */
struct sym_cache sym_cache;
+
+ /* The max alignment of output sections. */
+ bfd_vma max_alignment;
};
@@ -274,6 +277,7 @@ riscv_elf_link_hash_table_create (bfd *abfd)
return NULL;
}
+ ret->max_alignment = (bfd_vma) -1;
return &ret->elf.root;
}
@@ -2976,7 +2980,17 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
info->keep_memory)))
goto fail;
- max_alignment = _bfd_riscv_get_max_alignment (sec);
+ if (htab)
+ {
+ max_alignment = htab->max_alignment;
+ if (max_alignment == (bfd_vma) -1)
+ {
+ max_alignment = _bfd_riscv_get_max_alignment (sec);
+ htab->max_alignment = max_alignment;
+ }
+ }
+ else
+ max_alignment = _bfd_riscv_get_max_alignment (sec);
/* Examine and consider relaxing each reloc. */
for (i = 0; i < sec->reloc_count; i++)
--
2.13.6