Hello,

Yuqian Yang, le sam. 08 févr. 2025 21:39:59 +0800, a ecrit:
> * Fix stack consumption measurement to make it also work on
>   GNU/Hurd.
>   The problem behind it is that GNU/Hurd uses a totally different
>   way to implement signal handling.

Yes, but

> With `-O2` enabled, the `SimpleSignalHandler` will consume less than
> 100 bytes.

That's not supposed to be so, if the LOG trick was working.

> diff --git a/absl/debugging/internal/stack_consumption.cc 
> b/absl/debugging/internal/stack_consumption.cc
> index b54a1b28..2713c9da 100644
> --- a/absl/debugging/internal/stack_consumption.cc
> +++ b/absl/debugging/internal/stack_consumption.cc
> @@ -66,7 +66,7 @@ constexpr bool kStackGrowsDown = true;
>  // handler. The difference between the stack consumption of these two signals
>  // handlers should give us the stack foorprint of interest.
>  
> -void EmptySignalHandler(int) {}
> +__attribute__((optimize("O0"))) void EmptySignalHandler(int signo) {}

This shouldn't be needed at all.  What happens otherwise?

>  
>  // This is arbitrary value, and could be increase further, at the cost of
>  // memset()ting it all to known sentinel value.
> diff --git a/absl/debugging/internal/stack_consumption_test.cc 
> b/absl/debugging/internal/stack_consumption_test.cc
> index 0255ac8f..6328edcc 100644
> --- a/absl/debugging/internal/stack_consumption_test.cc
> +++ b/absl/debugging/internal/stack_consumption_test.cc
> @@ -20,21 +20,15 @@
>  #include <string.h>
>  
>  #include "gtest/gtest.h"
> -#include "absl/log/log.h"
>  
>  namespace absl {
>  ABSL_NAMESPACE_BEGIN
>  namespace debugging_internal {
>  namespace {
>  
> -static void SimpleSignalHandler(int signo) {
> +static __attribute__((optimize("O0"))) void SimpleSignalHandler(int signo) {
>    char buf[100];
>    memset(buf, 'a', sizeof(buf));
> -
> -  // Never true, but prevents compiler from optimizing buf out.
> -  if (signo == 0) {
> -    LOG(INFO) << static_cast<void*>(buf);

That should be possibly working, making sure that buf gets filled. It is
however missing a trailing \0. Possibly that is what makes the compiler
believe the code is not actually ever called. It'd be useful to see the
generated assembly to be sure what happens exactly.

Samuel

Reply via email to