diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2015-01-07 10:51:35 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2015-01-20 09:49:27 +0000 |
commit | c05b575a8dfabab6af5d8586d1a5c0c67f819ac2 (patch) | |
tree | d235fe75c600d32d9f4d1e6b0044ec1838299ea9 /ld/ldlang.c | |
parent | 43d66c95c826441c64bacfa07095535ddea57a51 (diff) | |
download | gdb-c05b575a8dfabab6af5d8586d1a5c0c67f819ac2.zip gdb-c05b575a8dfabab6af5d8586d1a5c0c67f819ac2.tar.gz gdb-c05b575a8dfabab6af5d8586d1a5c0c67f819ac2.tar.bz2 |
ld: Don't evaluate unneeded PROVIDE expressions.
When creating a linker mapfile (using -Map=MAPFILE), we previously would
always try to evaluate the expression from a PROVIDE statement.
However, this is not always safe, consider:
PROVIDE (foo = 0x10);
PROVIDE (bar = foo);
In this example, if neither 'foo' or 'bar' is needed, then while
generating the linker mapfile evaluating the expression for 'foo' is
harmless (just the value 0x10). However, evaluating the expression for
'bar' requires the symbol 'foo', which is undefined. This used to cause
a fatal error.
This patch changes the behaviour, so that when the destination of the
PROVIDE is not defined (that is the PROVIDE is not going to provide
anything) the expression is not evaluated, and instead a special string
is displayed to indicate that the linker is discarding the PROVIDE
statement.
This change not only fixes the spurious undefined symbol error, but also
means that a user can now tell if a PROVIDE statement has provided
anything by inspecting the linker mapfile, something that could not be
done before.
ld/ChangeLog:
* ldlang.c (print_assignment): Only evaluate the expression for a
PROVIDE'd assignment when the destination is being defined.
Display a special message for PROVIDE'd symbols that are not being
provided.
ld/testsuite/ChangeLog:
* ld-scripts/provide-4.d: New file.
* ld-scripts/provide-4-map.d: New file.
* ld-scripts/provide-4.t: New file.
* ld-scripts/provide-5.d: New file.
* ld-scripts/provide-5.s: New file.
* ld-scripts/provide-5-map.d: New file.
* ld-scripts/provide-5.t: New file.
* ld-scripts/provide.exp: Run the provide-4.d and provide-5.d
tests.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r-- | ld/ldlang.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c index 0c72333..3ea22c2 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -3983,7 +3983,12 @@ print_assignment (lang_assignment_statement_type *assignment, osec = output_section->bfd_section; if (osec == NULL) osec = bfd_abs_section_ptr; - exp_fold_tree (tree, osec, &print_dot); + + if (assignment->exp->type.node_class != etree_provide) + exp_fold_tree (tree, osec, &print_dot); + else + expld.result.valid_p = FALSE; + if (expld.result.valid_p) { bfd_vma value; @@ -4021,7 +4026,10 @@ print_assignment (lang_assignment_statement_type *assignment, } else { - minfo ("*undef* "); + if (assignment->exp->type.node_class == etree_provide) + minfo ("[!provide]"); + else + minfo ("*undef* "); #ifdef BFD64 minfo (" "); #endif |