This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [GLIBC][PATCH v2] Remove strdup inlines
Mike Frysinger wrote:
> On 13 Dec 2016 09:24, Wilco Dijkstra wrote:
> > Mike Frysinger wrote:
> > > we aren't doing this for many other mem/str funcs. why should we do it
> > > for these two ? we should be all in, or not do any. imo, we should just
> > > omit them and be done unless there is strong/compelling evidence to show
> > > otherwise. if the only point is to support old/uncommon config combos,
> > > then that isn't a great reason imo.
>
> > A similar redirection is done for several other functions, including mempcpy, stpcpy
> > and bzero. The namespace issue only exists for non-C90 functions that are used
> > inside GLIBC, so a small subset of all supported functions.
>
> i think you're conflating those here. if you look closely, it's for C++
> code only, and it's because the signature is different (const-vs-non-const
> return). it's not for the reason you're doing a #define here.
No I'm not talking about the C++ const inlines, I mean redirects to avoid namespace
issues (and to enable GCC to optimize builtins) for non-C90 functions that are used
inside GLIBC. Eg:
#if (!IS_IN (libc) || !defined SHARED) \
&& !defined NO_MEMPCPY_STPCPY_REDIRECT
/* Redirect calls to __builtin_mempcpy and __builtin_stpcpy to call
__mempcpy and __stpcpy if not inlined. */
extern __typeof (mempcpy) mempcpy __asm__ ("__mempcpy");
extern __typeof (stpcpy) stpcpy __asm__ ("__stpcpy");
#endif
# ifndef _ISOMAC
# ifndef index
# define index(s, c) (strchr ((s), (c)))
# endif
# ifndef rindex
# define rindex(s, c) (strrchr ((s), (c)))
# endif
# endif
# ifdef __USE_MISC
# define strsep(s, reject) __strsep (s, reject)
# endif
# if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
# define strdup(s) __strdup (s)
# endif
# ifdef __USE_XOPEN2K8
# define strndup(s, n) __strndup (s, n)
# endif
Removing these causes linknamespace failures.
The question is what is the best approach - copy the magic for mempcpy/stpcpy (which
means you avoid having to do a whole-GLIBC rename and still get compiler builtin
optimization), use a define that redirects to a builtin (if it exists) or GLIBC internal name?
Note there are also plenty of calls to functions with underscores, eg. __stpcpy,
__mempcpy, __bzero, so we ideally need to either rename these to use the base name
or redirect to the builtin.
Wilco