mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
tools/nolibc/string: do not use __builtin_strlen() at -O0
clang wants to use strlen() for __builtin_strlen() at -O0. We don't really care about -O0 but it at least ought to build, so let's make sure we don't choke on this, by dropping the optimizationn for constant strings in this case. Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
This commit is contained in:
parent
0b37dff10b
commit
96980b833a
1 changed files with 10 additions and 1 deletions
|
@ -122,7 +122,9 @@ char *strcpy(char *dst, const char *src)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this function is only used with arguments that are not constants */
|
/* this function is only used with arguments that are not constants or when
|
||||||
|
* it's not known because optimizations are disabled.
|
||||||
|
*/
|
||||||
static __attribute__((unused))
|
static __attribute__((unused))
|
||||||
size_t nolibc_strlen(const char *str)
|
size_t nolibc_strlen(const char *str)
|
||||||
{
|
{
|
||||||
|
@ -132,11 +134,18 @@ size_t nolibc_strlen(const char *str)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* do not trust __builtin_constant_p() at -O0, as clang will emit a test and
|
||||||
|
* the two branches, then will rely on an external definition of strlen().
|
||||||
|
*/
|
||||||
|
#if defined(__OPTIMIZE__)
|
||||||
#define strlen(str) ({ \
|
#define strlen(str) ({ \
|
||||||
__builtin_constant_p((str)) ? \
|
__builtin_constant_p((str)) ? \
|
||||||
__builtin_strlen((str)) : \
|
__builtin_strlen((str)) : \
|
||||||
nolibc_strlen((str)); \
|
nolibc_strlen((str)); \
|
||||||
})
|
})
|
||||||
|
#else
|
||||||
|
#define strlen(str) nolibc_strlen((str))
|
||||||
|
#endif
|
||||||
|
|
||||||
static __attribute__((unused))
|
static __attribute__((unused))
|
||||||
size_t strlcat(char *dst, const char *src, size_t size)
|
size_t strlcat(char *dst, const char *src, size_t size)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue