This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: [PATCH] nptl: Add compiler barrier in nptl/tst-pthread-getattr


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:

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)
 {
---

--
Cheers,
Carlos.


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