* [PATCH] Rename strdup uses
@ 2017-01-11 16:02 Wilco Dijkstra
2017-01-11 17:26 ` Joseph Myers
2017-02-09 15:17 ` Wilco Dijkstra
0 siblings, 2 replies; 12+ messages in thread
From: Wilco Dijkstra @ 2017-01-11 16:02 UTC (permalink / raw)
To: libc-alpha; +Cc: nd
Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be
redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt
or linkname space failures. Although this means a loss of inlining (based on current
committed headers) in 2 cases, these are both error messages so not performance
critical.
ChangeLog:
2017-01-11 Wilco Dijkstra <wdijkstr@arm.com>
* elf/dl-cache.c (_dl_load_cache_lookup): Use __strdup.
* inet/rcmd.c (rcmd_af): Likewise.
* inet/rexec.c (rexec_af): Likewise.
* intl/dcigettext.c (_LIBC): Likewise.
* intl/finddomain.c (_nl_find_domain): Use strdup expansion.
* locale/loadarchive.c (_nl_load_locale_from_archive):
Use __strdup.
* locale/setlocale.c (setlocale): Likewise.
* posix/spawn_faction_addopen.c
(posix_spawn_file_actions_addopen): Likewise.
* stdlib/putenv.c (putenv): Use __strndup.
* sunrpc/svc_simple.c (__registerrpc): Use __strdup.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Use __strdup/__strndup.
--
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index cfa335eb326cd04f3892a09d4c00cef8208a2f33..4c8afd0684b96b44ec069f907b9537d4fc2ff6d2 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -302,7 +302,7 @@ _dl_load_cache_lookup (const char *name)
char *temp;
temp = alloca (strlen (best) + 1);
strcpy (temp, best);
- return strdup (temp);
+ return __strdup (temp);
}
#ifndef MAP_COPY
diff --git a/inet/rcmd.c b/inet/rcmd.c
index 8613d96764b08cc8fe3d988a0f38125a0cd54d04..b7cc7a82ba0ac1b39ccf03c589e00114b0bc79a5 100644
--- a/inet/rcmd.c
+++ b/inet/rcmd.c
@@ -149,7 +149,7 @@ rcmd_af (char **ahost, u_short rport, const char *locuser, const char *remuser,
if (res->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res->ai_canonname);
+ ahostbuf = __strdup (res->ai_canonname);
if (ahostbuf == NULL) {
__fxprintf(NULL, "%s",
_("rcmd: Cannot allocate memory\n"));
diff --git a/inet/rexec.c b/inet/rexec.c
index 24ac4b11b6d745aa53a80bd0f7bd10924246b526..43fb67bcf2c6d4fdff9e8dcd053786ab523f7aa1 100644
--- a/inet/rexec.c
+++ b/inet/rexec.c
@@ -73,7 +73,7 @@ rexec_af (char **ahost, int rport, const char *name, const char *pass,
if (res0->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res0->ai_canonname);
+ ahostbuf = __strdup (res0->ai_canonname);
if (ahostbuf == NULL) {
perror ("rexec: strdup");
return (-1);
diff --git a/intl/dcigettext.c b/intl/dcigettext.c
index dd0db4e6b299d1339a1224c99367525c9e7c00d3..39699fe05e58d2405be0a5ac3fd9b57983608be3 100644
--- a/intl/dcigettext.c
+++ b/intl/dcigettext.c
@@ -131,6 +131,7 @@ extern int errno;
/* Rename the non ANSI C functions. This is required by the standard
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
+# define strdup __strdup
# define getcwd __getcwd
# ifndef stpcpy
# define stpcpy __stpcpy
diff --git a/intl/finddomain.c b/intl/finddomain.c
index 2c3348ab54ff5f1d888bfa333cea0de3f4848252..e6d816120a90776ce2d5f2bb646e8ff582e4bb5a 100644
--- a/intl/finddomain.c
+++ b/intl/finddomain.c
@@ -124,18 +124,12 @@ _nl_find_domain (const char *dirname, char *locale,
alias_value = _nl_expand_alias (locale);
if (alias_value != NULL)
{
-#if defined _LIBC || defined HAVE_STRDUP
- locale = strdup (alias_value);
- if (locale == NULL)
- return NULL;
-#else
size_t len = strlen (alias_value) + 1;
locale = (char *) malloc (len);
if (locale == NULL)
return NULL;
memcpy (locale, alias_value, len);
-#endif
}
/* Now we determine the single parts of the locale name. First
diff --git a/locale/loadarchive.c b/locale/loadarchive.c
index 0ac11afa4ad6fa1e1037b3803a1aeabf43da63c4..6c785c9dc0326a6443852f1f38b3fca790057fa2 100644
--- a/locale/loadarchive.c
+++ b/locale/loadarchive.c
@@ -462,7 +462,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
if (__glibc_unlikely (lia == NULL))
return NULL;
- lia->name = strdup (*namep);
+ lia->name = __strdup (*namep);
if (__glibc_unlikely (lia->name == NULL))
{
free (lia);
diff --git a/locale/setlocale.c b/locale/setlocale.c
index 69b314134bc6213fe92247af012fb4a07ac59a90..1c0c7fc5be41532abf22f98c89180d91b179f536 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -283,7 +283,7 @@ setlocale (int category, const char *locale)
if (__glibc_unlikely (strchr (locale, ';') != NULL))
{
/* This is a composite name. Make a copy and split it up. */
- locale_copy = strdup (locale);
+ locale_copy = __strdup (locale);
if (__glibc_unlikely (locale_copy == NULL))
{
__libc_rwlock_unlock (__libc_setlocale_lock);
diff --git a/posix/spawn_faction_addopen.c b/posix/spawn_faction_addopen.c
index 4f37d0b8478c3c883150534922550aa13cfcac8e..6f8d3497d6333a0c04a6647154f334a93a55568e 100644
--- a/posix/spawn_faction_addopen.c
+++ b/posix/spawn_faction_addopen.c
@@ -34,7 +34,7 @@ posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
if (!__spawn_valid_fd (fd))
return EBADF;
- char *path_copy = strdup (path);
+ char *path_copy = __strdup (path);
if (path_copy == NULL)
return ENOMEM;
diff --git a/stdlib/putenv.c b/stdlib/putenv.c
index 71b9ab1d8c40e7505868c7d0bada186d96f71ae5..c7a0a442b9d871fd442b58a144e3c49c35f5e0d8 100644
--- a/stdlib/putenv.c
+++ b/stdlib/putenv.c
@@ -60,7 +60,7 @@ putenv (char *string)
int use_malloc = !__libc_use_alloca (name_end - string + 1);
if (__builtin_expect (use_malloc, 0))
{
- name = strndup (string, name_end - string);
+ name = __strndup (string, name_end - string);
if (name == NULL)
return -1;
}
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index baa177eec0f1fea3306e056033be29cee42fe132..acc9b9db14fa24b4b04e4ddca7d10980e661fe88 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -87,7 +87,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
transp = svcudp_create (RPC_ANYSOCK);
if (transp == NULL)
{
- buf = strdup (_("couldn't create an rpc server\n"));
+ buf = __strdup (_("couldn't create an rpc server\n"));
goto err_out;
}
}
@@ -103,7 +103,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
pl = (struct proglst_ *) malloc (sizeof (struct proglst_));
if (pl == NULL)
{
- buf = strdup (_("registerrpc: out of memory\n"));
+ buf = __strdup (_("registerrpc: out of memory\n"));
goto err_out;
}
pl->p_progname = progname;
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 740e9555d5c836c02a329b39540fb367ee8f8a4e..24d6d471710f5db3670b94056c5a0150c4742a47 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -536,7 +536,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
else
{
- namebuf = strndup (name, scope_delim - name);
+ namebuf = __strndup (name, scope_delim - name);
if (namebuf == NULL)
{
assert (!malloc_name);
@@ -1139,7 +1139,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
malloc_canonbuf = false;
else
{
- canon = strdup (canon);
+ canon = __strdup (canon);
if (canon == NULL)
{
result = -EAI_MEMORY;
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-01-11 16:02 [PATCH] Rename strdup uses Wilco Dijkstra
@ 2017-01-11 17:26 ` Joseph Myers
2017-01-12 15:16 ` Wilco Dijkstra
2017-02-09 15:17 ` Wilco Dijkstra
1 sibling, 1 reply; 12+ messages in thread
From: Joseph Myers @ 2017-01-11 17:26 UTC (permalink / raw)
To: Wilco Dijkstra; +Cc: libc-alpha, nd
On Wed, 11 Jan 2017, Wilco Dijkstra wrote:
> Rename existing uses of str(n)dup to __str(n)dup so it no longer needs
> to be redirected to a builtin. Also building GLIBC with -Os now no
> longer shows localplt or linkname space failures. Although this means a
If this fixes such failures then [BZ #15105] and [BZ #19463] should be
included in the ChangeLog entry (if it fixes *all* such failures, then
additionally the bugs would be resolved as FIXED with milestone set once
this is in).
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-01-11 17:26 ` Joseph Myers
@ 2017-01-12 15:16 ` Wilco Dijkstra
2017-01-12 15:48 ` Joseph Myers
0 siblings, 1 reply; 12+ messages in thread
From: Wilco Dijkstra @ 2017-01-12 15:16 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha, nd
Joseph Myers wrote:
> On Wed, 11 Jan 2017, Wilco Dijkstra wrote:
>
> > Rename existing uses of str(n)dup to __str(n)dup so it no longer needs
> > to be redirected to a builtin. Also building GLIBC with -Os now no
> > longer shows localplt or linkname space failures. Although this means a
>
> If this fixes such failures then [BZ #15105] and [BZ #19463] should be
> included in the ChangeLog entry (if it fixes *all* such failures, then
> additionally the bugs would be resolved as FIXED with milestone set once
> this is in).
Yes it fixes a few of those failures, but there are plenty left. I think most are due
to disabling inlines with -Os (rather than using __extern_always_inline).
The question is it worth trying to fix these too?
Wilco
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-01-12 15:16 ` Wilco Dijkstra
@ 2017-01-12 15:48 ` Joseph Myers
0 siblings, 0 replies; 12+ messages in thread
From: Joseph Myers @ 2017-01-12 15:48 UTC (permalink / raw)
To: Wilco Dijkstra; +Cc: libc-alpha, nd
[-- Attachment #1: Type: text/plain, Size: 1138 bytes --]
On Thu, 12 Jan 2017, Wilco Dijkstra wrote:
> Joseph Myers wrote:
> > On Wed, 11 Jan 2017, Wilco Dijkstra wrote:
> >
> > > Rename existing uses of str(n)dup to __str(n)dup so it no longer needs
> > > to be redirected to a builtin. Also building GLIBC with -Os now no
> > > longer shows localplt or linkname space failures. Although this means a
> >
> > If this fixes such failures then [BZ #15105] and [BZ #19463] should be
> > included in the ChangeLog entry (if it fixes *all* such failures, then
> > additionally the bugs would be resolved as FIXED with milestone set once
> > this is in).
>
> Yes it fixes a few of those failures, but there are plenty left. I think most are due
> to disabling inlines with -Os (rather than using __extern_always_inline).
> The question is it worth trying to fix these too?
Yes, they should be fixed. The appropriate fix would need to be
considered case by case - whether it's making the functions always inline,
or always inline when building glibc, or arranging for hidden_proto /
hidden_def to be used for the non-inlined function calls.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-01-11 16:02 [PATCH] Rename strdup uses Wilco Dijkstra
2017-01-11 17:26 ` Joseph Myers
@ 2017-02-09 15:17 ` Wilco Dijkstra
2017-02-09 21:44 ` Adhemerval Zanella
1 sibling, 1 reply; 12+ messages in thread
From: Wilco Dijkstra @ 2017-02-09 15:17 UTC (permalink / raw)
To: libc-alpha; +Cc: nd
ping (added mention of BZ tickets)
From: Wilco Dijkstra
Sent: 11 January 2017 16:02
To: libc-alpha@sourceware.org
Cc: nd
Subject: [PATCH] Rename strdup uses
Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be
redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt
or linkname space failures (partial fix for BZ #15105 and BZ #19463). Although this
means a loss of inlining (based on current committed headers) in 2 cases, these
are both error messages so not performance critical.
ChangeLog:
2017-01-11 Wilco Dijkstra <wdijkstr@arm.com>
[BZ #15105]
[BZ #19463]
* elf/dl-cache.c (_dl_load_cache_lookup): Use __strdup.
* inet/rcmd.c (rcmd_af): Likewise.
* inet/rexec.c (rexec_af): Likewise.
* intl/dcigettext.c (_LIBC): Likewise.
* intl/finddomain.c (_nl_find_domain): Use strdup expansion.
* locale/loadarchive.c (_nl_load_locale_from_archive):
Use __strdup.
* locale/setlocale.c (setlocale): Likewise.
* posix/spawn_faction_addopen.c
(posix_spawn_file_actions_addopen): Likewise.
* stdlib/putenv.c (putenv): Use __strndup.
* sunrpc/svc_simple.c (__registerrpc): Use __strdup.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Use __strdup/__strndup.
--
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index cfa335eb326cd04f3892a09d4c00cef8208a2f33..4c8afd0684b96b44ec069f907b9537d4fc2ff6d2 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -302,7 +302,7 @@ _dl_load_cache_lookup (const char *name)
char *temp;
temp = alloca (strlen (best) + 1);
strcpy (temp, best);
- return strdup (temp);
+ return __strdup (temp);
}
#ifndef MAP_COPY
diff --git a/inet/rcmd.c b/inet/rcmd.c
index 8613d96764b08cc8fe3d988a0f38125a0cd54d04..b7cc7a82ba0ac1b39ccf03c589e00114b0bc79a5 100644
--- a/inet/rcmd.c
+++ b/inet/rcmd.c
@@ -149,7 +149,7 @@ rcmd_af (char **ahost, u_short rport, const char *locuser, const char *remuser,
if (res->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res->ai_canonname);
+ ahostbuf = __strdup (res->ai_canonname);
if (ahostbuf == NULL) {
__fxprintf(NULL, "%s",
_("rcmd: Cannot allocate memory\n"));
diff --git a/inet/rexec.c b/inet/rexec.c
index 24ac4b11b6d745aa53a80bd0f7bd10924246b526..43fb67bcf2c6d4fdff9e8dcd053786ab523f7aa1 100644
--- a/inet/rexec.c
+++ b/inet/rexec.c
@@ -73,7 +73,7 @@ rexec_af (char **ahost, int rport, const char *name, const char *pass,
if (res0->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res0->ai_canonname);
+ ahostbuf = __strdup (res0->ai_canonname);
if (ahostbuf == NULL) {
perror ("rexec: strdup");
return (-1);
diff --git a/intl/dcigettext.c b/intl/dcigettext.c
index dd0db4e6b299d1339a1224c99367525c9e7c00d3..39699fe05e58d2405be0a5ac3fd9b57983608be3 100644
--- a/intl/dcigettext.c
+++ b/intl/dcigettext.c
@@ -131,6 +131,7 @@ extern int errno;
/* Rename the non ANSI C functions. This is required by the standard
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
+# define strdup __strdup
# define getcwd __getcwd
# ifndef stpcpy
# define stpcpy __stpcpy
diff --git a/intl/finddomain.c b/intl/finddomain.c
index 2c3348ab54ff5f1d888bfa333cea0de3f4848252..e6d816120a90776ce2d5f2bb646e8ff582e4bb5a 100644
--- a/intl/finddomain.c
+++ b/intl/finddomain.c
@@ -124,18 +124,12 @@ _nl_find_domain (const char *dirname, char *locale,
alias_value = _nl_expand_alias (locale);
if (alias_value != NULL)
{
-#if defined _LIBC || defined HAVE_STRDUP
- locale = strdup (alias_value);
- if (locale == NULL)
- return NULL;
-#else
size_t len = strlen (alias_value) + 1;
locale = (char *) malloc (len);
if (locale == NULL)
return NULL;
memcpy (locale, alias_value, len);
-#endif
}
/* Now we determine the single parts of the locale name. First
diff --git a/locale/loadarchive.c b/locale/loadarchive.c
index 0ac11afa4ad6fa1e1037b3803a1aeabf43da63c4..6c785c9dc0326a6443852f1f38b3fca790057fa2 100644
--- a/locale/loadarchive.c
+++ b/locale/loadarchive.c
@@ -462,7 +462,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
if (__glibc_unlikely (lia == NULL))
return NULL;
- lia->name = strdup (*namep);
+ lia->name = __strdup (*namep);
if (__glibc_unlikely (lia->name == NULL))
{
free (lia);
diff --git a/locale/setlocale.c b/locale/setlocale.c
index 69b314134bc6213fe92247af012fb4a07ac59a90..1c0c7fc5be41532abf22f98c89180d91b179f536 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -283,7 +283,7 @@ setlocale (int category, const char *locale)
if (__glibc_unlikely (strchr (locale, ';') != NULL))
{
/* This is a composite name. Make a copy and split it up. */
- locale_copy = strdup (locale);
+ locale_copy = __strdup (locale);
if (__glibc_unlikely (locale_copy == NULL))
{
__libc_rwlock_unlock (__libc_setlocale_lock);
diff --git a/posix/spawn_faction_addopen.c b/posix/spawn_faction_addopen.c
index 4f37d0b8478c3c883150534922550aa13cfcac8e..6f8d3497d6333a0c04a6647154f334a93a55568e 100644
--- a/posix/spawn_faction_addopen.c
+++ b/posix/spawn_faction_addopen.c
@@ -34,7 +34,7 @@ posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
if (!__spawn_valid_fd (fd))
return EBADF;
- char *path_copy = strdup (path);
+ char *path_copy = __strdup (path);
if (path_copy == NULL)
return ENOMEM;
diff --git a/stdlib/putenv.c b/stdlib/putenv.c
index 71b9ab1d8c40e7505868c7d0bada186d96f71ae5..c7a0a442b9d871fd442b58a144e3c49c35f5e0d8 100644
--- a/stdlib/putenv.c
+++ b/stdlib/putenv.c
@@ -60,7 +60,7 @@ putenv (char *string)
int use_malloc = !__libc_use_alloca (name_end - string + 1);
if (__builtin_expect (use_malloc, 0))
{
- name = strndup (string, name_end - string);
+ name = __strndup (string, name_end - string);
if (name == NULL)
return -1;
}
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index baa177eec0f1fea3306e056033be29cee42fe132..acc9b9db14fa24b4b04e4ddca7d10980e661fe88 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -87,7 +87,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
transp = svcudp_create (RPC_ANYSOCK);
if (transp == NULL)
{
- buf = strdup (_("couldn't create an rpc server\n"));
+ buf = __strdup (_("couldn't create an rpc server\n"));
goto err_out;
}
}
@@ -103,7 +103,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
pl = (struct proglst_ *) malloc (sizeof (struct proglst_));
if (pl == NULL)
{
- buf = strdup (_("registerrpc: out of memory\n"));
+ buf = __strdup (_("registerrpc: out of memory\n"));
goto err_out;
}
pl->p_progname = progname;
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 740e9555d5c836c02a329b39540fb367ee8f8a4e..24d6d471710f5db3670b94056c5a0150c4742a47 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -536,7 +536,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
else
{
- namebuf = strndup (name, scope_delim - name);
+ namebuf = __strndup (name, scope_delim - name);
if (namebuf == NULL)
{
assert (!malloc_name);
@@ -1139,7 +1139,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
malloc_canonbuf = false;
else
{
- canon = strdup (canon);
+ canon = __strdup (canon);
if (canon == NULL)
{
result = -EAI_MEMORY;
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-02-09 15:17 ` Wilco Dijkstra
@ 2017-02-09 21:44 ` Adhemerval Zanella
0 siblings, 0 replies; 12+ messages in thread
From: Adhemerval Zanella @ 2017-02-09 21:44 UTC (permalink / raw)
To: libc-alpha
On 09/02/2017 13:17, Wilco Dijkstra wrote:
> ping (added mention of BZ tickets)
>
>
> From: Wilco Dijkstra
> Sent: 11 January 2017 16:02
> To: libc-alpha@sourceware.org
> Cc: nd
> Subject: [PATCH] Rename strdup uses
>
> Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be
> redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt
> or linkname space failures (partial fix for BZ #15105 and BZ #19463). Although this
> means a loss of inlining (based on current committed headers) in 2 cases, these
> are both error messages so not performance critical.
I would prefer to just clump both this patch and the one that removes strdup
inlines [1] together and then just remove the strdup and strndup macros
on string/string.h. Also, it seems that this patch is not really complete,
since by removing the defines on string.h I see the missing spot that
triggers PLT failures:
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index 1ac7524..017c78a 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -302,7 +302,7 @@ _dl_load_cache_lookup (const char *name)
char *temp;
temp = alloca (strlen (best) + 1);
strcpy (temp, best);
- return strdup (temp);
+ return __strdup (temp);
}
#ifndef MAP_COPY
With this change we can just remove the str{n}dup macros on string.h and
simplify this a lot.
[1] https://sourceware.org/ml/libc-alpha/2017-02/msg00187.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-03-07 15:30 ` Wilco Dijkstra
@ 2017-03-13 12:45 ` Adhemerval Zanella
0 siblings, 0 replies; 12+ messages in thread
From: Adhemerval Zanella @ 2017-03-13 12:45 UTC (permalink / raw)
To: Wilco Dijkstra; +Cc: libc-alpha, nd
LGTM, thanks.
On 07/03/2017 12:30, Wilco Dijkstra wrote:
>
>
> ping
>
>
>
> From: Wilco Dijkstra
> Sent: 10 February 2017 18:40
> To: Adhemerval Zanella
> Cc: libc-alpha@sourceware.org; nd
> Subject: Re: [PATCH] Rename strdup uses
>
> Adhemerval Zanella wrote:
>>
>> Ah right, although imho for such coupled patchset splitting is more confusing
>> than a single one.
>
> Well if it helps I can easily list them together (rebased to latest sources and the
> XOPEN defines now removed):
>
>
> Remove the str(n)dup inlines from string/bits/string2.h. Although inlining
> calls with constant strings shows a small (~10%) performance gain, strdup is
> typically used in error reporting code, so not performance critical.
> Remove the now unused __need_malloc_and_calloc related defines from stdlib.h.
>
> Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be
> redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt
> or linkname space failures (partial fix for BZ #15105 and BZ #19463).
>
> ChangeLog:
> 2017-02-10 Wilco Dijkstra <wdijkstr@arm.com>
>
> [BZ #15105]
> [BZ #19463]
> * elf/dl-cache.c (_dl_load_cache_lookup): Use __strdup.
> * inet/rcmd.c (rcmd_af): Likewise.
> * inet/rexec.c (rexec_af): Likewise.
> * intl/dcigettext.c (_LIBC): Likewise.
> * intl/finddomain.c (_nl_find_domain): Use strdup expansion.
> * locale/loadarchive.c (_nl_load_locale_from_archive):
> Use __strdup.
> * locale/setlocale.c (setlocale): Likewise.
> * posix/spawn_faction_addopen.c
> (posix_spawn_file_actions_addopen): Likewise.
> * stdlib/putenv.c (putenv): Use __strndup.
> * sunrpc/svc_simple.c (__registerrpc): Use __strdup.
> * sysdeps/posix/getaddrinfo.c (gaih_inet): Use __strdup/__strndup.
> * include/stdlib.h (__need_malloc_and_calloc): Remove uses.
> (__Need_M_And_C) Remove define/undef.
> * stdlib/stdlib.h (__need_malloc_and_calloc): Remove uses.
> (__malloc_and_calloc_defined): Remove define.
> * string/bits/string2.h (__strdup): Remove define.
> (strdup): Likewise.
> (__strndup): Likewise.
> (strndup): Likewise.
>
> ---
>
> diff --git a/include/stdlib.h b/include/stdlib.h
> index 352339e8595eb8229018cb27f7d2decf63f511c7..929cead59ae10afe03ae1286b72d8321f0ab2d90 100644
> --- a/include/stdlib.h
> +++ b/include/stdlib.h
> @@ -1,16 +1,12 @@
> #ifndef _STDLIB_H
>
> -#ifdef __need_malloc_and_calloc
> -#define __Need_M_And_C
> -#endif
> -
> #ifndef _ISOMAC
> # include <stddef.h>
> #endif
> #include <stdlib/stdlib.h>
>
> /* Now define the internal interfaces. */
> -#if !defined __Need_M_And_C && !defined _ISOMAC
> +#if !defined _ISOMAC
> # include <sys/stat.h>
>
> __BEGIN_DECLS
> @@ -269,6 +265,4 @@ __END_DECLS
>
> #endif
>
> -#undef __Need_M_And_C
> -
> #endif /* include/stdlib.h */
> diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
> index 292c6a2f053a2a578cd09d75307c26ed191e1c00..7cfbcafe79ec1f7c9d07c464bd56b9bd964755fd 100644
> --- a/stdlib/stdlib.h
> +++ b/stdlib/stdlib.h
> @@ -25,16 +25,13 @@
> #include <bits/libc-header-start.h>
>
> /* Get size_t, wchar_t and NULL from <stddef.h>. */
> -#define __need_size_t
> -#ifndef __need_malloc_and_calloc
> -# define __need_wchar_t
> -# define __need_NULL
> -#endif
> +#define __need_size_t
> +#define __need_wchar_t
> +#define __need_NULL
> #include <stddef.h>
>
> __BEGIN_DECLS
>
> -#ifndef __need_malloc_and_calloc
> #define _STDLIB_H 1
>
> #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
> @@ -434,10 +431,6 @@ extern int lcong48_r (unsigned short int __param[7],
> # endif /* Use misc. */
> #endif /* Use misc or X/Open. */
>
> -#endif /* don't just need malloc and calloc */
> -
> -#ifndef __malloc_and_calloc_defined
> -# define __malloc_and_calloc_defined
> __BEGIN_NAMESPACE_STD
> /* Allocate SIZE bytes of memory. */
> extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
> @@ -445,9 +438,7 @@ extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
> extern void *calloc (size_t __nmemb, size_t __size)
> __THROW __attribute_malloc__ __wur;
> __END_NAMESPACE_STD
> -#endif
>
> -#ifndef __need_malloc_and_calloc
> __BEGIN_NAMESPACE_STD
> /* Re-allocate the previously allocated block
> in PTR, making the new block SIZE bytes long. */
> @@ -944,9 +935,6 @@ extern int ttyslot (void) __THROW;
> # include <bits/stdlib-ldbl.h>
> #endif
>
> -#endif /* don't just need malloc and calloc */
> -#undef __need_malloc_and_calloc
> -
> __END_DECLS
>
> #endif /* stdlib.h */
> diff --git a/string/bits/string2.h b/string/bits/string2.h
> index e5337becf6fd21a7f303f4e9e8152f8571ec96b1..5d2bd0c8e2f39df6c7a407253e5995d9bb0f6cdb 100644
> --- a/string/bits/string2.h
> +++ b/string/bits/string2.h
> @@ -180,65 +180,6 @@ extern void *__rawmemchr (const void *__s, int __c);
> #endif
>
>
> -/* We need the memory allocation functions for inline strdup().
> - Referring to stdlib.h (even minimally) is not allowed
> - in any of the tight standards compliant modes. */
> -#ifdef __USE_MISC
> -
> -# if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
> -# define __need_malloc_and_calloc
> -# include <stdlib.h>
> -# endif
> -
> -# ifndef _HAVE_STRING_ARCH_strdup
> -
> -extern char *__strdup (const char *__string) __THROW __attribute_malloc__;
> -# define __strdup(s) \
> - (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
> - ? (((const char *) (s))[0] == '\0' \
> - ? (char *) calloc ((size_t) 1, (size_t) 1) \
> - : ({ size_t __len = strlen (s) + 1; \
> - char *__retval = (char *) malloc (__len); \
> - if (__retval != NULL) \
> - __retval = (char *) memcpy (__retval, s, __len); \
> - __retval; })) \
> - : __strdup (s)))
> -
> -# if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
> -# define strdup(s) __strdup (s)
> -# endif
> -# endif
> -
> -# ifndef _HAVE_STRING_ARCH_strndup
> -
> -extern char *__strndup (const char *__string, size_t __n)
> - __THROW __attribute_malloc__;
> -# define __strndup(s, n) \
> - (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
> - ? (((const char *) (s))[0] == '\0' \
> - ? (char *) calloc ((size_t) 1, (size_t) 1) \
> - : ({ size_t __len = strlen (s) + 1; \
> - size_t __n = (n); \
> - char *__retval; \
> - if (__n < __len) \
> - __len = __n + 1; \
> - __retval = (char *) malloc (__len); \
> - if (__retval != NULL) \
> - { \
> - __retval[__len - 1] = '\0'; \
> - __retval = (char *) memcpy (__retval, s, \
> - __len - 1); \
> - } \
> - __retval; })) \
> - : __strndup (s, n)))
> -
> -# ifdef __USE_XOPEN2K8
> -# define strndup(s, n) __strndup (s, n)
> -# endif
> -# endif
> -
> -#endif /* Use misc. or use GNU. */
> -
> #ifndef _FORCE_INLINES
> # undef __STRING_INLINE
> #endif
> diff --git a/elf/dl-cache.c b/elf/dl-cache.c
> index 1ac7524c3e8cc41eee0e4f20158b67f97a0f60bc..017c78aae36cd981f31b955966bb77c9b793567a 100644
> --- a/elf/dl-cache.c
> +++ b/elf/dl-cache.c
> @@ -302,7 +302,7 @@ _dl_load_cache_lookup (const char *name)
> char *temp;
> temp = alloca (strlen (best) + 1);
> strcpy (temp, best);
> - return strdup (temp);
> + return __strdup (temp);
> }
>
> #ifndef MAP_COPY
> diff --git a/inet/rcmd.c b/inet/rcmd.c
> index 8613d96764b08cc8fe3d988a0f38125a0cd54d04..b7cc7a82ba0ac1b39ccf03c589e00114b0bc79a5 100644
> --- a/inet/rcmd.c
> +++ b/inet/rcmd.c
> @@ -149,7 +149,7 @@ rcmd_af (char **ahost, u_short rport, const char *locuser, const char *remuser,
>
> if (res->ai_canonname){
> free (ahostbuf);
> - ahostbuf = strdup (res->ai_canonname);
> + ahostbuf = __strdup (res->ai_canonname);
> if (ahostbuf == NULL) {
> __fxprintf(NULL, "%s",
> _("rcmd: Cannot allocate memory\n"));
> diff --git a/inet/rexec.c b/inet/rexec.c
> index 24ac4b11b6d745aa53a80bd0f7bd10924246b526..43fb67bcf2c6d4fdff9e8dcd053786ab523f7aa1 100644
> --- a/inet/rexec.c
> +++ b/inet/rexec.c
> @@ -73,7 +73,7 @@ rexec_af (char **ahost, int rport, const char *name, const char *pass,
>
> if (res0->ai_canonname){
> free (ahostbuf);
> - ahostbuf = strdup (res0->ai_canonname);
> + ahostbuf = __strdup (res0->ai_canonname);
> if (ahostbuf == NULL) {
> perror ("rexec: strdup");
> return (-1);
> diff --git a/intl/dcigettext.c b/intl/dcigettext.c
> index 95fa72b1c548ee66d9771eac86488f7f034a0c89..2c7358796eb7853f31773ad8f5e6b89ee94ec5db 100644
> --- a/intl/dcigettext.c
> +++ b/intl/dcigettext.c
> @@ -131,6 +131,9 @@ extern int errno;
> /* Rename the non ANSI C functions. This is required by the standard
> because some ANSI C functions will require linking with this object
> file and the name space must not be polluted. */
> +# ifndef strdup
> +# define strdup __strdup
> +# endif
> # define getcwd __getcwd
> # ifndef stpcpy
> # define stpcpy __stpcpy
> diff --git a/intl/finddomain.c b/intl/finddomain.c
> index cb61a0c8d6b90023847ef0cc609524a0c0a070a0..88fd880dbcc3e21cd4975306f1196a906116d1cc 100644
> --- a/intl/finddomain.c
> +++ b/intl/finddomain.c
> @@ -124,18 +124,12 @@ _nl_find_domain (const char *dirname, char *locale,
> alias_value = _nl_expand_alias (locale);
> if (alias_value != NULL)
> {
> -#if defined _LIBC || defined HAVE_STRDUP
> - locale = strdup (alias_value);
> - if (locale == NULL)
> - return NULL;
> -#else
> size_t len = strlen (alias_value) + 1;
> locale = (char *) malloc (len);
> if (locale == NULL)
> return NULL;
>
> memcpy (locale, alias_value, len);
> -#endif
> }
>
> /* Now we determine the single parts of the locale name. First
> diff --git a/locale/loadarchive.c b/locale/loadarchive.c
> index fc6fb32a9d706c0501f83b166d3aa73a19c9c58f..e6e1a05d2e7b74abf81d136760f0c42d58744f57 100644
> --- a/locale/loadarchive.c
> +++ b/locale/loadarchive.c
> @@ -462,7 +462,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
> if (__glibc_unlikely (lia == NULL))
> return NULL;
>
> - lia->name = strdup (*namep);
> + lia->name = __strdup (*namep);
> if (__glibc_unlikely (lia->name == NULL))
> {
> free (lia);
> diff --git a/locale/setlocale.c b/locale/setlocale.c
> index 1603ef306a51a8fe9368a617eae67310b77ffb0f..19acc4b2c7173ece3b235f289c57c4c74f3da5cc 100644
> --- a/locale/setlocale.c
> +++ b/locale/setlocale.c
> @@ -283,7 +283,7 @@ setlocale (int category, const char *locale)
> if (__glibc_unlikely (strchr (locale, ';') != NULL))
> {
> /* This is a composite name. Make a copy and split it up. */
> - locale_copy = strdup (locale);
> + locale_copy = __strdup (locale);
> if (__glibc_unlikely (locale_copy == NULL))
> {
> __libc_rwlock_unlock (__libc_setlocale_lock);
> diff --git a/posix/spawn_faction_addopen.c b/posix/spawn_faction_addopen.c
> index 95111684bc4ea2f5dd82cc8287cc9ba0db6d9cb1..cbb3584345374e19b37560e4081c618bbb76d707 100644
> --- a/posix/spawn_faction_addopen.c
> +++ b/posix/spawn_faction_addopen.c
> @@ -34,7 +34,7 @@ posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
> if (!__spawn_valid_fd (fd))
> return EBADF;
>
> - char *path_copy = strdup (path);
> + char *path_copy = __strdup (path);
> if (path_copy == NULL)
> return ENOMEM;
>
> diff --git a/stdlib/putenv.c b/stdlib/putenv.c
> index 85890fec264cda0f7d1f6e4bc411b6e2f95af048..c0488fc50558ef2fc2878cdbe436e76276fa3898 100644
> --- a/stdlib/putenv.c
> +++ b/stdlib/putenv.c
> @@ -60,7 +60,7 @@ putenv (char *string)
> int use_malloc = !__libc_use_alloca (name_end - string + 1);
> if (__builtin_expect (use_malloc, 0))
> {
> - name = strndup (string, name_end - string);
> + name = __strndup (string, name_end - string);
> if (name == NULL)
> return -1;
> }
> diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
> index baa177eec0f1fea3306e056033be29cee42fe132..acc9b9db14fa24b4b04e4ddca7d10980e661fe88 100644
> --- a/sunrpc/svc_simple.c
> +++ b/sunrpc/svc_simple.c
> @@ -87,7 +87,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
> transp = svcudp_create (RPC_ANYSOCK);
> if (transp == NULL)
> {
> - buf = strdup (_("couldn't create an rpc server\n"));
> + buf = __strdup (_("couldn't create an rpc server\n"));
> goto err_out;
> }
> }
> @@ -103,7 +103,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
> pl = (struct proglst_ *) malloc (sizeof (struct proglst_));
> if (pl == NULL)
> {
> - buf = strdup (_("registerrpc: out of memory\n"));
> + buf = __strdup (_("registerrpc: out of memory\n"));
> goto err_out;
> }
> pl->p_progname = progname;
> diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
> index 43eb31365ed10059bb6e1147af197ed54550e6c5..eed7264850307b6b65b055a6936dc6362d5b3ff9 100644
> --- a/sysdeps/posix/getaddrinfo.c
> +++ b/sysdeps/posix/getaddrinfo.c
> @@ -536,7 +536,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
> }
> else
> {
> - namebuf = strndup (name, scope_delim - name);
> + namebuf = __strndup (name, scope_delim - name);
> if (namebuf == NULL)
> {
> assert (!malloc_name);
> @@ -1141,7 +1141,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
> malloc_canonbuf = false;
> else
> {
> - canon = strdup (canon);
> + canon = __strdup (canon);
> if (canon == NULL)
> {
> result = -EAI_MEMORY;
>
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-02-17 13:09 ` Wilco Dijkstra
@ 2017-03-07 15:30 ` Wilco Dijkstra
2017-03-13 12:45 ` Adhemerval Zanella
0 siblings, 1 reply; 12+ messages in thread
From: Wilco Dijkstra @ 2017-03-07 15:30 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: libc-alpha, nd
ping
From: Wilco Dijkstra
Sent: 10 February 2017 18:40
To: Adhemerval Zanella
Cc: libc-alpha@sourceware.org; nd
Subject: Re: [PATCH] Rename strdup uses
Adhemerval Zanella wrote:
>
> Ah right, although imho for such coupled patchset splitting is more confusing
> than a single one.
Well if it helps I can easily list them together (rebased to latest sources and the
XOPEN defines now removed):
Remove the str(n)dup inlines from string/bits/string2.h. Although inlining
calls with constant strings shows a small (~10%) performance gain, strdup is
typically used in error reporting code, so not performance critical.
Remove the now unused __need_malloc_and_calloc related defines from stdlib.h.
Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be
redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt
or linkname space failures (partial fix for BZ #15105 and BZ #19463).
ChangeLog:
2017-02-10 Wilco Dijkstra <wdijkstr@arm.com>
[BZ #15105]
[BZ #19463]
* elf/dl-cache.c (_dl_load_cache_lookup): Use __strdup.
* inet/rcmd.c (rcmd_af): Likewise.
* inet/rexec.c (rexec_af): Likewise.
* intl/dcigettext.c (_LIBC): Likewise.
* intl/finddomain.c (_nl_find_domain): Use strdup expansion.
* locale/loadarchive.c (_nl_load_locale_from_archive):
Use __strdup.
* locale/setlocale.c (setlocale): Likewise.
* posix/spawn_faction_addopen.c
(posix_spawn_file_actions_addopen): Likewise.
* stdlib/putenv.c (putenv): Use __strndup.
* sunrpc/svc_simple.c (__registerrpc): Use __strdup.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Use __strdup/__strndup.
* include/stdlib.h (__need_malloc_and_calloc): Remove uses.
(__Need_M_And_C) Remove define/undef.
* stdlib/stdlib.h (__need_malloc_and_calloc): Remove uses.
(__malloc_and_calloc_defined): Remove define.
* string/bits/string2.h (__strdup): Remove define.
(strdup): Likewise.
(__strndup): Likewise.
(strndup): Likewise.
---
diff --git a/include/stdlib.h b/include/stdlib.h
index 352339e8595eb8229018cb27f7d2decf63f511c7..929cead59ae10afe03ae1286b72d8321f0ab2d90 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -1,16 +1,12 @@
#ifndef _STDLIB_H
-#ifdef __need_malloc_and_calloc
-#define __Need_M_And_C
-#endif
-
#ifndef _ISOMAC
# include <stddef.h>
#endif
#include <stdlib/stdlib.h>
/* Now define the internal interfaces. */
-#if !defined __Need_M_And_C && !defined _ISOMAC
+#if !defined _ISOMAC
# include <sys/stat.h>
__BEGIN_DECLS
@@ -269,6 +265,4 @@ __END_DECLS
#endif
-#undef __Need_M_And_C
-
#endif /* include/stdlib.h */
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 292c6a2f053a2a578cd09d75307c26ed191e1c00..7cfbcafe79ec1f7c9d07c464bd56b9bd964755fd 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -25,16 +25,13 @@
#include <bits/libc-header-start.h>
/* Get size_t, wchar_t and NULL from <stddef.h>. */
-#define __need_size_t
-#ifndef __need_malloc_and_calloc
-# define __need_wchar_t
-# define __need_NULL
-#endif
+#define __need_size_t
+#define __need_wchar_t
+#define __need_NULL
#include <stddef.h>
__BEGIN_DECLS
-#ifndef __need_malloc_and_calloc
#define _STDLIB_H 1
#if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
@@ -434,10 +431,6 @@ extern int lcong48_r (unsigned short int __param[7],
# endif /* Use misc. */
#endif /* Use misc or X/Open. */
-#endif /* don't just need malloc and calloc */
-
-#ifndef __malloc_and_calloc_defined
-# define __malloc_and_calloc_defined
__BEGIN_NAMESPACE_STD
/* Allocate SIZE bytes of memory. */
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
@@ -445,9 +438,7 @@ extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
extern void *calloc (size_t __nmemb, size_t __size)
__THROW __attribute_malloc__ __wur;
__END_NAMESPACE_STD
-#endif
-#ifndef __need_malloc_and_calloc
__BEGIN_NAMESPACE_STD
/* Re-allocate the previously allocated block
in PTR, making the new block SIZE bytes long. */
@@ -944,9 +935,6 @@ extern int ttyslot (void) __THROW;
# include <bits/stdlib-ldbl.h>
#endif
-#endif /* don't just need malloc and calloc */
-#undef __need_malloc_and_calloc
-
__END_DECLS
#endif /* stdlib.h */
diff --git a/string/bits/string2.h b/string/bits/string2.h
index e5337becf6fd21a7f303f4e9e8152f8571ec96b1..5d2bd0c8e2f39df6c7a407253e5995d9bb0f6cdb 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -180,65 +180,6 @@ extern void *__rawmemchr (const void *__s, int __c);
#endif
-/* We need the memory allocation functions for inline strdup().
- Referring to stdlib.h (even minimally) is not allowed
- in any of the tight standards compliant modes. */
-#ifdef __USE_MISC
-
-# if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
-# define __need_malloc_and_calloc
-# include <stdlib.h>
-# endif
-
-# ifndef _HAVE_STRING_ARCH_strdup
-
-extern char *__strdup (const char *__string) __THROW __attribute_malloc__;
-# define __strdup(s) \
- (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
- ? (((const char *) (s))[0] == '\0' \
- ? (char *) calloc ((size_t) 1, (size_t) 1) \
- : ({ size_t __len = strlen (s) + 1; \
- char *__retval = (char *) malloc (__len); \
- if (__retval != NULL) \
- __retval = (char *) memcpy (__retval, s, __len); \
- __retval; })) \
- : __strdup (s)))
-
-# if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
-# define strdup(s) __strdup (s)
-# endif
-# endif
-
-# ifndef _HAVE_STRING_ARCH_strndup
-
-extern char *__strndup (const char *__string, size_t __n)
- __THROW __attribute_malloc__;
-# define __strndup(s, n) \
- (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
- ? (((const char *) (s))[0] == '\0' \
- ? (char *) calloc ((size_t) 1, (size_t) 1) \
- : ({ size_t __len = strlen (s) + 1; \
- size_t __n = (n); \
- char *__retval; \
- if (__n < __len) \
- __len = __n + 1; \
- __retval = (char *) malloc (__len); \
- if (__retval != NULL) \
- { \
- __retval[__len - 1] = '\0'; \
- __retval = (char *) memcpy (__retval, s, \
- __len - 1); \
- } \
- __retval; })) \
- : __strndup (s, n)))
-
-# ifdef __USE_XOPEN2K8
-# define strndup(s, n) __strndup (s, n)
-# endif
-# endif
-
-#endif /* Use misc. or use GNU. */
-
#ifndef _FORCE_INLINES
# undef __STRING_INLINE
#endif
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index 1ac7524c3e8cc41eee0e4f20158b67f97a0f60bc..017c78aae36cd981f31b955966bb77c9b793567a 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -302,7 +302,7 @@ _dl_load_cache_lookup (const char *name)
char *temp;
temp = alloca (strlen (best) + 1);
strcpy (temp, best);
- return strdup (temp);
+ return __strdup (temp);
}
#ifndef MAP_COPY
diff --git a/inet/rcmd.c b/inet/rcmd.c
index 8613d96764b08cc8fe3d988a0f38125a0cd54d04..b7cc7a82ba0ac1b39ccf03c589e00114b0bc79a5 100644
--- a/inet/rcmd.c
+++ b/inet/rcmd.c
@@ -149,7 +149,7 @@ rcmd_af (char **ahost, u_short rport, const char *locuser, const char *remuser,
if (res->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res->ai_canonname);
+ ahostbuf = __strdup (res->ai_canonname);
if (ahostbuf == NULL) {
__fxprintf(NULL, "%s",
_("rcmd: Cannot allocate memory\n"));
diff --git a/inet/rexec.c b/inet/rexec.c
index 24ac4b11b6d745aa53a80bd0f7bd10924246b526..43fb67bcf2c6d4fdff9e8dcd053786ab523f7aa1 100644
--- a/inet/rexec.c
+++ b/inet/rexec.c
@@ -73,7 +73,7 @@ rexec_af (char **ahost, int rport, const char *name, const char *pass,
if (res0->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res0->ai_canonname);
+ ahostbuf = __strdup (res0->ai_canonname);
if (ahostbuf == NULL) {
perror ("rexec: strdup");
return (-1);
diff --git a/intl/dcigettext.c b/intl/dcigettext.c
index 95fa72b1c548ee66d9771eac86488f7f034a0c89..2c7358796eb7853f31773ad8f5e6b89ee94ec5db 100644
--- a/intl/dcigettext.c
+++ b/intl/dcigettext.c
@@ -131,6 +131,9 @@ extern int errno;
/* Rename the non ANSI C functions. This is required by the standard
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
+# ifndef strdup
+# define strdup __strdup
+# endif
# define getcwd __getcwd
# ifndef stpcpy
# define stpcpy __stpcpy
diff --git a/intl/finddomain.c b/intl/finddomain.c
index cb61a0c8d6b90023847ef0cc609524a0c0a070a0..88fd880dbcc3e21cd4975306f1196a906116d1cc 100644
--- a/intl/finddomain.c
+++ b/intl/finddomain.c
@@ -124,18 +124,12 @@ _nl_find_domain (const char *dirname, char *locale,
alias_value = _nl_expand_alias (locale);
if (alias_value != NULL)
{
-#if defined _LIBC || defined HAVE_STRDUP
- locale = strdup (alias_value);
- if (locale == NULL)
- return NULL;
-#else
size_t len = strlen (alias_value) + 1;
locale = (char *) malloc (len);
if (locale == NULL)
return NULL;
memcpy (locale, alias_value, len);
-#endif
}
/* Now we determine the single parts of the locale name. First
diff --git a/locale/loadarchive.c b/locale/loadarchive.c
index fc6fb32a9d706c0501f83b166d3aa73a19c9c58f..e6e1a05d2e7b74abf81d136760f0c42d58744f57 100644
--- a/locale/loadarchive.c
+++ b/locale/loadarchive.c
@@ -462,7 +462,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
if (__glibc_unlikely (lia == NULL))
return NULL;
- lia->name = strdup (*namep);
+ lia->name = __strdup (*namep);
if (__glibc_unlikely (lia->name == NULL))
{
free (lia);
diff --git a/locale/setlocale.c b/locale/setlocale.c
index 1603ef306a51a8fe9368a617eae67310b77ffb0f..19acc4b2c7173ece3b235f289c57c4c74f3da5cc 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -283,7 +283,7 @@ setlocale (int category, const char *locale)
if (__glibc_unlikely (strchr (locale, ';') != NULL))
{
/* This is a composite name. Make a copy and split it up. */
- locale_copy = strdup (locale);
+ locale_copy = __strdup (locale);
if (__glibc_unlikely (locale_copy == NULL))
{
__libc_rwlock_unlock (__libc_setlocale_lock);
diff --git a/posix/spawn_faction_addopen.c b/posix/spawn_faction_addopen.c
index 95111684bc4ea2f5dd82cc8287cc9ba0db6d9cb1..cbb3584345374e19b37560e4081c618bbb76d707 100644
--- a/posix/spawn_faction_addopen.c
+++ b/posix/spawn_faction_addopen.c
@@ -34,7 +34,7 @@ posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
if (!__spawn_valid_fd (fd))
return EBADF;
- char *path_copy = strdup (path);
+ char *path_copy = __strdup (path);
if (path_copy == NULL)
return ENOMEM;
diff --git a/stdlib/putenv.c b/stdlib/putenv.c
index 85890fec264cda0f7d1f6e4bc411b6e2f95af048..c0488fc50558ef2fc2878cdbe436e76276fa3898 100644
--- a/stdlib/putenv.c
+++ b/stdlib/putenv.c
@@ -60,7 +60,7 @@ putenv (char *string)
int use_malloc = !__libc_use_alloca (name_end - string + 1);
if (__builtin_expect (use_malloc, 0))
{
- name = strndup (string, name_end - string);
+ name = __strndup (string, name_end - string);
if (name == NULL)
return -1;
}
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index baa177eec0f1fea3306e056033be29cee42fe132..acc9b9db14fa24b4b04e4ddca7d10980e661fe88 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -87,7 +87,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
transp = svcudp_create (RPC_ANYSOCK);
if (transp == NULL)
{
- buf = strdup (_("couldn't create an rpc server\n"));
+ buf = __strdup (_("couldn't create an rpc server\n"));
goto err_out;
}
}
@@ -103,7 +103,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
pl = (struct proglst_ *) malloc (sizeof (struct proglst_));
if (pl == NULL)
{
- buf = strdup (_("registerrpc: out of memory\n"));
+ buf = __strdup (_("registerrpc: out of memory\n"));
goto err_out;
}
pl->p_progname = progname;
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 43eb31365ed10059bb6e1147af197ed54550e6c5..eed7264850307b6b65b055a6936dc6362d5b3ff9 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -536,7 +536,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
else
{
- namebuf = strndup (name, scope_delim - name);
+ namebuf = __strndup (name, scope_delim - name);
if (namebuf == NULL)
{
assert (!malloc_name);
@@ -1141,7 +1141,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
malloc_canonbuf = false;
else
{
- canon = strdup (canon);
+ canon = __strdup (canon);
if (canon == NULL)
{
result = -EAI_MEMORY;
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-02-10 18:40 ` Wilco Dijkstra
@ 2017-02-17 13:09 ` Wilco Dijkstra
2017-03-07 15:30 ` Wilco Dijkstra
0 siblings, 1 reply; 12+ messages in thread
From: Wilco Dijkstra @ 2017-02-17 13:09 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: libc-alpha, nd
ping
From: Wilco Dijkstra
Sent: 10 February 2017 18:40
To: Adhemerval Zanella
Cc: libc-alpha@sourceware.org; nd
Subject: Re: [PATCH] Rename strdup uses
Adhemerval Zanella wrote:
>
> Ah right, although imho for such coupled patchset splitting is more confusing
> than a single one.
Well if it helps I can easily list them together (rebased to latest sources and the
XOPEN defines now removed):
Remove the str(n)dup inlines from string/bits/string2.h. Although inlining
calls with constant strings shows a small (~10%) performance gain, strdup is
typically used in error reporting code, so not performance critical.
Remove the now unused __need_malloc_and_calloc related defines from stdlib.h.
Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be
redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt
or linkname space failures (partial fix for BZ #15105 and BZ #19463).
ChangeLog:
2017-02-10 Wilco Dijkstra <wdijkstr@arm.com>
[BZ #15105]
[BZ #19463]
* elf/dl-cache.c (_dl_load_cache_lookup): Use __strdup.
* inet/rcmd.c (rcmd_af): Likewise.
* inet/rexec.c (rexec_af): Likewise.
* intl/dcigettext.c (_LIBC): Likewise.
* intl/finddomain.c (_nl_find_domain): Use strdup expansion.
* locale/loadarchive.c (_nl_load_locale_from_archive):
Use __strdup.
* locale/setlocale.c (setlocale): Likewise.
* posix/spawn_faction_addopen.c
(posix_spawn_file_actions_addopen): Likewise.
* stdlib/putenv.c (putenv): Use __strndup.
* sunrpc/svc_simple.c (__registerrpc): Use __strdup.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Use __strdup/__strndup.
* include/stdlib.h (__need_malloc_and_calloc): Remove uses.
(__Need_M_And_C) Remove define/undef.
* stdlib/stdlib.h (__need_malloc_and_calloc): Remove uses.
(__malloc_and_calloc_defined): Remove define.
* string/bits/string2.h (__strdup): Remove define.
(strdup): Likewise.
(__strndup): Likewise.
(strndup): Likewise.
---
diff --git a/include/stdlib.h b/include/stdlib.h
index 352339e8595eb8229018cb27f7d2decf63f511c7..929cead59ae10afe03ae1286b72d8321f0ab2d90 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -1,16 +1,12 @@
#ifndef _STDLIB_H
-#ifdef __need_malloc_and_calloc
-#define __Need_M_And_C
-#endif
-
#ifndef _ISOMAC
# include <stddef.h>
#endif
#include <stdlib/stdlib.h>
/* Now define the internal interfaces. */
-#if !defined __Need_M_And_C && !defined _ISOMAC
+#if !defined _ISOMAC
# include <sys/stat.h>
__BEGIN_DECLS
@@ -269,6 +265,4 @@ __END_DECLS
#endif
-#undef __Need_M_And_C
-
#endif /* include/stdlib.h */
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 292c6a2f053a2a578cd09d75307c26ed191e1c00..7cfbcafe79ec1f7c9d07c464bd56b9bd964755fd 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -25,16 +25,13 @@
#include <bits/libc-header-start.h>
/* Get size_t, wchar_t and NULL from <stddef.h>. */
-#define __need_size_t
-#ifndef __need_malloc_and_calloc
-# define __need_wchar_t
-# define __need_NULL
-#endif
+#define __need_size_t
+#define __need_wchar_t
+#define __need_NULL
#include <stddef.h>
__BEGIN_DECLS
-#ifndef __need_malloc_and_calloc
#define _STDLIB_H 1
#if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
@@ -434,10 +431,6 @@ extern int lcong48_r (unsigned short int __param[7],
# endif /* Use misc. */
#endif /* Use misc or X/Open. */
-#endif /* don't just need malloc and calloc */
-
-#ifndef __malloc_and_calloc_defined
-# define __malloc_and_calloc_defined
__BEGIN_NAMESPACE_STD
/* Allocate SIZE bytes of memory. */
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
@@ -445,9 +438,7 @@ extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
extern void *calloc (size_t __nmemb, size_t __size)
__THROW __attribute_malloc__ __wur;
__END_NAMESPACE_STD
-#endif
-#ifndef __need_malloc_and_calloc
__BEGIN_NAMESPACE_STD
/* Re-allocate the previously allocated block
in PTR, making the new block SIZE bytes long. */
@@ -944,9 +935,6 @@ extern int ttyslot (void) __THROW;
# include <bits/stdlib-ldbl.h>
#endif
-#endif /* don't just need malloc and calloc */
-#undef __need_malloc_and_calloc
-
__END_DECLS
#endif /* stdlib.h */
diff --git a/string/bits/string2.h b/string/bits/string2.h
index e5337becf6fd21a7f303f4e9e8152f8571ec96b1..5d2bd0c8e2f39df6c7a407253e5995d9bb0f6cdb 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -180,65 +180,6 @@ extern void *__rawmemchr (const void *__s, int __c);
#endif
-/* We need the memory allocation functions for inline strdup().
- Referring to stdlib.h (even minimally) is not allowed
- in any of the tight standards compliant modes. */
-#ifdef __USE_MISC
-
-# if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
-# define __need_malloc_and_calloc
-# include <stdlib.h>
-# endif
-
-# ifndef _HAVE_STRING_ARCH_strdup
-
-extern char *__strdup (const char *__string) __THROW __attribute_malloc__;
-# define __strdup(s) \
- (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
- ? (((const char *) (s))[0] == '\0' \
- ? (char *) calloc ((size_t) 1, (size_t) 1) \
- : ({ size_t __len = strlen (s) + 1; \
- char *__retval = (char *) malloc (__len); \
- if (__retval != NULL) \
- __retval = (char *) memcpy (__retval, s, __len); \
- __retval; })) \
- : __strdup (s)))
-
-# if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
-# define strdup(s) __strdup (s)
-# endif
-# endif
-
-# ifndef _HAVE_STRING_ARCH_strndup
-
-extern char *__strndup (const char *__string, size_t __n)
- __THROW __attribute_malloc__;
-# define __strndup(s, n) \
- (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
- ? (((const char *) (s))[0] == '\0' \
- ? (char *) calloc ((size_t) 1, (size_t) 1) \
- : ({ size_t __len = strlen (s) + 1; \
- size_t __n = (n); \
- char *__retval; \
- if (__n < __len) \
- __len = __n + 1; \
- __retval = (char *) malloc (__len); \
- if (__retval != NULL) \
- { \
- __retval[__len - 1] = '\0'; \
- __retval = (char *) memcpy (__retval, s, \
- __len - 1); \
- } \
- __retval; })) \
- : __strndup (s, n)))
-
-# ifdef __USE_XOPEN2K8
-# define strndup(s, n) __strndup (s, n)
-# endif
-# endif
-
-#endif /* Use misc. or use GNU. */
-
#ifndef _FORCE_INLINES
# undef __STRING_INLINE
#endif
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index 1ac7524c3e8cc41eee0e4f20158b67f97a0f60bc..017c78aae36cd981f31b955966bb77c9b793567a 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -302,7 +302,7 @@ _dl_load_cache_lookup (const char *name)
char *temp;
temp = alloca (strlen (best) + 1);
strcpy (temp, best);
- return strdup (temp);
+ return __strdup (temp);
}
#ifndef MAP_COPY
diff --git a/inet/rcmd.c b/inet/rcmd.c
index 8613d96764b08cc8fe3d988a0f38125a0cd54d04..b7cc7a82ba0ac1b39ccf03c589e00114b0bc79a5 100644
--- a/inet/rcmd.c
+++ b/inet/rcmd.c
@@ -149,7 +149,7 @@ rcmd_af (char **ahost, u_short rport, const char *locuser, const char *remuser,
if (res->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res->ai_canonname);
+ ahostbuf = __strdup (res->ai_canonname);
if (ahostbuf == NULL) {
__fxprintf(NULL, "%s",
_("rcmd: Cannot allocate memory\n"));
diff --git a/inet/rexec.c b/inet/rexec.c
index 24ac4b11b6d745aa53a80bd0f7bd10924246b526..43fb67bcf2c6d4fdff9e8dcd053786ab523f7aa1 100644
--- a/inet/rexec.c
+++ b/inet/rexec.c
@@ -73,7 +73,7 @@ rexec_af (char **ahost, int rport, const char *name, const char *pass,
if (res0->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res0->ai_canonname);
+ ahostbuf = __strdup (res0->ai_canonname);
if (ahostbuf == NULL) {
perror ("rexec: strdup");
return (-1);
diff --git a/intl/dcigettext.c b/intl/dcigettext.c
index 95fa72b1c548ee66d9771eac86488f7f034a0c89..2c7358796eb7853f31773ad8f5e6b89ee94ec5db 100644
--- a/intl/dcigettext.c
+++ b/intl/dcigettext.c
@@ -131,6 +131,9 @@ extern int errno;
/* Rename the non ANSI C functions. This is required by the standard
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
+# ifndef strdup
+# define strdup __strdup
+# endif
# define getcwd __getcwd
# ifndef stpcpy
# define stpcpy __stpcpy
diff --git a/intl/finddomain.c b/intl/finddomain.c
index cb61a0c8d6b90023847ef0cc609524a0c0a070a0..88fd880dbcc3e21cd4975306f1196a906116d1cc 100644
--- a/intl/finddomain.c
+++ b/intl/finddomain.c
@@ -124,18 +124,12 @@ _nl_find_domain (const char *dirname, char *locale,
alias_value = _nl_expand_alias (locale);
if (alias_value != NULL)
{
-#if defined _LIBC || defined HAVE_STRDUP
- locale = strdup (alias_value);
- if (locale == NULL)
- return NULL;
-#else
size_t len = strlen (alias_value) + 1;
locale = (char *) malloc (len);
if (locale == NULL)
return NULL;
memcpy (locale, alias_value, len);
-#endif
}
/* Now we determine the single parts of the locale name. First
diff --git a/locale/loadarchive.c b/locale/loadarchive.c
index fc6fb32a9d706c0501f83b166d3aa73a19c9c58f..e6e1a05d2e7b74abf81d136760f0c42d58744f57 100644
--- a/locale/loadarchive.c
+++ b/locale/loadarchive.c
@@ -462,7 +462,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
if (__glibc_unlikely (lia == NULL))
return NULL;
- lia->name = strdup (*namep);
+ lia->name = __strdup (*namep);
if (__glibc_unlikely (lia->name == NULL))
{
free (lia);
diff --git a/locale/setlocale.c b/locale/setlocale.c
index 1603ef306a51a8fe9368a617eae67310b77ffb0f..19acc4b2c7173ece3b235f289c57c4c74f3da5cc 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -283,7 +283,7 @@ setlocale (int category, const char *locale)
if (__glibc_unlikely (strchr (locale, ';') != NULL))
{
/* This is a composite name. Make a copy and split it up. */
- locale_copy = strdup (locale);
+ locale_copy = __strdup (locale);
if (__glibc_unlikely (locale_copy == NULL))
{
__libc_rwlock_unlock (__libc_setlocale_lock);
diff --git a/posix/spawn_faction_addopen.c b/posix/spawn_faction_addopen.c
index 95111684bc4ea2f5dd82cc8287cc9ba0db6d9cb1..cbb3584345374e19b37560e4081c618bbb76d707 100644
--- a/posix/spawn_faction_addopen.c
+++ b/posix/spawn_faction_addopen.c
@@ -34,7 +34,7 @@ posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
if (!__spawn_valid_fd (fd))
return EBADF;
- char *path_copy = strdup (path);
+ char *path_copy = __strdup (path);
if (path_copy == NULL)
return ENOMEM;
diff --git a/stdlib/putenv.c b/stdlib/putenv.c
index 85890fec264cda0f7d1f6e4bc411b6e2f95af048..c0488fc50558ef2fc2878cdbe436e76276fa3898 100644
--- a/stdlib/putenv.c
+++ b/stdlib/putenv.c
@@ -60,7 +60,7 @@ putenv (char *string)
int use_malloc = !__libc_use_alloca (name_end - string + 1);
if (__builtin_expect (use_malloc, 0))
{
- name = strndup (string, name_end - string);
+ name = __strndup (string, name_end - string);
if (name == NULL)
return -1;
}
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index baa177eec0f1fea3306e056033be29cee42fe132..acc9b9db14fa24b4b04e4ddca7d10980e661fe88 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -87,7 +87,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
transp = svcudp_create (RPC_ANYSOCK);
if (transp == NULL)
{
- buf = strdup (_("couldn't create an rpc server\n"));
+ buf = __strdup (_("couldn't create an rpc server\n"));
goto err_out;
}
}
@@ -103,7 +103,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
pl = (struct proglst_ *) malloc (sizeof (struct proglst_));
if (pl == NULL)
{
- buf = strdup (_("registerrpc: out of memory\n"));
+ buf = __strdup (_("registerrpc: out of memory\n"));
goto err_out;
}
pl->p_progname = progname;
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 43eb31365ed10059bb6e1147af197ed54550e6c5..eed7264850307b6b65b055a6936dc6362d5b3ff9 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -536,7 +536,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
else
{
- namebuf = strndup (name, scope_delim - name);
+ namebuf = __strndup (name, scope_delim - name);
if (namebuf == NULL)
{
assert (!malloc_name);
@@ -1141,7 +1141,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
malloc_canonbuf = false;
else
{
- canon = strdup (canon);
+ canon = __strdup (canon);
if (canon == NULL)
{
result = -EAI_MEMORY;
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-02-09 22:45 ` Adhemerval Zanella
@ 2017-02-10 18:40 ` Wilco Dijkstra
2017-02-17 13:09 ` Wilco Dijkstra
0 siblings, 1 reply; 12+ messages in thread
From: Wilco Dijkstra @ 2017-02-10 18:40 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: libc-alpha, nd
Adhemerval Zanella wrote:
>
> Ah right, although imho for such coupled patchset splitting is more confusing
> than a single one.
Well if it helps I can easily list them together (rebased to latest sources and the
XOPEN defines now removed):
Remove the str(n)dup inlines from string/bits/string2.h. Although inlining
calls with constant strings shows a small (~10%) performance gain, strdup is
typically used in error reporting code, so not performance critical.
Remove the now unused __need_malloc_and_calloc related defines from stdlib.h.
Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be
redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt
or linkname space failures (partial fix for BZ #15105 and BZ #19463).
ChangeLog:
2017-02-10 Wilco Dijkstra <wdijkstr@arm.com>
[BZ #15105]
[BZ #19463]
* elf/dl-cache.c (_dl_load_cache_lookup): Use __strdup.
* inet/rcmd.c (rcmd_af): Likewise.
* inet/rexec.c (rexec_af): Likewise.
* intl/dcigettext.c (_LIBC): Likewise.
* intl/finddomain.c (_nl_find_domain): Use strdup expansion.
* locale/loadarchive.c (_nl_load_locale_from_archive):
Use __strdup.
* locale/setlocale.c (setlocale): Likewise.
* posix/spawn_faction_addopen.c
(posix_spawn_file_actions_addopen): Likewise.
* stdlib/putenv.c (putenv): Use __strndup.
* sunrpc/svc_simple.c (__registerrpc): Use __strdup.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Use __strdup/__strndup.
* include/stdlib.h (__need_malloc_and_calloc): Remove uses.
(__Need_M_And_C) Remove define/undef.
* stdlib/stdlib.h (__need_malloc_and_calloc): Remove uses.
(__malloc_and_calloc_defined): Remove define.
* string/bits/string2.h (__strdup): Remove define.
(strdup): Likewise.
(__strndup): Likewise.
(strndup): Likewise.
---
diff --git a/include/stdlib.h b/include/stdlib.h
index 352339e8595eb8229018cb27f7d2decf63f511c7..929cead59ae10afe03ae1286b72d8321f0ab2d90 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -1,16 +1,12 @@
#ifndef _STDLIB_H
-#ifdef __need_malloc_and_calloc
-#define __Need_M_And_C
-#endif
-
#ifndef _ISOMAC
# include <stddef.h>
#endif
#include <stdlib/stdlib.h>
/* Now define the internal interfaces. */
-#if !defined __Need_M_And_C && !defined _ISOMAC
+#if !defined _ISOMAC
# include <sys/stat.h>
__BEGIN_DECLS
@@ -269,6 +265,4 @@ __END_DECLS
#endif
-#undef __Need_M_And_C
-
#endif /* include/stdlib.h */
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 292c6a2f053a2a578cd09d75307c26ed191e1c00..7cfbcafe79ec1f7c9d07c464bd56b9bd964755fd 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -25,16 +25,13 @@
#include <bits/libc-header-start.h>
/* Get size_t, wchar_t and NULL from <stddef.h>. */
-#define __need_size_t
-#ifndef __need_malloc_and_calloc
-# define __need_wchar_t
-# define __need_NULL
-#endif
+#define __need_size_t
+#define __need_wchar_t
+#define __need_NULL
#include <stddef.h>
__BEGIN_DECLS
-#ifndef __need_malloc_and_calloc
#define _STDLIB_H 1
#if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
@@ -434,10 +431,6 @@ extern int lcong48_r (unsigned short int __param[7],
# endif /* Use misc. */
#endif /* Use misc or X/Open. */
-#endif /* don't just need malloc and calloc */
-
-#ifndef __malloc_and_calloc_defined
-# define __malloc_and_calloc_defined
__BEGIN_NAMESPACE_STD
/* Allocate SIZE bytes of memory. */
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
@@ -445,9 +438,7 @@ extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
extern void *calloc (size_t __nmemb, size_t __size)
__THROW __attribute_malloc__ __wur;
__END_NAMESPACE_STD
-#endif
-#ifndef __need_malloc_and_calloc
__BEGIN_NAMESPACE_STD
/* Re-allocate the previously allocated block
in PTR, making the new block SIZE bytes long. */
@@ -944,9 +935,6 @@ extern int ttyslot (void) __THROW;
# include <bits/stdlib-ldbl.h>
#endif
-#endif /* don't just need malloc and calloc */
-#undef __need_malloc_and_calloc
-
__END_DECLS
#endif /* stdlib.h */
diff --git a/string/bits/string2.h b/string/bits/string2.h
index e5337becf6fd21a7f303f4e9e8152f8571ec96b1..5d2bd0c8e2f39df6c7a407253e5995d9bb0f6cdb 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -180,65 +180,6 @@ extern void *__rawmemchr (const void *__s, int __c);
#endif
-/* We need the memory allocation functions for inline strdup().
- Referring to stdlib.h (even minimally) is not allowed
- in any of the tight standards compliant modes. */
-#ifdef __USE_MISC
-
-# if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
-# define __need_malloc_and_calloc
-# include <stdlib.h>
-# endif
-
-# ifndef _HAVE_STRING_ARCH_strdup
-
-extern char *__strdup (const char *__string) __THROW __attribute_malloc__;
-# define __strdup(s) \
- (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
- ? (((const char *) (s))[0] == '\0' \
- ? (char *) calloc ((size_t) 1, (size_t) 1) \
- : ({ size_t __len = strlen (s) + 1; \
- char *__retval = (char *) malloc (__len); \
- if (__retval != NULL) \
- __retval = (char *) memcpy (__retval, s, __len); \
- __retval; })) \
- : __strdup (s)))
-
-# if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
-# define strdup(s) __strdup (s)
-# endif
-# endif
-
-# ifndef _HAVE_STRING_ARCH_strndup
-
-extern char *__strndup (const char *__string, size_t __n)
- __THROW __attribute_malloc__;
-# define __strndup(s, n) \
- (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
- ? (((const char *) (s))[0] == '\0' \
- ? (char *) calloc ((size_t) 1, (size_t) 1) \
- : ({ size_t __len = strlen (s) + 1; \
- size_t __n = (n); \
- char *__retval; \
- if (__n < __len) \
- __len = __n + 1; \
- __retval = (char *) malloc (__len); \
- if (__retval != NULL) \
- { \
- __retval[__len - 1] = '\0'; \
- __retval = (char *) memcpy (__retval, s, \
- __len - 1); \
- } \
- __retval; })) \
- : __strndup (s, n)))
-
-# ifdef __USE_XOPEN2K8
-# define strndup(s, n) __strndup (s, n)
-# endif
-# endif
-
-#endif /* Use misc. or use GNU. */
-
#ifndef _FORCE_INLINES
# undef __STRING_INLINE
#endif
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index 1ac7524c3e8cc41eee0e4f20158b67f97a0f60bc..017c78aae36cd981f31b955966bb77c9b793567a 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -302,7 +302,7 @@ _dl_load_cache_lookup (const char *name)
char *temp;
temp = alloca (strlen (best) + 1);
strcpy (temp, best);
- return strdup (temp);
+ return __strdup (temp);
}
#ifndef MAP_COPY
diff --git a/inet/rcmd.c b/inet/rcmd.c
index 8613d96764b08cc8fe3d988a0f38125a0cd54d04..b7cc7a82ba0ac1b39ccf03c589e00114b0bc79a5 100644
--- a/inet/rcmd.c
+++ b/inet/rcmd.c
@@ -149,7 +149,7 @@ rcmd_af (char **ahost, u_short rport, const char *locuser, const char *remuser,
if (res->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res->ai_canonname);
+ ahostbuf = __strdup (res->ai_canonname);
if (ahostbuf == NULL) {
__fxprintf(NULL, "%s",
_("rcmd: Cannot allocate memory\n"));
diff --git a/inet/rexec.c b/inet/rexec.c
index 24ac4b11b6d745aa53a80bd0f7bd10924246b526..43fb67bcf2c6d4fdff9e8dcd053786ab523f7aa1 100644
--- a/inet/rexec.c
+++ b/inet/rexec.c
@@ -73,7 +73,7 @@ rexec_af (char **ahost, int rport, const char *name, const char *pass,
if (res0->ai_canonname){
free (ahostbuf);
- ahostbuf = strdup (res0->ai_canonname);
+ ahostbuf = __strdup (res0->ai_canonname);
if (ahostbuf == NULL) {
perror ("rexec: strdup");
return (-1);
diff --git a/intl/dcigettext.c b/intl/dcigettext.c
index 95fa72b1c548ee66d9771eac86488f7f034a0c89..2c7358796eb7853f31773ad8f5e6b89ee94ec5db 100644
--- a/intl/dcigettext.c
+++ b/intl/dcigettext.c
@@ -131,6 +131,9 @@ extern int errno;
/* Rename the non ANSI C functions. This is required by the standard
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
+# ifndef strdup
+# define strdup __strdup
+# endif
# define getcwd __getcwd
# ifndef stpcpy
# define stpcpy __stpcpy
diff --git a/intl/finddomain.c b/intl/finddomain.c
index cb61a0c8d6b90023847ef0cc609524a0c0a070a0..88fd880dbcc3e21cd4975306f1196a906116d1cc 100644
--- a/intl/finddomain.c
+++ b/intl/finddomain.c
@@ -124,18 +124,12 @@ _nl_find_domain (const char *dirname, char *locale,
alias_value = _nl_expand_alias (locale);
if (alias_value != NULL)
{
-#if defined _LIBC || defined HAVE_STRDUP
- locale = strdup (alias_value);
- if (locale == NULL)
- return NULL;
-#else
size_t len = strlen (alias_value) + 1;
locale = (char *) malloc (len);
if (locale == NULL)
return NULL;
memcpy (locale, alias_value, len);
-#endif
}
/* Now we determine the single parts of the locale name. First
diff --git a/locale/loadarchive.c b/locale/loadarchive.c
index fc6fb32a9d706c0501f83b166d3aa73a19c9c58f..e6e1a05d2e7b74abf81d136760f0c42d58744f57 100644
--- a/locale/loadarchive.c
+++ b/locale/loadarchive.c
@@ -462,7 +462,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
if (__glibc_unlikely (lia == NULL))
return NULL;
- lia->name = strdup (*namep);
+ lia->name = __strdup (*namep);
if (__glibc_unlikely (lia->name == NULL))
{
free (lia);
diff --git a/locale/setlocale.c b/locale/setlocale.c
index 1603ef306a51a8fe9368a617eae67310b77ffb0f..19acc4b2c7173ece3b235f289c57c4c74f3da5cc 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -283,7 +283,7 @@ setlocale (int category, const char *locale)
if (__glibc_unlikely (strchr (locale, ';') != NULL))
{
/* This is a composite name. Make a copy and split it up. */
- locale_copy = strdup (locale);
+ locale_copy = __strdup (locale);
if (__glibc_unlikely (locale_copy == NULL))
{
__libc_rwlock_unlock (__libc_setlocale_lock);
diff --git a/posix/spawn_faction_addopen.c b/posix/spawn_faction_addopen.c
index 95111684bc4ea2f5dd82cc8287cc9ba0db6d9cb1..cbb3584345374e19b37560e4081c618bbb76d707 100644
--- a/posix/spawn_faction_addopen.c
+++ b/posix/spawn_faction_addopen.c
@@ -34,7 +34,7 @@ posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
if (!__spawn_valid_fd (fd))
return EBADF;
- char *path_copy = strdup (path);
+ char *path_copy = __strdup (path);
if (path_copy == NULL)
return ENOMEM;
diff --git a/stdlib/putenv.c b/stdlib/putenv.c
index 85890fec264cda0f7d1f6e4bc411b6e2f95af048..c0488fc50558ef2fc2878cdbe436e76276fa3898 100644
--- a/stdlib/putenv.c
+++ b/stdlib/putenv.c
@@ -60,7 +60,7 @@ putenv (char *string)
int use_malloc = !__libc_use_alloca (name_end - string + 1);
if (__builtin_expect (use_malloc, 0))
{
- name = strndup (string, name_end - string);
+ name = __strndup (string, name_end - string);
if (name == NULL)
return -1;
}
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index baa177eec0f1fea3306e056033be29cee42fe132..acc9b9db14fa24b4b04e4ddca7d10980e661fe88 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -87,7 +87,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
transp = svcudp_create (RPC_ANYSOCK);
if (transp == NULL)
{
- buf = strdup (_("couldn't create an rpc server\n"));
+ buf = __strdup (_("couldn't create an rpc server\n"));
goto err_out;
}
}
@@ -103,7 +103,7 @@ __registerrpc (u_long prognum, u_long versnum, u_long procnum,
pl = (struct proglst_ *) malloc (sizeof (struct proglst_));
if (pl == NULL)
{
- buf = strdup (_("registerrpc: out of memory\n"));
+ buf = __strdup (_("registerrpc: out of memory\n"));
goto err_out;
}
pl->p_progname = progname;
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 43eb31365ed10059bb6e1147af197ed54550e6c5..eed7264850307b6b65b055a6936dc6362d5b3ff9 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -536,7 +536,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
else
{
- namebuf = strndup (name, scope_delim - name);
+ namebuf = __strndup (name, scope_delim - name);
if (namebuf == NULL)
{
assert (!malloc_name);
@@ -1141,7 +1141,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
malloc_canonbuf = false;
else
{
- canon = strdup (canon);
+ canon = __strdup (canon);
if (canon == NULL)
{
result = -EAI_MEMORY;
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
2017-02-09 22:37 Wilco Dijkstra
@ 2017-02-09 22:45 ` Adhemerval Zanella
2017-02-10 18:40 ` Wilco Dijkstra
0 siblings, 1 reply; 12+ messages in thread
From: Adhemerval Zanella @ 2017-02-09 22:45 UTC (permalink / raw)
To: Wilco Dijkstra; +Cc: libc-alpha, nd
On 09/02/2017 20:36, Wilco Dijkstra wrote:
> Adhemerval Zanella wrote:
> On 09/02/2017 13:17, Wilco Dijkstra wrote:
>>> Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be
>>> redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt
>>> or linkname space failures (partial fix for BZ #15105 and BZ #19463). Although this
>>> means a loss of inlining (based on current committed headers) in 2 cases, these
>>> are both error messages so not performance critical.
>>
>> I would prefer to just clump both this patch and the one that removes strdup
>> inlines [1] together and then just remove the strdup and strndup macros
>> on string/string.h. Also, it seems that this patch is not really complete,
>> since by removing the defines on string.h I see the missing spot that
>> triggers PLT failures:
>
> I think you must have mispasted my patch as it starts like this:
>
> --
> diff --git a/elf/dl-cache.c b/elf/dl-cache.c
> index cfa335eb326cd04f3892a09d4c00cef8208a2f33..4c8afd0684b96b44ec069f907b9537d4fc2ff6d2 100644
> --- a/elf/dl-cache.c
> +++ b/elf/dl-cache.c
> @@ -302,7 +302,7 @@ _dl_load_cache_lookup (const char *name)
> char *temp;
> temp = alloca (strlen (best) + 1);
> strcpy (temp, best);
> - return strdup (temp);
> + return __strdup (temp);
> }
Indeed, my bad here.
>
> #ifndef MAP_COPY
> diff --git a/inet/rcmd.c b/inet/rcmd.c
>
>> With this change we can just remove the str{n}dup macros on string.h and
>> simplify this a lot.
>
> I'll remove that chunk from my other patch then. I specifically did this search and replace as
> a separate patch since it's much easier to review and get approval for minor clean-ups.
>
> Wilco
>
Ah right, although imho for such coupled patchset splitting is more confusing
than a single one.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Rename strdup uses
@ 2017-02-09 22:37 Wilco Dijkstra
2017-02-09 22:45 ` Adhemerval Zanella
0 siblings, 1 reply; 12+ messages in thread
From: Wilco Dijkstra @ 2017-02-09 22:37 UTC (permalink / raw)
To: adhemerval.zanella; +Cc: libc-alpha, nd
Adhemerval Zanella wrote:
On 09/02/2017 13:17, Wilco Dijkstra wrote:
> > Rename existing uses of str(n)dup to __str(n)dup so it no longer needs to be
> > redirected to a builtin. Also building GLIBC with -Os now no longer shows localplt
> > or linkname space failures (partial fix for BZ #15105 and BZ #19463). Although this
> > means a loss of inlining (based on current committed headers) in 2 cases, these
> > are both error messages so not performance critical.
>
> I would prefer to just clump both this patch and the one that removes strdup
> inlines [1] together and then just remove the strdup and strndup macros
> on string/string.h. Also, it seems that this patch is not really complete,
> since by removing the defines on string.h I see the missing spot that
> triggers PLT failures:
I think you must have mispasted my patch as it starts like this:
--
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index cfa335eb326cd04f3892a09d4c00cef8208a2f33..4c8afd0684b96b44ec069f907b9537d4fc2ff6d2 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -302,7 +302,7 @@ _dl_load_cache_lookup (const char *name)
char *temp;
temp = alloca (strlen (best) + 1);
strcpy (temp, best);
- return strdup (temp);
+ return __strdup (temp);
}
#ifndef MAP_COPY
diff --git a/inet/rcmd.c b/inet/rcmd.c
> With this change we can just remove the str{n}dup macros on string.h and
> simplify this a lot.
I'll remove that chunk from my other patch then. I specifically did this search and replace as
a separate patch since it's much easier to review and get approval for minor clean-ups.
Wilco
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2017-03-13 12:45 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-11 16:02 [PATCH] Rename strdup uses Wilco Dijkstra
2017-01-11 17:26 ` Joseph Myers
2017-01-12 15:16 ` Wilco Dijkstra
2017-01-12 15:48 ` Joseph Myers
2017-02-09 15:17 ` Wilco Dijkstra
2017-02-09 21:44 ` Adhemerval Zanella
2017-02-09 22:37 Wilco Dijkstra
2017-02-09 22:45 ` Adhemerval Zanella
2017-02-10 18:40 ` Wilco Dijkstra
2017-02-17 13:09 ` Wilco Dijkstra
2017-03-07 15:30 ` Wilco Dijkstra
2017-03-13 12:45 ` Adhemerval Zanella
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 read-only IMAP folder(s) and NNTP newsgroup(s).