* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
@ 2010-11-20 3:53 ` orangewarrior at gmail dot com
2010-11-29 15:00 ` rguenth at gcc dot gnu.org
` (13 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: orangewarrior at gmail dot com @ 2010-11-20 3:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
Lukasz Ligowski <orangewarrior at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |orangewarrior at gmail dot
| |com
--- Comment #5 from Lukasz Ligowski <orangewarrior at gmail dot com> 2010-11-20 01:56:34 UTC ---
works for me with ATmega2560 (arduino mega) on Gentoo gcc-4.5.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
2010-11-20 3:53 ` [Bug target/45263] registers used in __do_global_ctors can get clobbered orangewarrior at gmail dot com
@ 2010-11-29 15:00 ` rguenth at gcc dot gnu.org
2010-11-30 15:22 ` mschulze at ivs dot cs.ovgu.de
` (12 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-11-29 15:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mschulze at ivs dot
| |cs.ovgu.de
--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2010-11-29 14:57:33 UTC ---
*** Bug 46706 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
2010-11-20 3:53 ` [Bug target/45263] registers used in __do_global_ctors can get clobbered orangewarrior at gmail dot com
2010-11-29 15:00 ` rguenth at gcc dot gnu.org
@ 2010-11-30 15:22 ` mschulze at ivs dot cs.ovgu.de
2010-11-30 15:41 ` mschulze at ivs dot cs.ovgu.de
` (11 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: mschulze at ivs dot cs.ovgu.de @ 2010-11-30 15:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
--- Comment #7 from Michael Schulze <mschulze at ivs dot cs.ovgu.de> 2010-11-30 15:16:20 UTC ---
Created attachment 22579
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22579
alternative patch using register r15 instead of r20 avoids pushing/poping
In reaction to bug 29141, which is still pending and not fixed, I offer a patch
that corrects the handling of global constructors. The fix proposed in bug
29141 leads to wrong handling of global constructors since gcc version 4.4.0.
And this is independent of the 64kB boundary because the handling is always
wrong.
With the first provided patch the register r20 was always pushed and popped but
this is not necessary. The global-constructors patch avoids this and uses r15
instead of r20. Due to the compiler abi the register r15 is left unchanged by
called routines, and it has to be saved/restored by routines that use it.
I applied the global-constructor patch and then the compiler generates correct
code for the execution of global constructors regardless of whether the
constructor is located below or above 64kB. I tested the patch by my own but I
think it needs further tests. Please try it out. I think without such a patch
independent of using my one or the r20 patch, this bug is a show stopper since
gcc version 4.4.0.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2010-11-30 15:22 ` mschulze at ivs dot cs.ovgu.de
@ 2010-11-30 15:41 ` mschulze at ivs dot cs.ovgu.de
2010-12-04 3:11 ` westfw at yahoo dot com
` (10 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: mschulze at ivs dot cs.ovgu.de @ 2010-11-30 15:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
--- Comment #8 from Michael Schulze <mschulze at ivs dot cs.ovgu.de> 2010-11-30 15:21:57 UTC ---
Comment on attachment 22579
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22579
alternative patch using register r15 instead of r20 avoids pushing/poping
>diff -Naur gcc-4.5.1-orig/gcc/config/avr/libgcc.S gcc-4.5.1/gcc/config/avr/libgcc.S
>--- gcc-4.5.1-orig/gcc/config/avr/libgcc.S 2009-05-23 09:16:07.000000000 +0200
>+++ gcc-4.5.1/gcc/config/avr/libgcc.S 2010-11-30 14:35:53.000000000 +0100
>@@ -792,21 +792,22 @@
> __do_global_ctors:
> ldi r17, hi8(__ctors_start)
> ldi r16, hh8(__ctors_start)
>- ldi r28, lo8(__ctors_end)
>+ ldi r28, hh8(__ctors_end)
>+ mov r15, r28
>+ ldi r28, lo8(__ctors_end)
> ldi r29, hi8(__ctors_end)
>- ldi r20, hh8(__ctors_end)
> rjmp .L__do_global_ctors_start
> .L__do_global_ctors_loop:
> sbiw r28, 2
>- sbc r20, __zero_reg__
>+ sbc r15, __zero_reg__
> mov_h r31, r29
> mov_l r30, r28
>- out __RAMPZ__, r20
>+ out __RAMPZ__, r15
> XCALL __tablejump_elpm__
> .L__do_global_ctors_start:
> cpi r28, lo8(__ctors_start)
> cpc r29, r17
>- cpc r20, r16
>+ cpc r15, r16
> brne .L__do_global_ctors_loop
> #else
> __do_global_ctors:
>@@ -833,21 +834,22 @@
> __do_global_dtors:
> ldi r17, hi8(__dtors_end)
> ldi r16, hh8(__dtors_end)
>+ ldi r28, hh8(__dtors_start)
>+ mov r15, r28
> ldi r28, lo8(__dtors_start)
> ldi r29, hi8(__dtors_start)
>- ldi r20, hh8(__dtors_start)
> rjmp .L__do_global_dtors_start
> .L__do_global_dtors_loop:
> sbiw r28, 2
>- sbc r20, __zero_reg__
>+ sbc r15, __zero_reg__
> mov_h r31, r29
> mov_l r30, r28
>- out __RAMPZ__, r20
>+ out __RAMPZ__, r15
> XCALL __tablejump_elpm__
> .L__do_global_dtors_start:
> cpi r28, lo8(__dtors_end)
> cpc r29, r17
>- cpc r20, r16
>+ cpc r15, r16
> brne .L__do_global_dtors_loop
> #else
> __do_global_dtors:
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2010-11-30 15:41 ` mschulze at ivs dot cs.ovgu.de
@ 2010-12-04 3:11 ` westfw at yahoo dot com
2010-12-05 19:53 ` eric.weddington at atmel dot com
` (9 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: westfw at yahoo dot com @ 2010-12-04 3:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
--- Comment #9 from Bill Westfield <westfw at yahoo dot com> 2010-12-04 03:11:23 UTC ---
This is essentially identical to the patch I provided for
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44617
so it looks good to me.
I had two worries:
Is R15 used anywhere else in startup code that might not obey the register save
conventions (ie does do_global_ctors need to preserve R15)
The AVR has a lot of opcodes that are not valid on registers less than 16. It
doesn't look like any of these are used here, but I wasn't 100% positive that
using R15 wouldn't cause problems...
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2010-12-04 3:11 ` westfw at yahoo dot com
@ 2010-12-05 19:53 ` eric.weddington at atmel dot com
2010-12-06 9:08 ` mschulze at ivs dot cs.ovgu.de
` (8 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: eric.weddington at atmel dot com @ 2010-12-05 19:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
--- Comment #10 from Eric Weddington <eric.weddington at atmel dot com> 2010-12-05 19:52:33 UTC ---
(In reply to comment #9)
> Is R15 used anywhere else in startup code that might not obey the register save
> conventions (ie does do_global_ctors need to preserve R15)
I strongly suggest not using R15. The ATtiny10 Family of devices
(ATtiny10/4/5/9/20/40) only has R16-R31. So using R15 won't work for this class
of devices. It would be best if we can find a register that will for all AVR
devices.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2010-12-05 19:53 ` eric.weddington at atmel dot com
@ 2010-12-06 9:08 ` mschulze at ivs dot cs.ovgu.de
2011-04-13 16:38 ` gjl at gcc dot gnu.org
` (7 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: mschulze at ivs dot cs.ovgu.de @ 2010-12-06 9:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
--- Comment #11 from Michael Schulze <mschulze at ivs dot cs.ovgu.de> 2010-12-06 09:07:19 UTC ---
(In reply to comment #9)
> This is essentially identical to the patch I provided for
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44617
> so it looks good to me.
I hadn't see that patch but you are right it's almost identical.
> I had two worries:
> Is R15 used anywhere else in startup code that might not obey the register
> save conventions (ie does do_global_ctors need to preserve R15)
> The AVR has a lot of opcodes that are not valid on registers less than 16. It
> doesn't look like any of these are used here, but I wasn't 100% positive that
> using R15 wouldn't cause problems...
As far as I know r15 isn't used elsewhere in the start-up code and also your
second worry seems not to be a problem, because such instructions are not used
by that time.
(In reply to comment #10)
> I strongly suggest not using R15. The ATtiny10 Family of devices
> (ATtiny10/4/5/9/20/40) only has R16-R31. So using R15 won't work for this
> class of devices.
I disagree because the additional register is only in the start up code of
devices that have rampz and is omitted in all other cases. The ATtiny don't
have a rampz (correct me if I'm wrong) thus they are not faced with the
discussed problem in general. IMO, it is absolutely possible and correct to use
r15 here.
> It would be best if we can find a register that will for all AVR
> devices.
Due to the compiler's C calling conventions, there are no other free registers
to use without the need of pushing and popping this registers. Only registers
below r16 are free to use. All other free r16,r17,r28,r29 are already in use.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (6 preceding siblings ...)
2010-12-06 9:08 ` mschulze at ivs dot cs.ovgu.de
@ 2011-04-13 16:38 ` gjl at gcc dot gnu.org
2011-04-13 16:46 ` gjl at gcc dot gnu.org
` (6 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-04-13 16:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
--- Comment #12 from gjl at gcc dot gnu.org 2011-04-13 16:36:57 UTC ---
Author: gjl
Date: Wed Apr 13 16:36:50 2011
New Revision: 172384
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172384
Log:
PR target/45263
* config/avr/libgcc.S (__do_global_ctors, __do_global_dtors): Save
R20 around calls of __tablejump_elpm__
Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/avr/libgcc.S
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (7 preceding siblings ...)
2011-04-13 16:38 ` gjl at gcc dot gnu.org
@ 2011-04-13 16:46 ` gjl at gcc dot gnu.org
2011-04-14 15:40 ` gjl at gcc dot gnu.org
` (5 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-04-13 16:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
--- Comment #13 from gjl at gcc dot gnu.org 2011-04-13 16:46:32 UTC ---
Author: gjl
Date: Wed Apr 13 16:46:29 2011
New Revision: 172385
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172385
Log:
Fix ChangeLog entry for PR target/45263
Modified:
trunk/gcc/ChangeLog
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (8 preceding siblings ...)
2011-04-13 16:46 ` gjl at gcc dot gnu.org
@ 2011-04-14 15:40 ` gjl at gcc dot gnu.org
2011-05-30 8:56 ` gjl at gcc dot gnu.org
` (4 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-04-14 15:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
Georg-Johann Lay <gjl at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |gjl at gcc dot gnu.org
Known to work| |4.7.0
Resolution| |FIXED
--- Comment #14 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-04-14 15:40:11 UTC ---
Closed as resolved+fixed in 4.7.0
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (9 preceding siblings ...)
2011-04-14 15:40 ` gjl at gcc dot gnu.org
@ 2011-05-30 8:56 ` gjl at gcc dot gnu.org
2011-05-30 15:23 ` gjl at gcc dot gnu.org
` (3 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-05-30 8:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
--- Comment #15 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-05-30 08:53:15 UTC ---
Author: gjl
Date: Mon May 30 08:53:12 2011
New Revision: 174427
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174427
Log:
PR target/45263
* config/avr/libgcc.S (__do_global_ctors, __do_global_dtors):
Don't use r20 around calls of __tablejump_elpm__
Modified:
branches/gcc-4_6-branch/gcc/ChangeLog
branches/gcc-4_6-branch/gcc/config/avr/libgcc.S
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (10 preceding siblings ...)
2011-05-30 8:56 ` gjl at gcc dot gnu.org
@ 2011-05-30 15:23 ` gjl at gcc dot gnu.org
2012-05-02 17:25 ` gjl at gcc dot gnu.org
` (2 subsequent siblings)
14 siblings, 0 replies; 22+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-05-30 15:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
Georg-Johann Lay <gjl at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Version|4.6.1 |4.5.1
Target Milestone|--- |4.6.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (11 preceding siblings ...)
2011-05-30 15:23 ` gjl at gcc dot gnu.org
@ 2012-05-02 17:25 ` gjl at gcc dot gnu.org
2012-05-02 17:28 ` gjl at gcc dot gnu.org
2014-03-31 20:09 ` gjl at gcc dot gnu.org
14 siblings, 0 replies; 22+ messages in thread
From: gjl at gcc dot gnu.org @ 2012-05-02 17:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
--- Comment #16 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2012-05-02 17:23:14 UTC ---
Author: gjl
Date: Wed May 2 17:23:06 2012
New Revision: 187058
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187058
Log:
Backport from 2011-05-30 4.6-branch r174427.
PR target/45263
* config/avr/libgcc.S (__do_global_ctors, __do_global_dtors):
Don't use r20 around calls of __tablejump_elpm__
Modified:
branches/gcc-4_5-branch/gcc/ChangeLog
branches/gcc-4_5-branch/gcc/config/avr/libgcc.S
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (12 preceding siblings ...)
2012-05-02 17:25 ` gjl at gcc dot gnu.org
@ 2012-05-02 17:28 ` gjl at gcc dot gnu.org
2014-03-31 20:09 ` gjl at gcc dot gnu.org
14 siblings, 0 replies; 22+ messages in thread
From: gjl at gcc dot gnu.org @ 2012-05-02 17:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
Georg-Johann Lay <gjl at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Known to work|4.7.0 |4.5.4
Known to fail| |4.5.3
--- Comment #17 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2012-05-02 17:24:38 UTC ---
Backport to 4.5.4
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug target/45263] registers used in __do_global_ctors can get clobbered
[not found] <bug-45263-4@http.gcc.gnu.org/bugzilla/>
` (13 preceding siblings ...)
2012-05-02 17:28 ` gjl at gcc dot gnu.org
@ 2014-03-31 20:09 ` gjl at gcc dot gnu.org
14 siblings, 0 replies; 22+ messages in thread
From: gjl at gcc dot gnu.org @ 2014-03-31 20:09 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263
Georg-Johann Lay <gjl at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bobf at mrp3 dot com
--- Comment #18 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
*** Bug 60247 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 22+ messages in thread