Forwarded conversation Subject: [developer] SUNWspro compiler bug ------------------------
From: Matthew Ahrens <mahr...@delphix.com> Date: 11 September 2012 06:35 To: develo...@lists.illumos.org Is there a good place to report a SUNWspro compiler bug? I've found that functions that use alloca() (or c99 variable-length arrays) and are compiled with "-m64 -xO1 -Wu,-save_args" (as the kernel is) restore callee-saved registers incorrectly. Note that extant code works correctly because the kernel doesn't call alloca(), and 64-bit userland is not compiled with save_args. The incorrect assembly looks like: func: pushq %rbp func+1: movq %rsp,%rbp # save arguments: func+4: subq $0x18,%rsp func+8: movq %rdi,-0x8(%rbp) func+0xc: movq %rsi,-0x10(%rbp) func+0x10: movq %rdx,-0x18(%rbp) # callee-saved registers which this function needs: func+0x14: pushq %r12 func+0x16: pushq %r13 func+0x18: pushq %r14 func+0x1a: pushq %r15 # alloca(1): func+0x1c: subq $0x8,%rsp func+0x20: decq %rsp func+0x23: andq $0xfffffffffffffff0,%rsp ... some computation that uses %r12, %r13, %r14, %r15 # incorrectly change %rsp to what it was before the alloca() # should be -0x38 to include saved arguments func+0x187: leaq -0x20(%rbp),%rsp # restore callee-saved registers: func+0x18b: popq %r15 func+0x18d: popq %r14 func+0x18f: popq %r13 func+0x191: popq %r12 func+0x193: leave func+0x194: ret For an example, see the attached test program. --matt illumos-developer | Archives | Modify Your Subscription ---------- From: Richard Lowe <richl...@richlowe.net> Date: 11 September 2012 06:40 To: Matthew Ahrens <mahr...@delphix.com>, illumos-dev <develo...@lists.illumos.org> On Tue, Sep 11, 2012 at 12:35 AM, Matthew Ahrens <mahr...@delphix.com> wrote: > > Is there a good place to report a SUNWspro compiler bug? > > I've found that functions that use alloca() (or c99 variable-length arrays) > and are compiled with "-m64 -xO1 -Wu,-save_args" (as the kernel is) restore > callee-saved registers incorrectly. I hit this same issue when concocting the libproc changes I just sent out for review. I think you can file Studio bugs at bugs.sun.com still, but it won't be any good for illumos, since it'll only be fixed in a version of the compiler we can't really use. -- Rich illumos-developer | Archives | Modify Your Subscription Ced -- Cedric Blancher <cedric.blanc...@googlemail.com> Institute Pasteur
/* * fails when compile with: * /opt/SUNWspro/bin/cc -m64 -xO1 -Wu,-save_args bad.c * succeeds when compiled with: * /usr/sfw/bin/gcc -m64 -O2 -msave-args bad.c */ #include <sys/types.h> #include <stdlib.h> #include <alloca.h> #include <stdio.h> int func(void *a, void *b, void *c) { /* fails with either of these */ #if 0 static const int buflen = 1; char buf[buflen]; #else alloca(1); #endif /* * This computation will require several registers, thus forcing * some registers to be saved when the function is entered. */ uint64_t x = (uint64_t)a + 1; uint64_t y = (uint64_t)b + 1; uint64_t z = (uint64_t)c + 1; uint64_t tmp = ((((x*y + y*z) * (x*x + y*y)) / (1+(z*z + x*z) * (z*x + y*x))) % (1+((x*x + y*y) * (z*z + x*y)) / (1+(z*y + x*x) * (z*z + y*z)))) + (1+(((x*x + y*y) * (y*x + z*y)) / (1+(z*x + x*x) * (z*z + y*z))) % (1+((x*y + x*y) * (x*z + y*y)) / (1+(y*y + x*y) * (z*x + z*z)))) ; snprintf(NULL, 0, "%llx\n", tmp); printf("%p %p %p\n", a, b, c); return (0); } int main(int argc, char *argv[]) { printf("%p %p %p\n", argv[0], argv[1], argv[2]); func(argv[0], argv[1], argv[2]); printf("%p %p %p\n", argv[0], argv[1], argv[2]); return (0); }
_______________________________________________ opensolaris-discuss mailing list opensolaris-discuss@opensolaris.org