PATCH: Better messages for discarde section
H. J. Lu
hjl@lucon.org
Tue Jun 3 17:17:00 GMT 2003
On Tue, Jun 03, 2003 at 05:46:25PM +0100, Nick Clifton wrote:
>
>
> >> > -error_handler VPARAMS ((int id ATTRIBUTE_UNUSED, const char *fmt, ...))
> >> > +error_handler (int id, const char *fmt, ...)
> >> > {
> >> > - VA_OPEN (arg, fmt);
> >> > - VA_FIXEDARG (arg, const char *, fmt);
> >>
> >> Please do not remove the V.... macros. We have not switched over to
> >> using IsoC. (Well not yet anyway).
> >
> > I am not sure if I have a choice here since va_copy is used, which
> > is not available in K&R C.
>
> Why are you using va_copy ? If it is only because of the recursive
> call to einfo() inside your new code, then it might be cleaner to just
> set a flag and then tail-call einfo at the end of the function. That
> way it should work with K&R as well.
I used va_arg, which will advance arg. I changed my code to pass
another symbol name so that I can check if a warning has been
issued before.
>
>
> > + case -LD_DEFINITION_IN_DISCARDED_SECTION:
> > + case LD_DEFINITION_IN_DISCARDED_SECTION:
>
> What is the purpose of the negative version of
> LD_DEFINITION_IN_DISCARDED_SECTION ? Does anything use it ? Assuming
> that it is needed, it ought to be documented in a comment somewhere.
>
No one uses it yet. I can image we add "ld dicardisnotfatal" or
something like that.
H.J.
-------------- next part --------------
bfd/
2003-05-30 H.J. Lu <hongjiu.lu@intel.com>
* elflink.h (elf_link_input_bfd): Call linker error_handler
for discarded definitions.
include/
2003-05-30 H.J. Lu <hongjiu.lu@intel.com>
* bfdlink.h (LD_DEFINITION_IN_DISCARDED_SECTION): New.
ld/
2003-06-02 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-02 H.J. Lu <hongjiu.lu@intel.com>
* ld-discard/extern.d: Updated.
* ld-discard/start.d: Likewise.
* ld-discard/static.d: Likewise.
--- binutils/bfd/elflink.h.discard 2003-06-02 07:27:25.000000000 -0700
+++ binutils/bfd/elflink.h 2003-06-03 10:04:08.000000000 -0700
@@ -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;
}
}
}
--- binutils/include/bfdlink.h.discard 2003-06-02 07:27:26.000000000 -0700
+++ binutils/include/bfdlink.h 2003-06-03 08:09:52.000000000 -0700
@@ -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
};
/* The linker builds link_order structures which tell the code how to
--- binutils/ld/Makefile.am.discard 2003-06-02 16:19:16.000000000 -0700
+++ binutils/ld/Makefile.am 2003-06-03 08:15:35.000000000 -0700
@@ -1668,10 +1668,10 @@ ldmain.o: ldmain.c ../bfd/bfd.h $(INCDIR
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 \
--- binutils/ld/Makefile.in.discard 2003-06-02 16:19:16.000000000 -0700
+++ binutils/ld/Makefile.in 2003-06-03 08:17:10.000000000 -0700
@@ -2368,10 +2368,10 @@ ldmain.o: ldmain.c ../bfd/bfd.h $(INCDIR
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 \
--- binutils/ld/ldmisc.c.discard 2003-04-24 14:19:08.000000000 -0700
+++ binutils/ld/ldmisc.c 2003-06-03 10:08:52.000000000 -0700
@@ -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;
}
--- binutils/ld/testsuite/ld-discard/extern.d.discard 2002-10-12 08:43:29.000000000 -0700
+++ binutils/ld/testsuite/ld-discard/extern.d 2003-06-02 16:19:16.000000000 -0700
@@ -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
--- binutils/ld/testsuite/ld-discard/start.d.discard 2002-10-12 08:43:29.000000000 -0700
+++ binutils/ld/testsuite/ld-discard/start.d 2003-06-02 16:19:16.000000000 -0700
@@ -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
--- binutils/ld/testsuite/ld-discard/static.d.discard 2002-10-12 08:43:29.000000000 -0700
+++ binutils/ld/testsuite/ld-discard/static.d 2003-06-02 16:19:16.000000000 -0700
@@ -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
More information about the Binutils
mailing list