OSDN Git Service

remove attribute((const)) from pthread_self and errno location decls
authorRich Felker <dalias@aerifal.cx>
Thu, 17 Sep 2015 04:45:01 +0000 (04:45 +0000)
committerRich Felker <dalias@aerifal.cx>
Thu, 17 Sep 2015 04:45:01 +0000 (04:45 +0000)
this attribute was applied to pthread_self and the functions providing
the locations for errno and h_errno as an optimization; however, it is
subtly incorrect. as specified, it means the return value will always
be the same, which is not true; it varies per-thread.

this attribute also implies that the function does not depend on any
state, and that calls to it can safely be reordered across any other
code. however such reordering is unsafe for these functions: they
break when reordered before initialization of the thread pointer. such
breakage was actually observed when compiled by libfirm/cparser.

to some extent the reordering problem could be solved with strong
compiler barriers between the stages of early startup code, but the
specified meaning of of attribute((const)) is sufficiently strong that
a compiler would theoretically be justified inserting gratuitous calls
to attribute((const)) const functions at random locations (e.g. to
save the value in static storage for later use).

this reverts commit cbf35978a9870fb1f5c73a852c986d4fcca6c2d4.

include/errno.h
include/netdb.h
include/pthread.h

index 0361b33..93f5f6e 100644 (file)
@@ -9,9 +9,6 @@ extern "C" {
 
 #include <bits/errno.h>
 
-#ifdef __GNUC__
-__attribute__((const))
-#endif
 int *__errno_location(void);
 #define errno (*__errno_location())
 
index 703a4b2..4794068 100644 (file)
@@ -122,9 +122,6 @@ struct protoent *getprotobynumber (int);
  || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
 struct hostent *gethostbyname (const char *);
 struct hostent *gethostbyaddr (const void *, socklen_t, int);
-#ifdef __GNUC__
-__attribute__((const))
-#endif
 int *__h_errno_location(void);
 #define h_errno (*__h_errno_location())
 #define HOST_NOT_FOUND 1
index 99a74a5..af70b73 100644 (file)
@@ -79,9 +79,6 @@ int pthread_detach(pthread_t);
 _Noreturn void pthread_exit(void *);
 int pthread_join(pthread_t, void **);
 
-#ifdef __GNUC__
-__attribute__((const))
-#endif
 pthread_t pthread_self(void);
 
 int pthread_equal(pthread_t, pthread_t);