From: Willy Tarreau <[email protected]>
To: "Paul E . McKenney" <[email protected]>
Cc: [email protected], [email protected],
Ammar Faizi <[email protected]>
Subject: [PATCH 1/2] tools/nolibc/string: do not use __builtin_strlen() at -O0
Date: Wed, 23 Mar 2022 08:18:06 +0100 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
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 <[email protected]>
---
tools/include/nolibc/string.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h
index 0d5e870c7c0b..75a453870498 100644
--- a/tools/include/nolibc/string.h
+++ b/tools/include/nolibc/string.h
@@ -122,7 +122,9 @@ char *strcpy(char *dst, const char *src)
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))
size_t nolibc_strlen(const char *str)
{
@@ -132,11 +134,18 @@ size_t nolibc_strlen(const char *str)
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) ({ \
__builtin_constant_p((str)) ? \
__builtin_strlen((str)) : \
nolibc_strlen((str)); \
})
+#else
+#define strlen(str) nolibc_strlen((str))
+#endif
static __attribute__((unused))
size_t strlcat(char *dst, const char *src, size_t size)
--
2.35.1
next prev parent reply other threads:[~2022-03-23 7:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-23 7:18 [PATCH 0/2] nolibc: fix two build issues at -O0 Willy Tarreau
2022-03-23 7:18 ` Willy Tarreau [this message]
2022-03-23 7:18 ` [PATCH 2/2] tools/nolibc/stdlib: only reference the external environ when inlined Willy Tarreau
2022-03-23 13:36 ` Ammar Faizi
2022-03-23 23:16 ` [PATCH 0/2] nolibc: fix two build issues at -O0 Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox