Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20170611215520.GC1627@brightrain.aerifal.cx>
Date: Sun, 11 Jun 2017 17:55:20 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: redefinition of variable index in musl 1.1.16?

On Sun, Jun 11, 2017 at 06:31:17PM +0000, Pascal Cuoq wrote:
> Hello,
> 
> this message may describe a minor compilation issue on some
> platforms. Let me apologize right here if this is only caused by me
> messing up the defines.
> 
> Consider the file made of these two lines:
> 
> char *index (const char *, int);
> 
> static const unsigned char *index;
> 
> The above is an incorrect C program, as confirmed by GCC and Clang:
> 
> $ clang t.c
> t.c:3:29: error: redefinition of 'index' as different kind of symbol
> ...
> $ gcc t.c
> t.c:3:29: error: 'index' redeclared as different kind of symbol
> ...
> 
> It seems to me that musl's src/time/__tz.c may be an extended
> version of the same two-line program in some circumstances, through
> the following route:
> 
> - __tz.c includes string.h
> 
> - in some circumstances string.h includes strings.h:
> #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
> #include <strings.h>
> #endif
> 
> - strings.h may define a function “index”:
> #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
>  || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
>  || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
> int bcmp (const void *, const void *, size_t);
> void bcopy (const void *, void *, size_t);
> void bzero (void *, size_t);
> char *index (const char *, int);
> char *rindex (const char *, int);
> #endif
> 
> - __tz.c defines a static pointer to const unsigned char index at line 23.
> 
> Again I apologize for the waste of time if this is not something
> that can happen for people who compile musl normally. If it can
> happen, it can be fixed simply by choosing a name other than “index”
> for the variable that is static to __tz.c.

It's not a waste of time; I think it should probably be fixed, if for
no other reason than that the name is confusing. I wonder why we're
not hitting it. I thought _BSD_SOURCE was defined at musl build time,
but it seems it's just _XOPEN_SOURCE, so that probably explains it.

Of course you may hit the same problem in other places with less-bad
names if you define _BSD_SOURCE or worse yet _GNU_SOURCE. :)

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.