Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: Paul_Woegerer@mentor.com (Woegerer, Paul)
Subject: [lttng-dev] RFC: Fix crash in dlerror()
Date: Thu, 13 Feb 2014 17:51:01 +0100	[thread overview]
Message-ID: <52FCF7F5.9070908@mentor.com> (raw)
In-Reply-To: <581364674.24417.1392309613306.JavaMail.zimbra@efficios.com>

On 02/13/2014 05:40 PM, Mathieu Desnoyers wrote:
> (adding back lttng-dev, and CC Paul E. McKenney. He may have
> some interesting insight in this compiler reordering of store
> vs function call.)
>
> ----- Original Message -----
>> From: "Paul Woegerer" <Paul_Woegerer@mentor.com>
>> To: "Mathieu Desnoyers" <mathieu.desnoyers at efficios.com>
>> Cc: "Stefan Seefeld" <Stefan_Seefeld at mentor.com>
>> Sent: Thursday, February 13, 2014 10:39:30 AM
>> Subject: Re: [lttng-dev] RFC: Fix crash in dlerror()
>>
>> On 02/13/2014 03:47 PM, Mathieu Desnoyers wrote:
>>> ----- Original Message -----
>>>> From: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
>>>> To: "Paul Woegerer" <Paul_Woegerer at mentor.com>
>>>> Cc: "Stefan Seefeld" <Stefan_Seefeld at mentor.com>
>>>> Sent: Thursday, February 13, 2014 9:29:56 AM
>>>> Subject: Re: [lttng-dev] RFC: Fix crash in dlerror()
>>>>
>>>> ----- Original Message -----
>>>>> From: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
>>>>> To: "Paul Woegerer" <Paul_Woegerer at mentor.com>
>>>>> Cc: "Stefan Seefeld" <Stefan_Seefeld at mentor.com>
>>>>> Sent: Thursday, February 13, 2014 9:11:57 AM
>>>>> Subject: Re: [lttng-dev] RFC: Fix crash in dlerror()
>>>>>
>>>>> ----- Original Message -----
>>>>>> From: "Paul Woegerer" <Paul_Woegerer@mentor.com>
>>>>>> To: "Mathieu Desnoyers" <mathieu.desnoyers at efficios.com>
>>>>>> Cc: "Stefan Seefeld" <Stefan_Seefeld at mentor.com>
>>>>>> Sent: Thursday, February 13, 2014 8:46:58 AM
>>>>>> Subject: Re: [lttng-dev] RFC: Fix crash in dlerror()
>>>>>>
>>>>>> On 02/13/2014 02:17 PM, Mathieu Desnoyers wrote:
> [...]
>>>>> I've been able to reproduce with
>>>>>
>>>>> gcc version 4.8.2 (Debian 4.8.2-14)
>>>>>
>>>>> and indeed adding the volatile fixes the issue. But it seems wrong that
>>>>> the
>>>>> compiler thinks it is within its rights to assume it can move the store
>>>>> to that structure after the call to dlsym().
> [...]
>
>>> Adding a cmm_barrier() between the call to setup_static_allocator() and
>>> the first dlsym() call fixes the issue too.
>>>
>>> Thoughts ?
>> Intuitively I would have thought that the def-use analysis of the compiler
>> recognizes the first def to the fields as redundant.
>>
>> e.g.
>>
>> def cur_alloc.calloc (1)
>> def cur_alloc.calloc (2)
>> use cur_alloc.calloc
>>
>> so from compiler perspective (1) is redundant.
> Well actually, it's more:
>
> def cur_alloc.calloc (1)
>
>   calls to dlsym() (should act as a compiler memory barrier)
>
> def cur_alloc.calloc (2)
>
> (where the use of cur_alloc.calloc is within the dlsym() call)
>
> What seems to happen here is that gcc somehow assumes that dlsym() will never
> be interested in the value of the static variable cur_alloc.calloc. But I doubt
> this assumption is valid, because dlsym() could very well have access to a
> function pointer leading to a function within the object containing cur_alloc,
> and thus have to access cur_alloc. How can this store be optimized away without

To assume that dlsym() has "access" to the local static variable
cur_alloc is not something anyone should expect from the compiler. The
fact that dlsym() does have "access" is only due to preloading and the
circumstance that library functions that dlsym() itself uses are
redirected to the ones defined in the wrapper.

--
Best,
Paul

> breaking sequential consistency ?
>
>> It cannot know about the indirect recursion via dlsym. To express this to the
>> compiler you have to make the fields of your struct volatile.
> AFAIK, the compiler should assume that there may be a call to a function using
> cur_alloc within dlsym().
>
>> BTW, for copying cur_alloc, let the compiler create the memcpy for you.
> Good point!
>
> I don't see how volatile would be required here. Maybe it fixes the issue
> (so does adding a compiler barrier), but I feel uneasy just fixing it up
> within lttng-ust if there is a deeper issue in gcc 4.8.
>
> Thoughts ?
>
> Thanks,
>
> Mathieu
>
>


-- 
Paul Woegerer, SW Development Engineer
Sourcery Analyzer <http://go.mentor.com/sourceryanalyzer>
Mentor Graphics, Embedded Software Division




  reply	other threads:[~2014-02-13 16:51 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-07 21:50 Stefan Seefeld
2014-02-08 16:06 ` Mathieu Desnoyers
2014-02-08 16:53   ` Stefan Seefeld
2014-02-08 22:22     ` Mathieu Desnoyers
2014-02-09 16:28       ` Stefan Seefeld
2014-02-11  0:31         ` Mathieu Desnoyers
2014-02-11  0:53       ` Stefan Seefeld
2014-02-11 20:51         ` Mathieu Desnoyers
2014-02-11 20:55           ` Stefan Seefeld
2014-02-12  3:39             ` Mathieu Desnoyers
2014-02-12 14:35               ` Mathieu Desnoyers
2014-02-12 21:59                 ` Mathieu Desnoyers
     [not found] ` <52FCAA28.6020708@mentor.com>
     [not found]   ` <1026072798.24303.1392297452496.JavaMail.zimbra@efficios.com>
     [not found]     ` <52FCCCD2.9050302@mentor.com>
     [not found]       ` <610029715.24333.1392300717731.JavaMail.zimbra@efficios.com>
     [not found]         ` <1692042945.24342.1392301795996.JavaMail.zimbra@efficios.com>
     [not found]           ` <1119459836.24348.1392302831554.JavaMail.zimbra@efficios.com>
     [not found]             ` <52FCE732.9090508@mentor.com>
2014-02-13 16:40               ` Mathieu Desnoyers
2014-02-13 16:51                 ` Woegerer, Paul [this message]
2014-02-13 18:52                   ` Mathieu Desnoyers
2014-02-13 19:44                     ` Woegerer, Paul
2014-02-13 22:06                       ` Woegerer, Paul
2014-02-13 22:44                         ` Stefan Seefeld
2014-02-14  6:59                           ` Woegerer, Paul
2014-02-14 10:30                           ` Alexander Monakov
2014-02-14 11:35                             ` Woegerer, Paul
2014-02-14 11:54                             ` Woegerer, Paul
2014-02-14 13:45                             ` [lttng-dev] [PATCH] Force static_alloc setup to be written into memory Paul Woegerer
2014-02-14 14:08                               ` Mathieu Desnoyers
2014-02-14 14:23                               ` Alexander Monakov
2014-02-14 14:39                                 ` Woegerer, Paul
2014-02-14 14:46                                 ` Stefan Seefeld
2014-02-14 15:12                                 ` Mathieu Desnoyers

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=52FCF7F5.9070908@mentor.com \
    --to=paul_woegerer@mentor.com \
    /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