develooper Front page | perl.perl5.porters | Postings from August 2010

Re: Compiling with clang

Thread Previous | Thread Next
Ævar Arnfjörð Bjarmason
August 9, 2010 06:55
Re: Compiling with clang
Message ID:
On Thu, May 6, 2010 at 16:10,  <> wrote:
> I tried compiling bleadperl with clang (<>), which
> has nicely picky, verbose error messages.
> I fetch clang direct from svn. clang --version initially gave
> 'clang version 2.0 (trunk 102861)', and later (after (5) below) as
> 'clang version 2.0 (trunk 103176)'. gccversion comes out as
> 'GNU cc 4.2.1 Compatible Clang Compiler'.

Here's an update 3 months later on building perl with clang from SVN:

    $ /home/avar/src/llvm/Release+Asserts/bin/clang --version
    clang version 2.8 (trunk 110571)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix

> I configured perl with "./Configure -de -Dcc=/opt/clang-latest/bin/clang
> -Dprefix=/opt/blead-clang -Doptimize='-g -O3' -Dusedevel -Uversiononly"
> and built with 'make all'.

I used:

    ./Configure -Dusethreads
-Dprefix=~/perl5/installed -Dusedevel -des

> 1. clang does support the flag '-fstack-protector', but the resulting
> object doesn't compile: see <>.
> I hacked Configure to avoid specifying this flag. I assume this will be
> fixed in clang soon enough, so I haven't tried to make a corable patch.

That bug has now been fixed upstream, no configure hacking is needed

> 2. The build fails early complaining about the use of HEK_KEY() within
> macros such as GvNAME(), which provides a char[1] where char * is
> expected:
>  gv.c:685:7: error: passing 'char [1]' to parameter of incompatible type 'char const *'

This issue and the bug cited by Dominic
( seem solved. I can compile
perl with -DDEBUGGING and -DDEBUGGING=both and gv.c raises no error or
warning on compilation.

> This seems like a reasonable complaint, and I believe that we always intend
> to get a char * whenever we call HEK_KEY(). The patch to hv.h below avoids
> that; this is the only fatal error caused by perl source when compiling.
> 3. The warnings in core fall into a small number of classes. I'm not sure how
> far we want to go to shut these up:
> 3a. expression result unused (118 times)
> 35 SvUPGRADE(); 44 SvGROW(); 16 SvPV_force_*() variants; 6 CHECKOP();
> 4 SvNV(); 4 SvIV(); 2 my_snprintf(); 2 SvREFCNT_inc(); 2 LINKLIST();
> 2 GvAVn(); 1 ReREFCNT_inc().
> While I think there is some value to be gained to be clean of this warning,
> I do not think it outweighs the maintenance cost of getting and staying
> clean. I suggest rather that we specify '-Wno-unused-value' by default when
> the compiler is clang.

I don't see why. Compiler warnings don't mean something is wrong,
they're just something to keep in mind.

But yeah, if we're not interested in sprinkling (void)func(..)
everywhere we might want to shut it up.

> I include a patch to cflags.SH to achieve that for core; I hope some more
> shell- and portability-aware porter will cast an eye over that. I'm not
> sure how to fix this for extensions.

Aside from maybe applying the -Wno-unused-value patch this seems to be
not needed anymore.

> 5. The crashing code (see <>)
> resolves to:
>  #define _FILE_OFFSET_BITS 64
>  #define _GNU_SOURCE
>  #include <sys/stat.h>

Fixed upstream.

> This allowed a complete build, and:
>  All tests successful.
>  u=6.99  s=1.40  cu=643.38  cs=50.41  scripts=1701  tests=349409

Same here, both with and without -DDEBUGGING=both, here's the
test/perl output from the latter:

    All tests successful.
    Files=1838, Tests=384757, 347 wallclock secs (91.31 usr 53.56 sys
+ 588.81 cusr 125.80 csys = 859.48 CPU)
    Result: PASS

    $ ./perl -Ilib -V
    Summary of my perl5 (revision 5 version 13 subversion 3) configuration:
      Commit id: 45f6403b40da58011eab17ad0159b353c7d92509
        osname=linux, osvers=2.6.35-rc5-avar-akbar+,
        uname='linux v 2.6.35-rc5-avar-akbar+ #5 smp wed jul 14
20:07:18 utc 2010 x86_64 gnulinux '
-Dprefix=~/perl5/installed -Dusedevel -DDEBUGGING=both -des'
        hint=recommended, useposix=true, d_sigaction=define
        useithreads=define, usemultiplicity=define
        useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
        use64bitint=define, use64bitall=define, uselongdouble=undef
        usemymalloc=n, bincompat5005=undef
        cc='/home/avar/src/llvm/Release+Asserts/bin/clang', ccflags
='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE
        optimize='-O2 -g',
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
        ccversion='', gccversion='4.2.1 Compatible Clang Compiler',
        intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
        d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
        ivtype='long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8
        alignbytes=8, prototype=define
      Linker and Libraries:
        ld='/home/avar/src/llvm/Release+Asserts/bin/clang', ldflags ='
-fstack-protector -L/usr/local/lib'
        libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
        libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
        perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
        libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
      Dynamic Linking:
        dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
        cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib

    Characteristics of this binary (from libperl):
                            PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
                            PERL_TRACK_MEMPOOL PERL_USE_DEVEL USE_64_BIT_ALL
                            USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
                            USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API
      Built under linux
      Compiled at Aug  9 2010 13:42:46

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About