This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc 4.9.2 and above are not aware of malloc (and friends) hooks


Andrew and all,

as i explained, i already marked the global variable as volatile to get it work.

my (and other Open MPI folks) question is more about gcc :
- is this a bug ? (and it will be fixed, and volatile will not be
needed in the future)
- is this a known "feature" and it will not be fixed. (gcc
deliberately makes such aggressive optimizations that are known to be
illegal in very rare cases, so marking the variable as volatile is not
a workaround but a requirement)

thanks in advance for the clarification

Gilles

On Wed, Jun 10, 2015 at 10:33 AM, Gilles Gouaillardet
<gilles.gouaillardet@gmail.com> wrote:
> Andrew and all,
>
> as i explained, i already marked the global variable as volatile to get it work.
>
> my (and other Open MPI folks) question is more about gcc :
> - is this a bug ? (and it will be fixed, and volatile will not be
> needed in the future)
> - is this a known "feature" and it will not be fixed. (gcc
> deliberately makes such aggressive optimizations that are known to be
> illegal in very rare cases, so marking the variable as volatile is not
> a workaround but a requirement)
>
> thanks in advance for the clarification
>
> Gilles
>
> On Tue, Jun 9, 2015 at 1:48 PM, Andrew Pinski <pinskia@gmail.com> wrote:
>> On Tue, Jun 9, 2015 at 12:42 PM, Gilles Gouaillardet
>> <gilles.gouaillardet@gmail.com> wrote:
>>> This is a follow-up on a discussion about OpenMPI that started at
>>> http://www.open-mpi.org/community/lists/users/2015/06/27039.php
>>> and continued at https://github.com/open-mpi/ompi/pull/625
>>>
>>> The attached test program does not produce correct results with gcc
>>> 4.9.2 and gcc 5.1.0 with -O1 or greater (gcc 4.8.7 is safe)
>>>
>>> At first glance, it seems gcc is not aware a wrapper can be added to
>>> posix_memalign and hence posix_memalign can have some side effects
>>> such as updating user global variables.
>>
>> mark the global variable as volatile.
>>
>> Thanks,
>> Andrew
>>
>>>
>>>
>>> A workaround is to declare the global variable as volatile.
>>>
>>> The expected output of this test program is :
>>> global = 0
>>> changed !
>>> global = 1
>>>
>>>
>>> here are the full outputs with gcc 4.9.2 and 5.1.0 and from O0 to O3
>>>
>>> $ gcc --version ; for i in 0 1 2 3 ; do echo ; echo opt = O$i ; gcc -o
>>> test.O$i -Wno-deprecated-declarations -O$i test.c ; ./test.O$i ; done
>>> gcc (GCC) 4.9.2
>>> Copyright (C) 2014 Free Software Foundation, Inc.
>>> This is free software; see the source for copying conditions.  There is NO
>>> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>>>
>>>
>>> opt = O0
>>> global = 0
>>> changed !
>>> global = 1
>>>
>>> opt = O1
>>> global = 0
>>> global = 1
>>>
>>> opt = O2
>>> global = 0
>>> global = 0
>>>
>>> opt = O3
>>> global = 0
>>> global = 0
>>>
>>>
>>> $ gcc --version ; for i in 0 1 2 3 ; do echo ; echo opt = O$i ; gcc -o
>>> test.O$i -Wno-deprecated-declarations -O$i test.c ; ./test.O$i ; done
>>> gcc (GCC) 5.1.0
>>> Copyright (C) 2015 Free Software Foundation, Inc.
>>> This is free software; see the source for copying conditions.  There is NO
>>> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>>>
>>>
>>> opt = O0
>>> global = 0
>>> changed !
>>> global = 1
>>>
>>> opt = O1
>>> global = 0
>>> global = 0
>>>
>>> opt = O2
>>> global = 0
>>> global = 0
>>>
>>> opt = O3
>>> global = 0
>>> global = 0
>>>
>>>
>>> please note the different behaviour with O1 between gcc 4.9.2 and gcc 5.1.0
>>>
>>>
>>> Could you please comment on this issue ?
>>> - is this a bug ?
>>> - is this a "feature" ? (e.g. a known to be aggressive optimization
>>> that explicitly requires the global variable is declared as volatile)
>>>
>>>
>>> Thanks and regards,
>>>
>>> Gilles


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]