]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Implement and document --gc-keep-exported
authorfincs <fincs.alt1@gmail.com>
Fri, 16 Dec 2016 03:12:02 +0000 (13:42 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 16 Dec 2016 03:19:03 +0000 (13:49 +1030)
include/
* bfdlink.h (struct bfd_link_info): Add gc_keep_exported.
bfd/
* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Add handling
for info->gc_keep_exported.
(bfd_elf_gc_sections): Likewise.
ld/
* ld.texinfo: Document --gc-keep-exported.
* ldlex.h (enum option_values): Add OPTION_GC_KEEP_EXPORTED.
* lexsup.c (parse_args): Add handling for --gc-keep-exported.

bfd/ChangeLog
bfd/elflink.c
include/ChangeLog
include/bfdlink.h
ld/ChangeLog
ld/ld.texinfo
ld/ldlex.h
ld/lexsup.c

index 46cb3834dd5d6826743ed7e12384b481a3d04bdc..8c09c2c39102faa64b5f854e1785f9e63e26b308 100644 (file)
@@ -1,3 +1,9 @@
+2016-12-16  fincs  <fincs.alt1@gmail.com>
+
+       * elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Add handling
+       for info->gc_keep_exported.
+       (bfd_elf_gc_sections): Likewise.
+
 2016-12-15  Alan Modra  <amodra@gmail.com>
 
        PR ld/20968
index fe6662d0dd7987c8f8e504913f743239ee311610..07b79013d90c710def29183b29a3b2d3541b8305 100644 (file)
@@ -13051,6 +13051,7 @@ bfd_elf_gc_mark_dynamic_ref_symbol (struct elf_link_hash_entry *h, void *inf)
              && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
              && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
              && (!bfd_link_executable (info)
+                 || info->gc_keep_exported
                  || info->export_dynamic
                  || (h->dynamic
                      && d != NULL
@@ -13170,7 +13171,7 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
     return FALSE;
 
   /* Mark dynamically referenced symbols.  */
-  if (htab->dynamic_sections_created)
+  if (htab->dynamic_sections_created || info->gc_keep_exported)
     elf_link_hash_traverse (htab, bed->gc_mark_dynamic_ref, info);
 
   /* Grovel through relocs to find out who stays ...  */
index 57ea85ec4c6c709ff241d528d03287b3aea45faa..7e69c42f4862eb1d34acbe3fd05255c15e7b21e1 100644 (file)
@@ -1,3 +1,7 @@
+2016-12-16  fincs  <fincs.alt1@gmail.com>
+
+       * bfdlink.h (struct bfd_link_info): Add gc_keep_exported.
+
 2016-12-14  Maciej W. Rozycki  <macro@imgtec.com>
 
        * elf/mips.h (Elf_Internal_ABIFlags_v0): Also declare struct
index 9b2194f6d5ca930f661e338062cc64877fdfc66a..aea027b138d4e83a96089278ecadc24a1f45bf90 100644 (file)
@@ -328,6 +328,9 @@ struct bfd_link_info
   /* TRUE if unreferenced sections should be removed.  */
   unsigned int gc_sections: 1;
 
+  /* TRUE if exported symbols should be kept during section gc.  */
+  unsigned int gc_keep_exported: 1;
+
   /* TRUE if every symbol should be reported back via the notice
      callback.  */
   unsigned int notice_all: 1;
index 086434aa3bbb72d1fe94e741ed217d5d86197bab..8463c7c23b969a924c15f0d95a6dfa716c5f348b 100644 (file)
@@ -1,3 +1,9 @@
+2016-12-16  fincs  <fincs.alt1@gmail.com>
+
+       * ld.texinfo: Document --gc-keep-exported.
+       * ldlex.h (enum option_values): Add OPTION_GC_KEEP_EXPORTED.
+       * lexsup.c (parse_args): Add handling for --gc-keep-exported.
+
 2016-12-14  Yury Norov <ynorov@caviumnetworks.com>
 
        * ld/testsuite/ld-aarch64/aarch64-elf.exp: Add tests for tiny and
index ec7ff1b85a724d646bb3668b57799d8dcbb1b800..17503eb49730ef3e295c7d4af2f269204b38b754 100644 (file)
@@ -1558,6 +1558,18 @@ default behaviour (of not listing the sections that are removed) can
 be restored by specifying @samp{--no-print-gc-sections} on the command
 line.
 
+@kindex --gc-keep-exported
+@cindex garbage collection
+@item --gc-keep-exported
+When @samp{--gc-sections} is enabled, this option prevents garbage
+collection of unused input sections that contain global symbols having
+default or protected visibility.  This option is intended to be used for
+executables where unreferenced sections would otherwise be garbage
+collected regardless of the external visibility of contained symbols.
+Note that this option has no effect when linking shared objects since
+it is already the default behaviour.  This option is only supported for
+ELF format targets.
+
 @kindex --print-output-format
 @cindex output format
 @item --print-output-format
index 52f7198ad2ccec4a96474f2d865392657d6333da..fd29008e3c73f0f7afb1baf5d4bba3bbf2616270 100644 (file)
@@ -101,6 +101,7 @@ enum option_values
   OPTION_NO_GC_SECTIONS,
   OPTION_PRINT_GC_SECTIONS,
   OPTION_NO_PRINT_GC_SECTIONS,
+  OPTION_GC_KEEP_EXPORTED,
   OPTION_HASH_SIZE,
   OPTION_CHECK_SECTIONS,
   OPTION_NO_CHECK_SECTIONS,
index fb0b47f24e410107d16f17154a8ae24556a45585..8ff5d1f567e41dc01e5d55960889386675c3403d 100644 (file)
@@ -335,6 +335,9 @@ static const struct ld_option ld_options[] =
   { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
     '\0', NULL, N_("Do not list removed unused sections"),
     TWO_DASHES },
+  { {"gc-keep-exported", no_argument, NULL, OPTION_GC_KEEP_EXPORTED},
+    '\0', NULL, N_("Keep exported symbols when removing unused sections"),
+    TWO_DASHES },
   { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
     '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
     TWO_DASHES },
@@ -861,6 +864,9 @@ parse_args (unsigned argc, char **argv)
        case OPTION_PRINT_GC_SECTIONS:
          link_info.print_gc_sections = TRUE;
          break;
+       case OPTION_GC_KEEP_EXPORTED:
+         link_info.gc_keep_exported = TRUE;
+         break;
        case OPTION_HELP:
          help ();
          xexit (0);