Bug 12519 - size generated from .size _function, .-_function is faulty
Summary: size generated from .size _function, .-_function is faulty
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-25 03:38 UTC by Tien Hock Loh
Modified: 2011-02-25 17:00 UTC (History)
1 user (show)

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


Attachments
the reproduction case source file sample (159 bytes, text/plain)
2011-02-25 03:38 UTC, Tien Hock Loh
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tien Hock Loh 2011-02-25 03:38:27 UTC
Created attachment 5265 [details]
the reproduction case source file sample

See the foo.S attached. 
When the code is compiled and linked (with a dummy main function), objdump -x shows that a faulty _test_nop size is calculated (in the example, 2 instead of 4). Removing the .section fixes the problem. 

This is causing some issues with GDB debugger in our architecture (Nios II). We've tested this in our architecture and with IA32.
Comment 1 Alan Modra 2011-02-25 07:23:11 UTC
gas should give an error with the testcase, since the expression given cannot be calculated at assembly time.
Comment 2 cvs-commit@gcc.gnu.org 2011-02-25 07:48:55 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2011-02-25 07:48:51

Modified files:
	include/elf    : ChangeLog internal.h 

Log message:
	PR 12519
	* internal.h (ELF_SECTION_IN_SEGMENT_1): Don't match zero size
	sections at start or end of PT_DYNAMIC.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/elf/ChangeLog.diff?cvsroot=src&r1=1.410&r2=1.411
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/elf/internal.h.diff?cvsroot=src&r1=1.26&r2=1.27
Comment 3 cvs-commit@gcc.gnu.org 2011-02-25 07:50:41 UTC
CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_21-branch
Changes by:	amodra@sourceware.org	2011-02-25 07:50:37

Modified files:
	include/elf    : ChangeLog internal.h 

Log message:
	PR 12519
	* internal.h (ELF_SECTION_IN_SEGMENT_1): Don't match zero size
	sections at start or end of PT_DYNAMIC.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/elf/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.408&r2=1.408.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/elf/internal.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.26&r2=1.26.2.1
Comment 4 Tien Hock Loh 2011-02-25 07:58:40 UTC
So, the syntax is invalid? 
Thanks for the quick reply
Comment 5 Alan Modra 2011-02-25 12:35:15 UTC
Yes, you cannot size a function over two sections like that.
Comment 6 cvs-commit@gcc.gnu.org 2011-02-25 13:46:01 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2011-02-25 13:45:55

Modified files:
	gas            : ChangeLog 
	gas/config     : obj-elf.c 
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-mn10300: i135409-3.s 
	ld/testsuite/ld-sh/sh64: stolib.s 

Log message:
	PR gas/12519
	* config/obj-elf.c (elf_frob_symbol): Properly handle size expression.
	* ld-mn10300/i135409-3.s: Correct .size label reference.
	* ld-sh/sh64/stolib.s: Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4410&r2=1.4411
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/obj-elf.c.diff?cvsroot=src&r1=1.136&r2=1.137
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1369&r2=1.1370
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-mn10300/i135409-3.s.diff?cvsroot=src&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-sh/sh64/stolib.s.diff?cvsroot=src&r1=1.1&r2=1.2
Comment 8 Alan Modra 2011-02-25 13:49:21 UTC
Fixed.  Ignore commit messages in comment 2 and 3, which belong to PR12516.
Comment 9 cvs-commit@gcc.gnu.org 2011-02-25 17:00:33 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2011-02-25 17:00:30

Modified files:
	gas/testsuite  : ChangeLog 
	gas/testsuite/gas/elf: elf.exp 
Added files:
	gas/testsuite/gas/elf: bad-size.d bad-size.err bad-size.s 

Log message:
	Add a testcase for PR gas/12519.
	
	2011-02-25  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR gas/12519
	* gas/elf/bad-size.d: New.
	* gas/elf/bad-size.err: Likewise.
	* gas/elf/bad-size.s: Likewise.
	
	* gas/elf/elf.exp: Run bad-size.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1853&r2=1.1854
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/elf/bad-size.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/elf/bad-size.err.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/elf/bad-size.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/elf/elf.exp.diff?cvsroot=src&r1=1.74&r2=1.75