Patchwork nptl: Add compiler barrier in nptl/tst-pthread-getattr

login
register
mail settings
Submitter Carlos O'Donell
Date July 30, 2019, 1:49 a.m.
Message ID <6ae0059a-9c61-5722-aba9-0ba5968d5874@redhat.com>
Download mbox | patch
Permalink /patch/33850/
State New
Headers show

Comments

Carlos O'Donell - July 30, 2019, 1:49 a.m.
On 7/29/19 4:41 PM, Florian Weimer 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).

Good point.

I approve the original commit if you extend the comment to this:

---

Patch

diff --git a/nptl/tst-pthread-getattr.c b/nptl/tst-pthread-getattr.c
index a954778767..50a324cc68 100644
--- a/nptl/tst-pthread-getattr.c
+++ b/nptl/tst-pthread-getattr.c
@@ -41,8 +41,10 @@ 
  
  static size_t pagesize;
  
-/* Check if the page in which TARGET lies is accessible.  This will segfault
-   if it fails.  */
+/* Test that the page in which TARGET lies is accessible.  This will
+   segfault if the write fails.  This function has only half a page
+   of thread stack left and so should not do anything and immediately
+   return the address to which the stack reached.  */
  static volatile char *
  allocate_and_test (char *target)
  {