aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-02-27 12:22:58 -0800
committerH.J. Lu <hjl.tools@gmail.com>2021-07-08 09:59:28 -0700
commita8dde0a2114f87bcdc19946aeab26788f5eae1b7 (patch)
tree52c8cd4ecd4d2e1a296652841e4e9d63d61ed5a4 /ld
parent74b10a3219e44ba2585e3f7226a6455d41e92c1b (diff)
downloadgdb-a8dde0a2114f87bcdc19946aeab26788f5eae1b7.zip
gdb-a8dde0a2114f87bcdc19946aeab26788f5eae1b7.tar.gz
gdb-a8dde0a2114f87bcdc19946aeab26788f5eae1b7.tar.bz2
ld: Limit cache size and add --max-cache-size=SIZE
When link_info.keep_memory is true, linker caches the relocation information and symbol tables of input files in memory. When there are many input files with many relocations, we may run out of memory. Add --max-cache-size=SIZE to set the maximum cache size. bfd/ PR ld/18028 * bfd.c (bfd): Add alloc_size. * elf-bfd.h (_bfd_elf_link_info_read_relocs): New. * elf32-i386.c (elf_i386_check_relocs): Use _bfd_link_keep_memory. Update cache_size. * elf64-x86-64.c (elf_x86_64_check_relocs): Likewise. * elflink.c (_bfd_elf_link_read_relocs): Renamed to ... (_bfd_elf_link_info_read_relocs): This. Update cache_size. (_bfd_elf_link_read_relocs): New. (_bfd_elf_link_check_relocs): Call _bfd_elf_link_info_read_relocs instead of _bfd_elf_link_read_relocs. (elf_link_add_object_symbols): Likewise. (elf_link_input_bfd): Likewise. (init_reloc_cookie_rels): Likewise. (init_reloc_cookie): Update cache_size. Call _bfd_elf_link_info_read_relocs instead of _bfd_elf_link_read_relocs. (link_info_ok): New. (elf_gc_smash_unused_vtentry_relocs): Updated. Call _bfd_elf_link_info_read_relocs instead of _bfd_elf_link_read_relocs. (bfd_elf_gc_sections): Use link_info_ok. Pass &link_info_ok to elf_gc_smash_unused_vtentry_relocs. * libbfd-in.h (_bfd_link_keep_memory): New. * linker.c (_bfd_link_keep_memory): New. * opncls.c (bfd_alloc): Update alloc_size. * bfd-in2.h: Regenerated. * libbfd.h: Likewise. include/ PR ld/18028 * bfdlink.h (bfd_link_info): Add cache_size and max_cache_size. ld/ PR ld/18028 * NEWS: Mention --max-cache-size=SIZE. * ld.texi: Document --max-cache-size=SIZE. * ldlex.h (option_values): Add OPTION_MAX_CACHE_SIZE. * ldmain.c: (main): Set link_info.max_cache_size to -1. * lexsup.c (ld_options): Add --max-cache-size=SIZE. (parse_args): Support OPTION_MAX_CACHE_SIZE. * testsuite/ld-bootstrap/bootstrap.exp: Add test for --max-cache-size=-1.
Diffstat (limited to 'ld')
-rw-r--r--ld/NEWS3
-rw-r--r--ld/ld.texi6
-rw-r--r--ld/ldlex.h1
-rw-r--r--ld/ldmain.c1
-rw-r--r--ld/lexsup.c15
-rw-r--r--ld/testsuite/ld-bootstrap/bootstrap.exp3
6 files changed, 28 insertions, 1 deletions
diff --git a/ld/NEWS b/ld/NEWS
index 11bc574..92dd4fd 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,8 @@
-*- text -*-
+* Add --max-cache-size=SIZE to set the the maximum cache size to SIZE
+ bytes.
+
Changes in 2.37:
* arm-symbianelf support removed.
diff --git a/ld/ld.texi b/ld/ld.texi
index dd8f571..67c5083 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -2839,6 +2839,12 @@ has been used.
The @option{--reduce-memory-overheads} switch may be also be used to
enable other tradeoffs in future versions of the linker.
+@kindex --max-cache-size=@var{size}
+@item --max-cache-size=@var{size}
+@command{ld} normally caches the relocation information and symbol tables
+of input files in memory with the unlimited size. This option sets the
+maximum cache size to @var{size}.
+
@kindex --build-id
@kindex --build-id=@var{style}
@item --build-id
diff --git a/ld/ldlex.h b/ld/ldlex.h
index 9e8bf5f..9707d57 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -140,6 +140,7 @@ enum option_values
OPTION_WARN_TEXTREL,
OPTION_WARN_ALTERNATE_EM,
OPTION_REDUCE_MEMORY_OVERHEADS,
+ OPTION_MAX_CACHE_SIZE,
#if BFD_SUPPORTS_PLUGINS
OPTION_PLUGIN,
OPTION_PLUGIN_OPT,
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 42660eb..e4c6774 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -331,6 +331,7 @@ main (int argc, char **argv)
link_info.allow_undefined_version = true;
link_info.keep_memory = true;
+ link_info.max_cache_size = (bfd_size_type) -1;
link_info.combreloc = true;
link_info.strip_discarded = true;
link_info.prohibit_multiple_definition_absolute = false;
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 00274c5..c128fe3 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -433,6 +433,10 @@ static const struct ld_option ld_options[] =
OPTION_REDUCE_MEMORY_OVERHEADS},
'\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
TWO_DASHES },
+ { {"max-cache-size=SIZE", required_argument, NULL,
+ OPTION_MAX_CACHE_SIZE},
+ '\0', NULL, N_("Set the maximum cache size to SIZE bytes"),
+ TWO_DASHES },
{ {"relax", no_argument, NULL, OPTION_RELAX},
'\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES },
{ {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
@@ -1631,6 +1635,17 @@ parse_args (unsigned argc, char **argv)
config.hash_table_size = 1021;
break;
+ case OPTION_MAX_CACHE_SIZE:
+ {
+ char *end;
+ bfd_size_type cache_size = strtoul (optarg, &end, 0);
+ if (*end != '\0')
+ einfo (_("%F%P: invalid cache memory size: %s\n"),
+ optarg);
+ link_info.max_cache_size = cache_size;
+ }
+ break;
+
case OPTION_HASH_SIZE:
{
bfd_size_type new_size;
diff --git a/ld/testsuite/ld-bootstrap/bootstrap.exp b/ld/testsuite/ld-bootstrap/bootstrap.exp
index b21b48a..9c27c5f 100644
--- a/ld/testsuite/ld-bootstrap/bootstrap.exp
+++ b/ld/testsuite/ld-bootstrap/bootstrap.exp
@@ -55,7 +55,8 @@ if [check_plugin_api_available] {
# really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a
# new ld, ld3. ld2 and ld3 should be identical.
set test_flags {"" "strip" "--static" "-Wl,--traditional-format"
- "-Wl,--no-keep-memory" "-Wl,--relax"}
+ "-Wl,--no-keep-memory" "-Wl,--relax"
+ "-Wl,--max-cache-size=-1"}
if { [istarget "powerpc-*-*"] } {
lappend test_flags "-Wl,--ppc476-workaround"
}