[llvm] b81244f - Add LLVM_ATTRIBUTE_USED to fix problems which could be exposed by aggressive global pointer variable removal

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 26 13:31:42 PDT 2021


Author: Fangrui Song
Date: 2021-04-26T13:31:37-07:00
New Revision: b81244fa4ff9188df22847c6e11e050892292002

URL: https://github.com/llvm/llvm-project/commit/b81244fa4ff9188df22847c6e11e050892292002
DIFF: https://github.com/llvm/llvm-project/commit/b81244fa4ff9188df22847c6e11e050892292002.diff

LOG: Add LLVM_ATTRIBUTE_USED to fix problems which could be exposed by aggressive global pointer variable removal

Note to BuryPointer.cpp:GraveYard. 'unused' cannot prevent (1) dead store
elimination and (2) removal of the global pointer variable (D69428) but 'used' can.

Discovered when comparing link maps between HEAD+D69428 and HEAD.

Reviewed By: lattner

Differential Revision: https://reviews.llvm.org/D101217

Added: 
    

Modified: 
    llvm/lib/Support/BuryPointer.cpp
    llvm/lib/Support/Unix/Signals.inc

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/BuryPointer.cpp b/llvm/lib/Support/BuryPointer.cpp
index 536aee7665d4a..87d2406bbfd1f 100644
--- a/llvm/lib/Support/BuryPointer.cpp
+++ b/llvm/lib/Support/BuryPointer.cpp
@@ -19,7 +19,7 @@ void BuryPointer(const void *Ptr) {
   // will not be properly buried and a leak detector will report a leak, which
   // is what we want in such case.
   static const size_t kGraveYardMaxSize = 16;
-  LLVM_ATTRIBUTE_UNUSED static const void *GraveYard[kGraveYardMaxSize];
+  LLVM_ATTRIBUTE_USED static const void *GraveYard[kGraveYardMaxSize];
   static std::atomic<unsigned> GraveYardSize;
   unsigned Idx = GraveYardSize++;
   if (Idx >= kGraveYardMaxSize)

diff  --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 3d7b5d2fe5aac..575e2aab1eab2 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -255,7 +255,7 @@ static struct {
 // stack if we remove our signal handlers; that can't be done reliably if
 // someone else is also trying to do the same thing.
 static stack_t OldAltStack;
-static void* NewAltStackPointer;
+LLVM_ATTRIBUTE_USED static void *NewAltStackPointer;
 
 static void CreateSigAltStack() {
   const size_t AltStackSize = MINSIGSTKSZ + 64 * 1024;


        


More information about the llvm-commits mailing list