mailing list of musl libc
 help / color / mirror / code / Atom feed
* redefinition of variable index in musl 1.1.16?
@ 2017-06-11 18:31 Pascal Cuoq
  2017-06-11 21:55 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Pascal Cuoq @ 2017-06-11 18:31 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1628 bytes --]

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.

Pascal

[-- Attachment #2: Type: text/html, Size: 5525 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: redefinition of variable index in musl 1.1.16?
  2017-06-11 18:31 redefinition of variable index in musl 1.1.16? Pascal Cuoq
@ 2017-06-11 21:55 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2017-06-11 21:55 UTC (permalink / raw)
  To: musl

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-11 21:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-11 18:31 redefinition of variable index in musl 1.1.16? Pascal Cuoq
2017-06-11 21:55 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).