> On Apr 17, 2025, at 10:55 AM, Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> wrote: > > On Thu, Apr 17, 2025 at 6:31 PM Prasad Singamsetty > <prasad.singamsetty@xxxxxxxxxx> wrote: >> >> When CONFIG_FAIL_MAKE_REQUEST is not enabled, gcc may optimize out >> calls to should_fail_bio() because the content of should_fail_bio() >> is empty returning always 'false'. The gcc compiler then detects > > `should_fail_request` is the one that returns `false`, no? i.e. > `should_fail_bio` is the one that gets optimized due to that to return > `0`. > That is correct. I will update the commit message text. >> This issue is seen with gcc compiler version 14. Previous versions >> of gcc compiler (checked 9, 11, 12, 13) don't have this optimization. > > I wonder if whatever changed could be making other things fail. > > Anyway, given what Jens said, this may not be needed to begin with. > > But if it is, then as far as I recall, we try to avoid that kind of > "don't optimize" attribute (the one you used for Clang). So it would > be nice to find other ways to do it. Thanks for the clarification. > > For instance, if what you need is to keep the actual calls to > `should_fail_bio` (not `should_fail_request`), then adding a side > effect like the GCC manual suggests in the `noinline` attribute seems > also to work from a quick test: > > Even if a function is declared with the noinline attribute, there > are optimizations other than inlining that can cause calls to be > optimized away if it does not have side effects, although the function > call is live. To keep such calls from being optimized away, put asm > (""); in the called function, to serve as a special side effect. Thanks for the clarifications. The asm(“”) option also works and we will use that option to fix the issue as that is a preferred method. > > And if you also need to keep the function name emitted as-is, then > `__used` is also needed in GCC, but that would make sense to add > anyway if these functions were expected to be there. Given what Jens > said, I imagine that is why they aren't annotated like that already. Currently GCC is keeping the function even though the call is optimized out. I will update the patch to use asm(“”) option and resend it for review. Thanks, —Prasad > > I hope that helps. > > Cheers, > Miguel