Index: lib/Transforms/Instrumentation/SafeStack.cpp =================================================================== --- lib/Transforms/Instrumentation/SafeStack.cpp +++ lib/Transforms/Instrumentation/SafeStack.cpp @@ -47,6 +47,10 @@ #define DEBUG_TYPE "safestack" +static cl::opt NoTLS("safe-stack-no-tls", + cl::Hidden, + cl::desc("Use non-thread-local storage for the unsafe stack pointer")); + namespace llvm { STATISTIC(NumFunctions, "Total number of functions"); @@ -345,18 +349,22 @@ dyn_cast_or_null(M.getNamedValue(UnsafeStackPtrVar)); if (!UnsafeStackPtr) { + auto TLSModel = NoTLS ? + GlobalValue::NotThreadLocal : + GlobalValue::InitialExecTLSModel; // The global variable is not defined yet, define it ourselves. // We use the initial-exec TLS model because we do not support the // variable living anywhere other than in the main executable. UnsafeStackPtr = new GlobalVariable( M, StackPtrTy, false, GlobalValue::ExternalLinkage, nullptr, - UnsafeStackPtrVar, nullptr, GlobalValue::InitialExecTLSModel); + UnsafeStackPtrVar, nullptr, TLSModel); } else { // The variable exists, check its type and attributes. if (UnsafeStackPtr->getValueType() != StackPtrTy) report_fatal_error(Twine(UnsafeStackPtrVar) + " must have void* type"); - if (!UnsafeStackPtr->isThreadLocal()) - report_fatal_error(Twine(UnsafeStackPtrVar) + " must be thread-local"); + if (NoTLS == UnsafeStackPtr->isThreadLocal()) + report_fatal_error(Twine(UnsafeStackPtrVar) + " must " + + (NoTLS ? "not " : "") + "be thread-local"); } return UnsafeStackPtr; }