Yi-Feng Adam Zhang wrote:
Hi Girish,

It will generate an exception on Solaris. It's not Sun Studio fault. I think it's result from the Solaris OS design.

As others mentioned, it's not Studio's, GCC's, or the OS's fault. The application is in undefined territory and therefore broken.

You can use preload /usr/lib/[EMAIL PROTECTED] . You have the info at http://docs.sun.com/app/docs/doc/816-5165/6mbb0m9k7?a=view

Not really.

There are two causes of segmentation faults:

1) You try to access memory that's not in any segment, i.e. "no mapping at the fault address". Notably addresses close to 0, which is what [EMAIL PROTECTED] deals with, but this can also fail for other addresses.

2) You access something from the "wrong segment". For example trying to write to read-only memory. This is what is happening in Girish's example below.

Before shared libraries and mmap, there used to be only three segments (text=read/execute only, data=R/W; stack=R/W), while now there are many mmapped regions and multiple stacks. But the idea is the same.

Girish's case is the second, not the first.

More specifically from /usr/include/sys/machsig.h:
   #define SEGV_MAPERR     1       /* address not mapped to object */
   #define SEGV_ACCERR     2       /* invalid permissions */

Hugh.


-bash-3.00# LD_PRELOAD_32= /usr/lib/32/[EMAIL PROTECTED]
-bash-3.00# export LD_PRELOAD_32            **针对32位程序
-bash-3.00# LD_PRELOAD_64= /usr/lib/64/[EMAIL PROTECTED]
-bash-3.00# export LD_PRELOAD_64            **针对64位程序  

Regards,
Adam

girish wrote:
Can someone please explain why this program works in sunstudio C compiler but seg faults in gcc:

#include <stdio.h>
#include <string.h>

int
main()
{
        char *ptr = "adam";

        strcpy(ptr, "eve");
        printf("%s\n", ptr);
}
This message posted from opensolaris.org
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to