From: Alex Khatskevich <avkhatskevich@tarantool.org> To: Alexander Turenko <alexander.turenko@tarantool.org> Cc: georgy@tarantool.org, tarantool-patches@freelists.org Subject: [tarantool-patches] Re: [PATCH 1/3] Fix: prevent guard-breaker optimization Date: Thu, 11 Oct 2018 19:02:23 +0300 [thread overview] Message-ID: <b5a93d76-2b8c-570d-39ee-2fd45ea38289@tarantool.org> (raw) In-Reply-To: <20181010142610.m7aojo6ro5cuvpqq@tkn_work_nb> On 10.10.2018 17:26, Alexander Turenko wrote: > On Wed, Aug 08, 2018 at 02:10:01PM +0300, AKhatskevich wrote: >> In case of very aggressive optimizations the compiler can >> optimize guard-breaker function away and the `unit/guard` >> test would fail. > I think it is good to mention the specific compiler options (and a > certain compiler you are using to reproduce it) to give a user an idea > when things are going wrong and so what is the fix does. > > Is it due to discarding the noinline attribute in case of LTO on gcc? So > 'volatile' prevents inlining the function? I just guessing here, but I > think the commit message should clarify such things if possible. > >> --- >> test/unit/guard.cc | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/test/unit/guard.cc b/test/unit/guard.cc >> index 231b44c7d..2082dfd48 100644 >> --- a/test/unit/guard.cc >> +++ b/test/unit/guard.cc >> @@ -13,7 +13,7 @@ static int __attribute__((noinline)) >> stack_break_f(char *ptr) >> { >> char block[2048]; >> - char sum = 0; >> + volatile char sum = 0; > I think a reason of using 'volatile' keyword should be always properly > commented in the code, because it always fix some unobvious compiler > behaviour. Discussed verbally. Added a comment near volatile keyword. >> memset(block, 0xff, 2048); >> sum += block[block[4]]; >> ptrdiff_t stack_diff = ptr > block ? ptr - block : block - ptr; >> -- >> 2.14.1 >> >> New diff: commit d7acdc09aa471ea15b3821bab205d8fcdb9280c1 Author: AKhatskevich <avkhatskevich@tarantool.org> Date: Tue Aug 7 16:47:39 2018 +0300 Fix: prevent guard-breaker optimization In case of very aggressive optimizations the compiler can optimize guard-breaker function away and the `unit/guard` test would fail. diff --git a/test/unit/guard.cc b/test/unit/guard.cc index 231b44c7d..3d42fee31 100644 --- a/test/unit/guard.cc +++ b/test/unit/guard.cc @@ -13,7 +13,11 @@ static int __attribute__((noinline)) stack_break_f(char *ptr) { char block[2048]; - char sum = 0; + /* + * Make sum volatile to prevent a compiler from + * optimizing away call to this function. + */ + volatile char sum = 0; memset(block, 0xff, 2048); sum += block[block[4]]; ptrdiff_t stack_diff = ptr > block ? ptr - block : block - ptr;
next prev parent reply other threads:[~2018-10-11 16:02 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-08-08 11:10 [tarantool-patches] [PATCH 0/3] LTO && travis AKhatskevich 2018-08-08 11:10 ` [tarantool-patches] [PATCH 1/3] Fix: prevent guard-breaker optimization AKhatskevich 2018-10-10 14:26 ` [tarantool-patches] " Alexander Turenko 2018-10-11 16:02 ` Alex Khatskevich [this message] 2018-08-08 11:10 ` [tarantool-patches] [PATCH 2/3] Add LTO support AKhatskevich 2018-10-10 14:29 ` [tarantool-patches] " Alexander Turenko 2018-10-11 16:01 ` Alex Khatskevich 2018-08-08 11:10 ` [tarantool-patches] [PATCH 3/3] Add LTO testing && refactor travis.yml AKhatskevich 2018-10-10 14:43 ` [tarantool-patches] " Alexander Turenko 2018-10-11 16:12 ` [tarantool-patches] [PATCH] Enable 0069 policy AKhatskevich 2018-10-11 16:14 ` [tarantool-patches] [tarantool-small] " AKhatskevich 2018-10-11 16:15 ` [tarantool-patches] [tarantool-libyaml] " AKhatskevich 2018-10-11 16:18 ` [tarantool-patches] [tarantool-msgpuck] " AKhatskevich
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 \ --in-reply-to=b5a93d76-2b8c-570d-39ee-2fd45ea38289@tarantool.org \ --to=avkhatskevich@tarantool.org \ --cc=alexander.turenko@tarantool.org \ --cc=georgy@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH 1/3] Fix: prevent guard-breaker optimization' \ /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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox