public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Merge WARN and CWARN cases in _bfd_generic_link_add_one_symbol
@ 2014-08-07  0:42 Alan Modra
  2014-08-07  0:55 ` [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2014-08-07  0:42 UTC (permalink / raw)
  To: binutils

WARN has always been able to be handled by the CWARN case (WARN was
used when the previous symbols was undef, undefweak or common and thus
must be on the undefs list, so the CWARN test passes).  So let's merge
those two cases.

	* linker.c (WARN, CWARN): Collapse these states to WARN.
	(_bfd_generic_link_add_one_symbol): Use old CWARN case for
	new WARN.

diff --git a/bfd/linker.c b/bfd/linker.c
index 1877e67..93c5465 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -1342,8 +1342,7 @@ enum link_action
   CIND,		/* Make indirect symbol from existing common symbol.  */
   SET,		/* Add value to set.  */
   MWARN,	/* Make warning symbol.  */
-  WARN,		/* Issue warning.  */
-  CWARN,	/* Warn if referenced, else MWARN.  */
+  WARN,		/* Warn if referenced, else MWARN.  */
   CYCLE,	/* Repeat with symbol pointed to.  */
   REFC,		/* Mark indirect symbol referenced and then CYCLE.  */
   WARNC		/* Issue warning and then CYCLE.  */
@@ -1361,7 +1360,7 @@ static const enum link_action link_action[8][8] =
   /* DEFW_ROW 	*/  {DEFW,  DEFW,  DEFW,  NOACT, NOACT, NOACT, NOACT, CYCLE },
   /* COMMON_ROW	*/  {COM,   COM,   COM,   CREF,  COM,   BIG,   REFC,  WARNC },
   /* INDR_ROW	*/  {IND,   IND,   IND,   MDEF,  IND,   CIND,  MIND,  CYCLE },
-  /* WARN_ROW   */  {MWARN, WARN,  WARN,  CWARN, CWARN, WARN,  CWARN, NOACT },
+  /* WARN_ROW   */  {MWARN, WARN,  WARN,  WARN,  WARN,  WARN,  WARN,  NOACT },
   /* SET_ROW	*/  {SET,   SET,   SET,   SET,   SET,   SET,   CYCLE, CYCLE }
 };
 
@@ -1803,13 +1802,6 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 	  break;
 
 	case WARN:
-	  /* Issue a warning.  */
-	  if (! (*info->callbacks->warning) (info, string, h->root.string,
-					     hash_entry_bfd (h), NULL, 0))
-	    return FALSE;
-	  break;
-
-	case CWARN:
 	  /* Warn if this symbol has been referenced already,
 	     otherwise add a warning.  A symbol has been referenced if
 	     the u.undef.next field is not NULL, or it is the tail of the

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR
  2014-08-07  0:42 Merge WARN and CWARN cases in _bfd_generic_link_add_one_symbol Alan Modra
@ 2014-08-07  0:55 ` Alan Modra
  2014-08-11 22:21   ` Hans-Peter Nilsson
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2014-08-07  0:55 UTC (permalink / raw)
  To: binutils; +Cc: H.J. Lu

The thread https://sourceware.org/ml/binutils/2014-03/msg00261.html 
died without any resolution, I guess a case of me wanting perfection
and rejecting the good.  So now that I've merged the WARN and CWARN
my concern with HJ's patch is covered.  This is what I'm about to
commit on HJ's behalf.

bfd/
	PR ld/16746
	* linker.c (_bfd_generic_link_add_one_symbol): Don't issue a
	warning for references in LTO IR to warning symbols.

ld/testsuite/
	PR ld/16746
	* ld-plugin/lto.exp: Add 4 tests for PR ld/16746.
	* ld-plugin/pr16746a.c: New file.
	* ld-plugin/pr16746b.c: Likewise.
	* ld-plugin/pr16746c.c: Likewise.
	* ld-plugin/pr16746d.c: Likewise.

diff --git a/bfd/linker.c b/bfd/linker.c
index 93c5465..d4b053c 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -1776,8 +1776,10 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 	  break;
 
 	case WARNC:
-	  /* Issue a warning and cycle.  */
-	  if (h->u.i.warning != NULL)
+	  /* Issue a warning and cycle, except when the reference is
+	     in LTO IR.  */
+	  if (h->u.i.warning != NULL
+	      && (abfd->flags & BFD_PLUGIN) == 0)
 	    {
 	      if (! (*info->callbacks->warning) (info, h->u.i.warning,
 						 h->root.string, abfd,
@@ -1802,12 +1804,9 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 	  break;
 
 	case WARN:
-	  /* Warn if this symbol has been referenced already,
-	     otherwise add a warning.  A symbol has been referenced if
-	     the u.undef.next field is not NULL, or it is the tail of the
-	     undefined symbol list.  The REF case above helps to
-	     ensure this.  */
-	  if (h->u.undef.next != NULL || info->hash->undefs_tail == h)
+	  /* Warn if this symbol has been referenced already from non-IR,
+	     otherwise add a warning.  */
+	  if (h->non_ir_ref)
 	    {
 	      if (! (*info->callbacks->warning) (info, string, h->root.string,
 						 hash_entry_bfd (h), NULL, 0))
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 432c753..7ff5bfb 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -232,6 +232,18 @@ set lto_link_elf_tests [list \
   [list "Build libpr15146d.a" \
    "$plug_opt" "-flto -O2" \
    {pr15146d.c} {} "lib15146d.a"] \
+  [list "Build libpr16746a.a" \
+   "" "" \
+   {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
+  [list "Build libpr16746b.a" \
+   "$plug_opt" "-O2 -flto" \
+   {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
+  [list "PR ld/16746 (1)" \
+   "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
+   {dummy.c} {} "pr16746a.exe"] \
+  [list "PR ld/16746 (2)" \
+   "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \
+   {dummy.c} {} "pr16746b.exe"] \
 ]
 
 # Check final symbols in executables.
@@ -335,6 +347,20 @@ if { [is_elf_format] && [check_lto_shared_available] } {
     } {
 	fail $testname
     }
+    set testname "PR ld/16746 (3)"
+    set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
+    if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
+	pass $testname
+    } {
+	fail $testname
+    }
+    set testname "PR ld/16746 (4)"
+    set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
+    if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
+	pass $testname
+    } {
+	fail $testname
+    }
 }
 
 set testname "Build liblto-11.a"
diff --git a/ld/testsuite/ld-plugin/pr16746a.c b/ld/testsuite/ld-plugin/pr16746a.c
new file mode 100644
index 0000000..1705ef1
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr16746a.c
@@ -0,0 +1,3 @@
+static const char __evoke_link_warning_foobar[]
+ __attribute__ ((used, section (".gnu.warning.foobar\n\t#")))
+ = "foobar";
diff --git a/ld/testsuite/ld-plugin/pr16746b.c b/ld/testsuite/ld-plugin/pr16746b.c
new file mode 100644
index 0000000..c3b7a78
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr16746b.c
@@ -0,0 +1,5 @@
+static const char __evoke_link_warning_foobar[]
+ __attribute__ ((used, section (".gnu.warning.foobar\n\t#")))
+ = "foobar";
+
+void foobar (void) {}
diff --git a/ld/testsuite/ld-plugin/pr16746c.c b/ld/testsuite/ld-plugin/pr16746c.c
new file mode 100644
index 0000000..fb68ab7
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr16746c.c
@@ -0,0 +1,8 @@
+extern void foobar (void);
+int
+main (int argc, char **argv)
+{
+  if (__builtin_constant_p (argc))
+    foobar ();
+  return 0;
+}
diff --git a/ld/testsuite/ld-plugin/pr16746d.c b/ld/testsuite/ld-plugin/pr16746d.c
new file mode 100644
index 0000000..1fee4dd
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr16746d.c
@@ -0,0 +1,8 @@
+extern void foobar (void);
+int
+main (int argc, char **argv)
+{
+  if (!__builtin_constant_p (argc))
+    foobar ();
+  return 0;
+}


-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR
  2014-08-07  0:55 ` [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR Alan Modra
@ 2014-08-11 22:21   ` Hans-Peter Nilsson
  2014-08-12  1:12     ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: Hans-Peter Nilsson @ 2014-08-11 22:21 UTC (permalink / raw)
  To: amodra; +Cc: binutils, hjl.tools

> From: Alan Modra <amodra@gmail.com>
> Date: Thu, 7 Aug 2014 02:54:51 +0200

> So now that I've merged the WARN and CWARN
> my concern with HJ's patch is covered.  This is what I'm about to
> commit on HJ's behalf.
> 
> bfd/
> 	PR ld/16746
> 	* linker.c (_bfd_generic_link_add_one_symbol): Don't issue a
> 	warning for references in LTO IR to warning symbols.
> 
> ld/testsuite/
> 	PR ld/16746
> 	* ld-plugin/lto.exp: Add 4 tests for PR ld/16746.
> 	* ld-plugin/pr16746a.c: New file.
> 	* ld-plugin/pr16746b.c: Likewise.
> 	* ld-plugin/pr16746c.c: Likewise.
> 	* ld-plugin/pr16746d.c: Likewise.

This, commit db7129469b, regressed ld-cris/warn3 for cris-elf:
Running /home/hp/binutils/src/ld/testsuite/ld-cris/cris.exp ...
FAIL: ld-cris/warn3

(The test-case checks stabs warning support for cris a.out; the
expected warning is no longer emitted after that commit.  If you
want to remove stabs-aout-warning support altogether I don't
really mind, but I assume you agree that should be an explicit
change only done after verifying that there is no other issue
affecting warnings support.  Stabs warnings for ELF was broken
since long, see ld-cris/warn4.d)

brgds, H-P

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR
  2014-08-11 22:21   ` Hans-Peter Nilsson
@ 2014-08-12  1:12     ` Alan Modra
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Modra @ 2014-08-12  1:12 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: binutils, hjl.tools

On Tue, Aug 12, 2014 at 12:21:47AM +0200, Hans-Peter Nilsson wrote:
> This, commit db7129469b, regressed ld-cris/warn3 for cris-elf:
> Running /home/hp/binutils/src/ld/testsuite/ld-cris/cris.exp ...
> FAIL: ld-cris/warn3

That was silly of me.  non_ir_ref is only valid when plugins are
active.

	PR ld/16746
include/
	* bfdlink.h (struct bfd_link_info): Add lto_plugin_active.
bfd/
	* linker.c (_bfd_generic_link_add_one_symbol <WARN>): Handle
	!lto_plugin_active.
ld/
	* plugin.c (plugin_load_plugins): Set link_info.lto_plugin_active.

diff --git a/bfd/linker.c b/bfd/linker.c
index d4b053c..1a5ecef 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -1806,7 +1806,9 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 	case WARN:
 	  /* Warn if this symbol has been referenced already from non-IR,
 	     otherwise add a warning.  */
-	  if (h->non_ir_ref)
+	  if ((!info->lto_plugin_active
+	       && (h->u.undef.next != NULL || info->hash->undefs_tail == h))
+	      || h->non_ir_ref)
 	    {
 	      if (! (*info->callbacks->warning) (info, string, h->root.string,
 						 hash_entry_bfd (h), NULL, 0))
diff --git a/include/bfdlink.h b/include/bfdlink.h
index fc14a9f..58dba2a 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -292,6 +292,9 @@ struct bfd_link_info
      callback.  */
   unsigned int notice_all: 1;
 
+  /* TRUE if the LTO plugin is active.  */
+  unsigned int lto_plugin_active: 1;
+
   /* TRUE if we are loading LTO outputs.  */
   unsigned int loading_lto_outputs: 1;
 
diff --git a/ld/plugin.c b/ld/plugin.c
index f10c273..8d6ae05 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -841,6 +841,7 @@ plugin_load_plugins (void)
   plugin_callbacks = *orig_callbacks;
   plugin_callbacks.notice = &plugin_notice;
   link_info.notice_all = TRUE;
+  link_info.lto_plugin_active = TRUE;
   link_info.callbacks = &plugin_callbacks;
 }
 

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-08-12  1:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-07  0:42 Merge WARN and CWARN cases in _bfd_generic_link_add_one_symbol Alan Modra
2014-08-07  0:55 ` [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR Alan Modra
2014-08-11 22:21   ` Hans-Peter Nilsson
2014-08-12  1:12     ` Alan Modra

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).