This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c/7490: gcc dumps core when trying to compile the attached code.


>Number:         7490
>Category:       c
>Synopsis:       gcc dumps core when trying to compile the attached code.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          ice-on-legal-code
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 04 10:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Keith Reynolds
>Release:        3.0.4
>Organization:
Self
>Environment:
System: Linux shoshin.keithr.com 2.4.18 #56 Sun Jul 7 22:04:16 PDT 2002 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure --prefix=/usr/local/gcc
>Description:

When compiling code with a macro that defines a block, inside of which
is a function declaration with __attribute__ ((__alias__ ("other_function"))),
the compiler gets a Segmentation fault.

>How-To-Repeat:
Preprocessed source:

# 1 "foo.c"
# 1 "buffer_protect.h" 1
# 2 "foo.c" 2
# 1 "foo.c"
# 1 "/usr/include/stdlib.h" 1 3
# 25 "/usr/include/stdlib.h" 3
# 1 "/usr/include/features.h" 1 3
# 250 "/usr/include/features.h" 3
# 1 "/usr/include/sys/cdefs.h" 1 3
# 251 "/usr/include/features.h" 2 3
# 278 "/usr/include/features.h" 3
# 1 "/usr/include/gnu/stubs.h" 1 3
# 279 "/usr/include/features.h" 2 3
# 26 "/usr/include/stdlib.h" 2 3







# 1 "/usr/local/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/include/stddef.h" 1 3
# 199 "/usr/local/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/include/stddef.h" 3
typedef unsigned int size_t;
# 287 "/usr/local/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/include/stddef.h" 3
typedef long int wchar_t;
# 34 "/usr/include/stdlib.h" 2 3







typedef struct
  {
    int quot;
    int rem;
  } div_t;



typedef struct
  {
    long int quot;
    long int rem;
  } ldiv_t;
# 80 "/usr/include/stdlib.h" 3
extern size_t __ctype_get_mb_cur_max (void) ;



extern double atof (__const char *__nptr) ;

extern int atoi (__const char *__nptr) ;

extern long int atol (__const char *__nptr) ;



__extension__ extern long long int atoll (__const char *__nptr) ;



extern double strtod (__const char *__restrict __nptr, char **__restrict __endptr) ;
# 109 "/usr/include/stdlib.h" 3
extern long int strtol (__const char *__restrict __nptr, char **__restrict __endptr, int __base) ;


extern unsigned long int strtoul (__const char *__restrict __nptr, char **__restrict __endptr, int __base) ;





__extension__
extern long long int strtoq (__const char *__restrict __nptr, char **__restrict __endptr, int __base) ;


__extension__
extern unsigned long long int strtouq (__const char *__restrict __nptr, char **__restrict __endptr, int __base) ;
# 132 "/usr/include/stdlib.h" 3
__extension__
extern long long int strtoll (__const char *__restrict __nptr, char **__restrict __endptr, int __base) ;


__extension__
extern unsigned long long int strtoull (__const char *__restrict __nptr, char **__restrict __endptr, int __base) ;
# 196 "/usr/include/stdlib.h" 3
extern double __strtod_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) ;


extern float __strtof_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) ;

extern long double __strtold_internal (__const char * __restrict __nptr, char **__restrict __endptr, int __group) ;




extern long int __strtol_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) ;





extern unsigned long int __strtoul_internal (__const char * __restrict __nptr, char **__restrict __endptr, int __base, int __group) ;







__extension__
extern long long int __strtoll_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) ;





__extension__
extern unsigned long long int __strtoull_internal (__const char * __restrict __nptr, char ** __restrict __endptr, int __base, int __group) ;
# 333 "/usr/include/stdlib.h" 3
extern char *l64a (long int __n) ;


extern long int a64l (__const char *__s) ;


# 1 "/usr/include/sys/types.h" 1 3
# 26 "/usr/include/sys/types.h" 3
# 1 "/usr/include/features.h" 1 3
# 27 "/usr/include/sys/types.h" 2 3



# 1 "/usr/include/bits/types.h" 1 3
# 26 "/usr/include/bits/types.h" 3
# 1 "/usr/include/features.h" 1 3
# 27 "/usr/include/bits/types.h" 2 3


# 1 "/usr/local/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/include/stddef.h" 1 3
# 30 "/usr/include/bits/types.h" 2 3


typedef unsigned char __u_char;
typedef unsigned short __u_short;
typedef unsigned int __u_int;
typedef unsigned long __u_long;

__extension__ typedef unsigned long long int __u_quad_t;
__extension__ typedef long long int __quad_t;
# 49 "/usr/include/bits/types.h" 3
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;

__extension__ typedef signed long long int __int64_t;
__extension__ typedef unsigned long long int __uint64_t;

typedef __quad_t *__qaddr_t;

typedef __u_quad_t __dev_t;
typedef __u_int __uid_t;
typedef __u_int __gid_t;
typedef __u_long __ino_t;
typedef __u_int __mode_t;
typedef __u_int __nlink_t;
typedef long int __off_t;
typedef __quad_t __loff_t;
typedef int __pid_t;
typedef int __ssize_t;
typedef long int __rlim_t;
typedef __quad_t __rlim64_t;
typedef __u_int __id_t;

typedef struct
  {
    int __val[2];
  } __fsid_t;


typedef int __daddr_t;
typedef char *__caddr_t;
typedef long int __time_t;
typedef long int __swblk_t;

typedef long int __clock_t;


typedef unsigned long int __fd_mask;
# 100 "/usr/include/bits/types.h" 3
typedef struct
  {






    __fd_mask __fds_bits[1024 / (8 * sizeof (__fd_mask))];


  } __fd_set;


typedef int __key_t;


typedef unsigned short int __ipc_pid_t;





typedef long int __blkcnt_t;
typedef __quad_t __blkcnt64_t;


typedef __u_long __fsblkcnt_t;
typedef __u_quad_t __fsblkcnt64_t;


typedef __u_long __fsfilcnt_t;
typedef __u_quad_t __fsfilcnt64_t;


typedef __u_long __ino64_t;


typedef __loff_t __off64_t;


typedef long int __t_scalar_t;
typedef unsigned long int __t_uscalar_t;


typedef int __intptr_t;
# 31 "/usr/include/sys/types.h" 2 3


typedef __u_char u_char;
typedef __u_short u_short;
typedef __u_int u_int;
typedef __u_long u_long;
typedef __quad_t quad_t;
typedef __u_quad_t u_quad_t;
typedef __fsid_t fsid_t;


typedef __loff_t loff_t;



typedef __ino_t ino_t;
# 58 "/usr/include/sys/types.h" 3
typedef __dev_t dev_t;




typedef __gid_t gid_t;




typedef __mode_t mode_t;




typedef __nlink_t nlink_t;




typedef __uid_t uid_t;





typedef __off_t off_t;
# 96 "/usr/include/sys/types.h" 3
typedef __pid_t pid_t;




typedef __id_t id_t;



typedef __ssize_t ssize_t;




typedef __daddr_t daddr_t;
typedef __caddr_t caddr_t;



typedef __key_t key_t;






# 1 "/usr/include/time.h" 1 3
# 68 "/usr/include/time.h" 3
# 1 "/usr/include/bits/types.h" 1 3
# 69 "/usr/include/time.h" 2 3


typedef __time_t time_t;
# 123 "/usr/include/sys/types.h" 2 3


# 1 "/usr/local/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/include/stddef.h" 1 3
# 126 "/usr/include/sys/types.h" 2 3



typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
# 169 "/usr/include/sys/types.h" 3
typedef int int8_t __attribute__ ((__mode__ (__QI__)));
typedef int int16_t __attribute__ ((__mode__ (__HI__)));
typedef int int32_t __attribute__ ((__mode__ (__SI__)));
typedef int int64_t __attribute__ ((__mode__ (__DI__)));


typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__)));
typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__)));

typedef int register_t __attribute__ ((__mode__ (__word__)));
# 191 "/usr/include/sys/types.h" 3
# 1 "/usr/include/endian.h" 1 3
# 22 "/usr/include/endian.h" 3
# 1 "/usr/include/features.h" 1 3
# 23 "/usr/include/endian.h" 2 3
# 35 "/usr/include/endian.h" 3
# 1 "/usr/include/bits/endian.h" 1 3
# 36 "/usr/include/endian.h" 2 3
# 192 "/usr/include/sys/types.h" 2 3


# 1 "/usr/include/sys/select.h" 1 3
# 25 "/usr/include/sys/select.h" 3
# 1 "/usr/include/features.h" 1 3
# 26 "/usr/include/sys/select.h" 2 3


# 1 "/usr/include/bits/types.h" 1 3
# 29 "/usr/include/sys/select.h" 2 3


# 1 "/usr/include/bits/select.h" 1 3
# 32 "/usr/include/sys/select.h" 2 3


# 1 "/usr/include/bits/sigset.h" 1 3
# 23 "/usr/include/bits/sigset.h" 3
typedef int __sig_atomic_t;




typedef struct
  {
    unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
  } __sigset_t;
# 35 "/usr/include/sys/select.h" 2 3



# 1 "/usr/include/time.h" 1 3
# 83 "/usr/include/time.h" 3
struct timespec
  {
    long int tv_sec;
    long int tv_nsec;
  };
# 39 "/usr/include/sys/select.h" 2 3







struct timeval;

typedef __fd_mask fd_mask;


typedef __fd_set fd_set;
# 74 "/usr/include/sys/select.h" 3
extern int __select (int __nfds, __fd_set *__readfds, __fd_set *__writefds, __fd_set *__exceptfds, struct timeval *__timeout) ;


extern int select (int __nfds, __fd_set *__readfds, __fd_set *__writefds, __fd_set *__exceptfds, struct timeval *__timeout) ;
# 195 "/usr/include/sys/types.h" 2 3


# 1 "/usr/include/sys/sysmacros.h" 1 3
# 198 "/usr/include/sys/types.h" 2 3





typedef __blkcnt_t blkcnt_t;
typedef __fsblkcnt_t fsblkcnt_t;
typedef __fsfilcnt_t fsfilcnt_t;
# 340 "/usr/include/stdlib.h" 2 3






extern int32_t random (void) ;


extern void srandom (unsigned int __seed) ;





extern void * initstate (unsigned int __seed, void * __statebuf, size_t __statelen) ;




extern void * setstate (void * __statebuf) ;







struct random_data
  {
    int32_t *fptr;
    int32_t *rptr;
    int32_t *state;
    int rand_type;
    int rand_deg;
    int rand_sep;
    int32_t *end_ptr;
  };

extern int random_r (struct random_data *__restrict __buf, int32_t *__restrict __result) ;


extern int srandom_r (unsigned int __seed, struct random_data *__buf) ;

extern int initstate_r (unsigned int __seed, void * __restrict __statebuf, size_t __statelen, struct random_data *__restrict __buf) ;




extern int setstate_r (void * __restrict __statebuf, struct random_data *__restrict __buf) ;






extern int rand (void) ;

extern void srand (unsigned int __seed) ;



extern int rand_r (unsigned int *__seed) ;







extern double drand48 (void) ;
extern double erand48 (unsigned short int __xsubi[3]) ;


extern long int lrand48 (void) ;
extern long int nrand48 (unsigned short int __xsubi[3]) ;


extern long int mrand48 (void) ;
extern long int jrand48 (unsigned short int __xsubi[3]) ;


extern void srand48 (long int __seedval) ;
extern unsigned short int *seed48 (unsigned short int __seed16v[3]) ;
extern void lcong48 (unsigned short int __param[7]) ;


struct drand48_data
  {
    unsigned short int x[3];
    unsigned short int a[3];
    unsigned short int c;
    unsigned short int old_x[3];
    int init;
  };



extern int drand48_r (struct drand48_data *__restrict __buffer, double *__restrict __result) ;

extern int erand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, double *__restrict __result) ;




extern int lrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) ;

extern int nrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) ;




extern int mrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) ;

extern int jrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) ;




extern int srand48_r (long int __seedval, struct drand48_data *__buffer) ;

extern int seed48_r (unsigned short int __seed16v[3], struct drand48_data *__buffer) ;


extern int lcong48_r (unsigned short int __param[7], struct drand48_data *__buffer) ;
# 474 "/usr/include/stdlib.h" 3
extern void * malloc (size_t __size) ;

extern void * calloc (size_t __nmemb, size_t __size) ;





extern void * realloc (void * __ptr, size_t __size) ;

extern void free (void * __ptr) ;



extern void cfree (void * __ptr) ;



# 1 "/usr/include/alloca.h" 1 3
# 22 "/usr/include/alloca.h" 3
# 1 "/usr/include/features.h" 1 3
# 23 "/usr/include/alloca.h" 2 3


# 1 "/usr/local/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/include/stddef.h" 1 3
# 26 "/usr/include/alloca.h" 2 3







extern void * alloca (size_t __size) ;
# 493 "/usr/include/stdlib.h" 2 3




extern void * valloc (size_t __size) ;




extern void abort (void) __attribute__ ((__noreturn__));



extern int atexit (void (*__func) (void)) ;




extern int __on_exit (void (*__func) (int __status, void * __arg), void * __arg) ;

extern int on_exit (void (*__func) (int __status, void * __arg), void * __arg) ;






extern void exit (int __status) __attribute__ ((__noreturn__));
# 530 "/usr/include/stdlib.h" 3
extern char *getenv (__const char *__name) ;



extern char *__secure_getenv (__const char *__name) ;





extern int putenv (char *__string) ;





extern int setenv (__const char *__name, __const char *__value, int __replace) ;



extern void unsetenv (__const char *__name) ;






extern int clearenv (void) ;
# 566 "/usr/include/stdlib.h" 3
extern char *mktemp (char *__template) ;






extern int mkstemp (char *__template) ;




extern int system (__const char *__command) ;
# 595 "/usr/include/stdlib.h" 3
extern char *realpath (__const char *__restrict __name, char *__restrict __resolved) ;







typedef int (*__compar_fn_t) (__const void *, __const void *);
# 612 "/usr/include/stdlib.h" 3
extern void * bsearch (__const void * __key, __const void * __base, size_t __nmemb, size_t __size, __compar_fn_t __compar);





extern void qsort (void * __base, size_t __nmemb, size_t __size, __compar_fn_t __compar);




extern int abs (int __x) __attribute__ ((__const__));
extern long int labs (long int __x) __attribute__ ((__const__));
# 634 "/usr/include/stdlib.h" 3
extern div_t div (int __numer, int __denom) __attribute__ ((__const__));
extern ldiv_t ldiv (long int __numer, long int __denom)
     __attribute__ ((__const__));
# 651 "/usr/include/stdlib.h" 3
extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) ;





extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) ;





extern char *gcvt (double __value, int __ndigit, char *__buf) ;


extern char *qecvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) ;

extern char *qfcvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) ;

extern char *qgcvt (long double __value, int __ndigit, char *__buf) ;





extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) ;


extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) ;



extern int qecvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) ;


extern int qfcvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) ;
# 695 "/usr/include/stdlib.h" 3
extern int mblen (__const char *__s, size_t __n) ;


extern int mbtowc (wchar_t *__restrict __pwc, __const char *__restrict __s, size_t __n) ;



extern int wctomb (char *__s, wchar_t __wchar) ;



extern size_t mbstowcs (wchar_t *__restrict __pwcs, __const char *__restrict __s, size_t __n) ;


extern size_t wcstombs (char *__restrict __s, __const wchar_t *__restrict __pwcs, size_t __n) ;
# 718 "/usr/include/stdlib.h" 3
extern int rpmatch (__const char *__response) ;
# 2 "foo.c" 2

char *copy (char *src)
{
    char *cp;
    char dest[1024];

    cp = dest;
    ({ extern int __sprintf (char *__dest, char *__fmt, ...) __attribute__ ((__alias__ ("sprintf"))); if (sizeof (dest) == sizeof (char *)) __sprintf (dest, "%s", src); else snprintf (dest, sizeof (dest), "%s", src); });
    return (cp);
}

main (int argc, char * const *argv)
{
    printf ("%s\n", copy (argv[1]));
    exit (0);
}
	
>Fix:
Moving the function declarations to global scope in the header
file works around the problem, but causes the linker to warn
about the unsafe use of gets(), even if the program never calls
gets().

Removing the __alias__ attribute from the function declaration
inside the block prevents the ICE, but of course also requires
that the declared functions actually exist somewhere.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]