forked from Minki/linux
Urgent nolibc pull request for v6.1
This pull request contains a couple of commits that fix string-function bugs introduced by:96980b833a
("tools/nolibc/string: do not use __builtin_strlen() at -O0")66b6f755ad
("rcutorture: Import a copy of nolibc") These appeared in v5.19 and v5.0, respectively, but it would be good to get these fixes in sooner rather than later. Commits providing the corresponding tests are in -rcu and I expect to submit them into the upcoming v6.2 merge window. -----BEGIN PGP SIGNATURE----- iQJHBAABCgAxFiEEbK7UrM+RBIrCoViJnr8S83LZ+4wFAmNcVM8THHBhdWxtY2tA a2VybmVsLm9yZwAKCRCevxLzctn7jB6ED/43qPeIBl2n4w0MvIfFGW80/laSWZ0o J1r6z0EqTwyHJOx8Yv2tPtpqiJllQXTIH1t4d18wEn/4Bf7rykOCFpNHqvRrui4i kp7V5QQUsAOj5Erk7tenbuIA/x2oHkOBmPQwFTF8T+tBuH9cMKKg2bb4VYW40+Dc 31b3PbBoUDSg1USPfL357itbR+hp8oeWQZdrkYGI3pbF95FEz/49d5UOUZcLya4y TWXAFJFSVb5VLqju3Pg9aa8f2HK1JVAduEN/YRYM+h+9jURo6GV5gtUA1HNDHACF ZF5Q9cm+OwRLHvfMdX8nJl8wBAbumNkPe0S1ABOM0L38vcj2I+p3CIKF1cZK8Z0X QN9eU6EUanlkNcUIsAtT2If1Xs9On6C800Tl3HEGZmHQJmSIy2g++5LY88YfMFO9 Q+2vGIofixXqJEkwg/iFBOF2R57g3iUJNot3uq6Y5z0kWeZMtN5iXiydPd22/eIm puz1NEmTzWsvKN4bI64NmKmSxLbSJWc1Uaydo+XJPgbr1fblTYUKtculPRgbf3N2 4K0Z5k98Az/cbHj614eZ9sgomFbe43nJ/JLlVFsXVjx9H6PnpvrnIrcxRcWWt4+2 6nJwB+GMp/YpSbq74gqvt2LVG+NoYNQZKrQKNePj0vxyNwPx4YpMCrXDaodW3dLT O/G2Xl0HOBqNPA== =EN2i -----END PGP SIGNATURE----- Merge tag 'nolibc-urgent.2022.10.28a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu Pull nolibc fixes from Paul McKenney: "This contains a couple of fixes for string-function bugs" * tag 'nolibc-urgent.2022.10.28a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu: tools/nolibc/string: Fix memcmp() implementation tools/nolibc: Fix missing strlen() definition and infinite loop with gcc-12
This commit is contained in:
commit
54917c90c2
@ -19,9 +19,9 @@ static __attribute__((unused))
|
||||
int memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
size_t ofs = 0;
|
||||
char c1 = 0;
|
||||
int c1 = 0;
|
||||
|
||||
while (ofs < n && !(c1 = ((char *)s1)[ofs] - ((char *)s2)[ofs])) {
|
||||
while (ofs < n && !(c1 = ((unsigned char *)s1)[ofs] - ((unsigned char *)s2)[ofs])) {
|
||||
ofs++;
|
||||
}
|
||||
return c1;
|
||||
@ -125,14 +125,18 @@ char *strcpy(char *dst, const char *src)
|
||||
}
|
||||
|
||||
/* this function is only used with arguments that are not constants or when
|
||||
* it's not known because optimizations are disabled.
|
||||
* it's not known because optimizations are disabled. Note that gcc 12
|
||||
* recognizes an strlen() pattern and replaces it with a jump to strlen(),
|
||||
* thus itself, hence the asm() statement below that's meant to disable this
|
||||
* confusing practice.
|
||||
*/
|
||||
static __attribute__((unused))
|
||||
size_t nolibc_strlen(const char *str)
|
||||
size_t strlen(const char *str)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for (len = 0; str[len]; len++);
|
||||
for (len = 0; str[len]; len++)
|
||||
asm("");
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -140,13 +144,12 @@ size_t nolibc_strlen(const char *str)
|
||||
* the two branches, then will rely on an external definition of strlen().
|
||||
*/
|
||||
#if defined(__OPTIMIZE__)
|
||||
#define nolibc_strlen(x) strlen(x)
|
||||
#define strlen(str) ({ \
|
||||
__builtin_constant_p((str)) ? \
|
||||
__builtin_strlen((str)) : \
|
||||
nolibc_strlen((str)); \
|
||||
})
|
||||
#else
|
||||
#define strlen(str) nolibc_strlen((str))
|
||||
#endif
|
||||
|
||||
static __attribute__((unused))
|
||||
|
Loading…
Reference in New Issue
Block a user