C
Chul Min Kim
Hi,
I got a BUS ERROR from one of my company's program.
Let me briefly tell our environment.
Machine : Sun E3500 (Ultra Sparc II 400Mhz CPU 4EA)
OS : Solaris7
Compiler : Sun Workshop 5.0 cc complier
I get "BUS ERROR" only when I execute the binary which builds
with "-g" complier option.
However, the binary builds with "-O" option is ok. No Bus Error.
I found FAQ realted to this "Bus Error". I have read the articles
realted to this issue already. "Bus Error" is related to misallignment.
My question is "why" bus error is not occurred with the binary built
by "-O" complier option.
Here is source code.
/* SAMPLE CODE - BEGIN */
typedef struct _SVC10336_ {
int a;
char b;
char c;
} svc10336_t;
main()
{
char reqbuf[9454];
memset((char *)&reqbuf, 0x00, sizeof(reqbuf));
{
int a = 100;
memcpy(reqbuf, &a, 4);
reqbuf[4] = '3';
reqbuf[5] = '4';
}
svc_start(reqbuf);
}
svc_start(char *reqbuf)
{
tr_svc10336(reqbuf);
}
tr_svc10336(char *reqbuf)
{
svc10336_t *svc10336;
int a;
char b;
char c;
svc10336 = (svc10336_t *)reqbuf;
a = svc10336->a;
b = svc10336->b;
c = svc10336->c;
printf("a[%d] b[%c] c[%c]\n", a,b,c);
}
/* SAMPLE CODE - END */
Here is the command that I build the binary.
(1) $ cc -g -o sample sample.c
this binary goes to "Bus Error".
(2) $ cc -O -o sample sample.c
this binary OK.
I got a BUS ERROR from one of my company's program.
Let me briefly tell our environment.
Machine : Sun E3500 (Ultra Sparc II 400Mhz CPU 4EA)
OS : Solaris7
Compiler : Sun Workshop 5.0 cc complier
I get "BUS ERROR" only when I execute the binary which builds
with "-g" complier option.
However, the binary builds with "-O" option is ok. No Bus Error.
I found FAQ realted to this "Bus Error". I have read the articles
realted to this issue already. "Bus Error" is related to misallignment.
My question is "why" bus error is not occurred with the binary built
by "-O" complier option.
Here is source code.
/* SAMPLE CODE - BEGIN */
typedef struct _SVC10336_ {
int a;
char b;
char c;
} svc10336_t;
main()
{
char reqbuf[9454];
memset((char *)&reqbuf, 0x00, sizeof(reqbuf));
{
int a = 100;
memcpy(reqbuf, &a, 4);
reqbuf[4] = '3';
reqbuf[5] = '4';
}
svc_start(reqbuf);
}
svc_start(char *reqbuf)
{
tr_svc10336(reqbuf);
}
tr_svc10336(char *reqbuf)
{
svc10336_t *svc10336;
int a;
char b;
char c;
svc10336 = (svc10336_t *)reqbuf;
a = svc10336->a;
b = svc10336->b;
c = svc10336->c;
printf("a[%d] b[%c] c[%c]\n", a,b,c);
}
/* SAMPLE CODE - END */
Here is the command that I build the binary.
(1) $ cc -g -o sample sample.c
this binary goes to "Bus Error".
(2) $ cc -O -o sample sample.c
this binary OK.