This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] nptl: Add compiler barrier in nptl/tst-pthread-getattr
* Andreas Schwab:
> On Jul 30 2019, Florian Weimer <fweimer@redhat.com> wrote:
>
>> * Andreas Schwab:
>>
>>> On Jul 30 2019, Florian Weimer <fweimer@redhat.com> wrote:
>>>
>>>> * Andreas Schwab:
>>>>
>>>>> On Jul 29 2019, Florian Weimer <fweimer@redhat.com> wrote:
>>>>>
>>>>>> * Carlos O'Donell:
>>>>>>
>>>>>>>> tst-pthread-getattr.c: In function ‘allocate_and_test’:
>>>>>>>> tst-pthread-getattr.c:54:10: error: function returns address of local variable [-Werror=return-local-addr]
>>>>>>>> 54 | return mem;
>>>>>>>> | ^~~
>>>>>>>> In file included from ../include/alloca.h:3,
>>>>>>>> from tst-pthread-getattr.c:26:
>>>>>>>> ../stdlib/alloca.h:35:23: note: declared here
>>>>>>>> 35 | # define alloca(size) __builtin_alloca (size)
>>>>>>>> | ^~~~~~~~~~~~~~~~~~~~~~~
>>>>>>>> tst-pthread-getattr.c:51:9: note: in expansion of macro ‘alloca’
>>>>>>>> 51 | mem = alloca ((size_t) (mem - target));
>>>>>>>> | ^~~~~~
>>>>>>>>
>>>>>>>> The address itself is used in a check in the caller, so using
>>>>>>>> uintptr_t instead is reasonable.
>>>>>>>
>>>>>>> Any reason why we wouldn't move the test into the function?
>>>>>>
>>>>>> I think printf might fault because of its own stack usage (which can
>>>>>> easily exceed half a page in some cases).
>>>>>
>>>>> Then return only the value of the same-page check and print it in the
>>>>> parent.
>>>>
>>>> Sorry, what do you mean?
>>>
>>> If you don't want to print it in allocate_and_test, print it in main.
>>
>> Do you mean to print it in check_stack_top?
>
> Yes, the caller of allocate_and_test. But compute the check in
> allocate_and_test, so you don't need to return a handle to the memory
> that goes out of scope.
But we need that uintptr_t value to print the diagnostic anyway. I do
not see what we gain if we move the check of the value into
allocate_and_test. If printing the value is fine according to the C
semantics, using it in computations should be defined, too.
Thanks,
Florian