This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ld - fix for bug 13343


Hi,

I'm new here, I filed a minor bug report http://sourceware.org/bugzilla/show_bug.cgi?id=13343
about a useless error message in ld.

Here is a patch to fix it (based on v2.20, but should apply cleanly to the head). Tell me what you think.

Regards
Geza Lore


Author: Geza Lore <geza.lore@broadcom.com>
Date:?? Tue Oct 25 12:48:26 2011 +0100

??? Linker now gives useful error message.
??? 
????Fixed issue by annotating internal data structures with the name of the source
??? file they have been created from. The linker now identifies the script
??? and line number correctly where we were trying to decrement the location
??? counter, and also identifies the output section.

diff --git a/binutils/ld/ldexp.c b/binutils/ld/ldexp.c
index 62dcfd8..abc9b54 100644
--- a/binutils/ld/ldexp.c
+++ b/binutils/ld/ldexp.c
@@ -157,6 +157,7 @@ exp_intop (bfd_vma value)
?? etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->value));
?? new_e->type.node_code = INT;
?? new_e->type.lineno = lineno;
+? new_e->type.file_name = ldlex_get_file_name();
?? new_e->value.value = value;
?? new_e->value.str = NULL;
?? new_e->type.node_class = etree_value;
@@ -169,6 +170,7 @@ exp_bigintop (bfd_vma value, char *str)
?? etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->value));
?? new_e->type.node_code = INT;
?? new_e->type.lineno = lineno;
+? new_e->type.file_name = ldlex_get_file_name();
?? new_e->value.value = value;
?? new_e->value.str = str;
?? new_e->type.node_class = etree_value;
@@ -183,6 +185,7 @@ exp_relop (asection *section, bfd_vma value)
?? etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->rel));
?? new_e->type.node_code = REL;
?? new_e->type.lineno = lineno;
+? new_e->type.file_name = ldlex_get_file_name();
?? new_e->type.node_class = etree_rel;
?? new_e->rel.section = section;
?? new_e->rel.value = value;
@@ -765,8 +768,10 @@ exp_fold_tree_1 (etree_type *tree)
?????????? ??nextdot = expld.result.value + expld.section->vma;
?????????? ??if (nextdot < expld.dot
?????????? ??????&& expld.section != bfd_abs_section_ptr)
-?????????? ??? einfo (_("%F%S cannot move location counter backwards"
-???????????????? ???? " (from %V to %V)\n"), expld.dot, nextdot);
+?????????? ??? einfo (_("%F%s:%d cannot move location counter backwards"
+???????????????? ??? " (from %V to %V) in output section %s\n"),
+???????????????? ??? tree->type.file_name, tree->type.lineno, expld.dot,
+???????????????? ??? nextdot, expld.section->name);
?????????? ??else
?????????? ????{
?????????? ??????expld.dot = nextdot;
@@ -856,6 +861,7 @@ exp_binop (int code, etree_type *lhs, etree_type *rhs)

???value.type.node_code = code;
?? value.type.lineno = lhs->type.lineno;
+? value.type.file_name = lhs->type.file_name;
?? value.binary.lhs = lhs;
?? value.binary.rhs = rhs;
?? value.type.node_class = etree_binary;
@@ -875,6 +881,7 @@ exp_trinop (int code, etree_type *cond, etree_type *lhs, etree_type *rhs)

???value.type.node_code = code;
?? value.type.lineno = lhs->type.lineno;
+? value.type.file_name = lhs->type.file_name;
?? value.trinary.lhs = lhs;
?? value.trinary.cond = cond;
?? value.trinary.rhs = rhs;
@@ -895,6 +902,7 @@ exp_unop (int code, etree_type *child)

???value.unary.type.node_code = code;
?? value.unary.type.lineno = child->type.lineno;
+? value.unary.type.file_name = child->type.file_name;
?? value.unary.child = child;
?? value.unary.type.node_class = etree_unary;
?? exp_fold_tree_no_dot (&value);
@@ -913,6 +921,7 @@ exp_nameop (int code, const char *name)

???value.name.type.node_code = code;
?? value.name.type.lineno = lineno;
+? value.name.type.file_name = ldlex_get_file_name();
?? value.name.name = name;
?? value.name.type.node_class = etree_name;

@@ -934,6 +943,7 @@ exp_assop (int code, const char *dst, etree_type *src)
?? new_e = (etree_type *) stat_alloc (sizeof (new_e->assign));
?? new_e->type.node_code = code;
?? new_e->type.lineno = src->type.lineno;
+? new_e->type.file_name = src->type.file_name;
?? new_e->type.node_class = etree_assign;
?? new_e->assign.src = src;
?? new_e->assign.dst = dst;
@@ -950,6 +960,7 @@ exp_provide (const char *dst, etree_type *src, bfd_boolean hidden)
?? n = (etree_type *) stat_alloc (sizeof (n->assign));
?? n->assign.type.node_code = '=';
?? n->assign.type.lineno = src->type.lineno;
+? n->assign.type.file_name = src->type.file_name;
?? n->assign.type.node_class = etree_provide;
?? n->assign.src = src;
?? n->assign.dst = dst;
@@ -967,6 +978,7 @@ exp_assert (etree_type *exp, const char *message)
?? n = (etree_type *) stat_alloc (sizeof (n->assert_s));
?? n->assert_s.type.node_code = '!';
?? n->assert_s.type.lineno = exp->type.lineno;
+? n->assert_s.type.file_name = exp->type.file_name;
?? n->assert_s.type.node_class = etree_assert;
?? n->assert_s.child = exp;
?? n->assert_s.message = message;
diff --git a/binutils/ld/ldexp.h b/binutils/ld/ldexp.h
index a15f64a..97091c4 100644
--- a/binutils/ld/ldexp.h
+++ b/binutils/ld/ldexp.h
@@ -46,6 +46,7 @@ enum node_tree_enum {
typedef struct {
?? int node_code;
?? unsigned int lineno;
+? const char *file_name;
?? enum? node_tree_enum node_class;
} node_type;

diff --git a/binutils/ld/ldlex.h b/binutils/ld/ldlex.h
index 9663ce0..193b8e3 100644
--- a/binutils/ld/ldlex.h
+++ b/binutils/ld/ldlex.h
@@ -52,6 +52,7 @@ extern void ldlex_expression (void);
extern void ldlex_both (void);
extern void ldlex_command (void);
extern void ldlex_popstate (void);
+extern const char* ldlex_get_file_name (void);

?/* In lexsup.c.? */
extern int lex_input (void);
diff --git a/binutils/ld/ldlex.l b/binutils/ld/ldlex.l
index 5d5574d..034e773 100644
--- a/binutils/ld/ldlex.l
+++ b/binutils/ld/ldlex.l
@@ -603,6 +603,15 @@ ldlex_popstate (void)
{
?? yy_start = *(--state_stack_p);
}
+
+const char*
+ldlex_get_file_name (void)
+{
+??? if (include_stack_ptr > 0)
+??????? return file_name_stack[include_stack_ptr-1];
+??? else
+??????? return NULL;
+}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]