From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.redhat.com (mail.redhat.com [199.183.24.239]) by listman.redhat.com (Postfix) with ESMTP id 38ADE2F156 for ; Tue, 26 Sep 2000 04:55:44 -0400 (EDT) Received: (from mail@localhost) by mail.redhat.com (8.8.7/8.8.7) id EAA22942 for axp-list@listman.redhat.com; Tue, 26 Sep 2000 04:55:44 -0400 Received: from stegosaurus.bristol.quadrics.com (stegosaurus.quadrics.com [194.202.174.3]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id EAA22930 for ; Tue, 26 Sep 2000 04:55:30 -0400 Received: by stegosaurus.bristol.quadrics.com with Internet Mail Service (5.5.2650.21) id ; Tue, 26 Sep 2000 09:55:14 +0100 Message-ID: <010C86D15E4D1247B9A5DD312B7F5AA70BEC27@stegosaurus.bristol.quadrics.com> From: David Addison To: "'axp-list@redhat.com'" Subject: Weird Compaq CCC / GCC interaction ? Date: Tue, 26 Sep 2000 09:55:12 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C02797.7BF7DF34" X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0beta4 Precedence: bulk Reply-To: axp-list@redhat.com List-Id: Linux and Red Hat on Alpha processors This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C02797.7BF7DF34 Content-Type: text/plain; charset="iso-8859-1" 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 : 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 : 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. ------_=_NextPart_001_01C02797.7BF7DF34 Content-Type: text/html; charset="iso-8859-1"
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.
 
 

 
------_=_NextPart_001_01C02797.7BF7DF34--