aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-07-20 13:32:34 +0930
committerAlan Modra <amodra@gmail.com>2020-07-20 22:21:11 +0930
commit2f5541f384babda4aef3d6c8011a6d15af78e0a3 (patch)
tree77de27fb62718a1cdcff15552aaee892704d6c7b
parentb243ba58e833dbb03f3746c0146f1450822c5d05 (diff)
downloadgdb-2f5541f384babda4aef3d6c8011a6d15af78e0a3.zip
gdb-2f5541f384babda4aef3d6c8011a6d15af78e0a3.tar.gz
gdb-2f5541f384babda4aef3d6c8011a6d15af78e0a3.tar.bz2
PR26265, Spurious 'gc-sections requires ... when --init or --fini
bfd/ * elflink.c (_bfd_elf_gc_keep): Use bfd_is_const_section. ld/ PR 26265 * ldlang.c (undef_from_cmdline): Delete. (ldlang_add_undef): Mark "cmdline" param unused. (lang_end): Traverse gc_sym_list to determine whether a symbol root has been specified. Update error message. * testsuite/ld-gc/noent.d: Adjust for changed error message.
-rw-r--r--bfd/ChangeLog4
-rw-r--r--bfd/elflink.c3
-rw-r--r--ld/ChangeLog9
-rw-r--r--ld/ldlang.c26
-rw-r--r--ld/testsuite/ld-gc/noent.d2
5 files changed, 34 insertions, 10 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 43326b5..d6a1d87 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,7 @@
+2020-07-20 Alan Modra <amodra@gmail.com>
+
+ * elflink.c (_bfd_elf_gc_keep): Use bfd_is_const_section.
+
2020-07-19 Alan Modra <amodra@gmail.com>
* elf64-ppc.c (struct ppc_link_hash_table): Add has_power10_relocs.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 6978df5..286fc11 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -13779,8 +13779,7 @@ _bfd_elf_gc_keep (struct bfd_link_info *info)
if (h != NULL
&& (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
- && !bfd_is_abs_section (h->root.u.def.section)
- && !bfd_is_und_section (h->root.u.def.section))
+ && !bfd_is_const_section (h->root.u.def.section))
h->root.u.def.section->flags |= SEC_KEEP;
}
}
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 339fa78..13c25fa 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,12 @@
+2020-07-20 Alan Modra <amodra@gmail.com>
+
+ PR 26265
+ * ldlang.c (undef_from_cmdline): Delete.
+ (ldlang_add_undef): Mark "cmdline" param unused.
+ (lang_end): Traverse gc_sym_list to determine whether a symbol root
+ has been specified. Update error message.
+ * testsuite/ld-gc/noent.d: Adjust for changed error message.
+
2020-07-20 H.J. Lu <hongjiu.lu@intel.com>
PR gas/26263
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 23e787a..2b3a5f9 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -123,7 +123,6 @@ struct bfd_sym_chain entry_symbol = { NULL, NULL };
const char *entry_section = ".text";
struct lang_input_statement_flags input_flags;
bfd_boolean entry_from_cmdline;
-bfd_boolean undef_from_cmdline;
bfd_boolean lang_has_input_file = FALSE;
bfd_boolean had_output_filename = FALSE;
bfd_boolean lang_float_flag = FALSE;
@@ -3895,11 +3894,10 @@ typedef struct bfd_sym_chain ldlang_undef_chain_list_type;
#define ldlang_undef_chain_list_head entry_symbol.next
void
-ldlang_add_undef (const char *const name, bfd_boolean cmdline)
+ldlang_add_undef (const char *const name, bfd_boolean cmdline ATTRIBUTE_UNUSED)
{
ldlang_undef_chain_list_type *new_undef;
- undef_from_cmdline = undef_from_cmdline || cmdline;
new_undef = stat_alloc (sizeof (*new_undef));
new_undef->next = ldlang_undef_chain_list_head;
ldlang_undef_chain_list_head = new_undef;
@@ -6839,10 +6837,24 @@ lang_end (void)
--gc-sections, unless --gc-keep-exported was also given. */
if (bfd_link_relocatable (&link_info)
&& link_info.gc_sections
- && !link_info.gc_keep_exported
- && !(entry_from_cmdline || undef_from_cmdline))
- einfo (_("%F%P: gc-sections requires either an entry or "
- "an undefined symbol\n"));
+ && !link_info.gc_keep_exported)
+ {
+ struct bfd_sym_chain *sym;
+
+ for (sym = link_info.gc_sym_list; sym != NULL; sym = sym->next)
+ {
+ h = bfd_link_hash_lookup (link_info.hash, sym->name,
+ FALSE, FALSE, FALSE);
+ if (h != NULL
+ && (h->type == bfd_link_hash_defined
+ || h->type == bfd_link_hash_defweak)
+ && !bfd_is_const_section (h->u.def.section))
+ break;
+ }
+ if (!sym)
+ einfo (_("%F%P: --gc-sections requires a defined symbol root "
+ "specified by -e or -u\n"));
+ }
if (entry_symbol.name == NULL)
{
diff --git a/ld/testsuite/ld-gc/noent.d b/ld/testsuite/ld-gc/noent.d
index 1741a74..4980822 100644
--- a/ld/testsuite/ld-gc/noent.d
+++ b/ld/testsuite/ld-gc/noent.d
@@ -1,3 +1,3 @@
# name: --gc-sections -r without -e
# ld: --gc-sections -r
-# error: gc-sections requires either an entry or an undefined symbol
+# error: --gc-sections requires .*