This is the mail archive of the
mailing list for the binutils project.
Re: PR14962 fix
On Sun, Dec 16, 2012 at 4:18 PM, Alan Modra <firstname.lastname@example.org> wrote:
> When I first looked at PR14962 I was inclined to close the bug as
> WONTFIX, but I like the clever hack used to avoid cross-reference
> warnings on a subset of symbols. The reporter uses self-assignment in
> a linker script to convert symbols to absolute, thus avoiding the
> cross-reference check.
> The problem is that ld now runs lang_do_assignments early, before
> sections are mapped to output sections. Trying to convert symbols
> to absolute results in wrong values because section VMAs are not set.
> Of course, once the symbol is absolute it loses its original section,
> so a later lang_do_assingments won't correct the value. So we need to
> prevent self-assignment until section placement is complete.
> Interestingly, ldexp.c already contains code to catch a very limited
> set of self-assignment expressions, and ldlang.c has a more
> sophisticated recursive descent check for self-assignment. This patch
> replaces both lots of code with a simple modification to the normal
> expression evaluation code. Besides fixing the PR, I think this
> behaves better than the old scan_for_self_assignment(): The old code
> saw a reference on the false branch of "?:" as a self-assignment, and
> references in DEFINED(), and could get confused by symbols that
> happened to have the same name as a section.
> Not that the new code will catch all self-assignments. For example,
> x = ld_eval_count + 1;
> ld_eval_count = x;
> will circumvent the checks.
> PR ld/14962
> * ldexp.h (struct ldexp_control): Add "assign_name".
> * ldexp.c (fold_name <NAME>): Compare and clear assign_name on match.
> (exp_fold_tree_1): Remove existing code testing for self assignment.
> Instead set and test expld.assign_name.
> * ldlang.c (scan_for_self_assignment): Delete.
> (print_assignment): Instead set and test expld.assign_name.
We need a testcase to verify that it works as