public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: binutils@sourceware.org
Subject: gold patch committed: Implement --unresolved-symbols
Date: Sat, 09 Jul 2011 06:21:00 -0000	[thread overview]
Message-ID: <mcrk4bsugm4.fsf@coign.corp.google.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 473 bytes --]

This gold patch implements --unresolved-symbols more or less as it
exists in GNU ld.  Gold generally acts as like GNU ld using
--unresolved-symbols=ignore-in-shared-libs, and this patch does not
change that behaviour.  Committed to mainline.

Ian


2011-07-08  Ian Lance Taylor  <iant@google.com>

	PR gold/12386
	* options.h (class General_options): Add --unresolved-symbols.
	* target-reloc.h (issue_undefined_symbol_error): Check
	--unresolved-symbols.  Add comments.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2848 bytes --]

Index: options.h
===================================================================
RCS file: /cvs/src/src/gold/options.h,v
retrieving revision 1.166
diff -u -p -r1.166 options.h
--- options.h	6 Jul 2011 22:15:12 -0000	1.166
+++ options.h	9 Jul 2011 06:09:34 -0000
@@ -1069,6 +1069,13 @@ class General_options
   DEFINE_set(undefined, options::TWO_DASHES, 'u',
 	     N_("Create undefined reference to SYMBOL"), N_("SYMBOL"));
 
+  DEFINE_enum(unresolved_symbols, options::TWO_DASHES, '\0', NULL,
+	      N_("How to handle unresolved symbols"),
+	      ("ignore-all,report-all,ignore-in-object-files,"
+	       "ignore-in-shared-libs"),
+	      {"ignore-all", "report-all", "ignore-in-object-files",
+		  "ignore-in-shared-libs"});
+
   DEFINE_bool(verbose, options::TWO_DASHES, '\0', false,
               N_("Synonym for --debug=files"), NULL);
 
Index: target-reloc.h
===================================================================
RCS file: /cvs/src/src/gold/target-reloc.h,v
retrieving revision 1.48
diff -u -p -r1.48 target-reloc.h
--- target-reloc.h	9 Jul 2011 00:47:11 -0000	1.48
+++ target-reloc.h	9 Jul 2011 06:09:34 -0000
@@ -176,13 +176,46 @@ visibility_error(const Symbol* sym)
 inline bool
 issue_undefined_symbol_error(const Symbol* sym)
 {
-  return (sym != NULL
-	  && (sym->is_undefined() || sym->is_placeholder())
-	  && sym->binding() != elfcpp::STB_WEAK
-	  && !sym->is_defined_in_discarded_section()
-	  && !parameters->target().is_defined_by_abi(sym)
-	  && (!parameters->options().shared()
-	      || parameters->options().defs()));
+  // We only report global symbols.
+  if (sym == NULL)
+    return false;
+
+  // We only report undefined symbols.
+  if (!sym->is_undefined() && !sym->is_placeholder())
+    return false;
+
+  // We don't report weak symbols.
+  if (sym->binding() == elfcpp::STB_WEAK)
+    return false;
+
+  // We don't report symbols defined in discarded sections.
+  if (sym->is_defined_in_discarded_section())
+    return false;
+
+  // If the target defines this symbol, don't report it here.
+  if (parameters->target().is_defined_by_abi(sym))
+    return false;
+
+  // See if we've been told to ignore whether this symbol is
+  // undefined.
+  const char* const u = parameters->options().unresolved_symbols();
+  if (u != NULL)
+    {
+      if (strcmp(u, "ignore-all") == 0)
+	return false;
+      if (strcmp(u, "ignore-in-object-files") == 0 && !sym->in_dyn())
+	return false;
+      if (strcmp(u, "ignore-in-shared-libs") == 0 && !sym->in_reg())
+	return false;
+    }
+
+  // When creating a shared library, only report unresolved symbols if
+  // -z defs was used.
+  if (parameters->options().shared() && !parameters->options().defs())
+    return false;
+
+  // Otherwise issue a warning.
+  return true;
 }
 
 // This function implements the generic part of relocation processing.

                 reply	other threads:[~2011-07-09  6:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mcrk4bsugm4.fsf@coign.corp.google.com \
    --to=iant@google.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).