public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/fw/gcc-10-fixes] nptl: Add compiler barrier in nptl/tst-pthread-getattr
@ 2019-07-22 11:22 Florian Weimer
  0 siblings, 0 replies; only message in thread
From: Florian Weimer @ 2019-07-22 11:22 UTC (permalink / raw)
  To: glibc-cvs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 2451 bytes --]

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=fe0f9ca932585280325bb9779733761ff82e9ac3

commit fe0f9ca932585280325bb9779733761ff82e9ac3
Author: Florian Weimer <fweimer@redhat.com>
Date:   Mon Jul 22 13:21:18 2019 +0200

    nptl: Add compiler barrier in nptl/tst-pthread-getattr
    
    Recent GCC versions warn about the attempt to return the address of a
    local variable:
    
    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));
          |         ^~~~~~

Diff:
---
 ChangeLog                  |  3 +++
 nptl/tst-pthread-getattr.c | 14 +++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index c6dbb2e..114cb06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2019-07-22  Florian Weimer  <fweimer@redhat.com>
 
+	* nptl/tst-pthread-getattr.c (compiler_barrier): New function.
+	(allocate_and_test): Use it.
+
 	* sysdeps/unix/sysv/linux/bits/socket.h [__USE_MISC]: Include
 	<linux/sockios.h>.
 
diff --git a/nptl/tst-pthread-getattr.c b/nptl/tst-pthread-getattr.c
index a954778..a11a254 100644
--- a/nptl/tst-pthread-getattr.c
+++ b/nptl/tst-pthread-getattr.c
@@ -41,6 +41,15 @@
 
 static size_t pagesize;
 
+/* The weak attribute marks this function as interposable, so the
+   compiler cannot assume that the pointer remains unchanged.  */
+__attribute__ ((noinline, noclone,  weak))
+volatile char *
+compiler_barrier (volatile char *ptr)
+{
+  return ptr;
+}
+
 /* Check if the page in which TARGET lies is accessible.  This will segfault
    if it fails.  */
 static volatile char *
@@ -51,7 +60,10 @@ allocate_and_test (char *target)
   mem = alloca ((size_t) (mem - target));
 
   *mem = 42;
-  return mem;
+
+  /* Insert the compiler barrier to hide the fact that mem is
+     stack-allocated.  The address is only used in a diagnostic.  */
+  return compiler_barrier (mem);
 }
 
 static int


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-22 11:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 11:22 [glibc/fw/gcc-10-fixes] nptl: Add compiler barrier in nptl/tst-pthread-getattr Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).