* Weird Compaq CCC / GCC interaction ?
@ 2000-09-26 8:55 David Addison
2000-09-26 9:41 ` Andrei A. Dergatchev
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: David Addison @ 2000-09-26 8:55 UTC (permalink / raw)
To: 'axp-list@redhat.com'
[-- Attachment #1: Type: text/plain, Size: 2171 bytes --]
Help! Am I going mad or is there something obviously wrong with my C
programming skills?
Here are two very simple files to compile. What I have found is that if I
compile the fn.c code using gcc and ccc for the main code, it gets the wrong
answer. Whereas it works if I use either ccc or gcc for both. It also works
if I compile the fn.c code with ccc and main with gcc.
Anyone know what's wrong ... is this a bug with ccc or gcc ?
cat fn.c
unsigned int fn()
{
return (0xc00fc00f);
}
cat madness.c
extern unsigned int fn();
#define MAGIC 0xc00fc00f
int main()
{
unsigned int baseAddr;
baseAddr = fn();
if (baseAddr == MAGIC)
printf("GOOD baseAddr %x == %x\n", baseAddr, MAGIC);
else
printf("BADNESS baseAddr %x != %x\n", baseAddr, MAGIC);
}
Then compile as follows;
cc -O3 -c fn.c -o fn_gcc.o
ccc -O3 -c fn.c -o fn_ccc.o
ccc -O3 madness.c -o madness_gcc fn_gcc.o
ccc -O3 madness.c -o madness_ccc fn_ccc.o
Then run;
./madness_ccc
GOOD baseAddr c00fc00f == c00fc00f
./madness_gcc
BADNESS baseAddr c00fc00f != c00fc00f
It starts working if I change the MAGIC constant to 0x400fc00f so that
suggests sign problems ?
Disassembling the fn code we see the only differences ...
objdump -d fn_gcc.o
fn_gcc.o: file format elf64-alpha
Disassembly of section .text:
0000000000000000 <fn>:
0: 0f c0 1f 20 lda v0,-16369(zero)
4: 10 c0 00 24 ldah v0,-16368(v0)
8: 20 f6 01 48 zapnot v0,0xf,v0
c: 01 80 fa 6b ret zero,(ra),0x1
...
objdump -d fn_ccc.o
fn_ccc.o: file format elf64-alpha
Disassembly of section .text:
0000000000000000 <fn>:
0: 10 c0 1f 24 ldah v0,-16368(zero)
4: 1f 04 ff 47 nop
8: 0f c0 00 20 lda v0,-16369(v0)
c: 01 80 fa 6b ret zero,(ra),0x1
GCC is inserting a ZAPNOT instruction to zero the top 4-bytes - is this
correct ?
Or is the main code compilation that is broken, I notice that ccc uses 'xor'
to do the compare whereas gcc uses 'cmpeq' ?
For the record, I am using Alpha RH6.1 with ccc (ccc-6.2.9.504-2) and gcc
(egcs-2.91.66)
Cheers,
Addy.
[-- Attachment #2: Type: text/html, Size: 8059 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: Weird Compaq CCC / GCC interaction ?
2000-09-26 8:55 Weird Compaq CCC / GCC interaction ? David Addison
@ 2000-09-26 9:41 ` Andrei A. Dergatchev
2000-09-26 10:12 ` Nikita Schmidt
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: Andrei A. Dergatchev @ 2000-09-26 9:41 UTC (permalink / raw)
To: axp-list
[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]
Hi,
Well, while US members of our list are not available yet, here are my
humble
comments.
IMHO this question has little to do with C programming skills :-)
Man, you're opening up a huge can of worms - linking obj files made
with entirely different compilers and moreover passing unsigned ints
from one to another (in C, functions return int by default).
Personally, I wouldn't even expect to get it 100% working at first time.
> fn_gcc.o: file format elf64-alpha Disassembly of section
> .text: 0000000000000000 <fn>:
> 0: 0f c0 1f 20 lda v0,-16369(zero)
> 4: 10 c0 00 24 ldah v0,-16368(v0)
> 8: 20 f6 01 48 zapnot v0,0xf,v0
> c: 01 80 fa 6b ret zero,(ra),0x1
> ...
> objdump -d fn_ccc.o fn_ccc.o: file format elf64-alpha Disassembly
> of section .text: 0000000000000000 <fn>:
> 0: 10 c0 1f 24 ldah v0,-16368(zero)
> 4: 1f 04 ff 47 nop
> 8: 0f c0 00 20 lda v0,-16369(v0)
> c: 01 80 fa 6b ret zero,(ra),0x1
>
> AD> To me it seems that returned results are different in these 2
> cases.
> GCC is inserting a ZAPNOT instruction to zero the top 4-bytes - is
> this correct ?Or is the main code compilation that is broken, I notice
> that ccc uses 'xor' to do the compare whereas gcc uses 'cmpeq' ?
>
Alpha Assembly Language Programmer's Guide says that cmpeq compares
two *64-bit* values. I would look into that.
> Cheers,
> Addy.
Rgds,
Andrei
[-- Attachment #2: Type: text/html, Size: 3329 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: Weird Compaq CCC / GCC interaction ?
2000-09-26 8:55 Weird Compaq CCC / GCC interaction ? David Addison
2000-09-26 9:41 ` Andrei A. Dergatchev
@ 2000-09-26 10:12 ` Nikita Schmidt
2000-09-26 16:02 ` Michal Jaegermann
2000-09-26 12:23 ` Ivan Kokshaysky
2000-09-26 13:57 ` Ivan Kokshaysky
3 siblings, 1 reply; 13+ messages in thread
From: Nikita Schmidt @ 2000-09-26 10:12 UTC (permalink / raw)
To: axp-list
On Tuesday, 26 Sep, David Addison wrote:
>
> Anyone know what's wrong ... is this a bug with ccc or gcc ?
>
This looks like a bug in gcc - see below why.
> cat fn.c
>
> unsigned int fn()
> {
> return (0xc00fc00f);
> }
>
[...]
>
> objdump -d fn_gcc.o
>
> fn_gcc.o: file format elf64-alpha
>
> Disassembly of section .text:
>
> 0000000000000000 <fn>:
> 0: 0f c0 1f 20 lda v0,-16369(zero)
> 4: 10 c0 00 24 ldah v0,-16368(v0)
> 8: 20 f6 01 48 zapnot v0,0xf,v0
> c: 01 80 fa 6b ret zero,(ra),0x1
> ...
>
> objdump -d fn_ccc.o
>
> fn_ccc.o: file format elf64-alpha
>
> Disassembly of section .text:
>
> 0000000000000000 <fn>:
> 0: 10 c0 1f 24 ldah v0,-16368(zero)
> 4: 1f 04 ff 47 nop
> 8: 0f c0 00 20 lda v0,-16369(v0)
> c: 01 80 fa 6b ret zero,(ra),0x1
>
>
> GCC is inserting a ZAPNOT instruction to zero the top 4-bytes - is this
> correct ?
According to the Calling Standard for Alpha Systems, Section 4.1.5 "Unused
Bits in Passed Data," both signed and unsigned ints should be passed
sign-extended in registers. Gcc is compatible with itself, but not with
any other compiler which follows the documented conventions. If gcc
claims to be standards compliant, this is a bug; please submit a report.
Nikita
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: Weird Compaq CCC / GCC interaction ?
2000-09-26 10:12 ` Nikita Schmidt
@ 2000-09-26 16:02 ` Michal Jaegermann
0 siblings, 0 replies; 13+ messages in thread
From: Michal Jaegermann @ 2000-09-26 16:02 UTC (permalink / raw)
To: axp-list
>
> According to the Calling Standard for Alpha Systems, Section 4.1.5 "Unused
> Bits in Passed Data," both signed and unsigned ints should be passed
> sign-extended in registers.
Good to know but why this convention? If I follow implications
correctly (which is a big IF) then if I take results of such function
returning unsigned int, like in the example, and will cast its result to
long then I may get a negative number. OTOH if I do:
#define MAGIC 0xc00fc00fU
...
printf ("%ld\n", (long)MAGIC);
...
then result is positive and I would be quite surprised otherwise.
Or this Standard makes this also into a bug and expects that the
cast above is equivalent to (long)((int)MAGIC)? If yes then again
why?
Michal
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Weird Compaq CCC / GCC interaction ?
2000-09-26 8:55 Weird Compaq CCC / GCC interaction ? David Addison
2000-09-26 9:41 ` Andrei A. Dergatchev
2000-09-26 10:12 ` Nikita Schmidt
@ 2000-09-26 12:23 ` Ivan Kokshaysky
2000-09-26 13:57 ` Ivan Kokshaysky
3 siblings, 0 replies; 13+ messages in thread
From: Ivan Kokshaysky @ 2000-09-26 12:23 UTC (permalink / raw)
To: axp-list
On Tue, Sep 26, 2000 at 09:55:12AM +0100, David Addison wrote:
> 0000000000000000 <fn>:
> 0: 0f c0 1f 20 lda v0,-16369(zero)
> 4: 10 c0 00 24 ldah v0,-16368(v0)
> 8: 20 f6 01 48 zapnot v0,0xf,v0
> c: 01 80 fa 6b ret zero,(ra),0x1
> ...
>
What gcc version?
fn:
.frame $30,0,$26,0
.prologue 0
ldah $0,-16368
lda $0,-16369($0)
ret $31,($26),1
.end fn
.ident "GCC: (GNU) 2.96 20000911 (experimental)"
Ivan.
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: Weird Compaq CCC / GCC interaction ?
2000-09-26 8:55 Weird Compaq CCC / GCC interaction ? David Addison
` (2 preceding siblings ...)
2000-09-26 12:23 ` Ivan Kokshaysky
@ 2000-09-26 13:57 ` Ivan Kokshaysky
3 siblings, 0 replies; 13+ messages in thread
From: Ivan Kokshaysky @ 2000-09-26 13:57 UTC (permalink / raw)
To: axp-list
On Tue, Sep 26, 2000 at 09:55:12AM +0100, David Addison wrote:
...
> For the record, I am using Alpha RH6.1 with ccc (ccc-6.2.9.504-2) and gcc
> (egcs-2.91.66)
>
Oops, overlooked that, sorry.
I've just checked, gcc-2.95.2 has this bug too.
So live with it or upgrade to gcc-2.96...
Ivan.
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: Weird Compaq CCC / GCC interaction ?
@ 2000-09-26 13:59 David Addison
2000-09-26 15:36 ` Ivan Kokshaysky
0 siblings, 1 reply; 13+ messages in thread
From: David Addison @ 2000-09-26 13:59 UTC (permalink / raw)
To: 'axp-list@redhat.com'
The one that is standard with RH6.1 on Alpha - i.e.
egcs-1.1.2-24
gcc -v
Reading specs from /usr/lib/gcc-lib/alpha-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
On RH6.2 they're upto egcs-1.1.2-30 but I doubt that's got the fix in it.
Where can I get RPMs of more recent compilers ?
I just tried RH7.0 (gcc 2.96 based I think) but there is no Alpha release
yet.
Cheers,
Addy
> -----Original Message-----
> From: Ivan Kokshaysky [mailto:ink@jurassic.park.msu.ru]
> Sent: 26 September 2000 13:23
> To: axp-list@redhat.com
> Subject: Re: Weird Compaq CCC / GCC interaction ?
>
>
> On Tue, Sep 26, 2000 at 09:55:12AM +0100, David Addison wrote:
> > 0000000000000000 <fn>:
> > 0: 0f c0 1f 20 lda v0,-16369(zero)
> > 4: 10 c0 00 24 ldah v0,-16368(v0)
> > 8: 20 f6 01 48 zapnot v0,0xf,v0
> > c: 01 80 fa 6b ret zero,(ra),0x1
> > ...
> >
>
> What gcc version?
>
> fn:
> .frame $30,0,$26,0
> .prologue 0
> ldah $0,-16368
> lda $0,-16369($0)
> ret $31,($26),1
> .end fn
> .ident "GCC: (GNU) 2.96 20000911 (experimental)"
>
>
> Ivan.
>
>
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Weird Compaq CCC / GCC interaction ?
@ 2000-09-26 17:25 Larry Sendlosky
2000-09-26 18:01 ` Michal Jaegermann
2000-09-27 3:17 ` Richard Henderson
0 siblings, 2 replies; 13+ messages in thread
From: Larry Sendlosky @ 2000-09-26 17:25 UTC (permalink / raw)
To: axp-list
I haven't seen any of this thread, but the quoted spec is correct and
makes sense. Given the example below
MAGIC is an unsigned int (32bits) with value 0xc00fc00f. The compiler
should generate 0x00000000c00fc00f for the register value. This is
"sign extending" an unsigned int (there is no sign bit or it's
"inferred" to be zero).
If MAGIC was defined as int 0xc00fc00f, then the register value
should be 0xffffffffc00fc00f. int 0xc00fc00f is a negative number.
larry
> >
> > According to the Calling Standard for Alpha Systems, Section 4.1.5 "Unused
> > Bits in Passed Data," both signed and unsigned ints should be passed
> > sign-extended in registers.
>
> Good to know but why this convention? If I follow implications
> correctly (which is a big IF) then if I take results of such function
> returning unsigned int, like in the example, and will cast its result to
> long then I may get a negative number. OTOH if I do:
>
> #define MAGIC 0xc00fc00fU
> ...
> printf ("%ld\n", (long)MAGIC);
> ...
>
> then result is positive and I would be quite surprised otherwise.
> Or this Standard makes this also into a bug and expects that the
> cast above is equivalent to (long)((int)MAGIC)? If yes then again
> why?
>
> Michal
>
>
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
>
______________________________________________________________________
Larry Sendlosky ATS
larry@scrugs.lkg.dec.com (978) 506-6640 Compaq
----------------------------------------------------------------------
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: Weird Compaq CCC / GCC interaction ?
2000-09-26 17:25 Larry Sendlosky
@ 2000-09-26 18:01 ` Michal Jaegermann
2000-09-27 3:17 ` Richard Henderson
1 sibling, 0 replies; 13+ messages in thread
From: Michal Jaegermann @ 2000-09-26 18:01 UTC (permalink / raw)
To: axp-list
Larry Sendlosky wrote:
>
>
> I haven't seen any of this thread, but the quoted spec is correct and
> makes sense. Given the example below
>
> MAGIC is an unsigned int (32bits) with value 0xc00fc00f. The compiler
> should generate 0x00000000c00fc00f for the register value. This is
> "sign extending" an unsigned int (there is no sign bit or it's
> "inferred" to be zero).
That was really the question. The standard which we are talking about
seems to imply that a return value from an unsigned int function should
be 0xffffffffc00fc00f and not 0x00000000c00fc00f although you will
notice that only after a cast to long. gcc, save the latest stuff,
does what you describe above and this is non-conforming, if I understand
correctly what was said here. I was curious about further implications.
Michal
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Weird Compaq CCC / GCC interaction ?
2000-09-26 17:25 Larry Sendlosky
2000-09-26 18:01 ` Michal Jaegermann
@ 2000-09-27 3:17 ` Richard Henderson
1 sibling, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2000-09-27 3:17 UTC (permalink / raw)
To: axp-list
On Tue, Sep 26, 2000 at 01:25:47PM -0400, Larry Sendlosky wrote:
> MAGIC is an unsigned int (32bits) with value 0xc00fc00f. The compiler
> should generate 0x00000000c00fc00f for the register value. This is
> "sign extending" an unsigned int (there is no sign bit or it's
> "inferred" to be zero).
Incorrect. The calling conventions specify that bit 31 of a 32-bit
value should be replicated up. We choose this form because this is
what the 32-bit arithmetic and memory load instructions do, so oft
times we need perform no extra work.
Basicly, one should choose *some* canonical form for 32-bit data in
your 64-bit registers. Sign extending happens to be easiest on Alpha.
Failure to do so results in catastrophic failure in the face of missing
or incorrect prototypes -- all too common in source code even today.
Anyway, the gcc problem was brought to my attention by Steve Hobbes
from the Compaq compiler group back in January. It's been fixed since,
though I guess that's well after 2.95 was released.
r~
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: Weird Compaq CCC / GCC interaction ?
@ 2000-09-26 17:47 David Addison
0 siblings, 0 replies; 13+ messages in thread
From: David Addison @ 2000-09-26 17:47 UTC (permalink / raw)
To: 'axp-list@redhat.com'
It seems that the MAGIC value 0xc00fc00f is being sign extended as a
negative number. Changing the printf for the working case and printing out
longs instead of ints shows;
GOOD baseAddr ffffffffc00fc00f == ffffffffc00fc00f
Even casting MAGIC to an unsigned int doesn't make it a postive 64-bit
number. Declaring it as 'const unsigned int' does though.
So gcc is clearing the top 4-bytes of the return value in fn.c and so the
main code compares 0x00000000c00fc00f with 0xffffffffc00fc00f in the if
statement.
Is there a way to define the MAGIC value unsigned ? 0xc00fc00fU doesn't seem
to have any effect.
Addy.
> -----Original Message-----
> From: Larry Sendlosky [mailto:larry@scrugs.lkg.dec.com]
> Sent: 26 September 2000 18:26
> To: axp-list@redhat.com
> Subject: Re: Weird Compaq CCC / GCC interaction ?
>
>
>
>
> I haven't seen any of this thread, but the quoted spec is correct and
> makes sense. Given the example below
>
> MAGIC is an unsigned int (32bits) with value 0xc00fc00f. The compiler
> should generate 0x00000000c00fc00f for the register value. This is
> "sign extending" an unsigned int (there is no sign bit or it's
> "inferred" to be zero).
>
> If MAGIC was defined as int 0xc00fc00f, then the register value
> should be 0xffffffffc00fc00f. int 0xc00fc00f is a negative number.
>
>
> larry
>
>
> > >
> > > According to the Calling Standard for Alpha Systems,
> Section 4.1.5 "Unused
> > > Bits in Passed Data," both signed and unsigned ints
> should be passed
> > > sign-extended in registers.
> >
> > Good to know but why this convention? If I follow implications
> > correctly (which is a big IF) then if I take results of
> such function
> > returning unsigned int, like in the example, and will cast
> its result to
> > long then I may get a negative number. OTOH if I do:
> >
> > #define MAGIC 0xc00fc00fU
> > ...
> > printf ("%ld\n", (long)MAGIC);
> > ...
> >
> > then result is positive and I would be quite surprised otherwise.
> > Or this Standard makes this also into a bug and expects that the
> > cast above is equivalent to (long)((int)MAGIC)? If yes then again
> > why?
> >
> > Michal
> >
> >
> >
> > _______________________________________________
> > Axp-list mailing list
> > Axp-list@redhat.com
> > https://listman.redhat.com/mailman/listinfo/axp-list
> >
>
>
>
> ______________________________________________________________________
> Larry Sendlosky ATS
> larry@scrugs.lkg.dec.com (978) 506-6640 Compaq
> ----------------------------------------------------------------------
>
>
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: Weird Compaq CCC / GCC interaction ?
@ 2000-09-26 18:52 Larry Sendlosky
0 siblings, 0 replies; 13+ messages in thread
From: Larry Sendlosky @ 2000-09-26 18:52 UTC (permalink / raw)
To: axp-list
I don't have the original quote from the spec, but I believe it said:
Signed and unsigned 32bit integers should be signed extended into
a 64bit register. That is the example I gave in my previous message
(below).
A function that returns an unsigned int, as far as the caller is
concerned, returns 32bits of data to be treated as an unsigned int.
One could argue that it doesn't matter what the "upper" 32bits
in the 64bit R0 contain as long as the compiler only uses the "lower"
32bits as an unsigned int in subsequent usage by the caller's code.
The signed extension is a must so that arithmetic ops on 32bit values
work as one would expect when done in 64bit registers. That's all
the standard/spec requires.
> Larry Sendlosky wrote:
> >
> >
> > I haven't seen any of this thread, but the quoted spec is correct and
> > makes sense. Given the example below
> >
> > MAGIC is an unsigned int (32bits) with value 0xc00fc00f. The compiler
> > should generate 0x00000000c00fc00f for the register value. This is
> > "sign extending" an unsigned int (there is no sign bit or it's
> > "inferred" to be zero).
>
> That was really the question. The standard which we are talking about
> seems to imply that a return value from an unsigned int function should
> be 0xffffffffc00fc00f and not 0x00000000c00fc00f although you will
> notice that only after a cast to long. gcc, save the latest stuff,
> does what you describe above and this is non-conforming, if I understand
> correctly what was said here. I was curious about further implications.
>
I don't belive the spec attempts to specify the "format" of a 32bit
value placed in R0 when returning from a function. As long as the
compiler "does the right thing" with the "lower" 32bits in the
caller's code.
However, the Alpha "calling standard" may specify the format.
I've been talking about the Alpha SRM which describes the
representation of 32bit values in 64bit registers.
Can one of you send me the original problem privately? So I can
see what started all this.
thanks
larry
______________________________________________________________________
Larry Sendlosky ATS
larry@scrugs.lkg.dec.com (978) 506-6640 Compaq
----------------------------------------------------------------------
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2000-09-27 3:17 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-09-26 8:55 Weird Compaq CCC / GCC interaction ? David Addison
2000-09-26 9:41 ` Andrei A. Dergatchev
2000-09-26 10:12 ` Nikita Schmidt
2000-09-26 16:02 ` Michal Jaegermann
2000-09-26 12:23 ` Ivan Kokshaysky
2000-09-26 13:57 ` Ivan Kokshaysky
-- strict thread matches above, loose matches on Subject: below --
2000-09-26 13:59 David Addison
2000-09-26 15:36 ` Ivan Kokshaysky
2000-09-26 17:25 Larry Sendlosky
2000-09-26 18:01 ` Michal Jaegermann
2000-09-27 3:17 ` Richard Henderson
2000-09-26 17:47 David Addison
2000-09-26 18:52 Larry Sendlosky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox