bfd/
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 3 Jun 2003 18:15:05 +0000 (18:15 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 3 Jun 2003 18:15:05 +0000 (18:15 +0000)
2003-06-03  H.J. Lu <hongjiu.lu@intel.com>

* elflink.h (elf_link_input_bfd): Call linker error_handler
for discarded definitions.

include/

2003-06-03  H.J. Lu <hongjiu.lu@intel.com>

* bfdlink.h (LD_DEFINITION_IN_DISCARDED_SECTION): New.

ld/

2003-06-03  H.J. Lu <hongjiu.lu@intel.com>

* ldmisc.c: Include "bfdlink.h".
(error_handler): Handle LD_DEFINITION_IN_DISCARDED_SECTION
and -LD_DEFINITION_IN_DISCARDED_SECTION.

* Makefile.am: Rebuild dependency.
* Makefile.in: Regenerated.

ld/testsuite/

2003-06-03  H.J. Lu <hongjiu.lu@intel.com>

* ld-discard/extern.d: Updated.
* ld-discard/start.d: Likewise.
* ld-discard/static.d: Likewise.

12 files changed:
bfd/ChangeLog
bfd/elflink.h
include/ChangeLog
include/bfdlink.h
ld/ChangeLog
ld/Makefile.am
ld/Makefile.in
ld/ldmisc.c
ld/testsuite/ChangeLog
ld/testsuite/ld-discard/extern.d
ld/testsuite/ld-discard/start.d
ld/testsuite/ld-discard/static.d

index cbd2b41e449a62d6ae43a5bc5b9797c93f1e7db4..9ff266ae4629a49874b2688cbe40b529d11355b5 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-03  H.J. Lu <hongjiu.lu@intel.com>
+
+       * elflink.h (elf_link_input_bfd): Call linker error_handler
+       for discarded definitions.
+
 2003-06-03  Elias Athanasopoulos  <elathan@phys.uoa.gr>
 
        * syms.c (decode_section_type): Return 'n' if section flags are
index e7019f3761ea9427e7229e7f242cf82618475c3f..a7ef7427bf35ef904aa557845d7da815cc4d2661 100644 (file)
@@ -5003,13 +5003,13 @@ elf_link_input_bfd (finfo, input_bfd)
                              memset (rel, 0, sizeof (*rel));
                            }
                          else
-                           {
-                             if (! ((*finfo->info->callbacks->undefined_symbol)
-                                    (finfo->info, h->root.root.string,
-                                     input_bfd, o, rel->r_offset,
-                                     TRUE)))
-                               return FALSE;
-                           }
+                           finfo->info->callbacks->error_handler
+                             (LD_DEFINITION_IN_DISCARDED_SECTION,
+                              _("%T: discarded in section `%s' from %s\n"),
+                              h->root.root.string,
+                              h->root.root.string,
+                              h->root.u.def.section->name,
+                              bfd_archive_filename (h->root.u.def.section->owner));
                        }
                    }
                  else
@@ -5028,26 +5028,21 @@ elf_link_input_bfd (finfo, input_bfd)
                            }
                          else
                            {
-                             bfd_boolean ok;
-                             const char *msg
-                               = _("local symbols in discarded section %s");
-                             bfd_size_type amt
-                               = strlen (sec->name) + strlen (msg) - 1;
-                             char *buf = (char *) bfd_malloc (amt);
-
-                             if (buf != NULL)
-                               sprintf (buf, msg, sec->name);
-                             else
-                               buf = (char *) sec->name;
-                             ok = (*finfo->info->callbacks
-                                   ->undefined_symbol) (finfo->info, buf,
-                                                        input_bfd, o,
-                                                        rel->r_offset,
-                                                        TRUE);
-                             if (buf != sec->name)
+                             static int count;
+                             int ok;
+                             char *buf;
+
+                             ok = asprintf (&buf, "local symbol %d",
+                                            count++);
+                             if (ok <= 0)
+                               buf = (char *) "local symbol";
+                             finfo->info->callbacks->error_handler
+                               (LD_DEFINITION_IN_DISCARDED_SECTION,
+                                _("%T: discarded in section `%s' from %s\n"),
+                                buf, buf, sec->name,
+                                bfd_archive_filename (input_bfd));
+                             if (ok != -1)
                                free (buf);
-                             if (!ok)
-                               return FALSE;
                            }
                        }
                    }
index 41e67bc3307c3c0a8c7d1997699061aa5a282326..96f1777729ee8821a4a4c3b640e9d5c3067de172 100644 (file)
@@ -1,3 +1,7 @@
+2003-06-03  H.J. Lu <hongjiu.lu@intel.com>
+
+       * bfdlink.h (LD_DEFINITION_IN_DISCARDED_SECTION): New.
+
 2003-05-30  Ulrich Drepper  <drepper@redhat.com>
            Jakub Jelinek  <jakub@redhat.com>
 
index 61fcf96f4091b2b103e420645af8c96590b9eb2e..d68fe113f1f864232c9a45b8a9ecb0202c23efda 100644 (file)
@@ -495,6 +495,9 @@ struct bfd_link_callbacks
      ld.  */
   bfd_boolean (*error_handler)
     PARAMS ((int id, const char * fmt, ...));
+
+/* Identifiers of linker error messages used by error_handler.  */
+#define LD_DEFINITION_IN_DISCARDED_SECTION     1
 };
 \f
 /* The linker builds link_order structures which tell the code how to
index 731f6ecfd2ae53771f4c3c446f055d183bf10025..2652c8d4bb9a0c741dc3501ae9b9c685f5470350 100644 (file)
@@ -1,3 +1,12 @@
+2003-06-03  H.J. Lu <hongjiu.lu@intel.com>
+
+       * ldmisc.c: Include "bfdlink.h".
+       (error_handler): Handle LD_DEFINITION_IN_DISCARDED_SECTION
+       and -LD_DEFINITION_IN_DISCARDED_SECTION.
+
+       * Makefile.am: Rebuild dependency.
+       * Makefile.in: Regenerated.
+
 2003-06-03  Kaz Kojima  <kkojima@rr.iij4u.or.jp>
 
        * emulparams/shlelf_linux.sh (GENERATE_PIE_SCRIPT): Set to yes.
index a09ccfec73b5b946a77c6a8ac50e91f2aa570b39..0ad082412a8725bc41c5cffe3088a1b540130bb6 100644 (file)
@@ -1662,10 +1662,10 @@ ldmain.o: ldmain.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
   ldmain.h ldmisc.h ldwrite.h ldexp.h ldlang.h ldgram.h \
   ldlex.h ldfile.h ldemul.h ldctor.h
 ldmisc.o: ldmisc.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
-  $(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
-  $(INCDIR)/libiberty.h $(INCDIR)/demangle.h ld.h $(INCDIR)/bin-bugs.h \
-  ldmisc.h ldexp.h ldlang.h ldgram.h ldlex.h ldmain.h \
-  ldfile.h
+  $(INCDIR)/symcat.h $(INCDIR)/bfdlink.h sysdep.h config.h \
+  $(INCDIR)/fopen-same.h $(INCDIR)/libiberty.h $(INCDIR)/demangle.h \
+  ld.h $(INCDIR)/bin-bugs.h ldmisc.h ldexp.h ldlang.h \
+  ldgram.h ldlex.h ldmain.h ldfile.h
 ldver.o: ldver.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
   $(INCDIR)/symcat.h ../bfd/bfdver.h sysdep.h config.h \
   $(INCDIR)/fopen-same.h ld.h $(INCDIR)/bin-bugs.h ldver.h \
index f3e7cc5b2425a8d88ffe4be1d7a0a4f7ce0436bb..bd4b71cf58134c2586a3100adc387e3011a4ee3b 100644 (file)
@@ -2362,10 +2362,10 @@ ldmain.o: ldmain.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
   ldmain.h ldmisc.h ldwrite.h ldexp.h ldlang.h ldgram.h \
   ldlex.h ldfile.h ldemul.h ldctor.h
 ldmisc.o: ldmisc.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
-  $(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
-  $(INCDIR)/libiberty.h $(INCDIR)/demangle.h ld.h $(INCDIR)/bin-bugs.h \
-  ldmisc.h ldexp.h ldlang.h ldgram.h ldlex.h ldmain.h \
-  ldfile.h
+  $(INCDIR)/symcat.h $(INCDIR)/bfdlink.h sysdep.h config.h \
+  $(INCDIR)/fopen-same.h $(INCDIR)/libiberty.h $(INCDIR)/demangle.h \
+  ld.h $(INCDIR)/bin-bugs.h ldmisc.h ldexp.h ldlang.h \
+  ldgram.h ldlex.h ldmain.h ldfile.h
 ldver.o: ldver.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
   $(INCDIR)/symcat.h ../bfd/bfdver.h sysdep.h config.h \
   $(INCDIR)/fopen-same.h ld.h $(INCDIR)/bin-bugs.h ldver.h \
index a2e496da9c07552c88548ea178e9d6787ef995a1..461d697274d5c9e9bb0f06f7cbb07523b16865dd 100644 (file)
@@ -22,6 +22,7 @@
    02111-1307, USA.  */
 
 #include "bfd.h"
+#include "bfdlink.h"
 #include "sysdep.h"
 #include "libiberty.h"
 #include "demangle.h"
@@ -508,12 +509,63 @@ ld_abort (file, line, fn)
 }
 
 bfd_boolean
-error_handler VPARAMS ((int id ATTRIBUTE_UNUSED, const char *fmt, ...))
+error_handler VPARAMS ((int id, const char *fmt, ...))
 {
   VA_OPEN (arg, fmt);
   VA_FIXEDARG (arg, const char *, fmt);
 
+  va_start (arg, fmt);
+
+  switch (id)
+    {
+    default:
+      break;
+
+    /* We can be called with
+    
+       error_handler (-LD_DEFINITION_IN_DISCARDED_SECTION, "", 0);
+       
+       to make this error non-fatal and
+
+       error_handler (-LD_DEFINITION_IN_DISCARDED_SECTION, "", 1);
+
+       to make this error fatal.  */
+    case -LD_DEFINITION_IN_DISCARDED_SECTION:
+    case LD_DEFINITION_IN_DISCARDED_SECTION:
+      {
+       static struct bfd_hash_table *hash;
+       static int fatal = 1;
+       const char *name;
+
+       if (id == -LD_DEFINITION_IN_DISCARDED_SECTION)
+         {
+           fatal = va_arg (arg, int);
+           goto out;
+         }
+
+       name = va_arg (arg, const char *);
+       /* Only warn once about a particular undefined symbol.  */
+       if (hash == NULL)
+         {
+           hash = ((struct bfd_hash_table *)
+                   xmalloc (sizeof (struct bfd_hash_table)));
+           if (! bfd_hash_table_init (hash, bfd_hash_newfunc))
+             einfo (_("%F%P: bfd_hash_table_init failed: %E\n"));
+         }
+
+       if (bfd_hash_lookup (hash, name, FALSE, FALSE) != NULL)
+         goto out;
+
+       if (bfd_hash_lookup (hash, name, TRUE, TRUE) == NULL)
+         einfo (_("%F%P: bfd_hash_lookup failed: %E\n"));
+
+       if (fatal)
+         config.make_executable = FALSE;
+      }
+      break;
+    }
   vfinfo (stderr, fmt, arg);
+out:
   VA_CLOSE (arg);
   return TRUE;
 }
index 8cdb4c49fca95ec9b7860e644ffe9145a78708aa..cd38c94d1901a3bc8d6586972ecad869bdeb3ee2 100644 (file)
@@ -1,3 +1,9 @@
+2003-06-03  H.J. Lu <hongjiu.lu@intel.com>
+
+       * ld-discard/extern.d: Updated.
+       * ld-discard/start.d: Likewise.
+       * ld-discard/static.d: Likewise.
+
 2003-06-03  H.J. Lu <hongjiu.lu@intel.com>
 
        * ld-elfcomm/elfcomm.exp: Mark tests untested if compiler is
index 76d4263d7f76d0c58c781055ff8d268265cb11a2..10fa0f756f16c9de4930b41fd367aa596f6673c1 100644 (file)
@@ -1,3 +1,3 @@
 #source: extern.s
 #ld: -T discard.ld
-#error: undefined reference to `(data|local symbols in discarded section \.data\.exit)'
+#error: data: discarded in section `\.data\.exit' from tmpdir/dump0.o
index feef5eac9f9fb990d1e5aba585d0c94bb473ca55..b8f46ae7867accadf5aa39eb8dfd02726ffa26d6 100644 (file)
@@ -1,4 +1,4 @@
 #source: start.s
 #source: exit.s
 #ld: -T discard.ld
-#error: undefined reference to `data'
+#error: data: discarded in section `\.data\.exit' from tmpdir/dump1.o
index 2253f1aeac3fe97f85c0b6750be41d69639a4608..78b89b03136a02bdd72fc1aebe45b84cdbfe3d9a 100644 (file)
@@ -1,3 +1,3 @@
 #source: static.s
 #ld: -T discard.ld
-#error: undefined reference to `local symbols in discarded section \.data\.exit'
+#error: local symbol 0: discarded in section `\.data\.exit' from tmpdir/dump0.o