This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: PR ld/4090: Can't use ADDR on section after
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Sat, 31 Mar 2007 16:49:48 -0700
- Subject: PATCH: PR ld/4090: Can't use ADDR on section after
When we report problem in linker script, we may refer to the wrong
line number in linker script. It makes the error hard to find when
the linker script is quite line. This patch addresses this problem
by storing line number in node_type and set lineno before reporting
linker script problem.
H.J.
----
2007-03-31 H.J. Lu <hongjiu.lu@intel.com>
PR ld/4090
* ldexp.h (node_type): Add lineno.
* ldexp.c: Include "ldlex.h".
(exp_intop): Set the lineno field from lineno.
(exp_bigintop): Likewise.
(exp_relop): Likewise.
(exp_nameop): Likewise.
(exp_binop): Set the lineno field from lineno of lhs.
(exp_trinop): Likewise.
(exp_unop): Set the lineno field from lineno of child.
(exp_assop): Set the lineno field from lineno of src.
(exp_provide): Likewise.
(exp_assert): Set the lineno field from lineno of exp.
(exp_get_abs_int): Set lineno from lineno of nonconstant
expression when report problem.
--- ld/ldexp.c.loc 2007-03-31 07:56:37.000000000 -0700
+++ ld/ldexp.c 2007-03-31 16:45:01.000000000 -0700
@@ -36,6 +36,7 @@
#include "ldmain.h"
#include "ldmisc.h"
#include "ldexp.h"
+#include "ldlex.h"
#include <ldgram.h>
#include "ldlang.h"
#include "libiberty.h"
@@ -150,6 +151,7 @@ exp_intop (bfd_vma value)
{
etree_type *new = stat_alloc (sizeof (new->value));
new->type.node_code = INT;
+ new->type.lineno = lineno;
new->value.value = value;
new->value.str = NULL;
new->type.node_class = etree_value;
@@ -161,6 +163,7 @@ exp_bigintop (bfd_vma value, char *str)
{
etree_type *new = stat_alloc (sizeof (new->value));
new->type.node_code = INT;
+ new->type.lineno = lineno;
new->value.value = value;
new->value.str = str;
new->type.node_class = etree_value;
@@ -174,6 +177,7 @@ exp_relop (asection *section, bfd_vma va
{
etree_type *new = stat_alloc (sizeof (new->rel));
new->type.node_code = REL;
+ new->type.lineno = lineno;
new->type.node_class = etree_rel;
new->rel.section = section;
new->rel.value = value;
@@ -831,6 +835,7 @@ exp_binop (int code, etree_type *lhs, et
etree_type value, *new;
value.type.node_code = code;
+ value.type.lineno = lhs->type.lineno;
value.binary.lhs = lhs;
value.binary.rhs = rhs;
value.type.node_class = etree_binary;
@@ -849,6 +854,7 @@ exp_trinop (int code, etree_type *cond,
etree_type value, *new;
value.type.node_code = code;
+ value.type.lineno = lhs->type.lineno;
value.trinary.lhs = lhs;
value.trinary.cond = cond;
value.trinary.rhs = rhs;
@@ -868,6 +874,7 @@ exp_unop (int code, etree_type *child)
etree_type value, *new;
value.unary.type.node_code = code;
+ value.unary.type.lineno = child->type.lineno;
value.unary.child = child;
value.unary.type.node_class = etree_unary;
exp_fold_tree_no_dot (&value);
@@ -885,6 +892,7 @@ exp_nameop (int code, const char *name)
etree_type value, *new;
value.name.type.node_code = code;
+ value.name.type.lineno = lineno;
value.name.name = name;
value.name.type.node_class = etree_name;
@@ -905,6 +913,7 @@ exp_assop (int code, const char *dst, et
new = stat_alloc (sizeof (new->assign));
new->type.node_code = code;
+ new->type.lineno = src->type.lineno;
new->type.node_class = etree_assign;
new->assign.src = src;
new->assign.dst = dst;
@@ -920,6 +929,7 @@ exp_provide (const char *dst, etree_type
n = stat_alloc (sizeof (n->assign));
n->assign.type.node_code = '=';
+ n->assign.type.lineno = src->type.lineno;
n->assign.type.node_class = etree_provide;
n->assign.src = src;
n->assign.dst = dst;
@@ -936,6 +946,7 @@ exp_assert (etree_type *exp, const char
n = stat_alloc (sizeof (n->assert_s));
n->assert_s.type.node_code = '!';
+ n->assert_s.type.lineno = exp->type.lineno;
n->assert_s.type.node_class = etree_assert;
n->assert_s.child = exp;
n->assert_s.message = message;
@@ -1114,7 +1125,10 @@ exp_get_abs_int (etree_type *tree, int d
return expld.result.value;
}
else if (name != NULL && expld.phase != lang_mark_phase_enum)
- einfo (_("%F%S nonconstant expression for %s\n"), name);
+ {
+ lineno = tree->type.lineno;
+ einfo (_("%F%S: nonconstant expression for %s\n"), name);
+ }
}
return def;
}
--- ld/ldexp.h.loc 2007-03-31 07:56:37.000000000 -0700
+++ ld/ldexp.h 2007-03-31 16:24:18.000000000 -0700
@@ -32,6 +32,7 @@ typedef struct {
typedef struct {
int node_code;
+ unsigned int lineno;
enum {
etree_binary,
etree_trinary,