public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/41055]  New: libgcc functions and -mregparm don't work well together
@ 2009-08-13 14:46 patrick dot georgi at coresystems dot de
  2009-08-13 14:58 ` [Bug c/41055] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: patrick dot georgi at coresystems dot de @ 2009-08-13 14:46 UTC (permalink / raw)
  To: gcc-bugs

When building code with -mregparm=x on i?86 which uses libgcc functions (eg.
udivdi3), the calls to the libgcc functions use the calling convention as given
by mregparm, even though libgcc is internal to the compiler (and the user has
no ultimate control about when it is used).

Adding the compiler-native calling convention as regparm attribute to all calls
that are synthesized by the compiler might fix the problem.

The following shell script exhibits the problem.

cat > test.c << EOF
int main() {
 long long a= 4000000000;
 return a / 43937;
}
EOF

gcc -S test.c
mv test.s test.default.s

gcc -mregparm=3 -S test.c
mv test.s test.mregparm3.s

diff -u test.default.s test.mregparm3.s
exit 0
# there should be no difference in the calling convention
# as __divdi3 is taken from libgcc, but I get the result:
--- test.default.s      Do. Aug 13 15:47:28 2009
+++ test.mregparm3.s    Do. Aug 13 15:47:28 2009
 -18,10 +18,9 @@
        movl    $0, -4(%ebp)
        movl    -8(%ebp), %eax
        movl    -4(%ebp), %edx
+       subl    $8, %esp
        pushl   $0
        pushl   $43937
-       pushl   %edx
-       pushl   %eax
        call    __divdi3
        addl    $16, %esp
        leave


-- 
           Summary: libgcc functions and -mregparm don't work well together
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: patrick dot georgi at coresystems dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41055


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/41055] libgcc functions and -mregparm don't work well together
  2009-08-13 14:46 [Bug c/41055] New: libgcc functions and -mregparm don't work well together patrick dot georgi at coresystems dot de
@ 2009-08-13 14:58 ` rguenth at gcc dot gnu dot org
  2009-08-13 15:09 ` stepan at coresystems dot de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-13 14:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-08-13 14:58 -------
-mregparm changes the ABI, you have to rebuild libgcc with -mregparm to be
able to use it.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41055


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/41055] libgcc functions and -mregparm don't work well together
  2009-08-13 14:46 [Bug c/41055] New: libgcc functions and -mregparm don't work well together patrick dot georgi at coresystems dot de
  2009-08-13 14:58 ` [Bug c/41055] " rguenth at gcc dot gnu dot org
@ 2009-08-13 15:09 ` stepan at coresystems dot de
  2009-08-13 15:11 ` patrick dot georgi at coresystems dot de
  2009-08-13 15:37 ` matz at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: stepan at coresystems dot de @ 2009-08-13 15:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from stepan at coresystems dot de  2009-08-13 15:08 -------
So we have to rebuild parts of the compiler in order to get a working compiler,
depending on the compiler flags we use? That sounds pretty broken to me. In my
opinion, since -mregparm is a gcc run time option, not a compile time option,
the compiler should provide libgcc for every possible ABI and choose among
those.

Closing this bug is especially weird since #12081 implies that building the
compiler with -mregparm=3 is broken.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41055


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/41055] libgcc functions and -mregparm don't work well together
  2009-08-13 14:46 [Bug c/41055] New: libgcc functions and -mregparm don't work well together patrick dot georgi at coresystems dot de
  2009-08-13 14:58 ` [Bug c/41055] " rguenth at gcc dot gnu dot org
  2009-08-13 15:09 ` stepan at coresystems dot de
@ 2009-08-13 15:11 ` patrick dot georgi at coresystems dot de
  2009-08-13 15:37 ` matz at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: patrick dot georgi at coresystems dot de @ 2009-08-13 15:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from patrick dot georgi at coresystems dot de  2009-08-13 15:10 -------
(In reply to comment #1)
> -mregparm changes the ABI, you have to rebuild libgcc with -mregparm to be
> able to use it.
> 

I agree with that notion for general purpose libraries as used by the user. But
libgcc is an implementation artefact of GCC. I'd prefer not to use it, but GCC
forces me to.

If I use __divdi3 myself, GCC can expect that I fix up the call myself (using
some __attribute__((regparm))), but if GCC uses it, I think it's not to much to
ask for it to fix it up itself (as I don't have the means to do so, short of
rewriting assembler code)

I see three good solutions:
1. GCC calls its own libgcc calls in a proper way (and it should be able to do
so, if I as a user can change calling conventions per function call)
2. It refuses to use libgcc with mregparm, as it will break.
3. GCC supports multiple libgccs, choosing the right one automatically.

My guess is that solution 1 is the easiest. Hacks like
http://trac.nchc.org.tw/grid/browser/gpfs_3.1_ker2.6.20/lpp/mmfs/src/gpl-linux/mmwrap.c
shouldn't be necessary.


-- 

patrick dot georgi at coresystems dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41055


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/41055] libgcc functions and -mregparm don't work well together
  2009-08-13 14:46 [Bug c/41055] New: libgcc functions and -mregparm don't work well together patrick dot georgi at coresystems dot de
                   ` (2 preceding siblings ...)
  2009-08-13 15:11 ` patrick dot georgi at coresystems dot de
@ 2009-08-13 15:37 ` matz at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: matz at gcc dot gnu dot org @ 2009-08-13 15:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from matz at gcc dot gnu dot org  2009-08-13 15:36 -------
I agree with the reporters.  libgcc isn't some random library, GCC should call
it correctly even in the presence of -mregparm.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41055


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-08-13 15:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-13 14:46 [Bug c/41055] New: libgcc functions and -mregparm don't work well together patrick dot georgi at coresystems dot de
2009-08-13 14:58 ` [Bug c/41055] " rguenth at gcc dot gnu dot org
2009-08-13 15:09 ` stepan at coresystems dot de
2009-08-13 15:11 ` patrick dot georgi at coresystems dot de
2009-08-13 15:37 ` matz at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).