This is an archive of the discontinued LLVM Phabricator instance.

Fix sanitizer build against latest glibc
ClosedPublic

Authored by jakubjelinek on Jul 11 2017, 4:18 AM.

Details

Summary

libsanitizer doesn't build against latest glibc anymore, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81066 for details.
One of the changes is that stack_t changed from typedef struct sigaltstack { ... } stack_t; to typedef struct { ... } stack_t; for conformance reasons.
And the other change is that the glibc internal __need_res_state macro is now ignored, so when doing

#define __need_res_state
#include <resolv.h>

the effect is now the same as just

#include <resolv.h>

and thus one doesn't get just the

struct __res_state { ... };

definition, but newly also the

extern struct __res_state *__res_state(void) __attribute__ ((__const__));

prototype. So __res_state is no longer a type, but a function.

Diff Detail

Event Timeline

jakubjelinek created this revision.Jul 11 2017, 4:18 AM

Using stack_t in the internal_sigaltstack prototype is problematic, because stack_t is only defined in the *.cc file which includes signal.h through sys/wait.h. But describing what it points to isn't really necessary, the function could be also declared with uptr arguments, or sanitizer_stack_t if we define it independently, etc.
Alternative to using struct
res_state * is using res_state, i.e.

res_state statp = (res_state)state;
kcc accepted this revision.Jul 11 2017, 1:27 PM

LGTM (assuming it will keep working with older glibc)
Thanks!

This revision is now accepted and ready to land.Jul 11 2017, 1:27 PM

Could somebody please commit it? Thanks.

In D35246#805654, @kcc wrote:

LGTM (assuming it will keep working with older glibc)

Yes, both struct __res_state and stack_t should work even with very old glibc, looked at glibc 2.5.

kcc added a comment.Jul 13 2017, 12:32 PM

Could somebody please commit it? Thanks.

Will do later today.
Meanwhile, I'm pretty sure you'll get commit access if you request it.
http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

In D35246#805654, @kcc wrote:

LGTM (assuming it will keep working with older glibc)

Yes, both struct __res_state and stack_t should work even with very old glibc, looked at glibc 2.5.

kcc closed this revision.Jul 13 2017, 2:59 PM

It isn't enough:

/home/markus/llvm/compiler-rt/lib/esan/esan_sideline_linux.cpp: In static member function ‘static int __esan::SidelineThread::runSideline(void*)’:                                 
/home/markus/llvm/compiler-rt/lib/esan/esan_sideline_linux.cpp:73:22: error: aggregate ‘__esan::SidelineThread::runSideline(void*)::sigaltstack SigAltStack’ has incomplete type and cannot be defined
   struct sigaltstack SigAltStack;          
                      ^~~~~~~~~~~
diff --git a/compiler-rt/lib/esan/esan_sideline_linux.cpp b/compiler-rt/lib/esan/esan_sideline_linux.cpp                                                                           
index d04f5909d6a2..bc272dfe49f8 100644     
--- a/compiler-rt/lib/esan/esan_sideline_linux.cpp                                       
+++ b/compiler-rt/lib/esan/esan_sideline_linux.cpp                                       
@@ -70,7 +70,7 @@ int SidelineThread::runSideline(void *Arg) {                           
                                            
   // Set up a signal handler on an alternate stack for safety.                          
   InternalScopedBuffer<char> StackMap(SigAltStackSize);                                 
-  struct sigaltstack SigAltStack;          
+  stack_t SigAltStack;                     
   SigAltStack.ss_sp = StackMap.data();     
   SigAltStack.ss_size = SigAltStackSize;   
   SigAltStack.ss_flags = 0;