Bug 9571 - [PPC] problems with 'const', -msdata=eabi and sections.
Summary: [PPC] problems with 'const', -msdata=eabi and sections.
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 13646 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-02-04 14:06 UTC by Sergei Organov
Modified: 2005-07-23 22:39 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-rtems
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-01-11 16:49:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Organov 2003-02-04 14:06:01 UTC
Given the code:

$ cat const.cc
extern double const d;
double const d = 3.14;
double f() { return d; }
$ ~/try/tools/bin/ppc-rtems-gcc -meabi -msdata=eabi -c -O4 -save-temps -mregnames const.cc -o const.o
const.s: Assembler messages:
const.s:3: Warning: setting incorrect section attributes for .sdata2
$ cat const.s
	.file	"const.cc"
	.globl d
	.section	.sdata2,"aw",@progbits
	.align 3
	.type	d, @object
	.size	d, 8
d:
	.long	1074339512
	.long	1374389535
	.section	.rodata.cst8,"aM",@progbits,8
	.align 3
.LC0:
	.long	1074339512
	.long	1374389535
	.section	".text"
	.align 2
	.globl _Z1fv
	.type	_Z1fv, @function
_Z1fv:
.LFB3:
	lis %r3,.LC0@ha
	lfd %f1,.LC0@l(%r3)
	blr
.LFE3:
	.size	_Z1fv, .-_Z1fv
	.ident	"GCC: (GNU) 3.3 20030203 (prerelease)"


Problems: 

1. Attempt to set "w" attribute for read-only section '.sdata2'.
2. A copy of value of 'd' is put into section '.rodata.cst8'.
   The latter should better go away entirely or at least be 
   '.sdata2.cst8', I think.
3. As a consequence of (2) function f() needs 2 insns instead 
   of 1 to load the constant into register.

For comparison consider perfect code generated in this case:

$ cat var.cc
extern double d;
double d = 3.14;
double f() { return d; }
$ ~/try/tools/bin/ppc-rtems-gcc -meabi -msdata=eabi -c -O4 -save-temps -mregnames var.cc -o var.o
$ cat var.s
	.file	"var.cc"
	.globl d
	.section	.sdata,"aw",@progbits
	.align 3
	.type	d, @object
	.size	d, 8
d:
	.long	1074339512
	.long	1374389535
	.section	".text"
	.align 2
	.globl _Z1fv
	.type	_Z1fv, @function
_Z1fv:
.LFB3:
	lfd %f1,d@sda21(%r0)
	blr
.LFE3:
	.size	_Z1fv, .-_Z1fv
	.ident	"GCC: (GNU) 3.3 20030203 (prerelease)"

Release:
gcc version 3.3 20030203 (prerelease)

Environment:
Linux 2.4.20 i686

How-To-Repeat:
Refer to description.
Comment 1 Dara Hazeghi 2003-05-22 01:24:35 UTC
Hello,

I can confirm that this problem is still present on gcc 3.3 branch and mainline (20030521) on an 
i686-linux to powerpc-rtems cross compiler. gcc 3.2.3 did not have this problem, so this is a 
regression. Removing the -msdata=eabi fixes the problem.

Dara
Comment 2 Andrew Pinski 2003-05-26 00:22:30 UTC
see Dara's comment.
Comment 3 Franz Sirl 2003-06-17 13:52:40 UTC
This isn't a regression IMHO, independent of this bug -msdata=eabi is non-functional in gcc 
since at least gcc-2.95. So even if _this_ bug is fixed for 3.3.1 as a regression, -msdata=eabi 
will still be non-functional! 
If, however, we really want to fix all of the PPC sdata bugs for 3.3.x, I request backporting the 
gcc.dg/ppc-sdata-[12].c testcases to the 3.3 branch as a first step. 
 
Comment 4 Sergei Organov 2003-06-17 15:18:46 UTC
Subject: Re:  [3.3/3.4 regression] [PPC] problems with 'const', -msdata=eabi and sections.

"sirl@gcc.gnu.org" <gcc-bugzilla@gcc.gnu.org> writes:
> This isn't a regression IMHO, independent of this bug -msdata=eabi is
> non-functional in gcc since at least gcc-2.95.

This is surprise for me. I use gcc-2.95 with -msdata=eabi all the time for a
few years now and I didn't notice any problems with it yet. On the other hand,
I've immediately noticed the problem in 3.3 at the first try.

Comment 5 Franz Sirl 2003-06-17 15:31:15 UTC
r0 is used as a pointer to sdata2, this is a bug, it should be r2. And since only r2 is initialized in 
the ecrt*.o files, how can this work? Besides that, even if you initialize r0 manually, it is 
practically clobbered in about every function. 
 
Comment 6 Mark Mitchell 2003-07-20 00:52:12 UTC
Based on Franz's comments, this bug is not really a regression at all.

I've therefore removed the regression tags.
Comment 7 Sergei Organov 2003-10-14 14:42:44 UTC
> r0 is used as a pointer to sdata2, this is a bug, it should be r2.

No, the %r0 you see is fake. In the object file it's a special relocatable
symbol that is resolved to either 2 (r2) or 13 (r13) by the linker depending on
actual output section the symbol refers to, so there is no bug here.

As there is no bug at this point, the:

> Based on Franz's comments, this bug is not really a regression at all.
> I've therefore removed the regression tags.

is wrong as Franz's comments are wrong.
Comment 8 Andrew Pinski 2004-01-11 15:59:30 UTC
*** Bug 13646 has been marked as a duplicate of this bug. ***
Comment 9 Steve Meisner 2004-02-26 16:25:11 UTC
I have fixed this bug (and another) against the 3.3.3 release.  I am not a GCC
developer, just a hack that loves GCC.  The fix works for my needs, but most
likely is not how it should be implemented.  I could send a diff or a patch if
the developers are interested in seeing what I did.
Comment 10 CVS Commits 2004-11-29 06:24:45 UTC
Subject: Bug 9571

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	amodra@gcc.gnu.org	2004-11-29 06:24:31

Modified files:
	gcc            : ChangeLog varasm.c 

Log message:
	PR target/9571
	* varasm.c (default_elf_select_section_1): Pass decl to named_section.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6616&r2=2.6617
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&r1=1.461&r2=1.462

Comment 11 Andreas Schwab 2004-11-29 10:36:21 UTC
Breaks libgfortran on ia64. 
 
../../../libgfortran/generated/product_c4.c: In function '__product_c4': 
../../../libgfortran/generated/product_c4.c:143: internal compiler error: in 
named_section, at varasm.c:451 
Please submit a full bug report, 
with preprocessed source if appropriate. 
See <URL:http://gcc.gnu.org/bugs.html> for instructions. 
 
The decl is actually a COMPLEX_CST, i.e. not a DECL_P. 
 
Comment 12 Andrew Pinski 2004-11-29 13:35:54 UTC
Fixed.
Comment 13 Alan Modra 2004-11-30 06:44:28 UTC
My patch didn't completely fix this problem, only the wrong .sdata2 attributes.
Incidentally, the followup patch to fix the libgfortran breakage is:

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	amodra@gcc.gnu.org	2004-11-29 11:29:13

Modified files:
	gcc            : ChangeLog varasm.c 

Log message:
	* varasm.c (default_elf_select_section_1): Only pass DECL_P decl
	to named_section.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6618&r2=2.6619
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&r1=1.462&r2=1.463