Bug 25232 - <string.h> does not enable const correctness for strchr et al. for Clang++
Summary: <string.h> does not enable const correctness for strchr et al. for Clang++
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: string (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 2.31
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-29 11:26 UTC by Florian Weimer
Modified: 2019-12-05 16:21 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2019-11-29 11:26:57 UTC
The asm redirect magic is currently restricted to GCC versions with sufficiently new libstdc++:

/* Tell the caller that we provide correct C++ prototypes.  */
#if defined __cplusplus && __GNUC_PREREQ (4, 4)
# define __CORRECT_ISO_CPP_STRING_H_PROTO
#endif

Clang supports asm redirects and could use this facility as well, at least with libstdc++.

Mailing list discussion:

https://sourceware.org/ml/libc-alpha/2019-11/msg00996.html
Comment 1 Sourceware Commits 2019-12-05 15:50:54 UTC
The master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=953ceff17a4a15b10cfdd5edc3c8cae4884c8ec3

commit 953ceff17a4a15b10cfdd5edc3c8cae4884c8ec3
Author: Kamlesh Kumar <kamleshbhalui@gmail.com>
Date:   Thu Dec 5 16:49:00 2019 +0100

    <string.h>: Define __CORRECT_ISO_CPP_STRING_H_PROTO for Clang [BZ #25232]
    
    Without the asm redirects, strchr et al. are not const-correct.
    
    libc++ has a wrapper header that works with and without
    __CORRECT_ISO_CPP_STRING_H_PROTO (using a Clang extension).  But when
    Clang is used with libstdc++ or just C headers, the overloaded functions
    with the correct types are not declared.
    
    This change does not impact current GCC (with libstdc++ or libc++).
Comment 2 Florian Weimer 2019-12-05 15:53:05 UTC
Fixed for glibc 2.31.
Comment 3 Sourceware Commits 2019-12-05 16:20:00 UTC
The release/2.28/master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ef0051070f820dd5c83a73c0f069cfc4fb373db8

commit ef0051070f820dd5c83a73c0f069cfc4fb373db8
Author: Kamlesh Kumar <kamleshbhalui@gmail.com>
Date:   Thu Dec 5 16:56:04 2019 +0100

    <string.h>: Define __CORRECT_ISO_CPP_STRING_H_PROTO for Clang [BZ #25232]
    
    Without the asm redirects, strchr et al. are not const-correct.
    
    libc++ has a wrapper header that works with and without
    __CORRECT_ISO_CPP_STRING_H_PROTO (using a Clang extension).  But when
    Clang is used with libstdc++ or just C headers, the overloaded functions
    with the correct types are not declared.
    
    This change does not impact current GCC (with libstdc++ or libc++).
    
    (cherry picked from commit 953ceff17a4a15b10cfdd5edc3c8cae4884c8ec3)
Comment 4 Sourceware Commits 2019-12-05 16:21:21 UTC
The release/2.29/master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=42786ee476baa05c78e2ed8de8321e789e08ae09

commit 42786ee476baa05c78e2ed8de8321e789e08ae09
Author: Kamlesh Kumar <kamleshbhalui@gmail.com>
Date:   Thu Dec 5 16:55:19 2019 +0100

    <string.h>: Define __CORRECT_ISO_CPP_STRING_H_PROTO for Clang [BZ #25232]
    
    Without the asm redirects, strchr et al. are not const-correct.
    
    libc++ has a wrapper header that works with and without
    __CORRECT_ISO_CPP_STRING_H_PROTO (using a Clang extension).  But when
    Clang is used with libstdc++ or just C headers, the overloaded functions
    with the correct types are not declared.
    
    This change does not impact current GCC (with libstdc++ or libc++).
    
    (cherry picked from commit 953ceff17a4a15b10cfdd5edc3c8cae4884c8ec3)
Comment 5 Sourceware Commits 2019-12-05 16:21:43 UTC
The release/2.30/master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4719e1851cd1101e555f314497504a54ba3fb99a

commit 4719e1851cd1101e555f314497504a54ba3fb99a
Author: Kamlesh Kumar <kamleshbhalui@gmail.com>
Date:   Thu Dec 5 16:54:47 2019 +0100

    <string.h>: Define __CORRECT_ISO_CPP_STRING_H_PROTO for Clang [BZ #25232]
    
    Without the asm redirects, strchr et al. are not const-correct.
    
    libc++ has a wrapper header that works with and without
    __CORRECT_ISO_CPP_STRING_H_PROTO (using a Clang extension).  But when
    Clang is used with libstdc++ or just C headers, the overloaded functions
    with the correct types are not declared.
    
    This change does not impact current GCC (with libstdc++ or libc++).
    
    (cherry picked from commit 953ceff17a4a15b10cfdd5edc3c8cae4884c8ec3)