ambs / Config-AutoConf

Config::AutoConf Perl Module
Other
2 stars 7 forks source link

check_alignof_type fails with gcc #7

Closed plicease closed 9 years ago

plicease commented 9 years ago

This program works with clang but not gcc on an otherwise the same system:

use strict;
use warnings;
use Config::AutoConf;

unlink 'config.log';

my $ac = Config::AutoConf->new;

$ac->check_cc;
$ac->check_alignof_type('int');

output:

twin% perl foo.pl 
Checking for cc... cc
Checking for align of int... no

config.log:

Checking for cc ...cc
Checking for align of int ...compile stage failed - error building testIdvyZj.o from 'testIdvyZj.c' at /home/ollisg/perl5/perlbrew/perls/perl-5.16.3/lib/5.16.3/ExtUtils/CBuilder/Base.pm line 177.

testIdvyZj.c: In function ‘main’:
testIdvyZj.c:49:14: error: storage size of ‘test_array’ isn’t constant

failing program is:
/* end of conftest.h */

#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

  int
  main ()
  {
    #ifndef offsetof
# ifdef __ICC
#  define offsetof(type,memb) ((size_t)(((char *)(&((type*)0)->memb)) - ((char *)0)))
# else
#  define offsetof(type,memb) ((size_t)&((type*)0)->memb)
# endif
#endif
typedef struct { char x; int y; } ac__type_alignof_;
  static int test_array [(((long int)(offsetof(ac__type_alignof_, y))) >= 0) ? 1 : -1 ];
  test_array [0] = 0
;
    return 0;
  }

stdout was :
cc -I/home/ollisg/perl5/perlbrew/perls/perl-5.16.3/lib/5.16.3/x86_64-linux/CORE -fPIC -c -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -o testIdvyZj.o testIdvyZj.c

compile stage failed - error building testmDYP03.o from 'testmDYP03.c' at /home/ollisg/perl5/perlbrew/perls/perl-5.16.3/lib/5.16.3/ExtUtils/CBuilder/Base.pm line 177.

testmDYP03.c: In function ‘main’:
testmDYP03.c:49:14: error: size of array ‘test_array’ is negative
testmDYP03.c:49:14: error: storage size of ‘test_array’ isn’t constant

failing program is:
/* end of conftest.h */

#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

  int
  main ()
  {
    #ifndef offsetof
# ifdef __ICC
#  define offsetof(type,memb) ((size_t)(((char *)(&((type*)0)->memb)) - ((char *)0)))
# else
#  define offsetof(type,memb) ((size_t)&((type*)0)->memb)
# endif
#endif
typedef struct { char x; int y; } ac__type_alignof_;
  static int test_array [(((long int)(offsetof(ac__type_alignof_, y))) < 0) ? 1 : -1 ];
  test_array [0] = 0
;
    return 0;
  }

stdout was :
cc -I/home/ollisg/perl5/perlbrew/perls/perl-5.16.3/lib/5.16.3/x86_64-linux/CORE -fPIC -c -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -o testmDYP03.o testmDYP03.c

compile stage failed - error building testO2_wWV.o from 'testO2_wWV.c' at /home/ollisg/perl5/perlbrew/perls/perl-5.16.3/lib/5.16.3/ExtUtils/CBuilder/Base.pm line 177.

testO2_wWV.c: In function ‘main’:
testO2_wWV.c:49:14: error: size of array ‘test_array’ is negative
testO2_wWV.c:49:14: error: storage size of ‘test_array’ isn’t constant

failing program is:
/* end of conftest.h */

#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

  int
  main ()
  {
    #ifndef offsetof
# ifdef __ICC
#  define offsetof(type,memb) ((size_t)(((char *)(&((type*)0)->memb)) - ((char *)0)))
# else
#  define offsetof(type,memb) ((size_t)&((type*)0)->memb)
# endif
#endif
typedef struct { char x; int y; } ac__type_alignof_;
  static int test_array [(((long int)(offsetof(ac__type_alignof_, y))) < 0) ? 1 : -1 ];
  test_array [0] = 0
;
    return 0;
  }

stdout was :
cc -I/home/ollisg/perl5/perlbrew/perls/perl-5.16.3/lib/5.16.3/x86_64-linux/CORE -fPIC -c -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -o testO2_wWV.o testO2_wWV.c

compile stage failed - error building testFHWxSm.o from 'testFHWxSm.c' at /home/ollisg/perl5/perlbrew/perls/perl-5.16.3/lib/5.16.3/ExtUtils/CBuilder/Base.pm line 177.

testFHWxSm.c: In function ‘main’:
testFHWxSm.c:49:14: error: storage size of ‘test_array’ isn’t constant

failing program is:
/* end of conftest.h */

#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

  int
  main ()
  {
    #ifndef offsetof
# ifdef __ICC
#  define offsetof(type,memb) ((size_t)(((char *)(&((type*)0)->memb)) - ((char *)0)))
# else
#  define offsetof(type,memb) ((size_t)&((type*)0)->memb)
# endif
#endif
typedef struct { char x; int y; } ac__type_alignof_;
  static int test_array [(((long int)(offsetof(ac__type_alignof_, y))) > 0) ? 1 : -1 ];
  test_array [0] = 0
;
    return 0;
  }

stdout was :
cc -I/home/ollisg/perl5/perlbrew/perls/perl-5.16.3/lib/5.16.3/x86_64-linux/CORE -fPIC -c -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -o testFHWxSm.o testFHWxSm.c

no

versions:

twin% gcc --version
gcc (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

twin% cat /etc/de
debconf.conf     debian_version   default/         defoma/          deluser.conf     devscripts.conf  
twin% cat /etc/debian_version 
7.8
rehsack commented 9 years ago

Try this instead:

use strict;
use warnings;
use Config::AutoConf;

unlink 'config.log';

my $ac = Config::AutoConf->new;
$ac->check_cc;
$ac->check_default_headers;
$ac->check_alignof_type('int');
$ac->check_alignof_type( "I32",          { prologue => "#include <EXTERN.h>\n#include <perl.h>" } )

Seems that gcc requires something from it's libraries for that - I would rate it as a bug in gcc, but call it a day and call check_default_headers first ...

plicease commented 9 years ago

Thanks, that helps.