Article View: gnu.gcc.bug
Article #6337Byte swapping problem with gcc 2.7.2 cross compiler on Solaris, target m68k.
From: Erik Bertelsen
Date: Thu, 21 Dec 1995 00:00
Date: Thu, 21 Dec 1995 00:00
469 lines
10585 bytes
10585 bytes
Gcc 2.7.2 produces different assembly code for m68k-apple-netbsd target
depending on the host system for the compilation when compiling the file crt0.c
from NetBSD 1.1 (current).
When gcc 2.7.2 is run on the NetBSD/Mac68k host targeted for itself and
when it is running on a decstation
----------------
# GCC was configured as follows:
./configure --target=m68k-apple-netbsd1.1
echo host=mips-dec-ultrix4.4 target=m68k-apple-netbsd1.1 build=mips-dec-ultrix4.4
-------------------
it produces seemingly correct output.
When gcc 2.7.2 is hosted on a Solaris 2.3 system and target'ed for the
NetBSD/Mac68k
-----------------------------------------
#!/bin/sh
# GCC was configured as follows:
./configure --target=m68k-apple-netbsd1.1 --prefix=/home/gnu
echo host=sparc-sun-solaris2.3 target=m68k-apple-netbsd1.1 build=sparc-sun-solaris2.3
----------------------------------------
it produces bad assembly code.
It seems that it tries to include some code for doing byte-swapping (is
the sparc and m68k of same endian-ness?) after L8:, but this code is
* not needed, and it
* causes assembly errors because a $-sign is used to denote an immediate
value instead of a #-sign.
* is wrong because it ends up swapping the two bytes in the word.
The rest of this message consists of
- a copy of the source file crt0.c
- a diff listing of the two following files
- a copy of the start of the assembly file generated on Ultrix (good)
- a copy of the start of the assembly file generated on Solaris (bad)
regards
Erik Bertelsen
UNI-C, The Danish Computing Centre for Research and Education.
================= source file =========================
/* $NetBSD: crt0.c,v 1.14 1995/06/03 13:16:11 pk Exp $ */
/*
* Copyright (c) 1993 Paul Kranenburg
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Paul Kranenburg.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Erasmus) %G%";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <stdlib.h>
#include "common.h"
extern void start __P((void)) asm("start");
void
start()
{
struct kframe {
int kargc;
char *kargv[1]; /* size depends on kargc */
char kargstr[1]; /* size varies */
char kenvstr[1]; /* size varies */
};
/*
* ALL REGISTER VARIABLES!!!
*/
register struct kframe *kfp;
register char **argv, *ap;
#ifdef lint
kfp = 0;
initcode = initcode = 0;
#else /* not lint */
asm("lea a6@(4),%0" : "=r" (kfp)); /* catch it quick */
#endif /* not lint */
argv = &kfp->kargv[0];
environ = argv + kfp->kargc + 1;
if (ap = argv[0])
if ((__progname = _strrchr(ap, '/')) == NULL)
__progname = ap;
else
++__progname;
#ifdef DYNAMIC
/* ld(1) convention: if DYNAMIC = 0 then statically linked */
#ifdef stupid_gcc
if (&_DYNAMIC)
#else
if ( ({volatile caddr_t x = (caddr_t)&_DYNAMIC; x; }) )
#endif
__load_rtld(&_DYNAMIC);
#endif /* DYNAMIC */
asm("eprol:");
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&eprol, (u_long)&etext);
#endif MCRT0
asm ("__callmain:"); /* Defined for the benefit of debuggers */
exit(main(kfp->kargc, argv, environ));
}
#ifdef DYNAMIC
asm(" ___syscall:");
asm(" movel a7@+,a0"); /* return address */
asm(" movel a7@,d0"); /* syscall number */
asm(" movel a0,a7@");
asm(" trap #0"); /* do system call */
asm(" bcc 1f"); /* check error */
asm(" moveq #-1,d0");
asm(" 1: movel a7@,a0"); /* get return address, leave */
asm(" jmp a0@"); /* correct amount on stack */
#endif /* DYNAMIC */
#include "common.c"
#ifdef MCRT0
asm (" .text");
asm ("_eprol:");
#endif
============================diff listing between assembly outputs========
144c144,150
< cmpw #267,a6@(-30)
---
> movel a6@(-32),d0
> #APP
> rorw $8, d0
> rorl $16, d0
> rorw $8, d0
> #NO_APP
> cmpw #267,d0
=======================start of assembly file from Ultrix and from Macbsd===
#NO_APP
gcc2_compiled.:
___gnu_compiled_c:
.data
.type _sccsid,@object
.size _sccsid,18
_sccsid:
.ascii "%W% (Erasmus) %G%\0"
.globl ___progname
.even
.type ___progname,@object
.size ___progname,4
___progname:
.long _empty
.text
.even
.globl start
.type start,@function
start:
link a6,#-4
moveml #0x2030,sp@-
#APP
lea a6@(4),a3
#NO_APP
lea a3@(4),a2
movel a3@,d0
lea a2@(4,d0:l:4),a0
movel a0,_environ
movel a2@,d2
jeq L2
pea 47:w
movel d2,sp@-
jbsr __strrchr
movel d0,___progname
addqw #8,sp
jne L3
movel d2,___progname
jra L2
L3:
addql #1,___progname
L2:
movel #__DYNAMIC,a6@(-4)
movel a6@(-4),d0
movel a6@(-4),d0
jeq L5
pea __DYNAMIC
jbsr ___load_rtld
addqw #4,sp
L5:
#APP
eprol:
__callmain:
#NO_APP
movel _environ,sp@-
movel a2,sp@-
movel a3@,sp@-
jbsr _main
movel d0,sp@-
jbsr _exit
nop
Lfe1:
.size start,Lfe1-start
#APP
___syscall:
movel a7@+,a0
movel a7@,d0
movel a0,a7@
trap #0
bcc 1f
moveq #-1,d0
1: movel a7@,a0
jmp a0@
#NO_APP
.lcomm _crt.4,36
LC0:
.ascii "/usr/libexec/ld.so\0"
LC1:
.ascii "No ld.so\12\0"
LC2:
.ascii "Failure reading ld.so\12\0"
LC3:
.ascii "Bad magic: ld.so\12\0"
LC4:
.ascii "Cannot map ld.so\12\0"
LC5:
.ascii "crt0: update /usr/libexec/ld.so\12\0"
LC6:
.ascii "ld.so failed\12\0"
.even
.type ___load_rtld,@function
___load_rtld:
link a6,#-32
moveml #0x303c,sp@-
movel a6@(8),a5
movel #LC0,_crt.4+28
clrl sp@-
clrl sp@-
pea LC0
pea 5:w
lea ___syscall,a2
jbsr a2@
lea _crt.4+8,a0
movel d0,a0@
addqw #8,sp
addqw #8,sp
moveq #-1,d2
cmpl d0,d2
jne L7
pea 10:w
pea LC1
pea 2:w
pea 4:w
jbsr a2@
pea 1:w
pea 1:w
jbsr a2@
addw #24,sp
L7:
pea 32:w
pea a6@(-32)
movel _crt.4+8,sp@-
pea 3:w
lea ___syscall,a2
jbsr a2@
addqw #8,sp
addqw #8,sp
moveq #31,d3
cmpl d0,d3
jcs L8
pea 23:w
pea LC2
pea 2:w
pea 4:w
jbsr a2@
pea 1:w
pea 1:w
jbsr a2@
addw #24,sp
L8:
movel a6@(-32),d0
clrw d0
tstl d0
jeq L10
cmpw #267,a6@(-30)
jne L11
jra L9
L10:
===========================assembly generated on solaris==================
#NO_APP
gcc2_compiled.:
___gnu_compiled_c:
.data
.type _sccsid,@object
.size _sccsid,18
_sccsid:
.ascii "%W% (Erasmus) %G%\0"
.globl ___progname
.even
.type ___progname,@object
.size ___progname,4
___progname:
.long _empty
.text
.even
.globl start
.type start,@function
start:
link a6,#-4
moveml #0x2030,sp@-
#APP
lea a6@(4),a3
#NO_APP
lea a3@(4),a2
movel a3@,d0
lea a2@(4,d0:l:4),a0
movel a0,_environ
movel a2@,d2
jeq L2
pea 47:w
movel d2,sp@-
jbsr __strrchr
movel d0,___progname
addqw #8,sp
jne L3
movel d2,___progname
jra L2
L3:
addql #1,___progname
L2:
movel #__DYNAMIC,a6@(-4)
movel a6@(-4),d0
movel a6@(-4),d0
jeq L5
pea __DYNAMIC
jbsr ___load_rtld
addqw #4,sp
L5:
#APP
eprol:
__callmain:
#NO_APP
movel _environ,sp@-
movel a2,sp@-
movel a3@,sp@-
jbsr _main
movel d0,sp@-
jbsr _exit
nop
Lfe1:
.size start,Lfe1-start
#APP
___syscall:
movel a7@+,a0
movel a7@,d0
movel a0,a7@
trap #0
bcc 1f
moveq #-1,d0
1: movel a7@,a0
jmp a0@
#NO_APP
.lcomm _crt.4,36
LC0:
.ascii "/usr/libexec/ld.so\0"
LC1:
.ascii "No ld.so\12\0"
LC2:
.ascii "Failure reading ld.so\12\0"
LC3:
.ascii "Bad magic: ld.so\12\0"
LC4:
.ascii "Cannot map ld.so\12\0"
LC5:
.ascii "crt0: update /usr/libexec/ld.so\12\0"
LC6:
.ascii "ld.so failed\12\0"
.even
.type ___load_rtld,@function
___load_rtld:
link a6,#-32
moveml #0x303c,sp@-
movel a6@(8),a5
movel #LC0,_crt.4+28
clrl sp@-
clrl sp@-
pea LC0
pea 5:w
lea ___syscall,a2
jbsr a2@
lea _crt.4+8,a0
movel d0,a0@
addqw #8,sp
addqw #8,sp
moveq #-1,d2
cmpl d0,d2
jne L7
pea 10:w
pea LC1
pea 2:w
pea 4:w
jbsr a2@
pea 1:w
pea 1:w
jbsr a2@
addw #24,sp
L7:
pea 32:w
pea a6@(-32)
movel _crt.4+8,sp@-
pea 3:w
lea ___syscall,a2
jbsr a2@
addqw #8,sp
addqw #8,sp
moveq #31,d3
cmpl d0,d3
jcs L8
pea 23:w
pea LC2
pea 2:w
pea 4:w
jbsr a2@
pea 1:w
pea 1:w
jbsr a2@
addw #24,sp
L8:
movel a6@(-32),d0
clrw d0
tstl d0
jeq L10
movel a6@(-32),d0
#APP
rorw $8, d0
rorl $16, d0
rorw $8, d0
#NO_APP
cmpw #267,d0
jne L11
jra L9
L10:
=================end of attachments=================================
Technical Details
Message-ID:
<Pine.SOL.3.91.951221140807.3331A-100000@mediator.uni-c.dk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,5dc33d6610f309a3,start X-Google-Attributes: gid113d02,public From: erik@mediator.uni-c.dk (Erik Bertelsen) Subject: Byte swapping problem with gcc 2.7.2 cross compiler on Solaris, target m68k. Date: 1995/12/21 Message-ID: <Pine.SOL.3.91.951221140807.3331A-100000@mediator.uni-c.dk> X-Deja-AN: 122498327 distribution: gnu sender: daemon@cis.ohio-state.edu organization: GNUs Not Usenet newsgroups: gnu.gcc.bug