Patch RFC: Fix broken builds with Sun CC

ellie timoney ellie at fastmail.com
Fri Sep 18 01:00:57 EDT 2015


I'm having a look at tools/config2header and it looks like it already
has functionality in it to detect whether or not to use the union casts,
as of the following commit:

> commit 78610a7
> Author:     Rob Siemborski <rjs3 at andrew.cmu.edu>
> AuthorDate: Wed Feb 18 18:44:22 2004 +0000
> Commit:     Rob Siemborski <rjs3 at andrew.cmu.edu>
> CommitDate: Wed Feb 18 18:44:22 2004 +0000
> 
>     remove gnu-c style union casting (Paul Kranenburg <pk at cs.few.eur.nl>)

(and in fact, the second mailing list discussion you referenced has a
reply from Rob mentioning that this is fixed.)

If your $CC evaluates to 'gcc' then it will generate union casts;
otherwise, it will generate (void *) casts.  Watch:

> $rm lib/imapopts.c
> $make CC=gcc lib/imapopts.c
> ./tools/config2header CC="gcc" ./lib/imapopts.c ./lib/imapopts.h < ./lib/imapoptions
> $grep -A3 'IMAPOPT_ADDRESSBOOKPREFIX' lib/imapopts.c
>   { IMAPOPT_ADDRESSBOOKPREFIX, "addressbookprefix", 0, OPT_STRING,
>     (union config_value)((const char *) "#addressbooks"),
>     (union config_value)((const char *) "#addressbooks"),
>     { { NULL, IMAP_ENUM_ZERO } } },

Compare:

> $rm lib/imapopts.c
> $make CC=gcc-5 lib/imapopts.c
> ./tools/config2header CC="gcc-5" ./lib/imapopts.c ./lib/imapopts.h < ./lib/imapoptions
> $grep -A3 'IMAPOPT_ADDRESSBOOKPREFIX' lib/imapopts.c
>   { IMAPOPT_ADDRESSBOOKPREFIX, "addressbookprefix", 0, OPT_STRING,
>     {(void *)("#addressbooks")},
>     {(void *)("#addressbooks")},
>     { { NULL, IMAP_ENUM_ZERO } } },

[Note that in both cases my compiler is gcc version 5.  When it's
called, literally, "gcc", config2header generates the correct gcc-style
casts.  But when it's called anything else (in this case "gcc-5"), it
generates (void *) casts.]

Given that your lib/imapopts.c has got the gcc-style casts in it, this
suggests your CC was set to "gcc" at the time it was generated, and so
it generated it accordingly.

I don't know what the Sun compiler is called, though I'm assuming it
doesn't call itself "gcc".  If it does, there is your problem.

Otherwise, you should be able to do something like this to make sure it
uses the same compiler for the whole build:

> make clean
> ./configure CC=/path/to/sun/compiler [...]
> make

Cheers,

ellie

On Fri, Sep 18, 2015, at 10:13 AM, ellie timoney wrote:
> Hi Jens,
> 
> This is not as simple as just removing the casts from lib/imapopts.c --
> it's a generated file.  Note the comments at the top:
> 
> > /* auto-generated by config2header 1.17 */
> > 
> > /* DO NOT EDIT */
> > 
> > /* THIS FILE AUTOMATICALLY GENERATED BY config2header 1.17 */
> 
> config2header lives in the tools/ subdirectory.  Any patch to fix this
> issue would need to target that, not the file it produces.
> 
> The mailing list discussions you reference talk about this being a
> result of the Sun compiler being strict about "Ansi C", by which I'm
> assuming they mean C89/C90.  We generally target C99 these days (it is,
> after all, 16 years old, and has itself already been superceded by
> C11...).
> 
> I don't know if the Sun compiler has options to support C99, but if it
> does, have you tried using them?
> 
> Cheers,
> 
> ellie
> 
> On Tue, Sep 15, 2015, at 06:56 PM, Jens Erat wrote:
> > Dear Cyrus-maintainers,
> > 
> > building Cyrus IMAP 2.5.6 on Solaris 11 using the Sun CC, I experienced
> > issues with some casts in `lib/imapopts.c`, an excerpt (similar lines
> > occurring hundreds of times):
> > 
> > "lib/imapopts.c", line 32: invalid cast expression
> > "lib/imapopts.c", line 32: non-constant initializer involving a cast
> > "lib/imapopts.c", line 33: invalid cast expression
> > "lib/imapopts.c", line 33: non-constant initializer involving a cast
> > "lib/imapopts.c", line 36: invalid cast expression
> > "lib/imapopts.c", line 36: non-constant initializer involving a cast
> > "lib/imapopts.c", line 37: invalid cast expression
> > "lib/imapopts.c", line 37: non-constant initializer involving a cast
> > "lib/imapopts.c", line 40: invalid cast expression
> > "lib/imapopts.c", line 41: invalid cast expression
> > "lib/imapopts.c", line 44: invalid cast expression
> > "lib/imapopts.c", line 45: invalid cast expression
> > 
> > This seems to have been reported multiple times by now [1] [2]. I
> > applied the proposed fix by Christos Soulios in [1] (removing
> > "GCCisms"), and it works fine for us.
> > 
> > I'm not sure whether this fix is a good or a bad idea, but these casts
> > aren't, either, breaking compatibility with other compilers.
> > 
> > Regards from Lake Constance, Germany,
> > Jens Erat
> > 
> > [1]: http://comments.gmane.org/gmane.mail.imap.cyrus/8927
> > [2]:
> > http://lists.andrew.cmu.edu/pipermail/info-cyrus/2004-April/006894.html
> > 
> > -- 
> > Jens Erat
> > Universität Konstanz
> > Kommunikations-, Infomations-, Medienzentrum (KIM)
> > Abteilung Basisdienste
> > D-78457 Konstanz
> > Mail: jens.erat at uni-konstanz.de
> > 
> > Email had 2 attachments:
> > + cyrus-imapd-2.5.6-patch-casts.patch
> >   96k (text/x-patch)
> > + smime.p7s
> >   7k (application/pkcs7-signature)


More information about the Cyrus-devel mailing list