diff mbox

[committed] Fix libsanitizer build against recent glibc (PR sanitizer/81066)

Message ID 20170714091416.GA2123@tucnak
State New
Headers show

Commit Message

Jakub Jelinek July 14, 2017, 9:14 a.m. UTC
Hi!

glibc recently changed a couple of headers.  One change was
that typedef struct sigaltstack { ... } stack_t; is now
typedef struct { ... } stack_t;
and the other change is that resolv.h now ignores the former (private glibc
macro) __need_res_state macro and after
struct __res_state { ... };
typedef struct __res_state *res_state;
also newly adds
extern struct __res_state *__res_state(void) __attribute__ ((__const__));
declaration even if that macro is defined.

The following patch fixes both of these issues and should work even with
older glibcs.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.
Will backport to release branches soon.

2017-07-14  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/81066
	* sanitizer_common/sanitizer_linux.h: Cherry-pick upstream r307969.
	* sanitizer_common/sanitizer_linux.cc: Likewise.
	* sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc: Likewise.
	* tsan/tsan_platform_linux.cc: Likewise.


	Jakub

Comments

Matthias Klose Sept. 7, 2017, 7:08 a.m. UTC | #1
On 14.07.2017 11:14, Jakub Jelinek wrote:
> Hi!
> 
> glibc recently changed a couple of headers.  One change was
> that typedef struct sigaltstack { ... } stack_t; is now
> typedef struct { ... } stack_t;
> and the other change is that resolv.h now ignores the former (private glibc
> macro) __need_res_state macro and after
> struct __res_state { ... };
> typedef struct __res_state *res_state;
> also newly adds
> extern struct __res_state *__res_state(void) __attribute__ ((__const__));
> declaration even if that macro is defined.
> 
> The following patch fixes both of these issues and should work even with
> older glibcs.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.
> Will backport to release branches soon.

This was backported to gcc-7 only. Ok to backport to the gcc-5 and gcc-6 branches?

Matthias
libsanitizer/

	Backported from mainline
	2017-07-14  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/81066
	* sanitizer_common/sanitizer_linux.h: Cherry-pick upstream r307969.
	* sanitizer_common/sanitizer_linux.cc: Likewise.
	* sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc: Likewise.
	* tsan/tsan_platform_linux.cc: Likewise.

Index: b/src/libsanitizer/sanitizer_common/sanitizer_linux.cc
===================================================================
--- a/src/libsanitizer/sanitizer_common/sanitizer_linux.cc
+++ b/src/libsanitizer/sanitizer_common/sanitizer_linux.cc
@@ -546,8 +546,7 @@ uptr internal_prctl(int option, uptr arg
 }
 #endif
 
-uptr internal_sigaltstack(const struct sigaltstack *ss,
-                         struct sigaltstack *oss) {
+uptr internal_sigaltstack(const void *ss, void *oss) {
   return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
 }
 
Index: b/src/libsanitizer/sanitizer_common/sanitizer_linux.h
===================================================================
--- a/src/libsanitizer/sanitizer_common/sanitizer_linux.h
+++ b/src/libsanitizer/sanitizer_common/sanitizer_linux.h
@@ -19,7 +19,6 @@
 #include "sanitizer_platform_limits_posix.h"
 
 struct link_map;  // Opaque type returned by dlopen().
-struct sigaltstack;
 
 namespace __sanitizer {
 // Dirent structure for getdents(). Note that this structure is different from
@@ -28,8 +27,7 @@ struct linux_dirent;
 
 // Syscall wrappers.
 uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
-uptr internal_sigaltstack(const struct sigaltstack* ss,
-                          struct sigaltstack* oss);
+uptr internal_sigaltstack(const void* ss, void* oss);
 uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
     __sanitizer_sigset_t *oldset);
 void internal_sigfillset(__sanitizer_sigset_t *set);
Index: b/src/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
===================================================================
--- a/src/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+++ b/src/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
@@ -267,7 +267,7 @@ static int TracerThread(void* argument)
 
   // Alternate stack for signal handling.
   InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
-  struct sigaltstack handler_stack;
+  stack_t handler_stack;
   internal_memset(&handler_stack, 0, sizeof(handler_stack));
   handler_stack.ss_sp = handler_stack_memory.data();
   handler_stack.ss_size = kHandlerStackSize;
Index: b/src/libsanitizer/tsan/tsan_platform_linux.cc
===================================================================
--- a/src/libsanitizer/tsan/tsan_platform_linux.cc
+++ b/src/libsanitizer/tsan/tsan_platform_linux.cc
@@ -291,7 +291,7 @@ bool IsGlobalVar(uptr addr) {
 int ExtractResolvFDs(void *state, int *fds, int nfd) {
 #if SANITIZER_LINUX
   int cnt = 0;
-  __res_state *statp = (__res_state*)state;
+  struct __res_state *statp = (struct __res_state*)state;
   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
       fds[cnt++] = statp->_u._ext.nssocks[i];
Richard Biener Sept. 7, 2017, 7:10 a.m. UTC | #2
On Thu, Sep 7, 2017 at 9:08 AM, Matthias Klose <doko@ubuntu.com> wrote:
> On 14.07.2017 11:14, Jakub Jelinek wrote:
>> Hi!
>>
>> glibc recently changed a couple of headers.  One change was
>> that typedef struct sigaltstack { ... } stack_t; is now
>> typedef struct { ... } stack_t;
>> and the other change is that resolv.h now ignores the former (private glibc
>> macro) __need_res_state macro and after
>> struct __res_state { ... };
>> typedef struct __res_state *res_state;
>> also newly adds
>> extern struct __res_state *__res_state(void) __attribute__ ((__const__));
>> declaration even if that macro is defined.
>>
>> The following patch fixes both of these issues and should work even with
>> older glibcs.
>>
>> Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.
>> Will backport to release branches soon.
>
> This was backported to gcc-7 only. Ok to backport to the gcc-5 and gcc-6 branches?

Yes.

Richard.

> Matthias
>
diff mbox

Patch

--- libsanitizer/sanitizer_common/sanitizer_linux.h	(revision 307968)
+++ libsanitizer/sanitizer_common/sanitizer_linux.h	(revision 307969)
@@ -21,7 +21,6 @@ 
 #include "sanitizer_platform_limits_posix.h"
 
 struct link_map;  // Opaque type returned by dlopen().
-struct sigaltstack;
 
 namespace __sanitizer {
 // Dirent structure for getdents(). Note that this structure is different from
@@ -30,8 +29,7 @@  struct linux_dirent;
 
 // Syscall wrappers.
 uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
-uptr internal_sigaltstack(const struct sigaltstack* ss,
-                          struct sigaltstack* oss);
+uptr internal_sigaltstack(const void* ss, void* oss);
 uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
     __sanitizer_sigset_t *oldset);
 
--- libsanitizer/sanitizer_common/sanitizer_linux.cc	(revision 307968)
+++ libsanitizer/sanitizer_common/sanitizer_linux.cc	(revision 307969)
@@ -629,8 +629,7 @@  uptr internal_prctl(int option, uptr arg
 }
 #endif
 
-uptr internal_sigaltstack(const struct sigaltstack *ss,
-                         struct sigaltstack *oss) {
+uptr internal_sigaltstack(const void *ss, void *oss) {
   return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
 }
 
--- libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc	(revision 307968)
+++ libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc	(revision 307969)
@@ -287,7 +287,7 @@  static int TracerThread(void* argument)
 
   // Alternate stack for signal handling.
   InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
-  struct sigaltstack handler_stack;
+  stack_t handler_stack;
   internal_memset(&handler_stack, 0, sizeof(handler_stack));
   handler_stack.ss_sp = handler_stack_memory.data();
   handler_stack.ss_size = kHandlerStackSize;
--- libsanitizer/tsan/tsan_platform_linux.cc	(revision 307968)
+++ libsanitizer/tsan/tsan_platform_linux.cc	(revision 307969)
@@ -286,7 +286,7 @@  void InitializePlatform() {
 int ExtractResolvFDs(void *state, int *fds, int nfd) {
 #if SANITIZER_LINUX && !SANITIZER_ANDROID
   int cnt = 0;
-  __res_state *statp = (__res_state*)state;
+  struct __res_state *statp = (struct __res_state*)state;
   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
       fds[cnt++] = statp->_u._ext.nssocks[i];