* [PATCH] fortify: Ensure that __glibc_fortify condition is a constant [BZ #29141]
@ 2022-05-13 4:32 Siddhesh Poyarekar
2022-05-16 10:59 ` Florian Weimer
0 siblings, 1 reply; 2+ messages in thread
From: Siddhesh Poyarekar @ 2022-05-13 4:32 UTC (permalink / raw)
To: libc-alpha; +Cc: ptr, fweimer
The fix c8ee1c85 introduced a -1 check for object size without also
checking that object size is a constant. Because of this, the tree
optimizer passes in gcc fail to fold away one of the branches in
__glibc_fortify and trips on a spurious Wstringop-overflow. The warning
itself is incorrect and the branch does go away eventually in DCE in the
rtl passes in gcc, but the constant check is a helpful hint to simplify
code early, so add it in.
Resolves: BZ #29141
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
---
misc/sys/cdefs.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index f1faf8292c..1c2b044a0d 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -164,7 +164,7 @@
/* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
condition can be folded to a constant and if it is true, or unknown (-1) */
#define __glibc_safe_or_unknown_len(__l, __s, __osz) \
- ((__osz) == (__SIZE_TYPE__) -1 \
+ ((__builtin_constant_p (__osz) && (__osz) == (__SIZE_TYPE__) -1) \
|| (__glibc_unsigned_or_positive (__l) \
&& __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
(__s), (__osz))) \
--
2.35.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] fortify: Ensure that __glibc_fortify condition is a constant [BZ #29141]
2022-05-13 4:32 [PATCH] fortify: Ensure that __glibc_fortify condition is a constant [BZ #29141] Siddhesh Poyarekar
@ 2022-05-16 10:59 ` Florian Weimer
0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2022-05-16 10:59 UTC (permalink / raw)
To: Siddhesh Poyarekar; +Cc: libc-alpha, ptr
* Siddhesh Poyarekar:
> The fix c8ee1c85 introduced a -1 check for object size without also
> checking that object size is a constant. Because of this, the tree
> optimizer passes in gcc fail to fold away one of the branches in
> __glibc_fortify and trips on a spurious Wstringop-overflow. The warning
> itself is incorrect and the branch does go away eventually in DCE in the
> rtl passes in gcc, but the constant check is a helpful hint to simplify
> code early, so add it in.
>
> Resolves: BZ #29141
> Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
> ---
> misc/sys/cdefs.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
> index f1faf8292c..1c2b044a0d 100644
> --- a/misc/sys/cdefs.h
> +++ b/misc/sys/cdefs.h
> @@ -164,7 +164,7 @@
> /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
> condition can be folded to a constant and if it is true, or unknown (-1) */
> #define __glibc_safe_or_unknown_len(__l, __s, __osz) \
> - ((__osz) == (__SIZE_TYPE__) -1 \
> + ((__builtin_constant_p (__osz) && (__osz) == (__SIZE_TYPE__) -1) \
> || (__glibc_unsigned_or_positive (__l) \
> && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
> (__s), (__osz))) \
I *think* this is okay based on localized review.
Thanks,
Florian
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-16 11:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 4:32 [PATCH] fortify: Ensure that __glibc_fortify condition is a constant [BZ #29141] Siddhesh Poyarekar
2022-05-16 10:59 ` Florian Weimer
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).