Bug 13343 - cannot move location counter backwards - Error message provides useless source-file-name:lineno information
Summary: cannot move location counter backwards - Error message provides useless sourc...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-25 15:54 UTC by Geza Lore
Modified: 2012-02-18 12:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geza Lore 2011-10-25 15:54:52 UTC
The line number and source file name information provided with the "cannot move location counter backwards" error message always points after the last line of the last processed linker script. This makes tracking this error down in complex scripts difficult.

To reproduce, use this linker script to link anything with a .text section in it:

script.ld:

SECTIONS {
    text_test_section : {
        *(.text)

        . += -1;
    }
}

E.g.:
bash$ ld -T script.ld foo.o
script.ld:9 cannot move location counter backwards (from 00000000000000b8 to 00000000000000b7)

More demonstratively:
bash$ ld -T script.ld -T /dev/null foo.o
/dev/null:1 cannot move location counter backwards (from 00000000000000b8 to 00000000000000b7)

The error should identify the correct source file and line number and the offending output section.
Comment 1 Sourceware Commits 2012-02-17 14:10:05 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2012-02-17 14:09:57

Modified files:
	ld             : ChangeLog ld.h ldemul.c ldexp.c ldexp.h 
	                 ldfile.c ldfile.h ldgram.y ldlang.c ldlex.h 
	                 ldlex.l ldmain.c ldmisc.c lexsup.c 

Log message:
	PR ld/13343
	* ld.h (parsing_defsym): Delete.
	* ldexp.c (exp_intop, exp_bigintop, exp_relop): Set type.filename.
	(fold_binary, fold_name, exp_fold_tree_1, exp_get_vma, exp_get_fill,
	exp_get_abs_int): Add tree arg for %S in error messages.  Don't
	fudge lineno.
	(exp_binop, exp_unop, exp_nameop, exp_assop, exp_assert): Copy
	type.filename from sub-tree.
	(exp_trinop): Likewise, and use "cond" rather than "lhs".
	* ldexp.h (node_type): Add filename field to struct.
	* ldfile.c (ldfile_input_filename): Delete.  Remove all refs.
	* ldfile.h (ldfile_input_filename): Delete.
	* ldgram.y (phdr_type, phdr_qualifiers, yyerror): Add NULL arg for
	%S in error messages.
	* ldemul.c (syslib_default, hll_default): Likewise.
	* ldlang.c (lang_memory_region_lookup, lang_memory_region_alias,
	lang_get_regions, lang_new_phdr): Likewise.
	(lang_size_sections_1): Pass addr_tree for %S.
	* ldlex.h (lex_redirect): Update prototype.
	(ldlex_filename): Declare.
	* ldlex.l (<EOF>): Don't set ldfile_input_filename.
	(lex_redirect): Add fake_filename and count params.  Push
	fake_filename to file_name_stack and init lineno from count.
	(ldlex_filename): New function.
	(lex_warn_invalid): Use above.
	* ldmain.c (main): Update lex_redirect call.
	* ldmisc.c (vfinfo <%S>): Take file name and line number from
	etree_type arg, or use current if arg is NULL.
	* lexsup.c (parsing_defsym): Delete.
	(parse_args <OPTION_DEFSYM>): Update lex_redirect call.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2407&r2=1.2408
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ld.h.diff?cvsroot=src&r1=1.52&r2=1.53
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldemul.c.diff?cvsroot=src&r1=1.37&r2=1.38
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldexp.c.diff?cvsroot=src&r1=1.95&r2=1.96
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldexp.h.diff?cvsroot=src&r1=1.29&r2=1.30
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldfile.c.diff?cvsroot=src&r1=1.63&r2=1.64
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldfile.h.diff?cvsroot=src&r1=1.18&r2=1.19
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldgram.y.diff?cvsroot=src&r1=1.67&r2=1.68
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldlang.c.diff?cvsroot=src&r1=1.382&r2=1.383
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldlex.h.diff?cvsroot=src&r1=1.8&r2=1.9
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldlex.l.diff?cvsroot=src&r1=1.53&r2=1.54
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldmain.c.diff?cvsroot=src&r1=1.161&r2=1.162
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldmisc.c.diff?cvsroot=src&r1=1.40&r2=1.41
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/lexsup.c.diff?cvsroot=src&r1=1.128&r2=1.129
Comment 2 Alan Modra 2012-02-18 12:32:51 UTC
patch applied