Thread View: gnu.gcc.bug
2 messages
2 total messages
Started by Lack Mr G M
Thu, 07 Jan 1993 14:47
gcc-2.3.3 - bug on SUN for (char *) within a struct
Author: Lack Mr G M
Date: Thu, 07 Jan 1993 14:47
Date: Thu, 07 Jan 1993 14:47
120 lines
3142 bytes
3142 bytes
I wish to report a bug in gcc-2.3.3 on a SUN.
I have built gcc-2.3.3 on a Sun Sparcstation at SunOS4.1.1. The
configure option was "sparc-sun-sunos4.1" and I used CFLAGS=-O during
the makeing, which completed with no errors.
The following simple program dies with a segmentation fault. It
runs correctly with gcc-2.3.3 on an SG Indigo, with Suns own cc compiler
(and with other c compilers on other platforms).
It appears that the address of the "string-within-a-structure" is
not calculated correctly. I append the source and the assembler listing
produced by gcc -S.
==================== Begin test source ====================
#include <stdio.h>
#include <string.h>
struct button {
char *str ;
int opdisp ;
} ;
struct button buttons[2] = {
{ "ab00", 0, },
{ "ab01", 1, },
};
void main()
{
printf("Strings are %s and %s\n", buttons[0].str, buttons[1].str);
strcpy(buttons[0].str, "zz00");
strcpy(buttons[1].str, "zz01");
printf("Strings become %s and %s\n", buttons[0].str, buttons[1].str);
return;
}
==================== End test source ====================
==================== Begin assembler listing ====================
gcc2_compiled.:
.global _buttons
.text
.align 8
LC0:
.ascii "ab00\0"
.align 8
LC1:
.ascii "ab01\0"
.data
.align 4
_buttons:
.word LC0
.word 0
.word LC1
.word 1
.text
.align 8
LC2:
.ascii "Strings are %s and %s\12\0"
.align 8
LC3:
.ascii "zz00\0"
.align 8
LC4:
.ascii "zz01\0"
.align 8
LC5:
.ascii "Strings become %s and %s\12\0"
.align 4
.global _main
.proc 020
_main:
!#PROLOGUE# 0
save %sp,-136,%sp
!#PROLOGUE# 1
call ___main,0
nop
sethi %hi(_buttons),%o1
sethi %hi(_buttons+8),%o2
sethi %hi(LC2),%o3
or %o3,%lo(LC2),%o0
ld [%o1+%lo(_buttons)],%o1
ld [%o2+%lo(_buttons+8)],%o2
call _printf,0
nop
sethi %hi(_buttons),%o1
ld [%o1+%lo(_buttons)],%o0
sethi %hi(LC3),%o2
or %o2,%lo(LC3),%o1
call _strcpy,0
nop
sethi %hi(_buttons+8),%o1
ld [%o1+%lo(_buttons+8)],%o0
sethi %hi(LC4),%o2
or %o2,%lo(LC4),%o1
call _strcpy,0
nop
sethi %hi(_buttons),%o1
sethi %hi(_buttons+8),%o2
sethi %hi(LC5),%o3
or %o3,%lo(LC5),%o0
ld [%o1+%lo(_buttons)],%o1
ld [%o2+%lo(_buttons+8)],%o2
call _printf,0
nop
b L1
nop
L1:
ret
restore
==================== End assembler listing ====================
-------------------------- Gordon Lack ----------------------------------
The contents of this message *may* reflect my personal opinion. They are
*not* intended to reflect those of my employer, or anyone else.
Re: gcc-2.3.3 - bug on SUN for (char *) within a struct
Author: Simon Leinen
Date: Fri, 08 Jan 1993 12:23
Date: Fri, 08 Jan 1993 12:23
22 lines
1567 bytes
1567 bytes
In article <9301071447.AA12676@uk0x06.ggr.co.uk> gml4410@ggr.co.UK
(Lack Mr G M) writes:
I wish to report a bug in gcc-2.3.3 on a SUN.
I have built gcc-2.3.3 on a Sun Sparcstation at SunOS4.1.1. The
configure option was "sparc-sun-sunos4.1" and I used CFLAGS=-O during
the makeing, which completed with no errors.
The following simple program dies with a segmentation fault. It
runs correctly with gcc-2.3.3 on an SG Indigo, with Suns own cc compiler
(and with other c compilers on other platforms).
If there's a bug, then it's that the GCC-compiled binary on the SGI
doesn't get the segmentation fault. Your strcpy()'s are overwriting
string constants, which are usually allocated in read-only space by
GCC (as you can see by the ".text" directives preceding the ".ascii"
directives for your string constants). This is a deliberate design
decision which improves VM performance. If you want to turn this
behaviour off, you can pass the "-fwritable-strings" option to GCC.
--
Simon.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads